G4VRML2SceneHandler.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // G4VRML2SceneHandler.cc
00030 // Satoshi Tanaka & Yasuhide Sawada
00031 
00032 #ifndef WIN32
00033 
00034 
00035 //=================//
00036 #ifdef G4VIS_BUILD_VRML_DRIVER
00037 //=================//
00038 
00039 
00040 //#define DEBUG_FR_SCENE
00041 
00042 #include <unistd.h>
00043 #include <fstream>
00044 #include <cmath>
00045 
00046 #include "globals.hh"
00047 #include "G4VisManager.hh"
00048 
00049 #include "G4VPhysicalVolume.hh"
00050 #include "G4LogicalVolume.hh"
00051 #include "G4Point3D.hh"
00052 #include "G4VModel.hh"
00053 #include "G4Scene.hh"
00054 #include "G4VisAttributes.hh"
00055 #include "G4Polyhedron.hh"
00056 #include "G4Box.hh"
00057 #include "G4Cons.hh"
00058 #include "G4Polyline.hh"
00059 #include "G4Trd.hh"
00060 #include "G4Tubs.hh"
00061 #include "G4Text.hh"
00062 #include "G4Circle.hh"
00063 #include "G4Square.hh"
00064 
00065 #include "G4VRML2SceneHandler.hh"
00066 #include "G4VRML2Viewer.hh"
00067 #include "G4VRML2.hh"
00068 
00069 
00070 
00071 G4VRML2SceneHandler::G4VRML2SceneHandler(G4VRML2& system, const G4String& name) :
00072         G4VSceneHandler(system, fSceneIdCount++, name),
00073         fSystem(system),
00074         fPVPickable ( false ), 
00075         fDest()
00076 {
00077         
00078         // PV name pickability  
00079         if( getenv( "G4VRML_PV_PICKABLE" ) != NULL ) {
00080 
00081                 int is_pickable ;
00082                 sscanf( getenv("G4VRML_PV_PICKABLE"), "%d", &is_pickable ) ;
00083 
00084                 if ( is_pickable ) { SetPVPickability ( true ) ; }
00085         } 
00086         
00087         // PV Transparency
00088         SetPVTransparency ();
00089 
00090 }
00091 
00092 
00093 G4VRML2SceneHandler::~G4VRML2SceneHandler()
00094 {
00095 #if defined DEBUG_FR_SCENE
00096   if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00097         G4cout << "***** ~G4VRML2SceneHandler" << G4endl;
00098 #endif 
00099 }
00100 
00101 
00102 
00103 #define  G4VRML2SCENEHANDLER   G4VRML2SceneHandler
00104 #define  IS_CONNECTED  fDest.isConnected() 
00105 #include "G4VRML2SceneHandlerFunc.icc"
00106 #undef   IS_CONNECTED
00107 #undef   G4VRML2SCENEHANDLER
00108 
00109 
00110 void G4VRML2SceneHandler::connectPort(G4int max_trial)
00111 {
00112         G4int trial = 0 ;
00113         int port = fSystem.getPort();
00114         for (trial = 0; !fDest.isConnected()&& trial < max_trial; trial++, port++ ) {
00115                 if (fDest.connect( (const char * )fSystem.getHostName(), port)) {
00116                     // INET domain connection is established
00117                   if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
00118                         G4cout << "*** GEANT4 is connected to port  ";
00119                         G4cout << fDest.getPort(); 
00120                         G4cout << " of server  " << fSystem.getHostName() << G4endl;
00121                   }
00122                         break; 
00123                 } else { 
00124                         // Connection failed. Try the next port.
00125                   if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
00126                         G4cout << "*** GEANT4 incremented targeting port to ";
00127                         G4cout << port << G4endl;
00128                   }
00129                 }
00130 
00131                 sleep (1);
00132 
00133         } // for
00134 
00135         if (!fDest.isConnected()) {
00136           if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
00137                 G4cout << "*** INET Connection failed. " << G4endl;
00138                 G4cout << "    Maybe, you have not invoked viewer  g4vrmlview  yet, " << G4endl;
00139                 G4cout << "    or too many viewers are already running in the " << G4endl;
00140                 G4cout << "    server host(" << fSystem.getHostName() << "). " << G4endl;
00141           }
00142         }
00143 }
00144 
00145 void G4VRML2SceneHandler::closePort()
00146 {
00147         fDest.close();
00148         if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00149               G4cout << "*** INET Connection closed. " << G4endl;
00150 }
00151 
00152 
00153 G4int G4VRML2SceneHandler::fSceneIdCount = 0;
00154 
00155 #endif
00156 #endif //WIN32

Generated on Mon May 27 17:50:21 2013 for Geant4 by  doxygen 1.4.7