Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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 <TGNumberEntry.h>
19#include <TGLabel.h>
20#include <TGTextEntry.h>
21#include <TClass.h>
22
23
24//________________________________________________________________________
25//////////////////////////////////////////////////////////////////////////
26//
27// TStructNodeEditor is an editor for changing node attributes such as
28// maximum numbers of level or maximum number of objects diplayed if this
29// node is our top node. We can also change color associated with a class
30// or chagne color to default.
31//
32//////////////////////////////////////////////////////////////////////////
33
34////////////////////////////////////////////////////////////////////////////////
35/// Constructor of node attributes GUI.
36
38 : TGedFrame(p, width, height, options | kVerticalFrame, back), fColors(colors)
39{
40 MakeTitle("TStructNode");
41 fInit = kFALSE;
42
43 TGLayoutHints* expandX = new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 5,5,5,5);
44 fNodeNameLabel = new TGLabel(this, "No node selected");
45 this->AddFrame(fNodeNameLabel, expandX);
46
47 fTypeName = new TGLabel(this);
48
49 this->AddFrame(fTypeName, expandX);
50
51 TGHorizontalFrame* maxObjectsFrame = new TGHorizontalFrame(this);
52 TGLabel* fMaxObjectslabel = new TGLabel(maxObjectsFrame, "Max objects:");
53 maxObjectsFrame->AddFrame(fMaxObjectslabel);
54
55 fMaxObjectsNumberEntry = new TGNumberEntry(maxObjectsFrame, 0);
59 fMaxObjectsNumberEntry->Connect("ValueSet(Long_t)", "TStructNodeEditor", this, "MaxObjectsValueSetSlot(Long_t)");
60 maxObjectsFrame->AddFrame(fMaxObjectsNumberEntry);
61 this->AddFrame(maxObjectsFrame, expandX);
62
63 TGHorizontalFrame* maxLevelFrame = new TGHorizontalFrame(this);
64 TGLabel* fMaxLevelsLabel = new TGLabel(maxLevelFrame, "Max levels:");
65 maxLevelFrame->AddFrame(fMaxLevelsLabel);
66 fMaxLevelsNumberEntry = new TGNumberEntry(maxLevelFrame, 0);
70 fMaxLevelsNumberEntry->Connect("ValueSet(Long_t)", "TStructNodeEditor", this, "MaxLevelsValueSetSlot(Long_t)");
71 maxLevelFrame->AddFrame(fMaxLevelsNumberEntry);
72 this->AddFrame(maxLevelFrame, expandX);
73
74 fNameEntry = new TGTextEntry(this, fName.Data());
75 this->AddFrame(fNameEntry, expandX);
76 fNameEntry->SetState(kFALSE);
77
78 fColorSelect = new TGColorSelect(this);
79 fColorSelect->Connect("ColorSelected(Pixel_t)", "TStructNodeEditor", this, "ColorSelectedSlot(Pixel_t)");
80 this->AddFrame(fColorSelect, expandX);
81 fColorSelect->SetEnabled(kFALSE);
82
83 fAutoRefesh = new TGCheckButton(this, "Auto refesh");
84 fAutoRefesh->SetOn();
85 fAutoRefesh->Connect("Toggled(Bool_t)", "TStructNodeEditor", this, "AutoRefreshButtonSlot(Bool_t)");
86 fAutoRefesh->SetEnabled(kFALSE);
87 this->AddFrame(fAutoRefesh, expandX);
88
89 fDefaultButton = new TGTextButton(this, "Default color");
90 fDefaultButton->Connect("Clicked()", "TStructNodeEditor", this, "DefaultButtonSlot()");
91 this->AddFrame(fDefaultButton, expandX);
92 fDefaultButton->SetEnabled(kFALSE);
93
94
95 fApplyButton = new TGTextButton(this, "Apply");
96 fApplyButton->Connect("Clicked()", "TStructNodeEditor", this, "ApplyButtonSlot()");
97 fApplyButton->SetEnabled(kFALSE);
98 this->AddFrame(fApplyButton, expandX);
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Destructor of node editor.
103
107
108////////////////////////////////////////////////////////////////////////////////
109/// ApplyButton Slot. Activated when user press Apply button. Sets properties of a node
110
112{
113 Bool_t needReset = false;
114
115 if ((Int_t)(fNode->GetMaxLevel()) != fMaxLevelsNumberEntry->GetIntNumber()) {
116 fNode->SetMaxLevel(fMaxLevelsNumberEntry->GetIntNumber());
117 needReset = true;
118 }
119
120 if ((Int_t)(fNode->GetMaxObjects()) != fMaxObjectsNumberEntry->GetIntNumber()) {
121 fNode->SetMaxObjects(fMaxObjectsNumberEntry->GetIntNumber());
122 needReset = true;
123 }
124
125 if (fSelectedPropert) {
126 fSelectedPropert->SetColor(fColorSelect->GetColor());
127 fSelectedPropert->SetName(fNameEntry->GetText());
128 }
129
130 Update(needReset);
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// Activated when user chage condition
135
137{
138 if (on) {
139 Update(kTRUE);
140 }
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Slot connected to the fill area color.
145
147{
148 if (fAvoidSignal) {
149 return;
150 }
151
153 if (prop) {
154 prop->SetColor(color);
155 } else {
156 // add property
157 prop = new TStructNodeProperty(fNode->GetTypeName(), color);
158 fColors->Add(prop);
159 fColors->Sort();
160 fSelectedPropert = prop;
161 fNameEntry->SetText(fNode->GetTypeName());
162 }
163 Update();
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// Slot for Defaulf button. Sets color of class to default
168
170{
172 fColors->Remove(prop);
174 fNameEntry->SetText(fSelectedPropert->GetName());
175 fColorSelect->SetColor(fSelectedPropert->GetPixel(), kFALSE);
176 Update();
177 }
178}
179
180////////////////////////////////////////////////////////////////////////////////
181/// Retruns property associated to the class of given node "node". If property isn't found
182/// then returns NULL
183
185{
186 TIter it(fColors);
188 while ((prop = (TStructNodeProperty*) it() )) {
189 TString propName(prop->GetName());
190 if (propName.EndsWith("+")) {
191
192 if (TClass* cl = TClass::GetClass(node->GetTypeName())) {
193 propName.Remove(propName.Length()-1, 1);
194 if (cl->InheritsFrom(propName.Data())) {
195 return prop;
196 }
197 }
198 } else {
199 if (propName == TString(node->GetTypeName())) {
200 return prop;
201 }
202 }
203 }
204
205 return nullptr;
206}
207
208////////////////////////////////////////////////////////////////////////////////
209/// Returns property with default color
210
215
216////////////////////////////////////////////////////////////////////////////////
217/// Enables button and fields
218
220{
221 fMaxObjectsNumberEntry->SetState(kTRUE);
222 fMaxLevelsNumberEntry->SetState(kTRUE);
223 fNameEntry->SetState(kTRUE);
224 fColorSelect->SetEnabled(kTRUE);
225 fDefaultButton->SetEnabled(kTRUE);
226 fApplyButton->SetEnabled(kTRUE);
227 fAutoRefesh->SetEnabled(kTRUE);
228 fInit = kTRUE;
229}
230
231////////////////////////////////////////////////////////////////////////////////
232/// Emmited when user changes maximum number of levels
233
235{
236 fNode->SetMaxLevel(fMaxLevelsNumberEntry->GetIntNumber());
237
238 if(fAutoRefesh->IsOn()) {
239 Update(kTRUE);
240 }
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// Emmited when user changes maximum number of objects
245
247{
248 fNode->SetMaxObjects(fMaxObjectsNumberEntry->GetIntNumber());
249
250 if(fAutoRefesh->IsOn()) {
251 Update(kTRUE);
252 }
253}
254
255////////////////////////////////////////////////////////////////////////////////
256/// Pick up the used node attributes.
257
259{
260 fNode = dynamic_cast<TStructNode *>(obj);
261 if (!fNode) return;
262
263 // Add max level
264 fMaxLevelsNumberEntry->SetIntNumber(fNode->GetMaxLevel());
265
266 // Add max objects
267 fMaxObjectsNumberEntry->SetIntNumber(fNode->GetMaxObjects());
268
269 // Type label
270 fTypeName->SetText(fNode->GetTypeName());
271
272 // name label
273 fNodeNameLabel->SetText(fNode->GetName());
274
275 // Add color property
277 if (!fSelectedPropert)
278 {
280 }
281 fNameEntry->SetText(fSelectedPropert->GetName());
282 fColorSelect->SetColor(fSelectedPropert->GetPixel(), kFALSE);
283
284 if (!fInit) {
285 Init();
286 }
287}
288
289////////////////////////////////////////////////////////////////////////////////
290/// Signal emmited when color or other property like number of level is changed
291/// without camera reset
292
294{
295 Emit("Update(Bool_t)", false);
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// Signal emmited when color or other property like number of level is changed.
300/// If "resetCamera" is true, then current camera is reset.
301
303{
304 Emit("Update(Bool_t)", resetCamera);
305}
@ kVerticalFrame
Definition GuiTypes.h:382
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:41
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsExpandX
Definition TGLayout.h:30
Color * colors
Definition X3DBuffer.c:21
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
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:2994
Selects different options.
Definition TGButton.h:264
Like a checkbutton but instead of the check mark there is color area with a little down arrow.
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
This class handles GUI labels.
Definition TGLabel.h:24
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
TGNumberEntry is a number entry input widget with up/down buttons.
@ kNESInteger
Style of number entry field.
@ kNELLimitMin
Lower limit only.
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
ROOT GUI Window base class.
Definition TGWindow.h:23
TString fName
name of the window used in SavePrimitive()
Definition TGWindow.h:30
TGedFrame(const TGedFrame &)=delete
Bool_t fInit
init flag for setting signals/slots
Definition TGedFrame.h:47
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition TGedFrame.cxx:94
Bool_t fAvoidSignal
flag for executing slots
Definition TGedFrame.h:50
A doubly linked list.
Definition TList.h:38
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
Mother of all ROOT objects.
Definition TObject.h:42
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2250
const char * Data() const
Definition TString.h:384
TString & Remove(Ssiz_t pos)
Definition TString.h:694
TGColorSelect * fColorSelect
void MaxLevelsValueSetSlot(Long_t)
Emmited when user changes maximum number of levels.
TStructNodeProperty * GetDefaultProperty()
Returns property with default color.
void MaxObjectsValueSetSlot(Long_t)
Emmited when user changes maximum number of objects.
void DefaultButtonSlot()
Slot for Defaulf button. Sets color of class to default.
~TStructNodeEditor() override
Destructor of node editor.
TGNumberEntry * fMaxLevelsNumberEntry
void AutoRefreshButtonSlot(Bool_t on)
Activated when user chage condition.
void ColorSelectedSlot(Pixel_t color)
Slot connected to the fill area color.
void SetModel(TObject *obj) override
Pick up the used node attributes.
TGNumberEntry * fMaxObjectsNumberEntry
TStructNodeProperty * fSelectedPropert
TGCheckButton * fAutoRefesh
TGTextEntry * fNameEntry
TStructNodeEditor(TList *colors, const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of node attributes GUI.
TGTextButton * fApplyButton
TGTextButton * fDefaultButton
void Update() override
Signal emmited when color or other property like number of level is changed without camera reset.
TStructNodeProperty * FindNodeProperty(TStructNode *node)
Retruns property associated to the class of given node "node".
void Init()
Enables button and fields.
void ApplyButtonSlot()
ApplyButton Slot. Activated when user press Apply button. Sets properties of a node.
void SetColor(const TColor &color)
Sets the color to "color".
TString GetTypeName() const
Returns name of class.