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 //
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, UInt_t w, UInt_t h) :
58  TGTransientFrame(gClient->GetDefaultRoot(),p,w,h),
59  m_detailViewManager(iManager),
60  m_colorManager(iColorMgr),
61  m_dialogBuilder(0)
62 {
63  m_changes = iSelMgr->selectionChanged_.connect(boost::bind(&CmsShowModelPopup::fillModelPopup, this, _1));
64 
65  SetCleanup(kDeepCleanup);
66 
67  TGVerticalFrame* vf = new TGVerticalFrame(this);
68  AddFrame(vf, new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 2, 2, 2, 4));
70 
71  // Do the layouting of the various widgets.
73  .addLabel(" ", 14, 1, &m_modelLabel)
74  .addLabel("Color", 8)
75  .addColorPicker(iColorMgr, &m_colorSelectWidget).expand(false)
76  .addHSeparator()
77  .addLabel("Opacity", 8)
79  .addHSeparator(2)
80  .addCheckbox("Visible", &m_isVisibleButton)
81  .addHSeparator();
82 
83  // Dummy button for detail views. Can be overidden.
84  TGTextButton *detailedViewButton = new TGTextButton(this, "Open Detailed View", 0);
85  AddFrame(detailedViewButton, new TGLayoutHints(kLHintsExpandX, 4, 4, 4, 4));
86  m_openDetailedViewButtons.push_back(detailedViewButton);
87 
88  m_colorSelectWidget->Connect("ColorChosen(Color_t)", "CmsShowModelPopup", this, "changeModelColor(Color_t)");
89  m_isVisibleButton->Connect("Toggled(Bool_t)", "CmsShowModelPopup", this, "toggleModelVisible(Bool_t)");
90  m_opacitySlider->Connect("PositionChanged(Int_t)", "CmsShowModelPopup",
91  this, "changeModelOpacity(Int_t)");
92 
93  SetWindowName("Object Controller");
94  MapSubwindows();
95  Resize(GetDefaultSize());
96  Layout();
97 
98  fillModelPopup(*iSelMgr);
99 }
100 
101 // CmsShowModelPopup::CmsShowModelPopup(const CmsShowModelPopup& rhs)
102 // {
103 // // do actual copying here;
104 // }
105 
107 {
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 //
134 void
136 {
137  disconnectAll();
138  // Handles the case in which the selection is empty.
139  if (iSelMgr.selected().empty())
140  return;
141 
142  // Handle the case in which the selection is not empty.
143  bool multipleNames = false, multipleColors = false, multipleVis = false,
144  multipleTransparecy = false;
145 
146  m_models = iSelMgr.selected();
147  std::set<FWModelId>::const_iterator id = m_models.begin();
148  const FWEventItem* item = id->item();
149  const FWEventItem::ModelInfo info = item->modelInfo(id->index());
150  const FWDisplayProperties &props = info.displayProperties();
151 
152  // The old logic was broken here. It was enought that the last item
153  // was the same as the first one, and all of them would have been considered
154  // equal. This should fix it. The idea is that if any of the elements in
155  // models in [1, N] are different from the first, then we consider the
156  // set with multipleXYZ.
157  for (std::set<FWModelId>::const_iterator i = ++(m_models.begin()),
158  e = m_models.end(); i != e; ++i)
159  {
160  const FWEventItem::ModelInfo &nextInfo = i->item()->modelInfo(i->index());
161  const FWDisplayProperties &nextProps = nextInfo.displayProperties();
162 
163  multipleNames = multipleNames || (item->name() != i->item()->name());
164  multipleColors = multipleColors || (props.color() != nextProps.color());
165  multipleVis = multipleVis || (props.isVisible() != nextProps.isVisible());
166  multipleTransparecy = multipleTransparecy
167  || (props.transparency() != nextProps.transparency());
168  }
169 
170  // Handle the name.
171  std::ostringstream s;
172  if (multipleNames)
173  s << m_models.size() << " objects";
174  else
175  s << m_models.size() << " " << item->name();
176  m_modelLabel->SetText(s.str().c_str());
177 
178  if (m_models.size()==1)
179  {
180  m_modelLabel->SetText(item->modelName(id->index()).c_str());
181  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*id);
182  m_openDetailedViewButtons.front()->SetEnabled(viewChoices.size()>0);
183  //be sure we show just the right number of buttons
184  if(viewChoices.size() > m_openDetailedViewButtons.size())
185  {
186  for(size_t i = 0, e = m_openDetailedViewButtons.size(); i != e; ++i)
187  {
188  // printf("show existing buttons\n");
189  TGCompositeFrame* cf = (TGCompositeFrame*)m_openDetailedViewButtons[i]->GetParent();
190  cf->ShowFrame(m_openDetailedViewButtons[i]);
191  }
192 
193  //now we make additional buttons
194  TGTextButton *button;
195  for(size_t index = m_openDetailedViewButtons.size(); index < viewChoices.size(); ++index)
196  {
197  // printf("add new button %s \n ", viewChoices[index].c_str());
198  button = new TGTextButton(this, "dummy", index);
199  AddFrame(button, new TGLayoutHints(kLHintsExpandX, 4, 4, 4, 4));
200  TGCompositeFrame* cf = (TGCompositeFrame*)button->GetParent();
201  cf->MapWindow();
202  cf->MapSubwindows();
203  m_openDetailedViewButtons.push_back(button);
204 
205  button->Connect("Clicked()", "CmsShowModelPopup", this, "clicked()");
206  }
207  }
208  else if (!viewChoices.empty())
209  {
210  // printf("show button subset %d \n", viewChoices.size());
211  for (size_t i = 0, e = viewChoices.size(); i != e; ++i)
212  {
213  TGCompositeFrame* cf = (TGCompositeFrame*)m_openDetailedViewButtons[i]->GetParent();
214  cf->ShowFrame(m_openDetailedViewButtons[i]);
215  }
216  }
217 
218  //set the names
219  for (size_t i = 0, e = viewChoices.size(); i != e; ++i)
220  {
221  m_openDetailedViewButtons[i]->SetText(("Open " + viewChoices[i] + " Detail View ...").c_str());
222  }
223  }
224 
225  // Set the various widgets.
226  m_colorSelectWidget->SetColorByIndex(props.color(), kFALSE);
227  m_opacitySlider->SetPosition(100 - props.transparency());
228  m_isVisibleButton->SetDisabledAndSelected(props.isVisible());
229 
230  m_opacitySlider->SetEnabled(kTRUE);
231  m_colorSelectWidget->SetEnabled(kTRUE);
232  m_isVisibleButton->SetEnabled(kTRUE);
233 
234  m_modelChangedConn = item->changed_.connect(boost::bind(&CmsShowModelPopup::updateDisplay, this));
235  m_destroyedConn = item->goingToBeDestroyed_.connect(boost::bind(&CmsShowModelPopup::disconnectAll, this));
236 
237  Resize(GetDefaultSize());
238  Layout();
239 }
240 
243 void
245 {
246  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end();
247  i != e; ++i)
248  {
249  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
250  const FWDisplayProperties &p = info.displayProperties();
252 
253  if (p.isVisible())
254  m_isVisibleButton->SetState(kButtonDown, kFALSE);
255  else
256  m_isVisibleButton->SetState(kButtonUp, kFALSE);
257 
258  m_opacitySlider->SetPosition(100 - p.transparency());
259  }
260 }
261 
262 /* Called by FWGUIManager when change background/colorset. */
263 void
265 {
266  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end();
267  i != e; ++i)
268  {
269  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
270  const FWDisplayProperties &p = info.displayProperties();
272  }
273 }
274 
278 void
280  m_modelChangedConn.disconnect();
281  m_destroyedConn.disconnect();
282  // m_item = 0;
283  // m_model = 0;
284  m_modelLabel->SetText("No object selected");
285  m_colorSelectWidget->SetColorByIndex(kRed,kFALSE);
286  m_isVisibleButton->SetDisabledAndSelected(kTRUE);
287  m_colorSelectWidget->SetEnabled(kFALSE);
288  m_opacitySlider->SetEnabled(kFALSE);
289  m_isVisibleButton->SetEnabled(kFALSE);
290  m_openDetailedViewButtons.front()->SetEnabled(kFALSE);
291  m_openDetailedViewButtons.front()->SetText("Open Detail View ...");
292  assert(!m_openDetailedViewButtons.empty());
293  for(size_t i = 1, e = m_openDetailedViewButtons.size(); i != e; ++i)
294  {
295  TGCompositeFrame* cf = (TGCompositeFrame*)m_openDetailedViewButtons[i]->GetParent();
296  cf->HideFrame(m_openDetailedViewButtons[i]);
297  }
298 
299 
300 }
301 
309 void
311 {
312  if (m_models.empty())
313  return;
314 
315  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
316  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i)
317  {
318  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
319  FWDisplayProperties changeProperties = info.displayProperties();
320  changeProperties.setColor(color);
321  i->item()->setDisplayProperties(i->index(), changeProperties);
322  }
323 }
324 
328 void
330 {
331  if (m_models.empty())
332  return;
333 
334  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
335  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i)
336  {
337  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
338  FWDisplayProperties changeProperties = info.displayProperties();
339  changeProperties.setTransparency(100 - opacity);
340  i->item()->setDisplayProperties(i->index(), changeProperties);
341  }
342 }
343 
347 void
349  if(m_models.empty())
350  return;
351 
352  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
353  for (std::set<FWModelId>::iterator i = m_models.begin(); i != m_models.end(); ++i)
354  {
355  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
356  FWDisplayProperties changeProperties = info.displayProperties();
357  changeProperties.setIsVisible(on);
358  i->item()->setDisplayProperties(i->index(), changeProperties);
359  }
360 }
361 
362 void
364 {
365  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
366 
367  m_detailViewManager->openDetailViewFor( *(m_models.begin()), viewChoices.front() );
368 }
369 
370 void
372 {
373  TGTextButton *cs = static_cast<TGTextButton *>(gTQSender);
374  int iIndex = cs->WidgetId();
375  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
376 
377  m_detailViewManager->openDetailViewFor( *(m_models.begin()), *(viewChoices.begin()+iIndex) );
378 
379 }
380 //
381 // const member functions
382 //
383 
384 //
385 // static member functions
386 //
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)
static const TGPicture * info(bool iBackgroundIsBlack)
const FWDisplayProperties & displayProperties() const
Definition: FWEventItem.h:67
sigc::connection m_destroyedConn
auto_ptr< ClusterSequence > cs
const double w
Definition: UKUtility.cc:23
void changeModelColor(Color_t iColor)
void SetColorByIndex(Color_t iColor)
std::string modelName(int iIndex) const
Definition: FWEventItem.cc:574
const std::string & name() const
Definition: FWEventItem.cc:500
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:214
sigc::connection m_changes
sigc::connection m_modelChangedConn
Color_t color() const
TGCheckButton * m_isVisibleButton
Char_t transparency() const
std::set< FWModelId > m_models
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
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)
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:195
FWDetailViewManager * m_detailViewManager
void fillModelPopup(const FWSelectionManager &iSelMgr)
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:535
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)