File indexing completed on 2025-01-18 10:10:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT7_REveElement_hxx
0013 #define ROOT7_REveElement_hxx
0014
0015 #include <ROOT/REveTypes.hxx>
0016 #include <ROOT/REveVector.hxx>
0017 #include <ROOT/REveProjectionBases.hxx>
0018
0019 #include <memory>
0020 #include <list>
0021 #include <ostream>
0022 #include <set>
0023 #include <string>
0024
0025 #include <nlohmann/json.hpp>
0026
0027 class TGeoMatrix;
0028
0029 namespace ROOT {
0030 namespace Experimental {
0031
0032 class REveAunt;
0033 class REveScene;
0034 class REveCompound;
0035 class REveTrans;
0036 class REveRenderData;
0037
0038
0039
0040
0041
0042
0043
0044 class REveElement
0045 {
0046 friend class REveManager;
0047 friend class REveScene;
0048
0049 REveElement& operator=(const REveElement&) = delete;
0050
0051 public:
0052 typedef std::list<REveElement*> List_t;
0053
0054 typedef std::set<REveElement*> Set_t;
0055
0056 typedef std::list<REveAunt*> AuntList_t;
0057
0058 private:
0059 ElementId_t fElementId{0};
0060
0061 protected:
0062 REveElement *fMother {nullptr};
0063 REveScene *fScene {nullptr};
0064 REveElement *fSelectionMaster {nullptr};
0065
0066 ElementId_t get_mother_id() const;
0067 ElementId_t get_scene_id() const;
0068
0069 void assign_element_id_recurisvely();
0070 void assign_scene_recursively(REveScene* s);
0071
0072 protected:
0073 std::string fName;
0074 std::string fTitle;
0075 AuntList_t fAunts;
0076 List_t fChildren;
0077 TClass *fChildClass {nullptr};
0078 REveCompound *fCompound {nullptr};
0079 REveElement *fVizModel {nullptr};
0080 TString fVizTag;
0081
0082 Int_t fDenyDestroy{0};
0083 Bool_t fDestroyOnZeroRefCnt{kTRUE};
0084
0085 Bool_t fRnrSelf{kTRUE};
0086 Bool_t fRnrChildren{kTRUE};
0087 Bool_t fCanEditMainColor{kFALSE};
0088 Bool_t fCanEditMainTransparency{kFALSE};
0089 Bool_t fCanEditMainTrans{kFALSE};
0090
0091 Char_t fMainTransparency{0};
0092 Color_t fDefaultColor{kPink};
0093 Color_t *fMainColorPtr{nullptr};
0094 std::unique_ptr<REveTrans> fMainTrans;
0095
0096 void *fUserData{nullptr};
0097
0098 std::unique_ptr<REveRenderData> fRenderData;
0099
0100 virtual void PreDeleteElement();
0101 virtual void RemoveElementsInternal();
0102 virtual void AnnihilateRecursively();
0103
0104 static const std::string& ToString(Bool_t b);
0105
0106 public:
0107 REveElement(const std::string &name = "", const std::string &title = "");
0108 REveElement(const REveElement& e);
0109 virtual ~REveElement();
0110
0111 ElementId_t GetElementId() const { return fElementId; }
0112
0113 virtual REveElement* CloneElement() const;
0114 virtual REveElement* CloneElementRecurse(Int_t level = 0) const;
0115 virtual void CloneChildrenRecurse(REveElement *dest, Int_t level = 0) const;
0116
0117 const std::string &GetName() const { return fName; }
0118 const char* GetCName() const { return fName.c_str(); }
0119 const std::string &GetTitle() const { return fTitle; }
0120 const char* GetCTitle() const { return fTitle.c_str(); }
0121
0122 virtual std::string GetHighlightTooltip(const std::set<int>&) const;
0123
0124 void SetName (const std::string &name);
0125 void SetTitle(const std::string &title);
0126 void SetNameTitle(const std::string &name, const std::string &title);
0127 virtual void NameTitleChanged();
0128
0129 const TString& GetVizTag() const { return fVizTag; }
0130 void SetVizTag(const TString& tag) { fVizTag = tag; }
0131
0132 REveElement *GetVizModel() const { return fVizModel; }
0133 void SetVizModel(REveElement* model);
0134 Bool_t SetVizModelByTag();
0135
0136 Bool_t ApplyVizTag(const TString& tag, const TString& fallback_tag="");
0137
0138 virtual void PropagateVizParamsToProjecteds();
0139 virtual void PropagateVizParamsToChildren(REveElement* el = nullptr);
0140 virtual void CopyVizParams(const REveElement* el);
0141 virtual void CopyVizParamsFromDB();
0142 void SaveVizParams (std::ostream &out, const TString &tag, const TString &var);
0143 virtual void WriteVizParams(std::ostream &out, const TString &var);
0144
0145 REveCompound* GetCompound() { return fCompound; }
0146 void SetCompound(REveCompound* c) { fCompound = c; }
0147
0148 bool HasScene() { return fScene != nullptr; }
0149 bool HasMother() { return fMother != nullptr; }
0150
0151 REveScene* GetScene() { return fScene; }
0152 REveElement* GetMother() { return fMother; }
0153
0154 virtual void AddAunt(REveAunt *au);
0155 virtual void RemoveAunt(REveAunt *au);
0156 virtual void CheckReferenceCount(const std::string &from = "<unknown>");
0157
0158 AuntList_t &RefAunts() { return fAunts; }
0159 const AuntList_t &RefAunts() const { return fAunts; }
0160 Int_t NumAunts() const { return fAunts.size(); }
0161 Bool_t HasAunts() const { return !fAunts.empty(); }
0162
0163 TClass* GetChildClass() const { return fChildClass; }
0164 void SetChildClass(TClass* c) { fChildClass = c; }
0165
0166 List_t &RefChildren() { return fChildren; }
0167 const List_t &RefChildren() const { return fChildren; }
0168 Int_t NumChildren() const { return fChildren.size(); }
0169 Bool_t HasChildren() const { return !fChildren.empty(); }
0170
0171 Bool_t HasChild(REveElement *el);
0172 REveElement *FindChild(const TString &name, const TClass *cls = nullptr);
0173 REveElement *FindChild(TPRegexp ®exp, const TClass *cls = nullptr);
0174 Int_t FindChildren(List_t &matches, const TString& name, const TClass *cls = nullptr);
0175 Int_t FindChildren(List_t &matches, TPRegexp& regexp, const TClass* cls = nullptr);
0176 REveElement *FirstChild() const;
0177 REveElement *LastChild () const;
0178
0179 void EnableListElements(Bool_t rnr_self = kTRUE, Bool_t rnr_children = kTRUE);
0180 void DisableListElements(Bool_t rnr_self = kFALSE, Bool_t rnr_children = kFALSE);
0181
0182 Bool_t GetDestroyOnZeroRefCnt() const;
0183 void SetDestroyOnZeroRefCnt(Bool_t d);
0184
0185 Int_t GetDenyDestroy() const;
0186 void IncDenyDestroy();
0187 void DecDenyDestroy();
0188
0189
0190
0191 TClass *IsA() const;
0192
0193 virtual void ExportToCINT(const char *var_name);
0194
0195 virtual Bool_t AcceptElement(REveElement *el);
0196
0197 virtual void AddElement(REveElement *el);
0198 virtual void RemoveElement(REveElement *el);
0199 virtual void RemoveElementLocal(REveElement *el);
0200 virtual void RemoveElements();
0201 virtual void RemoveElementsLocal();
0202
0203 virtual void AnnihilateElements();
0204 virtual void Annihilate();
0205
0206 virtual void ProjectChild(REveElement *el, Bool_t same_depth = kTRUE);
0207 virtual void ProjectAllChildren(Bool_t same_depth = kTRUE);
0208
0209 virtual void Destroy();
0210 virtual void DestroyOrWarn();
0211 virtual void DestroyElements();
0212
0213 virtual Bool_t CanEditElement() const { return kTRUE; }
0214 virtual Bool_t SingleRnrState() const { return kFALSE; }
0215 virtual Bool_t GetRnrSelf() const { return fRnrSelf; }
0216 virtual Bool_t GetRnrChildren() const { return fRnrChildren; }
0217 virtual Bool_t GetRnrState() const { return fRnrSelf && fRnrChildren; }
0218 virtual Bool_t GetRnrAnything() const { return fRnrSelf || (fRnrChildren && HasChildren()); }
0219 virtual Bool_t SetRnrSelf(Bool_t rnr);
0220 virtual Bool_t SetRnrChildren(Bool_t rnr);
0221 virtual Bool_t SetRnrSelfChildren(Bool_t rnr_self, Bool_t rnr_children);
0222 virtual Bool_t SetRnrState(Bool_t rnr);
0223 virtual void PropagateRnrStateToProjecteds();
0224
0225 void SetupDefaultColorAndTransparency(Color_t col, Bool_t can_edit_color, Bool_t can_edit_transparency);
0226
0227 virtual Bool_t CanEditMainColor() const { return fCanEditMainColor; }
0228 void SetEditMainColor(Bool_t x) { fCanEditMainColor = x; }
0229 Color_t *GetMainColorPtr() const { return fMainColorPtr; }
0230 void SetMainColorPtr(Color_t *colptr) { fMainColorPtr = colptr; }
0231
0232 virtual Bool_t HasMainColor() const { return fMainColorPtr != nullptr; }
0233 virtual Color_t GetMainColor() const { return fMainColorPtr ? *fMainColorPtr : 0; }
0234 virtual void SetMainColor(Color_t color);
0235 void SetMainColorPixel(Pixel_t pixel);
0236 void SetMainColorRGB(UChar_t r, UChar_t g, UChar_t b);
0237 void SetMainColorRGB(Float_t r, Float_t g, Float_t b);
0238 virtual void PropagateMainColorToProjecteds(Color_t color, Color_t old_color);
0239
0240 virtual Bool_t CanEditMainTransparency() const { return fCanEditMainTransparency; }
0241 void SetEditMainTransparency(Bool_t x) { fCanEditMainTransparency = x; }
0242 virtual Char_t GetMainTransparency() const { return fMainTransparency; }
0243 virtual void SetMainTransparency(Char_t t);
0244 void SetMainAlpha(Float_t alpha);
0245 virtual void PropagateMainTransparencyToProjecteds(Char_t t, Char_t old_t);
0246
0247 virtual Bool_t CanEditMainTrans() const { return fCanEditMainTrans; }
0248 virtual Bool_t HasMainTrans() const { return fMainTrans.get() != nullptr; }
0249 virtual REveTrans* PtrMainTrans(Bool_t create=kTRUE);
0250 virtual REveTrans& RefMainTrans();
0251 virtual void InitMainTrans(Bool_t can_edit=kTRUE);
0252 virtual void DestroyMainTrans();
0253
0254 virtual void SetTransMatrix(Double_t *carr);
0255 virtual void SetTransMatrix(const TGeoMatrix &mat);
0256
0257 virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset);
0258 virtual void BuildRenderData();
0259
0260 void* GetUserData() const { return fUserData; }
0261 void SetUserData(void* ud) { fUserData = ud; }
0262
0263 REveRenderData *GetRenderData() const { return fRenderData.get(); }
0264
0265
0266
0267
0268
0269 protected:
0270
0271 enum ECompoundSelectionColorBits
0272 {
0273 kCSCBImplySelectAllChildren = BIT(0),
0274 kCSCBTakeMotherAsMaster = BIT(1),
0275 kCSCBApplyMainColorToAllChildren = BIT(2),
0276 kCSCBApplyMainColorToMatchingChildren = BIT(3),
0277 kCSCBApplyMainTransparencyToAllChildren = BIT(4),
0278 kCSCBApplyMainTransparencyToMatchingChildren = BIT(5)
0279 };
0280
0281 enum EDestruct
0282 {
0283 kNone,
0284 kStandard,
0285 kAnnihilate
0286 };
0287
0288 Short_t fImpliedSelected{0};
0289 Bool_t fPickable{false};
0290 UChar_t fCSCBits{0};
0291
0292 public:
0293 Bool_t IsPickable() const { return fPickable; }
0294 void SetPickable(Bool_t p) { fPickable = p; }
0295 void SetPickableRecursively(Bool_t p);
0296
0297 virtual REveElement* GetSelectionMaster();
0298 void SetSelectionMaster(REveElement *el) { fSelectionMaster = el; }
0299
0300 virtual void FillImpliedSelectedSet(Set_t& impSelSet, const std::set<int>&);
0301
0302 void IncImpliedSelected() { ++fImpliedSelected; }
0303 void DecImpliedSelected() { --fImpliedSelected; }
0304 int GetImpliedSelected() { return fImpliedSelected; }
0305
0306 void RecheckImpliedSelections();
0307
0308 void SetCSCBits(UChar_t f) { fCSCBits |= f; }
0309 void ResetCSCBits(UChar_t f) { fCSCBits &= ~f; }
0310 Bool_t TestCSCBits(UChar_t f) const { return (fCSCBits & f) != 0; }
0311
0312 void ResetAllCSCBits() { fCSCBits = 0; }
0313 void CSCImplySelectAllChildren() { fCSCBits |= kCSCBImplySelectAllChildren; }
0314 void CSCTakeMotherAsMaster() { fCSCBits |= kCSCBTakeMotherAsMaster; }
0315 void CSCApplyMainColorToAllChildren() { fCSCBits |= kCSCBApplyMainColorToAllChildren; }
0316 void CSCApplyMainColorToMatchingChildren() { fCSCBits |= kCSCBApplyMainColorToMatchingChildren; }
0317 void CSCApplyMainTransparencyToAllChildren() { fCSCBits |= kCSCBApplyMainTransparencyToAllChildren; }
0318 void CSCApplyMainTransparencyToMatchingChildren() { fCSCBits |= kCSCBApplyMainTransparencyToMatchingChildren; }
0319
0320 virtual bool RequiresExtraSelectionData() const { return false; }
0321 virtual void FillExtraSelectionData(nlohmann::json&, const std::set<int>&) const {}
0322
0323
0324
0325
0326 enum EChangeBits
0327 {
0328 kCBColorSelection = BIT(0),
0329 kCBTransBBox = BIT(1),
0330 kCBObjProps = BIT(2),
0331 kCBVisibility = BIT(3),
0332 kCBElementAdded = BIT(4)
0333
0334
0335
0336 };
0337
0338 protected:
0339 UChar_t fChangeBits{0};
0340 Char_t fDestructing{kNone};
0341
0342 public:
0343 void StampColorSelection() { AddStamp(kCBColorSelection); }
0344 void StampTransBBox() { AddStamp(kCBTransBBox); }
0345 void StampObjProps() { AddStamp(kCBObjProps); }
0346 void StampObjPropsPreChk() { if ( ! (fChangeBits & kCBObjProps)) AddStamp(kCBObjProps); }
0347 void StampVisibility() { AddStamp(kCBVisibility); }
0348 void StampElementAdded() { AddStamp(kCBElementAdded); }
0349
0350 virtual void AddStamp(UChar_t bits);
0351 virtual void ClearStamps() { fChangeBits = 0; }
0352
0353 UChar_t GetChangeBits() const { return fChangeBits; }
0354
0355
0356
0357 void VizDB_Apply(const std::string& tag);
0358 void VizDB_Reapply();
0359 void VizDB_UpdateModel(Bool_t update=kTRUE);
0360 void VizDB_Insert(const std::string& tag, Bool_t replace=kTRUE, Bool_t update=kTRUE);
0361 };
0362
0363
0364
0365
0366
0367
0368 class REveAunt
0369 {
0370 public:
0371 virtual ~REveAunt() {}
0372
0373 virtual bool HasNiece(REveElement *el) const = 0;
0374 virtual bool HasNieces() const = 0;
0375
0376 virtual bool AcceptNiece(REveElement *) { return true; }
0377
0378 virtual void AddNiece(REveElement *el)
0379 {
0380
0381 el->AddAunt(this);
0382 AddNieceInternal(el);
0383 }
0384 virtual void AddNieceInternal(REveElement *el) = 0;
0385
0386 virtual void RemoveNiece(REveElement *el)
0387 {
0388 RemoveNieceInternal(el);
0389 el->RemoveAunt(this);
0390 }
0391 virtual void RemoveNieceInternal(REveElement *el) = 0;
0392
0393 virtual void RemoveNieces() = 0;
0394 };
0395
0396
0397
0398
0399
0400
0401 class REveAuntAsList : public REveAunt
0402 {
0403 protected:
0404 REveElement::List_t fNieces;
0405
0406 public:
0407 ~REveAuntAsList() override
0408 {
0409 for (auto &n : fNieces) n->RemoveAunt(this);
0410 }
0411
0412 bool HasNiece(REveElement *el) const override
0413 {
0414 return std::find(fNieces.begin(), fNieces.end(), el) != fNieces.end();
0415 }
0416
0417 bool HasNieces() const override
0418 {
0419 return ! fNieces.empty();
0420 }
0421
0422 void AddNieceInternal(REveElement *el) override
0423 {
0424 fNieces.push_back(el);
0425 }
0426
0427 void RemoveNieceInternal(REveElement *el) override
0428 {
0429 fNieces.remove(el);
0430 }
0431
0432 void RemoveNieces() override
0433 {
0434 for (auto &n : fNieces) n->RemoveAunt(this);
0435 fNieces.clear();
0436 }
0437 };
0438
0439 }
0440 }
0441
0442 #endif