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 // $Id: FWGeometryTableManagerBase.cc,v 1.8 2013/04/14 20:39:19 amraktad Exp $
12 //
13 
14 //#define PERFTOOL_GEO_TABLE
15 
16 // user include files
17 #include <iostream>
18 #include <boost/bind.hpp>
19 #include <stack>
20 #ifdef PERFTOOL_GEO_TABLE
21 #include <google/profiler.h>
22 #endif
28 
29 #include "TMath.h"
30 #include "TGeoVolume.h"
31 #include "TGeoMatrix.h"
32 #include "TGeoShape.h"
33 #include "TGeoBBox.h"
34 #include "TGeoMatrix.h"
35 
36 #include "TGFrame.h"
37 #include "TEveUtil.h"
38 #include "boost/lexical_cast.hpp"
39 
40 
42 {
43  return m_node->GetName();
44 }
45 
46 
49  m_width(1),
50  m_height(1),
51  m_color(0xffffff),
52  m_isSelected(false)
53 {
54  GCValues_t gval;
55  gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle | kGCGraphicsExposures;
56  gval.fStipple = gClient->GetResourcePool()->GetCheckeredBitmap();
57  gval.fGraphicsExposures = kFALSE;
58  gval.fBackground = gVirtualX->GetPixel(kGray);
59  m_colorContext = gClient->GetResourcePool()->GetGCPool()->GetGC(&gval,kTRUE);
60 
61 }
62 
64 {
65  gClient->GetResourcePool()->GetGCPool()->FreeGC(m_colorContext->GetGC());
66 }
67 
69 {
70  m_color = gVirtualX->GetPixel(c);
71  m_isSelected = s;
72 }
73 
74 
75 void FWGeometryTableManagerBase::ColorBoxRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)
76 {
79  iWidth += 2*FWTabularWidget::kTextBuffer;
80  iHeight += 2*FWTabularWidget::kTextBuffer;
81 
82  m_colorContext->SetFillStyle(kFillSolid);
83  Pixel_t baq = m_colorContext->GetForeground();
84  m_colorContext->SetForeground(m_color);
85  gVirtualX->FillRectangle(iID, m_colorContext->GetGC(), iX, iY, iWidth, iHeight);
86 
87  if (m_isSelected)
88  {
89  m_colorContext->SetFillStyle(kFillOpaqueStippled);
90  gVirtualX->FillRectangle(iID, m_colorContext->GetGC(), iX, iY, iWidth, iHeight);
91  }
92  m_colorContext->SetForeground(baq);
93 }
94 
95 //==============================================================================
96 //==============================================================================
97 //
98 // class FWGeometryTableManagerBase
99 //
100 //==============================================================================
101 //==============================================================================
102 
104  :
105  m_highlightIdx(-1),
106  m_levelOffset(0),
107  m_editor(0),
109 {
112 
113  GCValues_t gval;
114  gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle | kGCGraphicsExposures;
115  gval.fForeground = gVirtualX->GetPixel(kGray);//gClient->GetResourcePool()->GetFrameHiliteColor();
116  gval.fBackground = gVirtualX->GetPixel(kWhite);//gClient->GetResourcePool()->GetFrameBgndColor();
117  gval.fFillStyle = kFillOpaqueStippled; // kFillTiled;
118  gval.fStipple = gClient->GetResourcePool()->GetCheckeredBitmap();
119  gval.fGraphicsExposures = kFALSE;
120  m_highlightContext = gClient->GetGC(&gval, kTRUE);
121 
123 }
124 
126 {
127 }
128 
129 
131 {
132  return unsorted;
133 }
134 
136 {
137  return m_row_to_index.size();
138 }
139 
140 
141 std::vector<std::string> FWGeometryTableManagerBase::getTitles() const
142 {
143  std::vector<std::string> returnValue;
144  returnValue.reserve(numberOfColumns());
145 
146  returnValue.push_back("Name");
147  returnValue.push_back("Color");
148  returnValue.push_back("Opcty");
149  returnValue.push_back("RnrSelf");
150  returnValue.push_back("RnrChildren");
151  returnValue.push_back("Material");
152  return returnValue;
153 }
154 
156 {
157  return "Geometry";
158 }
159 
160 
162 {
163  if(iToWhite) {
164  m_renderer.setGraphicsContext(&TGFrame::GetBlackGC());
165  } else {
166  m_renderer.setGraphicsContext(&TGFrame::GetWhiteGC());
167  }
168  m_renderer.setBlackIcon(iToWhite);
169 }
170 
171 //______________________________________________________________________________
173 {
174  if (row == -1)
175  return false;
176 
177  int idx = rowToIndex()[row];
178  // printf("click %s \n", m_entries[idx].name());
179 
180  int off = 0;
181  if (idx >= 0)
182  off = (m_entries[idx].m_level - m_levelOffset)* 20;
183 
184  // printf("compare %d %d level %d\n" , xPos, off, idx);
185  if (xPos > off && xPos < (off + 20))
186  {
187  m_entries[idx].switchBit(kExpanded);
188 
190  dataChanged();
192  return false;
193  }
194 
195  return true;
196 }
197 
198 
199 
200 
201 //______________________________________________________________________________
202 
203 void FWGeometryTableManagerBase::getNodeMatrix(const NodeInfo& data, TGeoHMatrix& mtx) const
204 {
205  // utility used by browser and FWGeoNode
206  // printf("================ FWGeometryTableManagerBase::getNodeMatri \n");
207  int pIdx = data.m_parent;
208 
209  while (pIdx > 0)
210  {
211  // printf("%s [%d]\n",m_entries.at(pIdx).name(), m_entries.at(pIdx).m_level );
212  mtx.MultiplyLeft(m_entries.at(pIdx).m_node->GetMatrix());
213  pIdx = m_entries.at(pIdx).m_parent;
214  }
215 
216  // printf("right %s [%d]\n",data.name(), data.m_level );
217  mtx.Multiply(data.m_node->GetMatrix());
218 }
219 
220 //______________________________________________________________________________
222 {
223  // std::cerr << "GeometryTableManagerBase::redrawTable ------------------------------------- \n";
224  if (m_entries.empty()) return;
225 
226  // if (setExpand) checkExpandLevel();
227 
229 
230 
231  dataChanged();
233 }
234 
235 
236 //______________________________________________________________________________
237 
239 {
240  std::vector<std::string> relPath;
241  while(idx >= 0)
242  {
243  relPath.push_back( m_entries[idx].name());
244  // printf("push %s \n",m_entries[idx].name() );
245  idx = m_entries[idx].m_parent;
246  }
247 
248  size_t ns = relPath.size();
249  for (size_t i = 1; i < ns; ++i )
250  {
251  path +="/";
252  path += relPath[ns-i -1];
253  // printf("push_back add to path %s\n", path.c_str());
254  }
255 }
256 
257 //______________________________________________________________________________
258 
259 
261 {
262  m_editor = editor;
264 }
265 
267 {
268  m_editTransparencyIdx = row;
269  m_editor->UnmapWindow();
270  m_editor->SetText(Form("%d", 100 - m_entries[row].m_transparency));
271  m_editor->Resize(40, 17);
272  m_editor->SetCursorPosition(2);
273  redrawTable();
274 }
275 
276 
277 
279 {
280  printf("transparency idx %d opaci %s \n",m_editTransparencyIdx, m_editor->GetText() );
281  if ( m_editTransparencyIdx >= 0)
282  {
283  using boost::lexical_cast;
284  using boost::bad_lexical_cast;
285  try {
286  int t = lexical_cast<int>(m_editor->GetText());
287  if (t > 100 || t < 0 )
288  {
289  fwLog(fwlog::kError) << "Transparency must be set in procentage [0-100].";
290  return;
291  }
292  m_entries[m_editTransparencyIdx].m_transparency = 100 - t;
293  printf("SET !! \n");
294  cancelEditor(true);
295  }
296  catch (bad_lexical_cast &) {
297  fwLog(fwlog::kError) << "Bad Lexical cast. Transparency must be set in procentage [0-100].";
298  }
299  }
300 }
301 
303 {
305 
306  if ( m_editor->IsMapped())
307  {
308  m_editor->UnmapWindow();
309  if (redraw) redrawTable();
310  }
311 }
312 
313 
314 //------------------------------------------------------------------------------
315 
317 {
318  data.setBitVal(kVisNodeSelf, x);
319 }
320 
321 //------------------------------------------------------------------------------
322 
324 {
325  data.setBitVal(kVisNodeChld, x);
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 
354 {
355  return data.testBit(kVisNodeChld);
356 }
357 
358 
359 bool FWGeometryTableManagerBase::isNodeRendered(int idx, int topNodeIdx) const
360 {
361  const NodeInfo& data = m_entries[idx];
362  bool foundParent = false;
363 
364  if (data.testBit(kVisNodeSelf))
365  {
366  int pidx = data.m_parent;
367  while (pidx >= 0 )
368  {
369  if (!m_entries[pidx].testBit(kVisNodeChld)) {
370  // printf ("parent disallow not visible !!! \n");
371  return false;
372  }
373 
374  if (pidx == topNodeIdx) { foundParent = true;
375  // printf("parent found \n");
376  break;
377  }
378  pidx = m_entries[pidx].m_parent;
379  }
380 
381  return foundParent;
382  }
383  return false;
384 }
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 setVisibilityChld(NodeInfo &, bool)
double xPos
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:51
tuple editor
Definition: idDealer.py:73
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
void setCellValueEditor(TGTextEntry *editor)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void visualPropertiesChanged()
Classes which inherit from FWTableManagerBase must call this when how the data is shown (e...
static const int kTextBuffer
Definition: DDAxes.h:10
void redrawTable(bool setExpand=false)
virtual int numberOfRows() const
Number of rows in the table.