CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/Fireworks/Core/src/FWProxyBuilderConfiguration.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWProxyBuilderConfiguration
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  
00010 //         Created:  Wed Jul 27 00:58:43 CEST 2011
00011 // $Id: FWProxyBuilderConfiguration.cc,v 1.8 2011/08/20 03:39:20 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include <iostream>
00018 #include <stdexcept>
00019 #include <boost/bind.hpp>
00020 
00021 #include "TGFrame.h"
00022 
00023 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
00024 #include "Fireworks/Core/interface/FWEventItem.h"
00025 #include "Fireworks/Core/interface/fwLog.h"
00026 #include "Fireworks/Core/interface/FWModelChangeManager.h"
00027 #include "Fireworks/Core/interface/FWItemChangeSignal.h"
00028 #include "Fireworks/Core/interface/FWConfiguration.h"
00029 #include "Fireworks/Core/interface/FWParameterBase.h"
00030 #include "Fireworks/Core/interface/FWGenericParameter.h"
00031 #include "Fireworks/Core/interface/FWEnumParameter.h"
00032 
00033 
00034 FWProxyBuilderConfiguration::FWProxyBuilderConfiguration(const FWConfiguration* c, const FWEventItem* item):
00035    m_txtConfig(c),
00036    m_item(item)
00037 {
00038 }
00039 
00040 FWProxyBuilderConfiguration::~FWProxyBuilderConfiguration()
00041 {
00042    delete m_txtConfig;
00043 }
00044 
00045 
00046 //______________________________________________________________________________
00047 
00048 void
00049 FWProxyBuilderConfiguration::addTo( FWConfiguration& iTo) const
00050 {
00051    if (begin() != end()) {
00052       FWConfiguration vTmp;
00053       FWConfigurableParameterizable::addTo(vTmp);
00054       iTo.addKeyValue("Var",vTmp, true);
00055    }
00056 }
00057 
00058 
00059 void
00060 FWProxyBuilderConfiguration::setFrom(const FWConfiguration& iFrom)
00061 {
00062    /*
00063      for(FWConfiguration::KeyValuesIt it = keyVals->begin(); it!= keyVals->end(); ++it)
00064      std::cout << it->first << "FWProxyBuilderConfiguration::setFrom  " << std::endl;
00065      }*/
00066 }
00067 
00068 
00069 //______________________________________________________________________________
00070 
00071 void 
00072 FWProxyBuilderConfiguration::makeSetter(TGCompositeFrame* frame, FWParameterBase* pb )
00073 {
00074    //  std::cout << "make setter " << pb->name() << std::endl;
00075 
00076    boost::shared_ptr<FWParameterSetterBase> ptr( FWParameterSetterBase::makeSetterFor(pb) );
00077    ptr->attach(pb, this); 
00078    TGFrame* tmpFrame = ptr->build(frame, false);
00079    frame->AddFrame(tmpFrame, new TGLayoutHints(kLHintsExpandX));
00080    m_setters.push_back(ptr);
00081 }
00082 
00083 void
00084 FWProxyBuilderConfiguration::populateFrame(TGCompositeFrame* settersFrame)
00085 {
00086    //  std::cout << "populate \n";
00087 
00088    TGCompositeFrame* frame =  new TGVerticalFrame(settersFrame);
00089    settersFrame->AddFrame(frame, new TGLayoutHints(kLHintsExpandX) );//|kLHintsExpandY
00090   
00091    for(const_iterator it =begin(); it != end(); ++it)
00092       makeSetter(frame, *it);
00093 
00094    settersFrame->MapSubwindows();   
00095 }
00096 
00097 //______________________________________________________________________________
00098 
00099 template <class T> FWGenericParameter<T>* FWProxyBuilderConfiguration::assertParam(const std::string& name, T def )
00100 {
00101    FWGenericParameter<T>*  mode = new FWGenericParameter<T>(this, name, def);
00102 
00103    //   std::cout << "FWProxyBuilderConfiguration::getVarParameter(). No parameter with name " << name << std::endl;
00104    if ( m_txtConfig) {
00105       const FWConfiguration* varConfig = m_txtConfig->keyValues() ? m_txtConfig->valueForKey("Var") : 0;
00106       if (varConfig) mode->setFrom(*varConfig);
00107    }
00108    mode->changed_.connect(boost::bind(&FWEventItem::proxyConfigChanged, (FWEventItem*)m_item));
00109    return mode;
00110 }
00111 
00112 
00113 
00114 template <class T> FWGenericParameterWithRange<T>* FWProxyBuilderConfiguration::assertParam(const std::string& name, T def, T min, T max )
00115 {
00116    FWGenericParameterWithRange<T>*  mode = new FWGenericParameterWithRange<T>(this, name, def, min, max);
00117 
00118    //   std::cout << "FWProxyBuilderConfiguration::getVarParameter(). No parameter with name " << name << std::endl;
00119    const FWConfiguration* varConfig = m_txtConfig &&  m_txtConfig->keyValues() ? m_txtConfig->valueForKey("Var") : 0;
00120    if (varConfig) mode->setFrom(*varConfig);
00121 
00122    mode->changed_.connect(boost::bind(&FWEventItem::proxyConfigChanged, (FWEventItem*)m_item));
00123    return mode;
00124 }
00125 
00126 template <class T> T FWProxyBuilderConfiguration::value(const std::string& pname)
00127 {
00128    FWGenericParameter<T>* param = 0;
00129 
00130    for (FWConfigurableParameterizable::const_iterator i = begin(); i != end(); ++i) 
00131    {
00132       if ((*i)->name() == pname)
00133       {
00134          param = (FWGenericParameter<T>* )(*i);
00135          break;
00136       }
00137    }
00138 
00139    if (param) 
00140       return param->value();
00141    else
00142       throw std::runtime_error("Invalid parameter request.");
00143 }
00144 
00145 // explicit template instantiation
00146 
00147 template bool FWProxyBuilderConfiguration::value<bool>(const std::string& name);
00148 template long FWProxyBuilderConfiguration::value<long>(const std::string& name);
00149 template double FWProxyBuilderConfiguration::value<double>(const std::string& name);
00150 
00151 template FWGenericParameter<bool>* FWProxyBuilderConfiguration::assertParam(const std::string& name, bool def);
00152 template FWGenericParameterWithRange<long>* FWProxyBuilderConfiguration::assertParam(const std::string& name, long def,long min, long max);
00153 template FWGenericParameterWithRange<double>* FWProxyBuilderConfiguration::assertParam(const std::string& name, double def,double min, double max);