CMS 3D CMS Logo

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 const char* FWGeometryTableManagerBase::NodeInfo::name() const { return m_node->GetName(); }
40 
42  : FWTableCellRendererBase(), m_width(1), m_height(1), m_color(0xffffff), m_isSelected(false) {
43  GCValues_t gval;
44  gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle | kGCGraphicsExposures;
45  gval.fStipple = gClient->GetResourcePool()->GetCheckeredBitmap();
46  gval.fGraphicsExposures = kFALSE;
47  gval.fBackground = gVirtualX->GetPixel(kGray);
48  m_colorContext = gClient->GetResourcePool()->GetGCPool()->GetGC(&gval, kTRUE);
49 }
50 
52  gClient->GetResourcePool()->GetGCPool()->FreeGC(m_colorContext->GetGC());
53 }
54 
56  m_color = gVirtualX->GetPixel(c);
57  m_isSelected = s;
58 }
59 
61  Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) {
64  iWidth += 2 * FWTabularWidget::kTextBuffer;
65  iHeight += 2 * FWTabularWidget::kTextBuffer;
66 
67  m_colorContext->SetFillStyle(kFillSolid);
68  Pixel_t baq = m_colorContext->GetForeground();
69  m_colorContext->SetForeground(m_color);
70  gVirtualX->FillRectangle(iID, m_colorContext->GetGC(), iX, iY, iWidth, iHeight);
71 
72  if (m_isSelected) {
73  m_colorContext->SetFillStyle(kFillOpaqueStippled);
74  gVirtualX->FillRectangle(iID, m_colorContext->GetGC(), iX, iY, iWidth, iHeight);
75  }
76  m_colorContext->SetForeground(baq);
77 }
78 
79 //==============================================================================
80 //==============================================================================
81 //
82 // class FWGeometryTableManagerBase
83 //
84 //==============================================================================
85 //==============================================================================
86 
91 
92  GCValues_t gval;
93  gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle | kGCGraphicsExposures;
94  gval.fForeground = gVirtualX->GetPixel(kGray); //gClient->GetResourcePool()->GetFrameHiliteColor();
95  gval.fBackground = gVirtualX->GetPixel(kWhite); //gClient->GetResourcePool()->GetFrameBgndColor();
96  gval.fFillStyle = kFillOpaqueStippled; // kFillTiled;
97  gval.fStipple = gClient->GetResourcePool()->GetCheckeredBitmap();
98  gval.fGraphicsExposures = kFALSE;
99  m_highlightContext = gClient->GetGC(&gval, kTRUE);
100 
102 }
103 
105 
106 int FWGeometryTableManagerBase::unsortedRowNumber(int unsorted) const { return unsorted; }
107 
109 
110 std::vector<std::string> FWGeometryTableManagerBase::getTitles() const {
111  std::vector<std::string> returnValue;
112  returnValue.reserve(numberOfColumns());
113 
114  returnValue.push_back("Name");
115  returnValue.push_back("Color");
116  returnValue.push_back("Opcty");
117  returnValue.push_back("RnrSelf");
118  returnValue.push_back("RnrChildren");
119  returnValue.push_back("Material");
120  return returnValue;
121 }
122 
123 const std::string FWGeometryTableManagerBase::title() const { return "Geometry"; }
124 
126  if (iToWhite) {
127  m_renderer.setGraphicsContext(&TGFrame::GetBlackGC());
128  } else {
129  m_renderer.setGraphicsContext(&TGFrame::GetWhiteGC());
130  }
131  m_renderer.setBlackIcon(iToWhite);
132 }
133 
134 //______________________________________________________________________________
136  if (row == -1)
137  return false;
138 
139  int idx = rowToIndex()[row];
140  // printf("click %s \n", m_entries[idx].name());
141 
142  int off = 0;
143  if (idx >= 0)
144  off = (m_entries[idx].m_level - m_levelOffset) * 20;
145 
146  // printf("compare %d %d level %d\n" , xPos, off, idx);
147  if (xPos > off && xPos < (off + 20)) {
148  m_entries[idx].switchBit(kExpanded);
149 
151  dataChanged();
153  return false;
154  }
155 
156  return true;
157 }
158 
159 //______________________________________________________________________________
160 
161 void FWGeometryTableManagerBase::getNodeMatrix(const NodeInfo& data, TGeoHMatrix& mtx) const {
162  // utility used by browser and FWGeoNode
163  // printf("================ FWGeometryTableManagerBase::getNodeMatri \n");
164  int pIdx = data.m_parent;
165 
166  while (pIdx > 0) {
167  // printf("%s [%d]\n",m_entries.at(pIdx).name(), m_entries.at(pIdx).m_level );
168  mtx.MultiplyLeft(m_entries.at(pIdx).m_node->GetMatrix());
169  pIdx = m_entries.at(pIdx).m_parent;
170  }
171 
172  // printf("right %s [%d]\n",data.name(), data.m_level );
173  mtx.Multiply(data.m_node->GetMatrix());
174 }
175 
176 //______________________________________________________________________________
178  // std::cerr << "GeometryTableManagerBase::redrawTable ------------------------------------- \n";
179  if (m_entries.empty())
180  return;
181 
182  // if (setExpand) checkExpandLevel();
183 
185 
186  dataChanged();
188 }
189 
190 //______________________________________________________________________________
191 
193  std::vector<std::string> relPath;
194  while (idx >= 0) {
195  relPath.push_back(m_entries[idx].name());
196  // printf("push %s \n",m_entries[idx].name() );
197  idx = m_entries[idx].m_parent;
198  }
199 
200  size_t ns = relPath.size();
201  for (size_t i = 1; i < ns; ++i) {
202  path += "/";
203  path += relPath[ns - i - 1];
204  // printf("push_back add to path %s\n", path.c_str());
205  }
206 }
207 
208 //______________________________________________________________________________
209 
211  m_editor = editor;
213 }
214 
216  m_editTransparencyIdx = row;
217  m_editor->UnmapWindow();
218  m_editor->SetText(Form("%d", 100 - m_entries[row].m_transparency));
219  m_editor->Resize(40, 17);
220  m_editor->SetCursorPosition(2);
221  redrawTable();
222 }
223 
225  printf("transparency idx %d opaci %s \n", m_editTransparencyIdx, m_editor->GetText());
226  if (m_editTransparencyIdx >= 0) {
227  using boost::bad_lexical_cast;
228  using boost::lexical_cast;
229  try {
230  int t = lexical_cast<int>(m_editor->GetText());
231  if (t > 100 || t < 0) {
232  fwLog(fwlog::kError) << "Transparency must be set in procentage [0-100].";
233  return;
234  }
235  m_entries[m_editTransparencyIdx].m_transparency = 100 - t;
236  printf("SET !! \n");
237  cancelEditor(true);
238  } catch (bad_lexical_cast&) {
239  fwLog(fwlog::kError) << "Bad Lexical cast. Transparency must be set in procentage [0-100].";
240  }
241  }
242 }
243 
246 
247  if (m_editor->IsMapped()) {
248  m_editor->UnmapWindow();
249  if (redraw)
250  redrawTable();
251  }
252 }
253 
254 //------------------------------------------------------------------------------
255 
257 
258 //------------------------------------------------------------------------------
259 
261 
262 //------------------------------------------------------------------------------
263 
265  TGeoNode* parentNode = m_entries[selectedIdx].m_node;
266  int nD = parentNode->GetNdaughters();
267  int dOff = 0;
268  for (int n = 0; n != nD; ++n) {
269  int idx = selectedIdx + 1 + n + dOff;
271 
272  setVisibility(data, v);
273  setVisibilityChld(data, v);
274 
275  getNNodesTotal(parentNode->GetDaughter(n), dOff);
276  }
277 }
278 
279 //------------------------------------------------------------------------------
280 
282 
283 //------------------------------------------------------------------------------
284 
286 
287 //------------------------------------------------------------------------------
288 
290  NodeInfo& nInfo = m_entries[selectedIdx];
291  TGeoNode* parentNode = nInfo.m_node;
292  int nD = parentNode->GetNdaughters();
293  int dOff = 0;
294  for (int n = 0; n != nD; ++n) {
295  int idx = selectedIdx + 1 + n + dOff;
297 
298  data.copyColorTransparency(nInfo);
299 
300  if (recurse) {
301  applyColorTranspToDaughters(idx, recurse);
302  }
303 
304  getNNodesTotal(parentNode->GetDaughter(n), dOff);
305  }
306 }
307 
308 //------------------------------------------------------------------------------
309 
310 bool FWGeometryTableManagerBase::isNodeRendered(int idx, int topNodeIdx) const {
311  const NodeInfo& data = m_entries[idx];
312  bool foundParent = false;
313 
314  if (data.testBit(kVisNodeSelf)) {
315  int pidx = data.m_parent;
316  while (pidx >= 0) {
317  if (!m_entries[pidx].testBit(kVisNodeChld)) {
318  // printf ("parent disallow not visible !!! \n");
319  return false;
320  }
321 
322  if (pidx == topNodeIdx) {
323  foundParent = true;
324  // printf("parent found \n");
325  break;
326  }
327  pidx = m_entries[pidx].m_parent;
328  }
329 
330  return foundParent;
331  }
332  return false;
333 }
std::vector< std::string > getTitles() const override
returns the title names for each column
bool isNodeRendered(int idx, int top_node_idx) const
bool firstColumnClicked(int row, int xPos)
virtual bool getVisibility(const NodeInfo &nodeInfo) const
#define nullptr
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)
int numberOfRows() const override
Number of rows in the table.
virtual int numberOfColumns() const =0
Number of columns in the table.
void setHighlightContext(const TGGC *context)
virtual void setCellEditor(TGTextEntry *editor)
virtual const std::string title() const
int unsortedRowNumber(int unsorted) const override
when passed the index to the sorted order of the rows it returns the original row number from the und...
void setGraphicsContext(const TGGC *iContext)
void setDaughtersSelfVisibility(bool)
virtual void setVisibility(NodeInfo &, bool)
static void getNNodesTotal(TGeoNode *geoNode, int &off)
void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) override
#define fwLog(_level_)
Definition: fwLog.h:45
UInt_t height() const override
returns the minimum height of the cell to which the renderer is representing
void setCellValueEditor(TGTextEntry *editor)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
void visualPropertiesChanged()
Classes which inherit from FWTableManagerBase must call this when how the data is shown (e...
static const int kTextBuffer
void redrawTable(bool setExpand=false)