ATLAS Offline Software
Loading...
Searching...
No Matches
VolumeHandleSharedData.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10#include "GeoModelKernel/GeoVPhysVol.h"
11#include "GeoModelKernel/GeoShapeShift.h"
12
17
18#include <Inventor/nodes/SoCylinder.h>
19#include <Inventor/nodes/SoRotationXYZ.h>
20#include <Inventor/nodes/SoSeparator.h>
21
22#include <map>
23
24//____________________________________________________________________
26public:
28 std::map<const GeoLogVol *, SoShape *> logvol2shape;
29 std::map<double, SoNode *> id2shape;
31 std::map<SoSeparator*,VolumeHandle*>* sonodesep2volhandle = nullptr;
32 GeoPVConstLink motherpV;
35 SoMaterial * topMaterial = nullptr;
39 int ref = 0;
40};
41
42//____________________________________________________________________
44 VP1GeoFlags::SubSystemFlag flag,std::map<SoSeparator*,VolumeHandle*>* sonodesep2volhandle,
45 const GeoPVConstLink& motherpV,PhiSectorManager*psm, SoMaterial * topMaterial,
47 ZappedVolumeListModel * zappedvolumelistmodel, VP1GeoTreeView * volbrowser, SoSeparator* textSep )
48 : m_d(new Imp), m_volumebrowser(volbrowser), m_textSep(textSep)
49{
50 m_d->ref = 0;
51 m_d->controller=controller;
52 m_d->sonodesep2volhandle = sonodesep2volhandle;
53 m_d->motherpV = motherpV;
54 m_d->phisectormanager = psm;
55 m_d->subsysflag = flag;
56 m_d->topMaterial = topMaterial;
57 m_d->matVisAttributes = matVisAttributes;
58 m_d->volVisAttributes = volVisAttributes;
59 m_d->zappedvolumelistmodel = zappedvolumelistmodel;
60}
61
62//____________________________________________________________________
64{
65 std::map<const GeoLogVol *, SoShape *>::iterator it, itE = m_d->logvol2shape.end();
66 for (it=m_d->logvol2shape.begin();it!=itE;++it) {
67 if (it->second)
68 it->second->unref();
69 }
70 std::map<double, SoNode *>::iterator it2, it2E = m_d->id2shape.end();
71 for (it2=m_d->id2shape.begin();it2!=it2E;++it2) {
72 if (it2->second)
73 it2->second->unref();
74 }
75 delete m_d; m_d=0;
76}
77
78//____________________________________________________________________
80{
81 ++(m_d->ref);
82}
83
84//____________________________________________________________________
86{
87 --(m_d->ref);
88 if (!m_d->ref)
89 delete this;
90}
91
92//____________________________________________________________________
94{
95 return m_d->matVisAttributes;
96}
97
98//____________________________________________________________________
100{
101 return m_d->volVisAttributes;
102}
103
104//____________________________________________________________________
106{
107 return m_d->topMaterial;
108}
109
110//____________________________________________________________________
115
116//____________________________________________________________________
118{
119 return m_d->phisectormanager;
120}
121
122//____________________________________________________________________
124{
125 return m_d->controller;
126}
127
128//_____________________________________________________________________________________
130{
131 assert(m_d->sonodesep2volhandle->find(n)==m_d->sonodesep2volhandle->end());
132 (*(m_d->sonodesep2volhandle))[n]=vh;
133 setShowVolumeOutlines(n,m_d->controller->showVolumeOutLines());
134}
135
136//_____________________________________________________________________________________
137void VolumeHandleSharedData::setShowVolumeOutlines(SoGroup*nodegroup,bool showvol)
138{
139 for (int i = 0; i<nodegroup->getNumChildren();++i) {
140 SoNode * n = nodegroup->getChild(i);
141 if (n->getTypeId().isDerivedFrom(SoGenericBox::getClassTypeId())) {
142 if (static_cast<SoGenericBox*>(n)->drawEdgeLines.getValue()!=showvol)
143 static_cast<SoGenericBox*>(n)->drawEdgeLines.setValue(showvol);
144 } else if (n->getTypeId().isDerivedFrom(SoTubs::getClassTypeId())) {
145 if (static_cast<SoTubs*>(n)->drawEdgeLines.getValue()!=showvol){
146 static_cast<SoTubs*>(n)->drawEdgeLines.setValue(showvol);
147 }
148 } else if (n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId())) {
149 if (static_cast<SoPcons*>(n)->drawEdgeLines.getValue()!=showvol){
150 static_cast<SoPcons*>(n)->drawEdgeLines.setValue(showvol);
151 }
152 } else if (n->getTypeId().isDerivedFrom(SoTessellated::getClassTypeId())) {
153 if (static_cast<SoTessellated*>(n)->drawEdgeLines.getValue()!=showvol){
154 static_cast<SoTessellated*>(n)->drawEdgeLines.setValue(showvol);
155 }
156 } else if (n->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) {
157 setShowVolumeOutlines(static_cast<SoGroup*>(n),showvol);
158 }
159 }
160}
161
162//_____________________________________________________________________________________
163SoNode * VolumeHandleSharedData::toShapeNode(const GeoPVConstLink& pV)
164{
165 const GeoLogVol * logVolume = pV->getLogVol();
166
167 // if shape already stored for this volume, return that
168 SoShape * shape (0);
169 std::map<const GeoLogVol *, SoShape *>::iterator itShape = m_d->logvol2shape.find(logVolume);
170 if (itShape!=m_d->logvol2shape.end()) {
171 return itShape->second;
172 }
173
174 const GeoShape * geoshape = logVolume->getShape();
175
176 m_d->visaction.reset();
177 if (geoshape->typeID()==GeoShapeShift::getClassTypeID()) {
178 dynamic_cast<const GeoShapeShift*>(geoshape)->getOp()->exec(&(m_d->visaction));
179 //NB: the transformation part of the GeoShapeShift will be applied elsewhere
180 } else {
181 geoshape->exec(&(m_d->visaction));
182 }
183 shape = m_d->visaction.getShape();
184 if (shape)
185 shape->ref();
186 m_d->logvol2shape[logVolume] = shape;
187 return shape;
188}
189
190//____________________________________________________________________
191SoNode * VolumeHandleSharedData::getSoCylinderOrientedLikeGeoTube(const double& radius, const double& halfLength)
192{
193 double id = radius - 9999.0*halfLength;
194 std::map<double, SoNode *>::iterator it = m_d->id2shape.find(id);
195 if (it!=m_d->id2shape.end())
196 return it->second;
197
198 SoGroup * group = new SoGroup;
199 SoRotationXYZ * rot = new SoRotationXYZ;
200 rot->axis.setValue(SoRotationXYZ::X);
201 rot->angle.setValue(M_PI*0.5f);
202 group->addChild(rot);
203 SoCylinder * cyl = new SoCylinder;
204 cyl->radius.setValue(radius);
205 cyl->height.setValue(2.0*halfLength);
206 group->addChild(cyl);
207 group->ref();
208 m_d->id2shape[id]=group;
209 return group;
210}
211
212//____________________________________________________________________
214{
215 return m_d->motherpV;
216}
217
218//____________________________________________________________________
220{
221 m_d->zappedvolumelistmodel->addToZappedVolumes(handle);
222}
223
224//____________________________________________________________________
226{
227 m_d->zappedvolumelistmodel->removeFromZappedVolumes(handle);
228}
#define M_PI
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
VolumeHandleSharedData(GeoSysController *controller, VP1GeoFlags::SubSystemFlag, std::map< SoSeparator *, VolumeHandle * > *sonodesep2volhandle, const GeoPVConstLink &motherpV, PhiSectorManager *, SoMaterial *topMaterial, MatVisAttributes *, VolVisAttributes *, ZappedVolumeListModel *, VP1GeoTreeView *, SoSeparator *)
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)