CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/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.48.2.1 2013/04/09 00:51:49 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).floatLeft()
00118       .addTextButton("Unselect all", &m_deselectAllButton).expand(false)
00119       .indent(3)
00120       .addLabel("Color Selection", 8)
00121       .addColorPicker(colorMgr, &m_cw).expand(false)
00122       .addTextView("", &m_selectError)
00123       .vSpacer()
00124       .endTab()
00125       .beginTab("Data")
00126       .indent(3)
00127       .addLabel("Name:", 8)
00128       .addTextEntry("None", &m_nameEntry)
00129       .addLabel("Labels:", 8)
00130       .addLabel("Type:", 8)
00131       .addTextEntry("None", &m_typeEntry)
00132       .addLabel("Module:", 8)
00133       .addTextEntry("None", &m_moduleEntry)
00134       .addLabel("Instance:", 8)
00135       .addTextEntry("None", &m_instanceEntry)
00136       .addLabel("Process:", 8)
00137       .addTextEntry("None", &m_processEntry)
00138       .addHSeparator()
00139       .addTextButton("Remove collection", &m_removeButton).expand(false)
00140       .vSpacer()
00141       .endTab()
00142       .untabs();
00143 
00144    m_filterError->SetForegroundColor(gVirtualX->GetPixel(kRed));
00145    m_filterError->SetBackgroundColor(TGFrame::GetDefaultFrameBackground());
00146    m_filterError->ChangeOptions(0);
00147    
00148    m_selectError->SetForegroundColor(gVirtualX->GetPixel(kRed));
00149    m_selectError->SetBackgroundColor(TGFrame::GetDefaultFrameBackground());
00150    m_selectError->ChangeOptions(0);
00151 
00152    m_filterExpressionEntry->setValidator(m_validator);
00153    m_selectExpressionEntry->setValidator(m_validator);
00154 
00155    m_colorSelectWidget->Connect("ColorChosen(Color_t)", "CmsShowEDI", this, "changeItemColor(Color_t)");
00156    m_cw->Connect("ColorChosen(Color_t)", "CmsShowEDI", this, "changeSelectionColor(Color_t)");
00157    m_opacitySlider->Connect("PositionChanged(Int_t)", "CmsShowEDI", this, "changeItemOpacity(Int_t)");
00158    m_isVisibleButton->Connect("Toggled(Bool_t)", "CmsShowEDI", this, "toggleItemVisible(Bool_t)");
00159    m_filterExpressionEntry->Connect("ReturnPressed()", "CmsShowEDI", this, "runFilter()");
00160    m_filterButton->Connect("Clicked()", "CmsShowEDI", this, "runFilter()");
00161    m_selectExpressionEntry->Connect("ReturnPressed()", "CmsShowEDI", this, "runSelection()");
00162    m_selectButton->Connect("Clicked()", "CmsShowEDI", this, "runSelection()");
00163    m_removeButton->Connect("Clicked()", "CmsShowEDI", this, "removeItem()");
00164    m_selectAllButton->Connect("Clicked()", "CmsShowEDI", this, "selectAll()");
00165    m_deselectAllButton->Connect("Clicked()", "CmsShowEDI", this, "deselectAll()");
00166    m_frontButton->Connect("Clicked()","CmsShowEDI",this,"moveToFront()");
00167    m_backButton->Connect("Clicked()","CmsShowEDI",this,"moveToBack()");
00168    m_layerEntry->Connect("ValueSet(Long_t)","CmsShowEDI",this,"moveToLayer(Long_t)");
00169    
00170 
00171    TGCompositeFrame* cf = m_tabs->GetTabContainer(0);
00172    m_settersFrame = new TGVerticalFrame(cf);
00173    m_settersFrame->SetCleanup(kDeepCleanup);
00174    // m_settersFrame->SetBackgroundColor(0xff00ff);
00175    cf->AddFrame(m_settersFrame, new TGLayoutHints(kLHintsExpandX| kLHintsExpandY ));
00176 
00177    SetWindowName("Collection Controller");
00178    MapSubwindows();
00179    Resize(GetDefaultSize());
00180    Layout();
00181 
00182    fillEDIFrame();
00183 }
00184 
00185 // CmsShowEDI::CmsShowEDI(const CmsShowEDI& rhs)
00186 // {
00187 //    // do actual copying here;
00188 // }
00189 
00190 CmsShowEDI::~CmsShowEDI()
00191 {
00192    disconnectAll();
00193    m_colorSelectWidget->Disconnect("ColorSelected(Pixel_t)", this, "changeItemColor(Pixel_t)");
00194    m_cw->Disconnect("ColorSelected(Pixel_t)", this, "changeSelectionColor(Pixel_t)");
00195    m_opacitySlider->Disconnect("PositionChanged(Int_t)", this, "changeItemColor");
00196    m_isVisibleButton->Disconnect("Toggled(Bool_t)", this, "toggleItemVisible(Bool_t)");
00197    m_filterExpressionEntry->Disconnect("ReturnPressed()", this, "runFilter()");
00198    m_selectExpressionEntry->Disconnect("ReturnPressed()", this, "runSelection()");
00199    m_filterButton->Disconnect("Clicked()", this, "runFilter()");
00200    m_selectButton->Disconnect("Clicked()", this, "runSelection()");
00201    m_selectAllButton->Disconnect("Clicked()", this, "selectAll()");
00202    m_deselectAllButton->Disconnect("Clicked()", this, "deselectAll()");
00203    m_removeButton->Disconnect("Clicked()", this, "removeItem()");
00204    m_frontButton->Disconnect("Clicked()",this,"moveToFront()");
00205    m_backButton->Disconnect("Clicked()",this,"moveToBack()");
00206    m_layerEntry->Disconnect("ValueSet(Long_t)",this,"moveToLayer(Long_t)");
00207    //  delete m_objectLabel;
00208    //  delete m_colorSelectWidget;
00209    //  delete m_isVisibleButton;
00210    delete m_validator;
00211 }
00212 
00213 //
00214 // assignment operators
00215 //
00216 // const CmsShowEDI& CmsShowEDI::operator=(const CmsShowEDI& rhs)
00217 // {
00218 //   //An exception safe implementation is
00219 //   CmsShowEDI temp(rhs);
00220 //   swap(rhs);
00221 //
00222 //   return *this;
00223 // }
00224 
00225 //
00226 // member functions
00227 //
00228 
00229 void CmsShowEDI::clearPBFrame()
00230 {
00231    if (!m_settersFrame->GetList()->IsEmpty())
00232    {
00233       // printf("remove FRAME \n");
00234       TGFrameElement *el = (TGFrameElement*) m_settersFrame->GetList()->First();
00235       TGFrame* f = el->fFrame;
00236       f->UnmapWindow();
00237       m_settersFrame->RemoveFrame(f);
00238       f->DestroyWindow();
00239    }
00240 }
00241 
00242 void
00243 CmsShowEDI::fillEDIFrame() {
00244    FWEventItem* iItem =0;
00245    bool multipleCollections = false;
00246    if(!m_selectionManager->selectedItems().empty()) {
00247       if(m_selectionManager->selectedItems().size()==1) {
00248          iItem=*(m_selectionManager->selectedItems().begin());
00249       } else {
00250          multipleCollections=true;
00251       }
00252    }
00253    //m_item can be zero because we had 0 or many collections selected
00254    if (0 == m_item || iItem != m_item) {
00255       disconnectAll();
00256       m_item = iItem;
00257       if(0 != m_item) {
00258          const FWDisplayProperties &p = iItem->defaultDisplayProperties();
00259          m_objectLabel->SetText(iItem->name().c_str());
00260          m_colorSelectWidget->SetColorByIndex(p.color(),kFALSE);
00261          m_opacitySlider->SetPosition(100 - p.transparency());
00262          m_isVisibleButton->SetDisabledAndSelected(p.isVisible());
00263          m_validator->setType(ROOT::Reflex::Type::ByTypeInfo(*(iItem->modelType()->GetTypeInfo())));
00264          m_filterExpressionEntry->SetText(iItem->filterExpression().c_str());
00265          m_filterError->Clear();
00266          m_selectError->Clear();
00267          m_nameEntry->SetText(iItem->name().c_str());
00268          m_typeEntry->SetText(iItem->type()->GetName());
00269          m_moduleEntry->SetText(iItem->moduleLabel().c_str());
00270          m_instanceEntry->SetText(iItem->productInstanceLabel().c_str());
00271          m_processEntry->SetText(iItem->processName().c_str());
00272          //  else m_isVisibleButton->SetState(kButtonDown, kFALSE);
00273          m_colorSelectWidget->SetEnabled(kTRUE);
00274          m_opacitySlider->SetEnabled(kTRUE);
00275          m_isVisibleButton->SetEnabled(kTRUE);
00276          m_filterExpressionEntry->SetEnabled(kTRUE);
00277          m_selectExpressionEntry->SetEnabled(kTRUE);
00278          m_filterButton->SetEnabled(kTRUE);
00279          m_selectButton->SetEnabled(kTRUE);
00280          m_selectAllButton->SetEnabled(kTRUE);
00281          m_deselectAllButton->SetEnabled(kTRUE);
00282          m_cw->SetColorByIndex(p.color(),kFALSE);
00283          m_cw->SetEnabled(kTRUE);
00284          m_removeButton->SetEnabled(kTRUE);
00285          updateLayerControls();
00286          m_layerEntry->SetState(kTRUE);
00287          m_displayChangedConn = m_item->defaultDisplayPropertiesChanged_.connect(boost::bind(&CmsShowEDI::updateDisplay, this));
00288          m_modelChangedConn = m_item->changed_.connect(boost::bind(&CmsShowEDI::updateFilter, this));
00289          //    m_selectionChangedConn = m_selectionManager->selectionChanged_.connect(boost::bind(&CmsShowEDI::updateSelection, this));
00290          m_destroyedConn = m_item->goingToBeDestroyed_.connect(boost::bind(&CmsShowEDI::disconnectAll, this));
00291                        
00292          clearPBFrame();
00293          m_item->getConfig()->populateFrame(m_settersFrame);
00294       }
00295       else if(multipleCollections) {
00296          std::ostringstream s;
00297          s<<m_selectionManager->selectedItems().size()<<" Collections Selected";
00298          m_objectLabel->SetText(s.str().c_str());
00299       }
00300 
00301       Resize(GetDefaultSize());
00302       Layout();
00303    }
00304 }
00305 
00306 void
00307 CmsShowEDI::removeItem() {
00308    Int_t chosen=0;
00309    std::string message("This action will remove the ");
00310    message += m_item->name();
00311    message +=" collection from the display."
00312               "\nIf you wish to return the collection you would have to use the 'Add Collection' window.";
00313    new TGMsgBox(gClient->GetDefaultRoot(),
00314                 this,
00315                 "Remove Collection Confirmation",
00316                 message.c_str(),
00317                 kMBIconExclamation,
00318                 kMBCancel | kMBApply,
00319                 &chosen);
00320    if(kMBApply == chosen) {
00321       m_item->destroy();
00322       m_item = 0;
00323       //make sure the ROOT global editor does not try to use this
00324       gEve->EditElement(0);
00325       gEve->Redraw3D();
00326    }
00327 }
00328 
00329 void
00330 CmsShowEDI::updateDisplay() {
00331    //std::cout<<"Updating display"<<std::endl;
00332    const FWDisplayProperties &props = m_item->defaultDisplayProperties();
00333    m_colorSelectWidget->SetColorByIndex(props.color(),kFALSE);
00334    m_opacitySlider->SetPosition(100 - props.transparency());
00335    m_isVisibleButton->SetState(props.isVisible() ? kButtonDown : kButtonUp, kFALSE);
00336 }
00337 
00338 void
00339 CmsShowEDI::updateLayerControls()
00340 {
00341    m_backButton->SetEnabled(!m_item->isInBack());
00342    m_frontButton->SetEnabled(!m_item->isInFront());
00343    m_layerEntry->SetIntNumber(m_item->layer());
00344 }
00345 void
00346 CmsShowEDI::moveToBack()
00347 {
00348    m_item->moveToBack();
00349    updateLayerControls();
00350 }
00351 void
00352 CmsShowEDI::moveToFront()
00353 {
00354    m_item->moveToFront();
00355    updateLayerControls();
00356 }
00357 void
00358 CmsShowEDI::moveToLayer(Long_t)
00359 {
00360    m_item->moveToLayer(static_cast<Int_t>(m_layerEntry->GetIntNumber()));
00361    updateLayerControls(); 
00362 }
00363 
00364 void
00365 CmsShowEDI::updateFilter() {
00366    m_filterExpressionEntry->SetText(m_item->filterExpression().c_str());
00367 }
00368 
00369 void
00370 CmsShowEDI::disconnectAll() {
00371    m_objectLabel->SetText("No Collection Selected");
00372    clearPBFrame();
00373    if(0 != m_item) {
00374       m_displayChangedConn.disconnect();
00375       m_modelChangedConn.disconnect();
00376       m_destroyedConn.disconnect();
00377       m_item = 0;
00378       m_colorSelectWidget->SetColorByIndex(0,kFALSE);
00379       m_opacitySlider->SetPosition(100);
00380       m_isVisibleButton->SetDisabledAndSelected(kTRUE);
00381       m_filterExpressionEntry->SetText(0);
00382       m_selectExpressionEntry->SetText(0);
00383       m_nameEntry->SetText(0);
00384       m_typeEntry->SetText(0);
00385       m_moduleEntry->SetText(0);
00386       m_instanceEntry->SetText(0);
00387       m_processEntry->SetText(0);
00388       //  else m_isVisibleButton->SetState(kButtonDown, kFALSE);
00389       m_colorSelectWidget->SetEnabled(kFALSE);
00390       m_opacitySlider->SetEnabled(kFALSE);
00391       
00392       m_isVisibleButton->SetEnabled(kFALSE);
00393       m_filterExpressionEntry->SetEnabled(kFALSE);
00394       m_filterButton->SetEnabled(kFALSE);
00395       m_selectExpressionEntry->SetEnabled(kFALSE);
00396       m_selectButton->SetEnabled(kFALSE);
00397       m_selectAllButton->SetEnabled(kFALSE);
00398       m_deselectAllButton->SetEnabled(kFALSE);
00399       m_removeButton->SetEnabled(kFALSE);
00400       m_backButton->SetEnabled(kFALSE);
00401       m_frontButton->SetEnabled(kFALSE);
00402       m_layerEntry->SetIntNumber(0);
00403       m_layerEntry->SetState(kFALSE);
00404       m_layerEntry->GetNumberEntry()->SetEnabled(kFALSE);
00405       m_layerEntry->GetButtonUp()->SetEnabled(kFALSE);
00406       m_layerEntry->GetButtonDown()->SetEnabled(kFALSE);
00407    }
00408 }
00409 
00416 void
00417 CmsShowEDI::changeItemColor(Color_t color) {
00418    FWDisplayProperties changeProperties = m_item->defaultDisplayProperties();
00419    changeProperties.setColor(color);
00420    m_item->setDefaultDisplayProperties(changeProperties);
00421    m_cw->SetColorByIndex(color,kFALSE);
00422 }
00423 
00425 void
00426 CmsShowEDI::toggleItemVisible(Bool_t on) {
00427    FWDisplayProperties changeProperties = m_item->defaultDisplayProperties();
00428    changeProperties.setIsVisible(on);
00429    m_item->setDefaultDisplayProperties(changeProperties);
00430 }
00431 
00439 void
00440 CmsShowEDI::changeItemOpacity(Int_t opacity) {
00441    FWDisplayProperties changeProperties = m_item->defaultDisplayProperties();
00442    changeProperties.setTransparency(100 - opacity);
00443    m_item->setDefaultDisplayProperties(changeProperties);
00444 }
00445 
00446 void
00447 CmsShowEDI::runFilter() {
00448    const std::string filter(m_filterExpressionEntry->GetText());
00449    if (m_item != 0) {
00450       try {
00451          m_filterError->Clear();
00452          m_item->setFilterExpression(filter);
00453       } catch( const FWExpressionException& e) {
00454          m_filterError->AddLine(e.what().c_str());
00455          m_filterError->Update();
00456          if(e.column() > -1) {
00457             m_filterExpressionEntry->SetCursorPosition(e.column());
00458          }
00459       }
00460    }
00461 }
00462 
00463 void
00464 CmsShowEDI::runSelection() {
00465    FWModelExpressionSelector selector;
00466    const std::string selection(m_selectExpressionEntry->GetText());
00467    if (m_item != 0)
00468    {
00469       try
00470       {
00471          m_selectError->Clear();
00472          //NOTE call clearModelSelectionLeaveItem so that the item does not get deselected
00473          // just for safety use a copy of the pointer to m_item
00474          FWEventItem* item = m_item;
00475          item->selectionManager()-> clearModelSelectionLeaveItem();
00476 
00477          selector.select(item, selection, TColor::GetColor(m_cw->GetColor()));
00478       }
00479       catch( const FWExpressionException& e)
00480       {
00481          m_selectError->AddLine(e.what().c_str());
00482          m_selectError->Update();
00483          if (e.column() > -1)
00484          {
00485             m_selectExpressionEntry->SetCursorPosition(e.column());
00486          }
00487       }
00488    }
00489 }
00490 
00491 void
00492 CmsShowEDI::selectAll()
00493 {
00494    FWChangeSentry sentry(*(m_item->changeManager()));
00495    for (int i = 0; i < static_cast<int>(m_item->size()); i++)
00496    {
00497       m_item->select(i);
00498    }
00499 }
00500 void
00501 CmsShowEDI::deselectAll()
00502 {
00503    FWChangeSentry sentry(*(m_item->changeManager()));
00504    for (int i = 0; i < static_cast<int>(m_item->size()); i++)
00505    {
00506       m_item->unselect(i);
00507    }
00508 }
00509 
00510 void 
00511 CmsShowEDI::changeSelectionColor(Color_t c)
00512 {
00513    FWChangeSentry sentry(*(m_item->changeManager()));
00514    const std::set<FWModelId>& ss =  m_item->selectionManager()->selected();
00515    FWDisplayProperties dp = m_item->defaultDisplayProperties();
00516    dp.setColor(c);
00517    for (std::set<FWModelId>::const_iterator i = ss.begin(); i != ss.end(); ++i ) {
00518      m_item->setDisplayProperties(i->index(), dp);
00519    }
00520 }
00521 
00522 
00523 void 
00524 CmsShowEDI::show(FWDataCategories iToView)
00525 {
00526    m_tabs->SetTab(iToView);
00527 }
00528 
00529 /* Called by FWGUIManager when change background/colorset. */
00530 void 
00531 CmsShowEDI::colorSetChanged()
00532 {
00533    if (m_item)
00534    {
00535       const FWDisplayProperties &p = m_item->defaultDisplayProperties();
00536       m_colorSelectWidget->SetColorByIndex(p.color(),kFALSE);
00537       m_cw->SetColorByIndex(p.color(),kFALSE);
00538    }
00539 }