ATLAS Offline Software
Loading...
Searching...
No Matches
VP1Floor.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7// //
8// Implementation of class VP1Floor //
9// //
10// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11// Initial version: July 2008 //
12// //
14
16#include <Inventor/nodes/SoSeparator.h>
17#include <Inventor/nodes/SoVertexProperty.h>
18#include <Inventor/nodes/SoLineSet.h>
19#include <Inventor/SbColor4f.h>
20
21#ifdef BUILDVP1LIGHT
22 #include "CLHEP/Units/SystemOfUnits.h"
23 #define SYSTEM_OF_UNITS CLHEP
24#else
25 #include "GaudiKernel/SystemOfUnits.h"
26 #define SYSTEM_OF_UNITS Gaudi::Units
27#endif
28
29//____________________________________________________________________
30bool VP1Floor::calcParsFromExtentAndSpacing( const VP1HelperClassBase*helper,const double& extent, const double& spacing, const int& nmaxlimit, int& nmax, double& distmax )
31{
32 if (extent<0.0||spacing<=0.0)
33 return false;
34 nmax=static_cast<int>(extent/spacing+0.5);
35 if (nmax<1)
36 nmax =1;
37 if (nmax>nmaxlimit) {
38 helper->message("Too many lines requested. All will not be shown.");
39 nmax=nmaxlimit;
40 }
41 distmax = nmax*spacing;
42 return true;
43}
44
45//____________________________________________________________________
47public:
48 Imp(VP1Floor *,
49 SoSeparator * attachsep);
51 SoSeparator * attachSep;
52
53 bool shown;
54 SbColor4f colourAndTransp;
55 double extent;
56 double spacing;
57 double vertpos;
58
59 SoSeparator * sep;
60
61 void rebuild3DObjects();
62 void updateColour();
63};
64
65//____________________________________________________________________
66VP1Floor::VP1Floor(SoSeparator * attachsep,
67 IVP1System * sys,QObject * parent)
68 : QObject(parent), VP1HelperClassBase(sys,"VP1Floor"), m_d(new Imp(this,attachsep))
69{
70}
71
72//____________________________________________________________________
74{
75 setShown(false);
76 if (m_d->sep)
77 m_d->sep->unref();
78 m_d->attachSep->unref();
79 delete m_d;
80}
81
82//____________________________________________________________________
83VP1Floor::Imp::Imp(VP1Floor *tc,SoSeparator * as)
84 : theclass(tc), attachSep(as), shown(false),
85 colourAndTransp(SbColor4f(1,1,1,1)),extent(10), spacing(1), vertpos(0), sep(0)
86{
87 attachSep->ref();
88}
89
90//____________________________________________________________________
92{
93 theclass->messageVerbose("(Re)building 3D objects");
94
95 if (sep) {
96 sep->removeAllChildren();
97 } else {
98 sep = new SoSeparator;
99 sep->ref();
100 }
101
102 const bool save = sep->enableNotify(false);
103
104 int nmax; double distmax;
106 nmax = 10;
107 distmax = 10*SYSTEM_OF_UNITS::m;
108 theclass->message("ERROR: Problems calculating nmax/distmax.");
109 }
110
111 SoVertexProperty * floor_vertices = new SoVertexProperty();
112 int ivert(0);
113 int nsublines(0);
114 for (int ix = -nmax; ix<=nmax; ++ix) {
115 double x = ix*spacing;
116 floor_vertices->vertex.set1Value(ivert++,x,vertpos,-distmax);
117 floor_vertices->vertex.set1Value(ivert++,x,vertpos,+distmax);
118 ++nsublines;
119 }
120 for (int iz = -nmax; iz<=nmax; ++iz) {
121 double z = iz*spacing;
122 floor_vertices->vertex.set1Value(ivert++,-distmax,vertpos,z);
123 floor_vertices->vertex.set1Value(ivert++,+distmax,vertpos,z);
124 ++nsublines;
125 }
126
127 floor_vertices->materialBinding=SoMaterialBinding::OVERALL;
128 floor_vertices->normalBinding=SoNormalBinding::OVERALL;
129 SoLineSet * line = new SoLineSet();
130 line->numVertices.enableNotify(FALSE);
131 line->numVertices.setNum(nsublines);
132 for (int i=0;i<nsublines;++i)
133 line->numVertices.set1Value(i,2);
134 line->vertexProperty = floor_vertices;
135 line->numVertices.enableNotify(TRUE);
136 line->numVertices.touch();
137
138 sep->addChild(line);
139 updateColour();
140
141 if (save) {
142 sep->enableNotify(true);
143 sep->touch();
144 }
145
146}
147
148//____________________________________________________________________
150{
151 theclass->messageVerbose("Updating packed colour");
152 if (!sep||sep->getNumChildren()<1)
153 return;
154 SoNode * n = sep->getChild(0);
155 if (!n||n->getTypeId()!=SoLineSet::getClassTypeId())
156 return;
157 SoLineSet * line = static_cast<SoLineSet*>(n);
158 SoVertexProperty * vertices = static_cast<SoVertexProperty *>(line->vertexProperty.getValue());
159 if (!vertices)
160 return;
161 vertices->orderedRGBA = colourAndTransp.getPackedValue();
162}
163
164//____________________________________________________________________
166{
167 messageVerbose("Signal received: setShown("+str(b)+")");
168 if (m_d->shown==b)
169 return;
170 m_d->shown=b;
171 if (m_d->shown) {
172 m_d->rebuild3DObjects();
173 if (m_d->attachSep->findChild(m_d->sep)<0)
174 m_d->attachSep->addChild(m_d->sep);
175 } else {
176 if (m_d->sep&&m_d->attachSep->findChild(m_d->sep)>=0)
177 m_d->attachSep->removeChild(m_d->sep);
178 }
179}
180
181//____________________________________________________________________
182void VP1Floor::setColourAndTransp(const SbColor4f&ct)
183{
184 messageVerbose("Signal received in setColourAndTransp slot.");
185 if (m_d->colourAndTransp==ct)
186 return;
187 m_d->colourAndTransp=ct;
188 if (m_d->shown)
189 m_d->updateColour();
190}
191
192//____________________________________________________________________
193void VP1Floor::setExtent(const double& e)
194{
195 messageVerbose("Signal received: setExtent("+str(e)+")");
196 if (m_d->extent==e)
197 return;
198 m_d->extent=e;
199 if (m_d->shown)
200 m_d->rebuild3DObjects();
201}
202
203//____________________________________________________________________
204void VP1Floor::setSpacing(const double&s)
205{
206 messageVerbose("Signal received: setSpacing("+str(s)+")");
207 if (m_d->spacing==s)
208 return;
209 m_d->spacing=s;
210 if (m_d->shown)
211 m_d->rebuild3DObjects();
212}
213
214//____________________________________________________________________
216{
217 messageVerbose("Signal received: setVerticalPosition("+str(p)+")");
218 if (m_d->vertpos==p)
219 return;
220 m_d->vertpos=p;
221 if (m_d->shown)
222 m_d->rebuild3DObjects();
223}
static Double_t tc
const int nmax(200)
#define x
#define z
double vertpos
Definition VP1Floor.cxx:57
void rebuild3DObjects()
Definition VP1Floor.cxx:91
VP1Floor * theclass
Definition VP1Floor.cxx:50
double spacing
Definition VP1Floor.cxx:56
Imp(VP1Floor *, SoSeparator *attachsep)
Definition VP1Floor.cxx:83
SbColor4f colourAndTransp
Definition VP1Floor.cxx:54
void updateColour()
Definition VP1Floor.cxx:149
double extent
Definition VP1Floor.cxx:55
SoSeparator * attachSep
Definition VP1Floor.cxx:51
SoSeparator * sep
Definition VP1Floor.cxx:59
void setVerticalPosition(const double &)
Definition VP1Floor.cxx:215
VP1Floor(SoSeparator *attachsep, IVP1System *sys, QObject *parent=0)
Definition VP1Floor.cxx:66
void setExtent(const double &)
Definition VP1Floor.cxx:193
static bool calcParsFromExtentAndSpacing(const VP1HelperClassBase *, const double &extent, const double &spacing, const int &nmaxlimit, int &nmax, double &distmax)
Definition VP1Floor.cxx:30
virtual ~VP1Floor()
Definition VP1Floor.cxx:73
void setShown(bool)
Definition VP1Floor.cxx:165
static int nMax()
Definition VP1Floor.h:33
void setSpacing(const double &)
Definition VP1Floor.cxx:204
void setColourAndTransp(const SbColor4f &)
Definition VP1Floor.cxx:182
Imp * m_d
Definition VP1Floor.h:51
VP1HelperClassBase(IVP1System *sys=0, QString helpername="")
void messageVerbose(const QString &) const