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
24
25//________________________________________________________________________
26//////////////////////////////////////////////////////////////////////////
27//
28// TStructNodeEditor is an editor for changing node attributes such as
29// maximum numbers of level or maximum number of objects diplayed if this
30// node is our top node. We can also change color associated with a class
31// or chagne color to default.
32//
33//////////////////////////////////////////////////////////////////////////
34
35////////////////////////////////////////////////////////////////////////////////
36/// Constructor of node attributes GUI.
37
39 : TGedFrame(p, width, height, options | kVerticalFrame, back), fColors(colors)
40{
41 MakeTitle("TStructNode");
42 fInit = kFALSE;
43
44 TGLayoutHints* expandX = new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 5,5,5,5);
45 fNodeNameLabel = new TGLabel(this, "No node selected");
46 this->AddFrame(fNodeNameLabel, expandX);
47
48 fTypeName = new TGLabel(this);
49
50 this->AddFrame(fTypeName, expandX);
51
52 TGHorizontalFrame* maxObjectsFrame = new TGHorizontalFrame(this);
53 TGLabel* fMaxObjectslabel = new TGLabel(maxObjectsFrame, "Max objects:");
54 maxObjectsFrame->AddFrame(fMaxObjectslabel);
55
56 fMaxObjectsNumberEntry = new TGNumberEntry(maxObjectsFrame, 0);
60 fMaxObjectsNumberEntry->Connect("ValueSet(Long_t)", "TStructNodeEditor", this, "MaxObjectsValueSetSlot(Long_t)");
61 maxObjectsFrame->AddFrame(fMaxObjectsNumberEntry);
62 this->AddFrame(maxObjectsFrame, expandX);
63
64 TGHorizontalFrame* maxLevelFrame = new TGHorizontalFrame(this);
65 TGLabel* fMaxLevelsLabel = new TGLabel(maxLevelFrame, "Max levels:");
66 maxLevelFrame->AddFrame(fMaxLevelsLabel);
67 fMaxLevelsNumberEntry = new TGNumberEntry(maxLevelFrame, 0);
71 fMaxLevelsNumberEntry->Connect("ValueSet(Long_t)", "TStructNodeEditor", this, "MaxLevelsValueSetSlot(Long_t)");
72 maxLevelFrame->AddFrame(fMaxLevelsNumberEntry);
73 this->AddFrame(maxLevelFrame, expandX);
74
75 fNameEntry = new TGTextEntry(this, fName.Data());
76 this->AddFrame(fNameEntry, expandX);
77 fNameEntry->SetState(kFALSE);
78
79 fColorSelect = new TGColorSelect(this);
80 fColorSelect->Connect("ColorSelected(Pixel_t)", "TStructNodeEditor", this, "ColorSelectedSlot(Pixel_t)");
81 this->AddFrame(fColorSelect, expandX);
82 fColorSelect->SetEnabled(kFALSE);
83
84 fAutoRefesh = new TGCheckButton(this, "Auto refesh");
85 fAutoRefesh->SetOn();
86 fAutoRefesh->Connect("Toggled(Bool_t)", "TStructNodeEditor", this, "AutoRefreshButtonSlot(Bool_t)");
87 fAutoRefesh->SetEnabled(kFALSE);
88 this->AddFrame(fAutoRefesh, expandX);
89
90 fDefaultButton = new TGTextButton(this, "Default color");
91 fDefaultButton->Connect("Clicked()", "TStructNodeEditor", this, "DefaultButtonSlot()");
92 this->AddFrame(fDefaultButton, expandX);
93 fDefaultButton->SetEnabled(kFALSE);
94
95
96 fApplyButton = new TGTextButton(this, "Apply");
97 fApplyButton->Connect("Clicked()", "TStructNodeEditor", this, "ApplyButtonSlot()");
98 fApplyButton->SetEnabled(kFALSE);
99 this->AddFrame(fApplyButton, expandX);
100}
101
102////////////////////////////////////////////////////////////////////////////////
103/// Destructor of node editor.
104
108
109////////////////////////////////////////////////////////////////////////////////
110/// ApplyButton Slot. Activated when user press Apply button. Sets properties of a node
111
113{
114 Bool_t needReset = false;
115
116 if ((Int_t)(fNode->GetMaxLevel()) != fMaxLevelsNumberEntry->GetIntNumber()) {
117 fNode->SetMaxLevel(fMaxLevelsNumberEntry->GetIntNumber());
118 needReset = true;
119 }
120
121 if ((Int_t)(fNode->GetMaxObjects()) != fMaxObjectsNumberEntry->GetIntNumber()) {
122 fNode->SetMaxObjects(fMaxObjectsNumberEntry->GetIntNumber());
123 needReset = true;
124 }
125
126 if (fSelectedPropert) {
127 fSelectedPropert->SetColor(fColorSelect->GetColor());
128 fSelectedPropert->SetName(fNameEntry->GetText());
129 }
130
131 Update(needReset);
132}
133
134////////////////////////////////////////////////////////////////////////////////
135/// Activated when user chage condition
136
138{
139 if (on) {
140 Update(kTRUE);
141 }
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// Slot connected to the fill area color.
146
148{
149 if (fAvoidSignal) {
150 return;
151 }
152
154 if (prop) {
155 prop->SetColor(color);
156 } else {
157 // add property
158 prop = new TStructNodeProperty(fNode->GetTypeName(), color);
159 fColors->Add(prop);
160 fColors->Sort();
162 fNameEntry->SetText(fNode->GetTypeName());
163 }
164 Update();
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Slot for Defaulf button. Sets color of class to default
169
171{
173 fColors->Remove(prop);
175 fNameEntry->SetText(fSelectedPropert->GetName());
176 fColorSelect->SetColor(fSelectedPropert->GetPixel(), kFALSE);
177 Update();
178 }
179}
180
181////////////////////////////////////////////////////////////////////////////////
182/// Retruns property associated to the class of given node "node". If property isn't found
183/// then returns NULL
184
186{
187 TIter it(fColors);
189 while ((prop = (TStructNodeProperty*) it() )) {
190 TString propName(prop->GetName());
191 if (propName.EndsWith("+")) {
192
193 if (TClass* cl = TClass::GetClass(node->GetTypeName())) {
194 propName.Remove(propName.Length()-1, 1);
195 if (cl->InheritsFrom(propName.Data())) {
196 return prop;
197 }
198 }
199 } else {
200 if (propName == TString(node->GetTypeName())) {
201 return prop;
202 }
203 }
204 }
205
206 return nullptr;
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// Returns property with default color
211
216
217////////////////////////////////////////////////////////////////////////////////
218/// Enables button and fields
219
221{
222 fMaxObjectsNumberEntry->SetState(kTRUE);
223 fMaxLevelsNumberEntry->SetState(kTRUE);
224 fNameEntry->SetState(kTRUE);
225 fColorSelect->SetEnabled(kTRUE);
226 fDefaultButton->SetEnabled(kTRUE);
227 fApplyButton->SetEnabled(kTRUE);
228 fAutoRefesh->SetEnabled(kTRUE);
229 fInit = kTRUE;
230}
231
232////////////////////////////////////////////////////////////////////////////////
233/// Emmited when user changes maximum number of levels
234
236{
237 fNode->SetMaxLevel(fMaxLevelsNumberEntry->GetIntNumber());
238
239 if(fAutoRefesh->IsOn()) {
240 Update(kTRUE);
241 }
242}
243
244////////////////////////////////////////////////////////////////////////////////
245/// Emmited when user changes maximum number of objects
246
248{
249 fNode->SetMaxObjects(fMaxObjectsNumberEntry->GetIntNumber());
250
251 if(fAutoRefesh->IsOn()) {
252 Update(kTRUE);
253 }
254}
255
256////////////////////////////////////////////////////////////////////////////////
257/// Pick up the used node attributes.
258
260{
261 fNode = dynamic_cast<TStructNode *>(obj);
262 if (!fNode) return;
263
264 // Add max level
265 fMaxLevelsNumberEntry->SetIntNumber(fNode->GetMaxLevel());
266
267 // Add max objects
268 fMaxObjectsNumberEntry->SetIntNumber(fNode->GetMaxObjects());
269
270 // Type label
271 fTypeName->SetText(fNode->GetTypeName());
272
273 // name label
274 fNodeNameLabel->SetText(fNode->GetName());
275
276 // Add color property
278 if (!fSelectedPropert)
279 {
281 }
282 fNameEntry->SetText(fSelectedPropert->GetName());
283 fColorSelect->SetColor(fSelectedPropert->GetPixel(), kFALSE);
284
285 if (!fInit) {
286 Init();
287 }
288}
289
290////////////////////////////////////////////////////////////////////////////////
291/// Signal emmited when color or other property like number of level is changed
292/// without camera reset
293
295{
296 Emit("Update(Bool_t)", false);
297}
298
299////////////////////////////////////////////////////////////////////////////////
300/// Signal emmited when color or other property like number of level is changed.
301/// If "resetCamera" is true, then current camera is reset.
302
304{
305 Emit("Update(Bool_t)", resetCamera);
306}
@ kVerticalFrame
Definition GuiTypes.h:381
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
long Long_t
Definition RtypesCore.h:54
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsExpandX
Definition TGLayout.h:30
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h prop
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Color * colors
Definition X3DBuffer.c:21
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
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:2969
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:1117
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
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:95
Bool_t fAvoidSignal
flag for executing slots
Definition TGedFrame.h:50
A doubly linked list.
Definition TList.h:38
Mother of all ROOT objects.
Definition TObject.h:41
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2244
const char * Data() const
Definition TString.h:376
TString & Remove(Ssiz_t pos)
Definition TString.h:685
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.
TString GetTypeName() const
Returns name of class.