Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:16

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWLongParameterSetter
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Mon Mar 10 11:22:32 CDT 2008
0011 //
0012 
0013 // system include files
0014 #include "TGLabel.h"
0015 #include "TGNumberEntry.h"
0016 
0017 #include <cassert>
0018 #include <iostream>
0019 
0020 // user include files
0021 #include "Fireworks/Core/src/FWLongParameterSetter.h"
0022 
0023 //
0024 // constants, enums and typedefs
0025 //
0026 
0027 //
0028 // static data member definitions
0029 //
0030 
0031 //
0032 // constructors and destructor
0033 //
0034 FWLongParameterSetter::FWLongParameterSetter() : m_param(nullptr), m_widget(nullptr) {}
0035 
0036 // FWLongParameterSetter::FWLongParameterSetter(const FWLongParameterSetter& rhs)
0037 // {
0038 //    // do actual copying here;
0039 // }
0040 
0041 FWLongParameterSetter::~FWLongParameterSetter() {}
0042 
0043 //
0044 // assignment operators
0045 //
0046 // const FWLongParameterSetter& FWLongParameterSetter::operator=(const FWLongParameterSetter& rhs)
0047 // {
0048 //   //An exception safe implementation is
0049 //   FWLongParameterSetter temp(rhs);
0050 //   swap(rhs);
0051 //
0052 //   return *this;
0053 // }
0054 
0055 //
0056 // member functions
0057 //
0058 
0059 void FWLongParameterSetter::attach(FWParameterBase* iParam) {
0060   m_param = dynamic_cast<FWLongParameter*>(iParam);
0061   assert(nullptr != m_param);
0062 }
0063 
0064 TGFrame* FWLongParameterSetter::build(TGFrame* iParent, bool labelBack) {
0065   TGCompositeFrame* frame = new TGHorizontalFrame(iParent);
0066 
0067   // number entry widget
0068   TGNumberFormat::ELimit limits =
0069       m_param->min() == m_param->max()
0070           ? TGNumberFormat::kNELNoLimits
0071           : (m_param->min() > m_param->max() ? TGNumberFormat::kNELLimitMin : TGNumberFormat::kNELLimitMinMax);
0072   double min = 0;
0073   double max = 1;
0074   if (m_param->min() != m_param->max()) {
0075     min = m_param->min();
0076     max = m_param->max();
0077   }
0078   m_widget = new TGNumberEntry(frame,
0079                                m_param->value(),
0080                                5,                              // number of digits
0081                                0,                              // widget ID
0082                                TGNumberFormat::kNESInteger,    // style
0083                                TGNumberFormat::kNEAAnyNumber,  // input value filter
0084                                limits,                         // specify limits
0085                                min,                            // min value
0086                                max);                           // max value
0087 
0088   m_widget->Connect("ValueSet(Long_t)", "FWLongParameterSetter", this, "doUpdate(Long_t)");
0089 
0090   // label
0091   TGLabel* label = new TGLabel(frame, m_param->name().c_str());
0092   if (labelBack) {
0093     frame->AddFrame(m_widget, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 6, 2, 2));
0094     frame->AddFrame(label, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 0, 0));
0095   } else {
0096     frame->AddFrame(label, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
0097     frame->AddFrame(m_widget, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 8, 2, 2));
0098   }
0099 
0100   return frame;
0101 }
0102 
0103 void FWLongParameterSetter::doUpdate(Long_t) {
0104   //std::cout <<"doUpdate called"<<std::endl;
0105 
0106   // Idiotic TGNumberEntry arrow buttons can send several events and if
0107   // individual event processing takes longer it can happen that the widget
0108   // gets detroyed in the meantime. So, process all events from arrows as
0109   // soon as possible.
0110   static bool in_update = false;
0111   if (in_update)
0112     return;
0113   in_update = true;
0114   gClient->ProcessEventsFor((TGWindow*)gTQSender);
0115   in_update = false;
0116 
0117   assert(nullptr != m_param);
0118   assert(nullptr != m_widget);
0119   //std::cout <<m_widget->GetNumberEntry()->GetNumber()<<std::endl;
0120   m_param->set(m_widget->GetNumberEntry()->GetIntNumber());
0121   update();
0122 }
0123 
0124 //
0125 // const member functions
0126 //
0127 
0128 //
0129 // static member functions
0130 //