Logo ROOT  
Reference Guide
TStructNodeEditor.cxx
Go to the documentation of this file.
1// @(#)root/gviz3d:$Id$
2// Author: Tomasz Sosnicki 18/09/09
3
4/************************************************************************
5* Copyright (C) 1995-2009, 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#include "TStructNodeEditor.h"
14#include "TStructNode.h"
15#include "TStructNodeProperty.h"
16
17#include <TGColorSelect.h>
18#include <TColor.h>
19#include <TGNumberEntry.h>
20#include <TGLabel.h>
21#include <TGTextEntry.h>
22#include <TClass.h>
23
25
26//________________________________________________________________________
27//////////////////////////////////////////////////////////////////////////
28//
29// TStructNodeEditor is an editor for changing node attributes such as
30// maximum numbers of level or maximum number of objects diplayed if this
31// node is our top node. We can also change color associated with a class
32// or chagne color to default.
33//
34//////////////////////////////////////////////////////////////////////////
35
36////////////////////////////////////////////////////////////////////////////////
37/// Constructor of node attributes GUI.
38
40 : TGedFrame(p, width, height, options | kVerticalFrame, back), fColors(colors)
41{
42 MakeTitle("TStructNode");
43 fInit = kFALSE;
44
45 TGLayoutHints* expandX = new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 5,5,5,5);
46 fNodeNameLabel = new TGLabel(this, "No node selected");
47 this->AddFrame(fNodeNameLabel, expandX);
48
49 fTypeName = new TGLabel(this);
50
51 this->AddFrame(fTypeName, expandX);
52
53 TGHorizontalFrame* maxObjectsFrame = new TGHorizontalFrame(this);
54 TGLabel* fMaxObjectslabel = new TGLabel(maxObjectsFrame, "Max objects:");
55 maxObjectsFrame->AddFrame(fMaxObjectslabel);
56
57 fMaxObjectsNumberEntry = new TGNumberEntry(maxObjectsFrame, 0);
61 fMaxObjectsNumberEntry->Connect("ValueSet(Long_t)", "TStructNodeEditor", this, "MaxObjectsValueSetSlot(Long_t)");
62 maxObjectsFrame->AddFrame(fMaxObjectsNumberEntry);
63 this->AddFrame(maxObjectsFrame, expandX);
64
65 TGHorizontalFrame* maxLevelFrame = new TGHorizontalFrame(this);
66 TGLabel* fMaxLevelsLabel = new TGLabel(maxLevelFrame, "Max levels:");
67 maxLevelFrame->AddFrame(fMaxLevelsLabel);
68 fMaxLevelsNumberEntry = new TGNumberEntry(maxLevelFrame, 0);
72 fMaxLevelsNumberEntry->Connect("ValueSet(Long_t)", "TStructNodeEditor", this, "MaxLevelsValueSetSlot(Long_t)");
73 maxLevelFrame->AddFrame(fMaxLevelsNumberEntry);
74 this->AddFrame(maxLevelFrame, expandX);
75
76 fNameEntry = new TGTextEntry(this, fName.Data());
77 this->AddFrame(fNameEntry, expandX);
79
80 fColorSelect = new TGColorSelect(this);
81 fColorSelect->Connect("ColorSelected(Pixel_t)", "TStructNodeEditor", this, "ColorSelectedSlot(Pixel_t)");
82 this->AddFrame(fColorSelect, expandX);
84
85 fAutoRefesh = new TGCheckButton(this, "Auto refesh");
87 fAutoRefesh->Connect("Toggled(Bool_t)", "TStructNodeEditor", this, "AutoRefreshButtonSlot(Bool_t)");
89 this->AddFrame(fAutoRefesh, expandX);
90
91 fDefaultButton = new TGTextButton(this, "Default color");
92 fDefaultButton->Connect("Clicked()", "TStructNodeEditor", this, "DefaultButtonSlot()");
93 this->AddFrame(fDefaultButton, expandX);
95
96
97 fApplyButton = new TGTextButton(this, "Apply");
98 fApplyButton->Connect("Clicked()", "TStructNodeEditor", this, "ApplyButtonSlot()");
100 this->AddFrame(fApplyButton, expandX);
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Destructor of node editor.
105
107{
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// ApplyButton Slot. Activated when user press Apply button. Sets properties of a node
112
114{
115 Bool_t needReset = false;
116
119 needReset = true;
120 }
121
124 needReset = true;
125 }
126
127 if (fSelectedPropert) {
130 }
131
132 Update(needReset);
133}
134
135////////////////////////////////////////////////////////////////////////////////
136/// Activated when user chage condition
137
139{
140 if (on) {
141 Update(kTRUE);
142 }
143}
144
145////////////////////////////////////////////////////////////////////////////////
146/// Slot connected to the fill area color.
147
149{
150 if (fAvoidSignal) {
151 return;
152 }
153
155 if (prop) {
156 prop->SetColor(color);
157 } else {
158 // add property
159 prop = new TStructNodeProperty(fNode->GetTypeName(), color);
160 fColors->Add(prop);
161 fColors->Sort();
162 fSelectedPropert = prop;
164 }
165 Update();
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Slot for Defaulf button. Sets color of class to default
170
172{
174 fColors->Remove(prop);
178 Update();
179 }
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Retruns property associated to the class of given node "node". If property isn't found
184/// then returns NULL
185
187{
188 TIter it(fColors);
190 while ((prop = (TStructNodeProperty*) it() )) {
191 TString propName(prop->GetName());
192 if (propName.EndsWith("+")) {
193
194 if (TClass* cl = TClass::GetClass(node->GetTypeName())) {
195 propName.Remove(propName.Length()-1, 1);
196 if (cl->InheritsFrom(propName.Data())) {
197 return prop;
198 }
199 }
200 } else {
201 if (propName == TString(node->GetTypeName())) {
202 return prop;
203 }
204 }
205 }
206
207 return NULL;
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Returns property with default color
212
214{
215 return (TStructNodeProperty*)fColors->Last();
216}
217
218////////////////////////////////////////////////////////////////////////////////
219/// Enables button and fields
220
222{
230 fInit = kTRUE;
231}
232
233////////////////////////////////////////////////////////////////////////////////
234/// Emmited when user changes maximum number of levels
235
237{
239
240 if(fAutoRefesh->IsOn()) {
241 Update(kTRUE);
242 }
243}
244
245////////////////////////////////////////////////////////////////////////////////
246/// Emmited when user changes maximum number of objects
247
249{
251
252 if(fAutoRefesh->IsOn()) {
253 Update(kTRUE);
254 }
255}
256
257////////////////////////////////////////////////////////////////////////////////
258/// Pick up the used node attributes.
259
261{
262 fNode = dynamic_cast<TStructNode *>(obj);
263 if (!fNode) return;
264
265 // Add max level
267
268 // Add max objects
270
271 // Type label
272 fTypeName->SetText(fNode->GetTypeName());
273
274 // name label
276
277 // Add color property
279 if (!fSelectedPropert)
280 {
282 }
285
286 if (!fInit) {
287 Init();
288 }
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// Signal emmited when color or other property like number of level is changed
293/// without camera reset
294
296{
297 Emit("Update(Bool_t)", false);
298}
299
300////////////////////////////////////////////////////////////////////////////////
301/// Signal emmited when color or other property like number of level is changed.
302/// If "resetCamera" is true, then current camera is reset.
303
305{
306 Emit("Update(Bool_t)", resetCamera);
307}
@ kVerticalFrame
Definition: GuiTypes.h:381
ULong_t Pixel_t
Definition: GuiTypes.h:39
const Bool_t kFALSE
Definition: RtypesCore.h:90
long Long_t
Definition: RtypesCore.h:52
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
@ kLHintsLeft
Definition: TGLayout.h:31
@ kLHintsExpandX
Definition: TGLayout.h:37
Color * colors
Definition: X3DBuffer.c:21
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2948
virtual void SetOn(Bool_t on=kTRUE, Bool_t emit=kFALSE)
Definition: TGButton.h:120
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition: TGButton.cxx:411
virtual Bool_t IsOn() const
Definition: TGButton.h:311
void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
Pixel_t GetColor() const
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1101
virtual void SetText(TGString *newText)
Set new text in label.
Definition: TGLabel.cxx:178
virtual void SetIntNumber(Long_t val)
virtual void SetLimits(ELimit limits=TGNumberFormat::kNELNoLimits, Double_t min=0, Double_t max=1)
virtual void SetState(Bool_t enable=kTRUE)
Set the active state.
virtual Long_t GetIntNumber() const
virtual void SetFormat(EStyle style, EAttribute attr=TGNumberFormat::kNEAAnyNumber)
virtual void SetState(Bool_t state)
Set state of widget. If kTRUE=enabled, kFALSE=disabled.
const char * GetText() const
Definition: TGTextEntry.h:134
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.
TString fName
Definition: TGWindow.h:38
Bool_t fInit
Definition: TGedFrame.h:53
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
Bool_t fAvoidSignal
Definition: TGedFrame.h:56
A doubly linked list.
Definition: TList.h:44
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:821
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:692
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Definition: TList.cxx:936
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
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:131
Ssiz_t Length() const
Definition: TString.h:405
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2177
const char * Data() const
Definition: TString.h:364
TString & Remove(Ssiz_t pos)
Definition: TString.h:668
TGColorSelect * fColorSelect
void MaxLevelsValueSetSlot(Long_t)
Emmited when user changes maximum number of levels.
~TStructNodeEditor()
Destructor of node editor.
TStructNodeProperty * GetDefaultProperty()
Returns property with default color.
void SetModel(TObject *obj)
Pick up the used node attributes.
void MaxObjectsValueSetSlot(Long_t)
Emmited when user changes maximum number of objects.
void DefaultButtonSlot()
Slot for Defaulf button. Sets color of class to default.
void Update()
Signal emmited when color or other property like number of level is changed without camera reset.
TGNumberEntry * fMaxLevelsNumberEntry
void AutoRefreshButtonSlot(Bool_t on)
Activated when user chage condition.
TStructNode * fNode
void ColorSelectedSlot(Pixel_t color)
Slot connected to the fill area color.
TGNumberEntry * fMaxObjectsNumberEntry
TStructNodeProperty * fSelectedPropert
TGCheckButton * fAutoRefesh
TGTextEntry * fNameEntry
TGTextButton * fApplyButton
TGTextButton * fDefaultButton
TStructNodeProperty * FindNodeProperty(TStructNode *node)
Retruns property associated to the class of given node "node".
TStructNodeEditor(TList *colors, const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of node attributes GUI.
void Init()
Enables button and fields.
void ApplyButtonSlot()
ApplyButton Slot. Activated when user press Apply button. Sets properties of a node.
Pixel_t GetPixel() const
Return color in Pixel_t format.
void SetColor(const TColor &color)
Sets the color to "color".
UInt_t GetMaxLevel() const
Returns maximum number of leves displayed when the node is top node on scene.
TString GetTypeName() const
Returns name of class.
void SetMaxLevel(UInt_t level)
Sets maximum number of leves displayed when the node is top node on scene.
void SetMaxObjects(UInt_t max)
Sets maximum number of objects displayed when the node is top node on scene.
const char * GetName() const
Returns name of object.
UInt_t GetMaxObjects() const
Returns maximum number of objects displayed when the node is top node on scene.
struct void * fTypeName
Definition: cppyy.h:9