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 //
CmsShowModelPopup(FWDetailViewManager *, FWSelectionManager *, const FWColorManager *, const TGWindow *p=nullptr, UInt_t w=1, UInt_t h=1)
void setColor(Color_t iColor)
static const TGPicture * info(bool iBackgroundIsBlack)
sigc::connection m_destroyedConn
void changeModelColor(Color_t iColor)
void SetColorByIndex(Color_t iColor)
T w() const
void toggleModelVisible(Bool_t on=kTRUE)
FWDialogBuilder & addHSlider(size_t size, TGHSlider **out=nullptr)
Char_t transparency() const
sigc::connection m_changes
std::vector< std::string > detailViewsFor(const FWModelId &) const
FWDialogBuilder & addLabel(const char *text, size_t fontSize=12, size_t weight=0, TGLabel **out=nullptr)
assert(be >=bs)
const FWDisplayProperties & displayProperties() const
Definition: FWEventItem.h:64
FWDialogBuilder & addCheckbox(const char *text, TGCheckButton **out=nullptr)
sigc::connection m_modelChangedConn
TGCheckButton * m_isVisibleButton
std::set< FWModelId > m_models
~CmsShowModelPopup() override
FWDialogBuilder & addHSeparator(size_t horizontalPadding=4, size_t verticalPadding=3)
void changeModelOpacity(Int_t opacity=100)
sigc::signal< void(const FWSelectionManager &)> selectionChanged_
std::vector< TGTextButton * > m_openDetailedViewButtons
FWDialogBuilder & expand(size_t expandX=true, size_t expandY=false)
void setTransparency(Char_t transparency)
void openDetailViewFor(const FWModelId &, const std::string &)
FWDialogBuilder * m_dialogBuilder
FWDetailViewManager * m_detailViewManager
void fillModelPopup(const FWSelectionManager &iSelMgr)
const std::set< FWModelId > & selected() const
void setIsVisible(bool iSet)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
TGHSlider * m_opacitySlider
FWDialogBuilder & indent(int left=2, int right=-1)
FWDialogBuilder & addColorPicker(const FWColorManager *manager, FWColorSelect **out=nullptr)
FWColorSelect * m_colorSelectWidget