CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 <functional>
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 #include "TVirtualX.h"
35 #include "TGFrame.h"
36 #include "TEveUtil.h"
37 
38 const char* FWGeometryTableManagerBase::NodeInfo::name() const { return m_node->GetName(); }
39 
41  : FWTableCellRendererBase(), m_width(1), m_height(1), m_color(0xffffff), m_isSelected(false) {
42  GCValues_t gval;
43  gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle | kGCGraphicsExposures;
44  gval.fStipple = gClient->GetResourcePool()->GetCheckeredBitmap();
45  gval.fGraphicsExposures = kFALSE;
46  gval.fBackground = gVirtualX->GetPixel(kGray);
47  m_colorContext = gClient->GetResourcePool()->GetGCPool()->GetGC(&gval, kTRUE);
48 }
49 
51  gClient->GetResourcePool()->GetGCPool()->FreeGC(m_colorContext->GetGC());
52 }
53 
55  m_color = gVirtualX->GetPixel(c);
56  m_isSelected = s;
57 }
58 
60  Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) {
63  iWidth += 2 * FWTabularWidget::kTextBuffer;
64  iHeight += 2 * FWTabularWidget::kTextBuffer;
65 
66  m_colorContext->SetFillStyle(kFillSolid);
67  Pixel_t baq = m_colorContext->GetForeground();
68  m_colorContext->SetForeground(m_color);
69  gVirtualX->FillRectangle(iID, m_colorContext->GetGC(), iX, iY, iWidth, iHeight);
70 
71  if (m_isSelected) {
72  m_colorContext->SetFillStyle(kFillOpaqueStippled);
73  gVirtualX->FillRectangle(iID, m_colorContext->GetGC(), iX, iY, iWidth, iHeight);
74  }
75  m_colorContext->SetForeground(baq);
76 }
77 
78 //==============================================================================
79 //==============================================================================
80 //
81 // class FWGeometryTableManagerBase
82 //
83 //==============================================================================
84 //==============================================================================
85 
90 
91  GCValues_t gval;
92  gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle | kGCGraphicsExposures;
93  gval.fForeground = gVirtualX->GetPixel(kGray); //gClient->GetResourcePool()->GetFrameHiliteColor();
94  gval.fBackground = gVirtualX->GetPixel(kWhite); //gClient->GetResourcePool()->GetFrameBgndColor();
95  gval.fFillStyle = kFillOpaqueStippled; // kFillTiled;
96  gval.fStipple = gClient->GetResourcePool()->GetCheckeredBitmap();
97  gval.fGraphicsExposures = kFALSE;
98  m_highlightContext = gClient->GetGC(&gval, kTRUE);
99 
101 }
102 
104 
105 int FWGeometryTableManagerBase::unsortedRowNumber(int unsorted) const { return unsorted; }
106 
108 
109 std::vector<std::string> FWGeometryTableManagerBase::getTitles() const {
110  std::vector<std::string> returnValue;
111  returnValue.reserve(numberOfColumns());
112 
113  returnValue.push_back("Name");
114  returnValue.push_back("Color");
115  returnValue.push_back("Opcty");
116  returnValue.push_back("RnrSelf");
117  returnValue.push_back("RnrChildren");
118  returnValue.push_back("Material");
119  return returnValue;
120 }
121 
122 const std::string FWGeometryTableManagerBase::title() const { return "Geometry"; }
123 
125  if (iToWhite) {
126  m_renderer.setGraphicsContext(&TGFrame::GetBlackGC());
127  } else {
128  m_renderer.setGraphicsContext(&TGFrame::GetWhiteGC());
129  }
130  m_renderer.setBlackIcon(iToWhite);
131 }
132 
133 //______________________________________________________________________________
135  if (row == -1)
136  return false;
137 
138  int idx = rowToIndex()[row];
139  // printf("click %s \n", m_entries[idx].name());
140 
141  int off = 0;
142  if (idx >= 0)
143  off = (m_entries[idx].m_level - m_levelOffset) * 20;
144 
145  // printf("compare %d %d level %d\n" , xPos, off, idx);
146  if (xPos > off && xPos < (off + 20)) {
147  m_entries[idx].switchBit(kExpanded);
148 
150  dataChanged();
152  return false;
153  }
154 
155  return true;
156 }
157 
158 //______________________________________________________________________________
159 
160 void FWGeometryTableManagerBase::getNodeMatrix(const NodeInfo& data, TGeoHMatrix& mtx) const {
161  // utility used by browser and FWGeoNode
162  // printf("================ FWGeometryTableManagerBase::getNodeMatri \n");
163  int pIdx = data.m_parent;
164 
165  while (pIdx > 0) {
166  // printf("%s [%d]\n",m_entries.at(pIdx).name(), m_entries.at(pIdx).m_level );
167  mtx.MultiplyLeft(m_entries.at(pIdx).m_node->GetMatrix());
168  pIdx = m_entries.at(pIdx).m_parent;
169  }
170 
171  // printf("right %s [%d]\n",data.name(), data.m_level );
172  mtx.Multiply(data.m_node->GetMatrix());
173 }
174 
175 //______________________________________________________________________________
177  // std::cerr << "GeometryTableManagerBase::redrawTable ------------------------------------- \n";
178  if (m_entries.empty())
179  return;
180 
181  // if (setExpand) checkExpandLevel();
182 
184 
185  dataChanged();
187 }
188 
189 //______________________________________________________________________________
190 
192  std::vector<std::string> relPath;
193  while (idx >= 0) {
194  relPath.push_back(m_entries[idx].name());
195  // printf("push %s \n",m_entries[idx].name() );
196  idx = m_entries[idx].m_parent;
197  }
198 
199  size_t ns = relPath.size();
200  for (size_t i = 1; i < ns; ++i) {
201  path += "/";
202  path += relPath[ns - i - 1];
203  // printf("push_back add to path %s\n", path.c_str());
204  }
205 }
206 
207 //______________________________________________________________________________
208 
210  m_editor = editor;
212 }
213 
215  m_editTransparencyIdx = row;
216  m_editor->UnmapWindow();
217  m_editor->SetText(Form("%d", 100 - m_entries[row].m_transparency));
218  m_editor->Resize(40, 17);
219  m_editor->SetCursorPosition(2);
220  redrawTable();
221 }
222 
224  printf("transparency idx %d opaci %s \n", m_editTransparencyIdx, m_editor->GetText());
225  if (m_editTransparencyIdx >= 0) {
226  try {
227  int t = std::stoi(m_editor->GetText());
228  if (t > 100 || t < 0) {
229  fwLog(fwlog::kError) << "Transparency must be set in procentage [0-100].";
230  return;
231  }
232  m_entries[m_editTransparencyIdx].m_transparency = 100 - t;
233  printf("SET !! \n");
234  cancelEditor(true);
235  } catch (const std::exception&) {
236  fwLog(fwlog::kError) << "Bad Lexical cast. Transparency must be set in procentage [0-100].";
237  }
238  }
239 }
240 
243 
244  if (m_editor->IsMapped()) {
245  m_editor->UnmapWindow();
246  if (redraw)
247  redrawTable();
248  }
249 }
250 
251 //------------------------------------------------------------------------------
252 
254 
255 //------------------------------------------------------------------------------
256 
258 
259 //------------------------------------------------------------------------------
260 
262  TGeoNode* parentNode = m_entries[selectedIdx].m_node;
263  int nD = parentNode->GetNdaughters();
264  int dOff = 0;
265  for (int n = 0; n != nD; ++n) {
266  int idx = selectedIdx + 1 + n + dOff;
267  NodeInfo& data = m_entries[idx];
268 
269  setVisibility(data, v);
270  setVisibilityChld(data, v);
271 
272  getNNodesTotal(parentNode->GetDaughter(n), dOff);
273  }
274 }
275 
276 //------------------------------------------------------------------------------
277 
279 
280 //------------------------------------------------------------------------------
281 
283 
284 //------------------------------------------------------------------------------
285 
286 void FWGeometryTableManagerBase::applyColorTranspToDaughters(int selectedIdx, bool recurse) {
287  NodeInfo& nInfo = m_entries[selectedIdx];
288  TGeoNode* parentNode = nInfo.m_node;
289  int nD = parentNode->GetNdaughters();
290  int dOff = 0;
291  for (int n = 0; n != nD; ++n) {
292  int idx = selectedIdx + 1 + n + dOff;
293  NodeInfo& data = m_entries[idx];
294 
295  data.copyColorTransparency(nInfo);
296 
297  if (recurse) {
298  applyColorTranspToDaughters(idx, recurse);
299  }
300 
301  getNNodesTotal(parentNode->GetDaughter(n), dOff);
302  }
303 }
304 
305 //------------------------------------------------------------------------------
306 
307 bool FWGeometryTableManagerBase::isNodeRendered(int idx, int topNodeIdx) const {
308  const NodeInfo& data = m_entries[idx];
309  bool foundParent = false;
310 
311  if (data.testBit(kVisNodeSelf)) {
312  int pidx = data.m_parent;
313  while (pidx >= 0) {
314  if (!m_entries[pidx].testBit(kVisNodeChld)) {
315  // printf ("parent disallow not visible !!! \n");
316  return false;
317  }
318 
319  if (pidx == topNodeIdx) {
320  foundParent = true;
321  // printf("parent found \n");
322  break;
323  }
324  pidx = m_entries[pidx].m_parent;
325  }
326 
327  return foundParent;
328  }
329  return false;
330 }
virtual int numberOfColumns() const =0
Number of columns in the table.
bool isNodeRendered(int idx, int top_node_idx) const
bool firstColumnClicked(int row, int xPos)
const edm::EventSetup & c
virtual bool getVisibility(const NodeInfo &nodeInfo) 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...
virtual void recalculateVisibility()=0
virtual bool getVisibilityChld(const NodeInfo &nodeInfo) const
UInt_t height() const override
returns the minimum height of the cell to which the renderer is representing
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)
printf("params %d %f %f %f\n", minT, eps, errmax, chi2max)
void setHighlightContext(const TGGC *context)
virtual void setCellEditor(TGTextEntry *editor)
virtual const std::string title() const
uint16_t const *__restrict__ x
Definition: gpuClustering.h:39
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
int numberOfRows() const override
Number of rows in the table.
#define fwLog(_level_)
Definition: fwLog.h:45
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)
std::vector< std::string > getTitles() const override
returns the title names for each column