CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWGeometryTableManagerBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWGeometryTableManagerBase
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Alja Mrak-Tadel, Matevz Tadel
10 // Created: Thu Jan 27 14:50:57 CET 2011
11 //
12 
13 //#define PERFTOOL_GEO_TABLE
14 
15 // user include files
16 #include <iostream>
17 #include <boost/bind.hpp>
18 #include <stack>
19 #ifdef PERFTOOL_GEO_TABLE
20 #include <google/profiler.h>
21 #endif
27 
28 #include "TMath.h"
29 #include "TGeoVolume.h"
30 #include "TGeoMatrix.h"
31 #include "TGeoShape.h"
32 #include "TGeoBBox.h"
33 #include "TGeoMatrix.h"
34 
35 #include "TGFrame.h"
36 #include "TEveUtil.h"
37 #include "boost/lexical_cast.hpp"
38 
39 
41 {
42  return m_node->GetName();
43 }
44 
45 
48  m_width(1),
49  m_height(1),
50  m_color(0xffffff),
51  m_isSelected(false)
52 {
53  GCValues_t gval;
54  gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle | kGCGraphicsExposures;
55  gval.fStipple = gClient->GetResourcePool()->GetCheckeredBitmap();
56  gval.fGraphicsExposures = kFALSE;
57  gval.fBackground = gVirtualX->GetPixel(kGray);
58  m_colorContext = gClient->GetResourcePool()->GetGCPool()->GetGC(&gval,kTRUE);
59 
60 }
61 
63 {
64  gClient->GetResourcePool()->GetGCPool()->FreeGC(m_colorContext->GetGC());
65 }
66 
68 {
69  m_color = gVirtualX->GetPixel(c);
70  m_isSelected = s;
71 }
72 
73 
74 void FWGeometryTableManagerBase::ColorBoxRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)
75 {
78  iWidth += 2*FWTabularWidget::kTextBuffer;
79  iHeight += 2*FWTabularWidget::kTextBuffer;
80 
81  m_colorContext->SetFillStyle(kFillSolid);
82  Pixel_t baq = m_colorContext->GetForeground();
83  m_colorContext->SetForeground(m_color);
84  gVirtualX->FillRectangle(iID, m_colorContext->GetGC(), iX, iY, iWidth, iHeight);
85 
86  if (m_isSelected)
87  {
88  m_colorContext->SetFillStyle(kFillOpaqueStippled);
89  gVirtualX->FillRectangle(iID, m_colorContext->GetGC(), iX, iY, iWidth, iHeight);
90  }
91  m_colorContext->SetForeground(baq);
92 }
93 
94 //==============================================================================
95 //==============================================================================
96 //
97 // class FWGeometryTableManagerBase
98 //
99 //==============================================================================
100 //==============================================================================
101 
103  :
104  m_highlightIdx(-1),
105  m_levelOffset(0),
106  m_editor(0),
108 {
111 
112  GCValues_t gval;
113  gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle | kGCGraphicsExposures;
114  gval.fForeground = gVirtualX->GetPixel(kGray);//gClient->GetResourcePool()->GetFrameHiliteColor();
115  gval.fBackground = gVirtualX->GetPixel(kWhite);//gClient->GetResourcePool()->GetFrameBgndColor();
116  gval.fFillStyle = kFillOpaqueStippled; // kFillTiled;
117  gval.fStipple = gClient->GetResourcePool()->GetCheckeredBitmap();
118  gval.fGraphicsExposures = kFALSE;
119  m_highlightContext = gClient->GetGC(&gval, kTRUE);
120 
122 }
123 
125 {
126 }
127 
128 
130 {
131  return unsorted;
132 }
133 
135 {
136  return m_row_to_index.size();
137 }
138 
139 
140 std::vector<std::string> FWGeometryTableManagerBase::getTitles() const
141 {
142  std::vector<std::string> returnValue;
143  returnValue.reserve(numberOfColumns());
144 
145  returnValue.push_back("Name");
146  returnValue.push_back("Color");
147  returnValue.push_back("Opcty");
148  returnValue.push_back("RnrSelf");
149  returnValue.push_back("RnrChildren");
150  returnValue.push_back("Material");
151  return returnValue;
152 }
153 
155 {
156  return "Geometry";
157 }
158 
159 
161 {
162  if(iToWhite) {
163  m_renderer.setGraphicsContext(&TGFrame::GetBlackGC());
164  } else {
165  m_renderer.setGraphicsContext(&TGFrame::GetWhiteGC());
166  }
167  m_renderer.setBlackIcon(iToWhite);
168 }
169 
170 //______________________________________________________________________________
172 {
173  if (row == -1)
174  return false;
175 
176  int idx = rowToIndex()[row];
177  // printf("click %s \n", m_entries[idx].name());
178 
179  int off = 0;
180  if (idx >= 0)
181  off = (m_entries[idx].m_level - m_levelOffset)* 20;
182 
183  // printf("compare %d %d level %d\n" , xPos, off, idx);
184  if (xPos > off && xPos < (off + 20))
185  {
186  m_entries[idx].switchBit(kExpanded);
187 
189  dataChanged();
191  return false;
192  }
193 
194  return true;
195 }
196 
197 
198 
199 
200 //______________________________________________________________________________
201 
202 void FWGeometryTableManagerBase::getNodeMatrix(const NodeInfo& data, TGeoHMatrix& mtx) const
203 {
204  // utility used by browser and FWGeoNode
205  // printf("================ FWGeometryTableManagerBase::getNodeMatri \n");
206  int pIdx = data.m_parent;
207 
208  while (pIdx > 0)
209  {
210  // printf("%s [%d]\n",m_entries.at(pIdx).name(), m_entries.at(pIdx).m_level );
211  mtx.MultiplyLeft(m_entries.at(pIdx).m_node->GetMatrix());
212  pIdx = m_entries.at(pIdx).m_parent;
213  }
214 
215  // printf("right %s [%d]\n",data.name(), data.m_level );
216  mtx.Multiply(data.m_node->GetMatrix());
217 }
218 
219 //______________________________________________________________________________
221 {
222  // std::cerr << "GeometryTableManagerBase::redrawTable ------------------------------------- \n";
223  if (m_entries.empty()) return;
224 
225  // if (setExpand) checkExpandLevel();
226 
228 
229 
230  dataChanged();
232 }
233 
234 
235 //______________________________________________________________________________
236 
238 {
239  std::vector<std::string> relPath;
240  while(idx >= 0)
241  {
242  relPath.push_back( m_entries[idx].name());
243  // printf("push %s \n",m_entries[idx].name() );
244  idx = m_entries[idx].m_parent;
245  }
246 
247  size_t ns = relPath.size();
248  for (size_t i = 1; i < ns; ++i )
249  {
250  path +="/";
251  path += relPath[ns-i -1];
252  // printf("push_back add to path %s\n", path.c_str());
253  }
254 }
255 
256 //______________________________________________________________________________
257 
258 
260 {
261  m_editor = editor;
263 }
264 
266 {
267  m_editTransparencyIdx = row;
268  m_editor->UnmapWindow();
269  m_editor->SetText(Form("%d", 100 - m_entries[row].m_transparency));
270  m_editor->Resize(40, 17);
271  m_editor->SetCursorPosition(2);
272  redrawTable();
273 }
274 
275 
276 
278 {
279  printf("transparency idx %d opaci %s \n",m_editTransparencyIdx, m_editor->GetText() );
280  if ( m_editTransparencyIdx >= 0)
281  {
282  using boost::lexical_cast;
283  using boost::bad_lexical_cast;
284  try {
285  int t = lexical_cast<int>(m_editor->GetText());
286  if (t > 100 || t < 0 )
287  {
288  fwLog(fwlog::kError) << "Transparency must be set in procentage [0-100].";
289  return;
290  }
291  m_entries[m_editTransparencyIdx].m_transparency = 100 - t;
292  printf("SET !! \n");
293  cancelEditor(true);
294  }
295  catch (bad_lexical_cast &) {
296  fwLog(fwlog::kError) << "Bad Lexical cast. Transparency must be set in procentage [0-100].";
297  }
298  }
299 }
300 
302 {
304 
305  if ( m_editor->IsMapped())
306  {
307  m_editor->UnmapWindow();
308  if (redraw) redrawTable();
309  }
310 }
311 
312 
313 //------------------------------------------------------------------------------
314 
316 {
317  data.setBitVal(kVisNodeSelf, x);
318 }
319 
320 //------------------------------------------------------------------------------
321 
323 {
324  data.setBitVal(kVisNodeChld, x);
325 }
326 
327 //------------------------------------------------------------------------------
328 
330 {
331  TGeoNode *parentNode = m_entries[selectedIdx].m_node;
332  int nD = parentNode->GetNdaughters();
333  int dOff = 0;
334  for (int n = 0; n != nD; ++n)
335  {
336  int idx = selectedIdx + 1 + n + dOff;
338 
339  setVisibility(data, v);
340  setVisibilityChld(data, v);
341 
342  getNNodesTotal(parentNode->GetDaughter(n), dOff);
343  }
344 }
345 
346 //------------------------------------------------------------------------------
347 
349 {
350  return data.testBit(kVisNodeSelf);
351 }
352 
353 //------------------------------------------------------------------------------
354 
356 {
357  return data.testBit(kVisNodeChld);
358 }
359 
360 //------------------------------------------------------------------------------
361 
363 {
364  NodeInfo &nInfo = m_entries[selectedIdx];
365  TGeoNode *parentNode = nInfo.m_node;
366  int nD = parentNode->GetNdaughters();
367  int dOff = 0;
368  for (int n = 0; n != nD; ++n)
369  {
370  int idx = selectedIdx + 1 + n + dOff;
372 
373  data.copyColorTransparency(nInfo);
374 
375  if (recurse)
376  {
377  applyColorTranspToDaughters(idx, recurse);
378  }
379 
380  getNNodesTotal(parentNode->GetDaughter(n), dOff);
381  }
382 }
383 
384 //------------------------------------------------------------------------------
385 
386 bool FWGeometryTableManagerBase::isNodeRendered(int idx, int topNodeIdx) const
387 {
388  const NodeInfo& data = m_entries[idx];
389  bool foundParent = false;
390 
391  if (data.testBit(kVisNodeSelf))
392  {
393  int pidx = data.m_parent;
394  while (pidx >= 0 )
395  {
396  if (!m_entries[pidx].testBit(kVisNodeChld)) {
397  // printf ("parent disallow not visible !!! \n");
398  return false;
399  }
400 
401  if (pidx == topNodeIdx) { foundParent = true;
402  // printf("parent found \n");
403  break;
404  }
405  pidx = m_entries[pidx].m_parent;
406  }
407 
408  return foundParent;
409  }
410  return false;
411 }
virtual int numberOfColumns() const =0
Number of columns in the table.
virtual UInt_t height() const
returns the minimum height of the cell to which the renderer is representing
int i
Definition: DBlmapReader.cc:9
bool isNodeRendered(int idx, int top_node_idx) const
virtual std::vector< std::string > getTitles() const
returns the title names for each column
virtual void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)
bool firstColumnClicked(int row, int xPos)
virtual bool getVisibility(const NodeInfo &nodeInfo) const
virtual void recalculateVisibility()=0
virtual bool getVisibilityChld(const NodeInfo &nodeInfo) const
void getNodePath(int, std::string &) const
void getNodeMatrix(const NodeInfo &nodeInfo, TGeoHMatrix &mat) const
void dataChanged()
Classes which inherit from FWTableManagerBase must call this when their underlying data changes...
virtual void applyColorTranspToDaughters(int selectedIdx, bool recurse)
virtual void setVisibilityChld(NodeInfo &, bool)
T x() const
Cartesian x coordinate.
void setHighlightContext(const TGGC *context)
virtual void setCellEditor(TGTextEntry *editor)
virtual const std::string title() const
void setGraphicsContext(const TGGC *iContext)
void setDaughtersSelfVisibility(bool)
virtual void setVisibility(NodeInfo &, bool)
static void getNNodesTotal(TGeoNode *geoNode, int &off)
virtual int unsortedRowNumber(int unsorted) const
when passed the index to the sorted order of the rows it returns the original row number from the und...
#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...
void setCellValueEditor(TGTextEntry *editor)
void visualPropertiesChanged()
Classes which inherit from FWTableManagerBase must call this when how the data is shown (e...
static const int kTextBuffer
volatile std::atomic< bool > shutdown_flag false
void redrawTable(bool setExpand=false)
virtual int numberOfRows() const
Number of rows in the table.