Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:01:20

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWEnumParameterSetter
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  matevz
0010 //         Created:  Fri Apr 30 15:17:33 CEST 2010
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "Fireworks/Core/interface/FWEnumParameterSetter.h"
0017 #include "TGComboBox.h"
0018 #include "TGLabel.h"
0019 #include <cassert>
0020 
0021 //
0022 // constants, enums and typedefs
0023 //
0024 
0025 //
0026 // static data member definitions
0027 //
0028 
0029 //
0030 // constructors and destructor
0031 //
0032 FWEnumParameterSetter::FWEnumParameterSetter() : m_param(nullptr), m_widget(nullptr) {}
0033 
0034 // FWEnumParameterSetter::FWEnumParameterSetter(const FWEnumParameterSetter& rhs)
0035 // {
0036 //    // do actual copying here;
0037 // }
0038 
0039 FWEnumParameterSetter::~FWEnumParameterSetter() {}
0040 
0041 //
0042 // assignment operators
0043 //
0044 // const FWEnumParameterSetter& FWEnumParameterSetter::operator=(const FWEnumParameterSetter& rhs)
0045 // {
0046 //   //An exception safe implementation is
0047 //   FWEnumParameterSetter temp(rhs);
0048 //   swap(rhs);
0049 //
0050 //   return *this;
0051 // }
0052 
0053 //
0054 // member functions
0055 //
0056 
0057 void FWEnumParameterSetter::attach(FWParameterBase* iParam) {
0058   m_param = dynamic_cast<FWEnumParameter*>(iParam);
0059   assert(nullptr != m_param);
0060 }
0061 
0062 TGFrame* FWEnumParameterSetter::build(TGFrame* iParent, bool labelBack) {
0063   TGCompositeFrame* frame = new TGHorizontalFrame(iParent);
0064 
0065   m_widget = new TGComboBox(frame);
0066   std::map<Long_t, std::string>::const_iterator me = m_param->entryMap().begin();
0067   UInt_t max_len = 0;
0068   while (me != m_param->entryMap().end()) {
0069     m_widget->AddEntry(me->second.c_str(), static_cast<Int_t>(me->first));
0070     if (me->second.length() > max_len)
0071       max_len = me->second.length();
0072     ++me;
0073   }
0074   m_widget->Resize(8 * max_len + 20, 20);
0075   m_widget->Select(static_cast<Int_t>(m_param->value()), kFALSE);
0076 
0077   m_widget->Connect("Selected(Int_t)", "FWEnumParameterSetter", this, "doUpdate(Int_t)");
0078 
0079   // label
0080   TGLabel* label = new TGLabel(frame, m_param->name().c_str());
0081   if (labelBack) {
0082     frame->AddFrame(m_widget, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 6, 2, 2));
0083     frame->AddFrame(label, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 4, 0, 0));
0084   } else {
0085     frame->AddFrame(label, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
0086     frame->AddFrame(m_widget, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 8, 2, 2));
0087   }
0088   return frame;
0089 }
0090 
0091 void FWEnumParameterSetter::doUpdate(Int_t id) {
0092   assert(nullptr != m_param);
0093   assert(nullptr != m_widget);
0094   m_param->set((Long_t)id);
0095   update();
0096 }
0097 
0098 void FWEnumParameterSetter::setEnabled(bool x) { m_widget->SetEnabled(x); }
0099 
0100 //
0101 // const member functions
0102 //
0103 
0104 //
0105 // static member functions
0106 //