00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "G4tgrVolume.hh"
00037 #include "G4tgrUtils.hh"
00038 #include "G4tgrSolid.hh"
00039 #include "G4tgrVolumeMgr.hh"
00040 #include "G4tgrPlace.hh"
00041 #include "G4tgrPlaceSimple.hh"
00042 #include "G4tgrPlaceDivRep.hh"
00043 #include "G4tgrPlaceParameterisation.hh"
00044 #include "G4tgrFileReader.hh"
00045 #include "G4tgrMessenger.hh"
00046 #include "G4UIcommand.hh"
00047
00048
00049 G4tgrVolume::G4tgrVolume()
00050 : theName(""), theType(""),
00051 theMaterialName(""), theSolid(0), theVisibility(false),
00052 theRGBColour(0), theCheckOverlaps(false)
00053 {
00054 }
00055
00056
00057
00058 G4tgrVolume::~G4tgrVolume()
00059 {
00060 delete [] theRGBColour;
00061 }
00062
00063
00064
00065 G4tgrVolume::G4tgrVolume( const std::vector<G4String>& wl)
00066 {
00067 theType = "VOLSimple";
00068
00069
00070 theName = G4tgrUtils::GetString( wl[1] );
00071
00072 theVisibility = 1;
00073 theRGBColour = new G4double[4];
00074 for(size_t ii=0; ii<4; ii++) { theRGBColour[ii] = -1.; }
00075 theCheckOverlaps = 0;
00076
00077 if( wl.size() != 4 )
00078 {
00079
00080
00081 theMaterialName = G4tgrUtils::GetString( wl[wl.size()-1] );
00082
00083
00084 theSolid = G4tgrVolumeMgr::GetInstance()->CreateSolid( wl, 1 );
00085
00086 #ifdef G4VERBOSE
00087 if( G4tgrMessenger::GetVerboseLevel() >= 1 )
00088 {
00089 G4cout << "Created from new solid: "
00090 << *this << G4endl;
00091 }
00092 #endif
00093 }
00094 else
00095 {
00096
00097
00098 theMaterialName = G4tgrUtils::GetString( wl[3] );
00099 theSolid = G4tgrVolumeMgr::GetInstance()->FindSolid( wl[2], true );
00100
00101 #ifdef G4VERBOSE
00102 if( G4tgrMessenger::GetVerboseLevel() >= 1 )
00103 {
00104 G4cout << "Created from existing solid: "
00105 << *this << G4endl;
00106 }
00107 #endif
00108 }
00109 }
00110
00111
00112
00113 G4tgrVolume::G4tgrVolume( const G4tgrVolume& vol )
00114 {
00115 theName = vol.GetName();
00116 theType = vol.GetType();
00117 theMaterialName = vol.GetMaterialName();
00118 theSolid = vol.GetSolid();
00119 thePlacements = vol.GetPlacements();
00120 theVisibility = vol.GetVisibility();
00121 theRGBColour = vol.GetRGBColour();
00122 theCheckOverlaps = vol.GetCheckOverlaps();
00123 }
00124
00125
00126
00127 G4tgrVolume* G4tgrVolume::GetVolume( G4int ii ) const
00128 {
00129 G4String ErrMessage = "Should only be called for composite solids... "
00130 + G4UIcommand::ConvertToString(ii);
00131 G4Exception("G4tgrVolume::GetVolume()", "InvalidCall",
00132 FatalException, ErrMessage);
00133 return 0;
00134 }
00135
00136
00137
00138 G4tgrPlace* G4tgrVolume::AddPlace( const std::vector<G4String>& wl )
00139 {
00140
00141 G4tgrUtils::CheckWLsize( wl, 8, WLSIZE_EQ, " G4tgrVolume::AddPlace");
00142
00143 G4tgrPlaceSimple* pl = new G4tgrPlaceSimple( wl );
00144
00145
00146 std::vector<G4tgrPlace*>::iterator ite;
00147 for( ite = thePlacements.begin(); ite != thePlacements.end(); ite++)
00148 {
00149 if( ((*ite)->GetCopyNo() == pl->GetCopyNo())
00150 && ((*ite)->GetParentName() == pl->GetParentName()) )
00151 {
00152 G4String ErrMessage = "Repeated placement. Volume "
00153 + theName + " in " + pl->GetParentName();
00154 G4Exception("G4tgrVolume::AddPlace()", "InvalidArgument",
00155 FatalErrorInArgument, ErrMessage);
00156 }
00157 }
00158
00159 pl->SetVolume( this );
00160 thePlacements.push_back( pl );
00161
00162 #ifdef G4VERBOSE
00163 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00164 {
00165 G4cout << " G4tgrVolume: New placement: " << thePlacements.size()
00166 << " added for Volume " << theName
00167 << " inside " << pl->GetParentName()
00168 << " type " << pl->GetType() << G4endl;
00169 }
00170 #endif
00171
00172 G4tgrVolumeMgr::GetInstance()->RegisterParentChild( pl->GetParentName(), pl );
00173
00174 return pl;
00175 }
00176
00177
00178
00179 G4tgrPlaceDivRep*
00180 G4tgrVolume::AddPlaceReplica( const std::vector<G4String>& wl )
00181 {
00182
00183 G4tgrUtils::CheckWLsize( wl, 6, WLSIZE_GE, " G4tgrVolume::AddPlaceReplica");
00184 G4tgrUtils::CheckWLsize( wl, 7, WLSIZE_LE, " G4tgrVolume::AddPlaceReplica");
00185
00186 if( (wl.size() == 7) && (G4tgrUtils::GetDouble(wl[6]) != 0.)
00187 && (wl[3] != "PHI") )
00188 {
00189 G4Exception("G4tgrVolume::AddPlaceReplica",
00190 "Offset set for replica not along PHI, it will not be used",
00191 JustWarning,
00192 G4String("Volume "+wl[1]+" in volume "+wl[2]).c_str());
00193 }
00194
00195
00196 G4tgrPlaceDivRep* pl = new G4tgrPlaceDivRep( wl );
00197 pl->SetType("PlaceReplica");
00198 pl->SetVolume( this );
00199 thePlacements.push_back( pl );
00200
00201 #ifdef G4VERBOSE
00202 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00203 {
00204 G4cout << " G4tgrVolume: New placement replica: " << thePlacements.size()
00205 << " added for Volume " << theName
00206 << " inside " << pl->GetParentName() << G4endl;
00207 }
00208 #endif
00209
00210 G4tgrVolumeMgr::GetInstance()->RegisterParentChild( pl->GetParentName(), pl );
00211
00212 return pl;
00213 }
00214
00215
00216
00217 G4tgrPlaceParameterisation*
00218 G4tgrVolume::AddPlaceParam( const std::vector<G4String>& wl )
00219 {
00220
00221 G4tgrPlaceParameterisation* pl = new G4tgrPlaceParameterisation( wl );
00222
00223 pl->SetVolume( this );
00224 thePlacements.push_back( pl );
00225
00226 #ifdef G4VERBOSE
00227 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00228 {
00229 G4cout << " G4tgrVolume: New placement Param: " << thePlacements.size()
00230 << " added for Volume " << theName
00231 << " inside " << pl->GetParentName() << G4endl;
00232 }
00233 #endif
00234
00235 G4tgrVolumeMgr::GetInstance()->RegisterParentChild( pl->GetParentName(), pl );
00236
00237 return pl;
00238 }
00239
00240
00241
00242 void G4tgrVolume::AddVisibility( const std::vector<G4String>& wl )
00243 {
00244
00245 G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_EQ, " G4tgrVolume::AddVisibility");
00246
00247
00248 theVisibility = G4tgrUtils::GetBool( wl[2] );
00249 }
00250
00251
00252
00253 void G4tgrVolume::AddRGBColour( const std::vector<G4String>& wl )
00254 {
00255
00256 G4tgrUtils::CheckWLsize( wl, 5, WLSIZE_GE, " G4tgrVolume::AddRGBColour");
00257
00258
00259 theRGBColour[0] = G4tgrUtils::GetDouble( wl[2] );
00260 theRGBColour[1] = G4tgrUtils::GetDouble( wl[3] );
00261 theRGBColour[2] = G4tgrUtils::GetDouble( wl[4] );
00263 if( wl.size() == 6 )
00264 {
00265 theRGBColour[3] = G4tgrUtils::GetDouble( wl[5] );
00266 }
00267 }
00268
00269
00270
00271 void G4tgrVolume::AddCheckOverlaps( const std::vector<G4String>& wl )
00272 {
00273
00274 G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_GE, " G4tgrVolume::AddCheckOverlaps");
00275
00277 theCheckOverlaps = G4tgrUtils::GetBool( wl[2] );
00278
00279 }
00280
00281
00282
00283 std::ostream& operator<<(std::ostream& os, const G4tgrVolume& obj)
00284 {
00285 os << "G4tgrVolume= " << obj.theName << " Type= " << obj.theType
00286 << " Material= " << obj.theMaterialName
00287 << " Visibility " << obj.theVisibility
00288 << " Colour " << (obj.theRGBColour)[0] << " "
00289 << (obj.theRGBColour)[1] << " "
00290 << (obj.theRGBColour)[2] << " "
00291 << (obj.theRGBColour)[3] << " "
00292 << " CheckOverlaps " << obj.theCheckOverlaps
00293 << " N placements " << obj.thePlacements.size() << G4endl;
00294
00295 return os;
00296 }