CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/Fireworks/Core/src/FWLongParameterSetter.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWLongParameterSetter
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Mon Mar 10 11:22:32 CDT 2008
00011 // $Id: FWLongParameterSetter.cc,v 1.8 2012/02/22 03:45:59 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 #include "TGLabel.h"
00016 #include "TGNumberEntry.h"
00017 
00018 #include <assert.h>
00019 #include <iostream>
00020 
00021 // user include files
00022 #include "Fireworks/Core/src/FWLongParameterSetter.h"
00023 
00024 
00025 //
00026 // constants, enums and typedefs
00027 //
00028 
00029 //
00030 // static data member definitions
00031 //
00032 
00033 //
00034 // constructors and destructor
00035 //
00036 FWLongParameterSetter::FWLongParameterSetter() :
00037    m_param(0),
00038    m_widget(0)
00039 {
00040 }
00041 
00042 // FWLongParameterSetter::FWLongParameterSetter(const FWLongParameterSetter& rhs)
00043 // {
00044 //    // do actual copying here;
00045 // }
00046 
00047 FWLongParameterSetter::~FWLongParameterSetter()
00048 {
00049 }
00050 
00051 //
00052 // assignment operators
00053 //
00054 // const FWLongParameterSetter& FWLongParameterSetter::operator=(const FWLongParameterSetter& rhs)
00055 // {
00056 //   //An exception safe implementation is
00057 //   FWLongParameterSetter temp(rhs);
00058 //   swap(rhs);
00059 //
00060 //   return *this;
00061 // }
00062 
00063 //
00064 // member functions
00065 //
00066 
00067 void
00068 FWLongParameterSetter::attach(FWParameterBase* iParam)
00069 {
00070    m_param = dynamic_cast<FWLongParameter*>(iParam);
00071    assert(0!=m_param);
00072 }
00073 
00074 TGFrame*
00075 FWLongParameterSetter::build(TGFrame* iParent, bool labelBack)
00076 {
00077    TGCompositeFrame* frame = new TGHorizontalFrame(iParent);
00078 
00079    // number entry widget
00080    TGNumberFormat::ELimit limits = m_param->min()==m_param->max() ?
00081       TGNumberFormat::kNELNoLimits :
00082       ( m_param->min() > m_param->max() ? TGNumberFormat::kNELLimitMin : TGNumberFormat::kNELLimitMinMax);
00083    double min = 0;
00084    double max = 1;
00085    if (m_param->min()!=m_param->max())
00086    {
00087       min=m_param->min();
00088       max=m_param->max();
00089    }
00090    m_widget = new TGNumberEntry
00091       (frame, m_param->value(),
00092        5,                         // number of digits
00093        0,                         // widget ID
00094        TGNumberFormat::kNESInteger, // style
00095        TGNumberFormat::kNEAAnyNumber, // input value filter
00096        limits,                    // specify limits
00097        min,                       // min value
00098        max);                      // max value
00099 
00100    m_widget->Connect("ValueSet(Long_t)", "FWLongParameterSetter", this, "doUpdate(Long_t)");
00101 
00102    // label
00103    TGLabel* label = new TGLabel(frame, m_param->name().c_str());
00104    if (labelBack)
00105    {
00106       frame->AddFrame(m_widget, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2,6,2,2));
00107       frame->AddFrame(label,    new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2,2,0,0));
00108    }
00109    else
00110    {
00111       frame->AddFrame(label,    new TGLayoutHints(kLHintsLeft|kLHintsCenterY));
00112       frame->AddFrame(m_widget, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2,8,2,2));
00113    }
00114 
00115    return frame;
00116 }
00117 
00118 void
00119 FWLongParameterSetter::doUpdate(Long_t)
00120 {
00121    //std::cout <<"doUpdate called"<<std::endl;
00122 
00123    // Idiotic TGNumberEntry arrow buttons can send several events and if
00124    // individual event processing takes longer it can happen that the widget
00125    // gets detroyed in the meantime. So, process all events from arrows as
00126    // soon as possible.
00127    static bool in_update = false;
00128    if (in_update)
00129       return;
00130    in_update = true;
00131    gClient->ProcessEventsFor((TGWindow*)gTQSender);
00132    in_update = false;
00133       
00134    assert(0!=m_param);
00135    assert(0!=m_widget);
00136    //std::cout <<m_widget->GetNumberEntry()->GetNumber()<<std::endl;
00137    m_param->set(m_widget->GetNumberEntry()->GetIntNumber());
00138    update();
00139 }
00140 
00141 //
00142 // const member functions
00143 //
00144 
00145 //
00146 // static member functions
00147 //