Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-05 22:48:07

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     CmsShowModelPopup
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:
0010 //         Created:  Fri Jun 27 11:23:08 EDT 2008
0011 //
0012 
0013 // system include file
0014 #include <iostream>
0015 #include <sstream>
0016 #include <set>
0017 #include <cassert>
0018 #include <sigc++/sigc++.h>
0019 #include <functional>
0020 #include "TClass.h"
0021 #include "TGFrame.h"
0022 #include "TGButton.h"
0023 #include "TGLabel.h"
0024 #include "TGString.h"
0025 #include "TColor.h"
0026 #include "TG3DLine.h"
0027 #include "TGFont.h"
0028 #include "TGSlider.h"
0029 #include "TGButton.h"
0030 
0031 // user include files
0032 #include "Fireworks/Core/interface/CmsShowModelPopup.h"
0033 #include "Fireworks/Core/interface/FWDisplayProperties.h"
0034 #include "Fireworks/Core/src/FWColorSelect.h"
0035 #include "Fireworks/Core/interface/FWDialogBuilder.h"
0036 #include "Fireworks/Core/interface/FWModelChangeSignal.h"
0037 #include "Fireworks/Core/interface/FWModelChangeManager.h"
0038 #include "Fireworks/Core/interface/FWColorManager.h"
0039 #include "Fireworks/Core/interface/FWEventItem.h"
0040 #include "Fireworks/Core/interface/FWModelId.h"
0041 #include "Fireworks/Core/interface/FWSelectionManager.h"
0042 #include "Fireworks/Core/interface/FWDetailViewManager.h"
0043 
0044 //
0045 // constants, enums and typedefs
0046 //
0047 
0048 //
0049 // static data member definitions
0050 //
0051 //
0052 // constructors and destructor
0053 //
0054 CmsShowModelPopup::CmsShowModelPopup(FWDetailViewManager *iManager,
0055                                      FWSelectionManager *iSelMgr,
0056                                      const FWColorManager *iColorMgr,
0057                                      const TGWindow *p,
0058                                      UInt_t w,
0059                                      UInt_t h)
0060     : TGTransientFrame(gClient->GetDefaultRoot(), p, w, h),
0061       m_detailViewManager(iManager),
0062       m_colorManager(iColorMgr),
0063       m_dialogBuilder(nullptr) {
0064   m_changes =
0065       iSelMgr->selectionChanged_.connect(std::bind(&CmsShowModelPopup::fillModelPopup, this, std::placeholders::_1));
0066 
0067   SetCleanup(kDeepCleanup);
0068 
0069   TGVerticalFrame *vf = new TGVerticalFrame(this);
0070   AddFrame(vf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 4));
0071   m_dialogBuilder = new FWDialogBuilder(vf);
0072 
0073   // Do the layouting of the various widgets.
0074   m_dialogBuilder->indent(4)
0075       .addLabel(" ", 14, 1, &m_modelLabel)
0076       .addLabel("Color", 8)
0077       .addColorPicker(iColorMgr, &m_colorSelectWidget)
0078       .expand(false)
0079       .addHSeparator()
0080       .addLabel("Opacity", 8)
0081       .addHSlider(150, &m_opacitySlider)
0082       .addHSeparator(2)
0083       .addCheckbox("Visible", &m_isVisibleButton)
0084       .addHSeparator();
0085 
0086   // Dummy button for detail views. Can be overidden.
0087   TGTextButton *detailedViewButton = new TGTextButton(this, "Open Detailed View", 0);
0088   AddFrame(detailedViewButton, new TGLayoutHints(kLHintsExpandX, 4, 4, 4, 4));
0089   m_openDetailedViewButtons.push_back(detailedViewButton);
0090 
0091   m_colorSelectWidget->Connect("ColorChosen(Color_t)", "CmsShowModelPopup", this, "changeModelColor(Color_t)");
0092   m_isVisibleButton->Connect("Toggled(Bool_t)", "CmsShowModelPopup", this, "toggleModelVisible(Bool_t)");
0093   m_opacitySlider->Connect("PositionChanged(Int_t)", "CmsShowModelPopup", this, "changeModelOpacity(Int_t)");
0094 
0095   SetWindowName("Object Controller");
0096   MapSubwindows();
0097   Resize(GetDefaultSize());
0098   Layout();
0099 
0100   fillModelPopup(*iSelMgr);
0101 }
0102 
0103 // CmsShowModelPopup::CmsShowModelPopup(const CmsShowModelPopup& rhs)
0104 // {
0105 //    // do actual copying here;
0106 // }
0107 
0108 CmsShowModelPopup::~CmsShowModelPopup() {
0109   m_changes.disconnect();
0110   m_colorSelectWidget->Disconnect("ColorSelected(Pixel_t)", this, "changeModelColor(Pixel_t)");
0111   m_opacitySlider->Disconnect("PositionChanged(Int_t)", this, "changeModelOpacity(Int_t)");
0112   m_isVisibleButton->Disconnect("Toggled(Bool_t)", this, "toggleModelVisible(Bool_t)");
0113   disconnectAll();
0114 }
0115 
0116 //
0117 // assignment operators
0118 //
0119 // const CmsShowModelPopup& CmsShowModelPopup::operator=(const CmsShowModelPopup& rhs)
0120 // {
0121 //   //An exception safe implementation is
0122 //   CmsShowModelPopup temp(rhs);
0123 //   swap(rhs);
0124 //
0125 //   return *this;
0126 // }
0127 
0128 //
0129 // member functions
0130 //
0131 /** this updates the dialog when selection changes. It also handles multiple
0132     Selections by updating only the widgets which have non controversial 
0133     (i.e. different across selected objects) values.
0134   */
0135 void CmsShowModelPopup::fillModelPopup(const FWSelectionManager &iSelMgr) {
0136   disconnectAll();
0137   // Handles the case in which the selection is empty.
0138   if (iSelMgr.selected().empty())
0139     return;
0140 
0141   // Handle the case in which the selection is not empty.
0142   bool multipleNames = false, multipleColors = false, multipleVis = false, multipleTransparecy = false;
0143 
0144   m_models = iSelMgr.selected();
0145   std::set<FWModelId>::const_iterator id = m_models.begin();
0146   const FWEventItem *item = id->item();
0147   const FWEventItem::ModelInfo info = item->modelInfo(id->index());
0148   const FWDisplayProperties &props = info.displayProperties();
0149 
0150   // The old logic was broken here. It was enought that the last item
0151   // was the same as the first one, and all of them would have been considered
0152   // equal. This should fix it. The idea is that if any of the elements in
0153   // models in [1, N] are different from the first, then we consider the
0154   // set with multipleXYZ.
0155   for (std::set<FWModelId>::const_iterator i = ++(m_models.begin()), e = m_models.end(); i != e; ++i) {
0156     const FWEventItem::ModelInfo &nextInfo = i->item()->modelInfo(i->index());
0157     const FWDisplayProperties &nextProps = nextInfo.displayProperties();
0158 
0159     multipleNames = multipleNames || (item->name() != i->item()->name());
0160     multipleColors = multipleColors || (props.color() != nextProps.color());
0161     multipleVis = multipleVis || (props.isVisible() != nextProps.isVisible());
0162     multipleTransparecy = multipleTransparecy || (props.transparency() != nextProps.transparency());
0163   }
0164 
0165   // Handle the name.
0166   std::ostringstream s;
0167   if (multipleNames)
0168     s << m_models.size() << " objects";
0169   else
0170     s << m_models.size() << " " << item->name();
0171   m_modelLabel->SetText(s.str().c_str());
0172 
0173   if (m_models.size() == 1) {
0174     m_modelLabel->SetText(item->modelName(id->index()).c_str());
0175     std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*id);
0176     m_openDetailedViewButtons.front()->SetEnabled(!viewChoices.empty());
0177     //be sure we show just the right number of buttons
0178     if (viewChoices.size() > m_openDetailedViewButtons.size()) {
0179       for (size_t i = 0, e = m_openDetailedViewButtons.size(); i != e; ++i) {
0180         // printf("show existing buttons\n");
0181         TGCompositeFrame *cf = (TGCompositeFrame *)m_openDetailedViewButtons[i]->GetParent();
0182         cf->ShowFrame(m_openDetailedViewButtons[i]);
0183       }
0184 
0185       //now we make additional buttons
0186       TGTextButton *button;
0187       for (size_t index = m_openDetailedViewButtons.size(); index < viewChoices.size(); ++index) {
0188         button = new TGTextButton(this, "dummy", index);
0189         AddFrame(button, new TGLayoutHints(kLHintsExpandX, 4, 4, 4, 4));
0190         TGCompositeFrame *cf = (TGCompositeFrame *)button->GetParent();
0191         cf->MapWindow();
0192         cf->MapSubwindows();
0193         m_openDetailedViewButtons.push_back(button);
0194 
0195         button->Connect("Clicked()", "CmsShowModelPopup", this, "clicked()");
0196       }
0197     } else if (!viewChoices.empty()) {
0198       //  printf("show button subset %d \n",  viewChoices.size());
0199       for (size_t i = 0, e = viewChoices.size(); i != e; ++i) {
0200         TGCompositeFrame *cf = (TGCompositeFrame *)m_openDetailedViewButtons[i]->GetParent();
0201         cf->ShowFrame(m_openDetailedViewButtons[i]);
0202       }
0203     }
0204 
0205     //set the names
0206     for (size_t i = 0, e = viewChoices.size(); i != e; ++i) {
0207       if (viewChoices[i][0] == '!') {
0208         m_openDetailedViewButtons[i]->SetEnabled(false);
0209         m_openDetailedViewButtons[i]->SetText(("Open " + viewChoices[i].substr(1) + " Detail View ...").c_str());
0210 
0211       } else {
0212         m_openDetailedViewButtons[i]->SetText(("Open " + viewChoices[i] + " Detail View ...").c_str());
0213         m_openDetailedViewButtons[i]->SetEnabled(true);
0214       }
0215     }
0216   }
0217 
0218   // Set the various widgets.
0219   m_colorSelectWidget->SetColorByIndex(props.color(), kFALSE);
0220   m_opacitySlider->SetPosition(100 - props.transparency());
0221   m_isVisibleButton->SetDisabledAndSelected(props.isVisible());
0222 
0223   m_opacitySlider->SetEnabled(kTRUE);
0224   m_colorSelectWidget->SetEnabled(kTRUE);
0225   m_isVisibleButton->SetEnabled(kTRUE);
0226 
0227   m_modelChangedConn = item->changed_.connect(std::bind(&CmsShowModelPopup::updateDisplay, this));
0228   m_destroyedConn = item->goingToBeDestroyed_.connect(std::bind(&CmsShowModelPopup::disconnectAll, this));
0229 
0230   Resize(GetDefaultSize());
0231   Layout();
0232 }
0233 
0234 /** Based on the actual models properties, update the GUI. 
0235   */
0236 void CmsShowModelPopup::updateDisplay() {
0237   for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i) {
0238     const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
0239     const FWDisplayProperties &p = info.displayProperties();
0240     m_colorSelectWidget->SetColorByIndex(p.color(), kFALSE);
0241 
0242     if (p.isVisible())
0243       m_isVisibleButton->SetState(kButtonDown, kFALSE);
0244     else
0245       m_isVisibleButton->SetState(kButtonUp, kFALSE);
0246 
0247     m_opacitySlider->SetPosition(100 - p.transparency());
0248   }
0249 }
0250 
0251 /* Called by FWGUIManager when change background/colorset. */
0252 void CmsShowModelPopup::colorSetChanged() {
0253   for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i) {
0254     const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
0255     const FWDisplayProperties &p = info.displayProperties();
0256     m_colorSelectWidget->SetColorByIndex(p.color(), kFALSE);
0257   }
0258 }
0259 
0260 /** This is invoked to when no object is selected and sets the dialog in
0261     a disabled look.
0262   */
0263 void CmsShowModelPopup::disconnectAll() {
0264   m_modelChangedConn.disconnect();
0265   m_destroyedConn.disconnect();
0266   //  m_item = 0;
0267   //  m_model = 0;
0268   m_modelLabel->SetText("No object selected");
0269   m_colorSelectWidget->SetColorByIndex(kRed, kFALSE);
0270   m_isVisibleButton->SetDisabledAndSelected(kTRUE);
0271   m_colorSelectWidget->SetEnabled(kFALSE);
0272   m_opacitySlider->SetEnabled(kFALSE);
0273   m_isVisibleButton->SetEnabled(kFALSE);
0274   m_openDetailedViewButtons.front()->SetEnabled(kFALSE);
0275   m_openDetailedViewButtons.front()->SetText("Open Detail View ...");
0276   assert(!m_openDetailedViewButtons.empty());
0277   for (size_t i = 1, e = m_openDetailedViewButtons.size(); i != e; ++i) {
0278     TGCompositeFrame *cf = (TGCompositeFrame *)m_openDetailedViewButtons[i]->GetParent();
0279     cf->HideFrame(m_openDetailedViewButtons[i]);
0280   }
0281 }
0282 
0283 /** Change the color of the selected objects.
0284 
0285     NOTES:
0286     - Notice that the whole thing works with a "Copy old properties and modify"
0287       paradigm.
0288       
0289   */
0290 void CmsShowModelPopup::changeModelColor(Color_t color) {
0291   if (m_models.empty())
0292     return;
0293 
0294   FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
0295   for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i) {
0296     const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
0297     FWDisplayProperties changeProperties = info.displayProperties();
0298     changeProperties.setColor(color);
0299     i->item()->setDisplayProperties(i->index(), changeProperties);
0300   }
0301 }
0302 
0303 /** Change the opacity of the selected objects. See above in changeModelColor 
0304     for additional notes.
0305   */
0306 void CmsShowModelPopup::changeModelOpacity(Int_t opacity) {
0307   if (m_models.empty())
0308     return;
0309 
0310   FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
0311   for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i) {
0312     const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
0313     FWDisplayProperties changeProperties = info.displayProperties();
0314     changeProperties.setTransparency(100 - opacity);
0315     i->item()->setDisplayProperties(i->index(), changeProperties);
0316   }
0317 }
0318 
0319 /** Change (not toggle actually) the visibility of selected objects. 
0320     See changeModelColor for additional notes.
0321   */
0322 void CmsShowModelPopup::toggleModelVisible(Bool_t on) {
0323   if (m_models.empty())
0324     return;
0325 
0326   FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
0327   for (std::set<FWModelId>::iterator i = m_models.begin(); i != m_models.end(); ++i) {
0328     const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
0329     FWDisplayProperties changeProperties = info.displayProperties();
0330     changeProperties.setIsVisible(on);
0331     i->item()->setDisplayProperties(i->index(), changeProperties);
0332   }
0333 }
0334 
0335 void CmsShowModelPopup::openDetailedView() {
0336   std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
0337 
0338   m_detailViewManager->openDetailViewFor(*(m_models.begin()), viewChoices.front());
0339 }
0340 
0341 void CmsShowModelPopup::clicked() {
0342   TGTextButton *cs = static_cast<TGTextButton *>(gTQSender);
0343   int iIndex = cs->WidgetId();
0344   std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
0345 
0346   m_detailViewManager->openDetailViewFor(*(m_models.begin()), *(viewChoices.begin() + iIndex));
0347 }
0348 //
0349 // const member functions
0350 //
0351 
0352 //
0353 // static member functions
0354 //