G4HepRepFileXMLWriter Class Reference

#include <G4HepRepFileXMLWriter.hh>


Public Member Functions

 G4HepRepFileXMLWriter ()
void addType (const char *name, int newTypeDepth)
void addInstance ()
void addPrimitive ()
void addPoint (double x, double y, double z)
void addAttDef (const char *name, const char *desc, const char *type, const char *extra)
void addAttValue (const char *name, const char *value)
void addAttValue (const char *name, double value)
void addAttValue (const char *name, int value)
void addAttValue (const char *name, bool value)
void addAttValue (const char *name, double value1, double value2, double value3)
void open (const char *filespec)
void close ()
void endTypes ()

Data Fields

bool isOpen
int typeDepth
bool inType [50]
bool inInstance [50]
char * prevTypeName [50]


Detailed Description

Definition at line 51 of file G4HepRepFileXMLWriter.hh.


Constructor & Destructor Documentation

G4HepRepFileXMLWriter::G4HepRepFileXMLWriter (  ) 

Definition at line 48 of file G4HepRepFileXMLWriter.cc.

References isOpen.

00049 {
00050   isOpen = false;
00051   init();
00052 }


Member Function Documentation

void G4HepRepFileXMLWriter::addAttDef ( const char *  name,
const char *  desc,
const char *  type,
const char *  extra 
)

Definition at line 195 of file G4HepRepFileXMLWriter.cc.

References G4cout, and G4endl.

Referenced by G4HepRepFileSceneHandler::AddCompound().

00199 {
00200   if (fout.good())
00201   {
00202     indent();
00203     fout << "  <heprep:attdef extra=\"" << extra << "\" name=\"" << name << "\" type=\"" << type << "\"" << G4endl;
00204     indent();
00205     fout << "  desc=\"" << desc << "\"/>" << G4endl;
00206   } else {
00207 #ifdef G4HEPREPFILEDEBUG
00208     G4cout << "G4HepRepFileXMLWriter:addAttDef No file is currently open" << G4endl;
00209 #endif
00210   }
00211 }

void G4HepRepFileXMLWriter::addAttValue ( const char *  name,
double  value1,
double  value2,
double  value3 
)

Definition at line 281 of file G4HepRepFileXMLWriter.cc.

References G4cout, and G4endl.

00285 {
00286   if (fout.good())
00287   {
00288     int redness = int(value1*255.);
00289     int greenness = int(value2*255.);
00290     int blueness = int(value3*255.);
00291     indent();
00292     fout << "  <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
00293     indent();
00294     fout << "    value=\"" << redness << "," << greenness << "," << blueness << "\"/>" << G4endl;
00295   } else {
00296 #ifdef G4HEPREPFILEDEBUG
00297     G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
00298 #endif
00299   }
00300 }

void G4HepRepFileXMLWriter::addAttValue ( const char *  name,
bool  value 
)

Definition at line 262 of file G4HepRepFileXMLWriter.cc.

References G4cout, and G4endl.

00264 {
00265   if (fout.good())
00266   {
00267     indent();
00268     fout << "  <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
00269     indent();
00270     if (value)
00271       fout << "    value=\"True\"/>" << G4endl;
00272     else
00273       fout << "    value=\"False\"/>" << G4endl;
00274   } else {
00275 #ifdef G4HEPREPFILEDEBUG
00276     G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
00277 #endif
00278   }
00279 }

void G4HepRepFileXMLWriter::addAttValue ( const char *  name,
int  value 
)

Definition at line 246 of file G4HepRepFileXMLWriter.cc.

References G4cout, and G4endl.

00248 {
00249   if (fout.good())
00250   {
00251     indent();
00252     fout << "  <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
00253     indent();
00254     fout << "    value=\"" << value << "\"/>" << G4endl;
00255   } else {
00256 #ifdef G4HEPREPFILEDEBUG
00257     G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
00258 #endif
00259   }
00260 }

void G4HepRepFileXMLWriter::addAttValue ( const char *  name,
double  value 
)

Definition at line 230 of file G4HepRepFileXMLWriter.cc.

References G4cout, and G4endl.

00232 {
00233   if (fout.good())
00234   {
00235     indent();
00236     fout << "  <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
00237     indent();
00238     fout << "    value=\"" << value << "\"/>" << G4endl;
00239   } else {
00240 #ifdef G4HEPREPFILEDEBUG
00241     G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
00242 #endif
00243   }
00244 }

void G4HepRepFileXMLWriter::addAttValue ( const char *  name,
const char *  value 
)

Definition at line 214 of file G4HepRepFileXMLWriter.cc.

References G4cout, and G4endl.

