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 <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 #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);
274 
275  getNNodesTotal(parentNode->GetDaughter(n), dOff);
276  }
277 }
278 
279 //------------------------------------------------------------------------------
280 
282 
283 //------------------------------------------------------------------------------
284 
286 
287 //------------------------------------------------------------------------------
288 
289 void FWGeometryTableManagerBase::applyColorTranspToDaughters(int selectedIdx, bool recurse) {
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) {
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 }
FWGeometryTableManagerBase::m_editor
TGTextEntry * m_editor
Definition: FWGeometryTableManagerBase.h:200
FWGeometryTableManagerBase::kExpanded
Definition: FWGeometryTableManagerBase.h:43
fwLog
#define fwLog(_level_)
Definition: fwLog.h:45
FWGeometryTableManagerBase::recalculateVisibility
virtual void recalculateVisibility()=0
mps_fire.i
i
Definition: mps_fire.py:428
funct::false
false
Definition: Factorize.h:29
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
FWGeometryTableManagerBase::m_entries
Entries_v m_entries
Definition: FWGeometryTableManagerBase.h:196
FWGeometryTableManagerBase::~FWGeometryTableManagerBase
~FWGeometryTableManagerBase() override
Definition: FWGeometryTableManagerBase.cc:104
FWGeometryTableManagerBase::ColorBoxRenderer::m_colorContext
TGGC * m_colorContext
Definition: FWGeometryTableManagerBase.h:108
FWGeometryTableManagerBase::showEditor
void showEditor(int)
Definition: FWGeometryTableManagerBase.cc:215
FWGeometryTableManagerBase::firstColumnClicked
bool firstColumnClicked(int row, int xPos)
Definition: FWGeometryTableManagerBase.cc:135
FWGeometryTableManagerBase::m_highlightContext
TGGC * m_highlightContext
Definition: FWGeometryTableManagerBase.h:190
FWGeometryTableManagerBase::cancelEditor
void cancelEditor(bool)
Definition: FWGeometryTableManagerBase.cc:244
FWGeometryTableManagerBase::ColorBoxRenderer::draw
void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) override
Definition: FWGeometryTableManagerBase.cc:60
DDAxes::x
findQualityFiles.v
v
Definition: findQualityFiles.py:179
FWGeometryTableManagerBase.h
FWGeometryTableManagerBase::rowToIndex
std::vector< int > rowToIndex()
Definition: FWGeometryTableManagerBase.h:133
FWTableManagerBase::visualPropertiesChanged
void visualPropertiesChanged()
Classes which inherit from FWTableManagerBase must call this when how the data is shown (e....
Definition: FWTableManagerBase.cc:70
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
FWTabularWidget::kTextBuffer
static const int kTextBuffer
Definition: FWTabularWidget.h:35
FWTextTableCellRenderer::setHighlightContext
void setHighlightContext(const TGGC *context)
Definition: FWTextTableCellRenderer.h:58
alignCSCRings.s
s
Definition: alignCSCRings.py:92
FWGeometryTableManagerBase::getNodePath
void getNodePath(int, std::string &) const
Definition: FWGeometryTableManagerBase.cc:192
FWGeometryTableManagerBase::NodeInfo::m_node
TGeoNode * m_node
Definition: FWGeometryTableManagerBase.h:58
FWGeometryTableManagerBase::getNNodesTotal
static void getNNodesTotal(TGeoNode *geoNode, int &off)
Definition: FWGeometryTableManagerBase.h:204
FWGeometryTableManagerBase::FWGeometryTableManagerBase
FWGeometryTableManagerBase()
Definition: FWGeometryTableManagerBase.cc:87
FWTextTableCellRenderer::height
UInt_t height() const override
returns the minimum height of the cell to which the renderer is representing
Definition: FWTextTableCellRenderer.cc:119
FWGeometryTableManagerBase::title
virtual const std::string title() const
Definition: FWGeometryTableManagerBase.cc:123
FWGeometryTableManagerBase::unsortedRowNumber
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...
Definition: FWGeometryTableManagerBase.cc:106
FWGeometryTableManagerBase::applyColorTranspToDaughters
virtual void applyColorTranspToDaughters(int selectedIdx, bool recurse)
Definition: FWGeometryTableManagerBase.cc:289
FWGeometryTableManagerBase::m_editTransparencyIdx
int m_editTransparencyIdx
Definition: FWGeometryTableManagerBase.h:201
FWGeometryTableManagerBase::isNodeRendered
bool isNodeRendered(int idx, int top_node_idx) const
Definition: FWGeometryTableManagerBase.cc:310
FWGeometryTableManagerBase::ColorBoxRenderer::setData
void setData(Color_t c, bool)
Definition: FWGeometryTableManagerBase.cc:55
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FWGeometryTableManagerBase::ColorBoxRenderer::ColorBoxRenderer
ColorBoxRenderer()
Definition: FWGeometryTableManagerBase.cc:41
FWTextTableCellRenderer::setGraphicsContext
void setGraphicsContext(const TGGC *iContext)
Definition: FWTextTableCellRenderer.h:57
FWTableManagerBase::dataChanged
void dataChanged()
Classes which inherit from FWTableManagerBase must call this when their underlying data changes.
Definition: FWTableManagerBase.cc:63
FWGeometryTableManagerBase::setVisibilityChld
virtual void setVisibilityChld(NodeInfo &, bool)
Definition: FWGeometryTableManagerBase.cc:260
FWGeometryTableManagerBase::m_levelOffset
int m_levelOffset
Definition: FWGeometryTableManagerBase.h:198
FWGeometryTableManagerBase::setBackgroundToWhite
void setBackgroundToWhite(bool)
Definition: FWGeometryTableManagerBase.cc:125
FWGeometryTableManagerBase::getNodeMatrix
void getNodeMatrix(const NodeInfo &nodeInfo, TGeoHMatrix &mat) const
Definition: FWGeometryTableManagerBase.cc:161
FWTabularWidget.h
FWTableManagerBase::numberOfColumns
virtual int numberOfColumns() const =0
Number of columns in the table.
FWGeometryTableManagerBase::getVisibilityChld
virtual bool getVisibilityChld(const NodeInfo &nodeInfo) const
Definition: FWGeometryTableManagerBase.cc:285
FWGeometryTableManagerBase::kVisNodeSelf
Definition: FWGeometryTableManagerBase.h:45
FWGeometryTableManagerBase::setDaughtersSelfVisibility
void setDaughtersSelfVisibility(bool)
FWGeometryTableManagerBase::NodeInfo::name
const char * name() const
Definition: FWGeometryTableManagerBase.cc:39
FWTableCellRendererBase
Definition: FWTableCellRendererBase.h:44
fwLog.h
FWGeometryTableManagerBase::applyTransparencyFromEditor
void applyTransparencyFromEditor()
Definition: FWGeometryTableManagerBase.cc:224
FWGeometryTableManagerBase::m_highlightIdx
int m_highlightIdx
Definition: FWGeometryTableManagerBase.h:90
FWGeometryTableManagerBase::NodeInfo
Definition: FWGeometryTableManagerBase.h:52
FWColorBoxIcon.h
FWTextTreeCellRenderer::setBlackIcon
void setBlackIcon(bool value)
Definition: FWTextTreeCellRenderer.h:66
FWGeometryTableManagerBase::setCellValueEditor
void setCellValueEditor(TGTextEntry *editor)
Definition: FWGeometryTableManagerBase.cc:210
FWGeometryTableManagerBase::setVisibility
virtual void setVisibility(NodeInfo &, bool)
Definition: FWGeometryTableManagerBase.cc:256
GlobalContexts.h
FWGeometryTableManagerBase::ColorBoxRenderer::~ColorBoxRenderer
~ColorBoxRenderer() override
Definition: FWGeometryTableManagerBase.cc:51
FWGeometryTableManagerBase::redrawTable
void redrawTable(bool setExpand=false)
Definition: FWGeometryTableManagerBase.cc:177
genVertex_cff.x
x
Definition: genVertex_cff.py:12
FWGeometryTableManagerBase::numberOfRows
int numberOfRows() const override
Number of rows in the table.
Definition: FWGeometryTableManagerBase.cc:108
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
FWTextTreeCellRenderer::setCellEditor
virtual void setCellEditor(TGTextEntry *editor)
Definition: FWTextTreeCellRenderer.h:61
fwlog::kError
Definition: fwLog.h:35
FWGeometryTableManagerBase::m_row_to_index
std::vector< int > m_row_to_index
Definition: FWGeometryTableManagerBase.h:194
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
FWGeometryTableManagerBase::m_renderer
FWTextTreeCellRenderer m_renderer
Definition: FWGeometryTableManagerBase.h:191
FWGeometryTableManagerBase::kVisNodeChld
Definition: FWGeometryTableManagerBase.h:46
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
FWGeometryTableManagerBase::getTitles
std::vector< std::string > getTitles() const override
returns the title names for each column
Definition: FWGeometryTableManagerBase.cc:110
FWGeometryTableManagerBase::ColorBoxRenderer::m_height
UInt_t m_height
Definition: FWGeometryTableManagerBase.h:105
FWGeometryTableManagerBase::ColorBoxRenderer::m_width
UInt_t m_width
Definition: FWGeometryTableManagerBase.h:104
FWGeometryTableManagerBase::m_colorBoxRenderer
ColorBoxRenderer m_colorBoxRenderer
Definition: FWGeometryTableManagerBase.h:192
FWGeometryTableManagerBase::getVisibility
virtual bool getVisibility(const NodeInfo &nodeInfo) const
Definition: FWGeometryTableManagerBase.cc:281