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 <functional>
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 =
65  iSelMgr->selectionChanged_.connect(std::bind(&CmsShowModelPopup::fillModelPopup, this, std::placeholders::_1));
66 
67  SetCleanup(kDeepCleanup);
68 
69  TGVerticalFrame *vf = new TGVerticalFrame(this);
70  AddFrame(vf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 4));
72 
73  // Do the layouting of the various widgets.
75  .addLabel(" ", 14, 1, &m_modelLabel)
76  .addLabel("Color", 8)
78  .expand(false)
79  .addHSeparator()
80  .addLabel("Opacity", 8)
82  .addHSeparator(2)
83  .addCheckbox("Visible", &m_isVisibleButton)
84  .addHSeparator();
85 
86  // Dummy button for detail views. Can be overidden.
87  TGTextButton *detailedViewButton = new TGTextButton(this, "Open Detailed View", 0);
88  AddFrame(detailedViewButton, new TGLayoutHints(kLHintsExpandX, 4, 4, 4, 4));
89  m_openDetailedViewButtons.push_back(detailedViewButton);
90 
91  m_colorSelectWidget->Connect("ColorChosen(Color_t)", "CmsShowModelPopup", this, "changeModelColor(Color_t)");
92  m_isVisibleButton->Connect("Toggled(Bool_t)", "CmsShowModelPopup", this, "toggleModelVisible(Bool_t)");
93  m_opacitySlider->Connect("PositionChanged(Int_t)", "CmsShowModelPopup", this, "changeModelOpacity(Int_t)");
94 
95  SetWindowName("Object Controller");
96  MapSubwindows();
97  Resize(GetDefaultSize());
98  Layout();
99 
100  fillModelPopup(*iSelMgr);
101 }
102 
103 // CmsShowModelPopup::CmsShowModelPopup(const CmsShowModelPopup& rhs)
104 // {
105 // // do actual copying here;
106 // }
107 
109  m_changes.disconnect();
110  m_colorSelectWidget->Disconnect("ColorSelected(Pixel_t)", this, "changeModelColor(Pixel_t)");
111  m_opacitySlider->Disconnect("PositionChanged(Int_t)", this, "changeModelOpacity(Int_t)");
112  m_isVisibleButton->Disconnect("Toggled(Bool_t)", this, "toggleModelVisible(Bool_t)");
113  disconnectAll();
114 }
115 
116 //
117 // assignment operators
118 //
119 // const CmsShowModelPopup& CmsShowModelPopup::operator=(const CmsShowModelPopup& rhs)
120 // {
121 // //An exception safe implementation is
122 // CmsShowModelPopup temp(rhs);
123 // swap(rhs);
124 //
125 // return *this;
126 // }
127 
128 //
129 // member functions
130 //
136  disconnectAll();
137  // Handles the case in which the selection is empty.
138  if (iSelMgr.selected().empty())
139  return;
140 
141  // Handle the case in which the selection is not empty.
142  bool multipleNames = false, multipleColors = false, multipleVis = false, multipleTransparecy = false;
143 
144  m_models = iSelMgr.selected();
145  std::set<FWModelId>::const_iterator id = m_models.begin();
146  const FWEventItem *item = id->item();
147  const FWEventItem::ModelInfo info = item->modelInfo(id->index());
148  const FWDisplayProperties &props = info.displayProperties();
149 
150  // The old logic was broken here. It was enought that the last item
151  // was the same as the first one, and all of them would have been considered
152  // equal. This should fix it. The idea is that if any of the elements in
153  // models in [1, N] are different from the first, then we consider the
154  // set with multipleXYZ.
155  for (std::set<FWModelId>::const_iterator i = ++(m_models.begin()), e = m_models.end(); i != e; ++i) {
156  const FWEventItem::ModelInfo &nextInfo = i->item()->modelInfo(i->index());
157  const FWDisplayProperties &nextProps = nextInfo.displayProperties();
158 
159  multipleNames = multipleNames || (item->name() != i->item()->name());
160  multipleColors = multipleColors || (props.color() != nextProps.color());
161  multipleVis = multipleVis || (props.isVisible() != nextProps.isVisible());
162  multipleTransparecy = multipleTransparecy || (props.transparency() != nextProps.transparency());
163  }
164 
165  // Handle the name.
166  std::ostringstream s;
167  if (multipleNames)
168  s << m_models.size() << " objects";
169  else
170  s << m_models.size() << " " << item->name();
171  m_modelLabel->SetText(s.str().c_str());
172 
173  if (m_models.size() == 1) {
174  m_modelLabel->SetText(item->modelName(id->index()).c_str());
175  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*id);
176  m_openDetailedViewButtons.front()->SetEnabled(!viewChoices.empty());
177  //be sure we show just the right number of buttons
178  if (viewChoices.size() > m_openDetailedViewButtons.size()) {
179  for (size_t i = 0, e = m_openDetailedViewButtons.size(); i != e; ++i) {
180  // printf("show existing buttons\n");
181  TGCompositeFrame *cf = (TGCompositeFrame *)m_openDetailedViewButtons[i]->GetParent();
182  cf->ShowFrame(m_openDetailedViewButtons[i]);
183  }
184 
185  //now we make additional buttons
186  TGTextButton *button;
187  for (size_t index = m_openDetailedViewButtons.size(); index < viewChoices.size(); ++index) {
188  button = new TGTextButton(this, "dummy", index);
189  AddFrame(button, new TGLayoutHints(kLHintsExpandX, 4, 4, 4, 4));
190  TGCompositeFrame *cf = (TGCompositeFrame *)button->GetParent();
191  cf->MapWindow();
192  cf->MapSubwindows();
193  m_openDetailedViewButtons.push_back(button);
194 
195  button->Connect("Clicked()", "CmsShowModelPopup", this, "clicked()");
196  }
197  } else if (!viewChoices.empty()) {
198  // printf("show button subset %d \n", viewChoices.size());
199  for (size_t i = 0, e = viewChoices.size(); i != e; ++i) {
200  TGCompositeFrame *cf = (TGCompositeFrame *)m_openDetailedViewButtons[i]->GetParent();
201  cf->ShowFrame(m_openDetailedViewButtons[i]);
202  }
203  }
204 
205  //set the names
206  for (size_t i = 0, e = viewChoices.size(); i != e; ++i) {
207  if (viewChoices[i][0] == '!') {
208  m_openDetailedViewButtons[i]->SetEnabled(false);
209  m_openDetailedViewButtons[i]->SetText(("Open " + viewChoices[i].substr(1) + " Detail View ...").c_str());
210 
211  } else {
212  m_openDetailedViewButtons[i]->SetText(("Open " + viewChoices[i] + " Detail View ...").c_str());
213  m_openDetailedViewButtons[i]->SetEnabled(true);
214  }
215  }
216  }
217 
218  // Set the various widgets.
219  m_colorSelectWidget->SetColorByIndex(props.color(), kFALSE);
220  m_opacitySlider->SetPosition(100 - props.transparency());
221  m_isVisibleButton->SetDisabledAndSelected(props.isVisible());
222 
223  m_opacitySlider->SetEnabled(kTRUE);
224  m_colorSelectWidget->SetEnabled(kTRUE);
225  m_isVisibleButton->SetEnabled(kTRUE);
226 
227  m_modelChangedConn = item->changed_.connect(std::bind(&CmsShowModelPopup::updateDisplay, this));
228  m_destroyedConn = item->goingToBeDestroyed_.connect(std::bind(&CmsShowModelPopup::disconnectAll, this));
229 
230  Resize(GetDefaultSize());
231  Layout();
232 }
233 
237  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i) {
238  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
239  const FWDisplayProperties &p = info.displayProperties();
240  m_colorSelectWidget->SetColorByIndex(p.color(), kFALSE);
241 
242  if (p.isVisible())
243  m_isVisibleButton->SetState(kButtonDown, kFALSE);
244  else
245  m_isVisibleButton->SetState(kButtonUp, kFALSE);
246 
247  m_opacitySlider->SetPosition(100 - p.transparency());
248  }
249 }
250 
251 /* Called by FWGUIManager when change background/colorset. */
253  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i) {
254  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
255  const FWDisplayProperties &p = info.displayProperties();
256  m_colorSelectWidget->SetColorByIndex(p.color(), kFALSE);
257  }
258 }
259 
264  m_modelChangedConn.disconnect();
265  m_destroyedConn.disconnect();
266  // m_item = 0;
267  // m_model = 0;
268  m_modelLabel->SetText("No object selected");
269  m_colorSelectWidget->SetColorByIndex(kRed, kFALSE);
270  m_isVisibleButton->SetDisabledAndSelected(kTRUE);
271  m_colorSelectWidget->SetEnabled(kFALSE);
272  m_opacitySlider->SetEnabled(kFALSE);
273  m_isVisibleButton->SetEnabled(kFALSE);
274  m_openDetailedViewButtons.front()->SetEnabled(kFALSE);
275  m_openDetailedViewButtons.front()->SetText("Open Detail View ...");
277  for (size_t i = 1, e = m_openDetailedViewButtons.size(); i != e; ++i) {
278  TGCompositeFrame *cf = (TGCompositeFrame *)m_openDetailedViewButtons[i]->GetParent();
279  cf->HideFrame(m_openDetailedViewButtons[i]);
280  }
281 }
282 
291  if (m_models.empty())
292  return;
293 
294  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
295  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i) {
296  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
297  FWDisplayProperties changeProperties = info.displayProperties();
298  changeProperties.setColor(color);
299  i->item()->setDisplayProperties(i->index(), changeProperties);
300  }
301 }
302 
307  if (m_models.empty())
308  return;
309 
310  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
311  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i) {
312  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
313  FWDisplayProperties changeProperties = info.displayProperties();
314  changeProperties.setTransparency(100 - opacity);
315  i->item()->setDisplayProperties(i->index(), changeProperties);
316  }
317 }
318 
323  if (m_models.empty())
324  return;
325 
326  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
327  for (std::set<FWModelId>::iterator i = m_models.begin(); i != m_models.end(); ++i) {
328  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
329  FWDisplayProperties changeProperties = info.displayProperties();
330  changeProperties.setIsVisible(on);
331  i->item()->setDisplayProperties(i->index(), changeProperties);
332  }
333 }
334 
336  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
337 
338  m_detailViewManager->openDetailViewFor(*(m_models.begin()), viewChoices.front());
339 }
340 
342  TGTextButton *cs = static_cast<TGTextButton *>(gTQSender);
343  int iIndex = cs->WidgetId();
344  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
345 
346  m_detailViewManager->openDetailViewFor(*(m_models.begin()), *(viewChoices.begin() + iIndex));
347 }
348 //
349 // const member functions
350 //
351 
352 //
353 // static member functions
354 //
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:428
CmsShowModelPopup::m_opacitySlider
TGHSlider * m_opacitySlider
Definition: CmsShowModelPopup.h:102
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:47
CmsShowModelPopup::disconnectAll
void disconnectAll()
Definition: CmsShowModelPopup.cc:263
CmsShowModelPopup::m_modelChangedConn
sigc::connection m_modelChangedConn
Definition: CmsShowModelPopup.h:96
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:153
FWColorSelect.h
FWDisplayProperties::color
Color_t color() const
Definition: FWDisplayProperties.h:47
CmsShowModelPopup::changeModelColor
void changeModelColor(Color_t iColor)
Definition: CmsShowModelPopup.cc:290
CmsShowModelPopup::clicked
void clicked()
Definition: CmsShowModelPopup.cc:341
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:306
FWSelectionManager.h
CmsShowModelPopup::colorSetChanged
void colorSetChanged()
Definition: CmsShowModelPopup.cc:252
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:236
FWChangeSentry
Definition: FWModelChangeManager.h:68
FWSelectionManager::selected
const std::set< FWModelId > & selected() const
Definition: FWSelectionManager.cc:168
CmsShowModelPopup::~CmsShowModelPopup
~CmsShowModelPopup() override
Definition: CmsShowModelPopup.cc:108
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:335
FWDisplayProperties::setColor
void setColor(Color_t iColor)
Definition: FWDisplayProperties.h:62
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
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:135
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:29
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:322
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