CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: CmsShowModelPopup.cc,v 1.33 2012/09/21 09:26:26 eulisse Exp $
12 //
13 
14 // system include file
15 #include <iostream>
16 #include <sstream>
17 #include <set>
18 #include <cassert>
19 #include <sigc++/sigc++.h>
20 #include <boost/bind.hpp>
21 #include "TClass.h"
22 #include "TGFrame.h"
23 #include "TGButton.h"
24 #include "TGLabel.h"
25 #include "TGString.h"
26 #include "TColor.h"
27 #include "TG3DLine.h"
28 #include "TGFont.h"
29 #include "TGSlider.h"
30 #include "TGButton.h"
31 
32 // user include files
44 
45 //
46 // constants, enums and typedefs
47 //
48 
49 //
50 // static data member definitions
51 //
52 //
53 // constructors and destructor
54 //
56  FWSelectionManager* iSelMgr,
57  const FWColorManager* iColorMgr,
58  const TGWindow* p, UInt_t w, UInt_t h) :
59  TGTransientFrame(gClient->GetDefaultRoot(),p,w,h),
60  m_detailViewManager(iManager),
61  m_colorManager(iColorMgr),
62  m_dialogBuilder(0)
63 {
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)
76  .addColorPicker(iColorMgr, &m_colorSelectWidget).expand(false)
77  .addHSeparator()
78  .addLabel("Opacity", 8)
80  .addHSeparator(2)
81  .addCheckbox("Visible", &m_isVisibleButton)
82  .addHSeparator();
83 
84  // Dummy button for detail views. Can be overidden.
85  TGTextButton *detailedViewButton = new TGTextButton(this, "Open Detailed View", 0);
86  AddFrame(detailedViewButton, new TGLayoutHints(kLHintsExpandX, 4, 4, 4, 4));
87  m_openDetailedViewButtons.push_back(detailedViewButton);
88 
89  m_colorSelectWidget->Connect("ColorChosen(Color_t)", "CmsShowModelPopup", this, "changeModelColor(Color_t)");
90  m_isVisibleButton->Connect("Toggled(Bool_t)", "CmsShowModelPopup", this, "toggleModelVisible(Bool_t)");
91  m_opacitySlider->Connect("PositionChanged(Int_t)", "CmsShowModelPopup",
92  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 {
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 //
135 void
137 {
138  disconnectAll();
139  // Handles the case in which the selection is empty.
140  if (iSelMgr.selected().empty())
141  return;
142 
143  // Handle the case in which the selection is not empty.
144  bool multipleNames = false, multipleColors = false, multipleVis = false,
145  multipleTransparecy = false;
146 
147  m_models = iSelMgr.selected();
148  std::set<FWModelId>::const_iterator id = m_models.begin();
149  const FWEventItem* item = id->item();
150  const FWEventItem::ModelInfo info = item->modelInfo(id->index());
151  const FWDisplayProperties &props = info.displayProperties();
152 
153  // The old logic was broken here. It was enought that the last item
154  // was the same as the first one, and all of them would have been considered
155  // equal. This should fix it. The idea is that if any of the elements in
156  // models in [1, N] are different from the first, then we consider the
157  // set with multipleXYZ.
158  for (std::set<FWModelId>::const_iterator i = ++(m_models.begin()),
159  e = m_models.end(); i != e; ++i)
160  {
161  const FWEventItem::ModelInfo &nextInfo = i->item()->modelInfo(i->index());
162  const FWDisplayProperties &nextProps = nextInfo.displayProperties();
163 
164  multipleNames = multipleNames || (item->name() != i->item()->name());
165  multipleColors = multipleColors || (props.color() != nextProps.color());
166  multipleVis = multipleVis || (props.isVisible() != nextProps.isVisible());
167  multipleTransparecy = multipleTransparecy
168  || (props.transparency() != nextProps.transparency());
169  }
170 
171  // Handle the name.
172  std::ostringstream s;
173  if (multipleNames)
174  s << m_models.size() << " objects";
175  else
176  s << m_models.size() << " " << item->name();
177  m_modelLabel->SetText(s.str().c_str());
178 
179  if (m_models.size()==1)
180  {
181  m_modelLabel->SetText(item->modelName(id->index()).c_str());
182  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*id);
183  m_openDetailedViewButtons.front()->SetEnabled(viewChoices.size()>0);
184  //be sure we show just the right number of buttons
185  if(viewChoices.size() > m_openDetailedViewButtons.size())
186  {
187  for(size_t i = 0, e = m_openDetailedViewButtons.size(); i != e; ++i)
188  {
189  // printf("show existing buttons\n");
190  TGCompositeFrame* cf = (TGCompositeFrame*)m_openDetailedViewButtons[i]->GetParent();
191  cf->ShowFrame(m_openDetailedViewButtons[i]);
192  }
193 
194  //now we make additional buttons
195  TGTextButton *button;
196  for(size_t index = m_openDetailedViewButtons.size(); index < viewChoices.size(); ++index)
197  {
198  // printf("add new button %s \n ", viewChoices[index].c_str());
199  button = new TGTextButton(this, "dummy", index);
200  AddFrame(button, new TGLayoutHints(kLHintsExpandX, 4, 4, 4, 4));
201  TGCompositeFrame* cf = (TGCompositeFrame*)button->GetParent();
202  cf->MapWindow();
203  cf->MapSubwindows();
204  m_openDetailedViewButtons.push_back(button);
205 
206  button->Connect("Clicked()", "CmsShowModelPopup", this, "clicked()");
207  }
208  }
209  else if (!viewChoices.empty())
210  {
211  // printf("show button subset %d \n", viewChoices.size());
212  for (size_t i = 0, e = viewChoices.size(); i != e; ++i)
213  {
214  TGCompositeFrame* cf = (TGCompositeFrame*)m_openDetailedViewButtons[i]->GetParent();
215  cf->ShowFrame(m_openDetailedViewButtons[i]);
216  }
217  }
218 
219  //set the names
220  for (size_t i = 0, e = viewChoices.size(); i != e; ++i)
221  {
222  m_openDetailedViewButtons[i]->SetText(("Open " + viewChoices[i] + " Detail View ...").c_str());
223  }
224  }
225 
226  // Set the various widgets.
227  m_colorSelectWidget->SetColorByIndex(props.color(), kFALSE);
228  m_opacitySlider->SetPosition(100 - props.transparency());
229  m_isVisibleButton->SetDisabledAndSelected(props.isVisible());
230 
231  m_opacitySlider->SetEnabled(kTRUE);
232  m_colorSelectWidget->SetEnabled(kTRUE);
233  m_isVisibleButton->SetEnabled(kTRUE);
234 
235  m_modelChangedConn = item->changed_.connect(boost::bind(&CmsShowModelPopup::updateDisplay, this));
236  m_destroyedConn = item->goingToBeDestroyed_.connect(boost::bind(&CmsShowModelPopup::disconnectAll, this));
237 
238  Resize(GetDefaultSize());
239  Layout();
240 }
241 
244 void
246 {
247  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end();
248  i != e; ++i)
249  {
250  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
251  const FWDisplayProperties &p = info.displayProperties();
253 
254  if (p.isVisible())
255  m_isVisibleButton->SetState(kButtonDown, kFALSE);
256  else
257  m_isVisibleButton->SetState(kButtonUp, kFALSE);
258 
259  m_opacitySlider->SetPosition(100 - p.transparency());
260  }
261 }
262 
263 /* Called by FWGUIManager when change background/colorset. */
264 void
266 {
267  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end();
268  i != e; ++i)
269  {
270  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
271  const FWDisplayProperties &p = info.displayProperties();
273  }
274 }
275 
279 void
281  m_modelChangedConn.disconnect();
282  m_destroyedConn.disconnect();
283  // m_item = 0;
284  // m_model = 0;
285  m_modelLabel->SetText("No object selected");
286  m_colorSelectWidget->SetColorByIndex(kRed,kFALSE);
287  m_isVisibleButton->SetDisabledAndSelected(kTRUE);
288  m_colorSelectWidget->SetEnabled(kFALSE);
289  m_opacitySlider->SetEnabled(kFALSE);
290  m_isVisibleButton->SetEnabled(kFALSE);
291  m_openDetailedViewButtons.front()->SetEnabled(kFALSE);
292  m_openDetailedViewButtons.front()->SetText("Open Detail View ...");
293  assert(!m_openDetailedViewButtons.empty());
294  for(size_t i = 1, e = m_openDetailedViewButtons.size(); i != e; ++i)
295  {
296  TGCompositeFrame* cf = (TGCompositeFrame*)m_openDetailedViewButtons[i]->GetParent();
297  cf->HideFrame(m_openDetailedViewButtons[i]);
298  }
299 
300 
301 }
302 
310 void
312 {
313  if (m_models.empty())
314  return;
315 
316  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
317  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i)
318  {
319  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
320  FWDisplayProperties changeProperties = info.displayProperties();
321  changeProperties.setColor(color);
322  i->item()->setDisplayProperties(i->index(), changeProperties);
323  }
324 }
325 
329 void
331 {
332  if (m_models.empty())
333  return;
334 
335  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
336  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i)
337  {
338  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
339  FWDisplayProperties changeProperties = info.displayProperties();
340  changeProperties.setTransparency(100 - opacity);
341  i->item()->setDisplayProperties(i->index(), changeProperties);
342  }
343 }
344 
348 void
350  if(m_models.empty())
351  return;
352 
353  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
354  for (std::set<FWModelId>::iterator i = m_models.begin(); i != m_models.end(); ++i)
355  {
356  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
357  FWDisplayProperties changeProperties = info.displayProperties();
358  changeProperties.setIsVisible(on);
359  i->item()->setDisplayProperties(i->index(), changeProperties);
360  }
361 }
362 
363 void
365 {
366  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
367 
368  m_detailViewManager->openDetailViewFor( *(m_models.begin()), viewChoices.front() );
369 }
370 
371 void
373 {
374  TGTextButton *cs = static_cast<TGTextButton *>(gTQSender);
375  int iIndex = cs->WidgetId();
376  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
377 
378  m_detailViewManager->openDetailViewFor( *(m_models.begin()), *(viewChoices.begin()+iIndex) );
379 
380 }
381 //
382 // const member functions
383 //
384 
385 //
386 // static member functions
387 //
const std::set< FWModelId > & selected() const
int i
Definition: DBlmapReader.cc:9
FWDialogBuilder & addHSlider(size_t size, TGHSlider **out=0)
void setColor(Color_t iColor)
const FWDisplayProperties & displayProperties() const
Definition: FWEventItem.h:68
sigc::connection m_destroyedConn
auto_ptr< ClusterSequence > cs
void changeModelColor(Color_t iColor)
void SetColorByIndex(Color_t iColor)
std::string modelName(int iIndex) const
Definition: FWEventItem.cc:575
const std::string & name() const
Definition: FWEventItem.cc:501
FWDialogBuilder & addLabel(const char *text, size_t fontSize=12, size_t weight=0, TGLabel **out=0)
void toggleModelVisible(Bool_t on=kTRUE)
FWItemChangeSignal goingToBeDestroyed_
Definition: FWEventItem.h:215
sigc::connection m_changes
sigc::connection m_modelChangedConn
Color_t color() const
TGCheckButton * m_isVisibleButton
Char_t transparency() const
std::set< FWModelId > m_models
FWDialogBuilder & addHSeparator(size_t horizontalPadding=4, size_t verticalPadding=3)
void changeModelOpacity(Int_t opacity=100)
CmsShowModelPopup(FWDetailViewManager *, FWSelectionManager *, const FWColorManager *, const TGWindow *p=0, UInt_t w=1, UInt_t h=1)
unsigned int UInt_t
Definition: FUTypes.h:12
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
std::vector< std::string > detailViewsFor(const FWModelId &) const
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 &)
sigc::signal< void, const FWSelectionManager & > selectionChanged_
FWDialogBuilder * m_dialogBuilder
FWModelChangeSignal changed_
Definition: FWEventItem.h:196
FWDetailViewManager * m_detailViewManager
void fillModelPopup(const FWSelectionManager &iSelMgr)
T w() const
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:536
void setIsVisible(bool iSet)
FWDialogBuilder & addCheckbox(const char *text, TGCheckButton **out=0)
TGHSlider * m_opacitySlider
FWDialogBuilder & indent(int left=2, int right=-1)
FWColorSelect * m_colorSelectWidget
FWDialogBuilder & addColorPicker(const FWColorManager *manager, FWColorSelect **out=0)