Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TEveElement.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/eve:$Id$
0002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TEveElement
0013 #define ROOT_TEveElement
0014 
0015 #include "TEveUtil.h"
0016 #include "TEveProjectionBases.h"
0017 
0018 #include "TNamed.h"
0019 #include "TRef.h"
0020 #include <list>
0021 #include <set>
0022 
0023 class TGListTree;
0024 class TGListTreeItem;
0025 class TGPicture;
0026 
0027 class TEveCompound;
0028 class TEveTrans;
0029 class TGeoMatrix;
0030 
0031 /******************************************************************************/
0032 // TEveElement
0033 /******************************************************************************/
0034 
0035 class TEveElement
0036 {
0037    friend class TEveManager;
0038 
0039    TEveElement& operator=(const TEveElement&) = delete;
0040 
0041 public:
0042    class TEveListTreeInfo
0043    {
0044    public:
0045       TGListTree*     fTree;
0046       TGListTreeItem* fItem;
0047 
0048       TEveListTreeInfo() : fTree(nullptr), fItem(nullptr) {}
0049       TEveListTreeInfo(TGListTree* lt, TGListTreeItem* lti) : fTree(lt), fItem(lti) {}
0050       TEveListTreeInfo(const TEveListTreeInfo& l) : fTree(l.fTree), fItem(l.fItem) {}
0051       virtual ~TEveListTreeInfo() {}
0052 
0053       TEveListTreeInfo& operator=(const TEveListTreeInfo& l)
0054       { fTree = l.fTree; fItem = l.fItem; return *this; }
0055 
0056       bool operator==(const TEveListTreeInfo& x) const
0057       { return fTree == x.fTree && fItem == x.fItem; }
0058       bool operator<(const TEveListTreeInfo& x) const
0059       { return fTree == x.fTree ? fItem < x.fItem : fTree < x.fTree; }
0060 
0061       ClassDef(TEveListTreeInfo, 0); // Structure agregating data for a render element image in a list tree.
0062    };
0063 
0064    static const TGPicture*                      fgRnrIcons[4];
0065    static const TGPicture*                      fgListTreeIcons[9];
0066 
0067    typedef std::set<TEveListTreeInfo>           sLTI_t;
0068    typedef sLTI_t::iterator                     sLTI_i;
0069    typedef sLTI_t::reverse_iterator             sLTI_ri;
0070 
0071    typedef std::list<TEveElement*>              List_t;
0072    typedef List_t::iterator                     List_i;
0073    typedef List_t::const_iterator               List_ci;
0074 
0075    typedef std::set<TEveElement*>               Set_t;
0076    typedef Set_t::iterator                      Set_i;
0077    typedef Set_t::const_iterator                Set_ci;
0078 
0079 protected:
0080    List_t           fParents;              //  List of parents.
0081    List_t           fChildren;             //  List of children.
0082    TEveCompound    *fCompound;             //  Compound this object belongs to.
0083    TEveElement     *fVizModel;             //! Element used as model from VizDB.
0084    TString          fVizTag;               //  Tag used to query VizDB for model element.
0085 
0086    Int_t            fNumChildren;          //!
0087    Int_t            fParentIgnoreCnt;      //! Counter for parents that are ignored in ref-counting.
0088    Int_t            fTopItemCnt;           //! Counter for top-level list-tree items that prevent automatic destruction.
0089    Int_t            fDenyDestroy;          //! Deny-destroy count.
0090    Bool_t           fDestroyOnZeroRefCnt;  //  Auto-destruct when ref-count reaches zero.
0091 
0092    Bool_t           fRnrSelf;                 //  Render this element.
0093    Bool_t           fRnrChildren;             //  Render children of this element.
0094    Bool_t           fCanEditMainColor;        //  Allow editing of main color.
0095    Bool_t           fCanEditMainTransparency; //  Allow editing of main transparency.
0096    Bool_t           fCanEditMainTrans;        //  Allow editing of main transformation.
0097 
0098    Char_t           fMainTransparency;     //  Main-transparency variable.
0099    Color_t         *fMainColorPtr;         //  Pointer to main-color variable.
0100    TEveTrans       *fMainTrans;            //  Pointer to main transformation matrix.
0101 
0102    sLTI_t           fItems;                //! Set of list-tree-items.
0103 
0104    TRef             fSource;               //  External object that is represented by this element.
0105    void            *fUserData;             //! Externally assigned and controlled user data.
0106 
0107    virtual void PreDeleteElement();
0108    virtual void RemoveElementsInternal();
0109    virtual void AnnihilateRecursively();
0110 
0111    static const char* ToString(Bool_t b);
0112 
0113 public:
0114    TEveElement();
0115    TEveElement(Color_t& main_color);
0116    TEveElement(const TEveElement& e);
0117    virtual ~TEveElement();
0118 
0119    virtual TEveElement* CloneElement() const;
0120    virtual TEveElement* CloneElementRecurse(Int_t level=0) const;
0121    virtual void         CloneChildrenRecurse(TEveElement* dest, Int_t level=0) const;
0122 
0123    virtual const char* GetElementName()  const;
0124    virtual const char* GetElementTitle() const;
0125    virtual TString     GetHighlightTooltip() { return TString(GetElementTitle()); }
0126    virtual void SetElementName (const char* name);
0127    virtual void SetElementTitle(const char* title);
0128    virtual void SetElementNameTitle(const char* name, const char* title);
0129    virtual void NameTitleChanged();
0130 
0131    const TString& GetVizTag() const             { return fVizTag; }
0132    void           SetVizTag(const TString& tag) { fVizTag = tag;  }
0133 
0134    TEveElement*   GetVizModel() const           { return fVizModel; }
0135    void           SetVizModel(TEveElement* model);
0136    Bool_t         FindVizModel();
0137 
0138    Bool_t         ApplyVizTag(const TString& tag, const TString& fallback_tag="");
0139 
0140    virtual void PropagateVizParamsToProjecteds();
0141    virtual void PropagateVizParamsToElements(TEveElement* el=nullptr);
0142    virtual void CopyVizParams(const TEveElement* el);
0143    virtual void CopyVizParamsFromDB();
0144    void         SaveVizParams (std::ostream& out, const TString& tag, const TString& var);
0145    virtual void WriteVizParams(std::ostream& out, const TString& var);
0146 
0147    TEveElement*  GetMaster();
0148    TEveCompound* GetCompound()                { return fCompound; }
0149    void          SetCompound(TEveCompound* c) { fCompound = c;    }
0150 
0151    virtual void AddParent(TEveElement* re);
0152    virtual void RemoveParent(TEveElement* re);
0153    virtual void CheckReferenceCount(const TEveException& eh="TEveElement::CheckReferenceCount ");
0154    virtual void CollectSceneParents(List_t& scenes);
0155    virtual void CollectSceneParentsFromChildren(List_t& scenes,
0156                                                 TEveElement* parent);
0157 
0158    List_i  BeginParents()        { return  fParents.begin();  }
0159    List_i  EndParents()          { return  fParents.end();    }
0160    List_ci BeginParents()  const { return  fParents.begin();  }
0161    List_ci EndParents()    const { return  fParents.end();    }
0162    Int_t   NumParents()    const { return  fParents.size();   }
0163    Bool_t  HasParents()    const { return !fParents.empty();  }
0164 
0165    const List_t& RefChildren() const { return  fChildren;     }
0166    List_i  BeginChildren()       { return  fChildren.begin(); }
0167    List_i  EndChildren()         { return  fChildren.end();   }
0168    List_ci BeginChildren() const { return  fChildren.begin(); }
0169    List_ci EndChildren()   const { return  fChildren.end();   }
0170    Int_t   NumChildren()   const { return  fNumChildren;      }
0171    Bool_t  HasChildren()   const { return  fNumChildren != 0; }
0172 
0173    Bool_t       HasChild(TEveElement* el);
0174    TEveElement* FindChild(const TString& name, const TClass* cls=nullptr);
0175    TEveElement* FindChild(TPRegexp& regexp, const TClass* cls=nullptr);
0176    Int_t        FindChildren(List_t& matches, const TString&  name, const TClass* cls=nullptr);
0177    Int_t        FindChildren(List_t& matches, TPRegexp& regexp, const TClass* cls=nullptr);
0178    TEveElement* FirstChild() const;
0179    TEveElement* LastChild () const;
0180 
0181    void EnableListElements (Bool_t rnr_self=kTRUE,  Bool_t rnr_children=kTRUE);  // *MENU*
0182    void DisableListElements(Bool_t rnr_self=kFALSE, Bool_t rnr_children=kFALSE); // *MENU*
0183 
0184    Bool_t GetDestroyOnZeroRefCnt() const;
0185    void   SetDestroyOnZeroRefCnt(Bool_t d);
0186 
0187    Int_t  GetDenyDestroy() const;
0188    void   IncDenyDestroy();
0189    void   DecDenyDestroy();
0190 
0191    Int_t  GetParentIgnoreCnt() const;
0192    void   IncParentIgnoreCnt();
0193    void   DecParentIgnoreCnt();
0194 
0195    virtual void PadPaint(Option_t* option);
0196    virtual void PaintStandard(TObject* id);
0197 
0198    virtual TObject* GetObject      (const TEveException& eh) const;
0199    virtual TObject* GetEditorObject(const TEveException& eh) const { return GetObject(eh); }
0200    virtual TObject* GetRenderObject(const TEveException& eh) const { return GetObject(eh); }
0201 
0202    // --------------------------------
0203 
0204    virtual void ExpandIntoListTree(TGListTree* ltree, TGListTreeItem* parent);
0205    virtual void DestroyListSubTree(TGListTree* ltree, TGListTreeItem* parent);
0206 
0207    virtual TGListTreeItem* AddIntoListTree(TGListTree* ltree,
0208                                            TGListTreeItem* parent_lti);
0209    virtual TGListTreeItem* AddIntoListTree(TGListTree* ltree,
0210                                            TEveElement* parent);
0211    virtual TGListTreeItem* AddIntoListTrees(TEveElement* parent);
0212 
0213    virtual Bool_t          RemoveFromListTree(TGListTree* ltree,
0214                                               TGListTreeItem* parent_lti);
0215    virtual Int_t           RemoveFromListTrees(TEveElement* parent);
0216 
0217    virtual sLTI_i          FindItem(TGListTree* ltree);
0218    virtual sLTI_i          FindItem(TGListTree* ltree,
0219                                     TGListTreeItem* parent_lti);
0220    virtual TGListTreeItem* FindListTreeItem(TGListTree* ltree);
0221    virtual TGListTreeItem* FindListTreeItem(TGListTree* ltree,
0222                                             TGListTreeItem* parent_lti);
0223 
0224    virtual Int_t GetNItems() const { return fItems.size(); }
0225 
0226    void         SpawnEditor();                // *MENU*
0227    virtual void ExportToCINT(char* var_name); // *MENU*
0228 
0229    void    DumpSourceObject() const;                       // *MENU*
0230    void    PrintSourceObject() const;                      // *MENU*
0231    void    ExportSourceObjectToCINT(char* var_name) const; // *MENU*
0232 
0233    virtual Bool_t AcceptElement(TEveElement* el);
0234 
0235    virtual void AddElement(TEveElement* el);
0236    virtual void RemoveElement(TEveElement* el);
0237    virtual void RemoveElementLocal(TEveElement* el);
0238    virtual void RemoveElements();
0239    virtual void RemoveElementsLocal();
0240 
0241    virtual void AnnihilateElements();
0242    virtual void Annihilate();
0243 
0244    virtual void ProjectChild(TEveElement* el, Bool_t same_depth=kTRUE);
0245    virtual void ProjectAllChildren(Bool_t same_depth=kTRUE);
0246 
0247    virtual void Destroy();                      // *MENU*
0248    virtual void DestroyOrWarn();
0249    virtual void DestroyElements();              // *MENU*
0250 
0251    virtual Bool_t HandleElementPaste(TEveElement* el);
0252    virtual void   ElementChanged(Bool_t update_scenes=kTRUE, Bool_t redraw=kFALSE);
0253 
0254    virtual Bool_t CanEditElement() const { return kTRUE; }
0255    virtual Bool_t SingleRnrState() const { return kFALSE; }
0256    virtual Bool_t GetRnrSelf()     const { return fRnrSelf; }
0257    virtual Bool_t GetRnrChildren() const { return fRnrChildren; }
0258    virtual Bool_t GetRnrState()    const { return fRnrSelf && fRnrChildren; }
0259    virtual Bool_t GetRnrAnything() const { return fRnrSelf || (fRnrChildren && HasChildren()); }
0260    virtual Bool_t SetRnrSelf(Bool_t rnr);
0261    virtual Bool_t SetRnrChildren(Bool_t rnr);
0262    virtual Bool_t SetRnrSelfChildren(Bool_t rnr_self, Bool_t rnr_children);
0263    virtual Bool_t SetRnrState(Bool_t rnr);
0264    virtual void   PropagateRnrStateToProjecteds();
0265 
0266    virtual Bool_t CanEditMainColor() const   { return fCanEditMainColor; }
0267    void           SetEditMainColor(Bool_t x) { fCanEditMainColor = x; }
0268    Color_t* GetMainColorPtr()        const   { return fMainColorPtr; }
0269    void     SetMainColorPtr(Color_t* color)  { fMainColorPtr = color; }
0270 
0271    virtual Bool_t  HasMainColor() const { return fMainColorPtr != nullptr; }
0272    virtual Color_t GetMainColor() const { return fMainColorPtr ? *fMainColorPtr : 0; }
0273    virtual void    SetMainColor(Color_t color);
0274    void            SetMainColorPixel(Pixel_t pixel);
0275    void            SetMainColorRGB(UChar_t r, UChar_t g, UChar_t b);
0276    void            SetMainColorRGB(Float_t r, Float_t g, Float_t b);
0277    virtual void    PropagateMainColorToProjecteds(Color_t color, Color_t old_color);
0278 
0279    virtual Bool_t  CanEditMainTransparency() const   { return fCanEditMainTransparency; }
0280    void            SetEditMainTransparency(Bool_t x) { fCanEditMainTransparency = x; }
0281    virtual Char_t  GetMainTransparency()     const { return fMainTransparency; }
0282    virtual void    SetMainTransparency(Char_t t);
0283    void            SetMainAlpha(Float_t alpha);
0284    virtual void    PropagateMainTransparencyToProjecteds(Char_t t, Char_t old_t);
0285 
0286    virtual Bool_t     CanEditMainTrans() const { return fCanEditMainTrans; }
0287    virtual Bool_t     HasMainTrans()     const { return fMainTrans != nullptr;   }
0288    virtual TEveTrans* PtrMainTrans(Bool_t create=kTRUE);
0289    virtual TEveTrans& RefMainTrans();
0290    virtual void       InitMainTrans(Bool_t can_edit=kTRUE);
0291    virtual void       DestroyMainTrans();
0292 
0293    virtual void SetTransMatrix(Double_t* carr);
0294    virtual void SetTransMatrix(const TGeoMatrix& mat);
0295 
0296    TRef&    GetSource()                 { return fSource; }
0297    TObject* GetSourceObject()     const { return fSource.GetObject(); }
0298    void     SetSourceObject(TObject* o) { fSource = o; }
0299    /*
0300      void DumpSourceObject();    // *MENU*
0301      void InspectSourceObject(); // *MENU*
0302    */
0303 
0304    void* GetUserData() const { return fUserData; }
0305    void  SetUserData(void* ud) { fUserData = ud; }
0306 
0307 
0308    // Selection state and management
0309    //--------------------------------
0310 
0311 protected:
0312    Bool_t  fPickable;
0313    Bool_t  fSelected;             //!
0314    Bool_t  fHighlighted;          //!
0315    Short_t fImpliedSelected;      //!
0316    Short_t fImpliedHighlighted;   //!
0317 
0318    enum ECompoundSelectionColorBits
0319    {
0320       kCSCBImplySelectAllChildren           = BIT(0), // compound will select all children
0321       kCSCBTakeAnyParentAsMaster            = BIT(1), // element will take any compound parent as master
0322       kCSCBApplyMainColorToAllChildren      = BIT(2), // compound will apply color change to all children
0323       kCSCBApplyMainColorToMatchingChildren = BIT(3), // compound will apply color change to all children with matching color
0324       kCSCBApplyMainTransparencyToAllChildren      = BIT(4), // compound will apply transparency change to all children
0325       kCSCBApplyMainTransparencyToMatchingChildren = BIT(5)  // compound will apply transparency change to all children with matching color
0326    };
0327 
0328    enum EDestruct
0329    {
0330       kNone,
0331       kStandard,
0332       kAnnihilate
0333    };
0334 
0335    UChar_t fCSCBits;
0336 
0337 public:
0338    typedef void (TEveElement::* Select_foo)      (Bool_t);
0339    typedef void (TEveElement::* ImplySelect_foo) ();
0340 
0341    Bool_t IsPickable()    const { return fPickable; }
0342    void   SetPickable(Bool_t p) { fPickable = p; }
0343    void   SetPickableRecursively(Bool_t p);
0344 
0345    virtual TEveElement* ForwardSelection();
0346    virtual TEveElement* ForwardEdit();
0347 
0348    virtual void SelectElement(Bool_t state);
0349    virtual void IncImpliedSelected();
0350    virtual void DecImpliedSelected();
0351    virtual void UnSelected();
0352 
0353    virtual void HighlightElement(Bool_t state);
0354    virtual void IncImpliedHighlighted();
0355    virtual void DecImpliedHighlighted();
0356    virtual void UnHighlighted();
0357 
0358    virtual void FillImpliedSelectedSet(Set_t& impSelSet);
0359 
0360    virtual UChar_t GetSelectedLevel() const;
0361 
0362    void   RecheckImpliedSelections();
0363 
0364    void   SetCSCBits(UChar_t f)   { fCSCBits |=  f; }
0365    void   ResetCSCBits(UChar_t f) { fCSCBits &= ~f; }
0366    Bool_t TestCSCBits(UChar_t f) const { return (fCSCBits & f) != 0; }
0367 
0368    void   ResetAllCSCBits()                     { fCSCBits  =  0; }
0369    void   CSCImplySelectAllChildren()           { fCSCBits |= kCSCBImplySelectAllChildren; }
0370    void   CSCTakeAnyParentAsMaster()            { fCSCBits |= kCSCBTakeAnyParentAsMaster;  }
0371    void   CSCApplyMainColorToAllChildren()      { fCSCBits |= kCSCBApplyMainColorToAllChildren; }
0372    void   CSCApplyMainColorToMatchingChildren() { fCSCBits |= kCSCBApplyMainColorToMatchingChildren; }
0373    void   CSCApplyMainTransparencyToAllChildren()      { fCSCBits |= kCSCBApplyMainTransparencyToAllChildren; }
0374    void   CSCApplyMainTransparencyToMatchingChildren() { fCSCBits |= kCSCBApplyMainTransparencyToMatchingChildren; }
0375 
0376 
0377    // Change-stamping and change bits
0378    //---------------------------------
0379 
0380    enum EChangeBits
0381    {
0382       kCBColorSelection =  BIT(0), // Main color or select/hilite state changed.
0383       kCBTransBBox      =  BIT(1), // Transformation matrix or bounding-box changed.
0384       kCBObjProps       =  BIT(2), // Object changed, requires dropping its display-lists.
0385       kCBVisibility     =  BIT(3)  // Rendering of self/children changed.
0386       // kCBElementAdded   = BIT(), // Element was added to a new parent.
0387       // kCBElementRemoved = BIT()  // Element was removed from a parent.
0388 
0389       // Deletions are handled in a special way in TEveManager::PreDeleteElement().
0390    };
0391 
0392 protected:
0393    UChar_t      fChangeBits;  //!
0394    Char_t       fDestructing; //!
0395 
0396 public:
0397    void StampColorSelection() { AddStamp(kCBColorSelection); }
0398    void StampTransBBox()      { AddStamp(kCBTransBBox); }
0399    void StampObjProps()       { AddStamp(kCBObjProps); }
0400    void StampVisibility()     { AddStamp(kCBVisibility); }
0401    // void StampElementAdded()   { AddStamp(kCBElementAdded); }
0402    // void StampElementRemoved() { AddStamp(kCBElementRemoved); }
0403    virtual void AddStamp(UChar_t bits);
0404    virtual void ClearStamps() { fChangeBits = 0; }
0405 
0406    UChar_t GetChangeBits() const { return fChangeBits; }
0407 
0408 
0409    // List-tree icons
0410    //-----------------
0411 
0412    virtual const TGPicture* GetListTreeIcon(Bool_t open=kFALSE);
0413    virtual const TGPicture* GetListTreeCheckBoxIcon();
0414 
0415    // Menu entries for VizDB communication (here so they are last in the menu).
0416 
0417    void VizDB_Apply(const char* tag);           // *MENU*
0418    void VizDB_Reapply();                        // *MENU*
0419    void VizDB_UpdateModel(Bool_t update=kTRUE); // *MENU*
0420    void VizDB_Insert(const char* tag, Bool_t replace=kTRUE, Bool_t update=kTRUE); // *MENU*
0421 
0422    ClassDef(TEveElement, 0); // Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and list-tree item management.
0423 };
0424 
0425 
0426 /******************************************************************************/
0427 // TEveElementList
0428 /******************************************************************************/
0429 
0430 class TEveElementList : public TEveElement,
0431                         public TNamed,
0432                         public TEveProjectable
0433 {
0434 private:
0435    TEveElementList& operator=(const TEveElementList&); // Not implemented
0436 
0437 protected:
0438    Color_t   fColor;          // Color of the object.
0439    TClass   *fChildClass;     // Class of acceptable children, others are rejected.
0440 
0441 public:
0442    TEveElementList(const char* n="TEveElementList", const char* t="",
0443                    Bool_t doColor=kFALSE, Bool_t doTransparency=kFALSE);
0444    TEveElementList(const TEveElementList& e);
0445    ~TEveElementList() override {}
0446 
0447    TObject* GetObject(const TEveException& /*eh*/="TEveElementList::GetObject ") const override
0448    { const TObject* obj = this; return const_cast<TObject*>(obj); }
0449 
0450    TEveElementList* CloneElement() const override;
0451 
0452    const char* GetElementName()  const override { return GetName();  }
0453    const char* GetElementTitle() const override { return GetTitle(); }
0454 
0455    void SetElementName (const char* name) override
0456    { TNamed::SetName(name); NameTitleChanged(); }
0457 
0458    void SetElementTitle(const char* title) override
0459    { TNamed::SetTitle(title); NameTitleChanged(); }
0460 
0461    void SetElementNameTitle(const char* name, const char* title) override
0462    { TNamed::SetNameTitle(name, title); NameTitleChanged(); }
0463 
0464    TClass* GetChildClass() const { return fChildClass; }
0465    void    SetChildClass(TClass* c) { fChildClass = c; }
0466 
0467    Bool_t  AcceptElement(TEveElement* el) override;
0468 
0469    TClass* ProjectedClass(const TEveProjection* p) const override;
0470 
0471    ClassDefOverride(TEveElementList, 0); // List of TEveElement objects with a possibility to limit the class of accepted elements.
0472 };
0473 
0474 
0475 /******************************************************************************/
0476 // TEveElementListProjected
0477 /******************************************************************************/
0478 
0479 class TEveElementListProjected : public TEveElementList,
0480                                  public TEveProjected
0481 {
0482 private:
0483    TEveElementListProjected(const TEveElementListProjected&);            // Not implemented
0484    TEveElementListProjected& operator=(const TEveElementListProjected&); // Not implemented
0485 
0486 public:
0487    TEveElementListProjected();
0488    ~TEveElementListProjected() override {}
0489 
0490    void UpdateProjection() override;
0491    TEveElement* GetProjectedAsElement() override { return this; }
0492 
0493    ClassDefOverride(TEveElementListProjected, 0); // Projected TEveElementList.
0494 };
0495 
0496 #endif