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