CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWLongParameterSetter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWLongParameterSetter
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Mon Mar 10 11:22:32 CDT 2008
11 // $Id: FWLongParameterSetter.cc,v 1.8 2012/02/22 03:45:59 amraktad Exp $
12 //
13 
14 // system include files
15 #include "TGLabel.h"
16 #include "TGNumberEntry.h"
17 
18 #include <assert.h>
19 #include <iostream>
20 
21 // user include files
23 
24 
25 //
26 // constants, enums and typedefs
27 //
28 
29 //
30 // static data member definitions
31 //
32 
33 //
34 // constructors and destructor
35 //
37  m_param(0),
38  m_widget(0)
39 {
40 }
41 
42 // FWLongParameterSetter::FWLongParameterSetter(const FWLongParameterSetter& rhs)
43 // {
44 // // do actual copying here;
45 // }
46 
48 {
49 }
50 
51 //
52 // assignment operators
53 //
54 // const FWLongParameterSetter& FWLongParameterSetter::operator=(const FWLongParameterSetter& rhs)
55 // {
56 // //An exception safe implementation is
57 // FWLongParameterSetter temp(rhs);
58 // swap(rhs);
59 //
60 // return *this;
61 // }
62 
63 //
64 // member functions
65 //
66 
67 void
69 {
70  m_param = dynamic_cast<FWLongParameter*>(iParam);
71  assert(0!=m_param);
72 }
73 
74 TGFrame*
75 FWLongParameterSetter::build(TGFrame* iParent, bool labelBack)
76 {
77  TGCompositeFrame* frame = new TGHorizontalFrame(iParent);
78 
79  // number entry widget
80  TGNumberFormat::ELimit limits = m_param->min()==m_param->max() ?
81  TGNumberFormat::kNELNoLimits :
82  ( m_param->min() > m_param->max() ? TGNumberFormat::kNELLimitMin : TGNumberFormat::kNELLimitMinMax);
83  double min = 0;
84  double max = 1;
85  if (m_param->min()!=m_param->max())
86  {
87  min=m_param->min();
88  max=m_param->max();
89  }
90  m_widget = new TGNumberEntry
91  (frame, m_param->value(),
92  5, // number of digits
93  0, // widget ID
94  TGNumberFormat::kNESInteger, // style
95  TGNumberFormat::kNEAAnyNumber, // input value filter
96  limits, // specify limits
97  min, // min value
98  max); // max value
99 
100  m_widget->Connect("ValueSet(Long_t)", "FWLongParameterSetter", this, "doUpdate(Long_t)");
101 
102  // label
103  TGLabel* label = new TGLabel(frame, m_param->name().c_str());
104  if (labelBack)
105  {
106  frame->AddFrame(m_widget, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2,6,2,2));
107  frame->AddFrame(label, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2,2,0,0));
108  }
109  else
110  {
111  frame->AddFrame(label, new TGLayoutHints(kLHintsLeft|kLHintsCenterY));
112  frame->AddFrame(m_widget, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2,8,2,2));
113  }
114 
115  return frame;
116 }
117 
118 void
120 {
121  //std::cout <<"doUpdate called"<<std::endl;
122 
123  // Idiotic TGNumberEntry arrow buttons can send several events and if
124  // individual event processing takes longer it can happen that the widget
125  // gets detroyed in the meantime. So, process all events from arrows as
126  // soon as possible.
127  static bool in_update = false;
128  if (in_update)
129  return;
130  in_update = true;
131  gClient->ProcessEventsFor((TGWindow*)gTQSender);
132  in_update = false;
133 
134  assert(0!=m_param);
135  assert(0!=m_widget);
136  //std::cout <<m_widget->GetNumberEntry()->GetNumber()<<std::endl;
137  m_param->set(m_widget->GetNumberEntry()->GetIntNumber());
138  update();
139 }
140 
141 //
142 // const member functions
143 //
144 
145 //
146 // static member functions
147 //
FWParameterSetterEditorBase * frame() const
#define min(a, b)
Definition: mlp_lapack.h:161
const T & max(const T &a, const T &b)
virtual void attach(FWParameterBase *)
virtual TGFrame * build(TGFrame *iParent, bool labelBack=true)
const std::string & name() const