Referenced by G4HepRepFileSceneHandler::AddCompound(), G4HepRepFileSceneHandler::AddPrimitive(), G4HepRepFileSceneHandler::AddSolid(), G4HepRepFileSceneHandler::InitHit(), and G4HepRepFileSceneHandler::InitTrajectory().

00216 {
00217   if (fout.good())
00218   {
00219     indent();
00220     fout << "  <heprep:attvalue showLabel=\"NONE\" name=\"" << name << "\"" << G4endl;
00221     indent();
00222     fout << "    value=\"" << value << "\"/>" << G4endl;
00223   } else {
00224 #ifdef G4HEPREPFILEDEBUG
00225     G4cout << "G4HepRepFileXMLWriter:addAttValue No file is currently open" << G4endl;
00226 #endif
00227   }
00228 }

void G4HepRepFileXMLWriter::addInstance (  ) 

Definition at line 120 of file G4HepRepFileXMLWriter.cc.

References G4cout, G4endl, inInstance, inType, and typeDepth.

Referenced by G4HepRepFileSceneHandler::AddCompound(), addType(), G4HepRepFileSceneHandler::InitHit(), and G4HepRepFileSceneHandler::InitTrajectory().

00121 {
00122   if (fout.good())
00123   {
00124     if (inType[typeDepth])
00125     {
00126       endInstance();
00127       inInstance[typeDepth] = true;
00128       indent();
00129       fout << "<heprep:instance>" << G4endl;
00130     } else {
00131 #ifdef G4HEPREPFILEDEBUG
00132       G4cout << "G4HepRepFileXMLWriter:addInstance No HepRep Type is currently open" << G4endl;
00133 #endif
00134     }
00135   } else {
00136 #ifdef G4HEPREPFILEDEBUG
00137     G4cout << "G4HepRepFileXMLWriter:addInstance No file is currently open" << G4endl;
00138 #endif
00139   }
00140 }

void G4HepRepFileXMLWriter::addPoint ( double  x,
double  y,
double  z 
)

Definition at line 164 of file G4HepRepFileXMLWriter.cc.

References G4cout, G4endl, G4HepRepMessenger::getCenter(), G4HepRepMessenger::GetInstance(), and G4HepRepMessenger::getScale().

Referenced by G4HepRepFileSceneHandler::AddCompound(), G4HepRepFileSceneHandler::AddPrimitive(), and G4HepRepFileSceneHandler::AddSolid().

00165 {
00166   if (fout.good())
00167   {
00168     if (inPrimitive)
00169     {
00170       endPoint();
00171       inPoint = true;
00172       indent();
00173                 
00174                 // Include scale and center values
00175                 G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
00176                 G4double scale = messenger->getScale();
00177                 G4ThreeVector center = messenger->getCenter();
00178                 G4double xNew = scale * ( x - center.x());
00179                 G4double yNew = scale * ( y - center.y());
00180                 G4double zNew = scale * ( z - center.z());
00181                 
00182       fout << "<heprep:point x=\"" << xNew << "\" y=\"" << yNew << "\" z=\"" << zNew << "\">" << G4endl;
00183     } else {
00184 #ifdef G4HEPREPFILEDEBUG
00185       G4cout << "G4HepRepFileXMLWriter:addPoint No HepRep Primitive is currently open" << G4endl;
00186 #endif
00187     }
00188   } else {
00189 #ifdef G4HEPREPFILEDEBUG
00190     G4cout << "G4HepRepFileXMLWriter:addPoint No file is currently open" << G4endl;
00191 #endif
00192   }
00193 }

void G4HepRepFileXMLWriter::addPrimitive (  ) 

Definition at line 142 of file G4HepRepFileXMLWriter.cc.

References G4cout, G4endl, inInstance, and typeDepth.

Referenced by G4HepRepFileSceneHandler::AddCompound(), G4HepRepFileSceneHandler::AddPrimitive(), and G4HepRepFileSceneHandler::AddSolid().

00143 {
00144   if (fout.good())
00145   {
00146     if (inInstance[typeDepth])
00147     {
00148       endPrimitive();
00149       inPrimitive = true;
00150       indent();
00151       fout << "<heprep:primitive>" << G4endl;
00152     } else {
00153 #ifdef G4HEPREPFILEDEBUG
00154       G4cout << "G4HepRepFileXMLWriter:addPrimitive No HepRep Instance is currently open" << G4endl; 
00155 #endif
00156     }
00157   } else {
00158 #ifdef G4HEPREPFILEDEBUG
00159     G4cout << "G4HepRepFileXMLWriter:addPrimitive No file is currently open" << G4endl;
00160 #endif
00161   }
00162 }

void G4HepRepFileXMLWriter::addType ( const char *  name,
int  newTypeDepth 
)

Definition at line 71 of file G4HepRepFileXMLWriter.cc.

References addInstance(), G4cout, G4endl, inType, prevTypeName, and typeDepth.

