Logo ROOT  
Reference Guide
TEveParamList.cxx
Go to the documentation of this file.
1// @(#)root/eve:$Id$
2// Author: Dmytro Kovalskyi, 28.2.2008
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, 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#include "TEveParamList.h"
13
14// Cleanup these includes:
15#include "TGLabel.h"
16#include "TGButton.h"
17#include "TGNumberEntry.h"
18#include "TGColorSelect.h"
19#include "TGDoubleSlider.h"
20
21#include "TEveGValuators.h"
22#include "TGedEditor.h"
23
24/** \class TEveParamList
25\ingroup TEve
26Collection of named parameters.
27*/
28
30
31////////////////////////////////////////////////////////////////////////////////
32/// Constructor.
33
34TEveParamList::TEveParamList(const char* n, const char* t, Bool_t doColor) :
35 TNamed(n, t),
36 fColor(0)
37{
38 if (doColor) SetMainColorPtr(&fColor);
39}
40
41////////////////////////////////////////////////////////////////////////////////
42/// Get config-struct for float parameter 'name'.
43
45{
46 static const TEveException eh("TEveParamList::GetFloatParameter ");
47
48 for (FloatConfigVec_ci itr = fFloatParameters.begin(); itr != fFloatParameters.end(); ++itr)
49 if (itr->fName.CompareTo(name)==0 ) return *itr;
50 Error(eh, "parameter not found.");
51 return FloatConfig_t();
52}
53
54////////////////////////////////////////////////////////////////////////////////
55/// Get config-struct for int parameter 'name'.
56
58{
59 static const TEveException eh("TEveParamList::GetIntParameter ");
60
61 for (IntConfigVec_ci itr = fIntParameters.begin(); itr != fIntParameters.end(); ++itr)
62 if (itr->fName.CompareTo(name) == 0) return *itr;
63 Error(eh, "parameter not found.");
64 return IntConfig_t();
65}
66
67////////////////////////////////////////////////////////////////////////////////
68/// Get value for bool parameter 'name'.
69
71{
72 static const TEveException eh("TEveParamList::GetBoolParameter ");
73
74 for (BoolConfigVec_ci itr = fBoolParameters.begin(); itr != fBoolParameters.end(); ++itr)
75 if ( itr->fName.CompareTo(name)==0 ) return itr->fValue;
76 Error(eh, "parameter not found.");
77 return kFALSE;
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Emit ParamChanged() signal.
82
84{
85 Emit("ParamChanged(char*)", name);
86}
87
88/** \class TEveParamListEditor
89\ingroup TEve
90GUI editor for TEveParamList.
91
92Slot methods from this object do not call Update, instead they call
93their model's ParamChanged(const char* name) function which emits a
94corresponding signal.
95
96This helps in handling of parameter changes as they are probably
97related to displayed objects in a more complicated way. Further,
98the TGCheckButton::HandleButton() emits more signal after the
99Clicked() signal and if model is reset in the editor, its contents
100is removed. This results in a crash.
101*/
102
104
105////////////////////////////////////////////////////////////////////////////////
106/// Constructor.
107
109 UInt_t options, Pixel_t back) :
110 TGedFrame(p, width, height, options | kVerticalFrame, back),
111 fM (0),
112 fParamFrame (0)
113{
114 MakeTitle("TEveParamList");
115}
116
117////////////////////////////////////////////////////////////////////////////////
118/// Initialize widgets when a new object is selected.
119
121{
122 fM = dynamic_cast<TEveParamList*>(obj);
123
124 if (fParamFrame) {
128 delete fParamFrame;
129 }
130 fParamFrame = new TGVerticalFrame(this);
132
133 // integers
134 fIntParameters.clear();
135 for (UInt_t i = 0; i < fM->fIntParameters.size(); ++i)
136 {
138
139 // number entry widget
140 TGNumberEntry* widget = new TGNumberEntry
141 (frame, fM->fIntParameters[i].fValue,
142 5, // number of digits
143 i, // widget ID
145 TGNumberFormat::kNEAAnyNumber, // input value filter
146 TGNumberFormat::kNELLimitMinMax, // specify limits
147 fM->fIntParameters[i].fMin, // min value
148 fM->fIntParameters[i].fMax); // max value
149 frame->AddFrame(widget, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2,8,2,2));
150 widget->Connect("ValueSet(Long_t)", "TEveParamListEditor", this, "DoIntUpdate()");
151 fIntParameters.push_back(widget);
152
153 // label
154 frame->AddFrame(new TGLabel(frame,fM->fIntParameters[i].fName.Data()),
156
158 }
159
160
161 // floats
162 fFloatParameters.clear();
163 for (UInt_t i = 0; i < fM->fFloatParameters.size(); ++i)
164 {
166
167 // number entry widget
168 TGNumberEntry* widget = new TGNumberEntry
169 (frame, fM->fFloatParameters[i].fValue,
170 5, // number of digits
171 i, // widget ID
173 TGNumberFormat::kNEAAnyNumber, // input value filter
174 TGNumberFormat::kNELLimitMinMax, // specify limits
175 fM->fFloatParameters[i].fMin, // min value
176 fM->fFloatParameters[i].fMax); // max value
177 frame->AddFrame(widget, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2,8,2,2));
178 widget->Connect("ValueSet(Long_t)", "TEveParamListEditor", this, "DoFloatUpdate()");
179 fFloatParameters.push_back( widget );
180
181 // label
182 frame->AddFrame(new TGLabel(frame,fM->fFloatParameters[i].fName.Data()),
184
186 }
187
188 // boolean
189 fBoolParameters.clear();
190 for (UInt_t i = 0; i < fM->fBoolParameters.size(); ++i)
191 {
193 fM->fBoolParameters[i].fName.Data(),
194 i);
195 widget->Connect("Clicked()", "TEveParamListEditor", this, "DoBoolUpdate()");
196 fBoolParameters.push_back(widget);
197
198 fParamFrame->AddFrame(widget, new TGLayoutHints(kLHintsTop,2,0,1,1));
199 }
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// Set model object.
205
207{
208 InitModel(obj);
209
210 for (UInt_t i = 0; i < fIntParameters.size(); ++i)
211 fIntParameters[i]->GetNumberEntry()->SetIntNumber(fM->fIntParameters[i].fValue);
212
213 for (UInt_t i = 0; i < fFloatParameters.size(); ++i)
214 fFloatParameters[i]->GetNumberEntry()->SetNumber(fM->fFloatParameters[i].fValue);
215
216 for (UInt_t i = 0; i < fBoolParameters.size(); ++i)
217 fBoolParameters[i]->SetState( fM->fBoolParameters[i].fValue ? kButtonDown : kButtonUp);
218}
219
220////////////////////////////////////////////////////////////////////////////////
221/// Slot for integer parameter update.
222
224{
226 Int_t id = widget->WidgetId();
227 if (id < 0 || id >= (int) fM->fIntParameters.size()) return;
228 fM->fIntParameters[id].fValue = widget->GetNumberEntry()->GetIntNumber();
229
230 fM->ParamChanged(fM->fIntParameters[id].fName);
231 gTQSender = (void*) widget;
232}
233
234////////////////////////////////////////////////////////////////////////////////
235/// Slot for float parameter update.
236
238{
240 Int_t id = widget->WidgetId();
241 if (id < 0 || id >= (int) fM->fFloatParameters.size()) return;
242 fM->fFloatParameters[id].fValue = widget->GetNumberEntry()->GetNumber();
243
244 fM->ParamChanged(fM->fFloatParameters[id].fName);
245 gTQSender = (void*) widget;
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Slot for bool parameter update.
250
252{
254 Int_t id = widget->WidgetId();
255 if (id < 0 || id >= (int) fM->fBoolParameters.size()) return;
256 fM->fBoolParameters[id].fValue = widget->IsOn();
257
258 fM->ParamChanged(fM->fBoolParameters[id].fName);
259 gTQSender = (void*) widget;
260}
@ kVerticalFrame
Definition: GuiTypes.h:381
ULong_t Pixel_t
Definition: GuiTypes.h:39
const Bool_t kFALSE
Definition: RtypesCore.h:90
#define ClassImp(name)
Definition: Rtypes.h:361
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
@ kButtonDown
Definition: TGButton.h:54
@ kButtonUp
Definition: TGButton.h:53
@ kLHintsLeft
Definition: TGLayout.h:31
@ kLHintsCenterY
Definition: TGLayout.h:35
@ kLHintsTop
Definition: TGLayout.h:34
XFontStruct * id
Definition: TGX11.cxx:108
char name[80]
Definition: TGX11.cxx:109
R__EXTERN void * gTQSender
Definition: TQObject.h:44
void SetMainColorPtr(Color_t *color)
Definition: TEveElement.h:267
Exception class thrown by TEve classes and macros.
Definition: TEveUtil.h:102
GUI editor for TEveParamList.
TGVerticalFrame * fParamFrame
virtual void InitModel(TObject *obj)
Initialize widgets when a new object is selected.
std::vector< TGCheckButton * > fBoolParameters
std::vector< TGNumberEntry * > fIntParameters
void DoFloatUpdate()
Slot for float parameter update.
TEveParamListEditor(const TEveParamListEditor &)
void DoIntUpdate()
Slot for integer parameter update.
virtual void SetModel(TObject *obj)
Set model object.
void DoBoolUpdate()
Slot for bool parameter update.
TEveParamList * fM
std::vector< TGNumberEntry * > fFloatParameters
Collection of named parameters.
Definition: TEveParamList.h:27
IntConfigVec_t::const_iterator IntConfigVec_ci
Definition: TEveParamList.h:57
TEveParamList(const TEveParamList &)
BoolConfigVec_t::const_iterator BoolConfigVec_ci
Definition: TEveParamList.h:69
Color_t fColor
Definition: TEveParamList.h:76
IntConfigVec_t fIntParameters
Definition: TEveParamList.h:78
FloatConfigVec_t::const_iterator FloatConfigVec_ci
Definition: TEveParamList.h:43
void ParamChanged(const char *name)
Emit ParamChanged() signal.
IntConfig_t GetIntParameter(const TString &name)
Get config-struct for int parameter 'name'.
BoolConfigVec_t fBoolParameters
Definition: TEveParamList.h:79
Bool_t GetBoolParameter(const TString &name)
Get value for bool parameter 'name'.
FloatConfigVec_t fFloatParameters
Definition: TEveParamList.h:77
FloatConfig_t GetFloatParameter(const TString &name)
Get config-struct for float parameter 'name'.
virtual Bool_t IsOn() const
Definition: TGButton.h:311
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1101
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1148
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition: TGFrame.cxx:1133
virtual void UnmapWindow()
unmap window
Definition: TGFrame.h:231
virtual Long_t GetIntNumber() const
Get the numeric value (integer representation).
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
TGNumberEntryField * GetNumberEntry() const
Int_t WidgetId() const
Definition: TGWidget.h:80
virtual void DestroyWindow()
destroy window
Definition: TGWindow.cxx:182
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:891
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
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:866
Basic string class.
Definition: TString.h:131
const Int_t n
Definition: legend1.C:16