CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/Fireworks/Core/src/CmsShowEDI.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     CmsShowEDI
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Joshua Berger
00010 //         Created:  Mon Jun 23 15:48:11 EDT 2008
00011 // $Id: CmsShowEDI.cc,v 1.47 2012/02/22 03:45:58 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 #include <iostream>
00016 #include <sstream>
00017 #include <sigc++/sigc++.h>
00018 #include <boost/bind.hpp>
00019 #include "TClass.h"
00020 #include "TGFrame.h"
00021 #include "TGTab.h"
00022 #include "TGButton.h"
00023 #include "TGLabel.h"
00024 #include "TGString.h"
00025 #include "TColor.h"
00026 #include "TG3DLine.h"
00027 #include "TGNumberEntry.h"
00028 #include "TGTextEntry.h"
00029 #include "TGTextView.h"
00030 #include "TGLayout.h"
00031 #include "TGFont.h"
00032 #include "TEveManager.h"
00033 #include "TGSlider.h"
00034 #include "TGMsgBox.h"
00035 #include "TGComboBox.h"
00036 
00037 // user include files
00038 #include "Fireworks/Core/interface/CmsShowEDI.h"
00039 #include "Fireworks/Core/interface/FWSelectionManager.h"
00040 #include "Fireworks/Core/interface/FWDisplayProperties.h"
00041 #include "Fireworks/Core/interface/FWEventItem.h"
00042 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
00043 #include "Fireworks/Core/src/FWColorSelect.h"
00044 #include "Fireworks/Core/interface/FWModelChangeSignal.h"
00045 #include "Fireworks/Core/interface/FWModelExpressionSelector.h"
00046 #include "Fireworks/Core/interface/FWModelChangeManager.h"
00047 #include "Fireworks/Core/interface/FWColorManager.h"
00048 #include "Fireworks/Core/interface/FWExpressionException.h"
00049 #include "Fireworks/Core/src/FWGUIValidatingTextEntry.h"
00050 #include "Fireworks/Core/src/FWExpressionValidator.h"
00051 #include "Fireworks/Core/src/FWDialogBuilder.h"
00052 
00053 //
00054 // constants, enums and typedefs
00056 
00057 //
00058 // static data member definitions
00059 //
00060 
00061 //
00062 // constructors and destructor
00063 //
00064 CmsShowEDI::CmsShowEDI(const TGWindow* p, UInt_t w, UInt_t h, FWSelectionManager* selMgr, FWColorManager* colorMgr) :
00065    TGTransientFrame(gClient->GetDefaultRoot(), p, w, h),
00066    m_item(0),
00067    m_validator(new FWExpressionValidator),
00068    m_colorManager(colorMgr),
00069    m_settersFrame(0)
00070 {
00071    m_selectionManager = selMgr;
00072    SetCleanup(kDeepCleanup);
00073 
00074    m_selectionManager->itemSelectionChanged_.connect(boost::bind(&CmsShowEDI::fillEDIFrame,this));
00075 
00076    TGVerticalFrame* vf = new TGVerticalFrame(this);
00077    AddFrame(vf, new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 0, 0, 0, 0));
00078    FWDialogBuilder builder(vf);
00079 
00080    builder.indent(0)
00081       .addLabel(" ", 14, 2, &m_objectLabel)
00082       .vSpacer()
00083       .tabs(&m_tabs)
00084       .beginTab("Graphics")
00085       .indent(3)
00086       .addLabel("Color", 8)
00087       .addColorPicker(colorMgr, &m_colorSelectWidget).expand(false)
00088       .addHSeparator()
00089       .addLabel("Opacity", 8)
00090       .addHSlider(150, &m_opacitySlider)
00091       .addHSeparator()
00092       .addCheckbox("Visible", &m_isVisibleButton)
00093       .addHSeparator()
00094       .addLabel("Drawing order", 8)
00095       .addTextButton("To back", &m_backButton).floatLeft().expand(false)
00096       .addNumberEntry(0.0, 4, TGNumberFormat::kNESInteger,
00097                       FWEventItem::minLayerValue(), 
00098                       FWEventItem::maxLayerValue(), 
00099                       &m_layerEntry).expand(false).floatLeft()
00100       .addTextButton("To front", &m_frontButton).expand(false)
00101       .vSpacer()
00102       .addHSeparator()
00103       .endTab()
00104       .beginTab("Filter")
00105       .indent(3)
00106       .addLabel("Expression", 8)
00107       .addValidatingTextEntry(0, &m_filterExpressionEntry).floatLeft()
00108       .addTextButton("Filter", &m_filterButton).expand(false)
00109       .addTextView("", &m_filterError)
00110       .vSpacer()
00111       .endTab()
00112       .beginTab("Select")
00113       .indent(3)
00114       .addLabel("Expression", 8)
00115       .addValidatingTextEntry(0, &m_selectExpressionEntry)
00116       .addTextButton("Select", &m_selectButton).floatLeft().expand(false)
00117       .addTextButton("Select all", &m_selectAllButton).expand(false)
00118       .addTextView("", &m_selectError)
00119       .vSpacer()
00120       .endTab()
00121       .beginTab("Data")
00122       .indent(3)
00123       .addLabel("Name:", 8)
00124       .addTextEntry("None", &m_nameEntry)
00125       .addLabel("Labels:", 8)
00126       .addLabel("Type:", 8)
00127       .addTextEntry("None", &m_typeEntry)
00128       .addLabel("Module:", 8)
00129       .addTextEntry("None", &m_moduleEntry)
00130       .addLabel("Instance:", 8)
00131       .addTextEntry("None", &m_instanceEntry)
00132       .addLabel("Process:", 8)
00133       .addTextEntry("None", &m_processEntry)
00134       .addHSeparator()
00135       .addTextButton("Remove collection", &m_removeButton).expand(false)
00136       .vSpacer()
00137       .endTab()
00138       .untabs();
00139 
00140    m_filterError->SetForegroundColor(gVirtualX->GetPixel(kRed));
00141    m_filterError->SetBackgroundColor(TGFrame::GetDefaultFrameBackground());
00142    m_filterError->ChangeOptions(0);
00143    
00144    m_selectError->SetForegroundColor(gVirtualX->GetPixel(kRed));
00145    m_selectError->SetBackgroundColor(TGFrame::GetDefaultFrameBackground());
00146    m_selectError->ChangeOptions(0);
00147 
00148    m_filterExpressionEntry->setValidator(m_validator);
00149    m_selectExpressionEntry->setValidator(m_validator);
00150 
00151    m_colorSelectWidget->Connect("ColorChosen(Color_t)", "CmsShowEDI", this, "changeItemColor(Color_t)");
00152    m_opacitySlider->Connect("PositionChanged(Int_t)", "CmsShowEDI", this, "changeItemOpacity(Int_t)");
00153    m_isVisibleButton->Connect("Toggled(Bool_t)", "CmsShowEDI", this, "toggleItemVisible(Bool_t)");
00154    m_filterExpressionEntry->Connect("ReturnPressed()", "CmsShowEDI", this, "runFilter()");
00155    m_filterButton->Connect("Clicked()", "CmsShowEDI", this, "runFilter()");
00156    m_selectExpressionEntry->Connect("ReturnPressed()", "CmsShowEDI", this, "runSelection()");
00157    m_selectButton->Connect("Clicked()", "CmsShowEDI", this, "runSelection()");
00158    m_removeButton->Connect("Clicked()", "CmsShowEDI", this, "removeItem()");
00159    m_selectAllButton->Connect("Clicked()", "CmsShowEDI", this, "selectAll()");
00160    m_frontButton->Connect("Clicked()","CmsShowEDI",this,"moveToFront()");
00161    m_backButton->Connect("Clicked()","CmsShowEDI",this,"moveToBack()");
00162    m_layerEntry->Connect("ValueSet(Long_t)","CmsShowEDI",this,"moveToLayer(Long_t)");
00163    
00164 
00165    TGCompositeFrame* cf = m_tabs->GetTabContainer(0);
00166    m_settersFrame = new TGVerticalFrame(cf);
00167    m_settersFrame->SetCleanup(kDeepCleanup);
00168    // m_settersFrame->SetBackgroundColor(0xff00ff);
00169    cf->AddFrame(m_settersFrame, new TGLayoutHints(kLHintsExpandX| kLHintsExpandY ));
00170 
00171    SetWindowName("Collection Controller");
00172    MapSubwindows();
00173    Resize(GetDefaultSize());
00174    Layout();
00175 
00176    fillEDIFrame();
00177 }
00178 
00179 // CmsShowEDI::CmsShowEDI(const CmsShowEDI& rhs)
00180 // {
00181 //    // do actual copying here;
00182 // }
00183 
00184 CmsShowEDI::~CmsShowEDI()
00185 {
00186    disconnectAll();
00187    m_colorSelectWidget->Disconnect("ColorSelected(Pixel_t)", this, "changeItemColor(Pixel_t)");
00188    m_opacitySlider->Disconnect("PositionChanged(Int_t)", this, "changeItemColor");
00189    m_isVisibleButton->Disconnect("Toggled(Bool_t)", this, "toggleItemVisible(Bool_t)");
00190    m_filterExpressionEntry->Disconnect("ReturnPressed()", this, "runFilter()");
00191    m_selectExpressionEntry->Disconnect("ReturnPressed()", this, "runSelection()");
00192    m_filterButton->Disconnect("Clicked()", this, "runFilter()");
00193    m_selectButton->Disconnect("Clicked()", this, "runSelection()");
00194    m_selectAllButton->Disconnect("Clicked()", this, "selectAll()");
00195    m_removeButton->Disconnect("Clicked()", this, "removeItem()");
00196    m_frontButton->Disconnect("Clicked()",this,"moveToFront()");
00197    m_backButton->Disconnect("Clicked()",this,"moveToBack()");
00198    m_layerEntry->Disconnect("ValueSet(Long_t)",this,"moveToLayer(Long_t)");
00199    //  delete m_objectLabel;
00200    //  delete m_colorSelectWidget;
00201    //  delete m_isVisibleButton;
00202    delete m_validator;
00203 }
00204 
00205 //
00206 // assignment operators
00207 //
00208 // const CmsShowEDI& CmsShowEDI::operator=(const CmsShowEDI& rhs)
00209 // {
00210 //   //An exception safe implementation is
00211 //   CmsShowEDI temp(rhs);
00212 //   swap(rhs);
00213 //
00214 //   return *this;
00215 // }
00216 
00217 //
00218 // member functions
00219 //
00220 
00221 void CmsShowEDI::clearPBFrame()
00222 {
00223    if (!m_settersFrame->GetList()->IsEmpty())
00224    {
00225       // printf("remove FRAME \n");
00226       TGFrameElement *el = (TGFrameElement*) m_settersFrame->GetList()->First();
00227       TGFrame* f = el->fFrame;
00228       f->UnmapWindow();
00229       m_settersFrame->RemoveFrame(f);
00230       f->DestroyWindow();
00231    }
00232 }
00233 
00234 void
00235 CmsShowEDI::fillEDIFrame() {
00236    FWEventItem* iItem =0;
00237    bool multipleCollections = false;
00238    if(!m_selectionManager->selectedItems().empty()) {
00239       if(m_selectionManager->selectedItems().size()==1) {
00240          iItem=*(m_selectionManager->selectedItems().begin());
00241       } else {
00242          multipleCollections=true;
00243       }
00244    }
00245    //m_item can be zero because we had 0 or many collections selected
00246    if (0 == m_item || iItem != m_item) {
00247       disconnectAll();
00248       m_item = iItem;
00249       if(0 != m_item) {
00250          const FWDisplayProperties &p = iItem->defaultDisplayProperties();
00251          m_objectLabel->SetText(iItem->name().c_str());
00252          m_colorSelectWidget->SetColorByIndex(p.color(),kFALSE);
00253          m_opacitySlider->SetPosition(100 - p.transparency());
00254          m_isVisibleButton->SetDisabledAndSelected(p.isVisible());
00255          m_validator->setType(ROOT::Reflex::Type::ByTypeInfo(*(iItem->modelType()->GetTypeInfo())));
00256          m_filterExpressionEntry->SetText(iItem->filterExpression().c_str());
00257          m_filterError->Clear();
00258          m_selectError->Clear();
00259          m_nameEntry->SetText(iItem->name().c_str());
00260          m_typeEntry->SetText(iItem->type()->GetName());
00261          m_moduleEntry->SetText(iItem->moduleLabel().c_str());
00262          m_instanceEntry->SetText(iItem->productInstanceLabel().c_str());
00263          m_processEntry->SetText(iItem->processName().c_str());
00264          //  else m_isVisibleButton->SetState(kButtonDown, kFALSE);
00265          m_colorSelectWidget->SetEnabled(kTRUE);
00266          m_opacitySlider->SetEnabled(kTRUE);
00267          m_isVisibleButton->SetEnabled(kTRUE);
00268          m_filterExpressionEntry->SetEnabled(kTRUE);
00269          m_selectExpressionEntry->SetEnabled(kTRUE);
00270          m_filterButton->SetEnabled(kTRUE);
00271          m_selectButton->SetEnabled(kTRUE);
00272          m_selectAllButton->SetEnabled(kTRUE);
00273          m_removeButton->SetEnabled(kTRUE);
00274          updateLayerControls();
00275          m_layerEntry->SetState(kTRUE);
00276          m_displayChangedConn = m_item->defaultDisplayPropertiesChanged_.connect(boost::bind(&CmsShowEDI::updateDisplay, this));
00277          m_modelChangedConn = m_item->changed_.connect(boost::bind(&CmsShowEDI::updateFilter, this));
00278          //    m_selectionChangedConn = m_selectionManager->selectionChanged_.connect(boost::bind(&CmsShowEDI::updateSelection, this));
00279          m_destroyedConn = m_item->goingToBeDestroyed_.connect(boost::bind(&CmsShowEDI::disconnectAll, this));
00280                        
00281          clearPBFrame();
00282          m_item->getConfig()->populateFrame(m_settersFrame);
00283       }
00284       else if(multipleCollections) {
00285          std::ostringstream s;
00286          s<<m_selectionManager->selectedItems().size()<<" Collections Selected";
00287          m_objectLabel->SetText(s.str().c_str());
00288       }
00289 
00290       Resize(GetDefaultSize());
00291       Layout();
00292    }
00293 }
00294 
00295 void
00296 CmsShowEDI::removeItem() {
00297    Int_t chosen=0;
00298    std::string message("This action will remove the ");
00299    message += m_item->name();
00300    message +=" collection from the display."
00301               "\nIf you wish to return the collection you would have to use the 'Add Collection' window.";
00302    new TGMsgBox(gClient->GetDefaultRoot(),
00303                 this,
00304                 "Remove Collection Confirmation",
00305                 message.c_str(),
00306                 kMBIconExclamation,
00307                 kMBCancel | kMBApply,
00308                 &chosen);
00309    if(kMBApply == chosen) {
00310       m_item->destroy();
00311       m_item = 0;
00312       //make sure the ROOT global editor does not try to use this
00313       gEve->EditElement(0);
00314       gEve->Redraw3D();
00315    }
00316 }
00317 
00318 void
00319 CmsShowEDI::updateDisplay() {
00320    //std::cout<<"Updating display"<<std::endl;
00321    const FWDisplayProperties &props = m_item->defaultDisplayProperties();
00322    m_colorSelectWidget->SetColorByIndex(props.color(),kFALSE);
00323    m_opacitySlider->SetPosition(100 - props.transparency());
00324    m_isVisibleButton->SetState(props.isVisible() ? kButtonDown : kButtonUp, kFALSE);
00325 }
00326 
00327 void
00328 CmsShowEDI::updateLayerControls()
00329 {
00330    m_backButton->SetEnabled(!m_item->isInBack());
00331    m_frontButton->SetEnabled(!m_item->isInFront());
00332    m_layerEntry->SetIntNumber(m_item->layer());
00333 }
00334 void
00335 CmsShowEDI::moveToBack()
00336 {
00337    m_item->moveToBack();
00338    updateLayerControls();
00339 }
00340 void
00341 CmsShowEDI::moveToFront()
00342 {
00343    m_item->moveToFront();
00344    updateLayerControls();
00345 }
00346 void
00347 CmsShowEDI::moveToLayer(Long_t)
00348 {
00349    m_item->moveToLayer(static_cast<Int_t>(m_layerEntry->GetIntNumber()));
00350    updateLayerControls(); 
00351 }
00352 
00353 void
00354 CmsShowEDI::updateFilter() {
00355    m_filterExpressionEntry->SetText(m_item->filterExpression().c_str());
00356 }
00357 
00358 void
00359 CmsShowEDI::disconnectAll() {
00360    m_objectLabel->SetText("No Collection Selected");
00361    clearPBFrame();
00362    if(0 != m_item) {
00363       m_displayChangedConn.disconnect();
00364       m_modelChangedConn.disconnect();
00365       m_destroyedConn.disconnect();
00366       m_item = 0;
00367       m_colorSelectWidget->SetColorByIndex(0,kFALSE);
00368       m_opacitySlider->SetPosition(100);
00369       m_isVisibleButton->SetDisabledAndSelected(kTRUE);
00370       m_filterExpressionEntry->SetText(0);
00371       m_selectExpressionEntry->SetText(0);
00372       m_nameEntry->SetText(0);
00373       m_typeEntry->SetText(0);
00374       m_moduleEntry->SetText(0);
00375       m_instanceEntry->SetText(0);
00376       m_processEntry->SetText(0);
00377       //  else m_isVisibleButton->SetState(kButtonDown, kFALSE);
00378       m_colorSelectWidget->SetEnabled(kFALSE);
00379       m_opacitySlider->SetEnabled(kFALSE);
00380       
00381       m_isVisibleButton->SetEnabled(kFALSE);
00382       m_filterExpressionEntry->SetEnabled(kFALSE);
00383       m_filterButton->SetEnabled(kFALSE);
00384       m_selectExpressionEntry->SetEnabled(kFALSE);
00385       m_selectButton->SetEnabled(kFALSE);
00386       m_selectAllButton->SetEnabled(kFALSE);
00387       m_removeButton->SetEnabled(kFALSE);
00388       m_backButton->SetEnabled(kFALSE);
00389       m_frontButton->SetEnabled(kFALSE);
00390       m_layerEntry->SetIntNumber(0);
00391       m_layerEntry->SetState(kFALSE);
00392       m_layerEntry->GetNumberEntry()->SetEnabled(kFALSE);
00393       m_layerEntry->GetButtonUp()->SetEnabled(kFALSE);
00394       m_layerEntry->GetButtonDown()->SetEnabled(kFALSE);
00395    }
00396 }
00397 
00404 void
00405 CmsShowEDI::changeItemColor(Color_t color) {
00406    FWDisplayProperties changeProperties = m_item->defaultDisplayProperties();
00407    changeProperties.setColor(color);
00408    m_item->setDefaultDisplayProperties(changeProperties);
00409 }
00410 
00412 void
00413 CmsShowEDI::toggleItemVisible(Bool_t on) {
00414    FWDisplayProperties changeProperties = m_item->defaultDisplayProperties();
00415    changeProperties.setIsVisible(on);
00416    m_item->setDefaultDisplayProperties(changeProperties);
00417 }
00418 
00426 void
00427 CmsShowEDI::changeItemOpacity(Int_t opacity) {
00428    FWDisplayProperties changeProperties = m_item->defaultDisplayProperties();
00429    changeProperties.setTransparency(100 - opacity);
00430    m_item->setDefaultDisplayProperties(changeProperties);
00431 }
00432 
00433 void
00434 CmsShowEDI::runFilter() {
00435    const std::string filter(m_filterExpressionEntry->GetText());
00436    if (m_item != 0) {
00437       try {
00438          m_filterError->Clear();
00439          m_item->setFilterExpression(filter);
00440       } catch( const FWExpressionException& e) {
00441          m_filterError->AddLine(e.what().c_str());
00442          m_filterError->Update();
00443          if(e.column() > -1) {
00444             m_filterExpressionEntry->SetCursorPosition(e.column());
00445          }
00446       }
00447    }
00448 }
00449 
00450 void
00451 CmsShowEDI::runSelection() {
00452    FWModelExpressionSelector selector;
00453    const std::string selection(m_selectExpressionEntry->GetText());
00454    if (m_item != 0)
00455    {
00456       try
00457       {
00458          m_selectError->Clear();
00459          //NOTE call clearModelSelectionLeaveItem so that the item does not get deselected
00460          // just for safety use a copy of the pointer to m_item
00461          FWEventItem* item = m_item;
00462          item->selectionManager()-> clearModelSelectionLeaveItem();
00463 
00464          selector.select(item, selection);
00465       }
00466       catch( const FWExpressionException& e)
00467       {
00468          m_selectError->AddLine(e.what().c_str());
00469          m_selectError->Update();
00470          if (e.column() > -1)
00471          {
00472             m_selectExpressionEntry->SetCursorPosition(e.column());
00473          }
00474       }
00475    }
00476 }
00477 
00478 void
00479 CmsShowEDI::selectAll()
00480 {
00481    FWChangeSentry sentry(*(m_item->changeManager()));
00482    for (int i = 0; i < static_cast<int>(m_item->size()); i++)
00483    {
00484       m_item->select(i);
00485    }
00486 }
00487 void 
00488 CmsShowEDI::show(FWDataCategories iToView)
00489 {
00490    m_tabs->SetTab(iToView);
00491 }
00492 
00493 /* Called by FWGUIManager when change background/colorset. */
00494 void 
00495 CmsShowEDI::colorSetChanged()
00496 {
00497    if (m_item)
00498    {
00499       const FWDisplayProperties &p = m_item->defaultDisplayProperties();
00500       m_colorSelectWidget->SetColorByIndex(p.color(),kFALSE);
00501    }
00502 }