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  button = new TGTextButton(this, "dummy", index);
198  AddFrame(button, new TGLayoutHints(kLHintsExpandX, 4, 4, 4, 4));
199  TGCompositeFrame* cf = (TGCompositeFrame*)button->GetParent();
200  cf->MapWindow();
201  cf->MapSubwindows();
202  m_openDetailedViewButtons.push_back(button);
203 
204  button->Connect("Clicked()", "CmsShowModelPopup", this, "clicked()");
205  }
206  }
207  else if (!viewChoices.empty())
208  {
209  // printf("show button subset %d \n", viewChoices.size());
210  for (size_t i = 0, e = viewChoices.size(); i != e; ++i)
211  {
212  TGCompositeFrame* cf = (TGCompositeFrame*)m_openDetailedViewButtons[i]->GetParent();
213  cf->ShowFrame(m_openDetailedViewButtons[i]);
214  }
215  }
216 
217  //set the names
218  for (size_t i = 0, e = viewChoices.size(); i != e; ++i)
219  {
220  if ( viewChoices[i][0] == '!') {
221  m_openDetailedViewButtons[i]->SetEnabled(false);
222  m_openDetailedViewButtons[i]->SetText(("Open " + viewChoices[i].substr(1) + " Detail View ...").c_str());
223 
224  }
225  else {
226  m_openDetailedViewButtons[i]->SetText(("Open " + viewChoices[i] + " Detail View ...").c_str());
227  m_openDetailedViewButtons[i]->SetEnabled(true);
228  }
229  }
230  }
231 
232  // Set the various widgets.
233  m_colorSelectWidget->SetColorByIndex(props.color(), kFALSE);
234  m_opacitySlider->SetPosition(100 - props.transparency());
235  m_isVisibleButton->SetDisabledAndSelected(props.isVisible());
236 
237  m_opacitySlider->SetEnabled(kTRUE);
238  m_colorSelectWidget->SetEnabled(kTRUE);
239  m_isVisibleButton->SetEnabled(kTRUE);
240 
241  m_modelChangedConn = item->changed_.connect(boost::bind(&CmsShowModelPopup::updateDisplay, this));
242  m_destroyedConn = item->goingToBeDestroyed_.connect(boost::bind(&CmsShowModelPopup::disconnectAll, this));
243 
244  Resize(GetDefaultSize());
245  Layout();
246 }
247 
250 void
252 {
253  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end();
254  i != e; ++i)
255  {
256  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
257  const FWDisplayProperties &p = info.displayProperties();
259 
260  if (p.isVisible())
261  m_isVisibleButton->SetState(kButtonDown, kFALSE);
262  else
263  m_isVisibleButton->SetState(kButtonUp, kFALSE);
264 
265  m_opacitySlider->SetPosition(100 - p.transparency());
266  }
267 }
268 
269 /* Called by FWGUIManager when change background/colorset. */
270 void
272 {
273  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end();
274  i != e; ++i)
275  {
276  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
277  const FWDisplayProperties &p = info.displayProperties();
279  }
280 }
281 
285 void
287  m_modelChangedConn.disconnect();
288  m_destroyedConn.disconnect();
289  // m_item = 0;
290  // m_model = 0;
291  m_modelLabel->SetText("No object selected");
292  m_colorSelectWidget->SetColorByIndex(kRed,kFALSE);
293  m_isVisibleButton->SetDisabledAndSelected(kTRUE);
294  m_colorSelectWidget->SetEnabled(kFALSE);
295  m_opacitySlider->SetEnabled(kFALSE);
296  m_isVisibleButton->SetEnabled(kFALSE);
297  m_openDetailedViewButtons.front()->SetEnabled(kFALSE);
298  m_openDetailedViewButtons.front()->SetText("Open Detail View ...");
300  for(size_t i = 1, e = m_openDetailedViewButtons.size(); i != e; ++i)
301  {
302  TGCompositeFrame* cf = (TGCompositeFrame*)m_openDetailedViewButtons[i]->GetParent();
303  cf->HideFrame(m_openDetailedViewButtons[i]);
304  }
305 
306 
307 }
308 
316 void
318 {
319  if (m_models.empty())
320  return;
321 
322  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
323  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i)
324  {
325  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
326  FWDisplayProperties changeProperties = info.displayProperties();
327  changeProperties.setColor(color);
328  i->item()->setDisplayProperties(i->index(), changeProperties);
329  }
330 }
331 
335 void
337 {
338  if (m_models.empty())
339  return;
340 
341  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
342  for (std::set<FWModelId>::iterator i = m_models.begin(), e = m_models.end(); i != e; ++i)
343  {
344  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
345  FWDisplayProperties changeProperties = info.displayProperties();
346  changeProperties.setTransparency(100 - opacity);
347  i->item()->setDisplayProperties(i->index(), changeProperties);
348  }
349 }
350 
354 void
356  if(m_models.empty())
357  return;
358 
359  FWChangeSentry sentry(*(m_models.begin()->item()->changeManager()));
360  for (std::set<FWModelId>::iterator i = m_models.begin(); i != m_models.end(); ++i)
361  {
362  const FWEventItem::ModelInfo &info = i->item()->modelInfo(i->index());
363  FWDisplayProperties changeProperties = info.displayProperties();
364  changeProperties.setIsVisible(on);
365  i->item()->setDisplayProperties(i->index(), changeProperties);
366  }
367 }
368 
369 void
371 {
372  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
373 
374  m_detailViewManager->openDetailViewFor( *(m_models.begin()), viewChoices.front() );
375 }
376 
377 void
379 {
380  TGTextButton *cs = static_cast<TGTextButton *>(gTQSender);
381  int iIndex = cs->WidgetId();
382  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_models.begin()));
383 
384  m_detailViewManager->openDetailViewFor( *(m_models.begin()), *(viewChoices.begin()+iIndex) );
385 
386 }
387 //
388 // const member functions
389 //
390 
391 //
392 // static member functions
393 //
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:68
sigc::connection m_destroyedConn
auto_ptr< ClusterSequence > cs
const double w
Definition: UKUtility.cc:23
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void changeModelColor(Color_t iColor)
void SetColorByIndex(Color_t iColor)
std::string modelName(int iIndex) const
Definition: FWEventItem.cc:576
const std::string & name() const
Definition: FWEventItem.cc:502
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:219
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)
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:200
FWDetailViewManager * m_detailViewManager
void fillModelPopup(const FWSelectionManager &iSelMgr)
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:537
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)