Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VRML2SceneHandler.cc
Go to the documentation of this file.
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 // $Id: G4VRML2SceneHandler.cc 66373 2012-12-18 09:41:34Z gcosmo $
28 //
29 // G4VRML2SceneHandler.cc
30 // Satoshi Tanaka & Yasuhide Sawada
31 
32 #ifndef WIN32
33 
34 
35 //=================//
36 #ifdef G4VIS_BUILD_VRML_DRIVER
37 //=================//
38 
39 
40 //#define DEBUG_FR_SCENE
41 
42 #include <unistd.h>
43 #include <fstream>
44 #include <cmath>
45 
46 #include "globals.hh"
47 #include "G4VisManager.hh"
48 
49 #include "G4VPhysicalVolume.hh"
50 #include "G4LogicalVolume.hh"
51 #include "G4Point3D.hh"
52 #include "G4VModel.hh"
53 #include "G4Scene.hh"
54 #include "G4VisAttributes.hh"
55 #include "G4Polyhedron.hh"
56 #include "G4Box.hh"
57 #include "G4Cons.hh"
58 #include "G4Polyline.hh"
59 #include "G4Trd.hh"
60 #include "G4Tubs.hh"
61 #include "G4Text.hh"
62 #include "G4Circle.hh"
63 #include "G4Square.hh"
64 
65 #include "G4VRML2SceneHandler.hh"
66 #include "G4VRML2Viewer.hh"
67 #include "G4VRML2.hh"
68 
69 
70 
71 G4VRML2SceneHandler::G4VRML2SceneHandler(G4VRML2& system, const G4String& name) :
72  G4VSceneHandler(system, fSceneIdCount++, name),
73  fSystem(system),
74  fPVPickable ( false ),
75  fDest()
76 {
77 
78  // PV name pickability
79  if( getenv( "G4VRML_PV_PICKABLE" ) != NULL ) {
80 
81  int is_pickable ;
82  sscanf( getenv("G4VRML_PV_PICKABLE"), "%d", &is_pickable ) ;
83 
84  if ( is_pickable ) { SetPVPickability ( true ) ; }
85  }
86 
87  // PV Transparency
88  SetPVTransparency ();
89 
90 }
91 
92 
93 G4VRML2SceneHandler::~G4VRML2SceneHandler()
94 {
95 #if defined DEBUG_FR_SCENE
97  G4cout << "***** ~G4VRML2SceneHandler" << G4endl;
98 #endif
99 }
100 
101 
102 
103 #define G4VRML2SCENEHANDLER G4VRML2SceneHandler
104 #define IS_CONNECTED fDest.isConnected()
105 #include "G4VRML2SceneHandlerFunc.icc"
106 #undef IS_CONNECTED
107 #undef G4VRML2SCENEHANDLER
108 
109 
110 void G4VRML2SceneHandler::connectPort(G4int max_trial)
111 {
112  G4int trial = 0 ;
113  int port = fSystem.getPort();
114  for (trial = 0; !fDest.isConnected()&& trial < max_trial; trial++, port++ ) {
115  if (fDest.connect( (const char * )fSystem.getHostName(), port)) {
116  // INET domain connection is established
118  G4cout << "*** GEANT4 is connected to port ";
119  G4cout << fDest.getPort();
120  G4cout << " of server " << fSystem.getHostName() << G4endl;
121  }
122  break;
123  } else {
124  // Connection failed. Try the next port.
126  G4cout << "*** GEANT4 incremented targeting port to ";
127  G4cout << port << G4endl;
128  }
129  }
130 
131  sleep (1);
132 
133  } // for
134 
135  if (!fDest.isConnected()) {
137  G4cout << "*** INET Connection failed. " << G4endl;
138  G4cout << " Maybe, you have not invoked viewer g4vrmlview yet, " << G4endl;
139  G4cout << " or too many viewers are already running in the " << G4endl;
140  G4cout << " server host(" << fSystem.getHostName() << "). " << G4endl;
141  }
142  }
143 }
144 
145 void G4VRML2SceneHandler::closePort()
146 {
147  fDest.close();
149  G4cout << "*** INET Connection closed. " << G4endl;
150 }
151 
152 
153 G4int G4VRML2SceneHandler::fSceneIdCount = 0;
154 
155 #endif
156 #endif //WIN32
const XML_Char * name
Definition: expat.h:151
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
static Verbosity GetVerbosity()
#define G4endl
Definition: G4ios.hh:61