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