Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files 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 
24 ClassImp(TStructNodeEditor);
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 
106 TStructNodeEditor::~TStructNodeEditor()
107 {
108 }
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// ApplyButton Slot. Activated when user press Apply button. Sets properties of a node
112 
113 void TStructNodeEditor::ApplyButtonSlot()
114 {
115  Bool_t needReset = false;
116 
117  if ((Int_t)(fNode->GetMaxLevel()) != fMaxLevelsNumberEntry->GetIntNumber()) {
118  fNode->SetMaxLevel(fMaxLevelsNumberEntry->GetIntNumber());
119  needReset = true;
120  }
121 
122  if ((Int_t)(fNode->GetMaxObjects()) != fMaxObjectsNumberEntry->GetIntNumber()) {
123  fNode->SetMaxObjects(fMaxObjectsNumberEntry->GetIntNumber());
124  needReset = true;
125  }
126 
127  if (fSelectedPropert) {
128  fSelectedPropert->SetColor(fColorSelect->GetColor());
129  fSelectedPropert->SetName(fNameEntry->GetText());
130  }
131 
132  Update(needReset);
133 }
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 /// Activated when user chage condition
137 
138 void TStructNodeEditor::AutoRefreshButtonSlot(Bool_t on)
139 {
140  if (on) {
141  Update(kTRUE);
142  }
143 }
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Slot connected to the fill area color.
147 
148 void TStructNodeEditor::ColorSelectedSlot(Pixel_t color)
149 {
150  if (fAvoidSignal) {
151  return;
152  }
153 
154  TStructNodeProperty* prop = FindNodeProperty(fNode);
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;
163  fNameEntry->SetText(fNode->GetTypeName());
164  }
165  Update();
166 }
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// Slot for Defaulf button. Sets color of class to default
170 
171 void TStructNodeEditor::DefaultButtonSlot()
172 {
173  if (TStructNodeProperty* prop = FindNodeProperty(fNode)) {
174  fColors->Remove(prop);
175  fSelectedPropert = GetDefaultProperty();
176  fNameEntry->SetText(fSelectedPropert->GetName());
177  fColorSelect->SetColor(fSelectedPropert->GetPixel(), kFALSE);
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 
186 TStructNodeProperty* TStructNodeEditor::FindNodeProperty(TStructNode* node)
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 
213 TStructNodeProperty* TStructNodeEditor::GetDefaultProperty()
214 {
215  return (TStructNodeProperty*)fColors->Last();
216 }
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// Enables button and fields
220 
221 void TStructNodeEditor::Init()
222 {
223  fMaxObjectsNumberEntry->SetState(kTRUE);
224  fMaxLevelsNumberEntry->SetState(kTRUE);
225  fNameEntry->SetState(kTRUE);
226  fColorSelect->SetEnabled(kTRUE);
227  fDefaultButton->SetEnabled(kTRUE);
228  fApplyButton->SetEnabled(kTRUE);
229  fAutoRefesh->SetEnabled(kTRUE);
230  fInit = kTRUE;
231 }
232 
233 ////////////////////////////////////////////////////////////////////////////////
234 /// Emmited when user changes maximum number of levels
235 
236 void TStructNodeEditor::MaxLevelsValueSetSlot(Long_t)
237 {
238  fNode->SetMaxLevel(fMaxLevelsNumberEntry->GetIntNumber());
239 
240  if(fAutoRefesh->IsOn()) {
241  Update(kTRUE);
242  }
243 }
244 
245 ////////////////////////////////////////////////////////////////////////////////
246 /// Emmited when user changes maximum number of objects
247 
248 void TStructNodeEditor::MaxObjectsValueSetSlot(Long_t)
249 {
250  fNode->SetMaxObjects(fMaxObjectsNumberEntry->GetIntNumber());
251 
252  if(fAutoRefesh->IsOn()) {
253  Update(kTRUE);
254  }
255 }
256 
257 ////////////////////////////////////////////////////////////////////////////////
258 /// Pick up the used node attributes.
259 
260 void TStructNodeEditor::SetModel(TObject* obj)
261 {
262  fNode = dynamic_cast<TStructNode *>(obj);
263  if (!fNode) return;
264 
265  // Add max level
266  fMaxLevelsNumberEntry->SetIntNumber(fNode->GetMaxLevel());
267 
268  // Add max objects
269  fMaxObjectsNumberEntry->SetIntNumber(fNode->GetMaxObjects());
270 
271  // Type label
272  fTypeName->SetText(fNode->GetTypeName());
273 
274  // name label
275  fNodeNameLabel->SetText(fNode->GetName());
276 
277  // Add color property
278  fSelectedPropert = FindNodeProperty(fNode);
279  if (!fSelectedPropert)
280  {
281  fSelectedPropert = GetDefaultProperty();
282  }
283  fNameEntry->SetText(fSelectedPropert->GetName());
284  fColorSelect->SetColor(fSelectedPropert->GetPixel(), kFALSE);
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 
295 void TStructNodeEditor::Update()
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 
304 void TStructNodeEditor::Update(Bool_t resetCamera)
305 {
306  Emit("Update(Bool_t)", resetCamera);
307 }