00001
00002
00003 #include "VisGeant4/VisG4Volumes/interface/VisG4GeometryTwig.h"
00004 #include "VisGeant4/VisG4Volumes/interface/VisG4VolumeTwig.h"
00005 #include "VisGeant4/VisG4Volumes/interface/VisG4Navigator.h"
00006 #include "VisGeant4/VisG4Core/interface/VisG4VisManager.h"
00007 #include "Iguana/Framework/interface/IgRepSet.h"
00008 #include <G4TransportationManager.hh>
00009 #include <G4LogicalVolumeStore.hh>
00010 #include <G4VPhysicalVolume.hh>
00011 #include <G4VisAttributes.hh>
00012 #include <set>
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 VisG4GeometryTwig::VisG4GeometryTwig (VisG4VisManager *visManager, IgTwig *parent)
00027 : IgSimpleTwig (parent, "Detector", true, true, true)
00028 { visManager->notify (lat::CreateCallback (this, &VisG4GeometryTwig::update)); }
00029
00030 void
00031 VisG4GeometryTwig::update (void)
00032 {
00033 destroy ();
00034
00035 G4VPhysicalVolume *world
00036 = G4TransportationManager::GetTransportationManager ()
00037 ->GetNavigatorForTracking ()->GetWorldVolume ();
00038
00039 if (! world)
00040 return;
00041
00042
00043 ASSERT (world->GetLogicalVolume ());
00044 ASSERT (! world->IsReplicated ());
00045 VisG4Navigator::build (1, world, new VisG4VolumeTwig
00046 (this, world, true, false, true));
00047
00048
00049
00050
00051
00052
00053
00054
00055 std::set<G4VisAttributes *> seen;
00056 G4LogicalVolumeStore *volumes = G4LogicalVolumeStore::GetInstance ();
00057 for (unsigned i = 0; i < volumes->size (); ++i)
00058 {
00059 G4LogicalVolume *volume = (*volumes) [i];
00060 G4VisAttributes *attrs = const_cast<G4VisAttributes *>
00061 (volume->GetVisAttributes ());
00062
00063 if (! attrs)
00064 volume->SetVisAttributes (attrs = new G4VisAttributes);
00065
00066 if (seen.count (attrs))
00067 volume->SetVisAttributes (attrs = new G4VisAttributes (*attrs));
00068
00069 seen.insert (attrs);
00070 }
00071
00072
00073 IgRepSet::invalidate (this, STRUCTURE_MASK | SELF_MASK);
00074 }