Go to the documentation of this file.00001 #ifndef Fireworks_Core_FWGeometryTableManager_h
00002 #define Fireworks_Core_FWGeometryTableManager_h
00003
00004
00005
00006
00007
00016
00017
00018
00019
00020
00021
00022 #include <sigc++/sigc++.h>
00023 #include <boost/tr1/unordered_map.hpp>
00024
00025 #include "Fireworks/Core/interface/FWGeometryTableView.h"
00026
00027 #include "Fireworks/TableWidget/interface/FWTableManagerBase.h"
00028 #include "Fireworks/TableWidget/interface/FWTextTreeCellRenderer.h"
00029 #include "Fireworks/TableWidget/interface/FWTextTableCellRenderer.h"
00030 #include "Fireworks/TableWidget/interface/FWTableCellRendererBase.h"
00031
00032 #include "TGeoNode.h"
00033 #include "TGeoVolume.h"
00034
00035 class FWTableCellRendererBase;
00036
00037
00038 class TGeoNode;
00039
00040 class FWGeometryTableManager : public FWTableManagerBase
00041 {
00042 friend class FWGeometryTableView;
00043
00044 public:
00045 enum ECol { kName, kColor, kVisSelf, kVisChild, kMaterial, kPosX, kPosY, kPosZ , kNumCol };
00046
00047 enum Bits
00048 {
00049 kExpanded = BIT(0),
00050 kMatches = BIT(1),
00051 kChildMatches = BIT(2),
00052 kFilterCached = BIT(3),
00053
00054 kVisNode = BIT(4),
00055 kVisNodeChld = BIT(5)
00056
00057
00058
00059 };
00060
00061 struct NodeInfo
00062 {
00063 NodeInfo():m_node(0), m_parent(-1), m_color(0), m_level(-1),
00064 m_flags(kVisNode|kVisNodeChld)
00065 {}
00066
00067 TGeoNode* m_node;
00068 Int_t m_parent;
00069 Color_t m_color;
00070 UChar_t m_level;
00071 UChar_t m_flags;
00072
00073 const char* name() const;
00074 const char* nameIndent() const;
00075
00076 void setBit(UChar_t f) { m_flags |= f;}
00077 void resetBit(UChar_t f) { m_flags &= ~f; }
00078 void setBitVal(UChar_t f, bool x) { x ? setBit(f) : resetBit(f);}
00079
00080 bool testBit(UChar_t f) const { return (m_flags & f) == f; }
00081 bool testBitAny(UChar_t f) const { return (m_flags & f) != 0; }
00082
00083 void switchBit(UChar_t f) { testBit(f) ? resetBit(f) : setBit(f); }
00084 };
00085
00086 struct Match
00087 {
00088 bool m_matches;
00089 bool m_childMatches;
00090 Match() : m_matches(false), m_childMatches(false) {}
00091
00092 bool accepted() { return m_matches || m_childMatches; }
00093 };
00094
00095 typedef std::vector<NodeInfo> Entries_v;
00096 typedef Entries_v::iterator Entries_i;
00097
00098 typedef boost::unordered_map<TGeoVolume*, Match> Volumes_t;
00099 typedef Volumes_t::iterator Volumes_i;
00100
00101 private:
00102
00103 class ColorBoxRenderer : public FWTableCellRendererBase
00104 {
00105 public:
00106 ColorBoxRenderer();
00107 virtual ~ColorBoxRenderer();
00108
00109 virtual UInt_t width() const { return m_width; }
00110 virtual UInt_t height() const { return m_height; }
00111 void setData(Color_t c, bool);
00112 virtual void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight);
00113
00114 UInt_t m_width;
00115 UInt_t m_height;
00116 Pixel_t m_color;
00117 bool m_isSelected;
00118 TGGC* m_colorContext;
00119 };
00120
00121 public:
00122 FWGeometryTableManager(FWGeometryTableView*);
00123 virtual ~FWGeometryTableManager();
00124
00125
00126
00127 virtual int unsortedRowNumber(int unsorted) const;
00128 virtual int numberOfRows() const;
00129 virtual int numberOfColumns() const;
00130 virtual std::vector<std::string> getTitles() const;
00131 virtual FWTableCellRendererBase* cellRenderer(int iSortedRowNumber, int iCol) const;
00132
00133 virtual const std::string title() const;
00134
00135 int selectedRow() const;
00136 int selectedColumn() const;
00137 virtual bool rowIsSelected(int row) const;
00138
00139 std::vector<int> rowToIndex() { return m_row_to_index; }
00140
00141 void setSelection(int row, int column, int mask);
00142 virtual void implSort(int, bool) {}
00143
00144 void printChildren(int) const;
00145 bool nodeImported(int idx) const;
00146
00147 Entries_i refSelected();
00148 Entries_v& refEntries() {return m_entries;}
00149
00150 void loadGeometry( TGeoNode* , TObjArray*);
00151 void setBackgroundToWhite(bool);
00152 void getNodePath(int, std::string&) const;
00153
00154 int getLevelOffset() const { return m_levelOffset; }
00155
00156 void assertNodeFilterCache(NodeInfo& data);
00157
00158 void setDaughtersSelfVisibility(bool);
00159
00160 void getNodeMatrix(const NodeInfo& nodeInfo, TGeoHMatrix& mat) const;
00161
00162 void setVisibility(NodeInfo& nodeInfo, bool );
00163 void setVisibilityChld(NodeInfo& nodeInfo, bool);
00164
00165 bool getVisibilityChld(const NodeInfo& nodeInfo) const;
00166 bool getVisibility (const NodeInfo& nodeInfo) const;
00167
00168 static void getNNodesTotal(TGeoNode* geoNode, int& off);
00169
00170 private:
00171 FWGeometryTableManager(const FWGeometryTableManager&);
00172 const FWGeometryTableManager& operator=(const FWGeometryTableManager&);
00173
00174
00175 void firstColumnClicked(int row);
00176
00177
00178 void changeSelection(int iRow, int iColumn);
00179 void redrawTable();
00180
00181 void recalculateVisibility();
00182 void recalculateVisibilityNodeRec(int);
00183 void recalculateVisibilityVolumeRec(int);
00184
00185
00186 void checkChildMatches(TGeoVolume* v, std::vector<TGeoVolume*>&);
00187 void importChildren(int parent_idx);
00188 void checkHierarchy();
00189
00190
00191
00192 void updateFilter();
00193 void checkExpandLevel();
00194 void topGeoNodeChanged(int);
00195 void printMaterials();
00196
00197
00198
00199
00200
00201
00202 mutable FWTextTreeCellRenderer m_renderer;
00203 mutable ColorBoxRenderer m_colorBoxRenderer;
00204
00205 std::vector<int> m_row_to_index;
00206 int m_selectedRow;
00207 int m_selectedIdx;
00208 int m_selectedColumn;
00209
00210
00211 FWGeometryTableView* m_browser;
00212
00213 mutable Volumes_t m_volumes;
00214 Entries_v m_entries;
00215
00216 bool m_filterOff;
00217 int m_numVolumesMatched;
00218
00219 int m_topGeoNodeIdx;
00220 int m_levelOffset;
00221
00222
00223
00224 };
00225
00226
00227
00228 inline void FWGeometryTableManager::getNNodesTotal(TGeoNode* geoNode, int& off)
00229 {
00230 int nD = geoNode->GetNdaughters();
00231 off += nD;
00232 for (int i = 0; i < nD; ++i )
00233 {
00234 getNNodesTotal(geoNode->GetDaughter(i), off);
00235 }
00236 }
00237
00238 #endif