Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:40

0001 // @(#)root/eve7:$Id$
0002 // Author: Matevz Tadel 2007
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2019, 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 ROOT7_REveSelection
0013 #define ROOT7_REveSelection
0014 
0015 #include <ROOT/REveElement.hxx>
0016 
0017 #include <map>
0018 
0019 namespace ROOT {
0020 namespace Experimental {
0021 
0022 ////////////////////////////////////////////////////////////////////////////////
0023 /// REveSelection
0024 /// Container for selected and highlighted elements.
0025 ////////////////////////////////////////////////////////////////////////////////
0026 
0027 class REveSelection : public REveElement,
0028                       public REveAunt
0029 {
0030    friend class Deviator;
0031 
0032 public:
0033    enum EPickToSelect   // How to convert picking events to top selected element:
0034    { kPS_Ignore,        // ignore picking
0035      kPS_Element,       // select element (default for selection)
0036      kPS_Projectable,   // select projectable
0037      kPS_Compound,      // select compound
0038      kPS_PableCompound, // select projectable and compound
0039      kPS_Master         // select master element (top-level compound)
0040    };
0041 
0042    struct Record
0043    {
0044       REveElement    *f_primary{nullptr}; ///<! it's also implied through the map -- XXXX do i need it ????
0045       Set_t           f_implied;
0046       std::set<int>   f_sec_idcs;
0047       bool            f_is_sec{false};   ///<! is secondary-selected -- XXXX do i need it ????
0048 
0049       Record(REveElement *el) :
0050          f_primary (el),
0051          f_is_sec  (false)
0052       {
0053          // Apparently done in DoElementSelect
0054          // el->FillImpliedSelectedSet(f_implied);
0055       }
0056 
0057       Record(REveElement *el, const std::set<int>& secondary_idcs) :
0058          f_primary  (el),
0059          f_sec_idcs (secondary_idcs),
0060          f_is_sec   (true)
0061       {
0062          // Apparently done in DoElementSelect
0063          // el->FillImpliedSelectedSet(f_implied);
0064       }
0065 
0066       bool is_secondary() const { return f_is_sec; }
0067    };
0068 
0069    class Deviator {
0070     public:
0071       virtual ~Deviator(){};
0072       Deviator() {}
0073       virtual bool DeviateSelection(REveSelection* s, REveElement* el, bool multi, bool secondary, const std::set<int>& secondary_idcs) = 0;
0074    protected:
0075       void ExecuteNewElementPicked(REveSelection* s, REveElement* el, bool multi, bool secondary, const std::set<int>& secondary_idcs)
0076       {
0077          s->NewElementPickedInternal(el, multi, secondary, secondary_idcs);
0078       }
0079    };
0080 
0081    typedef std::map<REveElement*, Record>  SelMap_t;
0082    typedef SelMap_t::iterator              SelMap_i;
0083 
0084 private:
0085    REveSelection(const REveSelection &) = delete;
0086    REveSelection &operator=(const REveSelection &) = delete;
0087 
0088 protected:
0089    Color_t          fVisibleEdgeColor; ///<!
0090    Color_t          fHiddenEdgeColor;  ///<!
0091 
0092    std::vector<int> fPickToSelect;     ///<!
0093    bool             fActive{true};     ///<!
0094    bool             fIsMaster{false};  ///<!
0095    bool             fIsHighlight{false}; ///<!
0096 
0097    SelMap_t         fMap;              ///<!
0098    
0099    std::shared_ptr<Deviator>        fDeviator;///<!
0100 
0101    Record* find_record(REveElement *el)
0102    {
0103       auto i = fMap.find(el);
0104       return i != fMap.end() ? & i->second : nullptr;
0105    }
0106 
0107    void DoElementSelect  (SelMap_i &entry);
0108    void DoElementUnselect(SelMap_i &entry);
0109 
0110    void RecheckImpliedSet(SelMap_i &entry);
0111 
0112    void AddNieceForSelection(REveElement*, bool secondary, const std::set<int>&);
0113 
0114    void NewElementPickedInternal(REveElement* el, bool multi, bool secondary, const std::set<int>& secondary_idcs);
0115 
0116 public:
0117    REveSelection(const std::string &n = "REveSelection", const std::string &t = "",
0118                  Color_t col_visible = kViolet, Color_t col_hidden = kPink);
0119    ~REveSelection() override;
0120 
0121    void   SetVisibleEdgeColorRGB(UChar_t r, UChar_t g, UChar_t b);
0122    void   SetHiddenEdgeColorRGB(UChar_t r, UChar_t g, UChar_t b);
0123 
0124    const std::vector<int>& RefPickToSelect()  const { return fPickToSelect; }
0125    void   ClearPickToSelect()     { fPickToSelect.clear(); }
0126    void   AddPickToSelect(int ps) { fPickToSelect.push_back(ps); }
0127 
0128    bool GetIsMaster() const { return fIsMaster; }
0129    void SetIsMaster(bool m) { fIsMaster = m; }
0130    bool GetIsHighlight() const { return fIsHighlight; }
0131    void SetIsHighlight(bool m) { fIsHighlight = m; }
0132 
0133    std::shared_ptr<Deviator> GetDeviator() const { return fDeviator; }
0134    void   SetDeviator(std::shared_ptr<Deviator> d) { fDeviator = d; }
0135 
0136    bool   IsEmpty()  const { return   fMap.empty(); }
0137    bool   NotEmpty() const { return ! fMap.empty(); }
0138 
0139    // Abstract methods of REveAunt
0140    bool HasNiece(REveElement *el) const override;
0141    bool HasNieces() const override;
0142    bool AcceptNiece(REveElement *el) override;
0143    void AddNieceInternal(REveElement *el) override;
0144    void RemoveNieceInternal(REveElement *el) override;
0145    void RemoveNieces() override;
0146 
0147    void RemoveImpliedSelected(REveElement *el);
0148 
0149    void RecheckImpliedSetForElement(REveElement *el);
0150 
0151    void SelectionAdded(REveElement *el);    // *SIGNAL*
0152    void SelectionRemoved(REveElement *el);  // *SIGNAL*
0153    void SelectionCleared();                 // *SIGNAL*
0154    void SelectionRepeated(REveElement *el); // *SIGNAL*
0155 
0156    // ----------------------------------------------------------------
0157    // Interface to make selection active/non-active.
0158 
0159    virtual void ActivateSelection();
0160    virtual void DeactivateSelection();
0161 
0162    // ----------------------------------------------------------------
0163    // User input processing.
0164 
0165    REveElement *MapPickedToSelected(REveElement *el);
0166 
0167    virtual void UserPickedElement(REveElement *el, Bool_t multi = kFALSE);
0168    virtual void UserRePickedElement(REveElement *el);
0169    virtual void UserUnPickedElement(REveElement *el);
0170 
0171    void NewElementPicked(ElementId_t id, bool multi, bool secondary, const std::set<int>& secondary_idcs={});
0172    void NewElementPickedStr(ElementId_t id, bool multi, bool secondary, const char* secondary_idcs="");
0173    void ClearSelection();
0174 
0175    int  RemoveImpliedSelectedReferencesTo(REveElement *el);
0176 
0177    // ----------------------------------------------------------------
0178 
0179    Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override;
0180 
0181 };
0182 
0183 } // namespace Experimental
0184 } // namespace ROOT
0185 
0186 #endif