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//////////////////////////////////////////////////////////////////////////
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 "TGraph.h"
40#include "TVirtualPad.h"
41#include "TGraphErrors.h"
42#include "TVirtualX.h"
43
45
47 kShape = 0,
57};
58
59//______________________________________________________________________________
60
62 Int_t height, UInt_t options, Pixel_t back)
63 : TGedFrame(p, width, height, options | kVerticalFrame, back)
64{
65 // Constructor of graph editor.
66
67 fGraph = 0;
68 // TextEntry to change the title
69 MakeTitle("Title");
70
71 fTitlePrec = 2;
72 fTitle = new TGTextEntry(this, new TGTextBuffer(50), kGRAPH_TITLE);
74 fTitle->SetToolTipText("Enter the graph title string");
75 // better take kLHintsLeft and Right - Right is not working at the moment
76 AddFrame(fTitle, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
77
78 // Radio Buttons to change the draw options of the graph
79 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kVerticalFrame);
80 fgr = new TGButtonGroup(f2,3,1,3,5,"Shape");
82 fShape = new TGRadioButton(fgr,"No Line",kSHAPE_NOLINE); // no draw option
83 fShape->SetToolTipText("The points are not connected by a line");
84 fShape0 = new TGRadioButton(fgr,"Smooth Line ",kSHAPE_SMOOTH); // option C
85 fShape0->SetToolTipText("Draw a smooth graph curve");
86 fShape1 = new TGRadioButton(fgr,"Simple Line ",kSHAPE_SIMPLE); // option L
87 fShape1->SetToolTipText("Draw a simple poly-line between the graph points");
88 fShape2 = new TGRadioButton(fgr,"Bar Chart",kSHAPE_BAR); // option B
89 fShape2->SetToolTipText("Draw a bar chart at each graph point");
90 fShape3 = new TGRadioButton(fgr,"Fill area",kSHAPE_FILL); // option F
91 fShape3->SetToolTipText("A fill area is drawn");
92
94 fgr->Show();
96 f2->AddFrame(fgr, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
97
98 // CheckBox to activate/deactivate the drawing of the Marker
99 fMarkerOnOff = new TGCheckButton(f2,"Show Marker",kMARKER_ONOFF);
100 fMarkerOnOff->SetToolTipText("Make Marker visible/invisible");
101 f2->AddFrame(fMarkerOnOff, new TGLayoutHints(kLHintsTop, 5, 1, 0, 3));
102 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
103
104 // Exclusion zone parameters
105 MakeTitle("Exclusion Zone");
106 TGCompositeFrame *f3 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
107 AddFrame(f3, new TGLayoutHints(kLHintsTop, 1, 1, 5, 0));
108
110 fExSide->SetToolTipText("Zone is drawing side");
111 f3->AddFrame(fExSide, new TGLayoutHints(kLHintsTop, 5, 1, 0, 0));
112
116 fWidthCombo->Resize(91, 20);
117 f3->AddFrame(fWidthCombo, new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
119}
120
121//______________________________________________________________________________
122
124{
125 // Destructor of graph editor.
126
127 // children of TGButonGroup are not deleted
128 delete fShape;
129 delete fShape0;
130 delete fShape1;
131 delete fShape2;
132 delete fShape3;
133 delete fShape1lh;
134}
135
136//______________________________________________________________________________
137
139{
140 // Connect signals to slots.
141
142 fTitle->Connect("TextChanged(const char *)","TGraphEditor",this,"DoTitle(const char *)");
143 fgr->Connect("Clicked(Int_t)","TGraphEditor",this,"DoShape()");
144 fMarkerOnOff->Connect("Toggled(Bool_t)","TGraphEditor",this,"DoMarkerOnOff(Bool_t)");
145 fWidthCombo->Connect("Selected(Int_t)", "TGraphEditor", this, "DoGraphLineWidth()");
146 fExSide->Connect("Clicked()","TGraphEditor",this,"DoGraphLineWidth()");
147
148 fInit = kFALSE; // connect the slots to the signals only once
149}
150
151//______________________________________________________________________________
152
154{
155 // Pick up the used values of graph attributes.
156
157 fGraph = (TGraph *)obj;
159
160 // set the Title TextEntry
161 const char *text = fGraph->GetTitle();
163
164 TString opt = GetDrawOption();
165 opt.ToUpper();
166 Int_t i=0;
167 Bool_t make=kFALSE;
168 // Remove characters which appear twice in the draw option
169 TString dum = opt;
170 Int_t l = opt.Length()-1;
171 while (i < l) {
172 dum.Remove(dum.First(opt[i]),1);
173 if (dum.Contains(opt[i])){
174 opt.Remove(opt.First(opt[i]),1);
175 l--;
176 i--;
177 make=kTRUE;
178 }
179 i++;
180 }
181 // initialise the RadioButton group which shows the drawoption
182 if (opt.Contains("C")) {
184 fDrawShape='C';
185 } else if (opt.Contains("L")) {
187 fDrawShape='L';
188 } else if (opt.Contains("B")){
190 fDrawShape='B';
191 } else if (opt.Contains("F")){
193 fDrawShape='F';
194 } else {
196 fDrawShape=' ';
197 }
198 if (make) SetDrawOption(opt);
199 // if the draw option is A, P, AP the P option cannot be removed,
200 // we deactivate the CheckBox
201 // also initialising the MarkerOnOff checkbutton (== P option)
202 if (opt=="A" || opt=="AP" || opt=="PA" || opt == "P") {
203 if (!opt.Contains("P"))
204 opt +="P";
206 } else if (opt.Contains("P")) {
209
210 // Exclusion zone parameters
214
217}
218
219//______________________________________________________________________________
220
222{
223 // Slot for setting the graph title.
224
225 if (fAvoidSignal) return;
227 Update();
228}
229
230//______________________________________________________________________________
231
233{
234 // Slot connected to the draw options.
235
236 if (fAvoidSignal) return;
237 TString opt;
238 if (fGraph->InheritsFrom(TGraphErrors::Class()))
239 opt = fGraph->GetDrawOption();
240 else
241 opt = GetDrawOption();
242
243 opt.ToUpper();
244 Int_t s = 0;
246 else if (fShape0->GetState() == kButtonDown) s = kSHAPE_SMOOTH;
247 else if (fShape1->GetState() == kButtonDown) s = kSHAPE_SIMPLE;
248 else if (fShape2->GetState() == kButtonDown) s = kSHAPE_BAR;
249 else s = kSHAPE_FILL;
250
251 switch (s) {
252
253 // change draw option to No Line:
254 case kSHAPE_NOLINE: {
255 if (opt.Contains(fDrawShape))
256 opt.Remove(opt.First(fDrawShape),1);
257 fDrawShape = ' ';
259 break;
260 }
261
262 // change draw option to Smooth Line (C)
263 case kSHAPE_SMOOTH: {
264 if (fDrawShape == ' ')
265 opt +="C";
266 else if (opt.Contains(fDrawShape))
267 opt.Replace(opt.First(fDrawShape),1,'C');
268 fDrawShape = 'C';
269 break;
270 }
271
272 // change draw option to Simple Line (L)
273 case kSHAPE_SIMPLE: {
274 if (fDrawShape == ' ')
275 opt +="L";
276 else if (opt.Contains(fDrawShape))
277 opt.Replace(opt.First(fDrawShape),1,'L');
278 fDrawShape='L';
279 break;
280 }
281
282 // change draw option to Bar Chart (B)
283 case kSHAPE_BAR: {
284 if (fDrawShape == ' ')
285 opt +="B";
286 else if (opt.Contains(fDrawShape))
287 opt.Replace(opt.First(fDrawShape),1,'B');
288 fDrawShape='B';
289 break;
290 }
291
292 // change draw option to Fill Area (F)
293 case kSHAPE_FILL: {
294 if (fDrawShape == ' ')
295 opt +="F";
296 else if (opt.Contains(fDrawShape))
297 opt.Replace(opt.First(fDrawShape),1,'F');
298 fDrawShape='F';
299 break;
300 }
301 }
302
303 if (gPad && gPad->GetVirtCanvas())
304 gPad->GetVirtCanvas()->SetCursor(kWatch);
305 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kWatch));
306
307 // set/reset the Marker CheckBox
308 if (opt.Contains("P"))
310 else
312 if (opt=="A" || opt=="AP" || opt=="PA" || opt == "P") {
313 if (!opt.Contains("P"))
314 opt +="P";
316 }
317
318 // set/reset the exclusion zone CheckBox
319 if (opt.Contains("L") || opt.Contains("C")) {
323 } else {
326 }
327
328 SetDrawOption(opt);
329 if (gPad && gPad->GetVirtCanvas())
330 gPad->GetVirtCanvas()->SetCursor(kPointer);
331 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
332}
333
334//______________________________________________________________________________
335
337{
338 // Slot for setting markers as visible/invisible.
339
340 if (fAvoidSignal) return;
342 t.ToUpper();
343
344 // showing the marker:
345 if (on) {
346 if (!t.Contains("P")) t+="P";
348 } else {
349 // remove the marker option P
350 while (t.Contains("P")) t.Remove(t.First("P"),1);
352 }
353 SetDrawOption(t);
354}
355
356//______________________________________________________________________________
357
359{
360 // Slot connected to the graph line width.
361
362 if (fAvoidSignal) return;
364 Int_t lineWidth = TMath::Abs(fGraph->GetLineWidth()%100);
365 Int_t side = 1;
366 if (fExSide->GetState() == kButtonDown) side = -1;
367 fGraph->SetLineWidth(side*(100*width+lineWidth));
368 Update();
369}
370
@ 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:375
@ kPointer
Definition GuiTypes.h:375
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:92
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
include TDocParser_001 C image html pict1_TDocParser_001 png width
@ 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
#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:398
virtual EButtonState GetState() const
Definition TGButton.h:112
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set check button state.
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...
virtual void SetEnabled(Bool_t on=kTRUE)
Set state of combo box. If kTRUE=enabled, kFALSE=disabled.
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1102
virtual void ChangeOptions(UInt_t options)
Change composite frame options. Options is an OR of the EFrameTypes.
Definition TGFrame.cxx:1028
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition TGFrame.cxx:694
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:215
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition TGFrame.cxx:590
Handle_t GetId() const
Definition TGObject.h:47
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set radio button state.
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:82
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.
Bool_t fInit
Definition TGedFrame.h:54
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:57
virtual void SetModel(TObject *obj)
TGLayoutHints * fShape1lh
virtual void DoMarkerOnOff(Bool_t on)
TGRadioButton * fShape0
virtual ~TGraphEditor()
virtual void DoShape()
TGraph * fGraph
virtual void DoGraphLineWidth()
TGRadioButton * fShape
TGCheckButton * fMarkerOnOff
virtual void ConnectSignals2Slots()
TGButtonGroup * fgr
virtual void DoTitle(const char *text)
TGRadioButton * fShape2
TGCheckButton * fExSide
TGraphEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
TGRadioButton * fShape3
TGLineWidthComboBox * fWidthCombo
TGRadioButton * fShape1
TGTextEntry * fTitle
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:2339
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:343
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:445
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:136
Ssiz_t Length() const
Definition TString.h:410
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition TString.h:682
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:519
void ToUpper()
Change string to upper case.
Definition TString.cxx:1158
TString & Remove(Ssiz_t pos)
Definition TString.h:673
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:624
TText * text
Short_t Abs(Short_t d)
Definition TMathBase.h:120
auto * l
Definition textangle.C:4