1 | // |
---|
2 | // ******************************************************************** |
---|
3 | // * License and Disclaimer * |
---|
4 | // * * |
---|
5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
7 | // * conditions of the Geant4 Software License, included in the file * |
---|
8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
9 | // * include a list of copyright holders. * |
---|
10 | // * * |
---|
11 | // * Neither the authors of this software system, nor their employing * |
---|
12 | // * institutes,nor the agencies providing financial support for this * |
---|
13 | // * work make any representation or warranty, express or implied, * |
---|
14 | // * regarding this software system or assume any liability for its * |
---|
15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
16 | // * for the full disclaimer and the limitation of liability. * |
---|
17 | // * * |
---|
18 | // * This code implementation is the result of the scientific and * |
---|
19 | // * technical work of the GEANT4 collaboration. * |
---|
20 | // * By using, copying, modifying or distributing the software (or * |
---|
21 | // * any work based on the software) you agree to acknowledge its * |
---|
22 | // * use in resulting scientific publications, and indicate your * |
---|
23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
24 | // ******************************************************************** |
---|
25 | // |
---|
26 | // |
---|
27 | // $Id: G4tgrVolume.cc,v 1.13 2010/12/15 11:29:54 arce Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-04-ref-00 $ |
---|
29 | // |
---|
30 | // |
---|
31 | // class G4tgrVolume |
---|
32 | |
---|
33 | // History: |
---|
34 | // - Created. P.Arce, CIEMAT (November 2007) |
---|
35 | // ------------------------------------------------------------------------- |
---|
36 | |
---|
37 | #include "G4tgrVolume.hh" |
---|
38 | #include "G4tgrUtils.hh" |
---|
39 | #include "G4tgrSolid.hh" |
---|
40 | #include "G4tgrVolumeMgr.hh" |
---|
41 | #include "G4tgrPlace.hh" |
---|
42 | #include "G4tgrPlaceSimple.hh" |
---|
43 | #include "G4tgrPlaceDivRep.hh" |
---|
44 | #include "G4tgrPlaceParameterisation.hh" |
---|
45 | #include "G4tgrFileReader.hh" |
---|
46 | #include "G4tgrMessenger.hh" |
---|
47 | #include "G4UIcommand.hh" |
---|
48 | |
---|
49 | //------------------------------------------------------------- |
---|
50 | G4tgrVolume::G4tgrVolume() |
---|
51 | : theName(""), theType(""), |
---|
52 | theMaterialName(""), theSolid(0), theVisibility(false), |
---|
53 | theRGBColour(0), theCheckOverlaps(false) |
---|
54 | { |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | //------------------------------------------------------------- |
---|
59 | G4tgrVolume::~G4tgrVolume() |
---|
60 | { |
---|
61 | delete [] theRGBColour; |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | //------------------------------------------------------------- |
---|
66 | G4tgrVolume::G4tgrVolume( const std::vector<G4String>& wl) |
---|
67 | { |
---|
68 | theType = "VOLSimple"; |
---|
69 | |
---|
70 | //---------- set name |
---|
71 | theName = G4tgrUtils::GetString( wl[1] ); |
---|
72 | |
---|
73 | theVisibility = 1; |
---|
74 | theRGBColour = new G4double[4]; |
---|
75 | for(size_t ii=0; ii<4; ii++) { theRGBColour[ii] = -1.; } |
---|
76 | theCheckOverlaps = 0; |
---|
77 | |
---|
78 | if( wl.size() != 4 ) |
---|
79 | { |
---|
80 | //:VOLU tag to build a volume creating solid and material |
---|
81 | //---------- set material name |
---|
82 | theMaterialName = G4tgrUtils::GetString( wl[wl.size()-1] ); |
---|
83 | |
---|
84 | //---------- create only vector<double> of theSolidParams |
---|
85 | theSolid = G4tgrVolumeMgr::GetInstance()->CreateSolid( wl, 1 ); |
---|
86 | |
---|
87 | #ifdef G4VERBOSE |
---|
88 | if( G4tgrMessenger::GetVerboseLevel() >= 1 ) |
---|
89 | { |
---|
90 | G4cout << "Created from new solid: " |
---|
91 | << *this << G4endl; |
---|
92 | } |
---|
93 | #endif |
---|
94 | } |
---|
95 | else |
---|
96 | { |
---|
97 | //:VOLU tag to build a volume assigning material to solid |
---|
98 | //---------- set material name |
---|
99 | theMaterialName = G4tgrUtils::GetString( wl[3] ); |
---|
100 | theSolid = G4tgrVolumeMgr::GetInstance()->FindSolid( wl[2], true ); |
---|
101 | |
---|
102 | #ifdef G4VERBOSE |
---|
103 | if( G4tgrMessenger::GetVerboseLevel() >= 1 ) |
---|
104 | { |
---|
105 | G4cout << "Created from existing solid: " |
---|
106 | << *this << G4endl; |
---|
107 | } |
---|
108 | #endif |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | //------------------------------------------------------------------------- |
---|
114 | G4tgrVolume::G4tgrVolume( const G4tgrVolume& vol ) |
---|
115 | { |
---|
116 | theName = vol.GetName(); |
---|
117 | theType = vol.GetType(); |
---|
118 | theMaterialName = vol.GetMaterialName(); |
---|
119 | theSolid = const_cast<G4tgrSolid*>(vol.GetSolid()); |
---|
120 | thePlacements = vol.GetPlacements(); |
---|
121 | theVisibility = vol.GetVisibility(); |
---|
122 | theRGBColour = vol.GetRGBColour(); |
---|
123 | theCheckOverlaps = vol.GetCheckOverlaps(); |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | //------------------------------------------------------------------------- |
---|
128 | G4tgrVolume* G4tgrVolume::GetVolume( G4int ii ) const |
---|
129 | { |
---|
130 | G4String ErrMessage = "Should only be called for composite solids... " |
---|
131 | + G4UIcommand::ConvertToString(ii); |
---|
132 | G4Exception("G4tgrVolume::GetVolume()", "InvalidCall", |
---|
133 | FatalException, ErrMessage); |
---|
134 | return 0; |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | //------------------------------------------------------------- |
---|
139 | G4tgrPlace* G4tgrVolume::AddPlace( const std::vector<G4String>& wl ) |
---|
140 | { |
---|
141 | //---------- Check for exact number of words read |
---|
142 | G4tgrUtils::CheckWLsize( wl, 8, WLSIZE_EQ, " G4tgrVolume::AddPlace"); |
---|
143 | //---------- set G4tgrPlace |
---|
144 | G4tgrPlaceSimple* pl = new G4tgrPlaceSimple( wl ); |
---|
145 | //---------- check that there is no previous placement in |
---|
146 | // the same parent with the same copyNo |
---|
147 | std::vector<G4tgrPlace*>::iterator ite; |
---|
148 | for( ite = thePlacements.begin(); ite != thePlacements.end(); ite++) |
---|
149 | { |
---|
150 | if( ((*ite)->GetCopyNo() == pl->GetCopyNo()) |
---|
151 | && ((*ite)->GetParentName() == pl->GetParentName()) ) |
---|
152 | { |
---|
153 | G4String ErrMessage = "Repeated placement. Volume " |
---|
154 | + theName + " in " + pl->GetParentName(); |
---|
155 | G4Exception("G4tgrVolume::AddPlace()", "InvalidArgument", |
---|
156 | FatalErrorInArgument, ErrMessage); |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | pl->SetVolume( this ); |
---|
161 | thePlacements.push_back( pl ); |
---|
162 | |
---|
163 | #ifdef G4VERBOSE |
---|
164 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
165 | { |
---|
166 | G4cout << " G4tgrVolume: New placement: " << thePlacements.size() |
---|
167 | << " added for Volume " << theName |
---|
168 | << " inside " << pl->GetParentName() |
---|
169 | << " type " << pl->GetType() << G4endl; |
---|
170 | } |
---|
171 | #endif |
---|
172 | //---------- register parent - child |
---|
173 | G4tgrVolumeMgr::GetInstance()->RegisterParentChild( pl->GetParentName(), pl ); |
---|
174 | |
---|
175 | return pl; |
---|
176 | } |
---|
177 | |
---|
178 | |
---|
179 | //------------------------------------------------------------- |
---|
180 | G4tgrPlaceDivRep* |
---|
181 | G4tgrVolume::AddPlaceReplica( const std::vector<G4String>& wl ) |
---|
182 | { |
---|
183 | //---------- Check for exact number of words read |
---|
184 | G4tgrUtils::CheckWLsize( wl, 6, WLSIZE_GE, " G4tgrVolume::AddPlaceReplica"); |
---|
185 | G4tgrUtils::CheckWLsize( wl, 7, WLSIZE_LE, " G4tgrVolume::AddPlaceReplica"); |
---|
186 | |
---|
187 | if( (wl.size() == 7) && (G4tgrUtils::GetDouble(wl[6]) != 0.) |
---|
188 | && (wl[3] != "PHI") ) |
---|
189 | { |
---|
190 | G4Exception("G4tgrVolume::AddPlaceReplica", |
---|
191 | "Offset set for replica not along PHI, it will not be used", |
---|
192 | JustWarning, |
---|
193 | G4String("Volume "+wl[1]+" in volume "+wl[2]).c_str()); |
---|
194 | } |
---|
195 | |
---|
196 | //---------- set G4tgrPlace |
---|
197 | G4tgrPlaceDivRep* pl = new G4tgrPlaceDivRep( wl ); |
---|
198 | pl->SetType("PlaceReplica"); |
---|
199 | pl->SetVolume( this ); |
---|
200 | thePlacements.push_back( pl ); |
---|
201 | |
---|
202 | #ifdef G4VERBOSE |
---|
203 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
204 | { |
---|
205 | G4cout << " G4tgrVolume: New placement replica: " << thePlacements.size() |
---|
206 | << " added for Volume " << theName |
---|
207 | << " inside " << pl->GetParentName() << G4endl; |
---|
208 | } |
---|
209 | #endif |
---|
210 | //---------- register parent - child |
---|
211 | G4tgrVolumeMgr::GetInstance()->RegisterParentChild( pl->GetParentName(), pl ); |
---|
212 | |
---|
213 | return pl; |
---|
214 | } |
---|
215 | |
---|
216 | |
---|
217 | //------------------------------------------------------------- |
---|
218 | G4tgrPlaceParameterisation* |
---|
219 | G4tgrVolume::AddPlaceParam( const std::vector<G4String>& wl ) |
---|
220 | { |
---|
221 | //---------- set G4tgrPlaceParameterisation |
---|
222 | G4tgrPlaceParameterisation* pl = new G4tgrPlaceParameterisation( wl ); |
---|
223 | |
---|
224 | pl->SetVolume( this ); |
---|
225 | thePlacements.push_back( pl ); |
---|
226 | |
---|
227 | #ifdef G4VERBOSE |
---|
228 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
229 | { |
---|
230 | G4cout << " G4tgrVolume: New placement Param: " << thePlacements.size() |
---|
231 | << " added for Volume " << theName |
---|
232 | << " inside " << pl->GetParentName() << G4endl; |
---|
233 | } |
---|
234 | #endif |
---|
235 | //---------- register parent - child |
---|
236 | G4tgrVolumeMgr::GetInstance()->RegisterParentChild( pl->GetParentName(), pl ); |
---|
237 | |
---|
238 | return pl; |
---|
239 | } |
---|
240 | |
---|
241 | |
---|
242 | //------------------------------------------------------------- |
---|
243 | void G4tgrVolume::AddVisibility( const std::vector<G4String>& wl ) |
---|
244 | { |
---|
245 | //---------- Check for exact number of words read |
---|
246 | G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_EQ, " G4tgrVolume::AddVisibility"); |
---|
247 | |
---|
248 | //---------- Set visibility |
---|
249 | theVisibility = G4tgrUtils::GetBool( wl[2] ); |
---|
250 | } |
---|
251 | |
---|
252 | |
---|
253 | //------------------------------------------------------------- |
---|
254 | void G4tgrVolume::AddRGBColour( const std::vector<G4String>& wl ) |
---|
255 | { |
---|
256 | //---------- Check for exact number of words read |
---|
257 | G4tgrUtils::CheckWLsize( wl, 5, WLSIZE_GE, " G4tgrVolume::AddRGBColour"); |
---|
258 | |
---|
259 | //---------- Set RGB colour |
---|
260 | theRGBColour[0] = G4tgrUtils::GetDouble( wl[2] ); |
---|
261 | theRGBColour[1] = G4tgrUtils::GetDouble( wl[3] ); |
---|
262 | theRGBColour[2] = G4tgrUtils::GetDouble( wl[4] ); |
---|
263 | ///--------- Set transparency |
---|
264 | if( wl.size() == 6 ) |
---|
265 | { |
---|
266 | theRGBColour[3] = G4tgrUtils::GetDouble( wl[5] ); |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|
270 | |
---|
271 | //------------------------------------------------------------- |
---|
272 | void G4tgrVolume::AddCheckOverlaps( const std::vector<G4String>& wl ) |
---|
273 | { |
---|
274 | //---------- Check for exact number of words read |
---|
275 | G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_GE, " G4tgrVolume::AddCheckOverlaps"); |
---|
276 | |
---|
277 | ///--------- Set check overlaps |
---|
278 | theCheckOverlaps = G4tgrUtils::GetBool( wl[2] ); |
---|
279 | |
---|
280 | } |
---|
281 | |
---|
282 | |
---|
283 | // ------------------------------------------------------------------------- |
---|
284 | std::ostream& operator<<(std::ostream& os, const G4tgrVolume& obj) |
---|
285 | { |
---|
286 | os << "G4tgrVolume= " << obj.theName << " Type= " << obj.theType |
---|
287 | << " Material= " << obj.theMaterialName |
---|
288 | << " Visibility " << obj.theVisibility |
---|
289 | << " Colour " << (obj.theRGBColour)[0] << " " |
---|
290 | << (obj.theRGBColour)[1] << " " |
---|
291 | << (obj.theRGBColour)[2] << " " |
---|
292 | << (obj.theRGBColour)[3] << " " |
---|
293 | << " CheckOverlaps " << obj.theCheckOverlaps |
---|
294 | << " N placements " << obj.thePlacements.size() << G4endl; |
---|
295 | |
---|
296 | return os; |
---|
297 | } |
---|