test
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  if ( viewChoices[i][0] == '!') {
222  m_openDetailedViewButtons[i]->SetEnabled(false);
223  m_openDetailedViewButtons[i]->SetText(("Open " + viewChoices[i].substr(1) + " Detail View ...").c_str());
224 
225  }
226  else {
227  m_openDetailedViewButtons[i]->SetText(("Open " + viewChoices[i] + " Detail View ...").c_str());
228  m_openDetailedViewButtons[i]->SetEnabled(true);
229  }
230  }
231  }
232 
233  // Set the various widgets.
234  m_colorSelectWidget->SetColorByIndex(props.color(), kFALSE);
235  m_opacitySlider->SetPosition(100 - props.transparency());
236  m_isVisibleButton->SetDisabledAndSelected(props.isVisible());
237 
238  m_opacitySlider->SetEnabled(kTRUE);
239  m_colorSelectWidget->SetEnabled(kTRUE);
240  m_isVisibleButton->SetEnabled(kTRUE);
241 
242  m_modelChangedConn = item->changed_.connect(boost::bind(&CmsShowModelPopup::updateDisplay, this));
243  m_destroyedConn = item->goingToBeDestroyed_.connect(boost::bind(&CmsShowModelPopup::disconnectAll, this));
244 
245  Resize(GetDefaultSize());
246  Layout();
247 }
248 
251 void
253 {
254  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end();
255  i != e; ++i)
256  {
257  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
258  const FWDisplayProperties &p = info.displayProperties();
260 
261  if (p.isVisible())
262  m_isVisibleButton->SetState(kButtonDown, kFALSE);
263  else
264  m_isVisibleButton->SetState(kButtonUp, kFALSE);
265 
266  m_opacitySlider->SetPosition(100 - p.transparency());
267  }
268 }
269 
270 /* Called by FWGUIManager when change background/colorset. */
271 void
273 {
274  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end();
275  i != e; ++i)
276  {
277  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
278  const FWDisplayProperties &p = info.displayProperties();
280  }
281 }
282 
286 void
288  m_modelChangedConn.disconnect();
289  m_destroyedConn.disconnect();
290  // m_item = 0;
291  // m_model = 0;
292  m_modelLabel->SetText("No object selected");
293  m_colorSelectWidget->SetColorByIndex(kRed,kFALSE);
294  m_isVisibleButton->SetDisabledAndSelected(kTRUE);
295  m_colorSelectWidget->SetEnabled(kFALSE);
296  m_opacitySlider->SetEnabled(kFALSE);
297  m_isVisibleButton->SetEnabled(kFALSE);
298  m_openDetailedViewButtons.front()->SetEnabled(kFALSE);
299  m_openDetailedViewButtons.front()->SetText("Open Detail View ...");
301  for(size_t i = 1, e = m_openDetailedViewButtons.size(); i != e; ++i)
302  {
303  TGCompositeFrame* cf = (TGCompositeFrame*)m_openDetailedViewButtons[i]->GetParent();
304  cf->HideFrame(m_openDetailedViewButtons[i]);
305  }
306 
307 
308 }
309 
317 void
319 {
320  if (m_models.empty())
321  return;
322 
323  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
324  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i)
325  {
326  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
327  FWDisplayProperties changeProperties = info.displayProperties();
328  changeProperties.setColor(color);
329  i->item()->setDisplayProperties(i->index(), changeProperties);
330  }
331 }
332 
336 void
338 {
339  if (m_models.empty())
340  return;
341 
342  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
343  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i)
344  {
345  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
346  FWDisplayProperties changeProperties = info.displayProperties();
347  changeProperties.setTransparency(100 - opacity);
348  i->item()->setDisplayProperties(i->index(), changeProperties);
349  }
350 }
351 
355 void
357  if(m_models.empty())
358  return;
359 
360  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
361  for (std::set<FWModelId>::iterator i = m_models.begin(); i != m_models.end(); ++i)
362  {
363  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
364  FWDisplayProperties changeProperties = info.displayProperties();
365  changeProperties.setIsVisible(on);
366  i->item()->setDisplayProperties(i->index(), changeProperties);
367  }
368 }
369 
370 void
372 {
373  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
374 
375  m_detailViewManager->openDetailViewFor( *(m_models.begin()), viewChoices.front() );
376 }
377 
378 void
380 {
381  TGTextButton *cs = static_cast<TGTextButton *>(gTQSender);
382  int iIndex = cs->WidgetId();
383  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
384 
385  m_detailViewManager->openDetailViewFor( *(m_models.begin()), *(viewChoices.begin()+iIndex) );
386 
387 }
388 //
389 // const member functions
390 //
391 
392 //
393 // static member functions
394 //
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)
assert(m_qm.get())
FWItemChangeSignal goingToBeDestroyed_
Definition: FWEventItem.h:217
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:198
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)