CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Fireworks/Core/src/CmsShowModelPopup.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     CmsShowModelPopup
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:
00010 //         Created:  Fri Jun 27 11:23:08 EDT 2008
00011 // $Id: CmsShowModelPopup.cc,v 1.32 2010/11/11 19:45:49 amraktad Exp $
00012 //
00013 
00014 // system include file
00015 #include <iostream>
00016 #include <sstream>
00017 #include <set>
00018 #include <sigc++/sigc++.h>
00019 #include <boost/bind.hpp>
00020 #include "TClass.h"
00021 #include "TGFrame.h"
00022 #include "TGButton.h"
00023 #include "TGLabel.h"
00024 #include "TGString.h"
00025 #include "TColor.h"
00026 #include "TG3DLine.h"
00027 #include "TGFont.h"
00028 #include "TGSlider.h"
00029 #include "TGButton.h"
00030 
00031 // user include files
00032 #include "Fireworks/Core/interface/CmsShowModelPopup.h"
00033 #include "Fireworks/Core/interface/FWDisplayProperties.h"
00034 #include "Fireworks/Core/src/FWColorSelect.h"
00035 #include "Fireworks/Core/src/FWDialogBuilder.h"
00036 #include "Fireworks/Core/interface/FWModelChangeSignal.h"
00037 #include "Fireworks/Core/interface/FWModelChangeManager.h"
00038 #include "Fireworks/Core/interface/FWColorManager.h"
00039 #include "Fireworks/Core/interface/FWEventItem.h"
00040 #include "Fireworks/Core/interface/FWModelId.h"
00041 #include "Fireworks/Core/interface/FWSelectionManager.h"
00042 #include "Fireworks/Core/interface/FWDetailViewManager.h"
00043 
00044 //
00045 // constants, enums and typedefs
00046 //
00047 
00048 //
00049 // static data member definitions
00050 //
00051 //
00052 // constructors and destructor
00053 //
00054 CmsShowModelPopup::CmsShowModelPopup(FWDetailViewManager* iManager,
00055                                      FWSelectionManager* iSelMgr,
00056                                      const FWColorManager* iColorMgr,
00057                                      const TGWindow* p, UInt_t w, UInt_t h) :
00058    TGTransientFrame(gClient->GetDefaultRoot(),p,w,h),
00059    m_detailViewManager(iManager),
00060    m_colorManager(iColorMgr),
00061    m_dialogBuilder(0)
00062 {
00063    m_changes = iSelMgr->selectionChanged_.connect(boost::bind(&CmsShowModelPopup::fillModelPopup, this, _1));
00064 
00065    SetCleanup(kDeepCleanup);
00066 
00067    TGVerticalFrame* vf = new TGVerticalFrame(this);
00068    AddFrame(vf, new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 2, 2, 2, 4));
00069    m_dialogBuilder =  new FWDialogBuilder(vf);
00070   
00071    // Do the layouting of the various widgets.
00072    m_dialogBuilder->indent(4)
00073       .addLabel(" ", 14, 1, &m_modelLabel)
00074       .addLabel("Color", 8)
00075       .addColorPicker(iColorMgr, &m_colorSelectWidget).expand(false)
00076       .addHSeparator()
00077       .addLabel("Opacity", 8)
00078       .addHSlider(150, &m_opacitySlider)
00079       .addHSeparator(2)
00080       .addCheckbox("Visible", &m_isVisibleButton)
00081       .addHSeparator();
00082 
00083    // Dummy button for detail views. Can be overidden.
00084    TGTextButton *detailedViewButton = new TGTextButton(this, "Open Detailed View", 0); 
00085    AddFrame(detailedViewButton, new TGLayoutHints(kLHintsExpandX, 4, 4, 4, 4));
00086    m_openDetailedViewButtons.push_back(detailedViewButton);
00087 
00088    m_colorSelectWidget->Connect("ColorChosen(Color_t)", "CmsShowModelPopup", this, "changeModelColor(Color_t)");
00089    m_isVisibleButton->Connect("Toggled(Bool_t)", "CmsShowModelPopup", this, "toggleModelVisible(Bool_t)");
00090    m_opacitySlider->Connect("PositionChanged(Int_t)", "CmsShowModelPopup",
00091                             this, "changeModelOpacity(Int_t)");
00092 
00093    SetWindowName("Object Controller");
00094    MapSubwindows();
00095    Resize(GetDefaultSize());
00096    Layout();
00097 
00098    fillModelPopup(*iSelMgr);
00099 }
00100 
00101 // CmsShowModelPopup::CmsShowModelPopup(const CmsShowModelPopup& rhs)
00102 // {
00103 //    // do actual copying here;
00104 // }
00105 
00106 CmsShowModelPopup::~CmsShowModelPopup()
00107 {
00108    m_changes.disconnect();
00109    m_colorSelectWidget->Disconnect("ColorSelected(Pixel_t)", this, "changeModelColor(Pixel_t)");
00110    m_opacitySlider->Disconnect("PositionChanged(Int_t)", this, "changeModelOpacity(Int_t)");
00111    m_isVisibleButton->Disconnect("Toggled(Bool_t)", this, "toggleModelVisible(Bool_t)");
00112    disconnectAll();
00113 }
00114 
00115 //
00116 // assignment operators
00117 //
00118 // const CmsShowModelPopup& CmsShowModelPopup::operator=(const CmsShowModelPopup& rhs)
00119 // {
00120 //   //An exception safe implementation is
00121 //   CmsShowModelPopup temp(rhs);
00122 //   swap(rhs);
00123 //
00124 //   return *this;
00125 // }
00126 
00127 //
00128 // member functions
00129 //
00134 void
00135 CmsShowModelPopup::fillModelPopup(const FWSelectionManager& iSelMgr)
00136 {
00137    disconnectAll();
00138    // Handles the case in which the selection is empty.
00139    if (iSelMgr.selected().empty())
00140       return;
00141    
00142    // Handle the case in which the selection is not empty.
00143    bool multipleNames = false, multipleColors = false, multipleVis = false,
00144       multipleTransparecy = false;
00145 
00146    m_models = iSelMgr.selected();
00147    std::set<FWModelId>::const_iterator id = m_models.begin();
00148    const FWEventItem* item = id->item();
00149    const FWEventItem::ModelInfo info = item->modelInfo(id->index());
00150    const FWDisplayProperties &props = info.displayProperties();
00151    
00152    // The old logic was broken here. It was enought that the last item
00153    // was the same as the first one, and all of them would have been considered
00154    // equal. This should fix it. The idea is that if any of the elements in
00155    // models in [1, N] are different from the first, then we consider the
00156    // set with multipleXYZ.
00157    for (std::set<FWModelId>::const_iterator i = ++(m_models.begin()),
00158            e = m_models.end(); i != e; ++i) 
00159    {
00160       const FWEventItem::ModelInfo &nextInfo = i->item()->modelInfo(i->index());
00161       const FWDisplayProperties &nextProps = nextInfo.displayProperties();
00162       
00163       multipleNames = multipleNames || (item->name() != i->item()->name());
00164       multipleColors = multipleColors || (props.color() != nextProps.color());
00165       multipleVis = multipleVis || (props.isVisible() != nextProps.isVisible());
00166       multipleTransparecy = multipleTransparecy 
00167          || (props.transparency() != nextProps.transparency());
00168    }
00169    
00170    // Handle the name.
00171    std::ostringstream s;
00172    if (multipleNames) 
00173       s << m_models.size() << " objects";
00174    else
00175       s << m_models.size() << " " << item->name();
00176    m_modelLabel->SetText(s.str().c_str());
00177 
00178    if (m_models.size()==1)
00179    {
00180       m_modelLabel->SetText(item->modelName(id->index()).c_str());
00181       std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*id);
00182       m_openDetailedViewButtons.front()->SetEnabled(viewChoices.size()>0);
00183       //be sure we show just the right number of buttons
00184       if(viewChoices.size() > m_openDetailedViewButtons.size()) 
00185       {
00186          for(size_t i = 0, e = m_openDetailedViewButtons.size(); i != e; ++i)
00187          {
00188             // printf("show existing buttons\n");
00189             TGCompositeFrame* cf = (TGCompositeFrame*)m_openDetailedViewButtons[i]->GetParent();
00190             cf->ShowFrame(m_openDetailedViewButtons[i]);
00191          }
00192 
00193          //now we make additional buttons 
00194          TGTextButton *button;
00195          for(size_t index = m_openDetailedViewButtons.size(); index < viewChoices.size(); ++index)
00196          { 
00197             // printf("add new button %s \n ",  viewChoices[index].c_str());
00198             button = new TGTextButton(this, "dummy", index);
00199             AddFrame(button, new TGLayoutHints(kLHintsExpandX, 4, 4, 4, 4));
00200             TGCompositeFrame* cf = (TGCompositeFrame*)button->GetParent();
00201             cf->MapWindow();
00202             cf->MapSubwindows();
00203             m_openDetailedViewButtons.push_back(button);
00204 
00205             button->Connect("Clicked()", "CmsShowModelPopup", this, "clicked()");
00206          }
00207       }
00208       else if (!viewChoices.empty())
00209       {
00210          //  printf("show button subset %d \n",  viewChoices.size());
00211          for (size_t i = 0, e = viewChoices.size(); i != e; ++i)
00212          {
00213             TGCompositeFrame* cf = (TGCompositeFrame*)m_openDetailedViewButtons[i]->GetParent();
00214             cf->ShowFrame(m_openDetailedViewButtons[i]);
00215          }
00216       }
00217       
00218       //set the names
00219       for (size_t i = 0, e = viewChoices.size(); i != e; ++i)
00220       {
00221          m_openDetailedViewButtons[i]->SetText(("Open " + viewChoices[i] + " Detail View ...").c_str());
00222       }
00223    }
00224    
00225    // Set the various widgets.
00226    m_colorSelectWidget->SetColorByIndex(props.color(), kFALSE);
00227    m_opacitySlider->SetPosition(100 - props.transparency());
00228    m_isVisibleButton->SetDisabledAndSelected(props.isVisible());
00229 
00230    m_opacitySlider->SetEnabled(kTRUE);
00231    m_colorSelectWidget->SetEnabled(kTRUE);
00232    m_isVisibleButton->SetEnabled(kTRUE);
00233    
00234    m_modelChangedConn = item->changed_.connect(boost::bind(&CmsShowModelPopup::updateDisplay, this));
00235    m_destroyedConn = item->goingToBeDestroyed_.connect(boost::bind(&CmsShowModelPopup::disconnectAll, this));
00236 
00237    Resize(GetDefaultSize());
00238    Layout();
00239 }
00240 
00243 void
00244 CmsShowModelPopup::updateDisplay()
00245 {
00246    for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); 
00247         i != e; ++i)
00248    {
00249       const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
00250       const FWDisplayProperties &p = info.displayProperties();
00251       m_colorSelectWidget->SetColorByIndex(p.color(), kFALSE);
00252       
00253       if (p.isVisible())
00254          m_isVisibleButton->SetState(kButtonDown, kFALSE);
00255       else
00256          m_isVisibleButton->SetState(kButtonUp, kFALSE);
00257 
00258       m_opacitySlider->SetPosition(100 - p.transparency());
00259    }
00260 }
00261 
00262 /* Called by FWGUIManager when change background/colorset. */
00263 void 
00264 CmsShowModelPopup::colorSetChanged()
00265 { 
00266    for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); 
00267         i != e; ++i)
00268    {
00269       const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
00270       const FWDisplayProperties &p = info.displayProperties();
00271       m_colorSelectWidget->SetColorByIndex(p.color(), kFALSE);
00272    } 
00273 }
00274  
00278 void
00279 CmsShowModelPopup::disconnectAll() {
00280    m_modelChangedConn.disconnect();
00281    m_destroyedConn.disconnect();
00282    //  m_item = 0;
00283    //  m_model = 0;
00284    m_modelLabel->SetText("No object selected");
00285    m_colorSelectWidget->SetColorByIndex(kRed,kFALSE);
00286    m_isVisibleButton->SetDisabledAndSelected(kTRUE);
00287    m_colorSelectWidget->SetEnabled(kFALSE);
00288    m_opacitySlider->SetEnabled(kFALSE);
00289    m_isVisibleButton->SetEnabled(kFALSE);
00290    m_openDetailedViewButtons.front()->SetEnabled(kFALSE);
00291    m_openDetailedViewButtons.front()->SetText("Open Detail View ...");
00292    assert(!m_openDetailedViewButtons.empty());
00293    for(size_t i = 1, e = m_openDetailedViewButtons.size(); i != e; ++i)
00294    {
00295       TGCompositeFrame* cf = (TGCompositeFrame*)m_openDetailedViewButtons[i]->GetParent();
00296       cf->HideFrame(m_openDetailedViewButtons[i]);
00297    }
00298 
00299 
00300 }
00301 
00309 void
00310 CmsShowModelPopup::changeModelColor(Color_t color)
00311 {
00312    if (m_models.empty())
00313       return;
00314       
00315    FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
00316    for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i)
00317    {
00318       const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
00319       FWDisplayProperties changeProperties = info.displayProperties();
00320       changeProperties.setColor(color);
00321       i->item()->setDisplayProperties(i->index(), changeProperties);
00322    }
00323 }
00324 
00328 void
00329 CmsShowModelPopup::changeModelOpacity(Int_t opacity) 
00330 {
00331    if (m_models.empty())
00332       return;
00333    
00334    FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
00335    for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i)
00336    {
00337       const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
00338       FWDisplayProperties changeProperties = info.displayProperties();
00339       changeProperties.setTransparency(100 - opacity);
00340       i->item()->setDisplayProperties(i->index(), changeProperties);
00341    }
00342 }
00343 
00347 void
00348 CmsShowModelPopup::toggleModelVisible(Bool_t on) {
00349    if(m_models.empty())
00350       return;
00351    
00352    FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
00353    for (std::set<FWModelId>::iterator i = m_models.begin(); i != m_models.end(); ++i) 
00354    {
00355       const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
00356       FWDisplayProperties changeProperties = info.displayProperties();
00357       changeProperties.setIsVisible(on);
00358       i->item()->setDisplayProperties(i->index(), changeProperties);
00359    }
00360 }
00361 
00362 void
00363 CmsShowModelPopup::openDetailedView()
00364 {
00365    std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
00366 
00367    m_detailViewManager->openDetailViewFor( *(m_models.begin()), viewChoices.front() );
00368 }
00369 
00370 void
00371 CmsShowModelPopup::clicked()
00372 {
00373    TGTextButton *cs = static_cast<TGTextButton *>(gTQSender);
00374    int iIndex = cs->WidgetId();
00375    std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
00376    
00377    m_detailViewManager->openDetailViewFor( *(m_models.begin()), *(viewChoices.begin()+iIndex) );
00378    
00379 }   
00380 //
00381 // const member functions
00382 //
00383 
00384 //
00385 // static member functions
00386 //