CMS 3D CMS Logo

FWEnumParameterSetter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWEnumParameterSetter
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: matevz
10 // Created: Fri Apr 30 15:17:33 CEST 2010
11 //
12 
13 // system include files
14 
15 // user include files
17 #include "TGComboBox.h"
18 #include "TGLabel.h"
19 #include <cassert>
20 
21 //
22 // constants, enums and typedefs
23 //
24 
25 //
26 // static data member definitions
27 //
28 
29 //
30 // constructors and destructor
31 //
33 
34 // FWEnumParameterSetter::FWEnumParameterSetter(const FWEnumParameterSetter& rhs)
35 // {
36 // // do actual copying here;
37 // }
38 
40 
41 //
42 // assignment operators
43 //
44 // const FWEnumParameterSetter& FWEnumParameterSetter::operator=(const FWEnumParameterSetter& rhs)
45 // {
46 // //An exception safe implementation is
47 // FWEnumParameterSetter temp(rhs);
48 // swap(rhs);
49 //
50 // return *this;
51 // }
52 
53 //
54 // member functions
55 //
56 
58  m_param = dynamic_cast<FWEnumParameter*>(iParam);
59  assert(nullptr != m_param);
60 }
61 
62 TGFrame* FWEnumParameterSetter::build(TGFrame* iParent, bool labelBack) {
63  TGCompositeFrame* frame = new TGHorizontalFrame(iParent);
64 
65  m_widget = new TGComboBox(frame);
66  std::map<Long_t, std::string>::const_iterator me = m_param->entryMap().begin();
67  UInt_t max_len = 0;
68  while (me != m_param->entryMap().end()) {
69  m_widget->AddEntry(me->second.c_str(), static_cast<Int_t>(me->first));
70  if (me->second.length() > max_len)
71  max_len = me->second.length();
72  ++me;
73  }
74  m_widget->Resize(8 * max_len + 20, 20);
75  m_widget->Select(static_cast<Int_t>(m_param->value()), kFALSE);
76 
77  m_widget->Connect("Selected(Int_t)", "FWEnumParameterSetter", this, "doUpdate(Int_t)");
78 
79  // label
80  TGLabel* label = new TGLabel(frame, m_param->name().c_str());
81  if (labelBack) {
82  frame->AddFrame(m_widget, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 6, 2, 2));
83  frame->AddFrame(label, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 4, 0, 0));
84  } else {
85  frame->AddFrame(label, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
86  frame->AddFrame(m_widget, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 8, 2, 2));
87  }
88  return frame;
89 }
90 
92  assert(nullptr != m_param);
93  assert(nullptr != m_widget);
94  m_param->set((Long_t)id);
95  update();
96 }
97 
98 void FWEnumParameterSetter::setEnabled(bool x) { m_widget->SetEnabled(x); }
99 
100 //
101 // const member functions
102 //
103 
104 //
105 // static member functions
106 //
FWParameterSetterEditorBase * frame() const
void attach(FWParameterBase *) override
#define nullptr
const std::map< Long_t, std::string > & entryMap() const
TGFrame * build(TGFrame *iParent, bool labelBack=true) override
char const * label
void setEnabled(bool) override
const std::string & name() const