CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWGeometryTableView.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWGeometryTableView
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author:
10 // Created: Wed Jan 4 00:05:34 CET 2012
11 // $Id: FWGeometryTableView.cc,v 1.40 2012/05/10 21:31:18 amraktad Exp $
12 //
13 
14 // system include files
15 #include <boost/bind.hpp>
16 
17 // user include files
28 
33 
34 #include "KeySymbols.h"
35 #include "TGButton.h"
36 #include "TGComboBox.h"
37 #include "TGLabel.h"
38 #include "TGListBox.h"
39 #include "TGLViewer.h"
40 #include "TGeoMatrix.h"
41 #include "TGeoBBox.h"
42 
43 #include "TEveViewer.h"
44 #include "TEveScene.h"
45 #include "TEveSceneInfo.h"
46 #include "TEveManager.h"
47 #include "TGeoManager.h"
48 #include "TGLCamera.h"
49 
50 
51 //==============================================================================
52 //==============================================================================
53 //==============================================================================
54 //==============================================================================
55 
56 
58 {
59 public:
60 
62  mutable std::vector<const char*> m_list;
65 
66  virtual void addDaughtersRec(TGeoVolume* v) const
67  {
68  switch (m_browser->getFilterType())
69  {
71  m_list.push_back(v->GetMaterial()->GetName());
72  break;
74  m_list.push_back(v->GetMaterial()->GetTitle());
75  break;
77  m_list.push_back(v->GetShape()->GetName());
78  break;
80  m_list.push_back(v->GetShape()->ClassName());
81  break;
82  default:
83  std::cerr << "FWGeoMaterialValidator unhandeled case. \n";
84  }
85 
86  for (int i = 0; i < v->GetNdaughters(); ++i)
87  addDaughtersRec(v->GetNode(i)->GetVolume());
88 
89  }
90 
91  virtual void fillOptions(const char* iBegin, const char* iEnd, std::vector<std::pair<boost::shared_ptr<std::string>, std::string> >& oOptions) const
92  {
93  oOptions.clear();
94  m_list.clear();
95 
97  std::advance(tnit, m_browser->getTopNodeIdx());
99  addDaughtersRec(tnit->m_node->GetVolume());
100 
101  std::sort(m_list.begin(), m_list.end());
102  std::vector<const char*>::iterator ui = std::unique(m_list.begin(), m_list.end());
103  m_list.resize(ui - m_list.begin());
104 
105  std::string part(iBegin,iEnd);
106  unsigned int part_size = part.size();
107  std::string h = "";
108  // int cnt = 0;
109  oOptions.push_back(std::make_pair(boost::shared_ptr<std::string>(new std::string(*m_list.begin())), h));
110  std::vector<const char*>::iterator startIt = m_list.begin(); startIt++;
111  for (std::vector<const char*>::iterator i = startIt; i!=m_list.end(); ++i)
112  {
113  // std::cout << *i << " " << cnt++ << std::endl;
114  if ((strlen(*i) >= part_size) && strncmp(*i, part.c_str(), part_size ) == 0)
115  {
116  oOptions.push_back(std::make_pair(boost::shared_ptr<std::string>(new std::string((*i))),&((*i)[part_size]) ));
117  }
118  }
119  }
120 
121  bool isStringValid(std::string& exp)
122  {
123  std::cerr << "validation not used \n";
124  return false;
125  }
126 };
127 
128 
129 //==============================================================================
130 //==============================================================================
131 //==============================================================================
132 //==============================================================================
134  : FWGeometryTableViewBase(iParent, FWViewType::kGeometryTable, colMng),
135  m_tableManager(0),
136  m_filterEntry(0),
137  m_filterValidator(0),
138  m_mode(this, "Mode", 0l, 0l, 1l),
139  m_disableTopNode(this,"HideTopNode", true),
140  m_visLevel(this,"VisLevel", 3l, 1l, 100l),
141  m_filter(this,"Materials", std::string()),
142  m_filterType(this,"FilterType:", 0l, 0l, 3l),
143  m_visLevelFilter(this,"IgnoreVisLevelOnFilter", true),
144  m_selectRegion(this, "SelectNearCameraCenter", false),
145  m_regionRadius(this, "SphereRadius", 10.0, 1.0, 300.0),
146  m_proximityAlgo(this, "Proximity algorithm", 1l, 0l, 1l)
147 {
149 #if ROOT_VERSION_CODE < ROOT_VERSION(5,32,0)
150  m_eveScene = new FWGeoTopNodeEveScene(gls, "TopGeoNodeScene", "");
151 #else
152  m_eveScene = new TEveScene(gls, "TopGeoNodeScene", "");
153 #endif
154  gEve->GetScenes()->AddElement(m_eveScene);
155 
156  m_eveTopNode = new FWEveDetectorGeo(this);
157  m_eveTopNode->IncDenyDestroy();
158  m_eveTopNode->SetPickable(true);
159  m_eveScene->AddElement(m_eveTopNode);
160 
161  gls->m_eveTopNode = m_eveTopNode;
162  m_eveTopNode->m_scene = gls;
163 
164  // top row
165  TGHorizontalFrame *hp = new TGHorizontalFrame(m_frame);
166  {
167  TGTextButton *rb = new TGTextButton (hp, "CdTop");
168  hp->AddFrame(rb, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0) );
169  rb->Connect("Clicked()","FWGeometryTableViewBase",this,"cdTop()");
170  }
171  {
172  TGTextButton *rb = new TGTextButton (hp, "CdUp");
173  hp->AddFrame(rb, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
174  rb->Connect("Clicked()","FWGeometryTableViewBase",this,"cdUp()");
175  }
176  {
177  m_viewBox = new FWViewCombo(hp, this);
178  hp->AddFrame( m_viewBox,new TGLayoutHints(kLHintsExpandY, 2, 2, 0, 0));
179  }
180  {
181 
182  m_filterType.addEntry(kFilterMaterialName, "MaterialName");
183  m_filterType.addEntry(kFilterMaterialTitle, "MaterialTitle");
184  m_filterType.addEntry(kFilterShapeName, "ShapeName");
185  m_filterType.addEntry(kFilterShapeClassName, "ShapeClassName");
186 
187  boost::shared_ptr<FWParameterSetterBase> ptr( FWParameterSetterBase::makeSetterFor((FWParameterBase*)&m_filterType) );
188  ptr->attach((FWParameterBase*)&m_filterType, this);
189 
190  TGFrame* pframe = ptr->build(hp, false);
191  hp->AddFrame(pframe, new TGLayoutHints(kLHintsLeft));
192  m_filterTypeSetter.swap(ptr);
193  }
194  {
195  hp->AddFrame(new TGLabel(hp, "FilterExp:"), new TGLayoutHints(kLHintsBottom, 0, 0, 0, 2));
197  m_filterEntry->SetHeight(20);
200  hp->AddFrame(m_filterEntry, new TGLayoutHints(kLHintsExpandX, 0, 2, 1, 0));
202  m_filterEntry->getListBox()->Connect("Selected(int)", "FWGeometryTableView", this, "filterListCallback()");
203  m_filterEntry->Connect("ReturnPressed()", "FWGeometryTableView", this, "filterTextEntryCallback()");
204 
205  gVirtualX->GrabKey( m_filterEntry->GetId(),gVirtualX->KeysymToKeycode((int)kKey_A), kKeyControlMask, true);
206  }
207  m_frame->AddFrame(hp,new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 2, 2, 2, 0));
208 
210  {
211  TEveGeoManagerHolder gmgr( FWGeometryTableViewManager::getGeoMangeur());
212  m_tableManager->loadGeometry( gGeoManager->GetTopNode(), gGeoManager->GetListOfVolumes());
213  }
214  cdTop();
215 
216  m_mode.addEntry(kNode, "Node");
217  m_mode.addEntry(kVolume, "Volume");
218 
219  m_mode.changed_.connect(boost::bind(&FWGeometryTableView::refreshTable3D,this));
221  m_visLevel.changed_.connect(boost::bind(&FWGeometryTableView::refreshTable3D,this));
222 
223 
225 
227  postConst();
228 
229  m_proximityAlgo.addEntry(kBBoxCenter, "BBox center");
230  m_proximityAlgo.addEntry(kBBoxSurface, "BBox surface");
231 
235 
236 }
237 
239 {}
240 
241 //______________________________________________________________________________
242 void FWGeometryTableView::setPath(int parentIdx, std::string&)
243 {
245 
246  m_topNodeIdx.set(parentIdx);
248  getTableManager()->setLevelOffset(getTableManager()->refEntries().at(getTopNodeIdx()).m_level);
249 
251  refreshTable3D();
252 }
253 
254 //______________________________________________________________________________
256 {
257  return m_tableManager;
258 }
259 
260 //______________________________________________________________________________
262 {
263  if (!m_enableRedraw) return;
265  getTableManager()->redrawTable(true);
266 }
267 
268 //______________________________________________________________________________
270 {
271  // std::cout << "text entry click ed \n" ;
272  std::string exp = m_filterEntry->GetText();
273  updateFilter(exp);
274 }
275 
276 //______________________________________________________________________________
278 {
279  // std::cout << "list click ed [" << m_filterEntry->GetText() << "] \n" ;
280 
281  std::string exp = m_filterEntry->GetText();
282  updateFilter(exp);
283 }
284 
285 //______________________________________________________________________________
287 {
288  // std::cout << "=FWGeometryTableViewBase::updateFilter()" << m_filterEntry->GetText() <<std::endl;
289 
290 
291  if (exp.empty())
292  {
293  // std::cout << "FITLER OFF \n";
295  {
296  m_tableManager->setVisibility(*i, true);
298  }
299 
300  // NOTE: entry should be cleared automatically
301  m_filterEntry->Clear();
302  }
303 
304  m_filter.set(exp);
306  refreshTable3D();
307 
308 }
309 
310 //==============================================================================
311 
313 {
314  gui.requestTab("Style").
315  addParam(&m_mode).
316  addParam(&m_autoExpand).
317  separator().
318  addParam(&m_disableTopNode).
319  addParam(&m_minParentTransparency).
320  addParam(&m_minLeafTransparency).
321  addParam(&m_visLevel).
322  addParam(&m_visLevelFilter).
323  separator().
324  addParam(&m_selectRegion).
325  addParam(&m_regionRadius).
326  addParam(&m_proximityAlgo).separator();
327 
328  TGTextButton* butt = new TGTextButton(gui.getTabContainer(), "ReloadColors");
329  gui.getTabContainer()->AddFrame(butt);
330  butt->Connect("Clicked()", "FWGeometryTableViewBase", (FWGeometryTableViewBase*)this, "reloadColors()");
331 }
332 
333 
334 //------------------------------------------------------------------------------
335 
336 /*
337 void FWGeometryTableView::setPath(int parentIdx, std::string& path)
338 {
339  // printf("Set Path to [%s], current node \n", path.c_str());
340  m_topNodeIdx.set(parentIdx);
341  getTableManager()->refEntries().at(getTopNodeIdx()).setBitVal(FWGeometryTableManagerBase::kVisNodeSelf,!m_disableTopNode.value() );
342  getTableManager()->setLevelOffset(getTableManager()->refEntries().at(getTopNodeIdx()).m_level);
343 
344  m_eveTopNode->clearSelection();
345 
346  checkExpandLevel();
347  refreshTable3D();
348  FWGUIManager::getGUIManager()->updateStatus(path.c_str());
349  }*/
350 
351 //--------------------------------------------------------------
352 bool viewIsChecked(TEveViewer* v, TEveElement* el)
353 {
354  if (strstr( v->GetElementName(), "3D") )
355  {
356  for (TEveElement::List_i eit = v->BeginChildren(); eit != v->EndChildren(); ++eit )
357  {
358  TEveScene* s = ((TEveSceneInfo*)*eit)->GetScene();
359  if (el && s->HasChildren() && s->FirstChild() == el)
360  return true;
361  }
362 
363  }
364  return false;
365 }
366 
368 {
369  if (m_selectRegion.value())
370  {
371  double* center = 0;
372  for (TEveElement::List_i it = gEve->GetViewers()->BeginChildren(); it != gEve->GetViewers()->EndChildren(); ++it)
373  {
374  TEveViewer* v = ((TEveViewer*)(*it));
375  if (viewIsChecked(v, m_eveTopNode))
376  {
377  if (center) {
378  fwLog(fwlog::kWarning) << "Center picked from first view \n";
379  } else {
380  center = v->GetGLViewer()->CurrentCamera().GetCenterVec();
381  fwLog(fwlog::kInfo) << Form("Center picked (%.1f, %.1f, %.1f) from first selected 3D view \n",
382  center[0], center[1], center[2]);
383  }
384  }
385  }
386 
387  if (! center)
388  {
389  fwLog(fwlog::kError) << "No 3D view selected \n";
390  return;
391  }
392 
394  }
395  else
396  {
398  }
399 
400  refreshTable3D();
401 }
402 
403 //------------------------------------------------------------------------------
404 
406 {
407  m_enableRedraw = false;
408  for (const_iterator it =begin(), itEnd = end(); it != itEnd; ++it)
409  {
410  // printf("set from %s \n",(*it)->name().c_str() );
411  if ((*it)->name() == m_topNodeIdx.name() )
413  else
414  (*it)->setFrom(iFrom);
415  }
416 
417 
419 
420  TGComboBox* cbox = ((FWEnumParameterSetter*) m_filterTypeSetter.get())->getWidget();
421  cbox->Select(m_filterType.value(), false);
422  m_viewersConfig = iFrom.valueForKey("Viewers");
423 
424 
425  m_enableRedraw = true;
426  m_filterEntry->SetText(m_filter.value().c_str(), false);
429  refreshTable3D();
430  /*
431  getTableManager()->redrawTable();
432  m_eveTopNode->ElementChanged();
433  gEve->FullRedraw3D(false, true);
434  */
435 }
436 
437 //------------------------------------------------------------------------------
438 
440 {
442  refreshTable3D();
443 }
virtual void setVisibility(NodeInfo &nodeInfo, bool)
FWGeometryTableView * m_browser
int i
Definition: DBlmapReader.cc:9
std::vector< const char * > m_list
std::vector< FWParameterBase * >::const_iterator const_iterator
FWGeoTopNode * m_eveTopNode
const_iterator begin() const
virtual void setFrom(const FWConfiguration &)
void updateFilter(std::string &)
FWGeoMaterialValidator * m_filterValidator
FWDoubleParameter m_regionRadius
void setTopNodePathFromConfig(const FWConfiguration &iFrom)
virtual void setVisibilityChld(NodeInfo &nodeInfo, bool)
ViewerParameterGUI & requestTab(const char *)
FWGeometryTableView(TEveWindowSlot *iParent, FWColorManager *colMng)
const FWConfiguration * m_viewersConfig
ViewerParameterGUI & separator()
FWBoolParameter m_selectRegion
void checkRegionOfInterest(double *center, double radius, long algo)
static boost::shared_ptr< FWParameterSetterBase > makeSetterFor(FWParameterBase *)
FWBoolParameter m_disableTopNode
sigc::signal< void, T > changed_
virtual void addDaughtersRec(TGeoVolume *v) const
FWEnumParameter m_filterType
void clearSelection()
Definition: FWGeoTopNode.h:77
FWGeoTopNodeGLScene * m_scene
Definition: FWGeoTopNode.h:67
FWLongParameter m_visLevel
FWStringParameter m_filter
virtual void populateController(ViewerParameterGUI &) const
void setValidator(FWValidatorBase *)
const_iterator end() const
bool addEntry(Long_t id, const std::string &txt)
FWEnumParameter m_mode
FWGeometryTableManager * m_tableManager
boost::shared_ptr< FWParameterSetterBase > m_filterTypeSetter
FWGeoMaterialValidator(FWGeometryTableView *v)
bool isStringValid(std::string &exp)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
#define fwLog(_level_)
Definition: fwLog.h:51
bool viewIsChecked(TEveViewer *v, TEveElement *el)
part
Definition: HCALResponse.h:21
void loadGeometry(TGeoNode *iGeoTopNode, TObjArray *iVolumes)
TGCompositeFrame * getTabContainer()
FWBoolParameter m_visLevelFilter
FWEnumParameter m_proximityAlgo
const FWConfiguration * valueForKey(const std::string &iKey) const
FWGUIValidatingTextEntry * m_filterEntry
void redrawTable(bool setExpand=false)
virtual void setPath(int, std::string &)
mathSSE::Vec4< T > v
virtual void fillOptions(const char *iBegin, const char *iEnd, std::vector< std::pair< boost::shared_ptr< std::string >, std::string > > &oOptions) const
const std::string & name() const
virtual FWGeometryTableManagerBase * getTableManager()
list at
Definition: asciidump.py:428