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.10 2009/11/23 11:36:29 arce Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-03 $ |
---|
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 | { |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | //------------------------------------------------------------- |
---|
56 | G4tgrVolume::~G4tgrVolume() |
---|
57 | { |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | //------------------------------------------------------------- |
---|
62 | G4tgrVolume::G4tgrVolume( const std::vector<G4String>& wl) |
---|
63 | { |
---|
64 | theType = "VOLSimple"; |
---|
65 | |
---|
66 | //---------- set name |
---|
67 | theName = G4tgrUtils::GetString( wl[1] ); |
---|
68 | |
---|
69 | theVisibility = 1; |
---|
70 | theRGBColour = new G4double[4]; |
---|
71 | for(size_t ii=0; ii<4; ii++) { theRGBColour[ii] = -1.; } |
---|
72 | theCheckOverlaps = 0; |
---|
73 | |
---|
74 | if( wl.size() != 4 ) |
---|
75 | { |
---|
76 | //:VOLU tag to build a volume creating solid and material |
---|
77 | //---------- set material name |
---|
78 | theMaterialName = G4tgrUtils::GetString( wl[wl.size()-1] ); |
---|
79 | |
---|
80 | //---------- create only vector<double> of theSolidParams |
---|
81 | theSolid = G4tgrVolumeMgr::GetInstance()->CreateSolid( wl, 1 ); |
---|
82 | |
---|
83 | #ifdef G4VERBOSE |
---|
84 | if( G4tgrMessenger::GetVerboseLevel() >= 1 ) |
---|
85 | { |
---|
86 | G4cout << "Created from new solid: " |
---|
87 | << *this << G4endl; |
---|
88 | } |
---|
89 | #endif |
---|
90 | } |
---|
91 | else |
---|
92 | { |
---|
93 | //:VOLU tag to build a volume assigning material to solid |
---|
94 | //---------- set material name |
---|
95 | theMaterialName = G4tgrUtils::GetString( wl[3] ); |
---|
96 | theSolid = G4tgrVolumeMgr::GetInstance()->FindSolid( wl[2], true ); |
---|
97 | |
---|
98 | #ifdef G4VERBOSE |
---|
99 | if( G4tgrMessenger::GetVerboseLevel() >= 1 ) |
---|
100 | { |
---|
101 | G4cout << "Created from existing solid: " |
---|
102 | << *this << G4endl; |
---|
103 | } |
---|
104 | #endif |
---|
105 | } |
---|
106 | |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | //------------------------------------------------------------------------- |
---|
111 | G4tgrVolume::G4tgrVolume( const G4tgrVolume& vol ) |
---|
112 | { |
---|
113 | theName = vol.GetName(); |
---|
114 | theType = vol.GetType(); |
---|
115 | theMaterialName = vol.GetMaterialName(); |
---|
116 | theSolid = const_cast<G4tgrSolid*>(vol.GetSolid()); |
---|
117 | thePlacements = vol.GetPlacements(); |
---|
118 | theVisibility = vol.GetVisibility(); |
---|
119 | theRGBColour = vol.GetRGBColour(); |
---|
120 | theCheckOverlaps = vol.GetCheckOverlaps(); |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | //------------------------------------------------------------------------- |
---|
125 | G4tgrVolume* G4tgrVolume::GetVolume( G4int ii ) const |
---|
126 | { |
---|
127 | G4String ErrMessage = "Should only be called for composite solids... " |
---|
128 | + G4UIcommand::ConvertToString(ii); |
---|
129 | G4Exception("G4tgrVolume::GetVolume()", "InvalidCall", |
---|
130 | FatalException, ErrMessage); |
---|
131 | return 0; |
---|
132 | } |
---|
133 | |
---|
134 | |
---|
135 | //------------------------------------------------------------- |
---|
136 | G4tgrPlace* G4tgrVolume::AddPlace( const std::vector<G4String>& wl ) |
---|
137 | { |
---|
138 | //---------- Check for exact number of words read |
---|
139 | G4tgrUtils::CheckWLsize( wl, 8, WLSIZE_EQ, " G4tgrVolume::AddPlace"); |
---|
140 | //---------- set G4tgrPlace |
---|
141 | G4tgrPlaceSimple* pl = new G4tgrPlaceSimple( wl ); |
---|
142 | //---------- check that there is no previous placement in |
---|
143 | // the same parent with the same copyNo |
---|
144 | std::vector<G4tgrPlace*>::iterator ite; |
---|
145 | for( ite = thePlacements.begin(); ite != thePlacements.end(); ite++) |
---|
146 | { |
---|
147 | if( ((*ite)->GetCopyNo() == pl->GetCopyNo()) |
---|
148 | && ((*ite)->GetParentName() == pl->GetParentName()) ) |
---|
149 | { |
---|
150 | G4String ErrMessage = "Repeated placement. Volume " |
---|
151 | + theName + " in " + pl->GetParentName(); |
---|
152 | G4Exception("G4tgrVolume::AddPlace()", "InvalidArgument", |
---|
153 | FatalErrorInArgument, ErrMessage); |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | pl->SetVolume( this ); |
---|
158 | thePlacements.push_back( pl ); |
---|
159 | |
---|
160 | #ifdef G4VERBOSE |
---|
161 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
162 | { |
---|
163 | G4cout << " G4tgrVolume: New placement: " << thePlacements.size() |
---|
164 | << " added for Volume " << theName |
---|
165 | << " inside " << pl->GetParentName() |
---|
166 | << " type " << pl->GetType() << G4endl; |
---|
167 | } |
---|
168 | #endif |
---|
169 | //---------- register parent - child |
---|
170 | G4tgrVolumeMgr::GetInstance()->RegisterParentChild( pl->GetParentName(), pl ); |
---|
171 | |
---|
172 | return pl; |
---|
173 | } |
---|
174 | |
---|
175 | |
---|
176 | //------------------------------------------------------------- |
---|
177 | G4tgrPlaceDivRep* |
---|
178 | G4tgrVolume::AddPlaceReplica( const std::vector<G4String>& wl ) |
---|
179 | { |
---|
180 | //---------- Check for exact number of words read |
---|
181 | G4tgrUtils::CheckWLsize( wl, 6, WLSIZE_GE, " G4tgrVolume::AddPlaceReplica"); |
---|
182 | G4tgrUtils::CheckWLsize( wl, 7, WLSIZE_LE, " G4tgrVolume::AddPlaceReplica"); |
---|
183 | |
---|
184 | if( (wl.size() == 7) && (G4tgrUtils::GetDouble(wl[6]) != 0.) |
---|
185 | && (wl[3] != "PHI") ) |
---|
186 | { |
---|
187 | G4Exception("G4tgrVolume::AddPlaceReplica", |
---|
188 | "Offset set for replica not along PHI, it will not be used", |
---|
189 | JustWarning, |
---|
190 | G4String("Volume "+wl[1]+" in volume "+wl[2]).c_str()); |
---|
191 | } |
---|
192 | |
---|
193 | //---------- set G4tgrPlace |
---|
194 | G4tgrPlaceDivRep* pl = new G4tgrPlaceDivRep( wl ); |
---|
195 | pl->SetType("PlaceReplica"); |
---|
196 | pl->SetVolume( this ); |
---|
197 | thePlacements.push_back( pl ); |
---|
198 | |
---|
199 | #ifdef G4VERBOSE |
---|
200 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
201 | { |
---|
202 | G4cout << " G4tgrVolume: New placement replica: " << thePlacements.size() |
---|
203 | << " added for Volume " << theName |
---|
204 | << " inside " << pl->GetParentName() << G4endl; |
---|
205 | } |
---|
206 | #endif |
---|
207 | //---------- register parent - child |
---|
208 | G4tgrVolumeMgr::GetInstance()->RegisterParentChild( pl->GetParentName(), pl ); |
---|
209 | |
---|
210 | return pl; |
---|
211 | } |
---|
212 | |
---|
213 | |
---|
214 | //------------------------------------------------------------- |
---|
215 | G4tgrPlaceParameterisation* |
---|
216 | G4tgrVolume::AddPlaceParam( const std::vector<G4String>& wl ) |
---|
217 | { |
---|
218 | //---------- set G4tgrPlaceParameterisation |
---|
219 | G4tgrPlaceParameterisation* pl = new G4tgrPlaceParameterisation( wl ); |
---|
220 | |
---|
221 | pl->SetVolume( this ); |
---|
222 | thePlacements.push_back( pl ); |
---|
223 | |
---|
224 | #ifdef G4VERBOSE |
---|
225 | if( G4tgrMessenger::GetVerboseLevel() >= 2 ) |
---|
226 | { |
---|
227 | G4cout << " G4tgrVolume: New placement Param: " << thePlacements.size() |
---|
228 | << " added for Volume " << theName |
---|
229 | << " inside " << pl->GetParentName() << G4endl; |
---|
230 | } |
---|
231 | #endif |
---|
232 | //---------- register parent - child |
---|
233 | G4tgrVolumeMgr::GetInstance()->RegisterParentChild( pl->GetParentName(), pl ); |
---|
234 | |
---|
235 | return pl; |
---|
236 | } |
---|
237 | |
---|
238 | |
---|
239 | //------------------------------------------------------------- |
---|
240 | void G4tgrVolume::AddVisibility( const std::vector<G4String>& wl ) |
---|
241 | { |
---|
242 | //---------- Check for exact number of words read |
---|
243 | G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_EQ, " G4tgrVolume::AddVisibility"); |
---|
244 | |
---|
245 | //---------- Set visibility |
---|
246 | theVisibility = G4tgrUtils::GetBool( wl[2] ); |
---|
247 | } |
---|
248 | |
---|
249 | |
---|
250 | //------------------------------------------------------------- |
---|
251 | void G4tgrVolume::AddRGBColour( const std::vector<G4String>& wl ) |
---|
252 | { |
---|
253 | //---------- Check for exact number of words read |
---|
254 | G4tgrUtils::CheckWLsize( wl, 5, WLSIZE_GE, " G4tgrVolume::AddRGBColour"); |
---|
255 | |
---|
256 | //---------- Set RGB colour |
---|
257 | theRGBColour[0] = G4tgrUtils::GetDouble( wl[2] ); |
---|
258 | theRGBColour[1] = G4tgrUtils::GetDouble( wl[3] ); |
---|
259 | theRGBColour[2] = G4tgrUtils::GetDouble( wl[4] ); |
---|
260 | ///--------- Set transparency |
---|
261 | if( wl.size() == 6 ) |
---|
262 | { |
---|
263 | theRGBColour[3] = G4tgrUtils::GetDouble( wl[5] ); |
---|
264 | } |
---|
265 | } |
---|
266 | |
---|
267 | |
---|
268 | //------------------------------------------------------------- |
---|
269 | void G4tgrVolume::AddCheckOverlaps( const std::vector<G4String>& wl ) |
---|
270 | { |
---|
271 | //---------- Check for exact number of words read |
---|
272 | G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_GE, " G4tgrVolume::AddCheckOverlaps"); |
---|
273 | |
---|
274 | ///--------- Set check overlaps |
---|
275 | theCheckOverlaps = G4tgrUtils::GetBool( wl[2] ); |
---|
276 | |
---|
277 | } |
---|
278 | |
---|
279 | |
---|
280 | // ------------------------------------------------------------------------- |
---|
281 | std::ostream& operator<<(std::ostream& os, const G4tgrVolume& obj) |
---|
282 | { |
---|
283 | os << "G4tgrVolume= " << obj.theName << " Type= " << obj.theType |
---|
284 | << " Material= " << obj.theMaterialName |
---|
285 | << " Visibility " << obj.theVisibility |
---|
286 | << " Colour " << (obj.theRGBColour)[0] << " " |
---|
287 | << (obj.theRGBColour)[1] << " " |
---|
288 | << (obj.theRGBColour)[2] << " " |
---|
289 | << (obj.theRGBColour)[3] << " " |
---|
290 | << " CheckOverlaps " << obj.theCheckOverlaps |
---|
291 | << " N placements " << obj.thePlacements.size() << G4endl; |
---|
292 | |
---|
293 | return os; |
---|
294 | } |
---|