| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

GiGaSetVisAttributes.cpp

Go to the documentation of this file.
00001 // $Id: GiGaSetVisAttributes.cpp,v 1.3 2007/01/12 15:48:35 ranjard Exp $
00002 // Include files 
00003 
00004 // from Gaudi
00005 #include "GaudiKernel/DeclareFactoryEntries.h" 
00006 #include "GaudiKernel/IDataProviderSvc.h"
00007 #include "GaudiKernel/SmartDataPtr.h"
00008 
00009 // DetDesc
00010 #include "DetDesc/ILVolume.h" 
00011 // VisSvc
00012 #include "VisSvc/IVisualizationSvc.h"
00013 // Geant4 
00014 #include "G4VisAttributes.hh"
00015 #include "G4LogicalVolume.hh"
00016 #include "G4LogicalVolumeStore.hh"
00017 // GiGa
00018 //#include "GiGa/GiGaMACROs.h"
00019 // local 
00020 #include "GiGaSetVisAttributes.h"
00021 
00029 // Declaration of the Tool Factory
00030 DECLARE_TOOL_FACTORY( GiGaSetVisAttributes );
00031 
00032 // ============================================================================
00041 // ============================================================================
00042 GiGaSetVisAttributes::GiGaSetVisAttributes
00043 ( const std::string& type   , 
00044   const std::string& name   , 
00045   const IInterface*  parent ) 
00046   : GiGaToolBase   ( type , name , parent ) 
00047   , m_visSvcName   ( "VisualizationSvc"   ) 
00048   , m_visSvc       ( 0                    ) 
00049 {
00050   declareProperty ( "VisualizationService" , m_visSvcName ) ;
00051 };
00052 // ============================================================================
00053 
00054 
00055 // ============================================================================
00057 // ============================================================================
00058 GiGaSetVisAttributes::~GiGaSetVisAttributes(){};
00059 // ============================================================================
00060 
00061 // ============================================================================
00069 // ============================================================================
00070 StatusCode   GiGaSetVisAttributes::initialize  () 
00071 {
00072   StatusCode sc = GiGaToolBase::initialize () ;
00073   if( sc.isFailure() ) { return Error("GiGaToolBase is not initilized!",sc);}
00074   
00075   if( 0 == detSvc() ) 
00076     { return Error("IDataProviderSvc*(detSvc()) points ti NULL!"); }
00077   
00078   // get the service 
00079   if( 0 != m_visSvc ) { m_visSvc -> release () ; m_visSvc = 0 ; }
00080   sc = service( m_visSvcName , m_visSvc , true );
00081   if( sc.isFailure() ) 
00082     { return Error("IVisualizationSvc('"+m_visSvcName+"') is not located",sc); }
00083   if( 0 == m_visSvc || 0 == visSvc() ) 
00084     { return Error("IVisualizationSvc('"+m_visSvcName+"') is NULL " ) ; }
00085   
00086   return StatusCode::SUCCESS ;
00087 };
00088 // ============================================================================
00089 
00090 // ============================================================================
00098 // ============================================================================
00099 StatusCode   GiGaSetVisAttributes::finalize    () 
00100 {
00101   if( 0 != m_visSvc ) { m_visSvc -> release () ; m_visSvc = 0 ; }
00102   return GiGaToolBase::finalize ();
00103 };
00104 // ============================================================================
00105 
00106 // ============================================================================
00110 // ============================================================================
00111 const ILVolume* GiGaSetVisAttributes::volume
00112 ( const std::string& address ) const 
00113 {
00114   if( 0 == detSvc() ) 
00115     { Error("volume('"+address+"'): detSvc() is NULL"); return 0 ; } 
00116   SmartDataPtr<ILVolume> logvol( detSvc() , address ) ;
00117   return logvol ;
00118 };
00119 
00120 // ============================================================================
00124 // ============================================================================
00125 G4LogicalVolume* GiGaSetVisAttributes::g4volume         
00126 ( const std::string& address ) const 
00127 {
00128   const G4LogicalVolumeStore* store = G4LogicalVolumeStore::GetInstance();
00129   if( 0 == store ) 
00130   {
00131     Error ( "g4volume('" + address + "'): G4LogicalVolumeStore* is NULL!" ) ;
00132     return 0 ;
00133   }
00134   for( G4LogicalVolumeStore::const_iterator ivolume = 
00135          store -> begin() ; store->end() != ivolume ; ++ivolume ) 
00136   {
00137     G4LogicalVolume* vol = *ivolume ;
00138     if( 0 != vol ) {
00139       std::string G4VolName = vol->GetName();
00140       if (G4VolName == address ) { return vol ; }
00141     }
00142   }
00143   Error ( "g4volume('" + address + "'): volume is not found!" ) ;
00144   return 0 ;
00145 };
00146 // ============================================================================
00147 
00148 // ============================================================================
00154 // ============================================================================
00155 StatusCode GiGaSetVisAttributes::process ( const std::string& vol ) const 
00156 {
00157   if( 0 == detSvc () ) 
00158     { return Error( " process('" + vol + "'): detSvc () is NULL! " ) ; }
00159   if( 0 == visSvc () )
00160     { return Error( " process('" + vol + "'): visSvc () is NULL! " ) ; }
00161   
00162   // for all volumes 
00163   if( vol.empty() || "All" == vol || "ALL" == vol || "all" == vol ) 
00164     {
00165       const G4LogicalVolumeStore* store = G4LogicalVolumeStore::GetInstance();
00166       if( 0 == store ) 
00167         { return Error( " process('" + vol + 
00168                         "'): G4LogicalVolumeStore* is invalid" ) ; }
00169       for( G4LogicalVolumeStore::const_iterator ivolume = 
00170              store -> begin() ; store -> end() != ivolume ; ++ivolume ) 
00171         {
00172           G4LogicalVolume* vol = *ivolume ;
00173           if( 0 != vol ) { process( vol->GetName() ) ;  }
00174         }
00175       return StatusCode::SUCCESS ;
00176     };
00177   
00178   G4LogicalVolume* g4lv = g4volume ( vol ) ;
00179   if ( 0 == g4lv ) 
00180     { return Error( " process('" + vol + "'): invald G4LogicalVolume " ) ; }
00181   const ILVolume*    lv = volume   ( vol ) ;
00182   if( 0 == lv ) 
00183     { return Error( " process('" + vol + "'): invalid ILVolume "       ) ; }
00184   
00185   const VisAttribute va =  visSvc()-> visAttribute( lv ) ;
00186   
00187   static const VisAttribute s_def = VisAttribute () ;
00188   if( s_def.visible       () != va.visible       () || 
00189       s_def.openStatus    () != va.openStatus    () || 
00190       s_def.displayMode   () != va.displayMode   () || 
00191       s_def.color().red   () != va.color().red   () ||
00192       s_def.color().green () != va.color().green () ||
00193       s_def.color().blue  () != va.color().red   () ||
00194       s_def.color().alpha () != va.color().alpha ()  )
00195     {
00196       // create new attribute 
00197       G4VisAttributes* g4va = new G4VisAttributes () ;
00198       
00199       if      ( VisAttribute::VISIBLE     == va.visible     () ) 
00200         { g4va -> SetVisibility         ( true  ) ; }
00201       else if ( VisAttribute::NOT_VISIBLE == va.visible     () ) 
00202         { g4va -> SetVisibility         ( false ) ; }
00203       
00204       if      ( VisAttribute::OPENED      == va.openStatus  () )
00205         { g4va -> SetDaughtersInvisible ( false ) ; }
00206       else if ( VisAttribute::CLOSED      == va.openStatus  () )
00207         { g4va -> SetDaughtersInvisible ( true  ) ; }
00208       
00209       if      ( VisAttribute::PLAIN       == va.displayMode () )
00210         { g4va -> SetDaughtersInvisible ( true  ) ; }
00211       else if ( VisAttribute::WIRE_FRAME  == va.displayMode () )
00212         { g4va -> SetForceWireframe     ( true  ) ; }
00213       
00214       g4va -> SetColor( va.color () .red   () , 
00215                         va.color () .green () , 
00216                         va.color () .blue  () , 
00217                         va.color () .alpha () ) ;
00218       
00219       // set visualization attributes 
00220       g4lv -> SetVisAttributes( g4va ) ;
00221     }
00222   
00223   return StatusCode::SUCCESS ;
00224 };
00225 
00226 
00227 // ============================================================================
00228 // The END 
00229 // ============================================================================
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:01:38 2011 for GiGaVisUI by doxygen 1.4.7