| [233] | 1 | // this :
|
|---|
| 2 | #include <G4Lab/PhysicalVolumeAccessor.h>
|
|---|
| 3 |
|
|---|
| 4 | // Inventor :
|
|---|
| 5 | #include <Inventor/nodes/SoSeparator.h>
|
|---|
| 6 |
|
|---|
| 7 | #ifdef WIN32
|
|---|
| 8 | #undef pascal // Clash between windef.h and Geant4/SystemOfUnits.hh
|
|---|
| 9 | #endif
|
|---|
| 10 |
|
|---|
| 11 | // Geant4 :
|
|---|
| 12 | #include <G4VPhysicalVolume.hh>
|
|---|
| 13 | #include <G4LogicalVolume.hh>
|
|---|
| 14 | #include <G4PhysicalVolumeStore.hh>
|
|---|
| 15 | #include <G4TransportationManager.hh>
|
|---|
| 16 | #include <G4Navigator.hh>
|
|---|
| 17 |
|
|---|
| 18 | // Lib :
|
|---|
| 19 | #include <Slash/Core/ISession.h>
|
|---|
| 20 | #include <Slash/Data/IIterator.h>
|
|---|
| 21 | #include <Lib/Out.h>
|
|---|
| 22 | #include <Lib/Value.h>
|
|---|
| 23 | #include <Lib/smanip.h>
|
|---|
| 24 |
|
|---|
| 25 | // G4Lab :
|
|---|
| 26 | #include <G4Lab/GeometryVisitor.h>
|
|---|
| 27 | #include <G4Lab/SoVisitedVolume.h>
|
|---|
| 28 |
|
|---|
| 29 | #define UNLIMITED (-1)
|
|---|
| 30 |
|
|---|
| 31 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 32 | G4Lab::PhysicalVolumeAccessor::PhysicalVolumeAccessor(
|
|---|
| 33 | Slash::Core::ISession& aSession
|
|---|
| 34 | )
|
|---|
| 35 | :OnX::InventorAccessor(aSession)
|
|---|
| 36 | ,fType("PV")
|
|---|
| 37 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 38 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 39 | {
|
|---|
| 40 | //addProperty("id",Lib::Property::POINTER);
|
|---|
| 41 | addProperty("name",Lib::Property::STRING);
|
|---|
| 42 | addProperty("daughters",Lib::Property::INTEGER);
|
|---|
| 43 | }
|
|---|
| 44 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 45 | G4Lab::PhysicalVolumeAccessor::~PhysicalVolumeAccessor(
|
|---|
| 46 | )
|
|---|
| 47 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 48 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 49 | {
|
|---|
| 50 | }
|
|---|
| 51 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 52 | std::string G4Lab::PhysicalVolumeAccessor::name(
|
|---|
| 53 | ) const
|
|---|
| 54 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 55 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 56 | {
|
|---|
| 57 | return fType;
|
|---|
| 58 | }
|
|---|
| 59 | namespace G4Lab {
|
|---|
| 60 | class PhysicalVolumeIterator : public virtual Slash::Data::IIterator {
|
|---|
| 61 | public: //Slash::Data::IIterator
|
|---|
| 62 | virtual Slash::Data::IAccessor::Data object() {
|
|---|
| 63 | if(fIterator==fVector.end()) return 0;
|
|---|
| 64 | return *fIterator;
|
|---|
| 65 | }
|
|---|
| 66 | virtual void next() { ++fIterator; }
|
|---|
| 67 | virtual void* tag() { return 0;}
|
|---|
| 68 | public:
|
|---|
| 69 | PhysicalVolumeIterator(G4PhysicalVolumeStore& aVector):fVector(aVector) {
|
|---|
| 70 | fIterator = fVector.begin();
|
|---|
| 71 | }
|
|---|
| 72 | virtual ~PhysicalVolumeIterator() {}
|
|---|
| 73 | private:
|
|---|
| 74 | G4PhysicalVolumeStore& fVector;
|
|---|
| 75 | G4PhysicalVolumeStore::iterator fIterator;
|
|---|
| 76 | };
|
|---|
| 77 | }
|
|---|
| 78 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 79 | Slash::Data::IIterator* G4Lab::PhysicalVolumeAccessor::iterator(
|
|---|
| 80 | )
|
|---|
| 81 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 82 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 83 | {
|
|---|
| 84 | G4PhysicalVolumeStore* pvStore = G4PhysicalVolumeStore::GetInstance();
|
|---|
| 85 | if(!pvStore) {
|
|---|
| 86 | Lib::Out out(fSession.printer());
|
|---|
| 87 | out << "No physical volume store." << Lib::endl;
|
|---|
| 88 | return 0;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | return new PhysicalVolumeIterator(*pvStore);
|
|---|
| 92 | }
|
|---|
| 93 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 94 | Slash::Core::IValue* G4Lab::PhysicalVolumeAccessor::findValue(
|
|---|
| 95 | Slash::Data::IAccessor::Data aData
|
|---|
| 96 | ,const std::string& aName
|
|---|
| 97 | ,void*
|
|---|
| 98 | )
|
|---|
| 99 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 100 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 101 | {
|
|---|
| 102 | G4VPhysicalVolume* obj = (G4VPhysicalVolume*)aData;
|
|---|
| 103 | //if(aName=="id") {
|
|---|
| 104 | // return new Lib::Value((void*)obj);
|
|---|
| 105 | //} else
|
|---|
| 106 | if(aName=="name") {
|
|---|
| 107 | return new Lib::Value(obj->GetName());
|
|---|
| 108 | } else if(aName=="daughters") {
|
|---|
| 109 | G4LogicalVolume* logicalVolume = obj->GetLogicalVolume();
|
|---|
| 110 | return new Lib::Value(logicalVolume->GetNoDaughters());
|
|---|
| 111 | } else {
|
|---|
| 112 | return new Lib::Value();
|
|---|
| 113 | }
|
|---|
| 114 | }
|
|---|
| 115 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 116 | void G4Lab::PhysicalVolumeAccessor::visualize(
|
|---|
| 117 | Slash::Data::IAccessor::Data aData
|
|---|
| 118 | ,void*
|
|---|
| 119 | )
|
|---|
| 120 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 121 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 122 | {
|
|---|
| 123 | G4TransportationManager* tsp =
|
|---|
| 124 | G4TransportationManager::GetTransportationManager();
|
|---|
| 125 | if(!tsp) return;
|
|---|
| 126 | G4Navigator* nav = tsp->GetNavigatorForTracking();
|
|---|
| 127 | if(!nav) return;
|
|---|
| 128 | G4VPhysicalVolume* top = nav->GetWorldVolume();
|
|---|
| 129 | if(!top) return;
|
|---|
| 130 |
|
|---|
| 131 | G4VPhysicalVolume* obj = (G4VPhysicalVolume*)aData;
|
|---|
| 132 |
|
|---|
| 133 | //Get a style corresponding to PV type.
|
|---|
| 134 | {std::string s = obj->GetName();
|
|---|
| 135 | Lib::smanip::strip(s);
|
|---|
| 136 | std::string style = "PV("+s+")";
|
|---|
| 137 | if(!isStyle(style)) {
|
|---|
| 138 | style = "PV_"+s; //Backward compatibility.
|
|---|
| 139 | if(!isStyle(style)) {
|
|---|
| 140 | style = "PV"; //Default.
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|
| 143 | fillSoGC(style);}
|
|---|
| 144 |
|
|---|
| 145 | SoSeparator* separator = new SoSeparator;
|
|---|
| 146 |
|
|---|
| 147 | SoVisitedVolume soVisitedVolume(fSoGC,*separator,*obj);
|
|---|
| 148 |
|
|---|
| 149 | // WARNING : it may produces more than one scene object.
|
|---|
| 150 | // (Because the same PV may be found more than once in the
|
|---|
| 151 | // Geant4 geometry tree).
|
|---|
| 152 | GeometryVisitor geometryVisitor;
|
|---|
| 153 | G4Transform3D identity; //WIN32.
|
|---|
| 154 | geometryVisitor.visit(top,UNLIMITED,identity,&soVisitedVolume);
|
|---|
| 155 |
|
|---|
| 156 | // Send scene graph to the viewing region :
|
|---|
| 157 | if(separator->getNumChildren()) {
|
|---|
| 158 | fSoRegion->doIt(SbAddNode(separator,"staticScene"));
|
|---|
| 159 | } else {
|
|---|
| 160 | separator->unref();
|
|---|
| 161 | }
|
|---|
| 162 | }
|
|---|