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// Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
4
5/*************************************************************************
6 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#include "RBrowserWidget.hxx"
14
16
17#include "TGeoManager.h"
18#include "TGeoVolume.h"
19#include "TGeoMaterial.h"
20#include "TGeoMedium.h"
21
22using namespace ROOT::Experimental;
23
24using namespace std::string_literals;
25
26
29
30 std::unique_ptr<Browsable::RHolder> fObject; // geometry object
31
32 /** Create dummy geometry - when nothing else is there */
34 {
35 auto prev = gGeoManager;
36 gGeoManager = nullptr;
37
38 auto mgr = new TGeoManager("box", "poza1");
39 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
40 TGeoMedium *med = new TGeoMedium("MED",1,mat);
41 TGeoVolume *top = mgr->MakeBox("TOP",med,100,100,100);
42 mgr->SetTopVolume(top);
43 TGeoVolume *vol = mgr->MakeBox("BOX",med, 20,30,40);
44 vol->SetLineColor(kRed);
45 vol->SetLineWidth(2);
46 top->AddNode(vol,1);
47 mgr->CloseGeometry();
48
49 gGeoManager = prev;
50 return mgr;
51 }
52
53public:
54
56 {
59
60 // fViewer.SetGeometry(MakeDummy());
61 }
62
63 virtual ~RBrowserGeomWidget() = default;
64
65 std::string GetKind() const override { return "geom"s; }
66
67 void Show(const std::string &arg) override
68 {
69 fViewer.Show(arg);
70 }
71
72 std::string GetUrl() override
73 {
74 return "../"s + fViewer.GetWindowAddr() + "/"s;
75 }
76
77 bool DrawElement(std::shared_ptr<Browsable::RElement> &elem, const std::string &) override
78 {
79 if (!elem->IsCapable(Browsable::RElement::kActGeom))
80 return false;
81
82 fObject = elem->GetObject();
83 if (!fObject)
84 return false;
85
86 auto vol = fObject->Get<TGeoVolume>();
87 if (vol) {
88 fViewer.SetGeometry(vol->GetGeoManager(), vol->GetName());
89 return true;
90 }
91
92 auto node = fObject->Get<TGeoNode>();
93 if (node) {
94 fViewer.SetGeometry(node->GetVolume()->GetGeoManager(), node->GetVolume()->GetName());
95 return true;
96 }
97
98 // only handle TGeoManager now
99 auto mgr = fObject->Get<TGeoManager>();
100 if (!mgr) {
101 fObject.release();
102 return false;
103 }
104
105 fViewer.SetGeometry(const_cast<TGeoManager *>(mgr));
106
107 return true;
108 }
109
110};
111
112// ======================================================================
113
115protected:
116 std::shared_ptr<RBrowserWidget> Create(const std::string &name) final
117 {
118 return std::make_shared<RBrowserGeomWidget>(name);
119 }
120public:
RBrowserGeomProvider sRBrowserGeomProvider
@ kRed
Definition Rtypes.h:66
char name[80]
Definition TGX11.cxx:110
R__EXTERN TGeoManager * gGeoManager
std::shared_ptr< RBrowserWidget > Create(const std::string &name) final
~RBrowserGeomProvider()=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
virtual ~RBrowserGeomWidget()=default
void Show(const std::string &arg) override
bool DrawElement(std::shared_ptr< Browsable::RElement > &elem, const std::string &) override
std::string GetUrl() override
@ kActGeom
can be shown in geometry viewer
Definition RElement.hxx:57
Abstract Web-based widget, which can be used in the RBrowser Used to embed canvas,...
void SetTitle(const std::string &title)
std::string GetWindowAddr() const
Return URL address of web window used for geometry viewer.
void SetGeometry(TGeoManager *mgr, const std::string &volname="")
assign new geometry to the viewer
void Show(const RWebDisplayArgs &args="", bool always_start_new_browser=false)
Show or update geometry in web window If web browser already started - just refresh drawing like "rel...
void SetShowHierarchy(bool on=true)
Configures default hierarchy browser visibility, only has effect before showing web window.
The manager class for any TGeo geometry.
Definition TGeoManager.h:45
Base class describing materials.
Media are used to store properties related to tracking and which are useful only when using geometry ...
Definition TGeoMedium.h:24
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition TGeoNode.h:41
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:49
virtual TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=0, Option_t *option="")
Add a TGeoNode to the list of nodes.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.