CMS 3D CMS Logo

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 <functional>
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 #include "TVirtualX.h"
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 
55 public:
57  mutable std::vector<const char*> m_list;
60 
61  virtual void addDaughtersRec(TGeoVolume* v) const {
62  switch (m_browser->getFilterType()) {
64  m_list.push_back(v->GetMaterial()->GetName());
65  break;
67  m_list.push_back(v->GetMaterial()->GetTitle());
68  break;
70  m_list.push_back(v->GetShape()->GetName());
71  break;
73  m_list.push_back(v->GetShape()->ClassName());
74  break;
75  default:
76  std::cerr << "FWGeoMaterialValidator unhandeled case. \n";
77  }
78 
79  for (int i = 0; i < v->GetNdaughters(); ++i)
80  addDaughtersRec(v->GetNode(i)->GetVolume());
81  }
82 
83  void fillOptions(const char* iBegin,
84  const char* iEnd,
85  std::vector<std::pair<std::shared_ptr<std::string>, std::string> >& oOptions) const override {
86  oOptions.clear();
87  m_list.clear();
88 
90  std::advance(tnit, m_browser->getTopNodeIdx());
92  addDaughtersRec(tnit->m_node->GetVolume());
93 
94  std::sort(m_list.begin(), m_list.end());
95  std::vector<const char*>::iterator ui = std::unique(m_list.begin(), m_list.end());
96  m_list.resize(ui - m_list.begin());
97 
98  std::string part(iBegin, iEnd);
99  unsigned int part_size = part.size();
100  std::string h = "";
101  // int cnt = 0;
102  oOptions.push_back(std::make_pair(std::make_shared<std::string>(*m_list.begin()), h));
103  std::vector<const char*>::iterator startIt = m_list.begin();
104  startIt++;
105  for (std::vector<const char*>::iterator i = startIt; i != m_list.end(); ++i) {
106  // std::cout << *i << " " << cnt++ << std::endl;
107  if ((strlen(*i) >= part_size) && strncmp(*i, part.c_str(), part_size) == 0) {
108  oOptions.push_back(std::make_pair(std::make_shared<std::string>((*i)), &((*i)[part_size])));
109  }
110  }
111  }
112 
114  std::cerr << "validation not used \n";
115  return false;
116  }
117 };
118 
119 //==============================================================================
120 //==============================================================================
121 //==============================================================================
122 //==============================================================================
124  : FWGeometryTableViewBase(iParent, FWViewType::kGeometryTable, colMng),
125  m_tableManager(nullptr),
126  m_filterEntry(nullptr),
127  m_filterValidator(nullptr),
128  m_mode(this, "Mode", 0l, 0l, 1l),
129  m_disableTopNode(this, "HideTopNode", true),
130  m_visLevel(this, "VisLevel", 3l, 1l, 100l),
131  m_filter(this, "Materials", std::string()),
132  m_filterType(this, "FilterType:", 0l, 0l, 3l),
133  m_visLevelFilter(this, "IgnoreVisLevelOnFilter", true),
134  m_selectRegion(this, "SelectNearCameraCenter", false),
135  m_regionRadius(this, "SphereRadius", 10.0, 1.0, 300.0),
136  m_proximityAlgo(this, "Proximity algorithm", 1l, 0l, 1l) {
137  FWGeoTopNodeGLScene* gls = new FWGeoTopNodeGLScene(nullptr);
138 #if ROOT_VERSION_CODE < ROOT_VERSION(5, 32, 0)
139  m_eveScene = new FWGeoTopNodeEveScene(gls, "TopGeoNodeScene", "");
140 #else
141  m_eveScene = new TEveScene(gls, "TopGeoNodeScene", "");
142 #endif
143  gEve->GetScenes()->AddElement(m_eveScene);
144 
145  m_eveTopNode = new FWEveDetectorGeo(this);
146  m_eveTopNode->IncDenyDestroy();
147  m_eveTopNode->SetPickable(true);
148  m_eveScene->AddElement(m_eveTopNode);
149 
150  gls->m_eveTopNode = m_eveTopNode;
151  m_eveTopNode->m_scene = gls;
152 
153  // top row
154  TGHorizontalFrame* hp = new TGHorizontalFrame(m_frame);
155  {
156  TGTextButton* rb = new TGTextButton(hp, "CdTop");
157  hp->AddFrame(rb, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
158  rb->Connect("Clicked()", "FWGeometryTableViewBase", this, "cdTop()");
159  }
160  {
161  TGTextButton* rb = new TGTextButton(hp, "CdUp");
162  hp->AddFrame(rb, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
163  rb->Connect("Clicked()", "FWGeometryTableViewBase", this, "cdUp()");
164  }
165  {
166  m_viewBox = new FWViewCombo(hp, this);
167  hp->AddFrame(m_viewBox, new TGLayoutHints(kLHintsExpandY, 2, 2, 0, 0));
168  }
169  {
170  m_filterType.addEntry(kFilterMaterialName, "MaterialName");
171  m_filterType.addEntry(kFilterMaterialTitle, "MaterialTitle");
172  m_filterType.addEntry(kFilterShapeName, "ShapeName");
173  m_filterType.addEntry(kFilterShapeClassName, "ShapeClassName");
174 
175  std::shared_ptr<FWParameterSetterBase> ptr(FWParameterSetterBase::makeSetterFor((FWParameterBase*)&m_filterType));
176  ptr->attach((FWParameterBase*)&m_filterType, this);
177 
178  TGFrame* pframe = ptr->build(hp, false);
179  hp->AddFrame(pframe, new TGLayoutHints(kLHintsLeft));
180  m_filterTypeSetter.swap(ptr);
181  }
182  {
183  hp->AddFrame(new TGLabel(hp, "FilterExp:"), new TGLayoutHints(kLHintsBottom, 0, 0, 0, 2));
185  m_filterEntry->SetHeight(20);
188  hp->AddFrame(m_filterEntry, new TGLayoutHints(kLHintsExpandX, 0, 2, 1, 0));
190  m_filterEntry->getListBox()->Connect("Selected(int)", "FWGeometryTableView", this, "filterListCallback()");
191  m_filterEntry->Connect("ReturnPressed()", "FWGeometryTableView", this, "filterTextEntryCallback()");
192 
193  gVirtualX->GrabKey(m_filterEntry->GetId(), gVirtualX->KeysymToKeycode((int)kKey_A), kKeyControlMask, true);
194  }
195  m_frame->AddFrame(hp, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 2, 0));
196 
198  {
199  TEveGeoManagerHolder gmgr(FWGeometryTableViewManager::getGeoMangeur());
200  m_tableManager->loadGeometry(gGeoManager->GetTopNode(), gGeoManager->GetListOfVolumes());
201  }
202  cdTop();
203 
204  m_mode.addEntry(kNode, "Node");
205  m_mode.addEntry(kVolume, "Volume");
206 
207  m_mode.changed_.connect(std::bind(&FWGeometryTableView::refreshTable3D, this));
209  m_visLevel.changed_.connect(std::bind(&FWGeometryTableView::refreshTable3D, this));
210 
212 
214  postConst();
215 
216  m_proximityAlgo.addEntry(kBBoxCenter, "BBox center");
217  m_proximityAlgo.addEntry(kBBoxSurface, "BBox surface");
218 
222 }
223 
225 
226 //______________________________________________________________________________
229 
230  m_topNodeIdx.set(parentIdx);
232  ->refEntries()
233  .at(getTopNodeIdx())
235  getTableManager()->setLevelOffset(getTableManager()->refEntries().at(getTopNodeIdx()).m_level);
236 
238  refreshTable3D();
239 }
240 
241 //______________________________________________________________________________
243 
244 //______________________________________________________________________________
246  if (!m_enableRedraw)
247  return;
249  getTableManager()->redrawTable(true);
250 }
251 
252 //______________________________________________________________________________
254  // std::cout << "text entry click ed \n" ;
255  std::string exp = m_filterEntry->GetText();
256  updateFilter(exp);
257 }
258 
259 //______________________________________________________________________________
261  // std::cout << "list click ed [" << m_filterEntry->GetText() << "] \n" ;
262 
263  std::string exp = m_filterEntry->GetText();
264  updateFilter(exp);
265 }
266 
267 //______________________________________________________________________________
269  // std::cout << "=FWGeometryTableViewBase::updateFilter()" << m_filterEntry->GetText() <<std::endl;
270 
271  if (exp.empty()) {
272  // std::cout << "FITLER OFF \n";
274  i != m_tableManager->refEntries().end();
275  ++i) {
276  m_tableManager->setVisibility(*i, true);
278  }
279 
280  // NOTE: entry should be cleared automatically
281  m_filterEntry->Clear();
282  }
283 
284  m_filter.set(exp);
286  refreshTable3D();
287 }
288 
289 //==============================================================================
290 
292  gui.requestTab("Style")
293  .addParam(&m_mode)
295  .separator()
301  .separator()
305  .separator();
306 
307  TGTextButton* butt = new TGTextButton(gui.getTabContainer(), "ReloadColors");
308  gui.getTabContainer()->AddFrame(butt);
309  butt->Connect("Clicked()", "FWGeometryTableViewBase", (FWGeometryTableViewBase*)this, "reloadColors()");
310 }
311 
312 //------------------------------------------------------------------------------
313 
314 /*
315 void FWGeometryTableView::setPath(int parentIdx, std::string& path)
316 {
317  // printf("Set Path to [%s], current node \n", path.c_str());
318  m_topNodeIdx.set(parentIdx);
319  getTableManager()->refEntries().at(getTopNodeIdx()).setBitVal(FWGeometryTableManagerBase::kVisNodeSelf,!m_disableTopNode.value() );
320  getTableManager()->setLevelOffset(getTableManager()->refEntries().at(getTopNodeIdx()).m_level);
321 
322  m_eveTopNode->clearSelection();
323 
324  checkExpandLevel();
325  refreshTable3D();
326  FWGUIManager::getGUIManager()->updateStatus(path.c_str());
327  }*/
328 
329 //--------------------------------------------------------------
330 bool viewIsChecked(TEveViewer* v, TEveElement* el) {
331  if (strstr(v->GetElementName(), "3D")) {
332  for (TEveElement::List_i eit = v->BeginChildren(); eit != v->EndChildren(); ++eit) {
333  TEveScene* s = ((TEveSceneInfo*)*eit)->GetScene();
334  if (el && s->HasChildren() && s->FirstChild() == el)
335  return true;
336  }
337  }
338  return false;
339 }
340 
342  if (m_selectRegion.value()) {
343  double* center = nullptr;
344  for (TEveElement::List_i it = gEve->GetViewers()->BeginChildren(); it != gEve->GetViewers()->EndChildren(); ++it) {
345  TEveViewer* v = ((TEveViewer*)(*it));
346  if (viewIsChecked(v, m_eveTopNode)) {
347  if (center) {
348  fwLog(fwlog::kWarning) << "Center picked from first view \n";
349  } else {
350  center = v->GetGLViewer()->CurrentCamera().GetCenterVec();
351  fwLog(fwlog::kInfo) << Form(
352  "Center picked (%.1f, %.1f, %.1f) from first selected 3D view \n", center[0], center[1], center[2]);
353  }
354  }
355  }
356 
357  if (!center) {
358  fwLog(fwlog::kError) << "No 3D view selected \n";
359  return;
360  }
361 
363  } else {
365  }
366 
367  refreshTable3D();
368 }
369 
370 //------------------------------------------------------------------------------
371 
373  m_enableRedraw = false;
374  for (const_iterator it = begin(), itEnd = end(); it != itEnd; ++it) {
375  // printf("set from %s \n",(*it)->name().c_str() );
376  if ((*it)->name() == m_topNodeIdx.name())
378  else
379  (*it)->setFrom(iFrom);
380  }
381 
383 
384  TGComboBox* cbox = ((FWEnumParameterSetter*)m_filterTypeSetter.get())->getWidget();
385  cbox->Select(m_filterType.value(), false);
386  m_viewersConfig = iFrom.valueForKey("Viewers");
387 
388  m_enableRedraw = true;
389  m_filterEntry->SetText(m_filter.value().c_str(), false);
392  refreshTable3D();
393  /*
394  getTableManager()->redrawTable();
395  m_eveTopNode->ElementChanged();
396  gEve->FullRedraw3D(false, true);
397  */
398 }
399 
400 //------------------------------------------------------------------------------
401 
404  ->refEntries()
405  .at(getTopNodeIdx())
407  refreshTable3D();
408 }
FWGeometryTableView * m_browser
std::vector< const char * > m_list
FWGeoTopNode * m_eveTopNode
const_iterator begin() const
void updateFilter(std::string &)
void setPath(int, std::string &) override
FWGeoMaterialValidator * m_filterValidator
FWDoubleParameter m_regionRadius
void setTopNodePathFromConfig(const FWConfiguration &iFrom)
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)
FWBoolParameter m_disableTopNode
std::vector< FWParameterBase * >::const_iterator const_iterator
const_iterator end() const
const std::string & name() const
FWEnumParameter m_filterType
void clearSelection()
Definition: FWGeoTopNode.h:76
FWGeoTopNodeGLScene * m_scene
Definition: FWGeoTopNode.h:66
FWLongParameter m_visLevel
def unique(seq, keepstr=True)
Definition: tier0.py:24
FWStringParameter m_filter
void setValidator(FWValidatorBase *)
virtual void addDaughtersRec(TGeoVolume *v) const
bool addEntry(Long_t id, const std::string &txt)
std::shared_ptr< FWParameterSetterBase > m_filterTypeSetter
FWEnumParameter m_mode
FWGeometryTableManager * m_tableManager
void fillOptions(const char *iBegin, const char *iEnd, std::vector< std::pair< std::shared_ptr< std::string >, std::string > > &oOptions) const override
FWGeoMaterialValidator(FWGeometryTableView *v)
bool isStringValid(std::string &exp)
#define fwLog(_level_)
Definition: fwLog.h:45
bool viewIsChecked(TEveViewer *v, TEveElement *el)
part
Definition: HCALResponse.h:20
void setFrom(const FWConfiguration &) override
void loadGeometry(TGeoNode *iGeoTopNode, TObjArray *iVolumes)
ViewerParameterGUI & addParam(const FWParameterBase *)
FWGeometryTableManagerBase * getTableManager() override
TGCompositeFrame * getTabContainer()
const FWConfiguration * valueForKey(const std::string &iKey) const
static std::shared_ptr< FWParameterSetterBase > makeSetterFor(FWParameterBase *)
void setVisibility(NodeInfo &nodeInfo, bool) override
FWBoolParameter m_visLevelFilter
FWEnumParameter m_proximityAlgo
sigc::signal< void(T)> changed_
void populateController(ViewerParameterGUI &) const override
FWGUIValidatingTextEntry * m_filterEntry
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void redrawTable(bool setExpand=false)
void setVisibilityChld(NodeInfo &nodeInfo, bool) override