Geant4-11
G4DAWNFILESceneHandler.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//
28// Satoshi TANAKA
29// DAWNFILE scene.
30
31#define __G_ANSI_C__
32
33// #define DEBUG_FR_SCENE
34
35//----- header files
36#include <fstream>
37#include <stdlib.h>
38#include <string.h>
39#include <sstream>
40#include <iomanip>
41#include "globals.hh"
42#include "G4VisManager.hh"
43#include "G4FRConst.hh"
44#include "G4DAWNFILE.hh"
46#include "G4DAWNFILEViewer.hh"
47#include "G4Point3D.hh"
48#include "G4VisAttributes.hh"
49#include "G4Scene.hh"
50#include "G4Transform3D.hh"
51#include "G4Polyhedron.hh"
52#include "G4Box.hh"
53#include "G4Cons.hh"
54#include "G4Polyline.hh"
55#include "G4Trd.hh"
56#include "G4Tubs.hh"
57#include "G4Trap.hh"
58#include "G4Torus.hh"
59#include "G4Sphere.hh"
60#include "G4Para.hh"
61#include "G4Text.hh"
62#include "G4Circle.hh"
63#include "G4Square.hh"
64#include "G4VPhysicalVolume.hh"
65
66//----- constants
67const char FR_ENV_CULL_INVISIBLE_OBJECTS[] = "G4DAWN_CULL_INVISIBLE_OBJECTS";
68const char G4PRIM_FILE_HEADER[] = "g4_";
69const char DEFAULT_G4PRIM_FILE_NAME[] = "g4_0000.prim";
70const int FR_MAX_FILE_NUM = 100;
71
73// Driver-dependent part //
75
76//----- G4DAWNFILESceneHandler, constructor
78 const G4String& name)
79 : G4VSceneHandler(system, fSceneIdCount++, name)
80 , fSystem(system)
81 , fPrimDest()
82 , FRflag_in_modeling(false)
83 , flag_saving_g4_prim(false)
84 , COMMAND_BUF_SIZE(G4FRofstream::SEND_BUFMAX)
85 , fPrec(9)
86 , fPrec2(16)
87{
88 // g4.prim filename and its directory
89 if(std::getenv("G4DAWNFILE_DEST_DIR") == NULL)
90 {
91 strcpy(fG4PrimDestDir, ""); // output dir
92 strcpy(fG4PrimFileName, DEFAULT_G4PRIM_FILE_NAME); // filename
93 }
94 else
95 {
96 strcpy(fG4PrimDestDir, std::getenv("G4DAWNFILE_DEST_DIR")); // output dir
97 strcpy(fG4PrimFileName, DEFAULT_G4PRIM_FILE_NAME); // filename
98 }
99
100 // maximum number of g4.prim files in the dest directory
101 fMaxFileNum = FR_MAX_FILE_NUM; // initialization
102 if(std::getenv("G4DAWNFILE_MAX_FILE_NUM") != NULL)
103 {
104 sscanf(std::getenv("G4DAWNFILE_MAX_FILE_NUM"), "%d", &fMaxFileNum);
105 }
106 else
107 {
109 }
110 if(fMaxFileNum < 1)
111 {
112 fMaxFileNum = 1;
113 }
114
115 //----- precision control
116 if(std::getenv("G4DAWNFILE_PRECISION") != NULL)
117 {
118 sscanf(std::getenv("G4DAWNFILE_PRECISION"), "%d", &fPrec);
119 }
120 else
121 {
122 fPrec = 9;
123 }
124 fPrec2 = fPrec + 7;
125}
126
127//----- G4DAWNFILESceneHandler, destructor
129{
130#if defined DEBUG_FR_SCENE
132 G4cout << "***** ~G4DAWNFILESceneHandler" << G4endl;
133#endif
134 if(fPrimDest.IsOpen())
135 {
136 //----- End of modeling
137 // !EndModeling, !DrawAll, !CloseDevice,
138 // close g4.prim
140 }
141}
142
143//-----
145{
146 // g4_0000.prim, g4_0001.prim, ..., g4_MAX_FILE_INDEX.prim
147 const int MAX_FILE_INDEX = fMaxFileNum - 1;
148
149 // dest directory (null if no environmental variables is set)
151
152 // create full path name (default)
154
155 // Automatic updation of file names
156 for(int i = 0; i < fMaxFileNum; i++)
157 {
158 // Message in the final execution
159 if(i == MAX_FILE_INDEX)
160 {
162 {
163 G4cout << "===========================================" << G4endl;
164 G4cout << "WARNING MESSAGE from DAWNFILE driver: " << G4endl;
165 G4cout << " This file name is the final one in the " << G4endl;
166 G4cout << " automatic updation of the output file name." << G4endl;
167 G4cout << " You may overwrite existing files, i.e. " << G4endl;
168 G4cout << " g4_XXXX.prim and g4_XXXX.eps " << G4endl;
169 G4cout << "===========================================" << G4endl;
170 }
171 }
172
173 // re-determine file name as G4DAWNFILE_DEST_DIR/g4_XXXX.prim
174 std::ostringstream filename;
175 filename << fG4PrimDestDir << G4PRIM_FILE_HEADER << std::setw(4)
176 << std::setfill('0') << i << ".prim";
177 strncpy(fG4PrimFileName, filename.str().c_str(),
178 sizeof(fG4PrimFileName) - 1);
179 fG4PrimFileName[sizeof(fG4PrimFileName) - 1] = '\0';
180
181 // check validity of the file name
182 std::ifstream fin;
183 fin.open(fG4PrimFileName);
184 if(!fin)
185 {
186 // new file
187 fin.close();
188 break;
189 }
190 else
191 {
192 // already exists (try next)
193 fin.close();
194 }
195
196 } // for
197
198 G4cout << "=========================================== " << G4endl;
199 G4cout << "Output file: " << fG4PrimFileName << G4endl;
200 G4cout << "Destination directory (current dir if NULL): " << fG4PrimDestDir
201 << G4endl;
202 G4cout << "Maximal number of files in the destination directory: "
203 << fMaxFileNum << G4endl;
204 G4cout << "Note: " << G4endl;
205 G4cout << " * The maximal number is customizable as: " << G4endl;
206 G4cout << " % setenv G4DAWNFILE_MAX_FILE_NUM number " << G4endl;
207 G4cout << " * The destination directory is customizable as:" << G4endl;
208 G4cout << " % setenv G4DAWNFILE_DEST_DIR dir_name/ " << G4endl;
209 G4cout << " ** Do not forget \"/\" at the end of the " << G4endl;
210 G4cout << " dir_name, e.g. \"./tmp/\". " << G4endl;
211 G4cout << "=========================================== " << G4endl;
212
213} // G4DAWNFILESceneHandler::SetG4PrimFileName()
214
215//-----
217{
218#if defined DEBUG_FR_SCENE
220 G4cout << "***** BeginSavingG4Prim (called)\n";
221#endif
222
223 if(!IsSavingG4Prim())
224 {
225#if defined DEBUG_FR_SCENE
227 {
228 G4cout << "***** (started) ";
229 G4cout << "(open g4.prim, ##)" << G4endl;
230 }
231#endif
232 SetG4PrimFileName(); // result set to fG4PrimFileName
234
236 flag_saving_g4_prim = true;
237 }
238}
239
241{
242#if defined DEBUG_FR_SCENE
244 G4cout << "***** EndSavingG4Prim (called)\n";
245#endif
246
247 if(IsSavingG4Prim())
248 {
249#if defined DEBUG_FR_SCENE
251 G4cout << "***** (started) (close g4.prim)" << G4endl;
252#endif
254 flag_saving_g4_prim = false;
255 }
256}
257
258//-----
260{
261 if(!FRIsInModeling())
262 {
263#if defined DEBUG_FR_SCENE
265 G4cout
266 << "***** G4DAWNFILESceneHandler::FRBeginModeling (called & started)"
267 << G4endl;
268#endif
269
270 //----- Send saving command and heading comment
272
273 //----- Send bounding box command
275
276 //----- send SET_CAMERA command
277#if defined DEBUG_FR_SCENE
279 G4cout << "***** (!SetCamera in FRBeginModeling())" << G4endl;
280#endif
282
283 //----- open device
284#if defined DEBUG_FR_SCENE
286 G4cout << "***** (!OpenDevice in FRBeginModeling())" << G4endl;
287#endif
289
290 //----- begin sending primitives
291#if defined DEBUG_FR_SCENE
293 G4cout << "***** (!BeginModeling in FRBeginModeling())" << G4endl;
294#endif
296 FRflag_in_modeling = true;
297
298 } // if
299}
300
302// Common to DAWN and DAWNFILE drivers //
304
305#define G4FRSCENEHANDLER G4DAWNFILESceneHandler
306#include "G4FRSceneFunc.icc"
307#undef G4FRSCENEHANDLER
308
310// static variables //
312
313//----- static variables
const int FR_MAX_FILE_NUM
const char DEFAULT_G4PRIM_FILE_NAME[]
const char FR_ENV_CULL_INVISIBLE_OBJECTS[]
const char G4PRIM_FILE_HEADER[]
const char FR_G4_PRIM_HEADER[]
Definition: G4FRConst.hh:37
const char FR_OPEN_DEVICE[]
Definition: G4FRConst.hh:45
const char FR_BEGIN_MODELING[]
Definition: G4FRConst.hh:63
const char FR_SET_CAMERA[]
Definition: G4FRConst.hh:44
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
void SendBoundingBox(void)
void SendStr(const char *char_string)
G4DAWNFILESceneHandler(G4DAWNFILE &system, const G4String &name="")
void Open(const char *filename)
Definition: G4FRofstream.hh:68
G4bool IsOpen()
Definition: G4FRofstream.hh:55
static Verbosity GetVerbosity()
const char * name(G4int ptype)