[807] | 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 | // File name: RadmonVDetectorLabelledEntityConstructor.cc |
---|
| 28 | // Creation date: Sep 2005 |
---|
| 29 | // Main author: Riccardo Capra <capra@ge.infn.it> |
---|
| 30 | // |
---|
| 31 | // Id: $Id: RadmonVDetectorLabelledEntityConstructor.cc,v 1.7 2006/06/29 16:14:13 gunter Exp $ |
---|
| 32 | // Tag: $Name: $ |
---|
| 33 | // |
---|
| 34 | |
---|
| 35 | // Include files |
---|
| 36 | #include "RadmonVDetectorLabelledEntityConstructor.hh" |
---|
| 37 | #include "RadmonTokenizer.hh" |
---|
| 38 | #include "RadmonMaterialsManager.hh" |
---|
| 39 | #include "RadmonSensitiveDetector.hh" |
---|
| 40 | #include "G4SDManager.hh" |
---|
| 41 | #include "G4UIcommand.hh" |
---|
| 42 | #include "G4VisAttributes.hh" |
---|
| 43 | #include "globals.hh" |
---|
| 44 | |
---|
| 45 | G4double RadmonVDetectorLabelledEntityConstructor :: GetWidth(void) const |
---|
| 46 | { |
---|
| 47 | G4double value(GetAttributeAsMeasure("_WIDTH", "Length", -1.)); |
---|
| 48 | |
---|
| 49 | if (value>=0) |
---|
| 50 | return value; |
---|
| 51 | |
---|
| 52 | value=GetAttributeAsMeasure("Width", "Length", -1.); |
---|
| 53 | |
---|
| 54 | if (value>=0) |
---|
| 55 | return value; |
---|
| 56 | |
---|
| 57 | G4cout << "RadmonVDetectorLabelledEntityConstructor::GetWidth: \"Width\" attribute not defined." << G4endl; |
---|
| 58 | return -1; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | G4double RadmonVDetectorLabelledEntityConstructor :: GetHeight(void) const |
---|
| 64 | { |
---|
| 65 | G4double value(GetAttributeAsMeasure("_HEIGHT", "Length", -1.)); |
---|
| 66 | |
---|
| 67 | if (value>=0) |
---|
| 68 | return value; |
---|
| 69 | |
---|
| 70 | value=GetAttributeAsMeasure("Height", "Length", -1.); |
---|
| 71 | |
---|
| 72 | if (value>=0) |
---|
| 73 | return value; |
---|
| 74 | |
---|
| 75 | G4cout << "RadmonVDetectorLabelledEntityConstructor::GetHeight: \"Height\" attribute not defined." << G4endl; |
---|
| 76 | return -1; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | G4double RadmonVDetectorLabelledEntityConstructor :: GetThickness(void) const |
---|
| 82 | { |
---|
| 83 | G4double value(GetAttributeAsMeasure("_THICKNESS", "Length", -1.)); |
---|
| 84 | |
---|
| 85 | if (value>=0) |
---|
| 86 | return value; |
---|
| 87 | |
---|
| 88 | value=GetAttributeAsMeasure("Thickness", "Length", -1.); |
---|
| 89 | |
---|
| 90 | if (value>=0) |
---|
| 91 | return value; |
---|
| 92 | |
---|
| 93 | G4cout << "RadmonVDetectorLabelledEntityConstructor::GetThickness: \"Thickness\" attribute not defined." << G4endl; |
---|
| 94 | return -1; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | G4Material * RadmonVDetectorLabelledEntityConstructor :: GetMaterial(const G4String & attributeName) const |
---|
| 102 | { |
---|
| 103 | G4String materialStr(GetAttribute(attributeName, "#")); |
---|
| 104 | if (materialStr=="#") |
---|
| 105 | { |
---|
| 106 | G4cout << "RadmonDetectorSimpleBoxConstructor::ConstructLogicalVolume: \"" << attributeName << "\" attribute not defined." << G4endl; |
---|
| 107 | return 0; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | RadmonMaterialsManager * manager(RadmonMaterialsManager::Instance()); |
---|
| 111 | if (!manager->ExistsMaterial(materialStr)) |
---|
| 112 | { |
---|
| 113 | G4cout << "RadmonDetectorSimpleBoxConstructor::ConstructLogicalVolume: \"" << materialStr << "\" material not existent." << G4endl; |
---|
| 114 | return 0; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | return &manager->GetMaterial(materialStr); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | G4VisAttributes * RadmonVDetectorLabelledEntityConstructor :: AllocateVisAttributes(const G4String & attributeName, const G4Material * material) const |
---|
| 125 | { |
---|
| 126 | G4VisAttributes * visAttribute=new G4VisAttributes; |
---|
| 127 | |
---|
| 128 | G4String materialName(material->GetName()); |
---|
| 129 | |
---|
| 130 | RadmonMaterialsManager * instance(RadmonMaterialsManager::Instance()); |
---|
| 131 | |
---|
| 132 | visAttribute->SetColor(instance->GetMaterialColor(materialName)); |
---|
| 133 | visAttribute->SetVisibility(instance->GetMaterialVisibility(materialName)); |
---|
| 134 | if (instance->GetMaterialForceSolid(materialName)) |
---|
| 135 | visAttribute->SetForceSolid(true); |
---|
| 136 | else if (instance->GetMaterialForceWireframe(materialName)) |
---|
| 137 | visAttribute->SetForceWireframe(true); |
---|
| 138 | |
---|
| 139 | G4String str; |
---|
| 140 | str=GetAttribute(attributeName, "#"); |
---|
| 141 | if (str!="#") |
---|
| 142 | { |
---|
| 143 | G4String arg; |
---|
| 144 | RadmonTokenizer args(str); |
---|
| 145 | |
---|
| 146 | G4bool forceSolid(visAttribute->GetForcedDrawingStyle()==G4VisAttributes::solid && visAttribute->IsForceDrawingStyle()); |
---|
| 147 | G4bool forceWireframe(visAttribute->GetForcedDrawingStyle()==G4VisAttributes::wireframe && visAttribute->IsForceDrawingStyle()); |
---|
| 148 | G4bool visible(visAttribute->IsVisible()); |
---|
| 149 | G4double alpha(visAttribute->GetColor().GetAlpha()); |
---|
| 150 | G4double red(visAttribute->GetColor().GetRed()); |
---|
| 151 | G4double green(visAttribute->GetColor().GetGreen()); |
---|
| 152 | G4double blue(visAttribute->GetColor().GetBlue()); |
---|
| 153 | |
---|
| 154 | G4bool forceFound(false); |
---|
| 155 | G4bool visibleFound(false); |
---|
| 156 | G4int missingColors(4); |
---|
| 157 | |
---|
| 158 | for (G4int i(0); i<6; i++) |
---|
| 159 | { |
---|
| 160 | if (args.eos()) |
---|
| 161 | break; |
---|
| 162 | |
---|
| 163 | arg=args(); |
---|
| 164 | |
---|
| 165 | if (arg=="hidden" || arg=="visible") |
---|
| 166 | { |
---|
| 167 | if (visibleFound || missingColors==2 || missingColors==3) |
---|
| 168 | { |
---|
| 169 | missingColors=-1; |
---|
| 170 | break; |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | visibleFound=true; |
---|
| 174 | |
---|
| 175 | visible=(arg=="visible"); |
---|
| 176 | } |
---|
| 177 | else if (arg=="wireframe" || arg=="solid" || arg=="default") |
---|
| 178 | { |
---|
| 179 | if (forceFound || missingColors==2 || missingColors==3) |
---|
| 180 | { |
---|
| 181 | missingColors=-1; |
---|
| 182 | break; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | forceFound=true; |
---|
| 186 | |
---|
| 187 | forceWireframe=(arg=="wireframe"); |
---|
| 188 | forceSolid=(arg=="solid"); |
---|
| 189 | } |
---|
| 190 | else |
---|
| 191 | { |
---|
| 192 | G4double component(G4UIcommand::ConvertToDouble(arg)); |
---|
| 193 | if (component>1 || component<0 || missingColors==0) |
---|
| 194 | { |
---|
| 195 | missingColors=-1; |
---|
| 196 | break; |
---|
| 197 | } |
---|
| 198 | else |
---|
| 199 | { |
---|
| 200 | switch(missingColors) |
---|
| 201 | { |
---|
| 202 | case 4: |
---|
| 203 | red=component; |
---|
| 204 | break; |
---|
| 205 | |
---|
| 206 | case 3: |
---|
| 207 | green=component; |
---|
| 208 | break; |
---|
| 209 | |
---|
| 210 | case 2: |
---|
| 211 | blue=component; |
---|
| 212 | break; |
---|
| 213 | |
---|
| 214 | case 1: |
---|
| 215 | alpha=component; |
---|
| 216 | break; |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | missingColors--; |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | if (missingColors!=0 && missingColors!=4 && missingColors!=1) |
---|
| 225 | G4cout << "RadmonVDetectorLabelledEntityConstructor::AllocateVisAttribute: Invalid visualization attribute in \"" << attributeName << "\"." << G4endl; |
---|
| 226 | else |
---|
| 227 | { |
---|
| 228 | visAttribute->SetColor(red, green, blue, alpha); |
---|
| 229 | visAttribute->SetVisibility(visible); |
---|
| 230 | if (forceWireframe) |
---|
| 231 | visAttribute->SetForceWireframe(true); |
---|
| 232 | else if (forceSolid) |
---|
| 233 | visAttribute->SetForceSolid(true); |
---|
| 234 | } |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | return visAttribute; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | |
---|
| 241 | |
---|
| 242 | |
---|
| 243 | |
---|
| 244 | G4VSensitiveDetector * RadmonVDetectorLabelledEntityConstructor :: AllocateSensitiveDetector(const G4String & attributeName, const G4String & defaultAttrbuteValue) const |
---|
| 245 | { |
---|
| 246 | G4String name(GetAttribute(attributeName, defaultAttrbuteValue)); |
---|
| 247 | |
---|
| 248 | if (name.empty()) |
---|
| 249 | return 0; |
---|
| 250 | |
---|
| 251 | G4SDManager * manager(G4SDManager::GetSDMpointer()); |
---|
| 252 | |
---|
| 253 | G4VSensitiveDetector * sensitiveDetector(manager->FindSensitiveDetector(name, false)); |
---|
| 254 | |
---|
| 255 | if (sensitiveDetector) |
---|
| 256 | return sensitiveDetector; |
---|
| 257 | |
---|
| 258 | return new RadmonSensitiveDetector(name); |
---|
| 259 | } |
---|
| 260 | |
---|