Logo ROOT  
Reference Guide
TGraphEditor.cxx
Go to the documentation of this file.
1// @(#)root/ged:$Id$
2// Author: Carsten Hof 16/08/04
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12
13//////////////////////////////////////////////////////////////////////////
14// //
15// TGraphEditor //
16// //
17// Implements GUI for graph attributes. //
18// //
19// Title': set the title of the graph //
20// Change the Shape of the graph: //
21// 'No Line' = " ": just draw unconnected points //
22// 'Simple Line' = "L":simple poly line between every point is drawn//
23// 'Smooth Line' = "C":smooth curve is drawn //
24// 'Bar Chart' = "B": A bar chart is drawn at each point //
25// 'Fill Area' = "F": A fill area is drawn //
26// Check box: 'Marker On/Off' Set Marker visible/invisible //
27// //
28//////////////////////////////////////////////////////////////////////////
29//Begin_Html
30/*
31<img src="gif/TGraphEditor.gif">
32*/
33//End_Html
34
35#include "TGComboBox.h"
36#include "TGButtonGroup.h"
37#include "TGraphEditor.h"
38#include "TGTextEntry.h"
39#include "TGToolTip.h"
40#include "TGLabel.h"
41#include "TGraph.h"
42#include "TVirtualPad.h"
43#include "TGraphErrors.h"
44#include "TVirtualX.h"
45
47
49 kShape = 0,
59};
60
61//______________________________________________________________________________
62
64 Int_t height, UInt_t options, Pixel_t back)
65 : TGedFrame(p, width, height, options | kVerticalFrame, back)
66{
67 // Constructor of graph editor.
68
69 fGraph = 0;
70 // TextEntry to change the title
71 MakeTitle("Title");
72
73 fTitlePrec = 2;
74 fTitle = new TGTextEntry(this, new TGTextBuffer(50), kGRAPH_TITLE);
76 fTitle->SetToolTipText("Enter the graph title string");
77 // better take kLHintsLeft and Right - Right is not working at the moment
78 AddFrame(fTitle, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
79
80 // Radio Buttons to change the draw options of the graph
81 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kVerticalFrame);
82 fgr = new TGButtonGroup(f2,3,1,3,5,"Shape");
84 fShape = new TGRadioButton(fgr,"No Line",kSHAPE_NOLINE); // no draw option
85 fShape->SetToolTipText("The points are not connected by a line");
86 fShape0 = new TGRadioButton(fgr,"Smooth Line ",kSHAPE_SMOOTH); // option C
87 fShape0->SetToolTipText("Draw a smooth graph curve");
88 fShape1 = new TGRadioButton(fgr,"Simple Line ",kSHAPE_SIMPLE); // option L
89 fShape1->SetToolTipText("Draw a simple poly-line between the graph points");
90 fShape2 = new TGRadioButton(fgr,"Bar Chart",kSHAPE_BAR); // option B
91 fShape2->SetToolTipText("Draw a bar chart at each graph point");
92 fShape3 = new TGRadioButton(fgr,"Fill area",kSHAPE_FILL); // option F
93 fShape3->SetToolTipText("A fill area is drawn");
94
96 fgr->Show();
98 f2->AddFrame(fgr, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
99
100 // CheckBox to activate/deactivate the drawing of the Marker
101 fMarkerOnOff = new TGCheckButton(f2,"Show Marker",kMARKER_ONOFF);
102 fMarkerOnOff->SetToolTipText("Make Marker visible/invisible");
103 f2->AddFrame(fMarkerOnOff, new TGLayoutHints(kLHintsTop, 5, 1, 0, 3));
104 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
105
106 // Exclusion zone parameters
107 MakeTitle("Exclusion Zone");
108 TGCompositeFrame *f3 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
109 AddFrame(f3, new TGLayoutHints(kLHintsTop, 1, 1, 5, 0));
110
112 fExSide->SetToolTipText("Zone is drawing side");
113 f3->AddFrame(fExSide, new TGLayoutHints(kLHintsTop, 5, 1, 0, 0));
114
118 fWidthCombo->Resize(91, 20);
119 f3->AddFrame(fWidthCombo, new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
121}
122
123//______________________________________________________________________________
124
126{
127 // Destructor of graph editor.
128
129 // children of TGButonGroup are not deleted
130 delete fShape;
131 delete fShape0;
132 delete fShape1;
133 delete fShape2;
134 delete fShape3;
135 delete fShape1lh;
136}
137
138//______________________________________________________________________________
139
141{
142 // Connect signals to slots.
143
144 fTitle->Connect("TextChanged(const char *)","TGraphEditor",this,"DoTitle(const char *)");
145 fgr->Connect("Clicked(Int_t)","TGraphEditor",this,"DoShape()");
146 fMarkerOnOff->Connect("Toggled(Bool_t)","TGraphEditor",this,"DoMarkerOnOff(Bool_t)");
147 fWidthCombo->Connect("Selected(Int_t)", "TGraphEditor", this, "DoGraphLineWidth()");
148 fExSide->Connect("Clicked()","TGraphEditor",this,"DoGraphLineWidth()");
149
150 fInit = kFALSE; // connect the slots to the signals only once
151}
152
153//______________________________________________________________________________
154
156{
157 // Pick up the used values of graph attributes.
158
159 fGraph = (TGraph *)obj;
161
162 // set the Title TextEntry
163 const char *text = fGraph->GetTitle();
165
166 TString opt = GetDrawOption();
167 opt.ToUpper();
168 Int_t i=0;
170 // Remove characters which appear twice in the draw option
171 TString dum = opt;
172 Int_t l = opt.Length()-1;
173 while (i < l) {
174 dum.Remove(dum.First(opt[i]),1);
175 if (dum.Contains(opt[i])){
176 opt.Remove(opt.First(opt[i]),1);
177 l--;
178 i--;
179 make=kTRUE;
180 }
181 i++;
182 }
183 // initialise the RadioButton group which shows the drawoption
184 if (opt.Contains("C")) {
186 fDrawShape='C';
187 } else if (opt.Contains("L")) {
189 fDrawShape='L';
190 } else if (opt.Contains("B")){
192 fDrawShape='B';
193 } else if (opt.Contains("F")){
195 fDrawShape='F';
196 } else {
198 fDrawShape=' ';
199 }
200 if (make) SetDrawOption(opt);
201 // if the draw option is A, P, AP the P option cannot be removed,
202 // we deactivate the CheckBox
203 // also initialising the MarkerOnOff checkbutton (== P option)
204 if (opt=="A" || opt=="AP" || opt=="PA" || opt == "P") {
205 if (!opt.Contains("P"))
206 opt +="P";
208 } else if (opt.Contains("P")) {
211
212 // Exclusion zone parameters
216
219}
220
221//______________________________________________________________________________
222
224{
225 // Slot for setting the graph title.
226
227 if (fAvoidSignal) return;
229 Update();
230}
231
232//______________________________________________________________________________
233
235{
236 // Slot connected to the draw options.
237
238 if (fAvoidSignal) return;
239 TString opt;
241 opt = fGraph->GetDrawOption();
242 else
243 opt = GetDrawOption();
244
245 opt.ToUpper();
246 Int_t s = 0;
248 else if (fShape0->GetState() == kButtonDown) s = kSHAPE_SMOOTH;
249 else if (fShape1->GetState() == kButtonDown) s = kSHAPE_SIMPLE;
250 else if (fShape2->GetState() == kButtonDown) s = kSHAPE_BAR;
251 else s = kSHAPE_FILL;
252
253 switch (s) {
254
255 // change draw option to No Line:
256 case kSHAPE_NOLINE: {
257 if (opt.Contains(fDrawShape))
258 opt.Remove(opt.First(fDrawShape),1);
259 fDrawShape = ' ';
261 break;
262 }
263
264 // change draw option to Smooth Line (C)
265 case kSHAPE_SMOOTH: {
266 if (fDrawShape == ' ')
267 opt +="C";
268 else if (opt.Contains(fDrawShape))
269 opt.Replace(opt.First(fDrawShape),1,'C');
270 fDrawShape = 'C';
271 break;
272 }
273
274 // change draw option to Simple Line (L)
275 case kSHAPE_SIMPLE: {
276 if (fDrawShape == ' ')
277 opt +="L";
278 else if (opt.Contains(fDrawShape))
279 opt.Replace(opt.First(fDrawShape),1,'L');
280 fDrawShape='L';
281 break;
282 }
283
284 // change draw option to Bar Chart (B)
285 case kSHAPE_BAR: {
286 if (fDrawShape == ' ')
287 opt +="B";
288 else if (opt.Contains(fDrawShape))
289 opt.Replace(opt.First(fDrawShape),1,'B');
290 fDrawShape='B';
291 break;
292 }
293
294 // change draw option to Fill Area (F)
295 case kSHAPE_FILL: {
296 if (fDrawShape == ' ')
297 opt +="F";
298 else if (opt.Contains(fDrawShape))
299 opt.Replace(opt.First(fDrawShape),1,'F');
300 fDrawShape='F';
301 break;
302 }
303 }
304
305 if (gPad && gPad->GetVirtCanvas())
306 gPad->GetVirtCanvas()->SetCursor(kWatch);
307 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kWatch));
308
309 // set/reset the Marker CheckBox
310 if (opt.Contains("P"))
312 else
314 if (opt=="A" || opt=="AP" || opt=="PA" || opt == "P") {
315 if (!opt.Contains("P"))
316 opt +="P";
318 }
319
320 // set/reset the exclusion zone CheckBox
321 if (opt.Contains("L") || opt.Contains("C")) {
325 } else {
328 }
329
330 SetDrawOption(opt);
331 if (gPad && gPad->GetVirtCanvas())
332 gPad->GetVirtCanvas()->SetCursor(kPointer);
333 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
334}
335
336//______________________________________________________________________________
337
339{
340 // Slot for setting markers as visible/invisible.
341
342 if (fAvoidSignal) return;
344 t.ToUpper();
345
346 // showing the marker:
347 if (on) {
348 if (!t.Contains("P")) t+="P";
350 } else {
351 // remove the marker option P
352 while (t.Contains("P")) t.Remove(t.First("P"),1);
354 }
355 SetDrawOption(t);
356}
357
358//______________________________________________________________________________
359
361{
362 // Slot connected to the graph line width.
363
364 if (fAvoidSignal) return;
366 Int_t lineWidth = TMath::Abs(fGraph->GetLineWidth()%100);
367 Int_t side = 1;
368 if (fExSide->GetState() == kButtonDown) side = -1;
369 fGraph->SetLineWidth(side*(100*width+lineWidth));
370 Update();
371}
372
void Class()
Definition: Class.C:29
@ kChildFrame
Definition: GuiTypes.h:379
@ kSunkenFrame
Definition: GuiTypes.h:383
@ kVerticalFrame
Definition: GuiTypes.h:381
@ kDoubleBorder
Definition: GuiTypes.h:385
@ kFitWidth
Definition: GuiTypes.h:386
@ kHorizontalFrame
Definition: GuiTypes.h:382
@ kWatch
Definition: GuiTypes.h:374
@ kPointer
Definition: GuiTypes.h:374
ULong_t Pixel_t
Definition: GuiTypes.h:39
int Int_t
Definition: RtypesCore.h:43
const Bool_t kFALSE
Definition: RtypesCore.h:90
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
@ kButtonDown
Definition: TGButton.h:54
@ kButtonDisabled
Definition: TGButton.h:56
@ kButtonUp
Definition: TGButton.h:53
@ kButtonEngaged
Definition: TGButton.h:55
@ kLHintsLeft
Definition: TGLayout.h:31
@ kLHintsTop
Definition: TGLayout.h:34
EGraphWid
@ kGRAPH_LINE_WIDTH
@ kGRAPH_TITLE
@ kMARKER_ONOFF
@ kShape
@ kSHAPE_SMOOTH
@ kSHAPE_SIMPLE
@ kSHAPE_BAR
@ kGRAPH_LINE_SIDE
@ kSHAPE_FILL
@ kSHAPE_NOLINE
#define gPad
Definition: TVirtualPad.h:287
#define gVirtualX
Definition: TVirtualX.h:338
virtual Width_t GetLineWidth() const
Return the line width.
Definition: TAttLine.h:35
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
virtual void SetRadioButtonExclusive(Bool_t flag=kTRUE)
If enable is kTRUE, this button group will treat radio buttons as mutually exclusive,...
virtual void Show()
Show group of buttons.
virtual void SetLayoutHints(TGLayoutHints *l, TGButton *button=0)
Set layout hints for the specified button or if button=0 for all buttons.
virtual void SetButton(Int_t id, Bool_t down=kTRUE)
Sets the button with id to be on/down, and if this is an exclusive group, all other button in the gro...
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:397
virtual EButtonState GetState() const
Definition: TGButton.h:112
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set check button state.
Definition: TGButton.cxx:1202
virtual Int_t GetSelected() const
Definition: TGComboBox.h:134
virtual void Select(Int_t id, Bool_t emit=kTRUE)
Make the selected item visible in the combo box window and emit signals according to the second param...
Definition: TGComboBox.cxx:451
virtual void SetEnabled(Bool_t on=kTRUE)
Set state of combo box. If kTRUE=enabled, kFALSE=disabled.
Definition: TGComboBox.cxx:639
TGCompositeFrame(const TGCompositeFrame &)
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1101
virtual void ChangeOptions(UInt_t options)
Change composite frame options. Options is an OR of the EFrameTypes.
Definition: TGFrame.cxx:1027
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:693
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:216
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:589
Handle_t GetId() const
Definition: TGObject.h:47
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set radio button state.
Definition: TGButton.cxx:1565
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
virtual void SetText(const char *text, Bool_t emit=kTRUE)
Sets text entry to text, clears the selection and moves the cursor to the end of the line.
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
virtual Option_t * GetDrawOption() const
Get draw options of the selected object.
Definition: TGedFrame.cxx:81
virtual void SetDrawOption(Option_t *option="")
Set drawing option for object.
Definition: TGedFrame.cxx:145
Bool_t fInit
Definition: TGedFrame.h:53
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:73
Bool_t fAvoidSignal
Definition: TGedFrame.h:56
virtual void SetModel(TObject *obj)
TGLayoutHints * fShape1lh
Definition: TGraphEditor.h:45
virtual void DoMarkerOnOff(Bool_t on)
TGRadioButton * fShape0
Definition: TGraphEditor.h:41
virtual ~TGraphEditor()
virtual void DoShape()
TGraph * fGraph
Definition: TGraphEditor.h:38
virtual void DoGraphLineWidth()
TGRadioButton * fShape
Definition: TGraphEditor.h:40
TGCheckButton * fMarkerOnOff
Definition: TGraphEditor.h:46
virtual void ConnectSignals2Slots()
TGButtonGroup * fgr
Definition: TGraphEditor.h:39
Int_t fTitlePrec
Definition: TGraphEditor.h:37
virtual void DoTitle(const char *text)
TGRadioButton * fShape2
Definition: TGraphEditor.h:43
TGCheckButton * fExSide
Definition: TGraphEditor.h:48
TGraphEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
TGRadioButton * fShape3
Definition: TGraphEditor.h:44
TGLineWidthComboBox * fWidthCombo
Definition: TGraphEditor.h:47
TGRadioButton * fShape1
Definition: TGraphEditor.h:42
TGTextEntry * fTitle
Definition: TGraphEditor.h:36
A TGraph is an object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
virtual void SetTitle(const char *title="")
Change (i.e.
Definition: TGraph.cxx:2324
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TObject.cxx:341
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition: TQObject.cxx:866
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition: TString.h:677
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:499
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1138
TString & Remove(Ssiz_t pos)
Definition: TString.h:668
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
TText * text
constexpr std::array< decltype(std::declval< F >()(std::declval< int >())), N > make(F f)
static constexpr double s
Short_t Abs(Short_t d)
Definition: TMathBase.h:120
auto * l
Definition: textangle.C:4