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);
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");
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
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));
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();
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")) {
177 fDrawShape='C';
178 } else if (opt.Contains("L")) {
180 fDrawShape='L';
181 } else if (opt.Contains("B")){
183 fDrawShape='B';
184 } else if (opt.Contains("F")){
186 fDrawShape='F';
187 } else {
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";
199 } else if (opt.Contains("P")) {
202
203 // Exclusion zone parameters
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;
220 Update();
221}
222
223//______________________________________________________________________________
224
226{
227 // Slot connected to the draw options.
228
229 if (fAvoidSignal) return;
230 TString opt;
232 opt = fGraph->GetDrawOption();
233 else
234 opt = GetDrawOption();
235
236 opt.ToUpper();
237 Int_t s = 0;
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 = ' ';
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"))
303 else
305 if (opt=="A" || opt=="AP" || opt=="PA" || opt == "P") {
306 if (!opt.Contains("P"))
307 opt +="P";
309 }
310
311 // set/reset the exclusion zone CheckBox
312 if (opt.Contains("L") || opt.Contains("C")) {
316 } else {
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";
341 } else {
342 // remove the marker option P
343 while (t.Contains("P")) t.Remove(t.First("P"),1);
345 }
346 SetDrawOption(t);
347}
348
349//______________________________________________________________________________
350
352{
353 // Slot connected to the graph line width.
354
355 if (fAvoidSignal) return;
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
@ 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
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
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
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:37
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:45
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:439
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:289
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
void ChangeOptions(UInt_t options) override
Change composite frame options. Options is an OR of the EFrameTypes.
Definition TGFrame.cxx:1035
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition TGFrame.cxx:701
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:193
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: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()
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:2345
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
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:441
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:543
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:865
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:702
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:693
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:640
TLine l
Definition textangle.C:4