ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
39 TStructNodeEditor::TStructNodeEditor(TList* colors, const TGWindow *p, Int_t width, Int_t height, UInt_t options, Pixel_t back)
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);
58  fMaxObjectsNumberEntry->SetFormat(TGNumberEntry::kNESInteger);
59  fMaxObjectsNumberEntry->SetLimits(TGNumberEntry::kNELLimitMin, 1);
60  fMaxObjectsNumberEntry->SetState(kFALSE);
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);
69  fMaxLevelsNumberEntry->SetLimits(TGNumberEntry::kNELLimitMin, 1);
70  fMaxLevelsNumberEntry->SetFormat(TGNumberEntry::kNESInteger);
71  fMaxLevelsNumberEntry->SetState(kFALSE);
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);
78  fNameEntry->SetState(kFALSE);
79 
80  fColorSelect = new TGColorSelect(this);
81  fColorSelect->Connect("ColorSelected(Pixel_t)", "TStructNodeEditor", this, "ColorSelectedSlot(Pixel_t)");
82  this->AddFrame(fColorSelect, expandX);
83  fColorSelect->SetEnabled(kFALSE);
84 
85  fAutoRefesh = new TGCheckButton(this, "Auto refesh");
86  fAutoRefesh->SetOn();
87  fAutoRefesh->Connect("Toggled(Bool_t)", "TStructNodeEditor", this, "AutoRefreshButtonSlot(Bool_t)");
88  fAutoRefesh->SetEnabled(kFALSE);
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);
94  fDefaultButton->SetEnabled(kFALSE);
95 
96 
97  fApplyButton = new TGTextButton(this, "Apply");
98  fApplyButton->Connect("Clicked()", "TStructNodeEditor", this, "ApplyButtonSlot()");
99  fApplyButton->SetEnabled(kFALSE);
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();
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
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 }
TGNumberEntry * fMaxLevelsNumberEntry
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
UInt_t GetMaxLevel() const
Returns maximum number of leves displayed when the node is top node on scene.
void SetColor(Pixel_t color, Bool_t emit=kTRUE)
Set color.
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:137
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
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void SetState(Bool_t enable=kTRUE)
Set the active state.
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:771
virtual void SetState(Bool_t state)
Set state of widget. If kTRUE=enabled, kFALSE=disabled.
const char * GetName() const
Returns name of object.
TGTextEntry * fNameEntry
Bool_t fAvoidSignal
Definition: TGedFrame.h:58
ULong_t Pixel_t
Definition: GuiTypes.h:41
virtual void SetText(TGString *newText)
Set new text in label.
Definition: TGLabel.cxx:177
const char * GetText() const
Definition: TGTextEntry.h:140
TGTextButton * fDefaultButton
TGNumberEntry * fMaxObjectsNumberEntry
void Emit(const char *signal)
Acitvate signal without args.
Definition: TQObject.cxx:559
A doubly linked list.
Definition: TList.h:47
Pixel_t GetColor() const
~TStructNodeEditor()
Destructor of node editor.
TStructNodeProperty * fSelectedPropert
TStructNode * fNode
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:675
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
virtual Bool_t IsOn() const
Definition: TGButton.h:315
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
virtual void SetIntNumber(Long_t val)
UInt_t GetMaxObjects() const
Returns maximum number of objects displayed when the node is top node on scene.
TString GetTypeName() const
Returns name of class.
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:581
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
long Long_t
Definition: RtypesCore.h:50
Color * colors
Definition: X3DBuffer.c:19
void ColorSelectedSlot(Pixel_t color)
Slot connected to the fill area color.
ClassImp(TStructNodeEditor) TStructNodeEditor
Constructor of node attributes GUI.
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition: TGButton.cxx:409
Pixel_t GetPixel() const
Return color in Pixel_t format.
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
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:2801
void SetColor(const TColor &color)
Sets the color to "color".
Mother of all ROOT objects.
Definition: TObject.h:58
void ApplyButtonSlot()
ApplyButton Slot. Activated when user press Apply button. Sets properties of a node.
Bool_t fInit
Definition: TGedFrame.h:55
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:81
void DefaultButtonSlot()
Slot for Defaulf button. Sets color of class to default.
void Init()
Enables button and fields.
#define NULL
Definition: Rtypes.h:82
virtual Long_t GetIntNumber() const
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: Rtypes.h:91
TObject * obj
void SetModel(TObject *obj)
Pick up the used node attributes.