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