12 #ifndef ROOT7_REveElement_hxx
13 #define ROOT7_REveElement_hxx
35 template<
typename T,
typename SFINAE>
36 struct adl_serializer;
38 template<
template<
typename U,
typename V,
typename... Args>
class ObjectType,
39 template<typename U, typename... Args> class ArrayType,
42 class NumberIntegerType,
43 class NumberUnsignedType,
44 class NumberFloatType,
45 template<typename U> class AllocatorType,
46 template<typename T, typename SFINAE> class JSONSerializer>
49 using json = basic_json<std::map, std::vector, std::string,
50 bool, std::int64_t, std::uint64_t, double,
51 std::allocator, adl_serializer>;
55 namespace Experimental {
71 friend class REveManager;
72 friend class REveScene;
74 REveElement& operator=(
const REveElement&);
77 typedef std::list<REveElement*> List_t;
79 typedef std::set<REveElement*> Set_t;
81 typedef std::list<REveAunt*> AuntList_t;
84 ElementId_t fElementId{0};
87 REveElement *fMother {
nullptr};
88 REveScene *fScene {
nullptr};
89 REveElement *fSelectionMaster {
nullptr};
91 ElementId_t get_mother_id()
const;
92 ElementId_t get_scene_id()
const;
94 void assign_element_id_recurisvely();
95 void assign_scene_recursively(REveScene* s);
102 TClass *fChildClass {
nullptr};
103 REveCompound *fCompound {
nullptr};
104 REveElement *fVizModel {
nullptr};
107 Int_t fDenyDestroy{0};
108 Bool_t fDestroyOnZeroRefCnt{kTRUE};
110 Bool_t fRnrSelf{kTRUE};
111 Bool_t fRnrChildren{kTRUE};
112 Bool_t fCanEditMainColor{kFALSE};
113 Bool_t fCanEditMainTransparency{kFALSE};
114 Bool_t fCanEditMainTrans{kFALSE};
116 Char_t fMainTransparency{0};
117 Color_t fDefaultColor{kPink};
118 Color_t *fMainColorPtr{
nullptr};
119 std::unique_ptr<REveTrans> fMainTrans;
121 void *fUserData{
nullptr};
123 std::unique_ptr<REveRenderData> fRenderData;
125 virtual void PreDeleteElement();
126 virtual void RemoveElementsInternal();
127 virtual void AnnihilateRecursively();
129 static const std::string& ToString(Bool_t b);
132 REveElement(
const std::string &name =
"",
const std::string &title =
"");
133 REveElement(
const REveElement& e);
134 virtual ~REveElement();
136 ElementId_t GetElementId()
const {
return fElementId; }
138 virtual REveElement* CloneElement()
const;
139 virtual REveElement* CloneElementRecurse(Int_t level = 0)
const;
140 virtual void CloneChildrenRecurse(REveElement *dest, Int_t level = 0)
const;
142 std::string GetName()
const {
return fName; }
143 const char* GetCName()
const {
return fName.c_str(); }
144 std::string GetTitle()
const {
return fTitle; }
145 const char* GetCTitle()
const {
return fTitle.c_str(); }
147 virtual std::string GetHighlightTooltip()
const {
return fTitle; }
149 void SetName (
const std::string &name);
150 void SetTitle(
const std::string &title);
151 void SetNameTitle(
const std::string &name,
const std::string &title);
152 virtual void NameTitleChanged();
154 const TString& GetVizTag()
const {
return fVizTag; }
155 void SetVizTag(
const TString& tag) { fVizTag = tag; }
157 REveElement *GetVizModel()
const {
return fVizModel; }
158 void SetVizModel(REveElement* model);
159 Bool_t SetVizModelByTag();
161 Bool_t ApplyVizTag(
const TString& tag,
const TString& fallback_tag=
"");
163 virtual void PropagateVizParamsToProjecteds();
164 virtual void PropagateVizParamsToChildren(REveElement* el =
nullptr);
165 virtual void CopyVizParams(
const REveElement* el);
166 virtual void CopyVizParamsFromDB();
167 void SaveVizParams (std::ostream &out,
const TString &tag,
const TString &var);
168 virtual void WriteVizParams(std::ostream &out,
const TString &var);
170 REveCompound* GetCompound() {
return fCompound; }
171 void SetCompound(REveCompound* c) { fCompound = c; }
173 bool HasScene() {
return fScene !=
nullptr; }
174 bool HasMother() {
return fMother !=
nullptr; }
176 REveScene* GetScene() {
return fScene; }
177 REveElement* GetMother() {
return fMother; }
179 virtual void AddAunt(REveAunt *au);
180 virtual void RemoveAunt(REveAunt *au);
181 virtual void CheckReferenceCount(
const std::string &from =
"<unknown>");
183 AuntList_t &RefAunts() {
return fAunts; }
184 const AuntList_t &RefAunts()
const {
return fAunts; }
185 Int_t NumAunts()
const {
return fAunts.size(); }
186 Bool_t HasAunts()
const {
return !fAunts.empty(); }
188 TClass* GetChildClass()
const {
return fChildClass; }
189 void SetChildClass(TClass* c) { fChildClass = c; }
191 List_t &RefChildren() {
return fChildren; }
192 const List_t &RefChildren()
const {
return fChildren; }
193 Int_t NumChildren()
const {
return fChildren.size(); }
194 Bool_t HasChildren()
const {
return !fChildren.empty(); }
196 Bool_t HasChild(REveElement *el);
197 REveElement *FindChild(
const TString &name,
const TClass *cls =
nullptr);
198 REveElement *FindChild(TPRegexp ®exp,
const TClass *cls =
nullptr);
199 Int_t FindChildren(List_t &matches,
const TString& name,
const TClass *cls =
nullptr);
200 Int_t FindChildren(List_t &matches, TPRegexp& regexp,
const TClass* cls =
nullptr);
201 REveElement *FirstChild()
const;
202 REveElement *LastChild ()
const;
204 void EnableListElements(Bool_t rnr_self = kTRUE, Bool_t rnr_children = kTRUE);
205 void DisableListElements(Bool_t rnr_self = kFALSE, Bool_t rnr_children = kFALSE);
207 Bool_t GetDestroyOnZeroRefCnt()
const;
208 void SetDestroyOnZeroRefCnt(Bool_t d);
210 Int_t GetDenyDestroy()
const;
211 void IncDenyDestroy();
212 void DecDenyDestroy();
218 virtual void ExportToCINT(
const char *var_name);
220 virtual Bool_t AcceptElement(REveElement *el);
222 virtual void AddElement(REveElement *el);
223 virtual void RemoveElement(REveElement *el);
224 virtual void RemoveElementLocal(REveElement *el);
225 virtual void RemoveElements();
226 virtual void RemoveElementsLocal();
228 virtual void AnnihilateElements();
229 virtual void Annihilate();
231 virtual void ProjectChild(REveElement *el, Bool_t same_depth = kTRUE);
232 virtual void ProjectAllChildren(Bool_t same_depth = kTRUE);
234 virtual void Destroy();
235 virtual void DestroyOrWarn();
236 virtual void DestroyElements();
238 virtual Bool_t CanEditElement()
const {
return kTRUE; }
239 virtual Bool_t SingleRnrState()
const {
return kFALSE; }
240 virtual Bool_t GetRnrSelf()
const {
return fRnrSelf; }
241 virtual Bool_t GetRnrChildren()
const {
return fRnrChildren; }
242 virtual Bool_t GetRnrState()
const {
return fRnrSelf && fRnrChildren; }
243 virtual Bool_t GetRnrAnything()
const {
return fRnrSelf || (fRnrChildren && HasChildren()); }
244 virtual Bool_t SetRnrSelf(Bool_t rnr);
245 virtual Bool_t SetRnrChildren(Bool_t rnr);
246 virtual Bool_t SetRnrSelfChildren(Bool_t rnr_self, Bool_t rnr_children);
247 virtual Bool_t SetRnrState(Bool_t rnr);
248 virtual void PropagateRnrStateToProjecteds();
250 void SetupDefaultColorAndTransparency(Color_t col, Bool_t can_edit_color, Bool_t can_edit_transparency);
252 virtual Bool_t CanEditMainColor()
const {
return fCanEditMainColor; }
253 void SetEditMainColor(Bool_t x) { fCanEditMainColor = x; }
254 Color_t *GetMainColorPtr()
const {
return fMainColorPtr; }
255 void SetMainColorPtr(Color_t *colptr) { fMainColorPtr = colptr; }
257 virtual Bool_t HasMainColor()
const {
return fMainColorPtr !=
nullptr; }
258 virtual Color_t GetMainColor()
const {
return fMainColorPtr ? *fMainColorPtr : 0; }
259 virtual void SetMainColor(Color_t color);
260 void SetMainColorPixel(Pixel_t pixel);
261 void SetMainColorRGB(UChar_t r, UChar_t g, UChar_t b);
262 void SetMainColorRGB(Float_t r, Float_t g, Float_t b);
263 virtual void PropagateMainColorToProjecteds(Color_t color, Color_t old_color);
265 virtual Bool_t CanEditMainTransparency()
const {
return fCanEditMainTransparency; }
266 void SetEditMainTransparency(Bool_t x) { fCanEditMainTransparency = x; }
267 virtual Char_t GetMainTransparency()
const {
return fMainTransparency; }
268 virtual void SetMainTransparency(Char_t t);
269 void SetMainAlpha(Float_t alpha);
270 virtual void PropagateMainTransparencyToProjecteds(Char_t t, Char_t old_t);
272 virtual Bool_t CanEditMainTrans()
const {
return fCanEditMainTrans; }
273 virtual Bool_t HasMainTrans()
const {
return fMainTrans.get() !=
nullptr; }
274 virtual REveTrans* PtrMainTrans(Bool_t create=kTRUE);
275 virtual REveTrans& RefMainTrans();
276 virtual void InitMainTrans(Bool_t can_edit=kTRUE);
277 virtual void DestroyMainTrans();
279 virtual void SetTransMatrix(Double_t *carr);
280 virtual void SetTransMatrix(
const TGeoMatrix &mat);
282 virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset);
283 virtual void BuildRenderData();
285 void* GetUserData()
const {
return fUserData; }
286 void SetUserData(
void* ud) { fUserData = ud; }
288 REveRenderData *GetRenderData()
const {
return fRenderData.get(); }
296 enum ECompoundSelectionColorBits
298 kCSCBImplySelectAllChildren = BIT(0),
299 kCSCBTakeMotherAsMaster = BIT(1),
300 kCSCBApplyMainColorToAllChildren = BIT(2),
301 kCSCBApplyMainColorToMatchingChildren = BIT(3),
302 kCSCBApplyMainTransparencyToAllChildren = BIT(4),
303 kCSCBApplyMainTransparencyToMatchingChildren = BIT(5)
313 Short_t fImpliedSelected{0};
318 Bool_t IsPickable()
const {
return fPickable; }
319 void SetPickable(Bool_t p) { fPickable = p; }
320 void SetPickableRecursively(Bool_t p);
322 REveElement* GetSelectionMaster();
323 void SetSelectionMaster(REveElement *el) { fSelectionMaster = el; }
325 virtual void FillImpliedSelectedSet(Set_t& impSelSet);
327 void IncImpliedSelected() { ++fImpliedSelected; }
328 void DecImpliedSelected() { --fImpliedSelected; }
329 int GetImpliedSelected() {
return fImpliedSelected; }
331 void RecheckImpliedSelections();
333 void SetCSCBits(UChar_t f) { fCSCBits |= f; }
334 void ResetCSCBits(UChar_t f) { fCSCBits &= ~f; }
335 Bool_t TestCSCBits(UChar_t f)
const {
return (fCSCBits & f) != 0; }
337 void ResetAllCSCBits() { fCSCBits = 0; }
338 void CSCImplySelectAllChildren() { fCSCBits |= kCSCBImplySelectAllChildren; }
339 void CSCTakeMotherAsMaster() { fCSCBits |= kCSCBTakeMotherAsMaster; }
340 void CSCApplyMainColorToAllChildren() { fCSCBits |= kCSCBApplyMainColorToAllChildren; }
341 void CSCApplyMainColorToMatchingChildren() { fCSCBits |= kCSCBApplyMainColorToMatchingChildren; }
342 void CSCApplyMainTransparencyToAllChildren() { fCSCBits |= kCSCBApplyMainTransparencyToAllChildren; }
343 void CSCApplyMainTransparencyToMatchingChildren() { fCSCBits |= kCSCBApplyMainTransparencyToMatchingChildren; }
351 kCBColorSelection = BIT(0),
352 kCBTransBBox = BIT(1),
353 kCBObjProps = BIT(2),
354 kCBVisibility = BIT(3),
355 kCBElementAdded = BIT(4)
362 UChar_t fChangeBits{0};
363 Char_t fDestructing{kNone};
366 void StampColorSelection() { AddStamp(kCBColorSelection); }
367 void StampTransBBox() { AddStamp(kCBTransBBox); }
368 void StampObjProps() { AddStamp(kCBObjProps); }
369 void StampObjPropsPreChk() {
if ( ! (fChangeBits & kCBObjProps)) AddStamp(kCBObjProps); }
370 void StampVisibility() { AddStamp(kCBVisibility); }
371 void StampElementAdded() { AddStamp(kCBElementAdded); }
373 virtual void AddStamp(UChar_t bits);
374 virtual void ClearStamps() { fChangeBits = 0; }
376 UChar_t GetChangeBits()
const {
return fChangeBits; }
380 void VizDB_Apply(
const std::string& tag);
381 void VizDB_Reapply();
382 void VizDB_UpdateModel(Bool_t update=kTRUE);
383 void VizDB_Insert(
const std::string& tag, Bool_t replace=kTRUE, Bool_t update=kTRUE);
394 virtual ~REveAunt() {}
396 virtual bool HasNiece(REveElement *el)
const = 0;
397 virtual bool HasNieces()
const = 0;
399 virtual bool AcceptNiece(REveElement *) {
return true; }
401 virtual void AddNiece(REveElement *el)
405 AddNieceInternal(el);
407 virtual void AddNieceInternal(REveElement *el) = 0;
409 virtual void RemoveNiece(REveElement *el)
411 RemoveNieceInternal(el);
412 el->RemoveAunt(
this);
414 virtual void RemoveNieceInternal(REveElement *el) = 0;
416 virtual void RemoveNieces() = 0;
424 class REveAuntAsList :
public REveAunt
427 REveElement::List_t fNieces;
430 virtual ~REveAuntAsList()
432 for (
auto &n : fNieces) n->RemoveAunt(
this);
435 bool HasNiece(REveElement *el)
const override
437 return std::find(fNieces.begin(), fNieces.end(), el) != fNieces.end();
440 bool HasNieces()
const override
442 return ! fNieces.empty();
445 void AddNieceInternal(REveElement *el)
override
447 fNieces.push_back(el);
450 void RemoveNieceInternal(REveElement *el)
override
455 void RemoveNieces()
override
457 for (
auto &n : fNieces) n->RemoveAunt(
this);