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
39
41 kShape = 0,
51};
52
53//______________________________________________________________________________
54
56 Int_t height, UInt_t options, Pixel_t back)
57 : TGedFrame(p, width, height, options | kVerticalFrame, back)
58{
59 // Constructor of graph editor.
60
61 fGraph = 0;
62 // TextEntry to change the title
63 MakeTitle("Title");
64
65 fTitlePrec = 2;
66 fTitle = new TGTextEntry(this, new TGTextBuffer(50), kGRAPH_TITLE);
68 fTitle->SetToolTipText("Enter the graph title string");
69 // better take kLHintsLeft and Right - Right is not working at the moment
70 AddFrame(fTitle, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
71
72 // Radio Buttons to change the draw options of the graph
73 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kVerticalFrame);
74 fgr = new TGButtonGroup(f2,3,1,3,5,"Shape");
76 fShape = new TGRadioButton(fgr,"No Line",kSHAPE_NOLINE); // no draw option
77 fShape->SetToolTipText("The points are not connected by a line");
78 fShape0 = new TGRadioButton(fgr,"Smooth Line ",kSHAPE_SMOOTH); // option C
79 fShape0->SetToolTipText("Draw a smooth graph curve");
80 fShape1 = new TGRadioButton(fgr,"Simple Line ",kSHAPE_SIMPLE); // option L
81 fShape1->SetToolTipText("Draw a simple poly-line between the graph points");
82 fShape2 = new TGRadioButton(fgr,"Bar Chart",kSHAPE_BAR); // option B
83 fShape2->SetToolTipText("Draw a bar chart at each graph point");
84 fShape3 = new TGRadioButton(fgr,"Fill area",kSHAPE_FILL); // option F
85 fShape3->SetToolTipText("A fill area is drawn");
86
88 fgr->Show();
90 f2->AddFrame(fgr, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
91
92 // CheckBox to activate/deactivate the drawing of the Marker
93 fMarkerOnOff = new TGCheckButton(f2,"Show Marker",kMARKER_ONOFF);
94 fMarkerOnOff->SetToolTipText("Make Marker visible/invisible");
95 f2->AddFrame(fMarkerOnOff, new TGLayoutHints(kLHintsTop, 5, 1, 0, 3));
96 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
97
98 // Exclusion zone parameters
99 MakeTitle("Exclusion Zone");
100 TGCompositeFrame *f3 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
101 AddFrame(f3, new TGLayoutHints(kLHintsTop, 1, 1, 5, 0));
102
104 fExSide->SetToolTipText("Zone is drawing side");
105 f3->AddFrame(fExSide, new TGLayoutHints(kLHintsTop, 5, 1, 0, 0));
106
110 fWidthCombo->Resize(91, 20);
111 f3->AddFrame(fWidthCombo, new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
113}
114
115//______________________________________________________________________________
116
118{
119 // Destructor of graph editor.
120
121 // children of TGButonGroup are not deleted
122 delete fShape;
123 delete fShape0;
124 delete fShape1;
125 delete fShape2;
126 delete fShape3;
127 delete fShape1lh;
128}
129
130//______________________________________________________________________________
131
133{
134 // Connect signals to slots.
135
136 fTitle->Connect("TextChanged(const char *)","TGraphEditor",this,"DoTitle(const char *)");
137 fgr->Connect("Clicked(Int_t)","TGraphEditor",this,"DoShape()");
138 fMarkerOnOff->Connect("Toggled(Bool_t)","TGraphEditor",this,"DoMarkerOnOff(Bool_t)");
139 fWidthCombo->Connect("Selected(Int_t)", "TGraphEditor", this, "DoGraphLineWidth()");
140 fExSide->Connect("Clicked()","TGraphEditor",this,"DoGraphLineWidth()");
141
142 fInit = kFALSE; // connect the slots to the signals only once
143}
144
145//______________________________________________________________________________
146
148{
149 // Pick up the used values of graph attributes.
150
151 fGraph = (TGraph *)obj;
153
154 // set the Title TextEntry
155 const char *text = fGraph->GetTitle();
157
158 TString opt = GetDrawOption();
159 opt.ToUpper();
160 Int_t i=0;
161 Bool_t make=kFALSE;
162 // Remove characters which appear twice in the draw option
163 TString dum = opt;
164 Int_t l = opt.Length()-1;
165 while (i < l) {
166 dum.Remove(dum.First(opt[i]),1);
167 if (dum.Contains(opt[i])){
168 opt.Remove(opt.First(opt[i]),1);
169 l--;
170 i--;
171 make=kTRUE;
172 }
173 i++;
174 }
175 // initialise the RadioButton group which shows the drawoption
176 if (opt.Contains("C")) {
178 fDrawShape='C';
179 } else if (opt.Contains("L")) {
181 fDrawShape='L';
182 } else if (opt.Contains("B")){
184 fDrawShape='B';
185 } else if (opt.Contains("F")){
187 fDrawShape='F';
188 } else {
190 fDrawShape=' ';
191 }
192 if (make) SetDrawOption(opt);
193 // if the draw option is A, P, AP the P option cannot be removed,
194 // we deactivate the CheckBox
195 // also initialising the MarkerOnOff checkbutton (== P option)
196 if (opt=="A" || opt=="AP" || opt=="PA" || opt == "P") {
197 if (!opt.Contains("P"))
198 opt +="P";
200 } else if (opt.Contains("P")) {
203
204 // Exclusion zone parameters
208
211}
212
213//______________________________________________________________________________
214
216{
217 // Slot for setting the graph title.
218
219 if (fAvoidSignal) return;
221 Update();
222}
223
224//______________________________________________________________________________
225
227{
228 // Slot connected to the draw options.
229
230 if (fAvoidSignal) return;
231 TString opt;
233 opt = fGraph->GetDrawOption();
234 else
235 opt = GetDrawOption();
236
237 opt.ToUpper();
238 Int_t s = 0;
240 else if (fShape0->GetState() == kButtonDown) s = kSHAPE_SMOOTH;
241 else if (fShape1->GetState() == kButtonDown) s = kSHAPE_SIMPLE;
242 else if (fShape2->GetState() == kButtonDown) s = kSHAPE_BAR;
243 else s = kSHAPE_FILL;
244
245 switch (s) {
246
247 // change draw option to No Line:
248 case kSHAPE_NOLINE: {
249 if (opt.Contains(fDrawShape))
250 opt.Remove(opt.First(fDrawShape),1);
251 fDrawShape = ' ';
253 break;
254 }
255
256 // change draw option to Smooth Line (C)
257 case kSHAPE_SMOOTH: {
258 if (fDrawShape == ' ')
259 opt +="C";
260 else if (opt.Contains(fDrawShape))
261 opt.Replace(opt.First(fDrawShape),1,'C');
262 fDrawShape = 'C';
263 break;
264 }
265
266 // change draw option to Simple Line (L)
267 case kSHAPE_SIMPLE: {
268 if (fDrawShape == ' ')
269 opt +="L";
270 else if (opt.Contains(fDrawShape))
271 opt.Replace(opt.First(fDrawShape),1,'L');
272 fDrawShape='L';
273 break;
274 }
275
276 // change draw option to Bar Chart (B)
277 case kSHAPE_BAR: {
278 if (fDrawShape == ' ')
279 opt +="B";
280 else if (opt.Contains(fDrawShape))
281 opt.Replace(opt.First(fDrawShape),1,'B');
282 fDrawShape='B';
283 break;
284 }
285
286 // change draw option to Fill Area (F)
287 case kSHAPE_FILL: {
288 if (fDrawShape == ' ')
289 opt +="F";
290 else if (opt.Contains(fDrawShape))
291 opt.Replace(opt.First(fDrawShape),1,'F');
292 fDrawShape='F';
293 break;
294 }
295 }
296
297 if (gPad && gPad->GetVirtCanvas())
298 gPad->GetVirtCanvas()->SetCursor(kWatch);
299 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kWatch));
300
301 // set/reset the Marker CheckBox
302 if (opt.Contains("P"))
304 else
306 if (opt=="A" || opt=="AP" || opt=="PA" || opt == "P") {
307 if (!opt.Contains("P"))
308 opt +="P";
310 }
311
312 // set/reset the exclusion zone CheckBox
313 if (opt.Contains("L") || opt.Contains("C")) {
317 } else {
320 }
321
322 SetDrawOption(opt);
323 if (gPad && gPad->GetVirtCanvas())
324 gPad->GetVirtCanvas()->SetCursor(kPointer);
325 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
326}
327
328//______________________________________________________________________________
329
331{
332 // Slot for setting markers as visible/invisible.
333
334 if (fAvoidSignal) return;
336 t.ToUpper();
337
338 // showing the marker:
339 if (on) {
340 if (!t.Contains("P")) t+="P";
342 } else {
343 // remove the marker option P
344 while (t.Contains("P")) t.Remove(t.First("P"),1);
346 }
347 SetDrawOption(t);
348}
349
350//______________________________________________________________________________
351
353{
354 // Slot connected to the graph line width.
355
356 if (fAvoidSignal) return;
358 Int_t lineWidth = TMath::Abs(fGraph->GetLineWidth()%100);
359 Int_t side = 1;
360 if (fExSide->GetState() == kButtonDown) side = -1;
361 fGraph->SetLineWidth(side*(100*width+lineWidth));
362 Update();
363}
364
@ kWatch
Definition GuiTypes.h:375
@ kPointer
Definition GuiTypes.h:375
@ 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
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
@ 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
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char text
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:337
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
Organizes TGButton widgets in a group.
virtual void SetLayoutHints(TGLayoutHints *l, TGButton *button=nullptr)
Set layout hints for the specified button or if button=0 for all buttons.
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 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:445
virtual EButtonState GetState() const
Definition TGButton.h:112
Selects different options.
Definition TGButton.h:264
void SetState(EButtonState state, Bool_t emit=kFALSE) override
Set check button state.
virtual Int_t GetSelected() const
Definition TGComboBox.h:114
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.
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:287
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
void ChangeOptions(UInt_t options) override
Change composite frame options. Options is an OR of the EFrameTypes.
Definition TGFrame.cxx:1043
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition TGFrame.cxx:709
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:191
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
void SetState(EButtonState state, Bool_t emit=kFALSE) override
Set radio button state.
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
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:72
ROOT GUI Window base class.
Definition TGWindow.h:23
Base frame for implementing GUI - a service class.
Definition TGedFrame.h:27
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:95
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:72
Option_t * GetDrawOption() const override
Get draw options of the selected object.
Definition TGedFrame.cxx:80
Bool_t fAvoidSignal
flag for executing slots
Definition TGedFrame.h:50
Implements GUI for graph attributes.
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()
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
void SetTitle(const char *title="") override
Change (i.e.
Definition TGraph.cxx:2374
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
Mother of all ROOT objects.
Definition TObject.h:41
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition TObject.cxx:423
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
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:869
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition TString.h:694
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:538
void ToUpper()
Change string to upper case.
Definition TString.cxx:1195
TString & Remove(Ssiz_t pos)
Definition TString.h:685
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123
TLine l
Definition textangle.C:4