CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWGeometryTableViewBase.cc
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include <boost/bind.hpp>
4 #include <boost/regex.hpp>
5 
19 
20 
21 #include "TGFileDialog.h"
22 #include "TGeoNode.h"
23 #include "TGeoMatrix.h"
24 #include "TGStatusBar.h"
25 #include "TGButton.h"
26 #include "TGLabel.h"
27 #include "TGLPhysicalShape.h"
28 #include "TGMenu.h"
29 #include "TGComboBox.h"
30 // #define PERFTOOL_BROWSER
31 #include "TGeoShape.h"
32 #include "TGeoBBox.h"
33 #include "TEveManager.h"
34 #include "TEveGeoNode.h"
35 #include "TEveScene.h"
36 #include "TEveSceneInfo.h"
37 #include "TEveViewer.h"
38 #include "TGLViewer.h"
39 #include "TGLCamera.h"
40 #include "TEveSelection.h"
41 #ifdef PERFTOOL_BROWSER
42 #include <google/profiler.h>
43 #endif
44 
45 //______________________________________________________________________________
46 //==============================================================================
47 //==============================================================================
48 //==============================================================================
49 //==============================================================================
50 
52 {
53  if (event->fType == kButtonPress)
54  {
55  bool map = false;
56 
57  FWPopupMenu* m_viewPopup = new FWPopupMenu(0);
58 
59  TEveElementList* views = gEve->GetViewers();
60  int idx = 0;
61 
62  for (TEveElement::List_i it = views->BeginChildren(); it != views->EndChildren(); ++it)
63  {
64  TEveViewer* v = ((TEveViewer*)(*it));
65  if (strstr( v->GetElementName(), "3D") )
66  {
67  bool added = false;
68  m_viewPopup->AddEntry(v->GetElementName(), idx);
69 
70  for (TEveElement::List_i eit = v->BeginChildren(); eit != v->EndChildren(); ++eit )
71  {
72  TEveScene* s = ((TEveSceneInfo*)*eit)->GetScene();
73  if (m_el && s->HasChildren() && s->FirstChild() == m_el) {
74  added = true;
75  break;
76  }
77  }
78  map = true;
79  if (added)
80  m_viewPopup->CheckEntry(idx);
81  }
82  ++idx;
83  }
84 
85  if (map) {
86 
87  Window_t wdummy;
88  Int_t ax,ay;
89  gVirtualX->TranslateCoordinates(GetId(),
90  gClient->GetDefaultRoot()->GetId(),
91  event->fX, event->fY, //0,0 in local coordinates
92  ax,ay, //coordinates of screen
93  wdummy);
94 
95 
96  m_viewPopup->PlaceMenu(ax, ay, true,true);
97  m_viewPopup->Connect("Activated(Int_t)",
98  "FWGeometryTableViewBase",
99  const_cast<FWGeometryTableViewBase*>(m_tableView),
100  "selectView(Int_t)");
101  }
102  else
103  {
104  fwLog(fwlog::kInfo) << "No 3D View added. \n";
105  }
106  }
107  return true;
108 }
109 
110 //==============================================================================
111 //==============================================================================
112 // workaround to get ESC key event
113 
114 namespace {
115  class FWGeometryVF : public TGVerticalFrame
116  {
117  public:
118  FWGeometryVF(const TGWindow* p, FWGeometryTableViewBase* tv) :TGVerticalFrame(p), m_tv (tv)
119  {
120  m_tv = tv;
121  gVirtualX->SelectInput(GetId(), kKeyPressMask | kKeyReleaseMask | kExposureMask |
122  kPointerMotionMask | kStructureNotifyMask | kFocusChangeMask |
123  kEnterWindowMask | kLeaveWindowMask);
124  }
125 
126  virtual ~FWGeometryVF() {};
127 
128  virtual Bool_t HandleKey(Event_t *event) override
129  {
130  if (event->fCode == (UInt_t) gVirtualX->KeysymToKeycode(kKey_Escape)) {
131  m_tv->getTableManager()->cancelEditor(true);
132  }
133  return TGCompositeFrame::HandleKey(event);
134  }
135 
137  };
138 
139  class FWTranspEntry : public TGTextEntry
140  {
141  public:
142  FWTranspEntry(const TGWindow* p, FWGeometryTableViewBase* tv) :TGTextEntry(p), m_tv (tv){}
143  virtual ~FWTranspEntry() {}
144 
145  virtual Bool_t HandleKey(Event_t *event) override
146  {
147  if (event->fCode == (UInt_t) gVirtualX->KeysymToKeycode(kKey_Escape)) {
148  m_tv->getTableManager()->cancelEditor(true);
149  }
150  return TGTextEntry::HandleKey(event);
151  }
153  };
154 }
155 //==============================================================================
156 //==============================================================================
157 //==============================================================================
158 //==============================================================================
159 //==============================================================================
161  : FWViewBase(type),
162  m_topNodeIdx(this, "TopNodeIndex", -1l, 0, 1e7),
163  m_autoExpand(this,"ExpandList:", 1l, 0l, 100l),
164  m_enableHighlight(this,"EnableHighlight", true),
165  m_parentTransparencyFactor(this, "ParentTransparencyFactor", 1l, 0l, 100l),
166  m_leafTransparencyFactor(this, "LeafTransparencyFactor", 1l, 0l, 100l),
167 m_minParentTransparency(this, "MinParentTransparency", type == FWViewType::kOverlapTable ? 0l : 90l, 0l, 100l),
168  m_minLeafTransparency(this, "MinLeafTransparency", 0l, 0l, 100l),
169  m_colorManager(colMng),
170  m_colorPopup(0),
171  m_eveWindow(0),
172  m_frame(0),
173  m_viewBox(0),
174  m_viewersConfig(0),
176  m_marker(0),
177  m_eveTopNode(0),
178  m_eveScene(0),
180 {
181  m_eveWindow = iParent->MakeFrame(0);
182  TGCompositeFrame* xf = m_eveWindow->GetGUICompositeFrame();
183 
184  m_frame = new FWGeometryVF(xf, this);
185 
186  xf->AddFrame(m_frame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
187 
192 
193 }
194 
196 {
198  m_frame->AddFrame(m_tableWidget,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY,2,2,0,0));
202  m_tableWidget->Connect("cellClicked(Int_t,Int_t,Int_t,Int_t,Int_t,Int_t)",
203  "FWGeometryTableViewBase",this,
204  "cellClicked(Int_t,Int_t,Int_t,Int_t,Int_t,Int_t)");
206  // resetSetters();
207 
208 
209  FWTranspEntry *editor = new FWTranspEntry(m_tableWidget->body(), this);
210  editor->SetBackgroundColor(gVirtualX->GetPixel(kYellow-7));
211  editor->SetFrameDrawn(false);
212  editor->Connect("ReturnPressed()", "FWGeometryTableViewBase",this,"transparencyChanged()");
214 
215  m_frame->MapSubwindows();
216  editor->UnmapWindow();
217  m_frame->Layout();
218  m_eveWindow->GetGUICompositeFrame()->Layout();
219  m_frame->MapWindow();
220 }
221 //______________________________________________________________________________
222 
224 {
225  // take out composite frame and delete it directly (zwithout the timeout)
226  TGCompositeFrame *frame = m_eveWindow->GetGUICompositeFrame();
227  frame->RemoveFrame( m_frame );
228  delete m_frame;
229 
230 
231 
232  m_eveWindow->DestroyWindowAndSlot();
233  delete getTableManager();
234 }
235 
236 
237 namespace {
238 TEveScene* getMarkerScene(TEveViewer* v)
239 {
240  TEveElement* si = v->FindChild(Form("SI - EventScene %s", v->GetElementName()));
241  if(si)
242  return ((TEveSceneInfo*)(si))->GetScene();
243  else
244  return 0;
245 }
246 }
247 //==============================================================================
248 
249 
251 {
252  std::string p;
253  getTableManager()->getNodePath(idx, p);
254  setPath(idx, p);
255 }
256 
258 {
259  std::string path = "/" ;
260  path += getTableManager()->refEntries().at(0).name();
261  setPath(-1, path );
262 }
263 
265 {
266  if (getTopNodeIdx() != -1)
267  {
268  int pIdx = getTableManager()->refEntries()[getTopNodeIdx()].m_parent;
269  std::string p;
270  getTableManager()->getNodePath(pIdx, p);
271  setPath(pIdx, p);
272  }
273 }
274 
276 {
278 
279  // printf("set path %d \n", parentIdx);
280  m_topNodeIdx.set(parentIdx);
281  // getTableManager()->refEntries().at(getTopNodeIdx()).setBitVal(FWGeometryTableManagerBase::kVisNodeSelf,!m_disableTopNode.value() );
282  getTableManager()->setLevelOffset(getTableManager()->refEntries().at(getTopNodeIdx()).m_level);
283 
284 
286  refreshTable3D();
287 }
288 
289 //------------------------------------------------------------------------------
290 
292 {
293  // check expand state
294  int ae = m_autoExpand.value();
295  if ( m_topNodeIdx.value() > 0)
296  ae += getTableManager()->refEntries().at(m_topNodeIdx.value()).m_level;
297 
299  {
300  if (i->m_level < ae)
302  else
304  }
305 }
306 
307 //==============================================================================
308 
309 void
311 {
312  // post-config
313  if (m_viewersConfig) {
314  TEveElementList* viewers = gEve->GetViewers();
316 
317  if(0!=keyVals)
318  {
319  for(FWConfiguration::KeyValuesIt it = keyVals->begin(); it!= keyVals->end(); ++it) {
320 
321  TString sname = it->first;
322  TEveViewer* v = dynamic_cast<TEveViewer*>(viewers->FindChild(sname.Data()));
323  if (!v)
324  {
325  fwLog(fwlog::kError) << "FWGeometryTableViewBase::populate3DViewsFromConfig no viewer found " << it->first << std::endl;
326  return;
327  }
328  v->AddScene(m_eveScene);
330  if (m_marker) getMarkerScene(v)->AddElement(m_marker);
331 
332  gEve->FullRedraw3D(false, true);
333  }
334  }
335  }
336 }
337 
338 //==============================================================================
339 
340 void
342 {
343  // callback from sleclect view popup menu
344 
346 
347  TEveElement::List_i it = gEve->GetViewers()->BeginChildren();
348  std::advance(it, idx);
349  TEveViewer* v = (TEveViewer*)(*it);
350 
351  for (TEveElement::List_i eit = v->BeginChildren(); eit != v->EndChildren(); ++eit )
352  {
353  if ((((TEveSceneInfo*)(*eit))->GetScene()) == m_eveScene)
354  {
355  v->RemoveElement(*eit);
356  if (m_marker) getMarkerScene(v)->RemoveElement(m_marker);
357  gEve->Redraw3D();
358  return;
359  }
360  }
361 
362  if (m_marker) getMarkerScene(v)->AddElement(m_marker);
363  v->AddScene(m_eveScene);
364  gEve->Redraw3D();
365 }
366 
367 //==============================================================================
368 
369 void
371 {
372  // printf("cell clicled top node %p\n", (void*)m_eveTopNode);
373  if (gEve->GetSelection()->HasChild( m_eveTopNode))
374  gEve->GetSelection()->RemoveElement( m_eveTopNode);
375 
376  if (gEve->GetHighlight()->HasChild( m_eveTopNode))
377  gEve->GetHighlight()->RemoveElement( m_eveTopNode);
378 
379  // reset bits and sets for old selected table entry
382 
383 
385  gEve->GetSelection()->AddElement(m_eveTopNode);
386 
389  gEve->Redraw3D();
390 }
391 //______________________________________________________________________________
392 
393 void
394 FWGeometryTableViewBase::cellClicked(Int_t iRow, Int_t iColumn, Int_t iButton, Int_t iKeyMod, Int_t x, Int_t y)
395 {
396  int idx = getTableManager()->rowToIndex()[iRow];
398 
399  if (iColumn != 2) getTableManager()->cancelEditor(false);
400 
401  bool elementChanged = false;
402  if (iButton == kButton1)
403  {
404  if (iColumn == 0)
405  {
406  Window_t wdummy;
407  Int_t xLoc,yLoc;
408  gVirtualX->TranslateCoordinates(gClient->GetDefaultRoot()->GetId(), m_tableWidget->GetId(), x, y, xLoc, yLoc, wdummy);
409 
410  if (getTableManager()->firstColumnClicked(iRow, xLoc))
411  setColumnSelected(idx);
412  }
413  else if (iColumn == 1)
414  {
415  std::vector<Color_t> colors;
417 
418  if (!m_colorPopup) {
419  m_colorPopup = new FWColorPopup(gClient->GetDefaultRoot(), colors.front());
420  m_colorPopup->InitContent("", colors);
421  m_colorPopup->Connect("ColorSelected(Color_t)","FWGeometryTableViewBase", const_cast<FWGeometryTableViewBase*>(this), "nodeColorChangeRequested(Color_t");
422  }
424  m_colorPopup->SetName("Selected");
426  m_colorPopup->PlacePopup(x, y, m_colorPopup->GetDefaultWidth(), m_colorPopup->GetDefaultHeight());
427  return;
428  }
429  else if (iColumn == 2)
430  {
431  // transparency edit
432  getTableManager()->showEditor(idx);
433  }
434  else if (iColumn == 3)
435  {
436  // vis self
437  getTableManager()->setVisibility(ni, !getTableManager()->getVisibility(ni));
438  elementChanged = true;
439  }
440  else if (iColumn == 4)
441  {
442  // vis children
443  getTableManager()->setVisibilityChld(ni, !getTableManager()->getVisibilityChld(ni));
444  elementChanged = true;
445  }
446  else if (iColumn == 6)
447  {
448  // used in overlaps for RnrMarker column
449  ni.switchBit(BIT(5));
450  elementChanged = true;
451  }
452  else
453  {
454  setColumnSelected(idx);
455  }
456 
457  if (elementChanged) {
458  refreshTable3D();
459  // getTableManager()->dataChanged();
460  }
461  }
462  else if (iColumn == 0)
463  {
464  setColumnSelected(idx);
465  m_eveTopNode->popupMenu(x, y, 0);
466  }
467 }
468 
469 
471 {
473  if(backgroundIsWhite) {
476  } else {
479  }
480  getTableManager()->setBackgroundToWhite(backgroundIsWhite);
481  gClient->NeedRedraw(m_tableWidget);
482 }
483 
484 //______________________________________________________________________________
485 
487 {
488  // AMT: need to add virtual FWGeometryTableView::nodeColorChangeRequested() for volume mode
489 
490  // printf("color change %d \n", m_tableRowIndexForColorPopup);
491  if (m_tableRowIndexForColorPopup >= 0) {
493  ni.m_color = col;
494  ni.m_node->GetVolume()->SetLineColor(col);
495  refreshTable3D();
497  }
498 }
499 
500 
501 //______________________________________________________________________________
503 {
504  int selectedIdx = m_eveTopNode->getFirstSelectedTableIndex();
506  // printf("chosen item %s %d\n", ni.name(), menuIdx);
507 
508  TGeoVolume *gv = ni.m_node->GetVolume();
509  bool resetHome = false;
510  if (gv)
511  {
512  switch (menuIdx)
513  {
515  getTableManager()->setVisibility(ni, false);
516  refreshTable3D();
517  break;
518 
520  getTableManager()->setDaughtersSelfVisibility(selectedIdx, false);
521  refreshTable3D();
522  break;
523 
525  getTableManager()->setDaughtersSelfVisibility(selectedIdx, true);
526  refreshTable3D();
527  break;
528 
530  gv->InspectMaterial();
531  break;
532 
534  gv->InspectShape();
535  break;
536 
538  {
539  std::string ps;
540  getTableManager()->getNodePath(selectedIdx, ps);
541  std::cout << ps << std::endl;
542  break;
543  }
545  cdNode(selectedIdx);
546  break;
547 
549  cdNode(selectedIdx);
550  resetHome = true;
551  break;
552 
554  {
555  TGLViewer* v = FWGeoTopNode::s_pickedViewer;
556  v->CurrentCamera().SetExternalCenter(true);
558  v->SetDrawCameraCenter(true);
559  // resetHome = true;
560  break;
561  }
562  default:
563  return;
564  }
565  }
566 
567  if (resetHome) gEve->FullRedraw3D(true, true);
568 
569 }
570 //______________________________________________________________________________
572 {
574  refreshTable3D();
575 }
576 
577 //______________________________________________________________________________
578 
580 {
581  if (m_enableRedraw)
582  {
583  if (gEve->GetSelection()->HasChild(m_eveTopNode))
584  gEve->GetSelection()->RemoveElement(m_eveTopNode);
585 
586  if (gEve->GetHighlight()->HasChild(m_eveTopNode))
587  gEve->GetHighlight()->RemoveElement(m_eveTopNode);
588 
589  m_eveTopNode->m_scene->PadPaint(m_eveTopNode->m_scene->GetPad());
590  gEve->Redraw3D();
591 
593  }
594 }
595 
596 //______________________________________________________________________________
597 
599 {
601 
602  FWConfiguration viewers(1);
603  FWConfiguration tempArea;
604 
605  for(TEveElement::List_i k = gEve->GetViewers()->BeginChildren(); k!= gEve->GetViewers()->EndChildren(); ++k)
606  {
607  for (TEveElement::List_i eit = (*k)->BeginChildren(); eit != (*k)->EndChildren(); ++eit )
608  {
609  TEveScene* s = ((TEveSceneInfo*)*eit)->GetScene();
610  if (s->GetGLScene() == m_eveTopNode->m_scene)
611  {
612  viewers.addKeyValue( (*k)->GetElementName(), tempArea);
613  break;
614  }
615  }
616  }
617 
618  iTo.addKeyValue("Viewers", viewers, true);
619 }
620 
621 //______________________________________________________________________________
622 
624 {
625  int tn;
626  const FWConfiguration* value = iFrom.valueForKey( m_topNodeIdx.name() );
627  if (!value) return;
628 
629  std::istringstream s(value->value());
630  s>> tn;
631  int lastIdx = getTableManager()->refEntries().size() -1;
632  if (tn >= lastIdx) {
633  fwLog(fwlog::kWarning) << Form("Ignoring node path from confugration file -- %s value larger than number of nodes \n", m_topNodeIdx.name().c_str());
634  return;
635  }
636  // std::cerr << "set top node " << ;
637  m_topNodeIdx.set(tn);
638 }
639 
640 //______________________________________________________________________________
641 
643 {
644  // printf("relaodColors \n");
645  for (FWGeometryTableManagerBase::Entries_i i = getTableManager()->refEntries().begin(); i != getTableManager()->refEntries().end(); ++i)
646  {
647  i->m_color = i->m_node->GetVolume()->GetLineColor();
648  }
649 
650  refreshTable3D();
651 }
652 
653 
654 //______________________________________________________________________________
655 
657 {
658  gui.requestTab("Style").
659  separator().
660  //addParam(&m_parentTransparencyFactor).
661  // addParam(&m_leafTransparencyFactor).
662  addParam(&m_minParentTransparency).
663  addParam(&m_minLeafTransparency).
664  separator();
665  TGTextButton* butt = new TGTextButton(gui.getTabContainer(), "ReloadColors");
666  gui.getTabContainer()->AddFrame(butt);
667  butt->Connect("Clicked()", "FWGeometryTableViewBase", (FWGeometryTableViewBase*)this, "reloadColors()");
668 
669 }
670 
671 
const double Z[kNumberCalorimeter]
virtual void cellClicked(Int_t iRow, Int_t iColumn, Int_t iButton, Int_t iKeyMod, Int_t iGlobalX, Int_t iGlobalY)
type
Definition: HCALResponse.h:21
std::vector< std::pair< std::string, FWConfiguration > > KeyValues
int i
Definition: DBlmapReader.cc:9
void SetBackgroundColor(Pixel_t)
bool firstColumnClicked(int row, int xPos)
const KeyValues * keyValues() const
void InitContent(const char *name, const std::vector< Color_t > &colors, bool backgroundIsBlack=true)
virtual void addTo(FWConfiguration &) const
void SetName(const char *iName)
const_iterator begin() const
FWEveDigitSetScalableMarker * m_marker
FWLongParameter m_parentTransparencyFactor
void setTopNodePathFromConfig(const FWConfiguration &iFrom)
ViewerParameterGUI & requestTab(const char *)
const FWConfiguration * m_viewersConfig
std::vector< Color_t > colors
Definition: eve_filter.cc:26
#define X(str)
Definition: MuonsGrabber.cc:48
void fillLimitedColors(std::vector< Color_t > &cv) const
FWLongParameter m_leafTransparencyFactor
void SetHeaderBackgroundColor(Pixel_t)
void getNodePath(int, std::string &) const
virtual void setVisibilityChld(NodeInfo &, bool)
sigc::signal< void, T > changed_
virtual void setPath(int, std::string &)
void SetLineSeparatorColor(Pixel_t)
int getFirstSelectedTableIndex()
void clearSelection()
Definition: FWGeoTopNode.h:76
FWGeoTopNodeGLScene * m_scene
Definition: FWGeoTopNode.h:66
void PlacePopup(Int_t x, Int_t y, UInt_t w, UInt_t h)
void disableGrowInWidth()
tuple path
else: Piece not in the list, fine.
FWGeometryTableViewBase(TEveWindowSlot *, FWViewType::EType, FWColorManager *)
BackgroundColorIndex backgroundColorIndex() const
FWTabularWidget * body()
Definition: FWTableWidget.h:92
void ResetColors(const std::vector< Color_t > &colors, bool backgroundIsBlack=true)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual void popupMenu(int x, int y, TGLViewer *)
Definition: FWGeoTopNode.h:79
void setDaughtersSelfVisibility(bool)
virtual void setVisibility(NodeInfo &, bool)
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
int k[5][pyjets_maxn]
const std::string & value(unsigned int iIndex=0) const
#define fwLog(_level_)
Definition: fwLog.h:50
tuple editor
Definition: idDealer.py:73
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
bool selectPhysicalFromTable(int)
static TGLViewer * s_pickedViewer
Definition: FWGeoTopNode.h:85
void setCellValueEditor(TGTextEntry *editor)
KeyValues::const_iterator KeyValuesIt
TGCompositeFrame * getTabContainer()
virtual void UnHighlighted()
virtual Bool_t HandleButton(Event_t *event)
tuple cout
Definition: gather_cfg.py:121
const FWConfiguration * valueForKey(const std::string &iKey) const
Definition: DDAxes.h:10
int col
Definition: cuy.py:1008
void redrawTable(bool setExpand=false)
virtual void UnSelected()
virtual void populateController(ViewerParameterGUI &) const
const std::string & name() const
static TGLVector3 s_pickedCamera3DCenter
Definition: FWGeoTopNode.h:84
list at
Definition: asciidump.py:428
virtual void addTo(FWConfiguration &) const
virtual FWGeometryTableManagerBase * getTableManager()