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 //
12 
13 // system include files
14 #include <boost/bind.hpp>
15 
16 // user include files
27 
32 
33 #include "KeySymbols.h"
34 #include "TGButton.h"
35 #include "TGComboBox.h"
36 #include "TGLabel.h"
37 #include "TGListBox.h"
38 #include "TGLViewer.h"
39 #include "TGeoMatrix.h"
40 #include "TGeoBBox.h"
41 
42 #include "TEveViewer.h"
43 #include "TEveScene.h"
44 #include "TEveSceneInfo.h"
45 #include "TEveManager.h"
46 #include "TGeoManager.h"
47 #include "TGLCamera.h"
48 
49 
50 //==============================================================================
51 //==============================================================================
52 //==============================================================================
53 //==============================================================================
54 
55 
57 {
58 public:
59 
61  mutable std::vector<const char*> m_list;
64 
65  virtual void addDaughtersRec(TGeoVolume* v) const
66  {
67  switch (m_browser->getFilterType())
68  {
70  m_list.push_back(v->GetMaterial()->GetName());
71  break;
73  m_list.push_back(v->GetMaterial()->GetTitle());
74  break;
76  m_list.push_back(v->GetShape()->GetName());
77  break;
79  m_list.push_back(v->GetShape()->ClassName());
80  break;
81  default:
82  std::cerr << "FWGeoMaterialValidator unhandeled case. \n";
83  }
84 
85  for (int i = 0; i < v->GetNdaughters(); ++i)
86  addDaughtersRec(v->GetNode(i)->GetVolume());
87 
88  }
89 
90  virtual void fillOptions(const char* iBegin, const char* iEnd, std::vector<std::pair<boost::shared_ptr<std::string>, std::string> >& oOptions) const override
91  {
92  oOptions.clear();
93  m_list.clear();
94 
96  std::advance(tnit, m_browser->getTopNodeIdx());
98  addDaughtersRec(tnit->m_node->GetVolume());
99 
100  std::sort(m_list.begin(), m_list.end());
101  std::vector<const char*>::iterator ui = std::unique(m_list.begin(), m_list.end());
102  m_list.resize(ui - m_list.begin());
103 
104  std::string part(iBegin,iEnd);
105  unsigned int part_size = part.size();
106  std::string h = "";
107  // int cnt = 0;
108  oOptions.push_back(std::make_pair(boost::shared_ptr<std::string>(new std::string(*m_list.begin())), h));
109  std::vector<const char*>::iterator startIt = m_list.begin(); startIt++;
110  for (std::vector<const char*>::iterator i = startIt; i!=m_list.end(); ++i)
111  {
112  // std::cout << *i << " " << cnt++ << std::endl;
113  if ((strlen(*i) >= part_size) && strncmp(*i, part.c_str(), part_size ) == 0)
114  {
115  oOptions.push_back(std::make_pair(boost::shared_ptr<std::string>(new std::string((*i))),&((*i)[part_size]) ));
116  }
117  }
118  }
119 
121  {
122  std::cerr << "validation not used \n";
123  return false;
124  }
125 };
126 
127 
128 //==============================================================================
129 //==============================================================================
130 //==============================================================================
131 //==============================================================================
133  : FWGeometryTableViewBase(iParent, FWViewType::kGeometryTable, colMng),
134  m_tableManager(0),
135  m_filterEntry(0),
136  m_filterValidator(0),
137  m_mode(this, "Mode", 0l, 0l, 1l),
138  m_disableTopNode(this,"HideTopNode", true),
139  m_visLevel(this,"VisLevel", 3l, 1l, 100l),
140  m_filter(this,"Materials", std::string()),
141  m_filterType(this,"FilterType:", 0l, 0l, 3l),
142  m_visLevelFilter(this,"IgnoreVisLevelOnFilter", true),
143  m_selectRegion(this, "SelectNearCameraCenter", false),
144  m_regionRadius(this, "SphereRadius", 10.0, 1.0, 300.0),
145  m_proximityAlgo(this, "Proximity algorithm", 1l, 0l, 1l)
146 {
148 #if ROOT_VERSION_CODE < ROOT_VERSION(5,32,0)
149  m_eveScene = new FWGeoTopNodeEveScene(gls, "TopGeoNodeScene", "");
150 #else
151  m_eveScene = new TEveScene(gls, "TopGeoNodeScene", "");
152 #endif
153  gEve->GetScenes()->AddElement(m_eveScene);
154 
155  m_eveTopNode = new FWEveDetectorGeo(this);
156  m_eveTopNode->IncDenyDestroy();
157  m_eveTopNode->SetPickable(true);
158  m_eveScene->AddElement(m_eveTopNode);
159 
160  gls->m_eveTopNode = m_eveTopNode;
161  m_eveTopNode->m_scene = gls;
162 
163  // top row
164  TGHorizontalFrame *hp = new TGHorizontalFrame(m_frame);
165  {
166  TGTextButton *rb = new TGTextButton (hp, "CdTop");
167  hp->AddFrame(rb, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0) );
168  rb->Connect("Clicked()","FWGeometryTableViewBase",this,"cdTop()");
169  }
170  {
171  TGTextButton *rb = new TGTextButton (hp, "CdUp");
172  hp->AddFrame(rb, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
173  rb->Connect("Clicked()","FWGeometryTableViewBase",this,"cdUp()");
174  }
175  {
176  m_viewBox = new FWViewCombo(hp, this);
177  hp->AddFrame( m_viewBox,new TGLayoutHints(kLHintsExpandY, 2, 2, 0, 0));
178  }
179  {
180 
181  m_filterType.addEntry(kFilterMaterialName, "MaterialName");
182  m_filterType.addEntry(kFilterMaterialTitle, "MaterialTitle");
183  m_filterType.addEntry(kFilterShapeName, "ShapeName");
184  m_filterType.addEntry(kFilterShapeClassName, "ShapeClassName");
185 
186  boost::shared_ptr<FWParameterSetterBase> ptr( FWParameterSetterBase::makeSetterFor((FWParameterBase*)&m_filterType) );
187  ptr->attach((FWParameterBase*)&m_filterType, this);
188 
189  TGFrame* pframe = ptr->build(hp, false);
190  hp->AddFrame(pframe, new TGLayoutHints(kLHintsLeft));
191  m_filterTypeSetter.swap(ptr);
192  }
193  {
194  hp->AddFrame(new TGLabel(hp, "FilterExp:"), new TGLayoutHints(kLHintsBottom, 0, 0, 0, 2));
196  m_filterEntry->SetHeight(20);
199  hp->AddFrame(m_filterEntry, new TGLayoutHints(kLHintsExpandX, 0, 2, 1, 0));
201  m_filterEntry->getListBox()->Connect("Selected(int)", "FWGeometryTableView", this, "filterListCallback()");
202  m_filterEntry->Connect("ReturnPressed()", "FWGeometryTableView", this, "filterTextEntryCallback()");
203 
204  gVirtualX->GrabKey( m_filterEntry->GetId(),gVirtualX->KeysymToKeycode((int)kKey_A), kKeyControlMask, true);
205  }
206  m_frame->AddFrame(hp,new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 2, 2, 2, 0));
207 
209  {
210  TEveGeoManagerHolder gmgr( FWGeometryTableViewManager::getGeoMangeur());
211  m_tableManager->loadGeometry( gGeoManager->GetTopNode(), gGeoManager->GetListOfVolumes());
212  }
213  cdTop();
214 
215  m_mode.addEntry(kNode, "Node");
216  m_mode.addEntry(kVolume, "Volume");
217 
218  m_mode.changed_.connect(boost::bind(&FWGeometryTableView::refreshTable3D,this));
220  m_visLevel.changed_.connect(boost::bind(&FWGeometryTableView::refreshTable3D,this));
221 
222 
224 
226  postConst();
227 
228  m_proximityAlgo.addEntry(kBBoxCenter, "BBox center");
229  m_proximityAlgo.addEntry(kBBoxSurface, "BBox surface");
230 
234 
235 }
236 
238 {}
239 
240 //______________________________________________________________________________
242 {
244 
245  m_topNodeIdx.set(parentIdx);
247  getTableManager()->setLevelOffset(getTableManager()->refEntries().at(getTopNodeIdx()).m_level);
248 
250  refreshTable3D();
251 }
252 
253 //______________________________________________________________________________
255 {
256  return m_tableManager;
257 }
258 
259 //______________________________________________________________________________
261 {
262  if (!m_enableRedraw) return;
264  getTableManager()->redrawTable(true);
265 }
266 
267 //______________________________________________________________________________
269 {
270  // std::cout << "text entry click ed \n" ;
271  std::string exp = m_filterEntry->GetText();
272  updateFilter(exp);
273 }
274 
275 //______________________________________________________________________________
277 {
278  // std::cout << "list click ed [" << m_filterEntry->GetText() << "] \n" ;
279 
280  std::string exp = m_filterEntry->GetText();
281  updateFilter(exp);
282 }
283 
284 //______________________________________________________________________________
286 {
287  // std::cout << "=FWGeometryTableViewBase::updateFilter()" << m_filterEntry->GetText() <<std::endl;
288 
289 
290  if (exp.empty())
291  {
292  // std::cout << "FITLER OFF \n";
294  {
295  m_tableManager->setVisibility(*i, true);
297  }
298 
299  // NOTE: entry should be cleared automatically
300  m_filterEntry->Clear();
301  }
302 
303  m_filter.set(exp);
305  refreshTable3D();
306 
307 }
308 
309 //==============================================================================
310 
312 {
313  gui.requestTab("Style").
314  addParam(&m_mode).
315  addParam(&m_autoExpand).
316  separator().
317  addParam(&m_disableTopNode).
318  addParam(&m_minParentTransparency).
319  addParam(&m_minLeafTransparency).
320  addParam(&m_visLevel).
321  addParam(&m_visLevelFilter).
322  separator().
323  addParam(&m_selectRegion).
324  addParam(&m_regionRadius).
325  addParam(&m_proximityAlgo).separator();
326 
327  TGTextButton* butt = new TGTextButton(gui.getTabContainer(), "ReloadColors");
328  gui.getTabContainer()->AddFrame(butt);
329  butt->Connect("Clicked()", "FWGeometryTableViewBase", (FWGeometryTableViewBase*)this, "reloadColors()");
330 }
331 
332 
333 //------------------------------------------------------------------------------
334 
335 /*
336 void FWGeometryTableView::setPath(int parentIdx, std::string& path)
337 {
338  // printf("Set Path to [%s], current node \n", path.c_str());
339  m_topNodeIdx.set(parentIdx);
340  getTableManager()->refEntries().at(getTopNodeIdx()).setBitVal(FWGeometryTableManagerBase::kVisNodeSelf,!m_disableTopNode.value() );
341  getTableManager()->setLevelOffset(getTableManager()->refEntries().at(getTopNodeIdx()).m_level);
342 
343  m_eveTopNode->clearSelection();
344 
345  checkExpandLevel();
346  refreshTable3D();
347  FWGUIManager::getGUIManager()->updateStatus(path.c_str());
348  }*/
349 
350 //--------------------------------------------------------------
351 bool viewIsChecked(TEveViewer* v, TEveElement* el)
352 {
353  if (strstr( v->GetElementName(), "3D") )
354  {
355  for (TEveElement::List_i eit = v->BeginChildren(); eit != v->EndChildren(); ++eit )
356  {
357  TEveScene* s = ((TEveSceneInfo*)*eit)->GetScene();
358  if (el && s->HasChildren() && s->FirstChild() == el)
359  return true;
360  }
361 
362  }
363  return false;
364 }
365 
367 {
368  if (m_selectRegion.value())
369  {
370  double* center = 0;
371  for (TEveElement::List_i it = gEve->GetViewers()->BeginChildren(); it != gEve->GetViewers()->EndChildren(); ++it)
372  {
373  TEveViewer* v = ((TEveViewer*)(*it));
374  if (viewIsChecked(v, m_eveTopNode))
375  {
376  if (center) {
377  fwLog(fwlog::kWarning) << "Center picked from first view \n";
378  } else {
379  center = v->GetGLViewer()->CurrentCamera().GetCenterVec();
380  fwLog(fwlog::kInfo) << Form("Center picked (%.1f, %.1f, %.1f) from first selected 3D view \n",
381  center[0], center[1], center[2]);
382  }
383  }
384  }
385 
386  if (! center)
387  {
388  fwLog(fwlog::kError) << "No 3D view selected \n";
389  return;
390  }
391 
393  }
394  else
395  {
397  }
398 
399  refreshTable3D();
400 }
401 
402 //------------------------------------------------------------------------------
403 
405 {
406  m_enableRedraw = false;
407  for (const_iterator it =begin(), itEnd = end(); it != itEnd; ++it)
408  {
409  // printf("set from %s \n",(*it)->name().c_str() );
410  if ((*it)->name() == m_topNodeIdx.name() )
412  else
413  (*it)->setFrom(iFrom);
414  }
415 
416 
418 
419  TGComboBox* cbox = ((FWEnumParameterSetter*) m_filterTypeSetter.get())->getWidget();
420  cbox->Select(m_filterType.value(), false);
421  m_viewersConfig = iFrom.valueForKey("Viewers");
422 
423 
424  m_enableRedraw = true;
425  m_filterEntry->SetText(m_filter.value().c_str(), false);
428  refreshTable3D();
429  /*
430  getTableManager()->redrawTable();
431  m_eveTopNode->ElementChanged();
432  gEve->FullRedraw3D(false, true);
433  */
434 }
435 
436 //------------------------------------------------------------------------------
437 
439 {
441  refreshTable3D();
442 }
virtual void setVisibility(NodeInfo &nodeInfo, bool)
FWGeometryTableView * m_browser
int i
Definition: DBlmapReader.cc:9
std::vector< const char * > m_list
virtual void fillOptions(const char *iBegin, const char *iEnd, std::vector< std::pair< boost::shared_ptr< std::string >, std::string > > &oOptions) const override
std::vector< FWParameterBase * >::const_iterator const_iterator
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
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:78
FWGeoTopNodeGLScene * m_scene
Definition: FWGeoTopNode.h:68
FWLongParameter m_visLevel
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
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)
#define fwLog(_level_)
Definition: fwLog.h:50
bool viewIsChecked(TEveViewer *v, TEveElement *el)
part
Definition: HCALResponse.h:20
void loadGeometry(TGeoNode *iGeoTopNode, TObjArray *iVolumes)
TGCompositeFrame * getTabContainer()
FWBoolParameter m_visLevelFilter
FWEnumParameter m_proximityAlgo
const FWConfiguration * valueForKey(const std::string &iKey) const
volatile std::atomic< bool > shutdown_flag false
FWGUIValidatingTextEntry * m_filterEntry
void redrawTable(bool setExpand=false)
virtual void setPath(int, std::string &)
const std::string & name() const
virtual FWGeometryTableManagerBase * getTableManager()