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
15#include <ROOT/RGeomViewer.hxx>
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
61 virtual ~RBrowserGeomWidget() = default;
62
63 std::string GetKind() const override { return "geom"s; }
64
65 void Show(const std::string &arg) override { fViewer.Show(arg); }
66
67 std::string GetUrl() override { return "../"s + fViewer.GetWindowAddr() + "/"s; }
68
69 bool DrawElement(std::shared_ptr<Browsable::RElement> &elem, const std::string & = "") override
70 {
71 if (!elem->IsCapable(Browsable::RElement::kActGeom))
72 return false;
73
74 fObject = elem->GetObject();
75 if (!fObject)
76 return false;
77
78 auto vol = fObject->Get<TGeoVolume>();
79
80 if (vol) {
81 auto mgr = vol->GetGeoManager();
82
83 if (!mgr || (mgr->GetListOfVolumes()->GetLast() < 0) || (mgr->GetVolume(vol->GetName()) != vol))
84 fViewer.SetOnlyVolume(const_cast<TGeoVolume *>(vol));
85 else
86 fViewer.SetGeometry(vol->GetGeoManager(), vol->GetName());
87
88 return true;
89 }
90
91 auto node = fObject->Get<TGeoNode>();
92 if (node) {
93 fViewer.SetGeometry(node->GetVolume()->GetGeoManager(), node->GetVolume()->GetName());
94 return true;
95 }
96
97 // only handle TGeoManager now
98 auto mgr = fObject->Get<TGeoManager>();
99 if (!mgr) {
100 fObject.release();
101 return false;
102 }
103
104 fViewer.SetGeometry(const_cast<TGeoManager *>(mgr));
105
106 return true;
107 }
108
109};
110
111// ======================================================================
112
114protected:
115 std::shared_ptr<RBrowserWidget> Create(const std::string &name) final
116 {
117 return std::make_shared<RBrowserGeomWidget>(name);
118 }
119public:
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:60
Abstract Web-based widget, which can be used in the RBrowser Used to embed canvas,...
void SetTitle(const std::string &title)
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 SetGeometry(TGeoManager *mgr, const std::string &volname="")
assign new geometry to the viewer
std::string GetWindowAddr() const
Return URL address of web window used for geometry viewer.
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: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
TGeoManager * GetGeoManager() const
Definition TGeoVolume.h:172
virtual TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=nullptr, 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.