ATLAS Offline Software
Loading...
Searching...
No Matches
VolumeHandleSharedData.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10#include "GeoModelKernel/GeoVPhysVol.h"
11#include "GeoModelKernel/GeoShapeShift.h"
12
18
19#include <Inventor/nodes/SoCylinder.h>
20#include <Inventor/nodes/SoRotationXYZ.h>
21#include <Inventor/nodes/SoSeparator.h>
22
23#include <map>
24
25//____________________________________________________________________
27public:
29 std::map<const GeoLogVol *, SoShape *> logvol2shape;
30 std::map<double, SoNode *> id2shape;
32 std::map<SoSeparator*,VolumeHandle*>* sonodesep2volhandle = nullptr;
33 GeoPVConstLink motherpV;
36 SoMaterial * topMaterial = nullptr;
41 int ref = 0;
42};
43
44//____________________________________________________________________
46 VP1GeoFlags::SubSystemFlag flag,std::map<SoSeparator*,VolumeHandle*>* sonodesep2volhandle,
47 const GeoPVConstLink& motherpV,PhiSectorManager*psm, SoMaterial * topMaterial,
49 ZappedVolumeListModel * zappedvolumelistmodel, VP1GeoTreeView * volbrowser, SoSeparator* textSep,
50 std::optional<SbColor> outlineColour )
51 : m_d(new Imp), m_volumebrowser(volbrowser), m_textSep(textSep)
52{
53 m_d->ref = 0;
54 m_d->controller=controller;
55 m_d->sonodesep2volhandle = sonodesep2volhandle;
56 m_d->motherpV = motherpV;
57 m_d->phisectormanager = psm;
58 m_d->subsysflag = flag;
59 m_d->topMaterial = topMaterial;
60 if (outlineColour) {
62 m_d->outlineColour = new SoOutlineColour;
63 m_d->outlineColour->ref();
64 m_d->outlineColour->colour = *outlineColour;
65 }
66 m_d->matVisAttributes = matVisAttributes;
67 m_d->volVisAttributes = volVisAttributes;
68 m_d->zappedvolumelistmodel = zappedvolumelistmodel;
69}
70
71//____________________________________________________________________
73{
74 std::map<const GeoLogVol *, SoShape *>::iterator it, itE = m_d->logvol2shape.end();
75 for (it=m_d->logvol2shape.begin();it!=itE;++it) {
76 if (it->second)
77 it->second->unref();
78 }
79 std::map<double, SoNode *>::iterator it2, it2E = m_d->id2shape.end();
80 for (it2=m_d->id2shape.begin();it2!=it2E;++it2) {
81 if (it2->second)
82 it2->second->unref();
83 }
84 if (m_d->outlineColour)
85 m_d->outlineColour->unref();
86 delete m_d; m_d=0;
87}
88
89//____________________________________________________________________
91{
92 ++(m_d->ref);
93}
94
95//____________________________________________________________________
97{
98 --(m_d->ref);
99 if (!m_d->ref)
100 delete this;
101}
102
103//____________________________________________________________________
105{
106 return m_d->matVisAttributes;
107}
108
109//____________________________________________________________________
111{
112 return m_d->volVisAttributes;
113}
114
115//____________________________________________________________________
117{
118 return m_d->topMaterial;
119}
120
121//____________________________________________________________________
126
127//____________________________________________________________________
129{
130 return m_d->phisectormanager;
131}
132
133//____________________________________________________________________
135{
136 return m_d->controller;
137}
138
139//_____________________________________________________________________________________
141{
142 assert(m_d->sonodesep2volhandle->find(n)==m_d->sonodesep2volhandle->end());
143 (*(m_d->sonodesep2volhandle))[n]=vh;
144 // The volume separator scopes this optional colour to its own geometry.
145 if (m_d->outlineColour)
146 n->insertChild(m_d->outlineColour, 0);
147 setShowVolumeOutlines(n,m_d->controller->showVolumeOutLines());
148}
149
150//_____________________________________________________________________________________
151void VolumeHandleSharedData::setShowVolumeOutlines(SoGroup*nodegroup,bool showvol)
152{
153 for (int i = 0; i<nodegroup->getNumChildren();++i) {
154 SoNode * n = nodegroup->getChild(i);
155 if (n->getTypeId().isDerivedFrom(SoOutlineColour::getClassTypeId())) {
156 auto* colour = static_cast<SoOutlineColour*>(n);
157 if (colour->enabled.getValue() != showvol)
158 colour->enabled = showvol;
159 } else if (n->getTypeId().isDerivedFrom(SoGenericBox::getClassTypeId())) {
160 if (static_cast<SoGenericBox*>(n)->drawEdgeLines.getValue()!=showvol)
161 static_cast<SoGenericBox*>(n)->drawEdgeLines.setValue(showvol);
162 } else if (n->getTypeId().isDerivedFrom(SoTubs::getClassTypeId())) {
163 if (static_cast<SoTubs*>(n)->drawEdgeLines.getValue()!=showvol){
164 static_cast<SoTubs*>(n)->drawEdgeLines.setValue(showvol);
165 }
166 } else if (n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId())) {
167 if (static_cast<SoPcons*>(n)->drawEdgeLines.getValue()!=showvol){
168 static_cast<SoPcons*>(n)->drawEdgeLines.setValue(showvol);
169 }
170 } else if (n->getTypeId().isDerivedFrom(SoTessellated::getClassTypeId())) {
171 if (static_cast<SoTessellated*>(n)->drawEdgeLines.getValue()!=showvol){
172 static_cast<SoTessellated*>(n)->drawEdgeLines.setValue(showvol);
173 }
174 } else if (n->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) {
175 setShowVolumeOutlines(static_cast<SoGroup*>(n),showvol);
176 }
177 }
178}
179
180//_____________________________________________________________________________________
181SoNode * VolumeHandleSharedData::toShapeNode(const GeoPVConstLink& pV)
182{
183 const GeoLogVol * logVolume = pV->getLogVol();
184
185 // if shape already stored for this volume, return that
186 SoShape * shape (0);
187 std::map<const GeoLogVol *, SoShape *>::iterator itShape = m_d->logvol2shape.find(logVolume);
188 if (itShape!=m_d->logvol2shape.end()) {
189 return itShape->second;
190 }
191
192 const GeoShape * geoshape = logVolume->getShape();
193
194 m_d->visaction.reset();
195 if (geoshape->typeID()==GeoShapeShift::getClassTypeID()) {
196 dynamic_cast<const GeoShapeShift*>(geoshape)->getOp()->exec(&(m_d->visaction));
197 //NB: the transformation part of the GeoShapeShift will be applied elsewhere
198 } else {
199 geoshape->exec(&(m_d->visaction));
200 }
201 shape = m_d->visaction.getShape();
202 if (shape)
203 shape->ref();
204 m_d->logvol2shape[logVolume] = shape;
205 return shape;
206}
207
208//____________________________________________________________________
209SoNode * VolumeHandleSharedData::getSoCylinderOrientedLikeGeoTube(const double& radius, const double& halfLength)
210{
211 double id = radius - 9999.0*halfLength;
212 std::map<double, SoNode *>::iterator it = m_d->id2shape.find(id);
213 if (it!=m_d->id2shape.end())
214 return it->second;
215
216 SoGroup * group = new SoGroup;
217 SoRotationXYZ * rot = new SoRotationXYZ;
218 rot->axis.setValue(SoRotationXYZ::X);
219 rot->angle.setValue(M_PI*0.5f);
220 group->addChild(rot);
221 SoCylinder * cyl = new SoCylinder;
222 cyl->radius.setValue(radius);
223 cyl->height.setValue(2.0*halfLength);
224 group->addChild(cyl);
225 group->ref();
226 m_d->id2shape[id]=group;
227 return group;
228}
229
230//____________________________________________________________________
232{
233 return m_d->motherpV;
234}
235
236//____________________________________________________________________
238{
239 m_d->zappedvolumelistmodel->addToZappedVolumes(handle);
240}
241
242//____________________________________________________________________
244{
245 m_d->zappedvolumelistmodel->removeFromZappedVolumes(handle);
246}
#define M_PI
static void initClass()
SoPcons - Inventor version of the G4Cons Geant Geometry entity.
Definition SoPcons.h:42
SoTubs - Inventor version of the G4Tubs Geant Geometry entity.
Definition SoTubs.h:52
std::map< const GeoLogVol *, SoShape * > logvol2shape
std::map< double, SoNode * > id2shape
ZappedVolumeListModel * zappedvolumelistmodel
std::map< SoSeparator *, VolumeHandle * > * sonodesep2volhandle
VP1GeoFlags::SubSystemFlag subsysflag
SoSeparator * textSep() const
SoSeparator * m_textSep
base text sep
GeoPVConstLink geoPVConstLinkOfTreeTopsMother() const
PhiSectorManager * phiSectorManager() const
GeoSysController * controller() const
void registerNodeSepForVolumeHandle(SoSeparator *, VolumeHandle *)
SoNode * getSoCylinderOrientedLikeGeoTube(const double &radius, const double &halfLength)
static void setShowVolumeOutlines(SoGroup *nodesep, bool showvol)
VolVisAttributes * volVisAttributes() const
VP1GeoFlags::SubSystemFlag subSystemFlag() const
void removeZappedVolumesFromGui(VolumeHandle *)
void addZappedVolumeToGui(VolumeHandle *)
SoMaterial * fallBackTopLevelMaterial() const
MatVisAttributes * matVisAttributes() const
SoNode * toShapeNode(const GeoPVConstLink &pV)
VolumeHandleSharedData(GeoSysController *controller, VP1GeoFlags::SubSystemFlag, std::map< SoSeparator *, VolumeHandle * > *sonodesep2volhandle, const GeoPVConstLink &motherpV, PhiSectorManager *, SoMaterial *topMaterial, MatVisAttributes *, VolVisAttributes *, ZappedVolumeListModel *, VP1GeoTreeView *, SoSeparator *, std::optional< SbColor > outlineColour=std::nullopt)