36 using namespace ROOT::Experimental;
37 namespace REX = ROOT::Experimental;
51 REveElement::REveElement(
const std::string& name,
const std::string& title) :
70 REveElement::REveElement(
const REveElement& e) :
73 fChildClass (e.fChildClass),
75 fDestroyOnZeroRefCnt (e.fDestroyOnZeroRefCnt),
76 fRnrSelf (e.fRnrSelf),
77 fRnrChildren (e.fRnrChildren),
78 fCanEditMainColor (e.fCanEditMainColor),
79 fCanEditMainTransparency(e.fCanEditMainTransparency),
80 fCanEditMainTrans (e.fCanEditMainTrans),
81 fMainTransparency (e.fMainTransparency),
82 fPickable (e.fPickable),
85 SetVizModel(e.fVizModel);
88 fMainColorPtr = (Color_t*)((
const char*)
this + ((
const char*) e.fMainColorPtr - (
const char*) &e));
90 fMainTrans = std::make_unique<REveTrans>(*e.fMainTrans.get());
98 REveElement::~REveElement()
100 if (fDestructing != kAnnihilate)
102 fDestructing = kStandard;
103 RemoveElementsInternal();
106 fMother->RemoveElementLocal(
this);
107 fMother->fChildren.remove(
this);
111 fScene->SceneElementRemoved( fElementId);
114 for (
auto &au : fAunts)
116 au->RemoveNieceInternal(
this);
121 ElementId_t REveElement::get_mother_id()
const
123 return fMother ? fMother->GetElementId() : 0;
126 ElementId_t REveElement::get_scene_id()
const
128 return fScene ? fScene->GetElementId() : 0;
131 void REveElement::assign_element_id_recurisvely()
133 assert(fElementId == 0);
135 REX::gEve->AssignElementId(
this);
136 for (
auto &c : fChildren)
137 c->assign_element_id_recurisvely();
140 void REveElement::assign_scene_recursively(REveScene* s)
142 assert(fScene ==
nullptr);
148 if (fDestructing == kNone && fScene && fScene->IsAcceptingChanges())
152 for (
auto &c : fChildren)
153 c->assign_scene_recursively(s);
162 void REveElement::PreDeleteElement()
166 REX::gEve->PreDeleteElement(
this);
174 REveElement* REveElement::CloneElement()
const
176 return new REveElement(*
this);
184 REveElement* REveElement::CloneElementRecurse(Int_t level)
const
186 REveElement* el = CloneElement();
189 CloneChildrenRecurse(el, level);
199 void REveElement::CloneChildrenRecurse(REveElement* dest, Int_t level)
const
201 for (
auto &c: fChildren)
202 dest->AddElement(c->CloneElementRecurse(level));
211 void REveElement::SetName(
const std::string& name)
220 void REveElement::SetTitle(
const std::string& title)
232 void REveElement::SetNameTitle(
const std::string& name,
const std::string& title)
244 void REveElement::NameTitleChanged()
255 void REveElement::SetVizModel(REveElement* model)
266 Bool_t REveElement::SetVizModelByTag()
268 REveElement* model = REX::gEve->FindVizDBEntry(fVizTag);
289 Bool_t REveElement::ApplyVizTag(
const TString& tag,
const TString& fallback_tag)
293 if ((model = REX::gEve->FindVizDBEntry(tag)) !=
nullptr)
297 else if ( ! fallback_tag.IsNull() && (model = REX::gEve->FindVizDBEntry(fallback_tag)) !=
nullptr)
299 SetVizTag(fallback_tag);
305 CopyVizParamsFromDB();
308 Warning(
"REveElement::ApplyVizTag",
"entry for tag '%s' not found in VizDB.", tag.Data());
321 void REveElement::PropagateVizParamsToProjecteds()
323 REveProjectable* pable =
dynamic_cast<REveProjectable*
>(
this);
324 if (pable && pable->HasProjecteds())
326 pable->PropagateVizParams();
337 void REveElement::PropagateVizParamsToChildren(REveElement* el)
341 for (
auto &c : fChildren)
343 c->CopyVizParams(el);
352 void REveElement::CopyVizParams(
const REveElement* el)
354 fCanEditMainColor = el->fCanEditMainColor;
355 fCanEditMainTransparency = el->fCanEditMainTransparency;
356 fMainTransparency = el->fMainTransparency;
357 if (fMainColorPtr == & fDefaultColor) fDefaultColor = el->GetMainColor();
359 AddStamp(kCBColorSelection | kCBObjProps);
366 void REveElement::CopyVizParamsFromDB()
370 CopyVizParams(fVizModel);
374 Warning(
"REveElement::CopyVizParamsFromDB",
"VizModel has not been set.");
385 void REveElement::SaveVizParams(std::ostream& out,
const TString& tag,
const TString& var)
387 static const REveException eh(
"REveElement::GetObject ");
390 TString cls(IsA()->GetName());
394 TString intro =
" TAG='" + tag +
"', CLASS='" + cls +
"'";
395 out <<
" //" << intro <<
"\n";
396 out <<
" //" << TString(
'-', intro.Length()) <<
"\n";
397 out << t << cls <<
"* " << var <<
" = new " << cls <<
";\n";
399 WriteVizParams(out, var);
401 out << t <<
"REX::gEve->InsertVizDBEntry(\"" << tag <<
"\", "<< var <<
");\n";
412 void REveElement::WriteVizParams(std::ostream& out,
const TString& var)
414 TString t =
" " + var +
"->";
416 out << t <<
"SetElementName(\"" << fName <<
"\");\n";
417 out << t <<
"SetElementTitle(\"" << fTitle <<
"\");\n";
418 out << t <<
"SetEditMainColor(" << fCanEditMainColor <<
");\n";
419 out << t <<
"SetEditMainTransparency(" << fCanEditMainTransparency <<
");\n";
420 out << t <<
"SetMainTransparency(" << fMainTransparency <<
");\n";
426 void REveElement::VizDB_Apply(
const std::string& tag)
428 if (ApplyVizTag(tag))
430 PropagateVizParamsToProjecteds();
431 REX::gEve->Redraw3D();
439 void REveElement::VizDB_Reapply()
443 CopyVizParamsFromDB();
444 PropagateVizParamsToProjecteds();
445 REX::gEve->Redraw3D();
455 void REveElement::VizDB_UpdateModel(Bool_t update)
459 fVizModel->CopyVizParams(
this);
465 Error(
"VizDB_UpdateModel",
"update from vizdb -> elements not implemented.");
472 Warning(
"VizDB_UpdateModel",
"VizModel has not been set.");
481 void REveElement::VizDB_Insert(
const std::string& tag, Bool_t replace, Bool_t update)
483 static const REveException eh(
"REveElement::GetObject ");
486 REveElement* el =
reinterpret_cast<REveElement*
>(cls->New());
488 Error(
"VizDB_Insert",
"Creation of replica failed.");
491 el->CopyVizParams(
this);
492 Bool_t succ = REX::gEve->InsertVizDBEntry(tag, el, replace, update);
494 REX::gEve->Redraw3D();
503 void REveElement::AddAunt(REveAunt *au)
505 assert(au !=
nullptr);
507 fAunts.emplace_back(au);
515 void REveElement::RemoveAunt(REveAunt *au)
517 assert(au !=
nullptr);
528 void REveElement::CheckReferenceCount(
const std::string& from)
530 if (fDestructing != kNone)
533 if (fMother ==
nullptr && fDestroyOnZeroRefCnt && fDenyDestroy <= 0)
536 Info(
"REveElement::CheckReferenceCount",
"(called from %s) auto-destructing '%s' on zero reference count.",
537 from.c_str(), GetCName());
547 TClass *REveElement::IsA()
const
549 return TClass::GetClass(
typeid(*
this), kTRUE, kTRUE);
555 void REveElement::ExportToCINT(
const char *var_name)
557 const char* cname = IsA()->GetName();
558 gROOT->ProcessLine(TString::Format(
"%s* %s = (%s*)0x%lx;", cname, var_name, cname, (ULong_t)
this));
566 Bool_t REveElement::SetRnrSelf(Bool_t rnr)
568 if (SingleRnrState())
570 return SetRnrState(rnr);
577 PropagateRnrStateToProjecteds();
589 Bool_t REveElement::SetRnrChildren(Bool_t rnr)
591 if (SingleRnrState())
593 return SetRnrState(rnr);
596 if (rnr != fRnrChildren)
600 PropagateRnrStateToProjecteds();
610 Bool_t REveElement::SetRnrSelfChildren(Bool_t rnr_self, Bool_t rnr_children)
612 if (SingleRnrState())
614 return SetRnrState(rnr_self);
617 if (fRnrSelf != rnr_self || fRnrChildren != rnr_children)
620 fRnrChildren = rnr_children;
622 PropagateRnrStateToProjecteds();
633 Bool_t REveElement::SetRnrState(Bool_t rnr)
635 if (fRnrSelf != rnr || fRnrChildren != rnr)
637 fRnrSelf = fRnrChildren = rnr;
639 PropagateRnrStateToProjecteds();
649 void REveElement::PropagateRnrStateToProjecteds()
651 REveProjectable *pable =
dynamic_cast<REveProjectable*
>(
this);
652 if (pable && pable->HasProjecteds())
654 pable->PropagateRenderState(fRnrSelf, fRnrChildren);
662 void REveElement::SetupDefaultColorAndTransparency(Color_t col, Bool_t can_edit_color, Bool_t can_edit_transparency)
664 fMainColorPtr = & fDefaultColor;
666 fCanEditMainColor = can_edit_color;
667 fCanEditMainTransparency = can_edit_transparency;
673 void REveElement::SetMainColor(Color_t color)
675 Color_t old_color = GetMainColor();
679 *fMainColorPtr = color;
680 StampColorSelection();
683 PropagateMainColorToProjecteds(color, old_color);
689 void REveElement::SetMainColorPixel(Pixel_t pixel)
691 SetMainColor(TColor::GetColor(pixel));
697 void REveElement::SetMainColorRGB(UChar_t r, UChar_t g, UChar_t b)
699 SetMainColor(TColor::GetColor(r, g, b));
705 void REveElement::SetMainColorRGB(Float_t r, Float_t g, Float_t b)
707 SetMainColor(TColor::GetColor(r, g, b));
713 void REveElement::PropagateMainColorToProjecteds(Color_t color, Color_t old_color)
715 REveProjectable* pable =
dynamic_cast<REveProjectable*
>(
this);
716 if (pable && pable->HasProjecteds())
718 pable->PropagateMainColor(color, old_color);
726 void REveElement::SetMainTransparency(Char_t t)
728 Char_t old_t = GetMainTransparency();
730 if (t > 100) t = 100;
731 fMainTransparency = t;
732 StampColorSelection();
734 PropagateMainTransparencyToProjecteds(t, old_t);
741 void REveElement::SetMainAlpha(Float_t alpha)
743 if (alpha < 0) alpha = 0;
744 if (alpha > 1) alpha = 1;
745 SetMainTransparency((Char_t) (100.0f*(1.0f - alpha)));
751 void REveElement::PropagateMainTransparencyToProjecteds(Char_t t, Char_t old_t)
753 REveProjectable* pable =
dynamic_cast<REveProjectable*
>(
this);
754 if (pable && pable->HasProjecteds())
756 pable->PropagateMainTransparency(t, old_t);
764 REveTrans *REveElement::PtrMainTrans(Bool_t create)
766 if (!fMainTrans && create)
769 return fMainTrans.get();
776 REveTrans &REveElement::RefMainTrans()
781 return *fMainTrans.get();
789 void REveElement::InitMainTrans(Bool_t can_edit)
792 fMainTrans->UnitTrans();
794 fMainTrans = std::make_unique<REveTrans>();
795 fCanEditMainTrans = can_edit;
802 void REveElement::DestroyMainTrans()
804 fMainTrans.reset(
nullptr);
805 fCanEditMainTrans = kFALSE;
811 void REveElement::SetTransMatrix(Double_t* carr)
813 RefMainTrans().SetFrom(carr);
819 void REveElement::SetTransMatrix(
const TGeoMatrix& mat)
821 RefMainTrans().SetFrom(mat);
830 Bool_t REveElement::AcceptElement(REveElement* el)
834 if (fChildClass && ! el->IsA()->InheritsFrom(fChildClass))
842 void REveElement::AddElement(REveElement *el)
844 static const REveException eh(
"REveElement::AddElement ");
846 if (!el)
throw eh +
"called with nullptr argument.";
847 if ( ! AcceptElement(el))
throw eh + Form(
"parent '%s' rejects '%s'.", GetCName(), el->GetCName());
848 if (el->fElementId)
throw eh +
"element already has an id.";
850 if (el->fMother)
throw eh +
"element already has a Mother.";
857 if (fElementId) el->assign_element_id_recurisvely();
858 if (fScene && ! el->fScene) el->assign_scene_recursively(fScene);
862 fChildren.emplace_back(el);
875 void REveElement::RemoveElement(REveElement* el)
877 static const REveException eh(
"REveElement::RemoveElement ");
879 if (!el)
throw eh +
"called with nullptr argument.";
880 if (el->fMother !=
this)
throw eh +
"this element is not mother of el.";
882 RemoveElementLocal(el);
884 el->fScene->SceneElementRemoved(fElementId);
885 el->fMother =
nullptr;
886 el->fScene =
nullptr;
888 el->CheckReferenceCount();
890 fChildren.remove(el);
908 void REveElement::RemoveElementLocal(REveElement* )
918 void REveElement::RemoveElementsInternal()
920 RemoveElementsLocal();
922 for (
auto &c : fChildren)
924 c->fScene->SceneElementRemoved(c->fElementId);
925 c->fMother =
nullptr;
928 c->CheckReferenceCount();
939 void REveElement::RemoveElements()
943 RemoveElementsInternal();
952 void REveElement::RemoveElementsLocal()
968 void REveElement::ProjectChild(REveElement* el, Bool_t same_depth)
970 REveProjectable* pable =
dynamic_cast<REveProjectable*
>(
this);
971 if (pable && HasChild(el))
973 for (
auto &pp: pable->RefProjecteds())
975 auto pmgr = pp->GetManager();
976 Float_t cd = pmgr->GetCurrentDepth();
977 if (same_depth) pmgr->SetCurrentDepth(pp->GetDepth());
979 pmgr->SubImportElements(el, pp->GetProjectedAsElement());
981 if (same_depth) pmgr->SetCurrentDepth(cd);
998 void REveElement::ProjectAllChildren(Bool_t same_depth)
1000 REveProjectable* pable =
dynamic_cast<REveProjectable*
>(
this);
1003 for (
auto &pp: pable->RefProjecteds())
1005 REveProjectionManager *pmgr = pp->GetManager();
1006 Float_t cd = pmgr->GetCurrentDepth();
1007 if (same_depth) pmgr->SetCurrentDepth(pp->GetDepth());
1009 pmgr->SubImportChildren(
this, pp->GetProjectedAsElement());
1011 if (same_depth) pmgr->SetCurrentDepth(cd);
1019 Bool_t REveElement::HasChild(REveElement* el)
1021 return (std::find(fChildren.begin(), fChildren.end(), el) != fChildren.end());
1030 REveElement *REveElement::FindChild(
const TString& name,
const TClass* cls)
1032 for (
auto &c: fChildren)
1034 if (name.CompareTo(c->GetCName()) == 0)
1036 if (!cls || c->IsA()->InheritsFrom(cls))
1049 REveElement* REveElement::FindChild(TPRegexp ®exp,
const TClass *cls)
1051 for (
auto &c: fChildren)
1053 if (regexp.MatchB(c->GetName()))
1055 if (!cls || c->IsA()->InheritsFrom(cls))
1068 Int_t REveElement::FindChildren(List_t& matches,
1069 const TString& name,
const TClass* cls)
1072 for (
auto &c: fChildren)
1074 if (name.CompareTo(c->GetCName()) == 0)
1076 if (!cls || c->IsA()->InheritsFrom(cls))
1078 matches.push_back(c);
1092 Int_t REveElement::FindChildren(List_t &matches,
1093 TPRegexp ®exp,
const TClass *cls)
1096 for (
auto &c : fChildren)
1098 if (regexp.MatchB(c->GetCName()))
1100 if (!cls || c->IsA()->InheritsFrom(cls))
1102 matches.push_back(c);
1113 REveElement* REveElement::FirstChild()
const
1115 return HasChildren() ? fChildren.front() :
nullptr;
1121 REveElement* REveElement::LastChild ()
const
1123 return HasChildren() ? fChildren.back() :
nullptr;
1130 void REveElement::EnableListElements(Bool_t rnr_self, Bool_t rnr_children)
1132 for (
auto &c: fChildren)
1133 c->SetRnrSelfChildren(rnr_self, rnr_children);
1143 void REveElement::DisableListElements(Bool_t rnr_self, Bool_t rnr_children)
1145 for (
auto &c: fChildren)
1146 c->SetRnrSelfChildren(rnr_self, rnr_children);
1152 void REveElement::AnnihilateRecursively()
1155 REveProjectable* pable =
dynamic_cast<REveProjectable*
>(
this);
1156 if (pable && pable->HasProjecteds())
1157 pable->ClearProjectedList();
1160 RemoveElementsLocal();
1161 for (
auto &c : fChildren)
1162 c->AnnihilateRecursively();
1166 fDestructing = kAnnihilate;
1178 void REveElement::Annihilate()
1180 static const REveException eh(
"REveElement::Annihilate ");
1182 fDestructing = kAnnihilate;
1185 REveProjectable* pable =
dynamic_cast<REveProjectable*
>(
this);
1186 if (pable && pable->HasProjecteds())
1188 pable->AnnihilateProjecteds();
1194 fMother->RemoveElement(
this);
1199 AnnihilateRecursively();
1208 void REveElement::AnnihilateElements()
1210 while (!fChildren.empty())
1212 auto c = fChildren.front();
1223 void REveElement::Destroy()
1225 static const REveException eh(
"REveElement::Destroy ");
1227 if (fDenyDestroy > 0)
1228 throw eh + TString::Format(
"element '%s' (%s*) %p is protected against destruction.",
1229 GetCName(), IsA()->GetName(),
this);
1233 REX::gEve->Redraw3D();
1239 void REveElement::DestroyOrWarn()
1245 catch (REveException &exc)
1247 ::Warning(
"REveElement::DestroyOrWarn",
"Error while destroy element %p : %s",
this, exc.what());
1254 void REveElement::DestroyElements()
1256 while (HasChildren())
1258 auto c = fChildren.front();
1259 if (c->fDenyDestroy <= 0)
1264 catch (REveException &exc) {
1265 ::Warning(
"REveElement::DestroyElements",
"element destruction failed: '%s'.", exc.what());
1272 ::Info(
"REveElement::DestroyElements",
"element '%s' is protected against destruction, removing locally.", c->GetCName());
1277 REX::gEve->Redraw3D();
1285 Bool_t REveElement::GetDestroyOnZeroRefCnt()
const
1287 return fDestroyOnZeroRefCnt;
1295 void REveElement::SetDestroyOnZeroRefCnt(Bool_t d)
1297 fDestroyOnZeroRefCnt = d;
1304 Int_t REveElement::GetDenyDestroy()
const
1306 return fDenyDestroy;
1313 void REveElement::IncDenyDestroy()
1322 void REveElement::DecDenyDestroy()
1324 if (--fDenyDestroy <= 0)
1325 CheckReferenceCount(
"REveElement::DecDenyDestroy ");
1331 void REveElement::SetPickableRecursively(Bool_t p)
1334 for (
auto &c: fChildren)
1335 c->SetPickableRecursively(p);
1345 REveElement *REveElement::GetSelectionMaster()
1347 if (fSelectionMaster)
return fSelectionMaster;
1349 REveProjected* proj =
dynamic_cast<REveProjected*
>(
this);
1352 return dynamic_cast<REveElement*
>(proj->GetProjectable())->GetSelectionMaster();
1356 return fCompound->GetSelectionMaster();
1358 if (TestCSCBits(kCSCBTakeMotherAsMaster) && fMother)
1360 return fMother->GetSelectionMaster();
1375 void REveElement::FillImpliedSelectedSet(Set_t &impSelSet)
1377 REveProjectable* p =
dynamic_cast<REveProjectable*
>(
this);
1379 p->AddProjectedsToSet(impSelSet);
1390 void REveElement::RecheckImpliedSelections()
1415 void REveElement::AddStamp(UChar_t bits)
1417 if (fDestructing == kNone && fScene && fScene->IsAcceptingChanges())
1420 ::Info(Form(
"%s::AddStamp", GetCName()),
"%d + (%d) -> %d", fChangeBits, bits, fChangeBits | bits);
1422 if (fChangeBits == 0)
1424 fScene->SceneElementChanged(
this);
1427 fChangeBits |= bits;
1435 void REveElement::BuildRenderData()
1437 if (fMainTrans.get())
1439 fRenderData->SetMatrix(fMainTrans->Array());
1447 const std::string& REveElement::ToString(Bool_t b)
1449 static const std::string true_str (
"kTRUE");
1450 static const std::string false_str(
"kFALSE");
1452 return b ? true_str : false_str;
1460 Int_t REveElement::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
1462 j[
"_typename"] = IsA()->GetName();
1464 j[
"fTitle"] = fTitle;
1465 j[
"fElementId"] = GetElementId();
1466 j[
"fMotherId"] = get_mother_id();
1467 j[
"fSceneId"] = get_scene_id();
1468 j[
"fMasterId"] = GetSelectionMaster()->GetElementId();
1470 j[
"fRnrSelf"] = GetRnrSelf();
1471 j[
"fRnrChildren"] = GetRnrChildren();
1473 j[
"fMainColor"] = GetMainColor();
1474 j[
"fMainTransparency"] = GetMainTransparency();
1475 j[
"fPickable"] = fPickable;
1479 if (rnr_offset >= 0) {
1483 nlohmann::json rd = {};
1485 rd[
"rnr_offset"] = rnr_offset;
1486 rd[
"rnr_func"] = fRenderData->GetRnrFunc();
1487 rd[
"vert_size"] = fRenderData->SizeV();
1488 rd[
"norm_size"] = fRenderData->SizeN();
1489 rd[
"index_size"] = fRenderData->SizeI();
1490 rd[
"trans_size"] = fRenderData->SizeT();
1492 j[
"render_data"] = rd;
1494 ret = fRenderData->GetBinarySize();