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 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/VRML/src/G4VRML2FileSceneHandler.cc (Version 11.3.0) and /visualization/VRML/src/G4VRML2FileSceneHandler.cc (Version 5.0.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
 26 //                                                 23 //
                                                   >>  24 // $Id: G4VRML2FileSceneHandler.cc,v 1.8 2002/06/17 10:13:48 gcosmo Exp $
                                                   >>  25 // GEANT4 tag $Name: geant4-05-00 $
 27 //                                                 26 //
 28 // G4VRML2FileSceneHandler.cc                      27 // G4VRML2FileSceneHandler.cc
 29 // Satoshi Tanaka & Yasuhide Sawada                28 // Satoshi Tanaka & Yasuhide Sawada
 30                                                    29 
                                                   >>  30 
 31 //#define DEBUG_FR_SCENE                           31 //#define DEBUG_FR_SCENE
 32                                                    32 
 33 #include <fstream>                             <<  33 #include "g4std/fstream"
 34 #include <stdio.h>                                 34 #include <stdio.h>
 35 #include <string.h>                                35 #include <string.h>
 36 #include <stdlib.h>                                36 #include <stdlib.h>
 37 #include <cmath>                               <<  37 #include <math.h>
 38 #include <sstream>                             << 
 39 #include <iomanip>                             << 
 40                                                    38 
 41 #include "globals.hh"                              39 #include "globals.hh"
 42 #include "G4VPhysicalVolume.hh"                    40 #include "G4VPhysicalVolume.hh"
 43 #include "G4LogicalVolume.hh"                      41 #include "G4LogicalVolume.hh"
 44 #include "G4VisManager.hh"                     <<  42 #include "G4Point3D.hh"
 45 #include "G4VisAttributes.hh"                      43 #include "G4VisAttributes.hh"
 46 #include "G4VModel.hh"                             44 #include "G4VModel.hh"
 47 #include "G4Scene.hh"                              45 #include "G4Scene.hh"
 48 #include "G4Polyhedron.hh"                         46 #include "G4Polyhedron.hh"
 49 #include "G4Box.hh"                                47 #include "G4Box.hh"
 50 #include "G4Cons.hh"                               48 #include "G4Cons.hh"
 51 #include "G4Polyline.hh"                           49 #include "G4Polyline.hh"
 52 #include "G4Trd.hh"                                50 #include "G4Trd.hh"
 53 #include "G4Tubs.hh"                               51 #include "G4Tubs.hh"
 54 #include "G4Text.hh"                               52 #include "G4Text.hh"
 55 #include "G4Circle.hh"                             53 #include "G4Circle.hh"
 56 #include "G4Square.hh"                             54 #include "G4Square.hh"
 57                                                    55 
 58 #include "G4VRML2FileSceneHandler.hh"              56 #include "G4VRML2FileSceneHandler.hh"
 59 #include "G4VRML2FileViewer.hh"                    57 #include "G4VRML2FileViewer.hh"
 60 #include "G4VRML2File.hh"                          58 #include "G4VRML2File.hh"
 61                                                    59 
 62 // CONST                                           60 // CONST
 63                                                    61 
 64 const char WRL_FILE_HEADER[]       = "g4_";    <<  62 const char  WRL_FILE_HEADER      [] = "g4_";
 65 const char ENV_WRL_FILE_HEADER[]   = "G4VRMLFI <<  63 const char  DEFAULT_WRL_FILE_NAME[] = "g4.wrl";
 66 const char ENV_WRL_FILE_NAME[]     = "G4VRMLFI <<  64 const char  ENV_VRML_VIEWER      [] = "G4VRMLFILE_VIEWER";
 67 const char ENV_VRML_VIEWER[]       = "G4VRMLFI <<  65 const char  NO_VRML_VIEWER       [] = "NONE";
 68 const char NO_VRML_VIEWER[]        = "NONE";   <<  66 const char  VRMLFILE_DEST_DIR    [] = "G4VRMLFILE_DEST_DIR";
 69 const char VRMLFILE_DEST_DIR[]     = "G4VRMLFI <<  67 const int   DEFAULT_MAX_WRL_FILE_NUM = 100 ;
 70 const int DEFAULT_MAX_WRL_FILE_NUM = 100;      <<  68 
 71                                                <<  69 
 72 G4VRML2FileSceneHandler::G4VRML2FileSceneHandl <<  70 G4VRML2FileSceneHandler::G4VRML2FileSceneHandler(G4VRML2File& system, const G4String& name) :
 73                                                <<  71   G4VSceneHandler(system, fSceneIdCount++, name),
 74   : G4VSceneHandler(system, fSceneIdCount++, n <<  72   fSystem(system),
 75   , fSystem(system)                            <<  73   fFlagDestOpen( false ),
 76   , fFlagDestOpen(false)                       <<  74   fPVPickable  ( false ),
 77   , fPVPickable(false)                         <<  75         fDest()
 78   , fDest()                                    << 
 79 {                                                  76 {
 80   // output file name                          <<  77   fSceneCount++;
 81   strcpy(fVRMLFileName, "");                   <<  78 
                                                   >>  79   // output file name
                                                   >>  80   strcpy(fVRMLFileName, "");
                                                   >>  81 
                                                   >>  82   // destination directory
                                                   >>  83   if ( getenv( VRMLFILE_DEST_DIR ) == NULL ) {
                                                   >>  84     strcpy( fVRMLFileDestDir, "" );
                                                   >>  85   } else {
                                                   >>  86     strcpy( fVRMLFileDestDir, getenv( VRMLFILE_DEST_DIR ) );
                                                   >>  87   }
                                                   >>  88 
                                                   >>  89 
                                                   >>  90   // maximum number of g4.prim files in the dest directory
                                                   >>  91   fMaxFileNum = DEFAULT_MAX_WRL_FILE_NUM ; // initialization
                                                   >>  92   if ( getenv( "G4VRMLFILE_MAX_FILE_NUM" ) != NULL ) {  
                                                   >>  93     
                                                   >>  94     sscanf( getenv("G4VRMLFILE_MAX_FILE_NUM"), "%d", &fMaxFileNum ) ;
                                                   >>  95 
                                                   >>  96   } else {
                                                   >>  97     fMaxFileNum = DEFAULT_MAX_WRL_FILE_NUM ;
                                                   >>  98   }
                                                   >>  99   if( fMaxFileNum < 1 ) { fMaxFileNum = 1; }
                                                   >> 100 
                                                   >> 101 
                                                   >> 102   // PV name pickability  
                                                   >> 103   if( getenv( "G4VRML_PV_PICKABLE" ) != NULL ) {
 82                                                   104 
 83   // destination directory                     << 105     int is_pickable ;
 84   if(std::getenv(VRMLFILE_DEST_DIR) == NULL)   << 106     sscanf( getenv("G4VRML_PV_PICKABLE"), "%d", &is_pickable ) ;
 85   {                                            << 107 
 86     strcpy(fVRMLFileDestDir, "");              << 108     if ( is_pickable ) { SetPVPickability ( true ) ; }
 87   }                                            << 109   } 
 88   else                                         << 110 
 89   {                                            << 111   // PV Transparency
 90     strcpy(fVRMLFileDestDir, std::getenv(VRMLF << 112   SetPVTransparency ();
 91   }                                            << 
 92                                                << 
 93   // maximum number of g4.prim files in the de << 
 94   fMaxFileNum = DEFAULT_MAX_WRL_FILE_NUM;  //  << 
 95   if(std::getenv("G4VRMLFILE_MAX_FILE_NUM") != << 
 96   {                                            << 
 97     sscanf(std::getenv("G4VRMLFILE_MAX_FILE_NU << 
 98   }                                            << 
 99   else                                         << 
100   {                                            << 
101     fMaxFileNum = DEFAULT_MAX_WRL_FILE_NUM;    << 
102   }                                            << 
103   if(fMaxFileNum < 1)                          << 
104   {                                            << 
105     fMaxFileNum = 1;                           << 
106   }                                            << 
107                                                << 
108   // PV name pickability                       << 
109   if(std::getenv("G4VRML_PV_PICKABLE") != NULL << 
110   {                                            << 
111     int is_pickable;                           << 
112     sscanf(std::getenv("G4VRML_PV_PICKABLE"),  << 
113                                                << 
114     if(is_pickable)                            << 
115     {                                          << 
116       SetPVPickability(true);                  << 
117     }                                          << 
118   }                                            << 
119                                                   113 
120   // PV Transparency                           << 
121   SetPVTransparency();                         << 
122 }                                                 114 }
123                                                   115 
                                                   >> 116 
124 G4VRML2FileSceneHandler::~G4VRML2FileSceneHand    117 G4VRML2FileSceneHandler::~G4VRML2FileSceneHandler()
125 {                                                 118 {
126 #if defined DEBUG_FR_SCENE                        119 #if defined DEBUG_FR_SCENE
127   if(G4VisManager::GetVerbosity() >= G4VisMana << 120   G4cerr << "***** ~G4VRML2FileSceneHandler" << G4endl;
128     G4cout << "***** ~G4VRML2FileSceneHandler" << 121 #endif 
129 #endif                                         << 122   fSceneCount--;
130   VRMLEndModeling();                           << 
131 }                                                 123 }
132                                                   124 
133 #define G4VRML2SCENEHANDLER G4VRML2FileSceneHa << 125 
134 #define IS_CONNECTED this->isConnected()       << 126 #define  G4VRML2SCENEHANDLER   G4VRML2FileSceneHandler
                                                   >> 127 #define  IS_CONNECTED   this->isConnected() 
135 #include "G4VRML2SceneHandlerFunc.icc"            128 #include "G4VRML2SceneHandlerFunc.icc"
136 #undef IS_CONNECTED                            << 129 #undef   IS_CONNECTED
137 #undef G4VRML2SCENEHANDLER                     << 130 #undef   G4VRML2SCENEHANDLER
                                                   >> 131 
138                                                   132 
139 void G4VRML2FileSceneHandler::connectPort()       133 void G4VRML2FileSceneHandler::connectPort()
140 {                                                 134 {
141   // g4_00.wrl, g4_01.wrl, ..., g4_MAX_FILE_IN << 135   // g4_00.wrl, g4_01.wrl, ..., g4_MAX_FILE_INDEX.wrl
142   const int MAX_FILE_INDEX = fMaxFileNum - 1;  << 136   const int MAX_FILE_INDEX = fMaxFileNum - 1 ;
143                                                   137 
144   // dest directory (null if no environmental  << 138   // dest directory (null if no environmental variables is set)
145   strcpy(fVRMLFileName, fVRMLFileDestDir);     << 139   strcpy ( fVRMLFileName, fVRMLFileDestDir) ; 
146   // add filename if environment variable supp << 140 
147   if(std::getenv(ENV_WRL_FILE_NAME))           << 141   // create full path name (default)
148   {                                            << 142   strcat ( fVRMLFileName, DEFAULT_WRL_FILE_NAME );
149     strcat(fVRMLFileName, std::getenv(ENV_WRL_ << 143 
150   }                                            << 144   // Determine VRML file name
151   else                                         << 145   for( int i = 0 ; i < fMaxFileNum ; i++) { 
152   {                                            << 146 
153     // Determine VRML file name                << 147     // Message in the final execution
154     for(int i = 0; i < fMaxFileNum; i++)       << 148     if( i == MAX_FILE_INDEX ) 
155     {                                          << 149     {
156       // Message in the final execution        << 150       G4cerr << "==========================================="   << G4endl; 
157       if(i == MAX_FILE_INDEX)                  << 151       G4cerr << "WARNING MESSAGE from VRML2FILE driver:     "   << G4endl;
158       {                                        << 152       G4cerr << "  This file name is the final one in the   "   << G4endl;
159         if(G4VisManager::GetVerbosity() >= G4V << 153       G4cerr << "  automatic updation of the output file name." << G4endl; 
160         {                                      << 154       G4cerr << "  You may overwrite existing files, i.e.   "   << G4endl; 
161           G4cout << "========================= << 155                   G4cerr << "  g4_XX.wrl.                               "   << G4endl;
162           G4cout << "WARNING MESSAGE from VRML << 156       G4cerr << "==========================================="   << G4endl; 
163           G4cout << "  This file name is the f << 157     }
164           G4cout << "  automatic updation of t << 158 
165           G4cout << "  You may overwrite exist << 159     // re-determine file name as G4VRMLFILE_DEST_DIR/g4_XX.wrl 
166           G4cout << "  g4_XX.wrl.              << 160     if( i >=  0 && i <= 9 ) { 
167           G4cout << "========================= << 161       sprintf( fVRMLFileName, "%s%s%s%d.wrl" , fVRMLFileDestDir,  WRL_FILE_HEADER, "0", i );
168         }                                      << 162     } else {
169       }                                        << 163       sprintf( fVRMLFileName, "%s%s%d.wrl"   , fVRMLFileDestDir,  WRL_FILE_HEADER, i );
170                                                << 164     }
171       // re-determine file name as G4VRMLFILE_ << 165 
172       std::ostringstream filename;             << 166     // check validity of the file name
173       filename << fVRMLFileDestDir;            << 167     G4std::ifstream  fin ; 
174       if(std::getenv(ENV_WRL_FILE_HEADER) == N << 168     fin.open(fVRMLFileName) ;
175       {                                        << 169     if(!fin) { 
176         filename << WRL_FILE_HEADER;           << 170       // new file 
177       }                                        << 171       fin.close();  
178       else                                     << 172       break; 
179       {                                        << 173     } else { 
180         filename << std::getenv(ENV_WRL_FILE_H << 174       // already exists (try next) 
181       }                                        << 175       fin.close(); 
182       filename << std::setw(2) << std::setfill << 176     } 
183       strncpy(fVRMLFileName, filename.str().c_ << 177 
184       fVRMLFileName[sizeof(fVRMLFileName) - 1] << 178   } // for 
185                                                << 179 
186       // check validity of the file name       << 180   // open a VRML 2.0 file with determined file name
187       std::ifstream fin;                       << 181   G4cerr << "==========================================="  << G4endl; 
188       fin.open(fVRMLFileName);                 << 182   G4cerr << "Output VRML 2.0 file: " <<    fVRMLFileName << G4endl; 
189       if(!fin)                                 << 183   G4cerr << "Muximal number of file in the destination directory: " << fMaxFileNum << G4endl; 
190       {                                        << 184   G4cerr << "  (Customizable as: setenv G4VRMLFILE_MAX_FILE_NUM number) " << G4endl;
191         // new file                            << 185   G4cerr << "===========================================" << G4endl; 
192         fin.close();                           << 186 
193         break;                                 << 187   fDest.open(fVRMLFileName) ;  fFlagDestOpen =  true ;
194       }                                        << 
195       else                                     << 
196       {                                        << 
197         // already exists (try next)           << 
198         fin.close();                           << 
199       }                                        << 
200                                                << 
201     }  // for                                  << 
202   }                                            << 
203                                                << 
204   // open a VRML 2.0 file with determined file << 
205   if(G4VisManager::GetVerbosity() >= G4VisMana << 
206   {                                            << 
207     G4cout << "=============================== << 
208     G4cout << "Output VRML 2.0 file: " << fVRM << 
209     G4cout << "Maximum number of files in the  << 
210            << fMaxFileNum << G4endl;           << 
211     G4cout << "  (Customizable with the enviro << 
212               "G4VRMLFILE_MAX_FILE_NUM) "      << 
213            << G4endl;                          << 
214     G4cout << "=============================== << 
215   }                                            << 
216   fDest.open(fVRMLFileName);                   << 
217   fFlagDestOpen = true;                        << 
218 }                                                 188 }
219                                                   189 
                                                   >> 190 
220 void G4VRML2FileSceneHandler::closePort()         191 void G4VRML2FileSceneHandler::closePort()
221 {                                                 192 {
222   char command[256];                           << 193   char command[256] ;
223   char viewer[256];                            << 194   char viewer [256] ; 
224   strcpy(viewer, NO_VRML_VIEWER);  // initiali << 195   strcpy( viewer, NO_VRML_VIEWER ); // initialization
225   if(std::getenv(ENV_VRML_VIEWER))             << 196   if( getenv( ENV_VRML_VIEWER ) ) {
226   {                                            << 197     strcpy( viewer, getenv( ENV_VRML_VIEWER ) ) ;
227     strcpy(viewer, std::getenv(ENV_VRML_VIEWER << 198   }
228   }                                            << 199 
229                                                << 200   // close VRML file  
230   // close VRML file                           << 201   fDest.close();  fFlagDestOpen = false ;
231   fDest.close();                               << 202   G4cerr << "*** VRML 2.0 File  " << fVRMLFileName << "  is generated." << G4endl;
232   fFlagDestOpen = false;                       << 203 
233   if(G4VisManager::GetVerbosity() >= G4VisMana << 204   
234     G4cout << "*** VRML 2.0 File  " << fVRMLFi << 205   // Invoke viewer 
235            << G4endl;                          << 206 
236                                                << 207   if ( !strcmp(viewer, NO_VRML_VIEWER )) {
237   // Invoke viewer                             << 208     G4cerr << "MESSAGE from VRML2FILE driver:"     << G4endl;
238                                                << 209     G4cerr << "    Set an environmental variable  " ;
239   if(!strcmp(viewer, NO_VRML_VIEWER))          << 210     G4cerr <<      ENV_VRML_VIEWER << G4endl;
240   {                                            << 211     G4cerr << "    if you want to visualize the generated VRML file" << G4endl; 
241     if(G4VisManager::GetVerbosity() >= G4VisMa << 212     G4cerr << "    automatically.  For example, " << G4endl;
242     {                                          << 213     G4cerr << "    setenv  " << ENV_VRML_VIEWER << "  vrwave " << G4endl;
243       G4cout << "MESSAGE from VRML2FILE driver << 214   } else {
244       G4cout << "    Set an environmental vari << 215     sprintf( command, "%s %s", viewer, fVRMLFileName  );   
245       G4cout << ENV_VRML_VIEWER << G4endl;     << 216     system( command );
246       G4cout << "    if you want to visualize  << 217   }
247              << G4endl;                        << 
248       G4cout << "    automatically.  For examp << 
249       G4cout << "    setenv  " << ENV_VRML_VIE << 
250       G4cout << "ALSO you may change the file  << 
251              << ENV_WRL_FILE_HEADER << G4endl; << 
252       G4cout << "    or the whole filename wit << 
253              << G4endl;                        << 
254     }                                          << 
255   }                                            << 
256   else                                         << 
257   {                                            << 
258     std::ostringstream ossCommand;             << 
259     ossCommand << viewer << ' ' << fVRMLFileNa << 
260     strncpy(command, ossCommand.str().c_str(), << 
261     command[sizeof(command) - 1] = '\0';       << 
262     int iErr                     = system(comm << 
263     if(iErr != 0)                              << 
264     {                                          << 
265       G4ExceptionDescription ed;               << 
266       ed << "Error " << iErr << " when calling << 
267          << "\".";                             << 
268       G4Exception("G4VRML2FileSceneHandler::cl << 
269                   JustWarning, ed);            << 
270     }                                          << 
271   }                                            << 
272 }                                                 218 }
273                                                   219 
274 G4int G4VRML2FileSceneHandler::fSceneIdCount =    220 G4int G4VRML2FileSceneHandler::fSceneIdCount = 0;
                                                   >> 221 G4int G4VRML2FileSceneHandler::fSceneCount = 0;
275                                                   222