Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPieEditor.cxx
Go to the documentation of this file.
1// @(#)root/ged:$Id$
2// Author: Guido Volpi 12/10/2007
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 TPieEditor
14 \ingroup ged
15
16Implements GUI for pie-chart attributes.
17
18'Title': set the title of the graph
19
20*/
21
22
23#include "TGedEditor.h"
24#include "TGComboBox.h"
25#include "TGButtonGroup.h"
26#include "TPieEditor.h"
27#include "TGTextEntry.h"
28#include "TGNumberEntry.h"
29#include "TPie.h"
30#include "TVirtualPad.h"
31#include "TGColorSelect.h"
32#include "TColor.h"
33#include "TBox.h"
34#include "TPaveLabel.h"
35#include "TVirtualX.h"
36#include "snprintf.h"
37
39
40enum EPieWid {
41 kPie = 0,
54};
55
56////////////////////////////////////////////////////////////////////////////////
57/// Constructor of graph editor.
58
60 Int_t height, UInt_t options, Pixel_t back)
61 : TGedFrame(p, width, height, options | kVerticalFrame, back)
62{
63 fPie = 0;
64 // TextEntry to change the title
65 MakeTitle("Pie Chart");
66
67 fTitle = new TGTextEntry(this, new TGTextBuffer(50), kPIE_TITLE);
69 fTitle->SetToolTipText("Enter the pie title string");
70 // better take kLHintsLeft and Right - Right is not working at the moment
71 AddFrame(fTitle, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
72
73 // Radio Buttons to change the draw options of the graph
74 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kVerticalFrame);
75 fgr = new TGButtonGroup(f2,3,1,3,5,"Label direction");
77 fLblDirH = new TGRadioButton(fgr,"Horizontal",kPIE_HOR); // no draw option
78 fLblDirH->SetToolTipText("Draw horizontal labels");
79 fLblDirR = new TGRadioButton(fgr,"Radial",kPIE_RAD); // option C
80 fLblDirR->SetToolTipText("Draw labels radially");
81 fLblDirT = new TGRadioButton(fgr,"Tangential",kPIE_TAN); // option L
82 fLblDirT->SetToolTipText("Draw labels tangential to the piechart");
83
85 fgr->Show();
87 f2->AddFrame(fgr, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
88
89 // CheckBox to activate/deactivate the drawing of the Marker
90 fOutlineOnOff = new TGCheckButton(f2,"Outline",kPIE_OUTLINE);
91 fOutlineOnOff->SetToolTipText("Draw a line to mark the pie");
92 f2->AddFrame(fOutlineOnOff, new TGLayoutHints(kLHintsTop, 5, 1, 0, 3));
93 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
94
95 // Exclusion zone parameters
96 MakeTitle("3D options");
97 TGCompositeFrame *f3 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
98 AddFrame(f3, new TGLayoutHints(kLHintsTop, 1, 1, 5, 0));
99
100 fIs3D = new TGCheckButton(f3,"3D",kPIE_3D);
101 fIs3D->SetToolTipText("Draw a 3D charts");
102 f3->AddFrame(fIs3D, new TGLayoutHints(kLHintsTop, 5, 1, 0, 0));
103
105 //f3DAngle->SetToolTipText("3D angle: 0-90")
106 f3DAngle->Resize(50, 20);
107 f3->AddFrame(f3DAngle, new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
108 f3DAngle->Associate(f3);
109
111 //f3DHeight->SetToolTipText("3D thick")
112 f3DHeight->Resize(50, 20);
113 f3->AddFrame(f3DHeight, new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
114 f3DHeight->Associate(f3);
115
116 MakeTitle("Text");
117 TGCompositeFrame *f4 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
119 f4->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
120 fColorSelect->Associate(this);
122 f4->AddFrame(fSizeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
123 fSizeCombo->Resize(91, 20);
124 fSizeCombo->Associate(this);
125 AddFrame(f4, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
127 fTypeCombo->Resize(137, 20);
128 AddFrame(fTypeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
129}
130
131
132////////////////////////////////////////////////////////////////////////////////
133/// Destructor of pie editor.
134
136{
137}
138
139
140////////////////////////////////////////////////////////////////////////////////
141/// Connect signals to slots.
142
144{
145 fTitle->Connect("TextChanged(const char *)","TPieEditor",this,"DoTitle(const char *)");
146 fgr->Connect("Clicked(Int_t)","TPieEditor",this,"DoShape()");
147 fOutlineOnOff->Connect("Toggled(Bool_t)","TPieEditor",this,"DoMarkerOnOff(Bool_t)");
148 f3DAngle->Connect("ValueSet(Long_t)", "TPieEditor", this, "DoChange3DAngle()");
149 f3DHeight->Connect("ValueSet(Long_t)", "TPieEditor", this, "DoChange3DAngle()");
150 fIs3D->Connect("Clicked()","TPieEditor",this,"DoGraphLineWidth()");
151
152 // text attributes connection
153 fTypeCombo->Connect("Selected(Int_t)","TPieEditor",this,"DoTextChange()");
154 fSizeCombo->Connect("Selected(Int_t)","TPieEditor",this,"DoTextChange()");
155 fColorSelect->Connect("ColorSelected(Pixel_t)","TPieEditor",this,"DoTextChange()");
156
157 fInit = kFALSE; // connect the slots to the signals only once
158}
159
160
161////////////////////////////////////////////////////////////////////////////////
162/// Exclude TAttTextEditor from this interface.
163
165{
166 TGedEditor *gedEditor = GetGedEditor();
169}
170
171
172////////////////////////////////////////////////////////////////////////////////
173/// Pick up the used values of graph attributes.
174
176{
177 fPie = (TPie *)obj;
179
180 // set the Title TextEntry
181 const char *text = fPie->GetTitle();
183
184 TString soption = GetDrawOption();
185
186 // For the label orientation there are 3 possibilities:
187 // 0: horizontal
188 // 1: radial
189 // 2: tangent
190 Int_t lblor(0);
191
192 // Parse the options
193 Int_t idx;
194 // Paint the TPie in an existing canvas
195 if ( (idx=soption.Index("same"))>=0 ) {
196 // optionSame = kTRUE;
197 soption.Remove(idx,4);
198 }
199
200 if ( (idx=soption.Index("nol"))>=0 ) {
202 soption.Remove(idx,3);
203 }
204 else {
206 }
207
208 // check if is active the pseudo-3d
209 if ( (idx=soption.Index("3d"))>=0 ) {
213 soption.Remove(idx,2);
214 } else {
216 }
217
218 // seek if have to draw the labels around the pie chart
219 if ( (idx=soption.Index("t"))>=0 ) {
220 lblor = 2;
221 soption.Remove(idx,1);
222 }
223
224 // Seek if have to paint the labels along the radii
225 if ( (idx=soption.Index("r"))>=0 ) {
226 lblor = 1;
227 soption.Remove(idx,1);
228 }
229
230 switch(lblor) {
231 case 0:
233 break;
234 case 1:
236 break;
237 case 2:
239 break;
240 }
241
242 // set text attributes
244
248
249 Float_t s = fPie->GetTextSize();
250 Float_t dy;
251
252 if (obj->InheritsFrom(TPaveLabel::Class())) {
253 TBox *pl = (TBox*)obj;
254 dy = s * (pl->GetY2() - pl->GetY1());
255 }
256 else
257 dy = s * (fGedEditor->GetPad()->GetY2() - fGedEditor->GetPad()->GetY1());
258
260 if (size > 50) size = 50;
261 if (size < 0) size = 0;
263
266}
267
268
269////////////////////////////////////////////////////////////////////////////////
270/// Slot for setting the graph title.
271
272void TPieEditor::DoTitle(const char *text)
273{
274 if (fAvoidSignal) return;
276 Update();
277}
278
279
280////////////////////////////////////////////////////////////////////////////////
281/// Slot connected to the draw options.
282
284{
285 if (fAvoidSignal) return;
286
287 TString opt = GetDrawOption();
288
289 if (fLblDirH->GetState()==kButtonDown) {
290 if (opt.Contains("t")) opt.Remove(opt.First("t"),1);
291 if (opt.Contains("r")) opt.Remove(opt.First("r"),1);
292 }
293 else if (fLblDirR->GetState()==kButtonDown) {
294 if (opt.Contains("t")) opt.Remove(opt.First("t"),1);
295 if (!opt.Contains("r")) opt += "r";
296 }
297 else if (fLblDirT->GetState()==kButtonDown) {
298 if (!opt.Contains("t")) opt += "t";
299 if (opt.Contains("r")) opt.Remove(opt.First("r"),1);
300 }
301
302 SetDrawOption(opt);
303 if (gPad && gPad->GetVirtCanvas()) gPad->GetVirtCanvas()->SetCursor(kPointer);
304 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
305}
306
307
308////////////////////////////////////////////////////////////////////////////////
309/// Slot for setting markers as visible/invisible.
310
312{
313 if (fAvoidSignal) return;
315
316 if (t.Contains("nol") && fOutlineOnOff->GetState() == kButtonDown) {
317 t.Remove(t.First("nol"),3);
318 }
319 else if (!t.Contains("nol") && fOutlineOnOff->GetState() == kButtonUp) {
320 t += "nol";
321 }
322
323 SetDrawOption(t);
324}
325
326
327////////////////////////////////////////////////////////////////////////////////
328/// Slot for setting the 3D angle
329
331{
332 if (fAvoidSignal) return;
333
334 fPie->SetAngle3D(static_cast<Int_t>(f3DAngle->GetNumber()));
336
337 Update();
338
339}
340
341
342////////////////////////////////////////////////////////////////////////////////
343/// Slot connected to the graph line width.
344
346{
347 if (fAvoidSignal) return;
348
349 TString opt = GetDrawOption();
350 if (!opt.Contains("3d") && fIs3D->IsDown())
351 opt += "3d";
352 else if (opt.Contains("3d") && !fIs3D->IsDown())
353 opt.Remove(opt.First("3d"),2);
354
355 SetDrawOption(opt);
356
357 Update();
358}
359
360
361
362////////////////////////////////////////////////////////////////////////////////
363/// Change text.
364
366{
367 if (fAvoidSignal) return;
368
369 // font color
371
372 // font type
373 Int_t fontPrec = fPie->GetTextFont()%10;
374 Int_t fontType = fTypeCombo->GetSelected();
375 fPie->SetTextFont(fontType*10+fontPrec);
376
377 // font size
378 TVirtualPad* pad = fGedEditor->GetPad();
379
381
382 Float_t dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY((Int_t)val);
383 Float_t textSize;
384
386 TBox *pl = (TBox*)fGedEditor->GetModel();
387 textSize = dy/(pl->GetY2() - pl->GetY1());
388 }
389 else
390 textSize = dy/(pad->GetY2() - pad->GetY1());
391
392 fPie->SetTextSize(textSize);
393
394 Update();
395
396}
397
398
399////////////////////////////////////////////////////////////////////////////////
400/// Create text size combo box.
401
403{
404 char a[100];
405 TGComboBox *c = new TGComboBox(parent, id);
406
407 c->AddEntry("Default", 0);
408 for (int i = 1; i <= 50; i++) {
409 snprintf(a, 99, "%d", i);
410 c->AddEntry(a, i);
411 }
412
413 return c;
414}
@ kPointer
Definition GuiTypes.h:375
@ kChildFrame
Definition GuiTypes.h:379
@ kVerticalFrame
Definition GuiTypes.h:381
@ kFitWidth
Definition GuiTypes.h:386
@ kHorizontalFrame
Definition GuiTypes.h:382
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
short Color_t
Definition RtypesCore.h:92
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
@ kFONT_STYLE
@ kFONT_SIZE
@ kButtonDown
Definition TGButton.h:54
@ kButtonUp
Definition TGButton.h:53
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsTop
Definition TGLayout.h:27
winID h TVirtualViewer3D TVirtualGLPainter p
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
EPieWid
@ kPIE_3DTHICKNESS
@ kPie
@ kPIE_RAD
@ kPIE_3D
@ kPIE_FILL
@ kPIE_TAN
@ kFONT_STYLE
@ kFONT_COLOR
@ kFONT_SIZE
@ kPIE_TITLE
@ kPIE_HOR
@ kPIE_OUTLINE
@ kPIE_3DANGLE
#define gPad
#define gVirtualX
Definition TVirtualX.h:338
#define snprintf
Definition civetweb.c:1540
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:36
virtual Font_t GetTextFont() const
Return the text font.
Definition TAttText.h:35
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:34
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:44
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:46
static TClass * Class()
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:47
Create a Box.
Definition TBox.h:22
Double_t GetY1() const
Definition TBox.h:53
Double_t GetY2() const
Definition TBox.h:54
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition TColor.cxx:2082
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1823
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 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
Bool_t IsDown() const override
Definition TGButton.h:311
void SetState(EButtonState state, Bool_t emit=kFALSE) override
Set check button state.
Like a checkbutton but instead of the check mark there is color area with a little down arrow.
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
Pixel_t GetColor() const
A combobox (also known as a drop down listbox) allows the selection of one item out of a list of item...
Definition TGComboBox.h:47
virtual Int_t GetSelected() const
Definition TGComboBox.h:114
virtual TGLBEntry * GetSelectedEntry() const
Definition TGComboBox.h:115
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...
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
The TGFontTypeComboBox is user callable and it creates a combobox for selecting the font.
Definition TGComboBox.h:178
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:191
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
TGNumberEntry is a number entry input widget with up/down buttons.
void Associate(const TGWindow *w) override
Make w the window that will receive the generated messages.
virtual Double_t GetNumber() const
virtual void SetNumber(Double_t val, Bool_t emit=kTRUE)
@ kNEANonNegative
Non-negative number.
@ kNESReal
Real number.
@ kNESInteger
Style of number entry field.
@ kNELLimitMinMax
Both lower and upper limits.
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
virtual TVirtualPad * GetPad() const
Definition TGedEditor.h:78
virtual TObject * GetModel() const
Definition TGedEditor.h:79
void ExcludeClassEditor(TClass *cl, Bool_t recurse=kFALSE)
Exclude editor for class cl from current construction.
Base frame for implementing GUI - a service class.
Definition TGedFrame.h:27
virtual Option_t * GetDrawOption() const
Get draw options of the selected object.
Definition TGedFrame.cxx:80
virtual void ActivateBaseClassEditors(TClass *cl)
Provide list of editors for base-classes.
TGedEditor * fGedEditor
manager of this frame
Definition TGedFrame.h:48
virtual void SetDrawOption(Option_t *option="")
Set drawing option for object.
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
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition TGedFrame.cxx:72
TGedEditor * GetGedEditor()
Definition TGedFrame.h:71
Bool_t fAvoidSignal
flag for executing slots
Definition TGedFrame.h:50
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
Mother of all ROOT objects.
Definition TObject.h:41
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:483
static TClass * Class()
Implements GUI for pie-chart attributes.
Definition TPieEditor.h:28
TGRadioButton * fLblDirH
Draw slice's labels horizontal.
Definition TPieEditor.h:36
TGNumberEntry * f3DAngle
set the pseudo 3D angle
Definition TPieEditor.h:43
virtual void DoTextChange()
Change text.
TPie * fPie
Pie object.
Definition TPieEditor.h:34
virtual void ActivateBaseClassEditors(TClass *)
Exclude TAttTextEditor from this interface.
TGColorSelect * fColorSelect
font color selector
Definition TPieEditor.h:44
virtual ~TPieEditor()
Destructor of pie editor.
virtual void ConnectSignals2Slots()
Connect signals to slots.
virtual void DoChange3DAngle()
Slot for setting the 3D angle.
TGNumberEntry * f3DHeight
set the 3D tickness
Definition TPieEditor.h:42
TGCheckButton * fIs3D
set if is enabled the pseudo-3d mode
Definition TPieEditor.h:41
virtual void SetModel(TObject *)
Pick up the used values of graph attributes.
virtual void DoMarkerOnOff(Bool_t on)
Slot for setting markers as visible/invisible.
virtual void DoGraphLineWidth()
Slot connected to the graph line width.
TGLayoutHints * fShape1lh
layout-hints for fShape1
Definition TPieEditor.h:39
static TGComboBox * BuildFontSizeComboBox(TGFrame *, Int_t)
Create text size combo box.
TGRadioButton * fLblDirT
Draw slice's labels tangential to the piechart's circle.
Definition TPieEditor.h:38
TGRadioButton * fLblDirR
Draw slice's labels radial to the piechart.
Definition TPieEditor.h:37
TGComboBox * fSizeCombo
font size
Definition TPieEditor.h:46
TGButtonGroup * fgr
Group the Radiobuttons:
Definition TPieEditor.h:35
TGTextEntry * fTitle
Contains the title of the graph.
Definition TPieEditor.h:32
TGCheckButton * fOutlineOnOff
set piechart outline visible/unvisible
Definition TPieEditor.h:40
TGFontTypeComboBox * fTypeCombo
font style
Definition TPieEditor.h:45
TPieEditor(const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of graph editor.
virtual void DoShape()
Slot connected to the draw options.
virtual void DoTitle(const char *text)
Slot for setting the graph title.
Draw a Pie Chart,.
Definition TPie.h:23
void SetAngle3D(Float_t val=30.)
Set the value of for the pseudo 3D view angle, in degree.
Definition TPie.cxx:1151
Double_t GetHeight()
Definition TPie.h:72
void SetHeight(Double_t val=.08)
Set the height, in pixel, for the piechart if is drawn using the pseudo-3d mode.
Definition TPie.cxx:1271
Float_t GetAngle3D()
Definition TPie.h:61
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
Int_t Atoi() const
Return integer value of string.
Definition TString.cxx:1966
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:531
TString & Remove(Ssiz_t pos)
Definition TString.h:685
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:636
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:651
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual Int_t YtoPixel(Double_t y) const =0
virtual Double_t GetY1() const =0
virtual Double_t AbsPixeltoY(Int_t py)=0
virtual Double_t GetY2() const =0