Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RBrowserGeomWidget.cxx
Go to the documentation of this file.
1// Author: Sergey Linev <S.Linev@gsi.de>
2// Date: 2021-01-22
3
4/*************************************************************************
5 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "RBrowserWidget.hxx"
13
14#include <ROOT/RGeomViewer.hxx>
15
16#include "TGeoManager.h"
17#include "TGeoVolume.h"
18#include "TGeoMaterial.h"
19#include "TGeoMedium.h"
20
21using namespace ROOT;
22
23using namespace std::string_literals;
24
25
28
29 std::unique_ptr<Browsable::RHolder> fObject; // geometry object
30
31 /** Create dummy geometry - when nothing else is there */
33 {
34 auto prev = gGeoManager;
35 gGeoManager = nullptr;
36
37 auto mgr = new TGeoManager("box", "poza1");
38 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
39 TGeoMedium *med = new TGeoMedium("MED",1,mat);
40 TGeoVolume *top = mgr->MakeBox("TOP",med,100,100,100);
41 mgr->SetTopVolume(top);
42 TGeoVolume *vol = mgr->MakeBox("BOX",med, 20,30,40);
43 vol->SetLineColor(kRed);
44 vol->SetLineWidth(2);
45 top->AddNode(vol,1);
46 mgr->CloseGeometry();
47
48 gGeoManager = prev;
49 return mgr;
50 }
51
52public:
53
55 {
58 }
59
60 ~RBrowserGeomWidget() override = default;
61
62 std::string GetKind() const override { return "geom"s; }
63
64 std::shared_ptr<ROOT::RWebWindow> GetWindow() override { return fViewer.GetWindow(); }
65
66 bool DrawElement(std::shared_ptr<Browsable::RElement> &elem, const std::string & = "") override
67 {
68 if (!elem->IsCapable(Browsable::RElement::kActGeom))
69 return false;
70
71 fObject = elem->GetObject();
72 if (!fObject)
73 return false;
74
75 auto vol = fObject->Get<TGeoVolume>();
76
77 if (vol) {
78 auto mgr = vol->GetGeoManager();
79
80 if (!mgr || (mgr->GetListOfVolumes()->GetLast() < 0) || (mgr->GetVolume(vol->GetName()) != vol))
81 fViewer.SetOnlyVolume(const_cast<TGeoVolume *>(vol));
82 else
83 fViewer.SetGeometry(vol->GetGeoManager(), vol->GetName());
84
85 return true;
86 }
87
88 auto node = fObject->Get<TGeoNode>();
89 if (node) {
90 fViewer.SetGeometry(node->GetVolume()->GetGeoManager(), node->GetVolume()->GetName());
91 return true;
92 }
93
94 // only handle TGeoManager now
95 auto mgr = fObject->Get<TGeoManager>();
96 if (!mgr) {
97 fObject.release();
98 return false;
99 }
100
101 fViewer.SetGeometry(const_cast<TGeoManager *>(mgr));
102
103 return true;
104 }
105
106};
107
108// ======================================================================
109
111protected:
112 std::shared_ptr<RBrowserWidget> Create(const std::string &name) final
113 {
114 return std::make_shared<RBrowserGeomWidget>(name);
115 }
116public:
118 ~RBrowserGeomProvider() override = default;
RBrowserGeomProvider sRBrowserGeomProvider
@ kRed
Definition Rtypes.h:67
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:148
R__EXTERN TGeoManager * gGeoManager
std::shared_ptr< RBrowserWidget > Create(const std::string &name) final
~RBrowserGeomProvider() override=default
std::string GetKind() const override
TGeoManager * MakeDummy()
Create dummy geometry - when nothing else is there.
RBrowserGeomWidget(const std::string &name)
std::unique_ptr< Browsable::RHolder > fObject
~RBrowserGeomWidget() override=default
bool DrawElement(std::shared_ptr< Browsable::RElement > &elem, const std::string &="") override
std::shared_ptr< ROOT::RWebWindow > GetWindow() override
@ kActGeom
can be shown in geometry viewer
Definition RElement.hxx:58
Abstract Web-based widget, which can be used in the RBrowser Used to embed canvas,...
Web-based ROOT geometry viewer.
void SetTitle(const std::string &title)
void SetGeometry(TGeoManager *mgr, const std::string &volname="")
assign new geometry to the viewer
std::shared_ptr< RWebWindow > GetWindow()
void SetShowHierarchy(bool on=true)
Configures default hierarchy browser visibility, only has effect before showing web window.
void SetOnlyVolume(TGeoVolume *vol)
Draw only specified volume, special case when volume stored without valid geomanager.
The manager class for any TGeo geometry.
Definition TGeoManager.h:46
Base class describing materials.
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition TGeoMedium.h:23
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition TGeoNode.h:39
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
void SetLineWidth(Width_t lwidth) override
Set the line width.
virtual TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=nullptr, Option_t *option="")
Add a TGeoNode to the list of nodes.
void SetLineColor(Color_t lcolor) override
Set the line color.