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
38
54
55////////////////////////////////////////////////////////////////////////////////
56/// Constructor of graph editor.
57
59 Int_t height, UInt_t options, Pixel_t back)
60 : TGedFrame(p, width, height, options | kVerticalFrame, back)
61{
62 fPie = 0;
63 // TextEntry to change the title
64 MakeTitle("Pie Chart");
65
66 fTitle = new TGTextEntry(this, new TGTextBuffer(50), kPIE_TITLE);
67 fTitle->Resize(135, fTitle->GetDefaultHeight());
68 fTitle->SetToolTipText("Enter the pie 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,"Label direction");
75 fgr->SetRadioButtonExclusive(kTRUE);
76 fLblDirH = new TGRadioButton(fgr,"Horizontal",kPIE_HOR); // no draw option
77 fLblDirH->SetToolTipText("Draw horizontal labels");
78 fLblDirR = new TGRadioButton(fgr,"Radial",kPIE_RAD); // option C
79 fLblDirR->SetToolTipText("Draw labels radially");
80 fLblDirT = new TGRadioButton(fgr,"Tangential",kPIE_TAN); // option L
81 fLblDirT->SetToolTipText("Draw labels tangential to the piechart");
82
83 fgr->SetLayoutHints(fShape1lh=new TGLayoutHints(kLHintsLeft, 0,3,0,0), fLblDirH);
84 fgr->Show();
86 f2->AddFrame(fgr, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
87
88 // CheckBox to activate/deactivate the drawing of the Marker
89 fOutlineOnOff = new TGCheckButton(f2,"Outline",kPIE_OUTLINE);
90 fOutlineOnOff->SetToolTipText("Draw a line to mark the pie");
91 f2->AddFrame(fOutlineOnOff, new TGLayoutHints(kLHintsTop, 5, 1, 0, 3));
92 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
93
94 // Exclusion zone parameters
95 MakeTitle("3D options");
96 TGCompositeFrame *f3 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
97 AddFrame(f3, new TGLayoutHints(kLHintsTop, 1, 1, 5, 0));
98
99 fIs3D = new TGCheckButton(f3,"3D",kPIE_3D);
100 fIs3D->SetToolTipText("Draw a 3D charts");
101 f3->AddFrame(fIs3D, new TGLayoutHints(kLHintsTop, 5, 1, 0, 0));
102
104 //f3DAngle->SetToolTipText("3D angle: 0-90")
105 f3DAngle->Resize(50, 20);
106 f3->AddFrame(f3DAngle, new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
107 f3DAngle->Associate(f3);
108
110 //f3DHeight->SetToolTipText("3D thick")
111 f3DHeight->Resize(50, 20);
112 f3->AddFrame(f3DHeight, new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
113 f3DHeight->Associate(f3);
114
115 MakeTitle("Text");
116 TGCompositeFrame *f4 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
118 f4->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
119 fColorSelect->Associate(this);
121 f4->AddFrame(fSizeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
122 fSizeCombo->Resize(91, 20);
123 fSizeCombo->Associate(this);
124 AddFrame(f4, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
126 fTypeCombo->Resize(137, 20);
127 AddFrame(fTypeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
128}
129
130
131////////////////////////////////////////////////////////////////////////////////
132/// Destructor of pie editor.
133
137
138
139////////////////////////////////////////////////////////////////////////////////
140/// Connect signals to slots.
141
143{
144 fTitle->Connect("TextChanged(const char *)","TPieEditor",this,"DoTitle(const char *)");
145 fgr->Connect("Clicked(Int_t)","TPieEditor",this,"DoShape()");
146 fOutlineOnOff->Connect("Toggled(Bool_t)","TPieEditor",this,"DoMarkerOnOff(Bool_t)");
147 f3DAngle->Connect("ValueSet(Long_t)", "TPieEditor", this, "DoChange3DAngle()");
148 f3DHeight->Connect("ValueSet(Long_t)", "TPieEditor", this, "DoChange3DAngle()");
149 fIs3D->Connect("Clicked()","TPieEditor",this,"DoGraphLineWidth()");
150
151 // text attributes connection
152 fTypeCombo->Connect("Selected(Int_t)","TPieEditor",this,"DoTextChange()");
153 fSizeCombo->Connect("Selected(Int_t)","TPieEditor",this,"DoTextChange()");
154 fColorSelect->Connect("ColorSelected(Pixel_t)","TPieEditor",this,"DoTextChange()");
155
156 fInit = kFALSE; // connect the slots to the signals only once
157}
158
159
160////////////////////////////////////////////////////////////////////////////////
161/// Exclude TAttTextEditor from this interface.
162
169
170
171////////////////////////////////////////////////////////////////////////////////
172/// Pick up the used values of graph attributes.
173
175{
176 fPie = (TPie *)obj;
178
179 // set the Title TextEntry
180 const char *text = fPie->GetTitle();
181 fTitle->SetText(text);
182
183 TString soption = GetDrawOption();
184
185 // For the label orientation there are 3 possibilities:
186 // 0: horizontal
187 // 1: radial
188 // 2: tangent
189 Int_t lblor(0);
190
191 // Parse the options
192 Int_t idx;
193 // Paint the TPie in an existing canvas
194 if ( (idx=soption.Index("same"))>=0 ) {
195 // optionSame = kTRUE;
196 soption.Remove(idx,4);
197 }
198
199 if ( (idx=soption.Index("nol"))>=0 ) {
200 fOutlineOnOff->SetState(kButtonUp,kFALSE);
201 soption.Remove(idx,3);
202 }
203 else {
205 }
206
207 // check if is active the pseudo-3d
208 if ( (idx=soption.Index("3d"))>=0 ) {
209 fIs3D->SetState(kButtonDown, kFALSE);
210 f3DAngle->SetNumber(fPie->GetAngle3D());
211 f3DHeight->SetNumber(fPie->GetHeight());
212 soption.Remove(idx,2);
213 } else {
214 fIs3D->SetState(kButtonUp, kFALSE);
215 }
216
217 // seek if have to draw the labels around the pie chart
218 if ( (idx=soption.Index("t"))>=0 ) {
219 lblor = 2;
220 soption.Remove(idx,1);
221 }
222
223 // Seek if have to paint the labels along the radii
224 if ( (idx=soption.Index("r"))>=0 ) {
225 lblor = 1;
226 soption.Remove(idx,1);
227 }
228
229 switch(lblor) {
230 case 0:
231 fLblDirH->SetState(kButtonDown,kTRUE);
232 break;
233 case 1:
234 fLblDirR->SetState(kButtonDown,kTRUE);
235 break;
236 case 2:
237 fLblDirT->SetState(kButtonDown,kTRUE);
238 break;
239 }
240
241 // set text attributes
242 fTypeCombo->Select(fPie->GetTextFont() / 10);
243
244 Color_t c = fPie->GetTextColor();
246 fColorSelect->SetColor(p, kFALSE);
247
248 Float_t s = fPie->GetTextSize();
249 Float_t dy;
250
251 if (obj->InheritsFrom(TPaveLabel::Class())) {
252 TBox *pl = (TBox*)obj;
253 dy = s * (pl->GetY2() - pl->GetY1());
254 }
255 else
256 dy = s * (fGedEditor->GetPad()->GetY2() - fGedEditor->GetPad()->GetY1());
257
258 Int_t size = fGedEditor->GetPad()->YtoPixel(0.0) - fGedEditor->GetPad()->YtoPixel(dy);
259 if (size > 50) size = 50;
260 if (size < 0) size = 0;
261 fSizeCombo->Select(size, kFALSE);
262
265}
266
267
268////////////////////////////////////////////////////////////////////////////////
269/// Slot for setting the graph title.
270
271void TPieEditor::DoTitle(const char *text)
272{
273 if (fAvoidSignal) return;
274 fPie->SetTitle(text);
275 Update();
276}
277
278
279////////////////////////////////////////////////////////////////////////////////
280/// Slot connected to the draw options.
281
283{
284 if (fAvoidSignal) return;
285
286 TString opt = GetDrawOption();
287
288 if (fLblDirH->GetState()==kButtonDown) {
289 if (opt.Contains("t")) opt.Remove(opt.First("t"),1);
290 if (opt.Contains("r")) opt.Remove(opt.First("r"),1);
291 }
292 else if (fLblDirR->GetState()==kButtonDown) {
293 if (opt.Contains("t")) opt.Remove(opt.First("t"),1);
294 if (!opt.Contains("r")) opt += "r";
295 }
296 else if (fLblDirT->GetState()==kButtonDown) {
297 if (!opt.Contains("t")) opt += "t";
298 if (opt.Contains("r")) opt.Remove(opt.First("r"),1);
299 }
300
301 SetDrawOption(opt);
302 if (gPad && gPad->GetVirtCanvas()) gPad->GetVirtCanvas()->SetCursor(kPointer);
303 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
304}
305
306
307////////////////////////////////////////////////////////////////////////////////
308/// Slot for setting markers as visible/invisible.
309
311{
312 if (fAvoidSignal) return;
314
315 if (t.Contains("nol") && fOutlineOnOff->GetState() == kButtonDown) {
316 t.Remove(t.First("nol"),3);
317 }
318 else if (!t.Contains("nol") && fOutlineOnOff->GetState() == kButtonUp) {
319 t += "nol";
320 }
321
322 SetDrawOption(t);
323}
324
325
326////////////////////////////////////////////////////////////////////////////////
327/// Slot for setting the 3D angle
328
330{
331 if (fAvoidSignal) return;
332
333 fPie->SetAngle3D(static_cast<Int_t>(f3DAngle->GetNumber()));
334 fPie->SetHeight(f3DHeight->GetNumber());
335
336 Update();
337
338}
339
340
341////////////////////////////////////////////////////////////////////////////////
342/// Slot connected to the graph line width.
343
345{
346 if (fAvoidSignal) return;
347
348 TString opt = GetDrawOption();
349 if (!opt.Contains("3d") && fIs3D->IsDown())
350 opt += "3d";
351 else if (opt.Contains("3d") && !fIs3D->IsDown())
352 opt.Remove(opt.First("3d"),2);
353
354 SetDrawOption(opt);
355
356 Update();
357}
358
359
360
361////////////////////////////////////////////////////////////////////////////////
362/// Change text.
363
365{
366 if (fAvoidSignal) return;
367
368 // font color
369 fPie->SetTextColor(TColor::GetColor(fColorSelect->GetColor()));
370
371 // font type
372 Int_t fontPrec = fPie->GetTextFont()%10;
373 Int_t fontType = fTypeCombo->GetSelected();
374 fPie->SetTextFont(fontType*10+fontPrec);
375
376 // font size
377 TVirtualPad* pad = fGedEditor->GetPad();
378
379 Float_t val = TString(fSizeCombo->GetSelectedEntry()->GetTitle()).Atoi();
380
381 Float_t dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY((Int_t)val);
382 Float_t textSize;
383
384 if (fGedEditor->GetModel()->InheritsFrom(TPaveLabel::Class())) {
385 TBox *pl = (TBox*)fGedEditor->GetModel();
386 textSize = dy/(pl->GetY2() - pl->GetY1());
387 }
388 else
389 textSize = dy/(pad->GetY2() - pad->GetY1());
390
391 fPie->SetTextSize(textSize);
392
393 Update();
394
395}
396
397
398////////////////////////////////////////////////////////////////////////////////
399/// Create text size combo box.
400
402{
403 char a[100];
404 TGComboBox *c = new TGComboBox(parent, id);
405
406 c->AddEntry("Default", 0);
407 for (int i = 1; i <= 50; i++) {
408 snprintf(a, 99, "%d", i);
409 c->AddEntry(a, i);
410 }
411
412 return c;
413}
@ kChildFrame
Definition GuiTypes.h:380
@ kVerticalFrame
Definition GuiTypes.h:382
@ kFitWidth
Definition GuiTypes.h:387
@ kHorizontalFrame
Definition GuiTypes.h:383
@ kPointer
Definition GuiTypes.h:376
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:41
#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
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
short Color_t
Color number (short).
Definition RtypesCore.h:99
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kFONT_STYLE
@ kFONT_SIZE
@ kButtonDown
Definition TGButton.h:54
@ kButtonUp
Definition TGButton.h:53
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsTop
Definition TGLayout.h:27
EPieWid
@ kPIE_3DTHICKNESS
@ kPie
@ kPIE_RAD
@ kPIE_3D
@ kPIE_FILL
@ kPIE_TAN
@ kFONT_COLOR
@ kPIE_TITLE
@ kPIE_HOR
@ kPIE_OUTLINE
@ kPIE_3DANGLE
#define gPad
#define gVirtualX
Definition TVirtualX.h:375
#define snprintf
Definition civetweb.c:1579
static TClass * Class()
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:84
static Int_t GetColor(const char *hexcolor)
static ULong_t Number2Pixel(Int_t ci)
Organizes TGButton widgets in a group.
Selects different options.
Definition TGButton.h:264
Like a checkbutton but instead of the check mark there is color area with a little down arrow.
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 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
The TGFontTypeComboBox is user callable and it creates a combobox for selecting the font.
Definition TGComboBox.h:178
TGFrame(const TGFrame &)=delete
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.
@ 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
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
void ExcludeClassEditor(TClass *cl, Bool_t recurse=kFALSE)
Exclude editor for class cl from current construction.
virtual void ActivateBaseClassEditors(TClass *cl)
Provide list of editors for base-classes.
TGedEditor * fGedEditor
manager of this frame
Definition TGedFrame.h:48
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
TGedEditor * GetGedEditor()
Definition TGedFrame.h:71
Bool_t fAvoidSignal
flag for executing slots
Definition TGedFrame.h:50
Mother of all ROOT objects.
Definition TObject.h:42
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:549
static TClass * Class()
void ActivateBaseClassEditors(TClass *) override
Exclude TAttTextEditor from this interface.
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
TGColorSelect * fColorSelect
font color selector
Definition TPieEditor.h:44
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 DoMarkerOnOff(Bool_t on)
Slot for setting markers as visible/invisible.
virtual void DoGraphLineWidth()
Slot connected to the graph line width.
void SetModel(TObject *) override
Pick up the used values of graph attributes.
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.
~TPieEditor() override
Destructor of pie editor.
Definition TPie.h:23
Basic string class.
Definition TString.h:138
Int_t Atoi() const
Return integer value of string.
Definition TString.cxx:1994
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:545
TString & Remove(Ssiz_t pos)
Definition TString.h:694
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:641
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:660
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual Double_t GetY1() const =0
virtual Double_t GetY2() const =0
virtual Double_t AbsPixeltoY(Double_t py)=0
TText * text