Referenced by G4HepRepFileSceneHandler::AddCompound().

00072 {
00073   if (fout.good())
00074   {
00075     // Flatten structure if it exceeds maximum allowed typeDepth of 49.
00076     if (newTypeDepth > 49)
00077       newTypeDepth = 49;
00078 
00079     if (newTypeDepth < 0)
00080       newTypeDepth = 0;
00081 
00082     // Insert any layers that are missing from the hierarchy (protects against
00083     // callers that skip from, say, layer 1 to layer 3 with no layer 2).
00084     while (typeDepth < (newTypeDepth-1)) {
00085       addType("Layer Inserted by G4HepRepFileXMLWriter", typeDepth + 1);
00086       addInstance();
00087     }
00088 
00089     // If moving closer to the root, close previously open types.
00090     while (newTypeDepth<typeDepth)
00091       endType();
00092 
00093     // Close any remaining primitives of the current instance.
00094     endPrimitive();
00095 
00096     // If this is a new type name for the current depth, declare the
00097     // new Type.  Otherwise, it is just another Instance of the current Type.
00098     if (strcmp(name,prevTypeName[newTypeDepth])!=0)
00099     {
00100       if (inType[newTypeDepth])
00101         endType();
00102 
00103       prevTypeName[newTypeDepth] = new char[strlen(name)+1];
00104       strcpy(prevTypeName[newTypeDepth],name);
00105 
00106       inType[newTypeDepth] = true;
00107       indent();
00108       fout << "<heprep:type version=\"null\" name=\"" << name << "\">"
00109          << G4endl;
00110 
00111       typeDepth = newTypeDepth;
00112     }
00113   } else {
00114 #ifdef G4HEPREPFILEDEBUG
00115     G4cout << "G4HepRepFileXMLWriter:addType No file is currently open." << G4endl;
00116 #endif
00117   }
00118 }

void G4HepRepFileXMLWriter::close (  ) 

Definition at line 321 of file G4HepRepFileXMLWriter.cc.

References endTypes(), G4cout, G4endl, and isOpen.

Referenced by open(), and G4HepRepFileViewer::ShowView().

00322 {
00323   // Close any remaining open Types
00324   endTypes();
00325 
00326   if (fout.good()) {      
00327     fout << "</heprep:heprep>" << G4endl;
00328     fout.close( );
00329     isOpen = false;
00330   } else {
00331     G4cout << "G4HepRepFileXMLWriter:close No file is currently open" << G4endl;
00332   }
00333 }

void G4HepRepFileXMLWriter::endTypes (  ) 

Definition at line 335 of file G4HepRepFileXMLWriter.cc.

References typeDepth.

Referenced by close().

00336 {
00337   // Close any remaining open Types
00338     while(typeDepth>-1)
00339       endType();
00340 }

void G4HepRepFileXMLWriter::open ( const char *  filespec  ) 

Definition at line 302 of file G4HepRepFileXMLWriter.cc.

References close(), G4cout, G4endl, and isOpen.

00303 {
00304   if (isOpen)
00305     close();
00306   
00307   fout.open(fileSpec);
00308     
00309   if (fout.good()) {
00310     fout << "<?xml version=\"1.0\" ?>" << G4endl;
00311     fout << "<heprep:heprep xmlns:heprep=\"http://www.slac.stanford.edu/~perl/heprep/\"" << G4endl;
00312     fout << "  xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" xsi:schemaLocation=\"HepRep.xsd\">" << G4endl;
00313     
00314     isOpen = true;
00315     init();
00316   } else {
00317     G4cout << "G4HepRepFileXMLWriter:open Unable to write to file " << fileSpec << G4endl;
00318   }
00319 }


Field Documentation

bool G4HepRepFileXMLWriter::inInstance[50]

Definition at line 91 of file G4HepRepFileXMLWriter.hh.

Referenced by addInstance(), and addPrimitive().

bool G4HepRepFileXMLWriter::inType[50]

Definition at line 90 of file G4HepRepFileXMLWriter.hh.

Referenced by addInstance(), and addType().

bool G4HepRepFileXMLWriter::isOpen

Definition at line 88 of file G4HepRepFileXMLWriter.hh.

Referenced by close(), G4HepRepFileXMLWriter(), open(), and G4HepRepFileViewer::ShowView().

char* G4HepRepFileXMLWriter::prevTypeName[50]

Definition at line 92 of file G4HepRepFileXMLWriter.hh.

Referenced by G4HepRepFileSceneHandler::AddCompound(), and addType().

int G4HepRepFileXMLWriter::typeDepth

Definition at line 89 of file G4HepRepFileXMLWriter.hh.

Referenced by addInstance(), addPrimitive(), addType(), and endTypes().


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:52:12 2013 for Geant4 by  doxygen 1.4.7