Logo ROOT   6.12/07
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");
86  fAutoRefesh->SetOn();
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);
189  TStructNodeProperty* prop;
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
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 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
TGNumberEntry * fMaxLevelsNumberEntry
UInt_t GetMaxLevel() const
Returns maximum number of leves displayed when the node is top node on scene.
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:689
void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
TStructNodeProperty * FindNodeProperty(TStructNode *node)
Retruns property associated to the class of given node "node".
Basic string class.
Definition: TString.h:125
void MaxLevelsValueSetSlot(Long_t)
Emmited when user changes maximum number of levels.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void SetState(Bool_t enable=kTRUE)
Set the active state.
virtual void SetLimits(ELimit limits=TGNumberFormat::kNELNoLimits, Double_t min=0, Double_t max=1)
UInt_t GetMaxObjects() const
Returns maximum number of objects displayed when the node is top node on scene.
void MaxObjectsValueSetSlot(Long_t)
Emmited when user changes maximum number of objects.
TGTextButton * fApplyButton
TStructNodeProperty * GetDefaultProperty()
Returns property with default color.
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Definition: TList.cxx:933
virtual void SetState(Bool_t state)
Set state of widget. If kTRUE=enabled, kFALSE=disabled.
TGTextEntry * fNameEntry
Bool_t fAvoidSignal
Definition: TGedFrame.h:56
ULong_t Pixel_t
Definition: GuiTypes.h:39
virtual Long_t GetIntNumber() const
virtual void SetText(TGString *newText)
Set new text in label.
Definition: TGLabel.cxx:177
virtual Bool_t IsOn() const
Definition: TGButton.h:311
TGTextButton * fDefaultButton
TGNumberEntry * fMaxObjectsNumberEntry
A doubly linked list.
Definition: TList.h:44
~TStructNodeEditor()
Destructor of node editor.
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:867
TString GetTypeName() const
Returns name of class.
const char * GetName() const
Returns name of object.
TStructNodeProperty * fSelectedPropert
TStructNode * fNode
Pixel_t GetColor() const
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:818
void SetMaxObjects(UInt_t max)
Sets maximum number of objects displayed when the node is top node on scene.
TGCheckButton * fAutoRefesh
unsigned int UInt_t
Definition: RtypesCore.h:42
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
TString fName
Definition: TGWindow.h:39
virtual void SetIntNumber(Long_t val)
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.
const Bool_t kFALSE
Definition: RtypesCore.h:88
const char * GetText() const
Definition: TGTextEntry.h:134
TString & Remove(Ssiz_t pos)
Definition: TString.h:619
long Long_t
Definition: RtypesCore.h:50
Color * colors
Definition: X3DBuffer.c:19
virtual void SetFormat(EStyle style, EAttribute attr=TGNumberFormat::kNEAAnyNumber)
void ColorSelectedSlot(Pixel_t color)
Slot connected to the fill area color.
#define ClassImp(name)
Definition: Rtypes.h:359
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition: TGButton.cxx:409
void Update()
Signal emmited when color or other property like number of level is changed without camera reset...
void AutoRefreshButtonSlot(Bool_t on)
Activated when user chage condition.
TGColorSelect * fColorSelect
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual void SetOn(Bool_t on=kTRUE, Bool_t emit=kFALSE)
Definition: TGButton.h:120
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:2887
void SetColor(const TColor &color)
Sets the color to "color".
Mother of all ROOT objects.
Definition: TObject.h:37
void ApplyButtonSlot()
ApplyButton Slot. Activated when user press Apply button. Sets properties of a node.
Bool_t fInit
Definition: TGedFrame.h:53
void SetMaxLevel(UInt_t level)
Sets maximum number of leves displayed when the node is top node on scene.
virtual void Add(TObject *obj)
Definition: TList.h:87
void DefaultButtonSlot()
Slot for Defaulf button. Sets color of class to default.
void Init()
Enables button and fields.
Pixel_t GetPixel() const
Return color in Pixel_t format.
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:165
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...
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
void SetModel(TObject *obj)
Pick up the used node attributes.
const char * Data() const
Definition: TString.h:345