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//////////////////////////////////////////////////////////////////////////
14// //
15// TPieEditor //
16// //
17// Implements GUI for pie-chart attributes. //
18// //
19// Title': set the title of the graph //
20// //
21//////////////////////////////////////////////////////////////////////////
22//Begin_Html
23/*
24<img src="gif/TPieEditor.gif">
25*/
26//End_Html
27
28#include "TGedEditor.h"
29#include "TGComboBox.h"
30#include "TGButtonGroup.h"
31#include "TPieEditor.h"
32#include "TGTextEntry.h"
33#include "TGNumberEntry.h"
34#include "TPie.h"
35#include "TVirtualPad.h"
36#include "TGColorSelect.h"
37#include "TColor.h"
38#include "TBox.h"
39#include "TPaveLabel.h"
40#include "TVirtualX.h"
41#include "snprintf.h"
42
44
45enum EPieWid {
46 kPie = 0,
59};
60
61////////////////////////////////////////////////////////////////////////////////
62/// Constructor of graph editor.
63
65 Int_t height, UInt_t options, Pixel_t back)
66 : TGedFrame(p, width, height, options | kVerticalFrame, back)
67{
68 fPie = 0;
69 // TextEntry to change the title
70 MakeTitle("Pie Chart");
71
72 fTitle = new TGTextEntry(this, new TGTextBuffer(50), kPIE_TITLE);
74 fTitle->SetToolTipText("Enter the pie 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,"Label direction");
82 fLblDirH = new TGRadioButton(fgr,"Horizontal",kPIE_HOR); // no draw option
83 fLblDirH->SetToolTipText("Draw horizontal labels");
84 fLblDirR = new TGRadioButton(fgr,"Radial",kPIE_RAD); // option C
85 fLblDirR->SetToolTipText("Draw labels radially");
86 fLblDirT = new TGRadioButton(fgr,"Tangential",kPIE_TAN); // option L
87 fLblDirT->SetToolTipText("Draw labels tangential to the piechart");
88
90 fgr->Show();
92 f2->AddFrame(fgr, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
93
94 // CheckBox to activate/deactivate the drawing of the Marker
95 fOutlineOnOff = new TGCheckButton(f2,"Outline",kPIE_OUTLINE);
96 fOutlineOnOff->SetToolTipText("Draw a line to mark the pie");
97 f2->AddFrame(fOutlineOnOff, new TGLayoutHints(kLHintsTop, 5, 1, 0, 3));
98 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
99
100 // Exclusion zone parameters
101 MakeTitle("3D options");
102 TGCompositeFrame *f3 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
103 AddFrame(f3, new TGLayoutHints(kLHintsTop, 1, 1, 5, 0));
104
105 fIs3D = new TGCheckButton(f3,"3D",kPIE_3D);
106 fIs3D->SetToolTipText("Draw a 3D charts");
107 f3->AddFrame(fIs3D, new TGLayoutHints(kLHintsTop, 5, 1, 0, 0));
108
110 //f3DAngle->SetToolTipText("3D angle: 0-90")
111 f3DAngle->Resize(50, 20);
112 f3->AddFrame(f3DAngle, new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
113 f3DAngle->Associate(f3);
114
116 //f3DHeight->SetToolTipText("3D thick")
117 f3DHeight->Resize(50, 20);
118 f3->AddFrame(f3DHeight, new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
119 f3DHeight->Associate(f3);
120
121 MakeTitle("Text");
122 TGCompositeFrame *f4 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
124 f4->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
125 fColorSelect->Associate(this);
127 f4->AddFrame(fSizeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
128 fSizeCombo->Resize(91, 20);
129 fSizeCombo->Associate(this);
130 AddFrame(f4, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
132 fTypeCombo->Resize(137, 20);
133 AddFrame(fTypeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
134}
135
136
137////////////////////////////////////////////////////////////////////////////////
138/// Destructor of pie editor.
139
141{
142}
143
144
145////////////////////////////////////////////////////////////////////////////////
146/// Connect signals to slots.
147
149{
150 fTitle->Connect("TextChanged(const char *)","TPieEditor",this,"DoTitle(const char *)");
151 fgr->Connect("Clicked(Int_t)","TPieEditor",this,"DoShape()");
152 fOutlineOnOff->Connect("Toggled(Bool_t)","TPieEditor",this,"DoMarkerOnOff(Bool_t)");
153 f3DAngle->Connect("ValueSet(Long_t)", "TPieEditor", this, "DoChange3DAngle()");
154 f3DHeight->Connect("ValueSet(Long_t)", "TPieEditor", this, "DoChange3DAngle()");
155 fIs3D->Connect("Clicked()","TPieEditor",this,"DoGraphLineWidth()");
156
157 // text attributes connection
158 fTypeCombo->Connect("Selected(Int_t)","TPieEditor",this,"DoTextChange()");
159 fSizeCombo->Connect("Selected(Int_t)","TPieEditor",this,"DoTextChange()");
160 fColorSelect->Connect("ColorSelected(Pixel_t)","TPieEditor",this,"DoTextChange()");
161
162 fInit = kFALSE; // connect the slots to the signals only once
163}
164
165
166////////////////////////////////////////////////////////////////////////////////
167/// Exclude TAttTextEditor from this interface.
168
170{
171 TGedEditor *gedEditor = GetGedEditor();
172 gedEditor->ExcludeClassEditor(TAttText::Class());
174}
175
176
177////////////////////////////////////////////////////////////////////////////////
178/// Pick up the used values of graph attributes.
179
181{
182 fPie = (TPie *)obj;
184
185 // set the Title TextEntry
186 const char *text = fPie->GetTitle();
188
189 TString soption = GetDrawOption();
190
191 // For the label orientation there are 3 possibilities:
192 // 0: horizontal
193 // 1: radial
194 // 2: tangent
195 Int_t lblor(0);
196
197 // Parse the options
198 Int_t idx;
199 // Paint the TPie in an existing canvas
200 if ( (idx=soption.Index("same"))>=0 ) {
201 // optionSame = kTRUE;
202 soption.Remove(idx,4);
203 }
204
205 if ( (idx=soption.Index("nol"))>=0 ) {
207 soption.Remove(idx,3);
208 }
209 else {
211 }
212
213 // check if is active the pseudo-3d
214 if ( (idx=soption.Index("3d"))>=0 ) {
218 soption.Remove(idx,2);
219 } else {
221 }
222
223 // seek if have to draw the labels around the pie chart
224 if ( (idx=soption.Index("t"))>=0 ) {
225 lblor = 2;
226 soption.Remove(idx,1);
227 }
228
229 // Seek if have to paint the labels along the radii
230 if ( (idx=soption.Index("r"))>=0 ) {
231 lblor = 1;
232 soption.Remove(idx,1);
233 }
234
235 switch(lblor) {
236 case 0:
238 break;
239 case 1:
241 break;
242 case 2:
244 break;
245 }
246
247 // set text attributes
249
253
254 Float_t s = fPie->GetTextSize();
255 Float_t dy;
256
257 if (obj->InheritsFrom(TPaveLabel::Class())) {
258 TBox *pl = (TBox*)obj;
259 dy = s * (pl->GetY2() - pl->GetY1());
260 }
261 else
262 dy = s * (fGedEditor->GetPad()->GetY2() - fGedEditor->GetPad()->GetY1());
263
264 Int_t size = fGedEditor->GetPad()->YtoPixel(0.0) - fGedEditor->GetPad()->YtoPixel(dy);
265 if (size > 50) size = 50;
266 if (size < 0) size = 0;
267 fSizeCombo->Select(size, kFALSE);
268
271}
272
273
274////////////////////////////////////////////////////////////////////////////////
275/// Slot for setting the graph title.
276
277void TPieEditor::DoTitle(const char *text)
278{
279 if (fAvoidSignal) return;
281 Update();
282}
283
284
285////////////////////////////////////////////////////////////////////////////////
286/// Slot connected to the draw options.
287
289{
290 if (fAvoidSignal) return;
291
292 TString opt = GetDrawOption();
293
294 if (fLblDirH->GetState()==kButtonDown) {
295 if (opt.Contains("t")) opt.Remove(opt.First("t"),1);
296 if (opt.Contains("r")) opt.Remove(opt.First("r"),1);
297 }
298 else if (fLblDirR->GetState()==kButtonDown) {
299 if (opt.Contains("t")) opt.Remove(opt.First("t"),1);
300 if (!opt.Contains("r")) opt += "r";
301 }
302 else if (fLblDirT->GetState()==kButtonDown) {
303 if (!opt.Contains("t")) opt += "t";
304 if (opt.Contains("r")) opt.Remove(opt.First("r"),1);
305 }
306
307 SetDrawOption(opt);
308 if (gPad && gPad->GetVirtCanvas()) gPad->GetVirtCanvas()->SetCursor(kPointer);
309 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
310}
311
312
313////////////////////////////////////////////////////////////////////////////////
314/// Slot for setting markers as visible/invisible.
315
317{
318 if (fAvoidSignal) return;
320
321 if (t.Contains("nol") && fOutlineOnOff->GetState() == kButtonDown) {
322 t.Remove(t.First("nol"),3);
323 }
324 else if (!t.Contains("nol") && fOutlineOnOff->GetState() == kButtonUp) {
325 t += "nol";
326 }
327
328 SetDrawOption(t);
329}
330
331
332////////////////////////////////////////////////////////////////////////////////
333/// Slot for setting the 3D angle
334
336{
337 if (fAvoidSignal) return;
338
339 fPie->SetAngle3D(static_cast<Int_t>(f3DAngle->GetNumber()));
341
342 Update();
343
344}
345
346
347////////////////////////////////////////////////////////////////////////////////
348/// Slot connected to the graph line width.
349
351{
352 if (fAvoidSignal) return;
353
354 TString opt = GetDrawOption();
355 if (!opt.Contains("3d") && fIs3D->IsDown())
356 opt += "3d";
357 else if (opt.Contains("3d") && !fIs3D->IsDown())
358 opt.Remove(opt.First("3d"),2);
359
360 SetDrawOption(opt);
361
362 Update();
363}
364
365
366
367////////////////////////////////////////////////////////////////////////////////
368/// Change text.
369
371{
372 if (fAvoidSignal) return;
373
374 // font color
376
377 // font type
378 Int_t fontPrec = fPie->GetTextFont()%10;
379 Int_t fontType = fTypeCombo->GetSelected();
380 fPie->SetTextFont(fontType*10+fontPrec);
381
382 // font size
383 TVirtualPad* pad = fGedEditor->GetPad();
384
386
387 Float_t dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY((Int_t)val);
388 Float_t textSize;
389
390 if (fGedEditor->GetModel()->InheritsFrom(TPaveLabel::Class())) {
391 TBox *pl = (TBox*)fGedEditor->GetModel();
392 textSize = dy/(pl->GetY2() - pl->GetY1());
393 }
394 else
395 textSize = dy/(pad->GetY2() - pad->GetY1());
396
397 fPie->SetTextSize(textSize);
398
399 Update();
400
401}
402
403
404////////////////////////////////////////////////////////////////////////////////
405/// Create text size combo box.
406
408{
409 char a[100];
410 TGComboBox *c = new TGComboBox(parent, id);
411
412 c->AddEntry("Default", 0);
413 for (int i = 1; i <= 50; i++) {
414 snprintf(a, 99, "%d", i);
415 c->AddEntry(a, i);
416 }
417
418 return c;
419}
@ kChildFrame
Definition GuiTypes.h:379
@ kVerticalFrame
Definition GuiTypes.h:381
@ kFitWidth
Definition GuiTypes.h:386
@ kHorizontalFrame
Definition GuiTypes.h:382
@ kPointer
Definition GuiTypes.h:375
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
const Bool_t kFALSE
Definition RtypesCore.h:92
short Color_t
Definition RtypesCore.h:83
float Float_t
Definition RtypesCore.h:57
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
@ kFONT_STYLE
@ kFONT_SIZE
include TDocParser_001 C image html pict1_TDocParser_001 png width
@ kButtonDown
Definition TGButton.h:54
@ kButtonUp
Definition TGButton.h:53
@ kLHintsLeft
Definition TGLayout.h:31
@ kLHintsTop
Definition TGLayout.h:34
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:43
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:45
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:46
Create a Box.
Definition TBox.h:22
Double_t GetY1() const
Definition TBox.h:52
Double_t GetY2() const
Definition TBox.h:53
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition TColor.cxx:2016
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:1769
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 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 Bool_t IsDown() const
Definition TGButton.h:312
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
Pixel_t GetColor() const
virtual Int_t GetSelected() const
Definition TGComboBox.h:134
virtual TGLBEntry * GetSelectedEntry() const
Definition TGComboBox.h:135
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 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
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
virtual void SetNumber(Double_t val)
virtual void Associate(const TGWindow *w)
Make w the window that will receive the generated messages.
virtual Double_t GetNumber() const
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 TVirtualPad * GetPad() const
Definition TGedEditor.h:88
virtual TObject * GetModel() const
Definition TGedEditor.h:89
void ExcludeClassEditor(TClass *cl, Bool_t recurse=kFALSE)
Exclude editor for class cl from current construction.
virtual Option_t * GetDrawOption() const
Get draw options of the selected object.
Definition TGedFrame.cxx:81
virtual void ActivateBaseClassEditors(TClass *cl)
Provide list of editors for base-classes.
TGedEditor * fGedEditor
Definition TGedFrame.h:55
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
TGedEditor * GetGedEditor()
Definition TGedFrame.h:78
Bool_t fAvoidSignal
Definition TGedFrame.h:57
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
virtual const char * GetTitle() const
Returns title of object.
Definition TNamed.h:48
Mother of all ROOT objects.
Definition TObject.h:37
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:445
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:403
TGRadioButton * fLblDirH
Definition TPieEditor.h:43
TGNumberEntry * f3DAngle
Definition TPieEditor.h:50
virtual void DoTextChange()
Change text.
TPie * fPie
Definition TPieEditor.h:41
virtual void ActivateBaseClassEditors(TClass *)
Exclude TAttTextEditor from this interface.
TGColorSelect * fColorSelect
Definition TPieEditor.h:51
virtual ~TPieEditor()
Destructor of pie editor.
virtual void ConnectSignals2Slots()
Connect signals to slots.
virtual void DoChange3DAngle()
Slot for setting the 3D angle.
TGNumberEntry * f3DHeight
Definition TPieEditor.h:49
TGCheckButton * fIs3D
Definition TPieEditor.h:48
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
Definition TPieEditor.h:46
static TGComboBox * BuildFontSizeComboBox(TGFrame *, Int_t)
Create text size combo box.
TGRadioButton * fLblDirT
Definition TPieEditor.h:45
TGRadioButton * fLblDirR
Definition TPieEditor.h:44
TGComboBox * fSizeCombo
Definition TPieEditor.h:53
TPieEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of graph editor.
TGButtonGroup * fgr
Definition TPieEditor.h:42
TGTextEntry * fTitle
Definition TPieEditor.h:39
TGCheckButton * fOutlineOnOff
Definition TPieEditor.h:47
TGFontTypeComboBox * fTypeCombo
Definition TPieEditor.h:52
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:1180
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:1300
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:866
Basic string class.
Definition TString.h:136
Int_t Atoi() const
Return integer value of string.
Definition TString.cxx:1941
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:519
TString & Remove(Ssiz_t pos)
Definition TString.h:673
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:624
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:639
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
TText * text