CMS 3D CMS Logo

CmsShowModelPopup.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : CmsShowModelPopup
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author:
10 // Created: Fri Jun 27 11:23:08 EDT 2008
11 //
12 
13 // system include file
14 #include <iostream>
15 #include <sstream>
16 #include <set>
17 #include <cassert>
18 #include <sigc++/sigc++.h>
19 #include <boost/bind.hpp>
20 #include "TClass.h"
21 #include "TGFrame.h"
22 #include "TGButton.h"
23 #include "TGLabel.h"
24 #include "TGString.h"
25 #include "TColor.h"
26 #include "TG3DLine.h"
27 #include "TGFont.h"
28 #include "TGSlider.h"
29 #include "TGButton.h"
30 
31 // user include files
43 
44 //
45 // constants, enums and typedefs
46 //
47 
48 //
49 // static data member definitions
50 //
51 //
52 // constructors and destructor
53 //
55  FWSelectionManager *iSelMgr,
56  const FWColorManager *iColorMgr,
57  const TGWindow *p,
58  UInt_t w,
59  UInt_t h)
60  : TGTransientFrame(gClient->GetDefaultRoot(), p, w, h),
61  m_detailViewManager(iManager),
62  m_colorManager(iColorMgr),
63  m_dialogBuilder(nullptr) {
64  m_changes = iSelMgr->selectionChanged_.connect(boost::bind(&CmsShowModelPopup::fillModelPopup, this, _1));
65 
66  SetCleanup(kDeepCleanup);
67 
68  TGVerticalFrame *vf = new TGVerticalFrame(this);
69  AddFrame(vf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 4));
71 
72  // Do the layouting of the various widgets.
74  .addLabel(" ", 14, 1, &m_modelLabel)
75  .addLabel("Color", 8)
77  .expand(false)
78  .addHSeparator()
79  .addLabel("Opacity", 8)
81  .addHSeparator(2)
82  .addCheckbox("Visible", &m_isVisibleButton)
83  .addHSeparator();
84 
85  // Dummy button for detail views. Can be overidden.
86  TGTextButton *detailedViewButton = new TGTextButton(this, "Open Detailed View", 0);
87  AddFrame(detailedViewButton, new TGLayoutHints(kLHintsExpandX, 4, 4, 4, 4));
88  m_openDetailedViewButtons.push_back(detailedViewButton);
89 
90  m_colorSelectWidget->Connect("ColorChosen(Color_t)", "CmsShowModelPopup", this, "changeModelColor(Color_t)");
91  m_isVisibleButton->Connect("Toggled(Bool_t)", "CmsShowModelPopup", this, "toggleModelVisible(Bool_t)");
92  m_opacitySlider->Connect("PositionChanged(Int_t)", "CmsShowModelPopup", this, "changeModelOpacity(Int_t)");
93 
94  SetWindowName("Object Controller");
95  MapSubwindows();
96  Resize(GetDefaultSize());
97  Layout();
98 
99  fillModelPopup(*iSelMgr);
100 }
101 
102 // CmsShowModelPopup::CmsShowModelPopup(const CmsShowModelPopup& rhs)
103 // {
104 // // do actual copying here;
105 // }
106 
108  m_changes.disconnect();
109  m_colorSelectWidget->Disconnect("ColorSelected(Pixel_t)", this, "changeModelColor(Pixel_t)");
110  m_opacitySlider->Disconnect("PositionChanged(Int_t)", this, "changeModelOpacity(Int_t)");
111  m_isVisibleButton->Disconnect("Toggled(Bool_t)", this, "toggleModelVisible(Bool_t)");
112  disconnectAll();
113 }
114 
115 //
116 // assignment operators
117 //
118 // const CmsShowModelPopup& CmsShowModelPopup::operator=(const CmsShowModelPopup& rhs)
119 // {
120 // //An exception safe implementation is
121 // CmsShowModelPopup temp(rhs);
122 // swap(rhs);
123 //
124 // return *this;
125 // }
126 
127 //
128 // member functions
129 //
135  disconnectAll();
136  // Handles the case in which the selection is empty.
137  if (iSelMgr.selected().empty())
138  return;
139 
140  // Handle the case in which the selection is not empty.
141  bool multipleNames = false, multipleColors = false, multipleVis = false, multipleTransparecy = false;
142 
143  m_models = iSelMgr.selected();
144  std::set<FWModelId>::const_iterator id = m_models.begin();
145  const FWEventItem *item = id->item();
146  const FWEventItem::ModelInfo info = item->modelInfo(id->index());
147  const FWDisplayProperties &props = info.displayProperties();
148 
149  // The old logic was broken here. It was enought that the last item
150  // was the same as the first one, and all of them would have been considered
151  // equal. This should fix it. The idea is that if any of the elements in
152  // models in [1, N] are different from the first, then we consider the
153  // set with multipleXYZ.
154  for (std::set<FWModelId>::const_iterator i = ++(m_models.begin()), e = m_models.end(); i != e; ++i) {
155  const FWEventItem::ModelInfo &nextInfo = i->item()->modelInfo(i->index());
156  const FWDisplayProperties &nextProps = nextInfo.displayProperties();
157 
158  multipleNames = multipleNames || (item->name() != i->item()->name());
159  multipleColors = multipleColors || (props.color() != nextProps.color());
160  multipleVis = multipleVis || (props.isVisible() != nextProps.isVisible());
161  multipleTransparecy = multipleTransparecy || (props.transparency() != nextProps.transparency());
162  }
163 
164  // Handle the name.
165  std::ostringstream s;
166  if (multipleNames)
167  s << m_models.size() << " objects";
168  else
169  s << m_models.size() << " " << item->name();
170  m_modelLabel->SetText(s.str().c_str());
171 
172  if (m_models.size() == 1) {
173  m_modelLabel->SetText(item->modelName(id->index()).c_str());
174  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*id);
175  m_openDetailedViewButtons.front()->SetEnabled(!viewChoices.empty());
176  //be sure we show just the right number of buttons
177  if (viewChoices.size() > m_openDetailedViewButtons.size()) {
178  for (size_t i = 0, e = m_openDetailedViewButtons.size(); i != e; ++i) {
179  // printf("show existing buttons\n");
180  TGCompositeFrame *cf = (TGCompositeFrame *)m_openDetailedViewButtons[i]->GetParent();
181  cf->ShowFrame(m_openDetailedViewButtons[i]);
182  }
183 
184  //now we make additional buttons
185  TGTextButton *button;
186  for (size_t index = m_openDetailedViewButtons.size(); index < viewChoices.size(); ++index) {
187  button = new TGTextButton(this, "dummy", index);
188  AddFrame(button, new TGLayoutHints(kLHintsExpandX, 4, 4, 4, 4));
189  TGCompositeFrame *cf = (TGCompositeFrame *)button->GetParent();
190  cf->MapWindow();
191  cf->MapSubwindows();
192  m_openDetailedViewButtons.push_back(button);
193 
194  button->Connect("Clicked()", "CmsShowModelPopup", this, "clicked()");
195  }
196  } else if (!viewChoices.empty()) {
197  // printf("show button subset %d \n", viewChoices.size());
198  for (size_t i = 0, e = viewChoices.size(); i != e; ++i) {
199  TGCompositeFrame *cf = (TGCompositeFrame *)m_openDetailedViewButtons[i]->GetParent();
200  cf->ShowFrame(m_openDetailedViewButtons[i]);
201  }
202  }
203 
204  //set the names
205  for (size_t i = 0, e = viewChoices.size(); i != e; ++i) {
206  if (viewChoices[i][0] == '!') {
207  m_openDetailedViewButtons[i]->SetEnabled(false);
208  m_openDetailedViewButtons[i]->SetText(("Open " + viewChoices[i].substr(1) + " Detail View ...").c_str());
209 
210  } else {
211  m_openDetailedViewButtons[i]->SetText(("Open " + viewChoices[i] + " Detail View ...").c_str());
212  m_openDetailedViewButtons[i]->SetEnabled(true);
213  }
214  }
215  }
216 
217  // Set the various widgets.
218  m_colorSelectWidget->SetColorByIndex(props.color(), kFALSE);
219  m_opacitySlider->SetPosition(100 - props.transparency());
220  m_isVisibleButton->SetDisabledAndSelected(props.isVisible());
221 
222  m_opacitySlider->SetEnabled(kTRUE);
223  m_colorSelectWidget->SetEnabled(kTRUE);
224  m_isVisibleButton->SetEnabled(kTRUE);
225 
226  m_modelChangedConn = item->changed_.connect(boost::bind(&CmsShowModelPopup::updateDisplay, this));
227  m_destroyedConn = item->goingToBeDestroyed_.connect(boost::bind(&CmsShowModelPopup::disconnectAll, this));
228 
229  Resize(GetDefaultSize());
230  Layout();
231 }
232 
236  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i) {
237  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
238  const FWDisplayProperties &p = info.displayProperties();
239  m_colorSelectWidget->SetColorByIndex(p.color(), kFALSE);
240 
241  if (p.isVisible())
242  m_isVisibleButton->SetState(kButtonDown, kFALSE);
243  else
244  m_isVisibleButton->SetState(kButtonUp, kFALSE);
245 
246  m_opacitySlider->SetPosition(100 - p.transparency());
247  }
248 }
249 
250 /* Called by FWGUIManager when change background/colorset. */
252  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i) {
253  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
254  const FWDisplayProperties &p = info.displayProperties();
255  m_colorSelectWidget->SetColorByIndex(p.color(), kFALSE);
256  }
257 }
258 
263  m_modelChangedConn.disconnect();
264  m_destroyedConn.disconnect();
265  // m_item = 0;
266  // m_model = 0;
267  m_modelLabel->SetText("No object selected");
268  m_colorSelectWidget->SetColorByIndex(kRed, kFALSE);
269  m_isVisibleButton->SetDisabledAndSelected(kTRUE);
270  m_colorSelectWidget->SetEnabled(kFALSE);
271  m_opacitySlider->SetEnabled(kFALSE);
272  m_isVisibleButton->SetEnabled(kFALSE);
273  m_openDetailedViewButtons.front()->SetEnabled(kFALSE);
274  m_openDetailedViewButtons.front()->SetText("Open Detail View ...");
276  for (size_t i = 1, e = m_openDetailedViewButtons.size(); i != e; ++i) {
277  TGCompositeFrame *cf = (TGCompositeFrame *)m_openDetailedViewButtons[i]->GetParent();
278  cf->HideFrame(m_openDetailedViewButtons[i]);
279  }
280 }
281 
290  if (m_models.empty())
291  return;
292 
293  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
294  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i) {
295  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
296  FWDisplayProperties changeProperties = info.displayProperties();
297  changeProperties.setColor(color);
298  i->item()->setDisplayProperties(i->index(), changeProperties);
299  }
300 }
301 
306  if (m_models.empty())
307  return;
308 
309  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
310  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i) {
311  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
312  FWDisplayProperties changeProperties = info.displayProperties();
313  changeProperties.setTransparency(100 - opacity);
314  i->item()->setDisplayProperties(i->index(), changeProperties);
315  }
316 }
317 
322  if (m_models.empty())
323  return;
324 
325  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
326  for (std::set<FWModelId>::iterator i = m_models.begin(); i != m_models.end(); ++i) {
327  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
328  FWDisplayProperties changeProperties = info.displayProperties();
329  changeProperties.setIsVisible(on);
330  i->item()->setDisplayProperties(i->index(), changeProperties);
331  }
332 }
333 
335  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
336 
337  m_detailViewManager->openDetailViewFor(*(m_models.begin()), viewChoices.front());
338 }
339 
341  TGTextButton *cs = static_cast<TGTextButton *>(gTQSender);
342  int iIndex = cs->WidgetId();
343  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
344 
345  m_detailViewManager->openDetailViewFor(*(m_models.begin()), *(viewChoices.begin() + iIndex));
346 }
347 //
348 // const member functions
349 //
350 
351 //
352 // static member functions
353 //
FWColorSelect::SetColorByIndex
void SetColorByIndex(Color_t iColor)
Definition: FWColorSelect.cc:352
FWModelChangeManager.h
FWDialogBuilder::addHSeparator
FWDialogBuilder & addHSeparator(size_t horizontalPadding=4, size_t verticalPadding=3)
Definition: FWDialogBuilder.cc:345
FWDisplayProperties::isVisible
bool isVisible() const
Definition: FWDisplayProperties.h:51
mps_fire.i
i
Definition: mps_fire.py:355
CmsShowModelPopup::m_opacitySlider
TGHSlider * m_opacitySlider
Definition: CmsShowModelPopup.h:102
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:45
CmsShowModelPopup::disconnectAll
void disconnectAll()
Definition: CmsShowModelPopup.cc:262
CmsShowModelPopup::m_modelChangedConn
sigc::connection m_modelChangedConn
Definition: CmsShowModelPopup.h:96
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
CmsShowModelPopup::m_colorSelectWidget
FWColorSelect * m_colorSelectWidget
Definition: CmsShowModelPopup.h:90
FWDisplayProperties::setIsVisible
void setIsVisible(bool iSet)
Definition: FWDisplayProperties.h:71
FWModelId.h
FWDialogBuilder::indent
FWDialogBuilder & indent(int left=2, int right=-1)
Definition: FWDialogBuilder.cc:202
FWDetailViewManager::openDetailViewFor
void openDetailViewFor(const FWModelId &, const std::string &)
Definition: FWDetailViewManager.cc:71
cms::cuda::assert
assert(be >=bs)
CmsShowModelPopup::m_isVisibleButton
TGCheckButton * m_isVisibleButton
Definition: CmsShowModelPopup.h:91
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
FWColorSelect.h
FWDisplayProperties::color
Color_t color() const
Definition: FWDisplayProperties.h:47
CmsShowModelPopup::changeModelColor
void changeModelColor(Color_t iColor)
Definition: CmsShowModelPopup.cc:289
CmsShowModelPopup::clicked
void clicked()
Definition: CmsShowModelPopup.cc:340
FWEventItem::ModelInfo
Definition: FWEventItem.h:58
FWModelChangeSignal.h
FWDetailViewManager
Definition: FWDetailViewManager.h:35
alignCSCRings.s
s
Definition: alignCSCRings.py:92
CmsShowModelPopup::changeModelOpacity
void changeModelOpacity(Int_t opacity=100)
Definition: CmsShowModelPopup.cc:305
FWSelectionManager.h
CmsShowModelPopup::colorSetChanged
void colorSetChanged()
Definition: CmsShowModelPopup.cc:251
FWDialogBuilder
Definition: FWDialogBuilder.h:93
FWColorManager.h
FWSelectionManager::selectionChanged_
sigc::signal< void, const FWSelectionManager & > selectionChanged_
Definition: FWSelectionManager.h:53
w
const double w
Definition: UKUtility.cc:23
CmsShowModelPopup::updateDisplay
void updateDisplay()
Definition: CmsShowModelPopup.cc:235
FWChangeSentry
Definition: FWModelChangeManager.h:68
FWSelectionManager::selected
const std::set< FWModelId > & selected() const
Definition: FWSelectionManager.cc:168
CmsShowModelPopup::~CmsShowModelPopup
~CmsShowModelPopup() override
Definition: CmsShowModelPopup.cc:107
CmsShowModelPopup::m_changes
sigc::connection m_changes
Definition: CmsShowModelPopup.h:98
h
FWDisplayProperties::transparency
Char_t transparency() const
Definition: FWDisplayProperties.h:49
FWDialogBuilder.h
FWDialogBuilder::expand
FWDialogBuilder & expand(size_t expandX=true, size_t expandY=false)
Definition: FWDialogBuilder.cc:479
FWDialogBuilder::addHSlider
FWDialogBuilder & addHSlider(size_t size, TGHSlider **out=nullptr)
Definition: FWDialogBuilder.cc:275
FWDetailViewManager::detailViewsFor
std::vector< std::string > detailViewsFor(const FWModelId &) const
Definition: FWDetailViewManager.cc:112
FWDialogBuilder::addColorPicker
FWDialogBuilder & addColorPicker(const FWColorManager *manager, FWColorSelect **out=nullptr)
Definition: FWDialogBuilder.cc:265
CmsShowModelPopup::openDetailedView
void openDetailedView()
Definition: CmsShowModelPopup.cc:334
FWDisplayProperties::setColor
void setColor(Color_t iColor)
Definition: FWDisplayProperties.h:62
CmsShowModelPopup::m_openDetailedViewButtons
std::vector< TGTextButton * > m_openDetailedViewButtons
Definition: CmsShowModelPopup.h:92
FWSelectionManager
Definition: FWSelectionManager.h:34
CmsShowModelPopup::m_modelLabel
TGLabel * m_modelLabel
Definition: CmsShowModelPopup.h:89
CmsShowModelPopup::fillModelPopup
void fillModelPopup(const FWSelectionManager &iSelMgr)
Definition: CmsShowModelPopup.cc:134
CmsShowModelPopup::m_models
std::set< FWModelId > m_models
Definition: CmsShowModelPopup.h:95
CmsShowModelPopup::m_dialogBuilder
FWDialogBuilder * m_dialogBuilder
Definition: CmsShowModelPopup.h:103
FWDisplayProperties.h
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
FWDisplayProperties::setTransparency
void setTransparency(Char_t transparency)
Definition: FWDisplayProperties.h:65
FWColorManager
Definition: FWColorManager.h:45
FWEventItem.h
FWEventItem::ModelInfo::displayProperties
const FWDisplayProperties & displayProperties() const
Definition: FWEventItem.h:64
FWDisplayProperties
Definition: FWDisplayProperties.h:28
FWEventItem
Definition: FWEventItem.h:56
FWDetailViewManager.h
CmsShowModelPopup.h
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
CmsShowModelPopup::CmsShowModelPopup
CmsShowModelPopup(FWDetailViewManager *, FWSelectionManager *, const FWColorManager *, const TGWindow *p=nullptr, UInt_t w=1, UInt_t h=1)
Definition: CmsShowModelPopup.cc:54
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
CmsShowModelPopup::m_destroyedConn
sigc::connection m_destroyedConn
Definition: CmsShowModelPopup.h:97
CmsShowModelPopup::toggleModelVisible
void toggleModelVisible(Bool_t on=kTRUE)
Definition: CmsShowModelPopup.cc:321
FWDialogBuilder::addLabel
FWDialogBuilder & addLabel(const char *text, size_t fontSize=12, size_t weight=0, TGLabel **out=nullptr)
Definition: FWDialogBuilder.cc:212
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
CmsShowModelPopup::m_detailViewManager
FWDetailViewManager * m_detailViewManager
Definition: CmsShowModelPopup.h:100
FWDialogBuilder::addCheckbox
FWDialogBuilder & addCheckbox(const char *text, TGCheckButton **out=nullptr)
Definition: FWDialogBuilder.cc:327