CMS 3D CMS Logo

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