CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Fireworks/Core/interface/FWGeometryTableManager.h

Go to the documentation of this file.
00001 #ifndef Fireworks_Core_FWGeometryTableManager_h
00002 #define Fireworks_Core_FWGeometryTableManager_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Core
00006 // Class  :     FWGeometryTableManager
00007 // 
00016 //
00017 // Original Author:  Alja Mrak-Tadel, Matevz Tadel
00018 //         Created:  Thu Jan 27 14:50:40 CET 2011
00019 // $Id: FWGeometryTableManager.h,v 1.6 2011/02/14 20:02:51 amraktad Exp $
00020 //
00021 
00022 #include <sigc++/sigc++.h>
00023 #include <boost/tr1/unordered_map.hpp>
00024 
00025 #include "Fireworks/TableWidget/interface/FWTableManagerBase.h"
00026 #include "Fireworks/TableWidget/interface/FWTextTreeCellRenderer.h"
00027 
00028 #include "Fireworks/TableWidget/interface/FWTextTableCellRenderer.h"
00029 #include "Fireworks/TableWidget/interface/FWTableCellRendererBase.h"
00030 
00031 #include "TGeoNode.h"
00032 
00033 class FWTableCellRendererBase;
00034 class FWGeometryBrowser;
00035 
00036 class TGeoManager;
00037 class TGeoNode;
00038 
00039 class FWGeometryTableManager : public FWTableManagerBase
00040 {
00041 private:
00042    struct NodeInfo
00043    {
00044       NodeInfo():m_node(0), m_parent(-1), m_level(-1), 
00045                  m_imported(false), m_visible(false), m_expanded(false)
00046       {}  
00047 
00048       TGeoNode*   m_node;
00049       Int_t       m_parent;
00050       Short_t     m_level;
00051 
00052       Bool_t      m_imported;
00053       Bool_t      m_visible;
00054       Bool_t      m_expanded;
00055 
00056       const char* name() const;
00057    };
00058    
00059    struct Match
00060    {
00061       bool m_matches;
00062       bool m_childMatches;
00063       
00064       Match() : m_matches(true), m_childMatches(true) {}
00065    
00066       bool accepted() { return m_matches || m_childMatches; }
00067    };
00068 
00069    
00070    // AMT: this could be a common base class with FWCollectionSummaryModelCellRenderer ..
00071    class ColorBoxRenderer : public FWTableCellRendererBase
00072    { 
00073    public:
00074       ColorBoxRenderer();
00075       virtual ~ColorBoxRenderer();
00076   
00077       virtual UInt_t width() const { return m_width; }
00078       virtual UInt_t height() const { return m_height; }
00079       void setData(Color_t c, bool);
00080       virtual void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight);
00081 
00082       UInt_t  m_width;
00083       UInt_t  m_height;
00084       Pixel_t m_color;      
00085       bool    m_isSelected;
00086       TGGC*   m_colorContext;
00087 
00088    };
00089 
00090 public:
00091    FWGeometryTableManager(FWGeometryBrowser*);
00092    virtual ~FWGeometryTableManager();
00093    
00094    void firstColumnClicked(int row);
00095 
00096    // virtual functions of FWTableManagerBase
00097    
00098    virtual int unsortedRowNumber(int unsorted) const;
00099    virtual int numberOfRows() const;
00100    virtual int numberOfColumns() const;
00101    virtual std::vector<std::string> getTitles() const;
00102    virtual FWTableCellRendererBase* cellRenderer(int iSortedRowNumber, int iCol) const;
00103 
00104    virtual const std::string title() const;
00105 
00106    int selectedRow() const;
00107    int selectedColumn() const;
00108    virtual bool rowIsSelected(int row) const;
00109 
00110    std::vector<int> rowToIndex() { return m_row_to_index; }
00111 
00112    void setSelection(int row, int column, int mask); 
00113    virtual void implSort(int, bool) {}
00114    
00115    void loadGeometry(TGeoManager* geoManager);
00116 
00117 private:
00118    enum   ECol { kName, kColor,  kVisSelf, kVisChild, kMaterial, kPosition, kBBoxSize, kNumCol };
00119 
00120    FWGeometryTableManager(const FWGeometryTableManager&); // stop default
00121    const FWGeometryTableManager& operator=(const FWGeometryTableManager&); // stop default
00122 
00123    // table mng
00124    void changeSelection(int iRow, int iColumn);
00125    void redrawTable();
00126    void recalculateVisibility();
00127    
00128    // geo
00129    void checkUniqueVolume(TGeoVolume* v); 
00130    // void checkChildMatches(TGeoVolume* v, bool& res);
00131    void checkChildMatches(TGeoVolume* v,  std::vector<TGeoVolume*>&);
00132    int  getNdaughtersLimited(TGeoNode*) const;
00133    void getNNodesTotal(TGeoNode* geoNode, int level,int& off, bool debug) const;
00134    void setTableContent();
00135    void importChildren(int parent_idx, bool recurse);
00136    void checkHierarchy();
00137 
00138    // signal callbacks
00139    void updateMode();
00140    void updateFilter();
00141    void updateAutoExpand();
00142 
00143    bool filterOff() const;
00144    // ---------- member data --------------------------------
00145    typedef std::vector<NodeInfo> Entries_v;
00146    typedef Entries_v::iterator Entries_i;
00147    
00148    typedef boost::unordered_map<TGeoVolume*, Match>  Volumes_t;
00149    typedef Volumes_t::iterator               Volumes_i;
00150    
00151    // table stuff
00152    mutable FWTextTreeCellRenderer m_renderer;  
00153    mutable ColorBoxRenderer       m_colorBoxRenderer;  
00154 
00155    std::vector<int>  m_row_to_index;
00156    int               m_selectedRow;
00157    int               m_selectedColumn;
00158    
00159    // geo stuff
00160    FWGeometryBrowser*   m_browser;
00161    TGeoManager*       m_geoManager;
00162       
00163    mutable Volumes_t  m_volumes;
00164    Entries_v          m_entries;
00165    
00166    // cached values from browser
00167    int               m_autoExpand;
00168    int               m_maxDaughters;
00169    bool              m_modeVolume;
00170 
00171    
00172    sigc::signal<void,int,int> indexSelected_;
00173 };
00174 
00175 //______________________________________________________________________________
00176 inline int
00177 FWGeometryTableManager::getNdaughtersLimited(TGeoNode* geoNode) const
00178 {
00179    // used for debugging of table
00180    return TMath::Min(geoNode->GetNdaughters(), m_maxDaughters);
00181    //return  geoNode->GetNdaughters();
00182 }
00183 
00184 #endif