Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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/** \class TGraphEditor
14 \ingroup ged
15
16Implements GUI for graph attributes.
17
18Title': set the title of the graph
19Change the Shape of the graph:
20 'No Line' = " ": just draw unconnected points
21 'Simple Line' = "L":simple poly line between every point is drawn
22 'Smooth Line' = "C":smooth curve is drawn
23 'Bar Chart' = "B": A bar chart is drawn at each point
24 'Fill Area' = "F": A fill area is drawn
25Check box: 'Marker On/Off' Set Marker visible/invisible
26
27*/
28
29#include "TGComboBox.h"
30#include "TGButtonGroup.h"
31#include "TGraphEditor.h"
32#include "TGTextEntry.h"
33#include "TGraph.h"
34#include "TVirtualPad.h"
35#include "TGraphErrors.h"
36#include "TVirtualX.h"
37
38
51
52//______________________________________________________________________________
53
55 Int_t height, UInt_t options, Pixel_t back)
56 : TGedFrame(p, width, height, options | kVerticalFrame, back)
57{
58 // Constructor of graph editor.
59
60 fGraph = 0;
61 // TextEntry to change the title
62 MakeTitle("Title");
63
64 fTitlePrec = 2;
65 fTitle = new TGTextEntry(this, new TGTextBuffer(50), kGRAPH_TITLE);
66 fTitle->Resize(135, fTitle->GetDefaultHeight());
67 fTitle->SetToolTipText("Enter the graph title string");
68 // better take kLHintsLeft and Right - Right is not working at the moment
69 AddFrame(fTitle, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
70
71 // Radio Buttons to change the draw options of the graph
72 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kVerticalFrame);
73 fgr = new TGButtonGroup(f2,3,1,3,5,"Shape");
74 fgr->SetRadioButtonExclusive(kTRUE);
75 fShape = new TGRadioButton(fgr,"No Line",kSHAPE_NOLINE); // no draw option
76 fShape->SetToolTipText("The points are not connected by a line");
77 fShape0 = new TGRadioButton(fgr,"Smooth Line ",kSHAPE_SMOOTH); // option C
78 fShape0->SetToolTipText("Draw a smooth graph curve");
79 fShape1 = new TGRadioButton(fgr,"Simple Line ",kSHAPE_SIMPLE); // option L
80 fShape1->SetToolTipText("Draw a simple poly-line between the graph points");
81 fShape2 = new TGRadioButton(fgr,"Bar Chart",kSHAPE_BAR); // option B
82 fShape2->SetToolTipText("Draw a bar chart at each graph point");
83 fShape3 = new TGRadioButton(fgr,"Fill area",kSHAPE_FILL); // option F
84 fShape3->SetToolTipText("A fill area is drawn");
85
86 fgr->SetLayoutHints(fShape1lh=new TGLayoutHints(kLHintsLeft, 0,3,0,0), fShape1);
87 fgr->Show();
89 f2->AddFrame(fgr, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
90
91 // CheckBox to activate/deactivate the drawing of the Marker
92 fMarkerOnOff = new TGCheckButton(f2,"Show Marker",kMARKER_ONOFF);
93 fMarkerOnOff->SetToolTipText("Make Marker visible/invisible");
94 f2->AddFrame(fMarkerOnOff, new TGLayoutHints(kLHintsTop, 5, 1, 0, 3));
95 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
96
97 // Exclusion zone parameters
98 MakeTitle("Exclusion Zone");
99 TGCompositeFrame *f3 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
100 AddFrame(f3, new TGLayoutHints(kLHintsTop, 1, 1, 5, 0));
101
103 fExSide->SetToolTipText("Zone is drawing side");
104 f3->AddFrame(fExSide, new TGLayoutHints(kLHintsTop, 5, 1, 0, 0));
105
109 fWidthCombo->Resize(91, 20);
110 f3->AddFrame(fWidthCombo, new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
111 fWidthCombo->Associate(f3);
112}
113
114//______________________________________________________________________________
115
117{
118 // Destructor of graph editor.
119
120 // children of TGButonGroup are not deleted
121 delete fShape;
122 delete fShape0;
123 delete fShape1;
124 delete fShape2;
125 delete fShape3;
126 delete fShape1lh;
127}
128
129//______________________________________________________________________________
130
132{
133 // Connect signals to slots.
134
135 fTitle->Connect("TextChanged(const char *)","TGraphEditor",this,"DoTitle(const char *)");
136 fgr->Connect("Clicked(Int_t)","TGraphEditor",this,"DoShape()");
137 fMarkerOnOff->Connect("Toggled(Bool_t)","TGraphEditor",this,"DoMarkerOnOff(Bool_t)");
138 fWidthCombo->Connect("Selected(Int_t)", "TGraphEditor", this, "DoGraphLineWidth()");
139 fExSide->Connect("Clicked()","TGraphEditor",this,"DoGraphLineWidth()");
140
141 fInit = kFALSE; // connect the slots to the signals only once
142}
143
144//______________________________________________________________________________
145
147{
148 // Pick up the used values of graph attributes.
149
150 fGraph = (TGraph *)obj;
152
153 // set the Title TextEntry
154 const char *text = fGraph->GetTitle();
155 fTitle->SetText(text);
156
157 TString opt = GetDrawOption();
158 opt.ToUpper();
159 Int_t i=0;
160 Bool_t make=kFALSE;
161 // Remove characters which appear twice in the draw option
162 TString dum = opt;
163 Int_t l = opt.Length()-1;
164 while (i < l) {
165 dum.Remove(dum.First(opt[i]),1);
166 if (dum.Contains(opt[i])){
167 opt.Remove(opt.First(opt[i]),1);
168 l--;
169 i--;
170 make=kTRUE;
171 }
172 i++;
173 }
174 // initialise the RadioButton group which shows the drawoption
175 if (opt.Contains("C")) {
176 fgr->SetButton(kSHAPE_SMOOTH, kTRUE);
177 fDrawShape='C';
178 } else if (opt.Contains("L")) {
179 fgr->SetButton(kSHAPE_SIMPLE, kTRUE);
180 fDrawShape='L';
181 } else if (opt.Contains("B")){
182 fgr->SetButton(kSHAPE_BAR, kTRUE);
183 fDrawShape='B';
184 } else if (opt.Contains("F")){
185 fgr->SetButton(kSHAPE_FILL, kTRUE);
186 fDrawShape='F';
187 } else {
188 fgr->SetButton(kSHAPE_NOLINE, kTRUE);
189 fDrawShape=' ';
190 }
191 if (make) SetDrawOption(opt);
192 // if the draw option is A, P, AP the P option cannot be removed,
193 // we deactivate the CheckBox
194 // also initialising the MarkerOnOff checkbutton (== P option)
195 if (opt=="A" || opt=="AP" || opt=="PA" || opt == "P") {
196 if (!opt.Contains("P"))
197 opt +="P";
198 fMarkerOnOff->SetState(kButtonDisabled);
199 } else if (opt.Contains("P")) {
200 fMarkerOnOff->SetState(kButtonDown);
201 } else fMarkerOnOff->SetState(kButtonUp);
202
203 // Exclusion zone parameters
204 if (fGraph->GetLineWidth()<0) fExSide->SetState(kButtonDown, kFALSE);
205 else fExSide->SetState(kButtonUp, kFALSE);
206 fWidthCombo->Select(std::abs(Int_t(fGraph->GetLineWidth()/100)), kFALSE);
207
210}
211
212//______________________________________________________________________________
213
215{
216 // Slot for setting the graph title.
217
218 if (fAvoidSignal) return;
219 fGraph->SetTitle(text);
220 Update();
221}
222
223//______________________________________________________________________________
224
226{
227 // Slot connected to the draw options.
228
229 if (fAvoidSignal) return;
230 TString opt;
231 if (fGraph->InheritsFrom(TGraphErrors::Class()))
232 opt = fGraph->GetDrawOption();
233 else
234 opt = GetDrawOption();
235
236 opt.ToUpper();
237 Int_t s = 0;
238 if (fShape->GetState() == kButtonDown) s = kSHAPE_NOLINE;
239 else if (fShape0->GetState() == kButtonDown) s = kSHAPE_SMOOTH;
240 else if (fShape1->GetState() == kButtonDown) s = kSHAPE_SIMPLE;
241 else if (fShape2->GetState() == kButtonDown) s = kSHAPE_BAR;
242 else s = kSHAPE_FILL;
243
244 switch (s) {
245
246 // change draw option to No Line:
247 case kSHAPE_NOLINE: {
248 if (opt.Contains(fDrawShape))
249 opt.Remove(opt.First(fDrawShape),1);
250 fDrawShape = ' ';
251 fMarkerOnOff->SetState(kButtonDisabled);
252 break;
253 }
254
255 // change draw option to Smooth Line (C)
256 case kSHAPE_SMOOTH: {
257 if (fDrawShape == ' ')
258 opt +="C";
259 else if (opt.Contains(fDrawShape))
260 opt.Replace(opt.First(fDrawShape),1,'C');
261 fDrawShape = 'C';
262 break;
263 }
264
265 // change draw option to Simple Line (L)
266 case kSHAPE_SIMPLE: {
267 if (fDrawShape == ' ')
268 opt +="L";
269 else if (opt.Contains(fDrawShape))
270 opt.Replace(opt.First(fDrawShape),1,'L');
271 fDrawShape='L';
272 break;
273 }
274
275 // change draw option to Bar Chart (B)
276 case kSHAPE_BAR: {
277 if (fDrawShape == ' ')
278 opt +="B";
279 else if (opt.Contains(fDrawShape))
280 opt.Replace(opt.First(fDrawShape),1,'B');
281 fDrawShape='B';
282 break;
283 }
284
285 // change draw option to Fill Area (F)
286 case kSHAPE_FILL: {
287 if (fDrawShape == ' ')
288 opt +="F";
289 else if (opt.Contains(fDrawShape))
290 opt.Replace(opt.First(fDrawShape),1,'F');
291 fDrawShape='F';
292 break;
293 }
294 }
295
296 if (gPad && gPad->GetVirtCanvas())
297 gPad->GetVirtCanvas()->SetCursor(kWatch);
298 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kWatch));
299
300 // set/reset the Marker CheckBox
301 if (opt.Contains("P"))
302 fMarkerOnOff->SetState(kButtonDown);
303 else
304 fMarkerOnOff->SetState(kButtonUp);
305 if (opt=="A" || opt=="AP" || opt=="PA" || opt == "P") {
306 if (!opt.Contains("P"))
307 opt +="P";
308 fMarkerOnOff->SetState(kButtonDisabled);
309 }
310
311 // set/reset the exclusion zone CheckBox
312 if (opt.Contains("L") || opt.Contains("C")) {
313 if (fGraph->GetLineWidth()<0) fExSide->SetState(kButtonDown, kFALSE);
314 else fExSide->SetState(kButtonUp, kFALSE);
315 fWidthCombo->SetEnabled(kTRUE);
316 } else {
317 fExSide->SetState(kButtonDisabled);
318 fWidthCombo->SetEnabled(kFALSE);
319 }
320
321 SetDrawOption(opt);
322 if (gPad && gPad->GetVirtCanvas())
323 gPad->GetVirtCanvas()->SetCursor(kPointer);
324 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
325}
326
327//______________________________________________________________________________
328
330{
331 // Slot for setting markers as visible/invisible.
332
333 if (fAvoidSignal) return;
335 t.ToUpper();
336
337 // showing the marker:
338 if (on) {
339 if (!t.Contains("P")) t+="P";
340 fShape->SetState(kButtonEngaged);
341 } else {
342 // remove the marker option P
343 while (t.Contains("P")) t.Remove(t.First("P"),1);
344 fShape->SetState(kButtonDisabled);
345 }
346 SetDrawOption(t);
347}
348
349//______________________________________________________________________________
350
352{
353 // Slot connected to the graph line width.
354
355 if (fAvoidSignal) return;
356 Int_t width = fWidthCombo->GetSelected();
357 Int_t lineWidth = std::abs(fGraph->GetLineWidth()%100);
358 Int_t side = 1;
359 if (fExSide->GetState() == kButtonDown) side = -1;
360 fGraph->SetLineWidth(side*(100*width+lineWidth));
361 Update();
362}
363
@ kChildFrame
Definition GuiTypes.h:380
@ kSunkenFrame
Definition GuiTypes.h:384
@ kVerticalFrame
Definition GuiTypes.h:382
@ kDoubleBorder
Definition GuiTypes.h:386
@ kFitWidth
Definition GuiTypes.h:387
@ kHorizontalFrame
Definition GuiTypes.h:383
@ kWatch
Definition GuiTypes.h:376
@ kPointer
Definition GuiTypes.h:376
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:41
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kButtonDown
Definition TGButton.h:54
@ kButtonDisabled
Definition TGButton.h:56
@ kButtonUp
Definition TGButton.h:53
@ kButtonEngaged
Definition TGButton.h:55
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsTop
Definition TGLayout.h:27
EGraphWid
@ kGRAPH_LINE_WIDTH
@ kGRAPH_TITLE
@ kMARKER_ONOFF
@ kShape
@ kSHAPE_SMOOTH
@ kSHAPE_SIMPLE
@ kSHAPE_BAR
@ kGRAPH_LINE_SIDE
@ kSHAPE_FILL
@ kSHAPE_NOLINE
#define gPad
#define gVirtualX
Definition TVirtualX.h:375
Organizes TGButton widgets in a group.
Selects different options.
Definition TGButton.h:264
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
TGCompositeFrame(const TGCompositeFrame &)=delete
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition TGFrame.cxx:701
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
The TGLineWidthComboBox user callable and it creates a combobox for selecting the line width.
Definition TGComboBox.h:158
Handle_t GetId() const
Definition TGObject.h:41
Selects different options.
Definition TGButton.h:321
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
ROOT GUI Window base class.
Definition TGWindow.h:23
TGedFrame(const TGedFrame &)=delete
Bool_t fInit
init flag for setting signals/slots
Definition TGedFrame.h:47
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition TGedFrame.cxx:94
void SetDrawOption(Option_t *option="") override
Set drawing option for object.
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition TGedFrame.cxx:71
Option_t * GetDrawOption() const override
Get draw options of the selected object.
Definition TGedFrame.cxx:79
Bool_t fAvoidSignal
flag for executing slots
Definition TGedFrame.h:50
TGLayoutHints * fShape1lh
layout-hints for fShape1
virtual void DoMarkerOnOff(Bool_t on)
~TGraphEditor() override
TGRadioButton * fShape0
set smooth graph curve
virtual void DoShape()
TGraph * fGraph
Graph object.
virtual void DoGraphLineWidth()
TGRadioButton * fShape
just draw unconnected points
TGCheckButton * fMarkerOnOff
set Marker visible/unvisible
char fDrawShape
Shape of the Graph (simple, smooth, bar).
virtual void ConnectSignals2Slots()
TGButtonGroup * fgr
Group the Radiobuttons:
void SetModel(TObject *obj) override
TGraphEditor(const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Int_t fTitlePrec
font precision level
virtual void DoTitle(const char *text)
TGRadioButton * fShape2
set graph draw mode to bar chart
TGCheckButton * fExSide
set the exclusion zone side
TGRadioButton * fShape3
set graph draw mode to fill area
TGLineWidthComboBox * fWidthCombo
Exclusion zone width.
TGRadioButton * fShape1
set simple poly-line between every graph point
TGTextEntry * fTitle
Contains the title of the graph.
static TClass * Class()
Mother of all ROOT objects.
Definition TObject.h:42
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition TString.h:703
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:545
void ToUpper()
Change string to upper case.
Definition TString.cxx:1202
TString & Remove(Ssiz_t pos)
Definition TString.h:694
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:641
TText * text
TLine l
Definition textangle.C:4