Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/HepRep/src/G4HepRepFileSceneHandler.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 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/HepRep/src/G4HepRepFileSceneHandler.cc (Version 11.3.0) and /visualization/HepRep/src/G4HepRepFileSceneHandler.cc (Version 9.5.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
                                                   >>  26 // $Id: G4HepRepFileSceneHandler.cc,v 1.69 2010-06-05 06:25:03 perl Exp $
                                                   >>  27 // GEANT4 tag $Name: not supported by cvs2svn $
 26 //                                                 28 //
 27 //                                                 29 //
 28 // Joseph Perl  27th January 2002                  30 // Joseph Perl  27th January 2002
 29 // A base class for a scene handler to export      31 // A base class for a scene handler to export geometry and trajectories
 30 // to the HepRep xml file format.                  32 // to the HepRep xml file format.
 31                                                    33 
 32 #include "G4HepRepFileSceneHandler.hh"             34 #include "G4HepRepFileSceneHandler.hh"
 33 #include "G4HepRepFile.hh"                         35 #include "G4HepRepFile.hh"
 34 #include "G4HepRepMessenger.hh"                    36 #include "G4HepRepMessenger.hh"
 35 #include "G4UIcommand.hh"                          37 #include "G4UIcommand.hh"
 36                                                    38 
 37 #include "G4PhysicalConstants.hh"              << 
 38 #include "G4SystemOfUnits.hh"                  << 
 39 #include "G4Version.hh"                            39 #include "G4Version.hh"
 40 #include "G4VSolid.hh"                             40 #include "G4VSolid.hh"
 41 #include "G4PhysicalVolumeModel.hh"                41 #include "G4PhysicalVolumeModel.hh"
 42 #include "G4VPhysicalVolume.hh"                    42 #include "G4VPhysicalVolume.hh"
 43 #include "G4LogicalVolume.hh"                      43 #include "G4LogicalVolume.hh"
 44 #include "G4RotationMatrix.hh"                     44 #include "G4RotationMatrix.hh"
 45 #include "G4Material.hh"                           45 #include "G4Material.hh"
 46 #include "G4Polymarker.hh"                         46 #include "G4Polymarker.hh"
 47 #include "G4Polyline.hh"                           47 #include "G4Polyline.hh"
 48 #include "G4Text.hh"                               48 #include "G4Text.hh"
 49 #include "G4Circle.hh"                             49 #include "G4Circle.hh"
 50 #include "G4Square.hh"                             50 #include "G4Square.hh"
 51 #include "G4Polyhedron.hh"                         51 #include "G4Polyhedron.hh"
                                                   >>  52 #include "G4NURBS.hh"
 52 #include "G4VTrajectory.hh"                        53 #include "G4VTrajectory.hh"
 53 #include "G4VTrajectoryPoint.hh"                   54 #include "G4VTrajectoryPoint.hh"
 54 #include "G4TrajectoriesModel.hh"                  55 #include "G4TrajectoriesModel.hh"
 55 #include "G4VHit.hh"                               56 #include "G4VHit.hh"
 56 #include "G4AttDef.hh"                             57 #include "G4AttDef.hh"
 57 #include "G4AttValue.hh"                           58 #include "G4AttValue.hh"
 58 #include "G4AttCheck.hh"                           59 #include "G4AttCheck.hh"
 59 #include "G4VisManager.hh"                         60 #include "G4VisManager.hh"
 60 #include "G4VisTrajContext.hh"                     61 #include "G4VisTrajContext.hh"
 61 #include "G4VTrajectoryModel.hh"                   62 #include "G4VTrajectoryModel.hh"
 62                                                    63 
 63 // HepRep                                      <<  64 //HepRep
 64 #include "G4HepRepFileXMLWriter.hh"                65 #include "G4HepRepFileXMLWriter.hh"
 65                                                    66 
 66 G4int G4HepRepFileSceneHandler::fSceneIdCount      67 G4int G4HepRepFileSceneHandler::fSceneIdCount = 0;
 67 // Counter for HepRep scene handlers.              68 // Counter for HepRep scene handlers.
 68                                                    69 
 69 G4HepRepFileSceneHandler::G4HepRepFileSceneHan     70 G4HepRepFileSceneHandler::G4HepRepFileSceneHandler(G4VGraphicsSystem& system,
 70                                                <<  71                            const G4String& name):
 71   : G4VSceneHandler(system, fSceneIdCount++, n <<  72 G4VSceneHandler(system, fSceneIdCount++, name)
 72 {                                                  73 {
 73   hepRepXMLWriter = ((G4HepRepFile*) (&system) <<  74   hepRepXMLWriter = ((G4HepRepFile*)(&system))->GetHepRepXMLWriter();
 74   fileCounter     = 0;                         <<  75   fileCounter = 0;
 75                                                <<  76   
 76   inPrimitives2D       = false;                <<  77   inPrimitives2D = false;
 77   warnedAbout3DText    = false;                <<  78   warnedAbout3DText = false;
 78   warnedAbout2DMarkers = false;                <<  79   warnedAbout2DMarkers = false;
 79   haveVisible          = false;                <<  80   haveVisible = false;
 80   drawingTraj          = false;                <<  81   drawingTraj = false;
 81   doneInitTraj         = false;                <<  82   doneInitTraj = false;
 82   drawingHit           = false;                <<  83   drawingHit = false;
 83   doneInitHit          = false;                <<  84   doneInitHit = false;
 84   trajContext          = 0;                    << 
 85   trajAttValues        = 0;                    << 
 86   trajAttDefs          = 0;                    << 
 87   hitAttValues         = 0;                    << 
 88   hitAttDefs           = 0;                    << 
 89 }                                              << 
 90                                                << 
 91 G4HepRepFileSceneHandler::~G4HepRepFileSceneHa << 
 92                                                << 
 93 void G4HepRepFileSceneHandler::BeginModeling() << 
 94 {                                              << 
 95   G4VisManager* visManager        = G4VisManag << 
 96   const G4VTrajectoryModel* model = visManager << 
 97   trajContext                     = &model->Ge << 
 98                                                << 
 99   G4VSceneHandler::BeginModeling();  // Requir << 
100 }                                              << 
101                                                << 
102 void G4HepRepFileSceneHandler::EndModeling()   << 
103 {                                              << 
104   G4VSceneHandler::EndModeling();  // Required << 
105 }                                              << 
106                                                << 
107 void G4HepRepFileSceneHandler::BeginPrimitives << 
108   const G4Transform3D& objectTransformation)   << 
109 {                                              << 
110 #ifdef G4HEPREPFILEDEBUG                       << 
111   G4cout << "G4HepRepFileSceneHandler::BeginPr << 
112 #endif                                         << 
113   inPrimitives2D = true;                       << 
114   G4VSceneHandler::BeginPrimitives2D(objectTra << 
115 }                                              << 
116                                                << 
117 void G4HepRepFileSceneHandler::EndPrimitives2D << 
118 {                                              << 
119 #ifdef G4HEPREPFILEDEBUG                       << 
120   G4cout << "G4HepRepFileSceneHandler::EndPrim << 
121 #endif                                         << 
122   G4VSceneHandler::EndPrimitives2D();          << 
123   inPrimitives2D = false;                      << 
124 }                                              << 
125                                                << 
126 #ifdef G4HEPREPFILEDEBUG                       << 
127 void G4HepRepFileSceneHandler::PrintThings()   << 
128 {                                              << 
129   G4cout << "  with transformation " << fObjec << 
130   G4PhysicalVolumeModel* pPVModel =            << 
131     dynamic_cast<G4PhysicalVolumeModel*>(fpMod << 
132   if(pPVModel)                                 << 
133   {                                            << 
134     G4VPhysicalVolume* pCurrentPV = pPVModel-> << 
135     G4LogicalVolume* pCurrentLV   = pPVModel-> << 
136     G4int currentDepth            = pPVModel-> << 
137     G4cout << "\n  current physical volume: "  << 
138            << "\n  current logical volume: " < << 
139            << "\n  current depth of geometry t << 
140   }                                            << 
141   G4cout << G4endl;                            << 
142 }                                              << 
143 #endif                                         << 
144                                                << 
145 void G4HepRepFileSceneHandler::AddSolid(const  << 
146 {                                              << 
147 #ifdef G4HEPREPFILEDEBUG                       << 
148   G4cout << "G4HepRepFileSceneHandler::AddSoli << 
149          << box.GetName() << G4endl;           << 
150   PrintThings();                               << 
151 #endif                                         << 
152                                                << 
153   if(drawingTraj)                              << 
154     return;                                    << 
155                                                << 
156   if(drawingHit)                               << 
157     InitHit();                                 << 
158                                                << 
159   haveVisible = false;                         << 
160   AddHepRepInstance("Prism", NULL);            << 
161                                                << 
162   G4HepRepMessenger* messenger = G4HepRepMesse << 
163                                                << 
164   // Get and check applicable vis attributes.  << 
165   fpVisAttribs = fpViewer->GetApplicableVisAtt << 
166   if(fpVisAttribs && (fpVisAttribs->IsVisible( << 
167      messenger->getCullInvisibles())           << 
168     return;                                    << 
169                                                << 
170   hepRepXMLWriter->addPrimitive();             << 
171                                                << 
172   G4double dx = box.GetXHalfLength();          << 
173   G4double dy = box.GetYHalfLength();          << 
174   G4double dz = box.GetZHalfLength();          << 
175                                                << 
176   G4Point3D vertex1(G4Point3D(dx, dy, -dz));   << 
177   G4Point3D vertex2(G4Point3D(dx, -dy, -dz));  << 
178   G4Point3D vertex3(G4Point3D(-dx, -dy, -dz)); << 
179   G4Point3D vertex4(G4Point3D(-dx, dy, -dz));  << 
180   G4Point3D vertex5(G4Point3D(dx, dy, dz));    << 
181   G4Point3D vertex6(G4Point3D(dx, -dy, dz));   << 
182   G4Point3D vertex7(G4Point3D(-dx, -dy, dz));  << 
183   G4Point3D vertex8(G4Point3D(-dx, dy, dz));   << 
184                                                << 
185   vertex1 = (fObjectTransformation) *vertex1;  << 
186   vertex2 = (fObjectTransformation) *vertex2;  << 
187   vertex3 = (fObjectTransformation) *vertex3;  << 
188   vertex4 = (fObjectTransformation) *vertex4;  << 
189   vertex5 = (fObjectTransformation) *vertex5;  << 
190   vertex6 = (fObjectTransformation) *vertex6;  << 
191   vertex7 = (fObjectTransformation) *vertex7;  << 
192   vertex8 = (fObjectTransformation) *vertex8;  << 
193                                                << 
194   hepRepXMLWriter->addPoint(vertex1.x(), verte << 
195   hepRepXMLWriter->addPoint(vertex2.x(), verte << 
196   hepRepXMLWriter->addPoint(vertex3.x(), verte << 
197   hepRepXMLWriter->addPoint(vertex4.x(), verte << 
198   hepRepXMLWriter->addPoint(vertex5.x(), verte << 
199   hepRepXMLWriter->addPoint(vertex6.x(), verte << 
200   hepRepXMLWriter->addPoint(vertex7.x(), verte << 
201   hepRepXMLWriter->addPoint(vertex8.x(), verte << 
202 }                                              << 
203                                                << 
204 void G4HepRepFileSceneHandler::AddSolid(const  << 
205 {                                              << 
206 #ifdef G4HEPREPFILEDEBUG                       << 
207   G4cout << "G4HepRepFileSceneHandler::AddSoli << 
208          << cons.GetName() << G4endl;          << 
209   PrintThings();                               << 
210 #endif                                         << 
211                                                << 
212   // HepRApp does not correctly represent the  << 
213   // non-standard angles, let the base class c << 
214   G4RotationMatrix r = fObjectTransformation.g << 
215   G4bool linedUpWithAnAxis =                   << 
216     (std::fabs(r.phiX()) <= .001 || std::fabs( << 
217      std::fabs(r.phiZ()) <= .001 || std::fabs( << 
218      std::fabs(r.phiY() - pi) <= .001 || std:: << 
219   // G4cout << "Angle X:" << r.phiX() << ", An << 
220   // Z:" << r.phiZ() << G4endl; G4cout << "lin << 
221   // linedUpWithAnAxis << G4endl;              << 
222                                                << 
223   // HepRep does not have a primitive for a cu << 
224   // so if this cone is cut, let the base clas << 
225   // solid to polygons.                        << 
226   G4HepRepMessenger* messenger = G4HepRepMesse << 
227   if(cons.GetDeltaPhiAngle() < twopi || !lined << 
228      messenger->renderCylAsPolygons())         << 
229   {                                            << 
230     G4VSceneHandler::AddSolid(cons);  // Invok << 
231   }                                            << 
232   else                                         << 
233   {                                            << 
234     if(drawingTraj)                            << 
235       return;                                  << 
236                                                << 
237     if(drawingHit)                             << 
238       InitHit();                               << 
239                                                << 
240     haveVisible = false;                       << 
241     AddHepRepInstance("Cylinder", NULL);       << 
242                                                << 
243     // Get and check applicable vis attributes << 
244     fpVisAttribs = fpViewer->GetApplicableVisA << 
245     if(fpVisAttribs && (fpVisAttribs->IsVisibl << 
246        messenger->getCullInvisibles())         << 
247       return;                                  << 
248                                                << 
249     G4Point3D vertex1(G4Point3D(0., 0., -cons. << 
250     G4Point3D vertex2(G4Point3D(0., 0., cons.G << 
251                                                << 
252     vertex1 = (fObjectTransformation) *vertex1 << 
253     vertex2 = (fObjectTransformation) *vertex2 << 
254                                                << 
255     // Outer cylinder.                         << 
256     hepRepXMLWriter->addPrimitive();           << 
257     hepRepXMLWriter->addAttValue("Radius1", me << 
258                                                << 
259     hepRepXMLWriter->addAttValue("Radius2", me << 
260                                                << 
261     hepRepXMLWriter->addPoint(vertex1.x(), ver << 
262     hepRepXMLWriter->addPoint(vertex2.x(), ver << 
263                                                << 
264     // Inner cylinder.                         << 
265     hepRepXMLWriter->addPrimitive();           << 
266     hepRepXMLWriter->addAttValue("Radius1", me << 
267                                                << 
268     hepRepXMLWriter->addAttValue("Radius2", me << 
269                                                << 
270     hepRepXMLWriter->addPoint(vertex1.x(), ver << 
271     hepRepXMLWriter->addPoint(vertex2.x(), ver << 
272   }                                            << 
273 }                                              << 
274                                                << 
275 void G4HepRepFileSceneHandler::AddSolid(const  << 
276 {                                              << 
277 #ifdef G4HEPREPFILEDEBUG                       << 
278   G4cout << "G4HepRepFileSceneHandler::AddSoli << 
279          << tubs.GetName() << G4endl;          << 
280   PrintThings();                               << 
281 #endif                                         << 
282                                                << 
283   // HepRApp does not correctly represent the  << 
284   // non-standard angles, let the base class c << 
285   G4RotationMatrix r = fObjectTransformation.g << 
286   G4bool linedUpWithAnAxis =                   << 
287     (std::fabs(r.phiX()) <= .001 || std::fabs( << 
288      std::fabs(r.phiZ()) <= .001 || std::fabs( << 
289      std::fabs(r.phiY() - pi) <= .001 || std:: << 
290   // G4cout << "Angle X:" << r.phiX() << ", An << 
291   // Z:" << r.phiZ() << G4endl; G4cout << "lin << 
292   // linedUpWithAnAxis << G4endl;              << 
293                                                << 
294   // HepRep does not have a primitive for a cu << 
295   // so if this cylinder is cut, let the base  << 
296   // solid to polygons.                        << 
297   G4HepRepMessenger* messenger = G4HepRepMesse << 
298   if(tubs.GetDeltaPhiAngle() < twopi || !lined << 
299      messenger->renderCylAsPolygons())         << 
300   {                                            << 
301     G4VSceneHandler::AddSolid(tubs);  // Invok << 
302   }                                            << 
303   else                                         << 
304   {                                            << 
305     if(drawingTraj)                            << 
306       return;                                  << 
307                                                << 
308     if(drawingHit)                             << 
309       InitHit();                               << 
310                                                << 
311     haveVisible = false;                       << 
312     AddHepRepInstance("Cylinder", NULL);       << 
313                                                << 
314     // Get and check applicable vis attributes << 
315     fpVisAttribs = fpViewer->GetApplicableVisA << 
316     if(fpVisAttribs && (fpVisAttribs->IsVisibl << 
317        messenger->getCullInvisibles())         << 
318       return;                                  << 
319                                                << 
320     G4Point3D vertex1(G4Point3D(0., 0., -tubs. << 
321     G4Point3D vertex2(G4Point3D(0., 0., tubs.G << 
322                                                << 
323     vertex1 = (fObjectTransformation) *vertex1 << 
324     vertex2 = (fObjectTransformation) *vertex2 << 
325                                                << 
326     // Outer cylinder.                         << 
327     hepRepXMLWriter->addPrimitive();           << 
328     hepRepXMLWriter->addAttValue("Radius1",    << 
329                                  messenger->ge << 
330     hepRepXMLWriter->addAttValue("Radius2",    << 
331                                  messenger->ge << 
332     hepRepXMLWriter->addPoint(vertex1.x(), ver << 
333     hepRepXMLWriter->addPoint(vertex2.x(), ver << 
334                                                << 
335     // Inner cylinder.                         << 
336     if(tubs.GetInnerRadius() != 0.)            << 
337     {                                          << 
338       hepRepXMLWriter->addPrimitive();         << 
339       hepRepXMLWriter->addAttValue("Radius1",  << 
340                                                << 
341       hepRepXMLWriter->addAttValue("Radius2",  << 
342                                                << 
343       hepRepXMLWriter->addPoint(vertex1.x(), v << 
344       hepRepXMLWriter->addPoint(vertex2.x(), v << 
345     }                                          << 
346   }                                            << 
347 }                                              << 
348                                                << 
349 void G4HepRepFileSceneHandler::AddSolid(const  << 
350 {                                              << 
351 #ifdef G4HEPREPFILEDEBUG                       << 
352   G4cout << "G4HepRepFileSceneHandler::AddSoli << 
353          << trd.GetName() << G4endl;           << 
354   PrintThings();                               << 
355 #endif                                         << 
356                                                << 
357   if(drawingTraj)                              << 
358     return;                                    << 
359                                                << 
360   if(drawingHit)                               << 
361     InitHit();                                 << 
362                                                << 
363   haveVisible = false;                         << 
364   AddHepRepInstance("Prism", NULL);            << 
365                                                << 
366   G4HepRepMessenger* messenger = G4HepRepMesse << 
367                                                << 
368   // Get and check applicable vis attributes.  << 
369   fpVisAttribs = fpViewer->GetApplicableVisAtt << 
370   if(fpVisAttribs && (fpVisAttribs->IsVisible( << 
371      messenger->getCullInvisibles())           << 
372     return;                                    << 
373                                                << 
374   hepRepXMLWriter->addPrimitive();             << 
375                                                << 
376   G4double dx1 = trd.GetXHalfLength1();        << 
377   G4double dy1 = trd.GetYHalfLength1();        << 
378   G4double dx2 = trd.GetXHalfLength2();        << 
379   G4double dy2 = trd.GetYHalfLength2();        << 
380   G4double dz  = trd.GetZHalfLength();         << 
381                                                << 
382   G4Point3D vertex1(G4Point3D(dx1, dy1, -dz)); << 
383   G4Point3D vertex2(G4Point3D(dx1, -dy1, -dz)) << 
384   G4Point3D vertex3(G4Point3D(-dx1, -dy1, -dz) << 
385   G4Point3D vertex4(G4Point3D(-dx1, dy1, -dz)) << 
386   G4Point3D vertex5(G4Point3D(dx2, dy2, dz));  << 
387   G4Point3D vertex6(G4Point3D(dx2, -dy2, dz)); << 
388   G4Point3D vertex7(G4Point3D(-dx2, -dy2, dz)) << 
389   G4Point3D vertex8(G4Point3D(-dx2, dy2, dz)); << 
390                                                << 
391   vertex1 = (fObjectTransformation) *vertex1;  << 
392   vertex2 = (fObjectTransformation) *vertex2;  << 
393   vertex3 = (fObjectTransformation) *vertex3;  << 
394   vertex4 = (fObjectTransformation) *vertex4;  << 
395   vertex5 = (fObjectTransformation) *vertex5;  << 
396   vertex6 = (fObjectTransformation) *vertex6;  << 
397   vertex7 = (fObjectTransformation) *vertex7;  << 
398   vertex8 = (fObjectTransformation) *vertex8;  << 
399                                                << 
400   hepRepXMLWriter->addPoint(vertex1.x(), verte << 
401   hepRepXMLWriter->addPoint(vertex2.x(), verte << 
402   hepRepXMLWriter->addPoint(vertex3.x(), verte << 
403   hepRepXMLWriter->addPoint(vertex4.x(), verte << 
404   hepRepXMLWriter->addPoint(vertex5.x(), verte << 
405   hepRepXMLWriter->addPoint(vertex6.x(), verte << 
406   hepRepXMLWriter->addPoint(vertex7.x(), verte << 
407   hepRepXMLWriter->addPoint(vertex8.x(), verte << 
408 }                                                  85 }
409                                                    86 
410 void G4HepRepFileSceneHandler::AddSolid(const  << 
411 {                                              << 
412 #ifdef G4HEPREPFILEDEBUG                       << 
413   G4cout << "G4HepRepFileSceneHandler::AddSoli << 
414          << trap.GetName() << G4endl;          << 
415   PrintThings();                               << 
416 #endif                                         << 
417   G4VSceneHandler::AddSolid(trap);  // Invoke  << 
418 }                                              << 
419                                                    87 
420 void G4HepRepFileSceneHandler::AddSolid(const  <<  88 G4HepRepFileSceneHandler::~G4HepRepFileSceneHandler() {}
421 {                                              << 
422 #ifdef G4HEPREPFILEDEBUG                       << 
423   G4cout                                       << 
424     << "G4HepRepFileSceneHandler::AddSolid(con << 
425     << sphere.GetName() << G4endl;             << 
426   PrintThings();                               << 
427 #endif                                         << 
428   G4VSceneHandler::AddSolid(sphere);  // Invok << 
429 }                                              << 
430                                                << 
431 void G4HepRepFileSceneHandler::AddSolid(const  << 
432 {                                              << 
433 #ifdef G4HEPREPFILEDEBUG                       << 
434   G4cout << "G4HepRepFileSceneHandler::AddSoli << 
435          << para.GetName() << G4endl;          << 
436   PrintThings();                               << 
437 #endif                                         << 
438   G4VSceneHandler::AddSolid(para);  // Invoke  << 
439 }                                              << 
440                                                << 
441 void G4HepRepFileSceneHandler::AddSolid(const  << 
442 {                                              << 
443 #ifdef G4HEPREPFILEDEBUG                       << 
444   G4cout                                       << 
445     << "G4HepRepFileSceneHandler::AddSolid(con << 
446     << torus.GetName() << G4endl;              << 
447   PrintThings();                               << 
448 #endif                                         << 
449   G4VSceneHandler::AddSolid(torus);  // Invoke << 
450 }                                              << 
451                                                << 
452 void G4HepRepFileSceneHandler::AddSolid(const  << 
453 {                                              << 
454 #ifdef G4HEPREPFILEDEBUG                       << 
455   G4cout << "G4HepRepFileSceneHandler::AddSoli << 
456             "called for "                      << 
457          << polycone.GetName() << G4endl;      << 
458   PrintThings();                               << 
459 #endif                                         << 
460   G4VSceneHandler::AddSolid(polycone);  // Inv << 
461 }                                              << 
462                                                    89 
463 void G4HepRepFileSceneHandler::AddSolid(const  << 
464 {                                              << 
465 #ifdef G4HEPREPFILEDEBUG                       << 
466   G4cout << "G4HepRepFileSceneHandler::AddSoli << 
467             "called for "                      << 
468          << polyhedra.GetName() << G4endl;     << 
469   PrintThings();                               << 
470 #endif                                         << 
471   G4VSceneHandler::AddSolid(polyhedra);  // In << 
472 }                                              << 
473                                                    90 
474 void G4HepRepFileSceneHandler::AddSolid(const  <<  91 void G4HepRepFileSceneHandler::BeginModeling() {
475 {                                              <<  92     G4VisManager* visManager = G4VisManager::GetInstance();
476 #ifdef G4HEPREPFILEDEBUG                       <<  93     const G4VTrajectoryModel* model = visManager->CurrentTrajDrawModel();
477   G4cout << "G4HepRepFileSceneHandler::AddSoli <<  94     trajContext = & model->GetContext();
478          << orb.GetName() << G4endl;           <<  95   
479   PrintThings();                               <<  96   G4VSceneHandler::BeginModeling();  // Required: see G4VSceneHandler.hh.
                                                   >>  97 }
                                                   >>  98 
                                                   >>  99 
                                                   >> 100 void G4HepRepFileSceneHandler::EndModeling() {
                                                   >> 101   G4VSceneHandler::EndModeling();  // Required: see G4VSceneHandler.hh.
                                                   >> 102 }
                                                   >> 103 
                                                   >> 104 void G4HepRepFileSceneHandler::BeginPrimitives2D
                                                   >> 105 (const G4Transform3D& objectTransformation) {
                                                   >> 106 #ifdef G4HEPREPFILEDEBUG
                                                   >> 107   G4cout << "G4HepRepFileSceneHandler::BeginPrimitives2D() " << G4endl;
                                                   >> 108 #endif
                                                   >> 109   inPrimitives2D = true;
                                                   >> 110   G4VSceneHandler::BeginPrimitives2D(objectTransformation);
                                                   >> 111 }
                                                   >> 112 
                                                   >> 113 void G4HepRepFileSceneHandler::EndPrimitives2D () {
                                                   >> 114 #ifdef G4HEPREPFILEDEBUG
                                                   >> 115   G4cout << "G4HepRepFileSceneHandler::EndPrimitives2D() " << G4endl;
                                                   >> 116 #endif
                                                   >> 117   G4VSceneHandler::EndPrimitives2D();
                                                   >> 118   inPrimitives2D = false;
                                                   >> 119 }
                                                   >> 120 
                                                   >> 121 
                                                   >> 122 #ifdef G4HEPREPFILEDEBUG
                                                   >> 123 void G4HepRepFileSceneHandler::PrintThings() {
                                                   >> 124   G4cout <<
                                                   >> 125     "  with transformation "
                                                   >> 126   << (void*)fpObjectTransformation;
                                                   >> 127   G4PhysicalVolumeModel* pPVModel =
                                                   >> 128     dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
                                                   >> 129   if (pPVModel) {
                                                   >> 130     G4VPhysicalVolume* pCurrentPV = pPVModel->GetCurrentPV();
                                                   >> 131     G4LogicalVolume* pCurrentLV = pPVModel->GetCurrentLV();
                                                   >> 132     G4int currentDepth = pPVModel->GetCurrentDepth();
                                                   >> 133     G4cout <<
                                                   >> 134       "\n  current physical volume: "
                                                   >> 135       << pCurrentPV->GetName() <<
                                                   >> 136       "\n  current logical volume: "
                                                   >> 137       << pCurrentLV->GetName() <<
                                                   >> 138       "\n  current depth of geometry tree: "
                                                   >> 139       << currentDepth;
                                                   >> 140   }
                                                   >> 141   G4cout << G4endl;
                                                   >> 142 }
                                                   >> 143 #endif
                                                   >> 144 
                                                   >> 145 
                                                   >> 146 void G4HepRepFileSceneHandler::AddSolid(const G4Box& box) {
                                                   >> 147 #ifdef G4HEPREPFILEDEBUG
                                                   >> 148   G4cout <<
                                                   >> 149     "G4HepRepFileSceneHandler::AddSolid(const G4Box& box) called for "
                                                   >> 150   << box.GetName()
                                                   >> 151   << G4endl;
                                                   >> 152   PrintThings();
                                                   >> 153 #endif
                                                   >> 154   
                                                   >> 155   if (drawingTraj)
                                                   >> 156     return;
                                                   >> 157   
                                                   >> 158   if (drawingHit)
                                                   >> 159     InitHit();
                                                   >> 160   
                                                   >> 161   haveVisible = false;
                                                   >> 162   AddHepRepInstance("Prism", NULL);
                                                   >> 163   
                                                   >> 164   G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
                                                   >> 165   
                                                   >> 166   if (fpVisAttribs && (fpVisAttribs->IsVisible()==0) && messenger->getCullInvisibles())
                                                   >> 167     return;
                                                   >> 168   
                                                   >> 169   hepRepXMLWriter->addPrimitive();
                                                   >> 170   
                                                   >> 171   G4double dx = box.GetXHalfLength();
                                                   >> 172   G4double dy = box.GetYHalfLength();
                                                   >> 173   G4double dz = box.GetZHalfLength();
                                                   >> 174   
                                                   >> 175   G4Point3D vertex1(G4Point3D( dx, dy,-dz));
                                                   >> 176   G4Point3D vertex2(G4Point3D( dx,-dy,-dz));
                                                   >> 177   G4Point3D vertex3(G4Point3D(-dx,-dy,-dz));
                                                   >> 178   G4Point3D vertex4(G4Point3D(-dx, dy,-dz));
                                                   >> 179   G4Point3D vertex5(G4Point3D( dx, dy, dz));
                                                   >> 180   G4Point3D vertex6(G4Point3D( dx,-dy, dz));
                                                   >> 181   G4Point3D vertex7(G4Point3D(-dx,-dy, dz));
                                                   >> 182   G4Point3D vertex8(G4Point3D(-dx, dy, dz));
                                                   >> 183   
                                                   >> 184   vertex1 = (*fpObjectTransformation) * vertex1;
                                                   >> 185   vertex2 = (*fpObjectTransformation) * vertex2;
                                                   >> 186   vertex3 = (*fpObjectTransformation) * vertex3;
                                                   >> 187   vertex4 = (*fpObjectTransformation) * vertex4;
                                                   >> 188   vertex5 = (*fpObjectTransformation) * vertex5;
                                                   >> 189   vertex6 = (*fpObjectTransformation) * vertex6;
                                                   >> 190   vertex7 = (*fpObjectTransformation) * vertex7;
                                                   >> 191   vertex8 = (*fpObjectTransformation) * vertex8;
                                                   >> 192   
                                                   >> 193   hepRepXMLWriter->addPoint(vertex1.x(), vertex1.y(), vertex1.z());
                                                   >> 194   hepRepXMLWriter->addPoint(vertex2.x(), vertex2.y(), vertex2.z());
                                                   >> 195   hepRepXMLWriter->addPoint(vertex3.x(), vertex3.y(), vertex3.z());
                                                   >> 196   hepRepXMLWriter->addPoint(vertex4.x(), vertex4.y(), vertex4.z());
                                                   >> 197   hepRepXMLWriter->addPoint(vertex5.x(), vertex5.y(), vertex5.z());
                                                   >> 198   hepRepXMLWriter->addPoint(vertex6.x(), vertex6.y(), vertex6.z());
                                                   >> 199   hepRepXMLWriter->addPoint(vertex7.x(), vertex7.y(), vertex7.z());
                                                   >> 200   hepRepXMLWriter->addPoint(vertex8.x(), vertex8.y(), vertex8.z());
                                                   >> 201 }
                                                   >> 202 
                                                   >> 203 
                                                   >> 204 void G4HepRepFileSceneHandler::AddSolid(const G4Cons& cons) {
                                                   >> 205 #ifdef G4HEPREPFILEDEBUG
                                                   >> 206   G4cout <<
                                                   >> 207     "G4HepRepFileSceneHandler::AddSolid(const G4Cons& cons) called for "
                                                   >> 208   << cons.GetName()
                                                   >> 209   << G4endl;
                                                   >> 210   PrintThings();
                                                   >> 211 #endif
                                                   >> 212   
                                                   >> 213   // HepRApp does not correctly represent the end faces of cones at
                                                   >> 214   // non-standard angles, let the base class convert these solids to polygons.  
                                                   >> 215   G4RotationMatrix r = fpObjectTransformation->getRotation(); 
                                                   >> 216   G4bool linedUpWithAnAxis = (std::fabs(r.phiX())<=.001 ||  
                                                   >> 217                 std::fabs(r.phiY())<=.001 || 
                                                   >> 218                 std::fabs(r.phiZ())<=.001 ||
                                                   >> 219                 std::fabs(r.phiX()-pi)<=.001 ||
                                                   >> 220                 std::fabs(r.phiY()-pi)<=.001 ||
                                                   >> 221                 std::fabs(r.phiZ()-pi)<=.001);  
                                                   >> 222   //G4cout << "Angle X:" << r.phiX() << ", Angle Y:" << r.phiY() << ", Angle Z:" << r.phiZ() << G4endl;
                                                   >> 223   //G4cout << "linedUpWithAnAxis:" << linedUpWithAnAxis << G4endl;
                                                   >> 224   
                                                   >> 225   // HepRep does not have a primitive for a cut cone,
                                                   >> 226   // so if this cone is cut, let the base class convert this
                                                   >> 227   // solid to polygons.
                                                   >> 228   G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
                                                   >> 229   if (cons.GetDeltaPhiAngle() < twopi || !linedUpWithAnAxis || messenger->renderCylAsPolygons())
                                                   >> 230   {
                                                   >> 231     G4VSceneHandler::AddSolid(cons);  // Invoke default action.
                                                   >> 232   } else {
                                                   >> 233   
                                                   >> 234     if (drawingTraj)
                                                   >> 235       return;
                                                   >> 236     
                                                   >> 237     if (drawingHit)
                                                   >> 238       InitHit();
                                                   >> 239 
                                                   >> 240     haveVisible = false;
                                                   >> 241     AddHepRepInstance("Cylinder", NULL);
                                                   >> 242     
                                                   >> 243     G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
                                                   >> 244     
                                                   >> 245     if (fpVisAttribs && (fpVisAttribs->IsVisible()==0) && messenger->getCullInvisibles())
                                                   >> 246       return;
                                                   >> 247     
                                                   >> 248     G4Point3D vertex1(G4Point3D( 0., 0., -cons.GetZHalfLength()));
                                                   >> 249     G4Point3D vertex2(G4Point3D( 0., 0.,  cons.GetZHalfLength()));
                                                   >> 250     
                                                   >> 251     vertex1 = (*fpObjectTransformation) * vertex1;
                                                   >> 252     vertex2 = (*fpObjectTransformation) * vertex2;
                                                   >> 253         
                                                   >> 254     // Outer cylinder.
                                                   >> 255     hepRepXMLWriter->addPrimitive();
                                                   >> 256     hepRepXMLWriter->addAttValue("Radius1",messenger->getScale() * cons.GetOuterRadiusMinusZ());
                                                   >> 257     hepRepXMLWriter->addAttValue("Radius2",messenger->getScale() * cons.GetOuterRadiusPlusZ());
                                                   >> 258     hepRepXMLWriter->addPoint(vertex1.x(), vertex1.y(), vertex1.z());
                                                   >> 259     hepRepXMLWriter->addPoint(vertex2.x(), vertex2.y(), vertex2.z());
                                                   >> 260     
                                                   >> 261     // Inner cylinder.
                                                   >> 262     hepRepXMLWriter->addPrimitive();
                                                   >> 263     hepRepXMLWriter->addAttValue("Radius1",messenger->getScale() * cons.GetInnerRadiusMinusZ());
                                                   >> 264     hepRepXMLWriter->addAttValue("Radius2",messenger->getScale() * cons.GetInnerRadiusPlusZ());
                                                   >> 265     hepRepXMLWriter->addPoint(vertex1.x(), vertex1.y(), vertex1.z());
                                                   >> 266     hepRepXMLWriter->addPoint(vertex2.x(), vertex2.y(), vertex2.z());
                                                   >> 267   }
                                                   >> 268 }
                                                   >> 269 
                                                   >> 270 
                                                   >> 271 void G4HepRepFileSceneHandler::AddSolid(const G4Tubs& tubs) {
                                                   >> 272 #ifdef G4HEPREPFILEDEBUG
                                                   >> 273   G4cout <<
                                                   >> 274     "G4HepRepFileSceneHandler::AddSolid(const G4Tubs& tubs) called for "
                                                   >> 275   << tubs.GetName()
                                                   >> 276   << G4endl;
                                                   >> 277   PrintThings();
                                                   >> 278 #endif
                                                   >> 279   
                                                   >> 280   // HepRApp does not correctly represent the end faces of cylinders at
                                                   >> 281   // non-standard angles, let the base class convert these solids to polygons.  
                                                   >> 282   G4RotationMatrix r = fpObjectTransformation->getRotation(); 
                                                   >> 283   G4bool linedUpWithAnAxis = (std::fabs(r.phiX())<=.001 ||  
                                                   >> 284                 std::fabs(r.phiY())<=.001 || 
                                                   >> 285                 std::fabs(r.phiZ())<=.001 ||
                                                   >> 286                 std::fabs(r.phiX()-pi)<=.001 ||
                                                   >> 287                 std::fabs(r.phiY()-pi)<=.001 ||
                                                   >> 288                 std::fabs(r.phiZ()-pi)<=.001);  
                                                   >> 289   //G4cout << "Angle X:" << r.phiX() << ", Angle Y:" << r.phiY() << ", Angle Z:" << r.phiZ() << G4endl;
                                                   >> 290   //G4cout << "linedUpWithAnAxis:" << linedUpWithAnAxis << G4endl;
                                                   >> 291   
                                                   >> 292   // HepRep does not have a primitive for a cut cylinder,
                                                   >> 293   // so if this cylinder is cut, let the base class convert this
                                                   >> 294   // solid to polygons.
                                                   >> 295   G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
                                                   >> 296   if (tubs.GetDeltaPhiAngle() < twopi || !linedUpWithAnAxis || messenger->renderCylAsPolygons())
                                                   >> 297   {
                                                   >> 298     G4VSceneHandler::AddSolid(tubs);  // Invoke default action.
                                                   >> 299   } else {
                                                   >> 300   
                                                   >> 301     if (drawingTraj)
                                                   >> 302       return;
                                                   >> 303     
                                                   >> 304     if (drawingHit)
                                                   >> 305       InitHit();
                                                   >> 306 
                                                   >> 307     haveVisible = false;
                                                   >> 308     AddHepRepInstance("Cylinder", NULL);
                                                   >> 309     
                                                   >> 310     if (fpVisAttribs && (fpVisAttribs->IsVisible()==0) && messenger->getCullInvisibles())
                                                   >> 311       return;
                                                   >> 312     
                                                   >> 313     G4Point3D vertex1(G4Point3D( 0., 0., -tubs.GetZHalfLength()));
                                                   >> 314     G4Point3D vertex2(G4Point3D( 0., 0.,  tubs.GetZHalfLength()));
                                                   >> 315     
                                                   >> 316     vertex1 = (*fpObjectTransformation) * vertex1;
                                                   >> 317     vertex2 = (*fpObjectTransformation) * vertex2;
                                                   >> 318     
                                                   >> 319     // Outer cylinder.
                                                   >> 320     hepRepXMLWriter->addPrimitive();
                                                   >> 321     hepRepXMLWriter->addAttValue("Radius1", messenger->getScale() * tubs.GetOuterRadius());
                                                   >> 322     hepRepXMLWriter->addAttValue("Radius2", messenger->getScale() * tubs.GetOuterRadius());
                                                   >> 323     hepRepXMLWriter->addPoint(vertex1.x(), vertex1.y(), vertex1.z());
                                                   >> 324     hepRepXMLWriter->addPoint(vertex2.x(), vertex2.y(), vertex2.z());
                                                   >> 325     
                                                   >> 326     // Inner cylinder.
                                                   >> 327     if (tubs.GetInnerRadius() != 0.) {
                                                   >> 328       hepRepXMLWriter->addPrimitive();
                                                   >> 329       hepRepXMLWriter->addAttValue("Radius1", messenger->getScale() * tubs.GetInnerRadius());
                                                   >> 330       hepRepXMLWriter->addAttValue("Radius2", messenger->getScale() * tubs.GetInnerRadius());
                                                   >> 331       hepRepXMLWriter->addPoint(vertex1.x(), vertex1.y(), vertex1.z());
                                                   >> 332       hepRepXMLWriter->addPoint(vertex2.x(), vertex2.y(), vertex2.z());
                                                   >> 333     }
                                                   >> 334   }
                                                   >> 335 }
                                                   >> 336 
                                                   >> 337 
                                                   >> 338 void G4HepRepFileSceneHandler::AddSolid(const G4Trd& trd) {
                                                   >> 339 #ifdef G4HEPREPFILEDEBUG
                                                   >> 340   G4cout <<
                                                   >> 341     "G4HepRepFileSceneHandler::AddSolid(const G4Trd& trd) called for "
                                                   >> 342   << trd.GetName()
                                                   >> 343   << G4endl;
                                                   >> 344   PrintThings();
                                                   >> 345 #endif
                                                   >> 346   
                                                   >> 347   if (drawingTraj)
                                                   >> 348     return;
                                                   >> 349   
                                                   >> 350   if (drawingHit)
                                                   >> 351     InitHit();
                                                   >> 352   
                                                   >> 353   haveVisible = false;
                                                   >> 354   AddHepRepInstance("Prism", NULL);
                                                   >> 355   
                                                   >> 356   G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
                                                   >> 357   
                                                   >> 358   if (fpVisAttribs && (fpVisAttribs->IsVisible()==0) && messenger->getCullInvisibles())
                                                   >> 359     return;
                                                   >> 360   
                                                   >> 361   hepRepXMLWriter->addPrimitive();
                                                   >> 362   
                                                   >> 363   G4double dx1 = trd.GetXHalfLength1();
                                                   >> 364   G4double dy1 = trd.GetYHalfLength1();
                                                   >> 365   G4double dx2 = trd.GetXHalfLength2();
                                                   >> 366   G4double dy2 = trd.GetYHalfLength2();
                                                   >> 367   G4double dz = trd.GetZHalfLength();
                                                   >> 368   
                                                   >> 369   G4Point3D vertex1(G4Point3D( dx1, dy1,-dz));
                                                   >> 370   G4Point3D vertex2(G4Point3D( dx1,-dy1,-dz));
                                                   >> 371   G4Point3D vertex3(G4Point3D(-dx1,-dy1,-dz));
                                                   >> 372   G4Point3D vertex4(G4Point3D(-dx1, dy1,-dz));
                                                   >> 373   G4Point3D vertex5(G4Point3D( dx2, dy2, dz));
                                                   >> 374   G4Point3D vertex6(G4Point3D( dx2,-dy2, dz));
                                                   >> 375   G4Point3D vertex7(G4Point3D(-dx2,-dy2, dz));
                                                   >> 376   G4Point3D vertex8(G4Point3D(-dx2, dy2, dz));
                                                   >> 377   
                                                   >> 378   vertex1 = (*fpObjectTransformation) * vertex1;
                                                   >> 379   vertex2 = (*fpObjectTransformation) * vertex2;
                                                   >> 380   vertex3 = (*fpObjectTransformation) * vertex3;
                                                   >> 381   vertex4 = (*fpObjectTransformation) * vertex4;
                                                   >> 382   vertex5 = (*fpObjectTransformation) * vertex5;
                                                   >> 383   vertex6 = (*fpObjectTransformation) * vertex6;
                                                   >> 384   vertex7 = (*fpObjectTransformation) * vertex7;
                                                   >> 385   vertex8 = (*fpObjectTransformation) * vertex8;
                                                   >> 386   
                                                   >> 387   hepRepXMLWriter->addPoint(vertex1.x(), vertex1.y(), vertex1.z());
                                                   >> 388   hepRepXMLWriter->addPoint(vertex2.x(), vertex2.y(), vertex2.z());
                                                   >> 389   hepRepXMLWriter->addPoint(vertex3.x(), vertex3.y(), vertex3.z());
                                                   >> 390   hepRepXMLWriter->addPoint(vertex4.x(), vertex4.y(), vertex4.z());
                                                   >> 391   hepRepXMLWriter->addPoint(vertex5.x(), vertex5.y(), vertex5.z());
                                                   >> 392   hepRepXMLWriter->addPoint(vertex6.x(), vertex6.y(), vertex6.z());
                                                   >> 393   hepRepXMLWriter->addPoint(vertex7.x(), vertex7.y(), vertex7.z());
                                                   >> 394   hepRepXMLWriter->addPoint(vertex8.x(), vertex8.y(), vertex8.z());
                                                   >> 395 }
                                                   >> 396 
                                                   >> 397 
                                                   >> 398 void G4HepRepFileSceneHandler::AddSolid(const G4Trap& trap) {
                                                   >> 399 #ifdef G4HEPREPFILEDEBUG
                                                   >> 400   G4cout <<
                                                   >> 401     "G4HepRepFileSceneHandler::AddSolid(const G4Trap& trap) called for "
                                                   >> 402   << trap.GetName()
                                                   >> 403   << G4endl;
                                                   >> 404   PrintThings();
                                                   >> 405 #endif
                                                   >> 406   G4VSceneHandler::AddSolid(trap);  // Invoke default action.
                                                   >> 407 }
                                                   >> 408 
                                                   >> 409 
                                                   >> 410 void G4HepRepFileSceneHandler::AddSolid(const G4Sphere& sphere) {
                                                   >> 411 #ifdef G4HEPREPFILEDEBUG
                                                   >> 412   G4cout <<
                                                   >> 413     "G4HepRepFileSceneHandler::AddSolid(const G4Sphere& sphere) called for "
                                                   >> 414   << sphere.GetName()
                                                   >> 415   << G4endl;
                                                   >> 416   PrintThings();
                                                   >> 417 #endif
                                                   >> 418   G4VSceneHandler::AddSolid(sphere);  // Invoke default action.
                                                   >> 419 }
                                                   >> 420 
                                                   >> 421 
                                                   >> 422 void G4HepRepFileSceneHandler::AddSolid(const G4Para& para) {
                                                   >> 423 #ifdef G4HEPREPFILEDEBUG
                                                   >> 424   G4cout <<
                                                   >> 425     "G4HepRepFileSceneHandler::AddSolid(const G4Para& para) called for "
                                                   >> 426   << para.GetName()
                                                   >> 427   << G4endl;
                                                   >> 428   PrintThings();
                                                   >> 429 #endif
                                                   >> 430   G4VSceneHandler::AddSolid(para);  // Invoke default action.
                                                   >> 431 }
                                                   >> 432 
                                                   >> 433 
                                                   >> 434 void G4HepRepFileSceneHandler::AddSolid(const G4Torus& torus) {
                                                   >> 435 #ifdef G4HEPREPFILEDEBUG
                                                   >> 436   G4cout <<
                                                   >> 437     "G4HepRepFileSceneHandler::AddSolid(const G4Torus& torus) called for "
                                                   >> 438   << torus.GetName()
                                                   >> 439   << G4endl;
                                                   >> 440   PrintThings();
                                                   >> 441 #endif
                                                   >> 442   G4VSceneHandler::AddSolid(torus);  // Invoke default action.
                                                   >> 443 }
                                                   >> 444 
                                                   >> 445 
                                                   >> 446 void G4HepRepFileSceneHandler::AddSolid(const G4Polycone& polycone) {
                                                   >> 447 #ifdef G4HEPREPFILEDEBUG
                                                   >> 448   G4cout <<
                                                   >> 449     "G4HepRepFileSceneHandler::AddSolid(const G4Polycone& polycone) called for "
                                                   >> 450   << polycone.GetName()
                                                   >> 451   << G4endl;
                                                   >> 452   PrintThings();
                                                   >> 453 #endif
                                                   >> 454   G4VSceneHandler::AddSolid(polycone);  // Invoke default action.
                                                   >> 455 }
                                                   >> 456 
                                                   >> 457 
                                                   >> 458 void G4HepRepFileSceneHandler::AddSolid(const G4Polyhedra& polyhedra) {
                                                   >> 459 #ifdef G4HEPREPFILEDEBUG
                                                   >> 460   G4cout <<
                                                   >> 461     "G4HepRepFileSceneHandler::AddSolid(const G4Polyhedra& polyhedra) called for "
                                                   >> 462   << polyhedra.GetName()
                                                   >> 463   << G4endl;
                                                   >> 464   PrintThings();
                                                   >> 465 #endif
                                                   >> 466   G4VSceneHandler::AddSolid(polyhedra);  // Invoke default action.
                                                   >> 467 }
                                                   >> 468 
                                                   >> 469 
                                                   >> 470 void G4HepRepFileSceneHandler::AddSolid(const G4VSolid& solid) {
                                                   >> 471 #ifdef G4HEPREPFILEDEBUG
                                                   >> 472   G4cout <<
                                                   >> 473     "G4HepRepFileSceneHandler::AddSolid(const G4Solid& solid) called for "
                                                   >> 474   << solid.GetName()
                                                   >> 475   << G4endl;
                                                   >> 476   PrintThings();
                                                   >> 477 #endif
                                                   >> 478   G4VSceneHandler::AddSolid(solid);  // Invoke default action.
                                                   >> 479 }
                                                   >> 480 
                                                   >> 481 
                                                   >> 482 void G4HepRepFileSceneHandler::AddCompound (const G4VTrajectory& traj) {
                                                   >> 483 #ifdef G4HEPREPFILEDEBUG
                                                   >> 484   G4cout << "G4HepRepFileSceneHandler::AddCompound(const G4VTrajectory&) " << G4endl;
                                                   >> 485 #endif
                                                   >> 486   
                                                   >> 487   G4TrajectoriesModel* pTrModel =
                                                   >> 488     dynamic_cast<G4TrajectoriesModel*>(fpModel);
                                                   >> 489   if (!pTrModel) G4Exception
                                                   >> 490     ("G4HepRepFileSceneHandler::AddCompound(const G4VTrajectory&)",
                                                   >> 491      "vis-HepRep0001", FatalException, "Not a G4TrajectoriesModel.");
                                                   >> 492   
                                                   >> 493   // Pointers to hold trajectory attribute values and definitions.
                                                   >> 494   std::vector<G4AttValue>* rawTrajAttValues = traj.CreateAttValues();
                                                   >> 495   trajAttValues =
                                                   >> 496     new std::vector<G4AttValue>;
                                                   >> 497   trajAttDefs =
                                                   >> 498     new std::map<G4String,G4AttDef>;
                                                   >> 499   
                                                   >> 500   // Iterators to use with attribute values and definitions.
                                                   >> 501   std::vector<G4AttValue>::iterator iAttVal;
                                                   >> 502   std::map<G4String,G4AttDef>::const_iterator iAttDef;
                                                   >> 503   G4int i;
                                                   >> 504   
                                                   >> 505   // Get trajectory attributes and definitions in standard HepRep style
                                                   >> 506   // (uniform units, 3Vectors decomposed).
                                                   >> 507   if (rawTrajAttValues) {
                                                   >> 508     G4bool error = G4AttCheck(rawTrajAttValues,
                                                   >> 509                   traj.GetAttDefs()).Standard(trajAttValues,trajAttDefs);
                                                   >> 510     if (error) {
                                                   >> 511       G4cout << "G4HepRepFileSceneHandler::AddCompound(traj):"
                                                   >> 512       "\nERROR found during conversion to standard trajectory attributes."
                                                   >> 513       << G4endl;
                                                   >> 514     }
                                                   >> 515 #ifdef G4HEPREPFILEDEBUG 
                                                   >> 516     G4cout <<
                                                   >> 517       "G4HepRepFileSceneHandler::AddCompound(traj): standardised attributes:\n"
                                                   >> 518       << G4AttCheck(trajAttValues,trajAttDefs) << G4endl;
                                                   >> 519 #endif
                                                   >> 520     delete rawTrajAttValues;
                                                   >> 521   }
                                                   >> 522   
                                                   >> 523   // Open the HepRep output file if it is not already open.
                                                   >> 524   CheckFileOpen();
                                                   >> 525   
                                                   >> 526   // Add the Event Data Type if it hasn't already been added.
                                                   >> 527   if (strcmp("Event Data",hepRepXMLWriter->prevTypeName[0])!=0) {
                                                   >> 528     hepRepXMLWriter->addType("Event Data",0);
                                                   >> 529     hepRepXMLWriter->addInstance();
                                                   >> 530   }
                                                   >> 531   
                                                   >> 532   // Add the Trajectories Type.
                                                   >> 533   G4String previousName = hepRepXMLWriter->prevTypeName[1];
                                                   >> 534   hepRepXMLWriter->addType("Trajectories",1);
                                                   >> 535   
                                                   >> 536   // If this is the first trajectory of this event,
                                                   >> 537   // specify attribute values common to all trajectories.
                                                   >> 538   if (strcmp("Trajectories",previousName)!=0) {
                                                   >> 539     hepRepXMLWriter->addAttValue("Layer",100);
                                                   >> 540     
                                                   >> 541     // Take all Trajectory attDefs from first trajectory.
                                                   >> 542     // Would rather be able to get these attDefs without needing a reference from any
                                                   >> 543     // particular trajectory, but don't know how to do that.
                                                   >> 544     // Write out trajectory attribute definitions.
                                                   >> 545     if (trajAttValues && trajAttDefs) {
                                                   >> 546       for (iAttVal = trajAttValues->begin();
                                                   >> 547          iAttVal != trajAttValues->end(); ++iAttVal) {
                                                   >> 548         iAttDef = trajAttDefs->find(iAttVal->GetName());
                                                   >> 549         if (iAttDef != trajAttDefs->end()) {
                                                   >> 550           // Protect against incorrect use of Category.  Anything value other than the
                                                   >> 551           // standard ones will be considered to be in the physics category.
                                                   >> 552           G4String category = iAttDef->second.GetCategory();
                                                   >> 553           if (strcmp(category,"Draw")!=0 &&
                                                   >> 554             strcmp(category,"Physics")!=0 &&
                                                   >> 555             strcmp(category,"Association")!=0 &&
                                                   >> 556             strcmp(category,"PickAction")!=0)
                                                   >> 557             category = "Physics";
                                                   >> 558           hepRepXMLWriter->addAttDef(iAttVal->GetName(), iAttDef->second.GetDesc(),
                                                   >> 559                          category, iAttDef->second.GetExtra());
                                                   >> 560         }
                                                   >> 561       } 
                                                   >> 562     }
                                                   >> 563     
                                                   >> 564     // Take all TrajectoryPoint attDefs from first point of first trajectory.
                                                   >> 565     // Would rather be able to get these attDefs without needing a reference from any
                                                   >> 566     // particular point, but don't know how to do that.
                                                   >> 567     if ((trajContext->GetDrawStepPts() || trajContext->GetDrawAuxPts())
                                                   >> 568       && traj.GetPointEntries()>0) {
                                                   >> 569       G4VTrajectoryPoint* aTrajectoryPoint = traj.GetPoint(0);
                                                   >> 570       
                                                   >> 571       // Pointers to hold trajectory point attribute values and definitions.
                                                   >> 572       std::vector<G4AttValue>* rawPointAttValues = aTrajectoryPoint->CreateAttValues();
                                                   >> 573       std::vector<G4AttValue>* pointAttValues =
                                                   >> 574       new std::vector<G4AttValue>;
                                                   >> 575       std::map<G4String,G4AttDef>* pointAttDefs =
                                                   >> 576       new std::map<G4String,G4AttDef>;
                                                   >> 577       
                                                   >> 578       // Get first trajectory point's attributes and definitions in standard HepRep style
                                                   >> 579       // (uniform units, 3Vectors decomposed).
                                                   >> 580       if (rawPointAttValues) {
                                                   >> 581         G4bool error = G4AttCheck(rawPointAttValues,
                                                   >> 582                       aTrajectoryPoint->GetAttDefs()).Standard(pointAttValues,pointAttDefs);
                                                   >> 583         if (error) {
                                                   >> 584           G4cout << "G4HepRepFileSceneHandler::AddCompound(traj):"
                                                   >> 585           "\nERROR found during conversion to standard first point attributes." << G4endl;
                                                   >> 586         }
                                                   >> 587         
                                                   >> 588         // Write out point attribute definitions.
                                                   >> 589         if (pointAttValues && pointAttDefs) {
                                                   >> 590           for (iAttVal = pointAttValues->begin();
                                                   >> 591              iAttVal != pointAttValues->end(); ++iAttVal) {
                                                   >> 592             iAttDef =
                                                   >> 593             pointAttDefs->find(iAttVal->GetName());
                                                   >> 594             if (iAttDef != pointAttDefs->end()) {
                                                   >> 595               // Protect against incorrect use of Category.  Anything value other than the
                                                   >> 596               // standard ones will be considered to be in the physics category.
                                                   >> 597               G4String category = iAttDef->second.GetCategory();
                                                   >> 598               if (strcmp(category,"Draw")!=0 &&
                                                   >> 599                 strcmp(category,"Physics")!=0 &&
                                                   >> 600                 strcmp(category,"Association")!=0 &&
                                                   >> 601                 strcmp(category,"PickAction")!=0)
                                                   >> 602                 category = "Physics";
                                                   >> 603               // Do not write out the Aux or Pos attribute.  Aux does not conform to the HepRep rule
                                                   >> 604               // that each object can have only one instance of a given AttValue.
                                                   >> 605               // Both of these attributes are redundant to actual position information of the point.
                                                   >> 606               if (strcmp(iAttVal->GetName(),"Aux-X")!=0 &&
                                                   >> 607                 strcmp(iAttVal->GetName(),"Aux-Y")!=0 &&
                                                   >> 608                 strcmp(iAttVal->GetName(),"Aux-Z")!=0 &&
                                                   >> 609                 strcmp(iAttVal->GetName(),"Pos-X")!=0 &&
                                                   >> 610                 strcmp(iAttVal->GetName(),"Pos-Y")!=0 &&
                                                   >> 611                 strcmp(iAttVal->GetName(),"Pos-Z")!=0)
                                                   >> 612                 hepRepXMLWriter->addAttDef(iAttVal->GetName(), iAttDef->second.GetDesc(),
                                                   >> 613                             category, iAttDef->second.GetExtra());
                                                   >> 614             }
                                                   >> 615           }
                                                   >> 616         }
                                                   >> 617         delete rawPointAttValues;
                                                   >> 618       }
                                                   >> 619       
                                                   >> 620       // Clean up point attributes.
                                                   >> 621       if (pointAttValues)
                                                   >> 622         delete pointAttValues;
                                                   >> 623       if (pointAttDefs)
                                                   >> 624         delete pointAttDefs;
                                                   >> 625     }
                                                   >> 626   } // end of special treatment for when this is the first trajectory.
                                                   >> 627   
                                                   >> 628   // Now that we have written out all of the attributes that are based on the
                                                   >> 629   // trajectory's particulars, call base class to deconstruct trajectory into polyline and/or points
                                                   >> 630   // (or nothing if trajectory is to be filtered out).
                                                   >> 631   // If base class calls for drawing points, no points will actually be drawn there since we
                                                   >> 632   // instead need to do point drawing from here (in order to obtain the points attributes,
                                                   >> 633   // not available from AddPrimitive(...point).  Instead, such a call will just serve to set the
                                                   >> 634   // flag that tells us that point drawing was requested for this trajectory (depends on several
                                                   >> 635   // factors including i_mode, trajContext and filtering).
                                                   >> 636   drawingTraj = true;
                                                   >> 637   doneInitTraj = false;
                                                   >> 638   G4VSceneHandler::AddCompound(traj);
                                                   >> 639   drawingTraj = false;
                                                   >> 640   
                                                   >> 641   // Draw step points.
                                                   >> 642   if (trajContext->GetDrawStepPts()) {
                                                   >> 643     if (!doneInitTraj)
                                                   >> 644       InitTrajectory();
                                                   >> 645     // Create Trajectory Points as a subType of Trajectories.
                                                   >> 646     // Note that we should create this heprep type even if there are no actual points.
                                                   >> 647     // This allows the user to tell that points don't exist (admittedly odd) rather
                                                   >> 648     // than that they were omitted by the drawing mode.
                                                   >> 649     previousName = hepRepXMLWriter->prevTypeName[2];
                                                   >> 650     hepRepXMLWriter->addType("Trajectory Step Points",2);
                                                   >> 651 
                                                   >> 652     float redness;
                                                   >> 653     float greenness;
                                                   >> 654     float blueness;     
                                                   >> 655     G4int markSize;
                                                   >> 656     G4bool visible;
                                                   >> 657     G4bool square;
                                                   >> 658     G4Colour colour = trajContext->GetStepPtsColour();
                                                   >> 659     redness = colour.GetRed();
                                                   >> 660     greenness = colour.GetGreen();
                                                   >> 661     blueness = colour.GetBlue();
                                                   >> 662     markSize = (G4int) trajContext->GetStepPtsSize();
                                                   >> 663     visible = (G4int) trajContext->GetStepPtsVisible();
                                                   >> 664     square = (trajContext->GetStepPtsType()==G4Polymarker::squares);
                                                   >> 665 
                                                   >> 666     // Avoiding drawing anything black on black.  
                                                   >> 667     if (redness==0. && greenness==0. && blueness==0.) {
                                                   >> 668       redness = 1.;
                                                   >> 669       greenness = 1.;
                                                   >> 670       blueness = 1.;
                                                   >> 671     }
                                                   >> 672     
                                                   >> 673     // Specify attributes common to all trajectory points.
                                                   >> 674     if (strcmp("Trajectory Step Points",previousName)!=0) {
                                                   >> 675       hepRepXMLWriter->addAttValue("DrawAs","Point");
                                                   >> 676       hepRepXMLWriter->addAttValue("MarkColor", redness, greenness, blueness);
                                                   >> 677       hepRepXMLWriter->addAttValue("MarkSize",markSize);
                                                   >> 678       hepRepXMLWriter->addAttValue("Layer",110);
                                                   >> 679       hepRepXMLWriter->addAttValue("Visibility",visible);
                                                   >> 680       if (square)
                                                   >> 681         hepRepXMLWriter->addAttValue("MarkName","square");
                                                   >> 682       else
                                                   >> 683         hepRepXMLWriter->addAttValue("MarkName","dot");
                                                   >> 684     }
                                                   >> 685     
                                                   >> 686     // Loop over all points on this trajectory.
                                                   >> 687     for (i = 0; i < traj.GetPointEntries(); i++) {
                                                   >> 688       G4VTrajectoryPoint* aTrajectoryPoint = traj.GetPoint(i);
                                                   >> 689       
                                                   >> 690       // Each point is a separate instance of the type Trajectory Points.
                                                   >> 691       hepRepXMLWriter->addInstance();
                                                   >> 692       
                                                   >> 693       // Pointers to hold trajectory point attribute values and definitions.
                                                   >> 694       std::vector<G4AttValue>* rawPointAttValues = aTrajectoryPoint->CreateAttValues();
                                                   >> 695       std::vector<G4AttValue>* pointAttValues =
                                                   >> 696         new std::vector<G4AttValue>;
                                                   >> 697       std::map<G4String,G4AttDef>* pointAttDefs =
                                                   >> 698         new std::map<G4String,G4AttDef>;
                                                   >> 699       
                                                   >> 700       // Get trajectory point attributes and definitions in standard HepRep style
                                                   >> 701       // (uniform units, 3Vectors decomposed).
                                                   >> 702       if (rawPointAttValues) {
                                                   >> 703         G4bool error = G4AttCheck(rawPointAttValues,
                                                   >> 704                       aTrajectoryPoint->GetAttDefs()).Standard(pointAttValues,pointAttDefs);
                                                   >> 705         if (error) {
                                                   >> 706           G4cout << "G4HepRepFileSceneHandler::AddCompound(traj):"
                                                   >> 707           "\nERROR found during conversion to standard point attributes." << G4endl;
                                                   >> 708         }
                                                   >> 709         
                                                   >> 710         // Write out point attribute values.
                                                   >> 711         if (pointAttValues) {
                                                   >> 712           std::vector<G4AttValue>::iterator iAttVal;
                                                   >> 713           for (iAttVal = pointAttValues->begin();
                                                   >> 714              iAttVal != pointAttValues->end(); ++iAttVal)
                                                   >> 715             // Do not write out the Aux or Pos attribute.  Aux does not conform to the HepRep rule
                                                   >> 716             // that each object can have only one instance of a given AttValue.
                                                   >> 717             // Both of these attributes are redundant to actual position information of the point.
                                                   >> 718             if (strcmp(iAttVal->GetName(),"Aux-X")!=0 &&
                                                   >> 719               strcmp(iAttVal->GetName(),"Aux-Y")!=0 &&
                                                   >> 720               strcmp(iAttVal->GetName(),"Aux-Z")!=0 &&
                                                   >> 721               strcmp(iAttVal->GetName(),"Pos-X")!=0 &&
                                                   >> 722               strcmp(iAttVal->GetName(),"Pos-Y")!=0 &&
                                                   >> 723               strcmp(iAttVal->GetName(),"Pos-Z")!=0)
                                                   >> 724               hepRepXMLWriter->addAttValue(iAttVal->GetName(), iAttVal->GetValue());
                                                   >> 725           delete pointAttValues;
                                                   >> 726         }
                                                   >> 727         delete rawPointAttValues;
                                                   >> 728       }
                                                   >> 729       
                                                   >> 730       // Clean up point attributes.
                                                   >> 731       if (pointAttDefs)
                                                   >> 732         delete pointAttDefs;
                                                   >> 733       
                                                   >> 734       // Each trajectory point is made of a single primitive, a point.
                                                   >> 735       hepRepXMLWriter->addPrimitive();
                                                   >> 736       G4Point3D vertex = aTrajectoryPoint->GetPosition();
                                                   >> 737       hepRepXMLWriter->addPoint(vertex.x(), vertex.y(), vertex.z());
                                                   >> 738     }
                                                   >> 739   }
                                                   >> 740   
                                                   >> 741   // Draw Auxiliary Points
                                                   >> 742   if (trajContext->GetDrawAuxPts()) {
                                                   >> 743     if (!doneInitTraj)
                                                   >> 744       InitTrajectory();
                                                   >> 745     // Create Trajectory Points as a subType of Trajectories.
                                                   >> 746     // Note that we should create this heprep type even if there are no actual points.
                                                   >> 747     // This allows the user to tell that points don't exist (admittedly odd) rather
                                                   >> 748     // than that they were omitted by the drawing mode.
                                                   >> 749     previousName = hepRepXMLWriter->prevTypeName[2];
                                                   >> 750     hepRepXMLWriter->addType("Trajectory Auxiliary Points",2);
                                                   >> 751 
                                                   >> 752     float redness;
                                                   >> 753     float greenness;
                                                   >> 754     float blueness;     
                                                   >> 755     G4int markSize;
                                                   >> 756     G4bool visible;
                                                   >> 757     G4bool square;
                                                   >> 758     G4Colour colour = trajContext->GetAuxPtsColour();
                                                   >> 759     redness = colour.GetRed();
                                                   >> 760     greenness = colour.GetGreen();
                                                   >> 761     blueness = colour.GetBlue();
                                                   >> 762     markSize = (G4int) trajContext->GetAuxPtsSize();
                                                   >> 763     visible = (G4int) trajContext->GetAuxPtsVisible();
                                                   >> 764     square = (trajContext->GetAuxPtsType()==G4Polymarker::squares);
                                                   >> 765 
                                                   >> 766     // Avoiding drawing anything black on black.  
                                                   >> 767     if (redness==0. && greenness==0. && blueness==0.) {
                                                   >> 768       redness = 1.;
                                                   >> 769       greenness = 1.;
                                                   >> 770       blueness = 1.;
                                                   >> 771     }
                                                   >> 772     
                                                   >> 773     // Specify attributes common to all trajectory points.
                                                   >> 774     if (strcmp("Trajectory Auxiliary Points",previousName)!=0) {
                                                   >> 775       hepRepXMLWriter->addAttValue("DrawAs","Point");
                                                   >> 776       hepRepXMLWriter->addAttValue("MarkColor", redness, greenness, blueness);
                                                   >> 777       hepRepXMLWriter->addAttValue("MarkSize",markSize);
                                                   >> 778       hepRepXMLWriter->addAttValue("Layer",110);
                                                   >> 779       hepRepXMLWriter->addAttValue("Visibility",visible);
                                                   >> 780       if (square)
                                                   >> 781         hepRepXMLWriter->addAttValue("MarkName","Square");
                                                   >> 782       else
                                                   >> 783         hepRepXMLWriter->addAttValue("MarkName","Dot");
                                                   >> 784     }
                                                   >> 785     
                                                   >> 786     // Loop over all points on this trajectory.
                                                   >> 787     for (i = 0; i < traj.GetPointEntries(); i++) {
                                                   >> 788       G4VTrajectoryPoint* aTrajectoryPoint = traj.GetPoint(i);
                                                   >> 789       
                                                   >> 790       // Each point is a separate instance of the type Trajectory Points.
                                                   >> 791       hepRepXMLWriter->addInstance();
                                                   >> 792       
                                                   >> 793       // Pointers to hold trajectory point attribute values and definitions.
                                                   >> 794       std::vector<G4AttValue>* rawPointAttValues = aTrajectoryPoint->CreateAttValues();
                                                   >> 795       std::vector<G4AttValue>* pointAttValues =
                                                   >> 796         new std::vector<G4AttValue>;
                                                   >> 797       std::map<G4String,G4AttDef>* pointAttDefs =
                                                   >> 798         new std::map<G4String,G4AttDef>;
                                                   >> 799       
                                                   >> 800       // Get trajectory point attributes and definitions in standard HepRep style
                                                   >> 801       // (uniform units, 3Vectors decomposed).
                                                   >> 802       if (rawPointAttValues) {
                                                   >> 803         G4bool error = G4AttCheck(rawPointAttValues,
                                                   >> 804                       aTrajectoryPoint->GetAttDefs()).Standard(pointAttValues,pointAttDefs);
                                                   >> 805         if (error) {
                                                   >> 806           G4cout << "G4HepRepFileSceneHandler::AddCompound(traj):"
                                                   >> 807           "\nERROR found during conversion to standard point attributes." << G4endl;
                                                   >> 808         }
                                                   >> 809         
                                                   >> 810         // Write out point attribute values.
                                                   >> 811         if (pointAttValues) {
                                                   >> 812           std::vector<G4AttValue>::iterator iAttVal;
                                                   >> 813           for (iAttVal = pointAttValues->begin();
                                                   >> 814              iAttVal != pointAttValues->end(); ++iAttVal)
                                                   >> 815             // Do not write out the Aux or Pos attribute.  Aux does not conform to the HepRep rule
                                                   >> 816             // that each object can have only one instance of a given AttValue.
                                                   >> 817             // Both of these attributes are redundant to actual position information of the point.
                                                   >> 818             if (strcmp(iAttVal->GetName(),"Aux-X")!=0 &&
                                                   >> 819               strcmp(iAttVal->GetName(),"Aux-Y")!=0 &&
                                                   >> 820               strcmp(iAttVal->GetName(),"Aux-Z")!=0 &&
                                                   >> 821               strcmp(iAttVal->GetName(),"Pos-X")!=0 &&
                                                   >> 822               strcmp(iAttVal->GetName(),"Pos-Y")!=0 &&
                                                   >> 823               strcmp(iAttVal->GetName(),"Pos-Z")!=0)
                                                   >> 824               hepRepXMLWriter->addAttValue(iAttVal->GetName(), iAttVal->GetValue());
                                                   >> 825           delete pointAttValues;
                                                   >> 826         }
                                                   >> 827         delete rawPointAttValues;
                                                   >> 828       }
                                                   >> 829       
                                                   >> 830       // Clean up point attributes.
                                                   >> 831       if (pointAttDefs)
                                                   >> 832         delete pointAttDefs;
                                                   >> 833       
                                                   >> 834       // Each trajectory point is made of a single primitive, a point.
                                                   >> 835       G4Point3D vertex = aTrajectoryPoint->GetPosition();
                                                   >> 836       
                                                   >> 837       // Loop over auxiliary points associated with this Trajectory Point.
                                                   >> 838       const std::vector<G4ThreeVector>* auxiliaries = aTrajectoryPoint->GetAuxiliaryPoints();
                                                   >> 839       if (0 != auxiliaries) {
                                                   >> 840         for (size_t iAux=0; iAux<auxiliaries->size(); ++iAux) {
                                                   >> 841           const G4ThreeVector auxPos((*auxiliaries)[iAux]);
                                                   >> 842           hepRepXMLWriter->addPrimitive();
                                                   >> 843           hepRepXMLWriter->addPoint(auxPos.x(), auxPos.y(), auxPos.z());
                                                   >> 844         }
                                                   >> 845       }
                                                   >> 846     }
                                                   >> 847   }
                                                   >> 848 }
                                                   >> 849 
                                                   >> 850 
                                                   >> 851 void G4HepRepFileSceneHandler::AddCompound (const G4VHit& hit) {
                                                   >> 852 #ifdef G4HEPREPFILEDEBUG
                                                   >> 853   G4cout << "G4HepRepFileSceneHandler::AddCompound(G4VHit&) " << G4endl;
                                                   >> 854 #endif
                                                   >> 855   
                                                   >> 856   // Pointers to hold hit attribute values and definitions.
                                                   >> 857   std::vector<G4AttValue>* rawHitAttValues = hit.CreateAttValues();
                                                   >> 858   hitAttValues =
                                                   >> 859     new std::vector<G4AttValue>;
                                                   >> 860   hitAttDefs =
                                                   >> 861     new std::map<G4String,G4AttDef>;
                                                   >> 862   
                                                   >> 863   // Iterators to use with attribute values and definitions.
                                                   >> 864   std::vector<G4AttValue>::iterator iAttVal;
                                                   >> 865   std::map<G4String,G4AttDef>::const_iterator iAttDef;
                                                   >> 866   
                                                   >> 867   // Get hit attributes and definitions in standard HepRep style
                                                   >> 868   // (uniform units, 3Vectors decomposed).
                                                   >> 869   if (rawHitAttValues) {
                                                   >> 870     G4bool error = G4AttCheck(rawHitAttValues,
                                                   >> 871                   hit.GetAttDefs()).Standard(hitAttValues,hitAttDefs);
                                                   >> 872     if (error) {
                                                   >> 873       G4cout << "G4HepRepFileSceneHandler::AddCompound(hit):"
                                                   >> 874       "\nERROR found during conversion to standard hit attributes."
                                                   >> 875       << G4endl;
                                                   >> 876     }
                                                   >> 877 #ifdef G4HEPREPFILEDEBUG 
                                                   >> 878     G4cout <<
                                                   >> 879       "G4HepRepFileSceneHandler::AddCompound(hit): standardised attributes:\n"
                                                   >> 880       << G4AttCheck(hitAttValues,hitAttDefs) << G4endl;
                                                   >> 881 #endif
                                                   >> 882     delete rawHitAttValues;
                                                   >> 883   }
                                                   >> 884   
                                                   >> 885   // Open the HepRep output file if it is not already open.
                                                   >> 886   CheckFileOpen();
                                                   >> 887   
                                                   >> 888   // Add the Event Data Type if it hasn't already been added.
                                                   >> 889   if (strcmp("Event Data",hepRepXMLWriter->prevTypeName[0])!=0) {
                                                   >> 890     hepRepXMLWriter->addType("Event Data",0);
                                                   >> 891     hepRepXMLWriter->addInstance();
                                                   >> 892   }
                                                   >> 893   
                                                   >> 894   // Find out the current HitType.
                                                   >> 895   G4String hitType = "Hits";
                                                   >> 896   if (hitAttValues) {
                                                   >> 897     G4bool found = false;
                                                   >> 898     for (iAttVal = hitAttValues->begin();
                                                   >> 899        iAttVal != hitAttValues->end() && !found; ++iAttVal) {
                                                   >> 900       if (strcmp(iAttVal->GetName(),"HitType")==0) {
                                                   >> 901         hitType = iAttVal->GetValue();
                                                   >> 902         found = true;
                                                   >> 903       }
                                                   >> 904     }
                                                   >> 905   }
                                                   >> 906   
                                                   >> 907   // Add the Hits Type.
                                                   >> 908   G4String previousName = hepRepXMLWriter->prevTypeName[1];
                                                   >> 909   hepRepXMLWriter->addType(hitType,1);
                                                   >> 910   
                                                   >> 911   // If this is the first hit of this event,
                                                   >> 912   // specify attribute values common to all hits.
                                                   >> 913   if (strcmp(hitType,previousName)!=0) {
                                                   >> 914     hepRepXMLWriter->addAttValue("Layer",130);
                                                   >> 915     
                                                   >> 916     // Take all Hit attDefs from first hit.
                                                   >> 917     // Would rather be able to get these attDefs without needing a reference from any
                                                   >> 918     // particular hit, but don't know how to do that.
                                                   >> 919     // Write out hit attribute definitions.
                                                   >> 920     if (hitAttValues && hitAttDefs) {
                                                   >> 921       for (iAttVal = hitAttValues->begin();
                                                   >> 922          iAttVal != hitAttValues->end(); ++iAttVal) {
                                                   >> 923         iAttDef = hitAttDefs->find(iAttVal->GetName());
                                                   >> 924         if (iAttDef != hitAttDefs->end()) {
                                                   >> 925           // Protect against incorrect use of Category.  Anything value other than the
                                                   >> 926           // standard ones will be considered to be in the physics category.
                                                   >> 927           G4String category = iAttDef->second.GetCategory();
                                                   >> 928           if (strcmp(category,"Draw")!=0 &&
                                                   >> 929             strcmp(category,"Physics")!=0 &&
                                                   >> 930             strcmp(category,"Association")!=0 &&
                                                   >> 931             strcmp(category,"PickAction")!=0)
                                                   >> 932             category = "Physics";
                                                   >> 933           hepRepXMLWriter->addAttDef(iAttVal->GetName(), iAttDef->second.GetDesc(),
                                                   >> 934                          category, iAttDef->second.GetExtra());
                                                   >> 935         }
                                                   >> 936       }
                                                   >> 937     }
                                                   >> 938   } // end of special treatment for when this is the first hit.
                                                   >> 939   
                                                   >> 940   // Now that we have written out all of the attributes that are based on the
                                                   >> 941   // hit's particulars, call base class to deconstruct hit into a primitives.
                                                   >> 942   drawingHit = true;
                                                   >> 943   doneInitHit = false;
                                                   >> 944   G4VSceneHandler::AddCompound(hit);  // Invoke default action.
                                                   >> 945   drawingHit = false;
                                                   >> 946 }
                                                   >> 947 
                                                   >> 948 
                                                   >> 949 void G4HepRepFileSceneHandler::InitTrajectory() {
                                                   >> 950   if (!doneInitTraj) {
                                                   >> 951     // For every trajectory, add an instance of Type Trajectory.
                                                   >> 952     hepRepXMLWriter->addInstance();
                                                   >> 953     
                                                   >> 954     // Write out the trajectory's attribute values.
                                                   >> 955     if (trajAttValues) {
                                                   >> 956       std::vector<G4AttValue>::iterator iAttVal;
                                                   >> 957       for (iAttVal = trajAttValues->begin();
                                                   >> 958          iAttVal != trajAttValues->end(); ++iAttVal)
                                                   >> 959         hepRepXMLWriter->addAttValue(iAttVal->GetName(), iAttVal->GetValue());
                                                   >> 960       delete trajAttValues; 
                                                   >> 961     }
                                                   >> 962     
                                                   >> 963     // Clean up trajectory attributes.
                                                   >> 964     if (trajAttDefs)
                                                   >> 965       delete trajAttDefs;
                                                   >> 966     
                                                   >> 967     doneInitTraj = true;
                                                   >> 968   }
                                                   >> 969 }
                                                   >> 970 
                                                   >> 971 
                                                   >> 972 void G4HepRepFileSceneHandler::InitHit() {
                                                   >> 973   if (!doneInitHit) {
                                                   >> 974     // For every hit, add an instance of Type Hit.
                                                   >> 975     hepRepXMLWriter->addInstance();
                                                   >> 976     
                                                   >> 977     // Write out the hit's attribute values.
                                                   >> 978     if (hitAttValues) {
                                                   >> 979       std::vector<G4AttValue>::iterator iAttVal;
                                                   >> 980       for (iAttVal = hitAttValues->begin();
                                                   >> 981          iAttVal != hitAttValues->end(); ++iAttVal)
                                                   >> 982         hepRepXMLWriter->addAttValue(iAttVal->GetName(), iAttVal->GetValue());
                                                   >> 983       delete hitAttValues;
                                                   >> 984     }
                                                   >> 985     
                                                   >> 986     // Clean up hit attributes.
                                                   >> 987     if (hitAttDefs)
                                                   >> 988       delete hitAttDefs;
                                                   >> 989     
                                                   >> 990     doneInitHit = true;
                                                   >> 991   }
                                                   >> 992 }
                                                   >> 993 
                                                   >> 994 
                                                   >> 995 void G4HepRepFileSceneHandler::AddPrimitive(const G4Polyline& polyline) {
                                                   >> 996 #ifdef G4HEPREPFILEDEBUG
                                                   >> 997   G4cout <<
                                                   >> 998     "G4HepRepFileSceneHandler::AddPrimitive(const G4Polyline& polyline) called:"
                                                   >> 999     "\n  polyline: " << polyline
                                                   >> 1000   << G4endl;
                                                   >> 1001   PrintThings();
                                                   >> 1002 #endif
                                                   >> 1003   
                                                   >> 1004   G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
                                                   >> 1005   
                                                   >> 1006   if (fpVisAttribs && (fpVisAttribs->IsVisible()==0) && messenger->getCullInvisibles())
                                                   >> 1007     return;
                                                   >> 1008   
                                                   >> 1009   if (inPrimitives2D) {
                                                   >> 1010     if (!warnedAbout2DMarkers) {
                                                   >> 1011       G4cout << "HepRepFile does not currently support 2D lines." << G4endl;
                                                   >> 1012       warnedAbout2DMarkers = true;
                                                   >> 1013     }
                                                   >> 1014     return;
                                                   >> 1015     }
                                                   >> 1016   
                                                   >> 1017   if (drawingTraj)
                                                   >> 1018     InitTrajectory();
                                                   >> 1019     
                                                   >> 1020   if (drawingHit)
                                                   >> 1021     InitHit();
                                                   >> 1022   
                                                   >> 1023   haveVisible = true;
                                                   >> 1024   AddHepRepInstance("Line", polyline);
                                                   >> 1025   
                                                   >> 1026   hepRepXMLWriter->addPrimitive();
                                                   >> 1027   
                                                   >> 1028   for (size_t i=0; i < polyline.size(); i++) {
                                                   >> 1029     G4Point3D vertex = (*fpObjectTransformation) * polyline[i];
                                                   >> 1030     hepRepXMLWriter->addPoint(vertex.x(), vertex.y(), vertex.z());
                                                   >> 1031   }
                                                   >> 1032 }
                                                   >> 1033 
                                                   >> 1034 
                                                   >> 1035 
                                                   >> 1036 void G4HepRepFileSceneHandler::AddPrimitive (const G4Polymarker& line) {
                                                   >> 1037 #ifdef G4HEPREPFILEDEBUG
                                                   >> 1038   G4cout <<
                                                   >> 1039     "G4HepRepFileSceneHandler::AddPrimitive(const G4Polymarker& line) called"
                                                   >> 1040   << G4endl;
                                                   >> 1041   PrintThings();
                                                   >> 1042 #endif
                                                   >> 1043   
                                                   >> 1044   G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
                                                   >> 1045   
                                                   >> 1046   if (fpVisAttribs && (fpVisAttribs->IsVisible()==0) && messenger->getCullInvisibles())
                                                   >> 1047     return;
                                                   >> 1048   
                                                   >> 1049   if (inPrimitives2D) {
                                                   >> 1050     if (!warnedAbout2DMarkers) {
                                                   >> 1051       G4cout << "HepRepFile does not currently support 2D lines." << G4endl;
                                                   >> 1052       warnedAbout2DMarkers = true;
                                                   >> 1053     }
                                                   >> 1054     return;
                                                   >> 1055     }
                                                   >> 1056   
                                                   >> 1057   MarkerSizeType sizeType;
                                                   >> 1058   G4double size = GetMarkerSize (line, sizeType);
                                                   >> 1059   if (sizeType==world)
                                                   >> 1060     size = 4.;
                                                   >> 1061   
                                                   >> 1062   if (drawingTraj)
                                                   >> 1063     return;
                                                   >> 1064   
                                                   >> 1065   if (drawingHit)
                                                   >> 1066     InitHit();
                                                   >> 1067   
                                                   >> 1068   haveVisible = true;
                                                   >> 1069   AddHepRepInstance("Point", line);
                                                   >> 1070   
                                                   >> 1071   hepRepXMLWriter->addAttValue("MarkName", "Dot");
                                                   >> 1072   hepRepXMLWriter->addAttValue("MarkSize", (G4int) size);
                                                   >> 1073   
                                                   >> 1074   hepRepXMLWriter->addPrimitive();
                                                   >> 1075   
                                                   >> 1076   for (size_t i=0; i < line.size(); i++) {
                                                   >> 1077     G4Point3D vertex = (*fpObjectTransformation) * line[i];
                                                   >> 1078     hepRepXMLWriter->addPoint(vertex.x(), vertex.y(), vertex.z());
                                                   >> 1079   }
                                                   >> 1080 }
                                                   >> 1081 
                                                   >> 1082 
                                                   >> 1083 void G4HepRepFileSceneHandler::AddPrimitive(const G4Text& text) {
                                                   >> 1084 #ifdef G4HEPREPFILEDEBUG
                                                   >> 1085   G4cout <<
                                                   >> 1086     "G4HepRepFileSceneHandler::AddPrimitive(const G4Text& text) called:"
                                                   >> 1087     "\n  text: " << text.GetText()
                                                   >> 1088   << G4endl;
                                                   >> 1089   PrintThings();
                                                   >> 1090 #endif
                                                   >> 1091   
                                                   >> 1092   if (!inPrimitives2D) {
                                                   >> 1093     if (!warnedAbout3DText) {
                                                   >> 1094       G4cout << "HepRepFile does not currently support 3D text." << G4endl;
                                                   >> 1095       G4cout << "HepRep browsers can directly display text attributes on request." << G4endl;
                                                   >> 1096       G4cout << "See Application Developers Guide for how to attach attributes to viewable objects." << G4endl;
                                                   >> 1097       warnedAbout3DText = true;
                                                   >> 1098     }
                                                   >> 1099     return;
                                                   >> 1100     }
                                                   >> 1101   
                                                   >> 1102   MarkerSizeType sizeType;
                                                   >> 1103   G4double size = GetMarkerSize (text, sizeType);
                                                   >> 1104   if (sizeType==world)
                                                   >> 1105     size = 12.;
                                                   >> 1106   
                                                   >> 1107   haveVisible = true;
                                                   >> 1108   AddHepRepInstance("Text", text);
                                                   >> 1109   
                                                   >> 1110   hepRepXMLWriter->addAttValue("VAlign", "Top");
                                                   >> 1111   hepRepXMLWriter->addAttValue("HAlign", "Left");
                                                   >> 1112   hepRepXMLWriter->addAttValue("FontName", "Arial");
                                                   >> 1113   hepRepXMLWriter->addAttValue("FontStyle", "Plain");
                                                   >> 1114   hepRepXMLWriter->addAttValue("FontSize", (G4int) size);
                                                   >> 1115   hepRepXMLWriter->addAttValue("FontHasBanner", "TRUE");
                                                   >> 1116   hepRepXMLWriter->addAttValue("FontBannerColor", "0,0,0");
                                                   >> 1117   
                                                   >> 1118   const G4Colour& colour = GetTextColour(text);
                                                   >> 1119   float redness = colour.GetRed();
                                                   >> 1120   float greenness = colour.GetGreen();
                                                   >> 1121   float blueness = colour.GetBlue();
                                                   >> 1122     
                                                   >> 1123   // Avoiding drawing anything black on black.  
                                                   >> 1124   if (redness==0. && greenness==0. && blueness==0.) {
                                                   >> 1125     redness = 1.;
                                                   >> 1126     greenness = 1.;
                                                   >> 1127     blueness = 1.;
                                                   >> 1128   }
                                                   >> 1129   hepRepXMLWriter->addAttValue("FontColor",redness,greenness,blueness);
                                                   >> 1130   
                                                   >> 1131   hepRepXMLWriter->addPrimitive();
                                                   >> 1132   
                                                   >> 1133   hepRepXMLWriter->addAttValue("Text", text.GetText());
                                                   >> 1134   hepRepXMLWriter->addAttValue("VPos", .99-text.GetYOffset());
                                                   >> 1135   hepRepXMLWriter->addAttValue("HPos", text.GetXOffset());
                                                   >> 1136 }
                                                   >> 1137 
                                                   >> 1138 
                                                   >> 1139 void G4HepRepFileSceneHandler::AddPrimitive(const G4Circle& circle) {
                                                   >> 1140 #ifdef G4HEPREPFILEDEBUG
                                                   >> 1141   G4cout <<
                                                   >> 1142     "G4HepRepFileSceneHandler::AddPrimitive(const G4Circle& circle) called:"
                                                   >> 1143     "\n  radius: " << circle.GetWorldRadius()
                                                   >> 1144   << G4endl;
                                                   >> 1145   PrintThings();
                                                   >> 1146 #endif
                                                   >> 1147   
                                                   >> 1148   G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
                                                   >> 1149   
                                                   >> 1150   if (fpVisAttribs && (fpVisAttribs->IsVisible()==0) && messenger->getCullInvisibles())
                                                   >> 1151     return;
                                                   >> 1152   
                                                   >> 1153   if (inPrimitives2D) {
                                                   >> 1154     if (!warnedAbout2DMarkers) {
                                                   >> 1155       G4cout << "HepRepFile does not currently support 2D circles." << G4endl;
                                                   >> 1156       warnedAbout2DMarkers = true;
                                                   >> 1157     }
                                                   >> 1158     return;
                                                   >> 1159     }
                                                   >> 1160   
                                                   >> 1161   MarkerSizeType sizeType;
                                                   >> 1162   G4double size = GetMarkerSize (circle, sizeType);
                                                   >> 1163   if (sizeType==world)
                                                   >> 1164     size = 4.;
                                                   >> 1165   
                                                   >> 1166   if (drawingTraj)
                                                   >> 1167     return;
                                                   >> 1168   
                                                   >> 1169   if (drawingHit)
                                                   >> 1170     InitHit();
                                                   >> 1171   
                                                   >> 1172   haveVisible = true;
                                                   >> 1173   AddHepRepInstance("Point", circle);
                                                   >> 1174   
                                                   >> 1175   hepRepXMLWriter->addAttValue("MarkName", "Dot");
                                                   >> 1176   hepRepXMLWriter->addAttValue("MarkSize", (G4int) size);
                                                   >> 1177   
                                                   >> 1178   hepRepXMLWriter->addPrimitive();
                                                   >> 1179   
                                                   >> 1180   G4Point3D center = (*fpObjectTransformation) * circle.GetPosition();
                                                   >> 1181   hepRepXMLWriter->addPoint(center.x(), center.y(), center.z());
                                                   >> 1182 }
                                                   >> 1183 
                                                   >> 1184 
                                                   >> 1185 void G4HepRepFileSceneHandler::AddPrimitive(const G4Square& square) {
                                                   >> 1186 #ifdef G4HEPREPFILEDEBUG
                                                   >> 1187   G4cout <<
                                                   >> 1188     "G4HepRepFileSceneHandler::AddPrimitive(const G4Square& square) called:"
                                                   >> 1189     "\n  side: " << square.GetWorldRadius()
                                                   >> 1190   << G4endl;
                                                   >> 1191   PrintThings();
                                                   >> 1192 #endif
                                                   >> 1193   
                                                   >> 1194   G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
                                                   >> 1195   
                                                   >> 1196   if (fpVisAttribs && (fpVisAttribs->IsVisible()==0) && messenger->getCullInvisibles())
                                                   >> 1197     return;
                                                   >> 1198   
                                                   >> 1199   if (inPrimitives2D) {
                                                   >> 1200     if (!warnedAbout2DMarkers) {
                                                   >> 1201       G4cout << "HepRepFile does not currently support 2D squares." << G4endl;
                                                   >> 1202       warnedAbout2DMarkers = true;
                                                   >> 1203     }
                                                   >> 1204     return;
                                                   >> 1205     }
                                                   >> 1206   
                                                   >> 1207   MarkerSizeType sizeType;
                                                   >> 1208   G4double size = GetMarkerSize (square, sizeType);
                                                   >> 1209   if (sizeType==world)
                                                   >> 1210     size = 4.;
                                                   >> 1211   
                                                   >> 1212   if (drawingTraj)
                                                   >> 1213     return;
                                                   >> 1214   
                                                   >> 1215   if (drawingHit)
                                                   >> 1216     InitHit();
                                                   >> 1217   
                                                   >> 1218   haveVisible = true;
                                                   >> 1219   AddHepRepInstance("Point", square);
                                                   >> 1220   
                                                   >> 1221   hepRepXMLWriter->addAttValue("MarkName", "Square");
                                                   >> 1222   hepRepXMLWriter->addAttValue("MarkSize", (G4int) size);
                                                   >> 1223   
                                                   >> 1224   hepRepXMLWriter->addPrimitive();
                                                   >> 1225   
                                                   >> 1226   G4Point3D center = (*fpObjectTransformation) * square.GetPosition();
                                                   >> 1227   hepRepXMLWriter->addPoint(center.x(), center.y(), center.z());
                                                   >> 1228 }
                                                   >> 1229 
                                                   >> 1230 
                                                   >> 1231 void G4HepRepFileSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) {
                                                   >> 1232 #ifdef G4HEPREPFILEDEBUG
                                                   >> 1233   G4cout <<
                                                   >> 1234     "G4HepRepFileSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) called."
                                                   >> 1235   << G4endl;
                                                   >> 1236   PrintThings();
                                                   >> 1237 #endif
                                                   >> 1238   
                                                   >> 1239   G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
                                                   >> 1240   
                                                   >> 1241   if (fpVisAttribs && (fpVisAttribs->IsVisible()==0) && messenger->getCullInvisibles())
                                                   >> 1242     return;
                                                   >> 1243   
                                                   >> 1244   if(polyhedron.GetNoFacets()==0)return;
                                                   >> 1245   
                                                   >> 1246   if (drawingTraj)
                                                   >> 1247     return;
                                                   >> 1248   
                                                   >> 1249   if (drawingHit)
                                                   >> 1250     InitHit();
                                                   >> 1251   
                                                   >> 1252   haveVisible = true;
                                                   >> 1253   AddHepRepInstance("Polygon", polyhedron);
                                                   >> 1254   
                                                   >> 1255   G4Normal3D surfaceNormal;
                                                   >> 1256   G4Point3D vertex;
                                                   >> 1257   
                                                   >> 1258   G4bool notLastFace;
                                                   >> 1259   do {
                                                   >> 1260     hepRepXMLWriter->addPrimitive();
                                                   >> 1261     notLastFace = polyhedron.GetNextNormal (surfaceNormal);
                                                   >> 1262     
                                                   >> 1263     G4int edgeFlag = 1;
                                                   >> 1264     G4bool notLastEdge;
                                                   >> 1265     do {
                                                   >> 1266       notLastEdge = polyhedron.GetNextVertex (vertex, edgeFlag);
                                                   >> 1267       vertex = (*fpObjectTransformation) * vertex;
                                                   >> 1268       hepRepXMLWriter->addPoint(vertex.x(), vertex.y(), vertex.z());
                                                   >> 1269     } while (notLastEdge);
                                                   >> 1270   } while (notLastFace);
                                                   >> 1271 }
                                                   >> 1272 
                                                   >> 1273 
                                                   >> 1274 void G4HepRepFileSceneHandler::AddPrimitive(const G4NURBS&) {
                                                   >> 1275 #ifdef G4HEPREPFILEDEBUG
                                                   >> 1276   G4cout <<
                                                   >> 1277     "G4HepRepFileSceneHandler::AddPrimitive(const G4NURBS& nurbs) called."
                                                   >> 1278   << G4endl;
                                                   >> 1279   PrintThings();
480 #endif                                            1280 #endif
481   G4VSceneHandler::AddSolid(orb);  // Invoke d << 1281     G4cout << "G4HepRepFileSceneHandler::AddPrimitive G4NURBS : not implemented. " << G4endl;
482 }                                                 1282 }
483                                                   1283 
484 void G4HepRepFileSceneHandler::AddSolid(const  << 
485 {                                              << 
486 #ifdef G4HEPREPFILEDEBUG                       << 
487   G4cout << "G4HepRepFileSceneHandler::AddSoli << 
488             "called for "                      << 
489          << ellipsoid.GetName() << G4endl;     << 
490   PrintThings();                               << 
491 #endif                                         << 
492   G4VSceneHandler::AddSolid(ellipsoid);  // In << 
493 }                                              << 
494                                                   1284 
495 void G4HepRepFileSceneHandler::AddSolid(const  << 1285 G4HepRepFileXMLWriter *G4HepRepFileSceneHandler::GetHepRepXMLWriter() {
496 {                                              << 1286     return hepRepXMLWriter;
497 #ifdef G4HEPREPFILEDEBUG                       << 
498   G4cout << "G4HepRepFileSceneHandler::AddSoli << 
499             "called for "                      << 
500          << tess.GetName() << G4endl;          << 
501   PrintThings();                               << 
502 #endif                                         << 
503   G4VSceneHandler::AddSolid(tess);  // Invoke  << 
504 }                                              << 
505                                                << 
506 void G4HepRepFileSceneHandler::AddSolid(const  << 
507 {                                              << 
508 #ifdef G4HEPREPFILEDEBUG                       << 
509   G4cout                                       << 
510     << "G4HepRepFileSceneHandler::AddSolid(con << 
511     << solid.GetName() << G4endl;              << 
512   PrintThings();                               << 
513 #endif                                         << 
514   G4VSceneHandler::AddSolid(solid);  // Invoke << 
515 }                                                 1287 }
516                                                   1288 
517 void G4HepRepFileSceneHandler::AddCompound(con << 
518 {                                              << 
519 #ifdef G4HEPREPFILEDEBUG                       << 
520   G4cout << "G4HepRepFileSceneHandler::AddComp << 
521          << G4endl;                            << 
522 #endif                                         << 
523                                                << 
524   G4TrajectoriesModel* pTrModel = dynamic_cast << 
525   if(!pTrModel)                                << 
526     G4Exception("G4HepRepFileSceneHandler::Add << 
527                 "vis-HepRep0001", FatalExcepti << 
528                                                << 
529   // Pointers to hold trajectory attribute val << 
530   std::vector<G4AttValue>* rawTrajAttValues =  << 
531   trajAttValues                             =  << 
532   trajAttDefs                               =  << 
533                                                << 
534   // Iterators to use with attribute values an << 
535   std::vector<G4AttValue>::iterator iAttVal;   << 
536   std::map<G4String, G4AttDef>::const_iterator << 
537   G4int i;                                     << 
538                                                << 
539   // Get trajectory attributes and definitions << 
540   // (uniform units, 3Vectors decomposed).     << 
541   if(rawTrajAttValues)                         << 
542   {                                            << 
543     G4bool error = G4AttCheck(rawTrajAttValues << 
544                      .Standard(trajAttValues,  << 
545     if(error)                                  << 
546     {                                          << 
547       G4cout                                   << 
548         << "G4HepRepFileSceneHandler::AddCompo << 
549            "\nERROR found during conversion to << 
550         << G4endl;                             << 
551     }                                          << 
552 #ifdef G4HEPREPFILEDEBUG                       << 
553     G4cout << "G4HepRepFileSceneHandler::AddCo << 
554               "attributes:\n"                  << 
555            << G4AttCheck(trajAttValues, trajAt << 
556 #endif                                         << 
557     delete rawTrajAttValues;                   << 
558   }                                            << 
559                                                << 
560   // Open the HepRep output file if it is not  << 
561   CheckFileOpen();                             << 
562                                                << 
563   // Add the Event Data Type if it hasn't alre << 
564   if(strcmp("Event Data", hepRepXMLWriter->pre << 
565   {                                            << 
566     hepRepXMLWriter->addType("Event Data", 0); << 
567     hepRepXMLWriter->addInstance();            << 
568   }                                            << 
569                                                << 
570   // Add the Trajectories Type.                << 
571   G4String previousName = hepRepXMLWriter->pre << 
572   hepRepXMLWriter->addType("Trajectories", 1); << 
573                                                << 
574   // If this is the first trajectory of this e << 
575   // specify attribute values common to all tr << 
576   if(strcmp("Trajectories", previousName) != 0 << 
577   {                                            << 
578     hepRepXMLWriter->addAttValue("Layer", 100) << 
579                                                << 
580     // Take all Trajectory attDefs from first  << 
581     // Would rather be able to get these attDe << 
582     // from any particular trajectory, but don << 
583     // trajectory attribute definitions.       << 
584     if(trajAttValues && trajAttDefs)           << 
585     {                                          << 
586       for(iAttVal = trajAttValues->begin(); iA << 
587           ++iAttVal)                           << 
588       {                                        << 
589         iAttDef = trajAttDefs->find(iAttVal->G << 
590         if(iAttDef != trajAttDefs->end())      << 
591         {                                      << 
592           // Protect against incorrect use of  << 
593           // than the standard ones will be co << 
594           // category.                         << 
595           G4String category = iAttDef->second. << 
596           if(strcmp(category, "Draw") != 0 &&  << 
597              strcmp(category, "Physics") != 0  << 
598              strcmp(category, "Association") ! << 
599              strcmp(category, "PickAction") != << 
600             category = "Physics";              << 
601           hepRepXMLWriter->addAttDef(iAttVal-> << 
602                                      iAttDef-> << 
603                                      iAttDef-> << 
604         }                                      << 
605       }                                        << 
606     }                                          << 
607                                                << 
608     // Take all TrajectoryPoint attDefs from f << 
609     // Would rather be able to get these attDe << 
610     // from any particular point, but don't kn << 
611     if((trajContext->GetDrawStepPts() || trajC << 
612        traj.GetPointEntries() > 0)             << 
613     {                                          << 
614       G4VTrajectoryPoint* aTrajectoryPoint = t << 
615                                                << 
616       // Pointers to hold trajectory point att << 
617       std::vector<G4AttValue>* rawPointAttValu << 
618         aTrajectoryPoint->CreateAttValues();   << 
619       std::vector<G4AttValue>* pointAttValues  << 
620       std::map<G4String, G4AttDef>* pointAttDe << 
621         new std::map<G4String, G4AttDef>;      << 
622                                                << 
623       // Get first trajectory point's attribut << 
624       // HepRep style (uniform units, 3Vectors << 
625       if(rawPointAttValues)                    << 
626       {                                        << 
627         G4bool error =                         << 
628           G4AttCheck(rawPointAttValues, aTraje << 
629             .Standard(pointAttValues, pointAtt << 
630         if(error)                              << 
631         {                                      << 
632           G4cout << "G4HepRepFileSceneHandler: << 
633                     "\nERROR found during conv << 
634                     "attributes."              << 
635                  << G4endl;                    << 
636         }                                      << 
637                                                << 
638         // Write out point attribute definitio << 
639         if(pointAttValues && pointAttDefs)     << 
640         {                                      << 
641           for(iAttVal = pointAttValues->begin( << 
642               iAttVal != pointAttValues->end() << 
643           {                                    << 
644             iAttDef = pointAttDefs->find(iAttV << 
645             if(iAttDef != pointAttDefs->end()) << 
646             {                                  << 
647               // Protect against incorrect use << 
648               // other than the standard ones  << 
649               // physics category.             << 
650               G4String category = iAttDef->sec << 
651               if(strcmp(category, "Draw") != 0 << 
652                  strcmp(category, "Physics") ! << 
653                  strcmp(category, "Association << 
654                  strcmp(category, "PickAction" << 
655                 category = "Physics";          << 
656               // Do not write out the Aux or P << 
657               // conform to the HepRep rule th << 
658               // instance of a given AttValue. << 
659               // redundant to actual position  << 
660               if(strcmp(iAttVal->GetName(), "A << 
661                  strcmp(iAttVal->GetName(), "A << 
662                  strcmp(iAttVal->GetName(), "A << 
663                  strcmp(iAttVal->GetName(), "P << 
664                  strcmp(iAttVal->GetName(), "P << 
665                  strcmp(iAttVal->GetName(), "P << 
666                 hepRepXMLWriter->addAttDef(iAt << 
667                                            iAt << 
668                                            iAt << 
669             }                                  << 
670           }                                    << 
671         }                                      << 
672         delete rawPointAttValues;              << 
673       }                                        << 
674                                                << 
675       // Clean up point attributes.            << 
676       if(pointAttValues)                       << 
677         delete pointAttValues;                 << 
678       if(pointAttDefs)                         << 
679         delete pointAttDefs;                   << 
680     }                                          << 
681   }  // end of special treatment for when this << 
682                                                << 
683   // Now that we have written out all of the a << 
684   // trajectory's particulars, call base class << 
685   // polyline and/or points (or nothing if tra << 
686   // base class calls for drawing points, no p << 
687   // since we instead need to do point drawing << 
688   // points attributes, not available from Add << 
689   // such a call will just serve to set the fl << 
690   // drawing was requested for this trajectory << 
691   // including trajContext and filtering).     << 
692   drawingTraj  = true;                         << 
693   doneInitTraj = false;                        << 
694   G4VSceneHandler::AddCompound(traj);          << 
695   drawingTraj = false;                         << 
696                                                << 
697   // Draw step points.                         << 
698   if(trajContext->GetDrawStepPts())            << 
699   {                                            << 
700     if(!doneInitTraj)                          << 
701       InitTrajectory();                        << 
702     // Create Trajectory Points as a subType o << 
703     // Note that we should create this heprep  << 
704     // points. This allows the user to tell th << 
705     // odd) rather than that they were omitted << 
706     previousName = hepRepXMLWriter->prevTypeNa << 
707     hepRepXMLWriter->addType("Trajectory Step  << 
708                                                << 
709     float redness;                             << 
710     float greenness;                           << 
711     float blueness;                            << 
712     G4int markSize;                            << 
713     G4bool visible;                            << 
714     G4bool square;                             << 
715     G4Colour colour = trajContext->GetStepPtsC << 
716     redness         = colour.GetRed();         << 
717     greenness       = colour.GetGreen();       << 
718     blueness        = colour.GetBlue();        << 
719     markSize        = (G4int) trajContext->Get << 
720     visible         = (G4int) trajContext->Get << 
721     square          = (trajContext->GetStepPts << 
722                                                << 
723     // Avoiding drawing anything black on blac << 
724     if(redness == 0. && greenness == 0. && blu << 
725     {                                          << 
726       redness   = 1.;                          << 
727       greenness = 1.;                          << 
728       blueness  = 1.;                          << 
729     }                                          << 
730                                                << 
731     // Specify attributes common to all trajec << 
732     if(strcmp("Trajectory Step Points", previo << 
733     {                                          << 
734       hepRepXMLWriter->addAttValue("DrawAs", " << 
735       hepRepXMLWriter->addAttValue("MarkColor" << 
736       hepRepXMLWriter->addAttValue("MarkSize", << 
737       hepRepXMLWriter->addAttValue("Layer", 11 << 
738       hepRepXMLWriter->addAttValue("Visibility << 
739       if(square)                               << 
740         hepRepXMLWriter->addAttValue("MarkName << 
741       else                                     << 
742         hepRepXMLWriter->addAttValue("MarkName << 
743     }                                          << 
744                                                << 
745     // Loop over all points on this trajectory << 
746     for(i = 0; i < traj.GetPointEntries(); i++ << 
747     {                                          << 
748       G4VTrajectoryPoint* aTrajectoryPoint = t << 
749                                                << 
750       // Each point is a separate instance of  << 
751       hepRepXMLWriter->addInstance();          << 
752                                                << 
753       // Pointers to hold trajectory point att << 
754       std::vector<G4AttValue>* rawPointAttValu << 
755         aTrajectoryPoint->CreateAttValues();   << 
756       std::vector<G4AttValue>* pointAttValues  << 
757       std::map<G4String, G4AttDef>* pointAttDe << 
758         new std::map<G4String, G4AttDef>;      << 
759                                                << 
760       // Get trajectory point attributes and d << 
761       // style (uniform units, 3Vectors decomp << 
762       if(rawPointAttValues)                    << 
763       {                                        << 
764         G4bool error =                         << 
765           G4AttCheck(rawPointAttValues, aTraje << 
766             .Standard(pointAttValues, pointAtt << 
767         if(error)                              << 
768         {                                      << 
769           G4cout                               << 
770             << "G4HepRepFileSceneHandler::AddC << 
771                "\nERROR found during conversio << 
772             << G4endl;                         << 
773         }                                      << 
774                                                << 
775         // Write out point attribute values.   << 
776         if(pointAttValues)                     << 
777         {                                      << 
778           for(iAttVal = pointAttValues->begin( << 
779               iAttVal != pointAttValues->end() << 
780             // Do not write out the Aux or Pos << 
781             // to the HepRep rule that each ob << 
782             // a given AttValue. Both of these << 
783             // actual position information of  << 
784             if(strcmp(iAttVal->GetName(), "Aux << 
785                strcmp(iAttVal->GetName(), "Aux << 
786                strcmp(iAttVal->GetName(), "Aux << 
787                strcmp(iAttVal->GetName(), "Pos << 
788                strcmp(iAttVal->GetName(), "Pos << 
789                strcmp(iAttVal->GetName(), "Pos << 
790               hepRepXMLWriter->addAttValue(iAt << 
791                                            iAt << 
792         }                                      << 
793       }                                        << 
794                                                << 
795       // Clean up point attributes.            << 
796       delete pointAttDefs;                     << 
797       delete pointAttValues;                   << 
798       delete rawPointAttValues;                << 
799                                                << 
800       // Each trajectory point is made of a si << 
801       hepRepXMLWriter->addPrimitive();         << 
802       G4Point3D vertex = aTrajectoryPoint->Get << 
803       hepRepXMLWriter->addPoint(vertex.x(), ve << 
804     }                                          << 
805   }                                            << 
806                                                << 
807   // Draw Auxiliary Points                     << 
808   if(trajContext->GetDrawAuxPts())             << 
809   {                                            << 
810     if(!doneInitTraj)                          << 
811       InitTrajectory();                        << 
812     // Create Trajectory Points as a subType o << 
813     // Note that we should create this heprep  << 
814     // points. This allows the user to tell th << 
815     // odd) rather than that they were omitted << 
816     previousName = hepRepXMLWriter->prevTypeNa << 
817     hepRepXMLWriter->addType("Trajectory Auxil << 
818                                                << 
819     float redness;                             << 
820     float greenness;                           << 
821     float blueness;                            << 
822     G4int markSize;                            << 
823     G4bool visible;                            << 
824     G4bool square;                             << 
825     G4Colour colour = trajContext->GetAuxPtsCo << 
826     redness         = colour.GetRed();         << 
827     greenness       = colour.GetGreen();       << 
828     blueness        = colour.GetBlue();        << 
829     markSize        = (G4int) trajContext->Get << 
830     visible         = (G4int) trajContext->Get << 
831     square          = (trajContext->GetAuxPtsT << 
832                                                << 
833     // Avoiding drawing anything black on blac << 
834     if(redness == 0. && greenness == 0. && blu << 
835     {                                          << 
836       redness   = 1.;                          << 
837       greenness = 1.;                          << 
838       blueness  = 1.;                          << 
839     }                                          << 
840                                                << 
841     // Specify attributes common to all trajec << 
842     if(strcmp("Trajectory Auxiliary Points", p << 
843     {                                          << 
844       hepRepXMLWriter->addAttValue("DrawAs", " << 
845       hepRepXMLWriter->addAttValue("MarkColor" << 
846       hepRepXMLWriter->addAttValue("MarkSize", << 
847       hepRepXMLWriter->addAttValue("Layer", 11 << 
848       hepRepXMLWriter->addAttValue("Visibility << 
849       if(square)                               << 
850         hepRepXMLWriter->addAttValue("MarkName << 
851       else                                     << 
852         hepRepXMLWriter->addAttValue("MarkName << 
853     }                                          << 
854                                                << 
855     // Loop over all points on this trajectory << 
856     for(i = 0; i < traj.GetPointEntries(); i++ << 
857     {                                          << 
858       G4VTrajectoryPoint* aTrajectoryPoint = t << 
859                                                << 
860       // Each point is a separate instance of  << 
861       hepRepXMLWriter->addInstance();          << 
862                                                << 
863       // Pointers to hold trajectory point att << 
864       std::vector<G4AttValue>* rawPointAttValu << 
865         aTrajectoryPoint->CreateAttValues();   << 
866       std::vector<G4AttValue>* pointAttValues  << 
867       std::map<G4String, G4AttDef>* pointAttDe << 
868         new std::map<G4String, G4AttDef>;      << 
869                                                << 
870       // Get trajectory point attributes and d << 
871       // style (uniform units, 3Vectors decomp << 
872       if(rawPointAttValues)                    << 
873       {                                        << 
874         G4bool error =                         << 
875           G4AttCheck(rawPointAttValues, aTraje << 
876             .Standard(pointAttValues, pointAtt << 
877         if(error)                              << 
878         {                                      << 
879           G4cout                               << 
880             << "G4HepRepFileSceneHandler::AddC << 
881                "\nERROR found during conversio << 
882             << G4endl;                         << 
883         }                                      << 
884                                                << 
885         // Write out point attribute values.   << 
886         if(pointAttValues)                     << 
887         {                                      << 
888           for(iAttVal = pointAttValues->begin( << 
889               iAttVal != pointAttValues->end() << 
890             // Do not write out the Aux or Pos << 
891             // to the HepRep rule that each ob << 
892             // a given AttValue. Both of these << 
893             // actual position information of  << 
894             if(strcmp(iAttVal->GetName(), "Aux << 
895                strcmp(iAttVal->GetName(), "Aux << 
896                strcmp(iAttVal->GetName(), "Aux << 
897                strcmp(iAttVal->GetName(), "Pos << 
898                strcmp(iAttVal->GetName(), "Pos << 
899                strcmp(iAttVal->GetName(), "Pos << 
900               hepRepXMLWriter->addAttValue(iAt << 
901                                            iAt << 
902         }                                      << 
903       }                                        << 
904                                                << 
905       // Clean up point attributes.            << 
906       delete pointAttDefs;                     << 
907       delete pointAttValues;                   << 
908       delete rawPointAttValues;                << 
909                                                << 
910       // Each trajectory point is made of a si << 
911       G4Point3D vertex = aTrajectoryPoint->Get << 
912                                                << 
913       // Loop over auxiliary points associated << 
914       const std::vector<G4ThreeVector>* auxili << 
915         aTrajectoryPoint->GetAuxiliaryPoints() << 
916       if(0 != auxiliaries)                     << 
917       {                                        << 
918         for(size_t iAux = 0; iAux < auxiliarie << 
919         {                                      << 
920           const G4ThreeVector auxPos((*auxilia << 
921           hepRepXMLWriter->addPrimitive();     << 
922           hepRepXMLWriter->addPoint(auxPos.x() << 
923         }                                      << 
924       }                                        << 
925     }                                          << 
926   }                                            << 
927 }                                              << 
928                                                << 
929 void G4HepRepFileSceneHandler::AddCompound(con << 
930 {                                              << 
931 #ifdef G4HEPREPFILEDEBUG                       << 
932   G4cout << "G4HepRepFileSceneHandler::AddComp << 
933 #endif                                         << 
934                                                << 
935   // Pointers to hold hit attribute values and << 
936   std::vector<G4AttValue>* rawHitAttValues = h << 
937   hitAttValues                             = n << 
938   hitAttDefs                               = n << 
939                                                << 
940   // Iterators to use with attribute values an << 
941   std::vector<G4AttValue>::iterator iAttVal;   << 
942   std::map<G4String, G4AttDef>::const_iterator << 
943                                                << 
944   // Get hit attributes and definitions in sta << 
945   // (uniform units, 3Vectors decomposed).     << 
946   if(rawHitAttValues)                          << 
947   {                                            << 
948     G4bool error = G4AttCheck(rawHitAttValues, << 
949                      .Standard(hitAttValues, h << 
950     if(error)                                  << 
951     {                                          << 
952       G4cout << "G4HepRepFileSceneHandler::Add << 
953                 "\nERROR found during conversi << 
954              << G4endl;                        << 
955     }                                          << 
956 #ifdef G4HEPREPFILEDEBUG                       << 
957     G4cout << "G4HepRepFileSceneHandler::AddCo << 
958               "attributes:\n"                  << 
959            << G4AttCheck(hitAttValues, hitAttD << 
960 #endif                                         << 
961     delete rawHitAttValues;                    << 
962   }                                            << 
963                                                << 
964   // Open the HepRep output file if it is not  << 
965   CheckFileOpen();                             << 
966                                                << 
967   // Add the Event Data Type if it hasn't alre << 
968   if(strcmp("Event Data", hepRepXMLWriter->pre << 
969   {                                            << 
970     hepRepXMLWriter->addType("Event Data", 0); << 
971     hepRepXMLWriter->addInstance();            << 
972   }                                            << 
973                                                << 
974   // Find out the current HitType.             << 
975   G4String hitType = "Hits";                   << 
976   if(hitAttValues)                             << 
977   {                                            << 
978     G4bool found = false;                      << 
979     for(iAttVal = hitAttValues->begin();       << 
980         iAttVal != hitAttValues->end() && !fou << 
981     {                                          << 
982       if(strcmp(iAttVal->GetName(), "HitType") << 
983       {                                        << 
984         hitType = iAttVal->GetValue();         << 
985         found   = true;                        << 
986       }                                        << 
987     }                                          << 
988   }                                            << 
989                                                << 
990   // Add the Hits Type.                        << 
991   G4String previousName = hepRepXMLWriter->pre << 
992   hepRepXMLWriter->addType(hitType, 1);        << 
993                                                << 
994   // If this is the first hit of this event,   << 
995   // specify attribute values common to all hi << 
996   if(strcmp(hitType, previousName) != 0)       << 
997   {                                            << 
998     hepRepXMLWriter->addAttValue("Layer", 130) << 
999                                                << 
1000     // Take all Hit attDefs from first hit.   << 
1001     // Would rather be able to get these attD << 
1002     // from any particular hit, but don't kno << 
1003     // attribute definitions.                 << 
1004     if(hitAttValues && hitAttDefs)            << 
1005     {                                         << 
1006       for(iAttVal = hitAttValues->begin(); iA << 
1007           ++iAttVal)                          << 
1008       {                                       << 
1009         iAttDef = hitAttDefs->find(iAttVal->G << 
1010         if(iAttDef != hitAttDefs->end())      << 
1011         {                                     << 
1012           // Protect against incorrect use of << 
1013           // than the standard ones will be c << 
1014           // category.                        << 
1015           G4String category = iAttDef->second << 
1016           if(strcmp(category, "Draw") != 0 && << 
1017              strcmp(category, "Physics") != 0 << 
1018              strcmp(category, "Association")  << 
1019              strcmp(category, "PickAction") ! << 
1020             category = "Physics";             << 
1021           hepRepXMLWriter->addAttDef(iAttVal- << 
1022                                      iAttDef- << 
1023                                      iAttDef- << 
1024         }                                     << 
1025       }                                       << 
1026     }                                         << 
1027   }  // end of special treatment for when thi << 
1028                                               << 
1029   // Now that we have written out all of the  << 
1030   // hit's particulars, call base class to de << 
1031   drawingHit  = true;                         << 
1032   doneInitHit = false;                        << 
1033   G4VSceneHandler::AddCompound(hit);  // Invo << 
1034   drawingHit = false;                         << 
1035 }                                             << 
1036                                               << 
1037 void G4HepRepFileSceneHandler::InitTrajectory << 
1038 {                                             << 
1039   if(!doneInitTraj)                           << 
1040   {                                           << 
1041     // For every trajectory, add an instance  << 
1042     hepRepXMLWriter->addInstance();           << 
1043                                               << 
1044     // Write out the trajectory's attribute v << 
1045     if(trajAttValues)                         << 
1046     {                                         << 
1047       std::vector<G4AttValue>::iterator iAttV << 
1048       for(iAttVal = trajAttValues->begin(); i << 
1049           ++iAttVal)                          << 
1050         hepRepXMLWriter->addAttValue(iAttVal- << 
1051       delete trajAttValues;                   << 
1052     }                                         << 
1053                                               << 
1054     // Clean up trajectory attributes.        << 
1055     if(trajAttDefs)                           << 
1056       delete trajAttDefs;                     << 
1057                                               << 
1058     doneInitTraj = true;                      << 
1059   }                                           << 
1060 }                                             << 
1061                                               << 
1062 void G4HepRepFileSceneHandler::InitHit()      << 
1063 {                                             << 
1064   if(!doneInitHit)                            << 
1065   {                                           << 
1066     // For every hit, add an instance of Type << 
1067     hepRepXMLWriter->addInstance();           << 
1068                                               << 
1069     // Write out the hit's attribute values.  << 
1070     if(hitAttValues)                          << 
1071     {                                         << 
1072       std::vector<G4AttValue>::iterator iAttV << 
1073       for(iAttVal = hitAttValues->begin(); iA << 
1074           ++iAttVal)                          << 
1075         hepRepXMLWriter->addAttValue(iAttVal- << 
1076       delete hitAttValues;                    << 
1077     }                                         << 
1078                                               << 
1079     // Clean up hit attributes.               << 
1080     if(hitAttDefs)                            << 
1081       delete hitAttDefs;                      << 
1082                                               << 
1083     doneInitHit = true;                       << 
1084   }                                           << 
1085 }                                             << 
1086                                               << 
1087 void G4HepRepFileSceneHandler::AddPrimitive(c << 
1088 {                                             << 
1089 #ifdef G4HEPREPFILEDEBUG                      << 
1090   G4cout << "G4HepRepFileSceneHandler::AddPri << 
1091             "polyline) called:"               << 
1092             "\n  polyline: "                  << 
1093          << polyline << G4endl;               << 
1094   PrintThings();                              << 
1095 #endif                                        << 
1096                                               << 
1097   G4HepRepMessenger* messenger = G4HepRepMess << 
1098                                               << 
1099   if(fpVisAttribs && (fpVisAttribs->IsVisible << 
1100      messenger->getCullInvisibles())          << 
1101     return;                                   << 
1102                                               << 
1103   if(inPrimitives2D)                          << 
1104   {                                           << 
1105     if(!warnedAbout2DMarkers)                 << 
1106     {                                         << 
1107       G4cout << "HepRepFile does not currentl << 
1108       warnedAbout2DMarkers = true;            << 
1109     }                                         << 
1110     return;                                   << 
1111   }                                           << 
1112                                               << 
1113   if(drawingTraj)                             << 
1114     InitTrajectory();                         << 
1115                                               << 
1116   if(drawingHit)                              << 
1117     InitHit();                                << 
1118                                               << 
1119   haveVisible = true;                         << 
1120   AddHepRepInstance("Line", polyline);        << 
1121                                               << 
1122   hepRepXMLWriter->addPrimitive();            << 
1123                                               << 
1124   for(size_t i = 0; i < polyline.size(); i++) << 
1125   {                                           << 
1126     G4Point3D vertex = (fObjectTransformation << 
1127     hepRepXMLWriter->addPoint(vertex.x(), ver << 
1128   }                                           << 
1129 }                                             << 
1130                                               << 
1131 void G4HepRepFileSceneHandler::AddPrimitive(c << 
1132 {                                             << 
1133 #ifdef G4HEPREPFILEDEBUG                      << 
1134   G4cout                                      << 
1135     << "G4HepRepFileSceneHandler::AddPrimitiv << 
1136     << G4endl;                                << 
1137   PrintThings();                              << 
1138 #endif                                        << 
1139                                               << 
1140   G4HepRepMessenger* messenger = G4HepRepMess << 
1141                                               << 
1142   if(fpVisAttribs && (fpVisAttribs->IsVisible << 
1143      messenger->getCullInvisibles())          << 
1144     return;                                   << 
1145                                               << 
1146   if(inPrimitives2D)                          << 
1147   {                                           << 
1148     if(!warnedAbout2DMarkers)                 << 
1149     {                                         << 
1150       G4cout << "HepRepFile does not currentl << 
1151       warnedAbout2DMarkers = true;            << 
1152     }                                         << 
1153     return;                                   << 
1154   }                                           << 
1155                                               << 
1156   MarkerSizeType sizeType;                    << 
1157   G4double size = GetMarkerSize(line, sizeTyp << 
1158   if(sizeType == world)                       << 
1159     size = 4.;                                << 
1160                                               << 
1161   if(drawingTraj)                             << 
1162     return;                                   << 
1163                                               << 
1164   if(drawingHit)                              << 
1165     InitHit();                                << 
1166                                               << 
1167   haveVisible = true;                         << 
1168   AddHepRepInstance("Point", line);           << 
1169                                               << 
1170   hepRepXMLWriter->addAttValue("MarkName", "D << 
1171   hepRepXMLWriter->addAttValue("MarkSize", (G << 
1172                                               << 
1173   hepRepXMLWriter->addPrimitive();            << 
1174                                               << 
1175   for(size_t i = 0; i < line.size(); i++)     << 
1176   {                                           << 
1177     G4Point3D vertex = (fObjectTransformation << 
1178     hepRepXMLWriter->addPoint(vertex.x(), ver << 
1179   }                                           << 
1180 }                                             << 
1181                                               << 
1182 void G4HepRepFileSceneHandler::AddPrimitive(c << 
1183 {                                             << 
1184 #ifdef G4HEPREPFILEDEBUG                      << 
1185   G4cout << "G4HepRepFileSceneHandler::AddPri << 
1186             "\n  text: "                      << 
1187          << text.GetText() << G4endl;         << 
1188   PrintThings();                              << 
1189 #endif                                        << 
1190                                               << 
1191   if(!inPrimitives2D)                         << 
1192   {                                           << 
1193     if(!warnedAbout3DText)                    << 
1194     {                                         << 
1195       G4cout << "HepRepFile does not currentl << 
1196       G4cout                                  << 
1197         << "HepRep browsers can directly disp << 
1198         << G4endl;                            << 
1199       G4cout << "See Application Developers G << 
1200                 "to viewable objects."        << 
1201              << G4endl;                       << 
1202       warnedAbout3DText = true;               << 
1203     }                                         << 
1204     return;                                   << 
1205   }                                           << 
1206                                               << 
1207   MarkerSizeType sizeType;                    << 
1208   G4double size = GetMarkerSize(text, sizeTyp << 
1209   if(sizeType == world)                       << 
1210     size = 12.;                               << 
1211                                               << 
1212   haveVisible = true;                         << 
1213   AddHepRepInstance("Text", text);            << 
1214                                               << 
1215   hepRepXMLWriter->addAttValue("VAlign", "Top << 
1216   hepRepXMLWriter->addAttValue("HAlign", "Lef << 
1217   hepRepXMLWriter->addAttValue("FontName", "A << 
1218   hepRepXMLWriter->addAttValue("FontStyle", " << 
1219   hepRepXMLWriter->addAttValue("FontSize", (G << 
1220   hepRepXMLWriter->addAttValue("FontHasBanner << 
1221   hepRepXMLWriter->addAttValue("FontBannerCol << 
1222                                               << 
1223   const G4Colour& colour = GetTextColour(text << 
1224   float redness          = colour.GetRed();   << 
1225   float greenness        = colour.GetGreen(); << 
1226   float blueness         = colour.GetBlue();  << 
1227                                               << 
1228   // Avoiding drawing anything black on black << 
1229   if(redness == 0. && greenness == 0. && blue << 
1230   {                                           << 
1231     redness   = 1.;                           << 
1232     greenness = 1.;                           << 
1233     blueness  = 1.;                           << 
1234   }                                           << 
1235   hepRepXMLWriter->addAttValue("FontColor", r << 
1236                                               << 
1237   hepRepXMLWriter->addPrimitive();            << 
1238                                               << 
1239   hepRepXMLWriter->addAttValue("Text", text.G << 
1240   hepRepXMLWriter->addAttValue("VPos", .99 -  << 
1241   hepRepXMLWriter->addAttValue("HPos", text.G << 
1242 }                                             << 
1243                                               << 
1244 void G4HepRepFileSceneHandler::AddPrimitive(c << 
1245 {                                             << 
1246 #ifdef G4HEPREPFILEDEBUG                      << 
1247   G4cout                                      << 
1248     << "G4HepRepFileSceneHandler::AddPrimitiv << 
1249        "\n  radius: "                         << 
1250     << circle.GetWorldRadius() << G4endl;     << 
1251   PrintThings();                              << 
1252 #endif                                        << 
1253                                               << 
1254   G4HepRepMessenger* messenger = G4HepRepMess << 
1255                                               << 
1256   if(fpVisAttribs && (fpVisAttribs->IsVisible << 
1257      messenger->getCullInvisibles())          << 
1258     return;                                   << 
1259                                               << 
1260   if(inPrimitives2D)                          << 
1261   {                                           << 
1262     if(!warnedAbout2DMarkers)                 << 
1263     {                                         << 
1264       G4cout << "HepRepFile does not currentl << 
1265       warnedAbout2DMarkers = true;            << 
1266     }                                         << 
1267     return;                                   << 
1268   }                                           << 
1269                                               << 
1270   MarkerSizeType sizeType;                    << 
1271   G4double size = GetMarkerSize(circle, sizeT << 
1272   if(sizeType == world)                       << 
1273     size = 4.;                                << 
1274                                               << 
1275   if(drawingTraj)                             << 
1276     return;                                   << 
1277                                               << 
1278   if(drawingHit)                              << 
1279     InitHit();                                << 
1280                                               << 
1281   haveVisible = true;                         << 
1282   AddHepRepInstance("Point", circle);         << 
1283                                               << 
1284   hepRepXMLWriter->addAttValue("MarkName", "D << 
1285   hepRepXMLWriter->addAttValue("MarkSize", (G << 
1286                                               << 
1287   hepRepXMLWriter->addPrimitive();            << 
1288                                               << 
1289   G4Point3D center = (fObjectTransformation)  << 
1290   hepRepXMLWriter->addPoint(center.x(), cente << 
1291 }                                             << 
1292                                               << 
1293 void G4HepRepFileSceneHandler::AddPrimitive(c << 
1294 {                                             << 
1295 #ifdef G4HEPREPFILEDEBUG                      << 
1296   G4cout                                      << 
1297     << "G4HepRepFileSceneHandler::AddPrimitiv << 
1298        "\n  side: "                           << 
1299     << square.GetWorldRadius() << G4endl;     << 
1300   PrintThings();                              << 
1301 #endif                                        << 
1302                                               << 
1303   G4HepRepMessenger* messenger = G4HepRepMess << 
1304                                               << 
1305   if(fpVisAttribs && (fpVisAttribs->IsVisible << 
1306      messenger->getCullInvisibles())          << 
1307     return;                                   << 
1308                                               << 
1309   if(inPrimitives2D)                          << 
1310   {                                           << 
1311     if(!warnedAbout2DMarkers)                 << 
1312     {                                         << 
1313       G4cout << "HepRepFile does not currentl << 
1314       warnedAbout2DMarkers = true;            << 
1315     }                                         << 
1316     return;                                   << 
1317   }                                           << 
1318                                               << 
1319   MarkerSizeType sizeType;                    << 
1320   G4double size = GetMarkerSize(square, sizeT << 
1321   if(sizeType == world)                       << 
1322     size = 4.;                                << 
1323                                               << 
1324   if(drawingTraj)                             << 
1325     return;                                   << 
1326                                               << 
1327   if(drawingHit)                              << 
1328     InitHit();                                << 
1329                                               << 
1330   haveVisible = true;                         << 
1331   AddHepRepInstance("Point", square);         << 
1332                                               << 
1333   hepRepXMLWriter->addAttValue("MarkName", "S << 
1334   hepRepXMLWriter->addAttValue("MarkSize", (G << 
1335                                               << 
1336   hepRepXMLWriter->addPrimitive();            << 
1337                                               << 
1338   G4Point3D center = (fObjectTransformation)  << 
1339   hepRepXMLWriter->addPoint(center.x(), cente << 
1340 }                                             << 
1341                                               << 
1342 void G4HepRepFileSceneHandler::AddPrimitive(c << 
1343 {                                             << 
1344 #ifdef G4HEPREPFILEDEBUG                      << 
1345   G4cout << "G4HepRepFileSceneHandler::AddPri << 
1346             "polyhedron) called."             << 
1347          << G4endl;                           << 
1348   PrintThings();                              << 
1349 #endif                                        << 
1350                                               << 
1351   G4HepRepMessenger* messenger = G4HepRepMess << 
1352                                               << 
1353   if(fpVisAttribs && (fpVisAttribs->IsVisible << 
1354      messenger->getCullInvisibles())          << 
1355     return;                                   << 
1356                                               << 
1357   if(polyhedron.GetNoFacets() == 0)           << 
1358     return;                                   << 
1359                                               << 
1360   if(drawingTraj)                             << 
1361     return;                                   << 
1362                                               << 
1363   if(drawingHit)                              << 
1364     InitHit();                                << 
1365                                               << 
1366   haveVisible = true;                         << 
1367   AddHepRepInstance("Polygon", polyhedron);   << 
1368                                               << 
1369   G4Normal3D surfaceNormal;                   << 
1370   G4Point3D vertex;                           << 
1371                                               << 
1372   G4bool notLastFace;                         << 
1373   do                                          << 
1374   {                                           << 
1375     hepRepXMLWriter->addPrimitive();          << 
1376     notLastFace = polyhedron.GetNextNormal(su << 
1377                                               << 
1378     G4int edgeFlag = 1;                       << 
1379     G4bool notLastEdge;                       << 
1380     do                                        << 
1381     {                                         << 
1382       notLastEdge = polyhedron.GetNextVertex( << 
1383       vertex      = (fObjectTransformation) * << 
1384       hepRepXMLWriter->addPoint(vertex.x(), v << 
1385     } while(notLastEdge);                     << 
1386   } while(notLastFace);                       << 
1387 }                                             << 
1388                                               << 
1389 G4HepRepFileXMLWriter* G4HepRepFileSceneHandl << 
1390 {                                             << 
1391   return hepRepXMLWriter;                     << 
1392 }                                             << 
1393                                                  1289 
1394 void G4HepRepFileSceneHandler::AddHepRepInsta    1290 void G4HepRepFileSceneHandler::AddHepRepInstance(const char* primName,
1395                                               << 1291                          const G4Visible visible) {
1396 {                                             << 
1397 #ifdef G4HEPREPFILEDEBUG                         1292 #ifdef G4HEPREPFILEDEBUG
1398   G4cout << "G4HepRepFileSceneHandler::AddHep << 1293   G4cout <<
1399 #endif                                        << 1294     "G4HepRepFileSceneHandler::AddHepRepInstance called."
1400                                               << 1295   << G4endl;
1401   // Open the HepRep output file if it is not << 1296 #endif
1402   CheckFileOpen();                            << 1297   
1403                                               << 1298   // Open the HepRep output file if it is not already open.
1404   G4VPhysicalVolume* pCurrentPV = 0;          << 1299   CheckFileOpen();
1405   G4LogicalVolume* pCurrentLV   = 0;          << 1300   
1406   G4int currentDepth            = 0;          << 1301   G4VPhysicalVolume* pCurrentPV = 0;
1407   G4PhysicalVolumeModel* pPVModel =           << 1302   G4LogicalVolume* pCurrentLV = 0;
1408     dynamic_cast<G4PhysicalVolumeModel*>(fpMo << 1303   G4int currentDepth = 0;
1409   if(pPVModel)                                << 1304   G4PhysicalVolumeModel* pPVModel = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
1410   {                                           << 1305   if (pPVModel) {
1411     pCurrentPV   = pPVModel->GetCurrentPV();  << 1306     pCurrentPV = pPVModel->GetCurrentPV();
1412     pCurrentLV   = pPVModel->GetCurrentLV();  << 1307     pCurrentLV = pPVModel->GetCurrentLV();
1413     currentDepth = pPVModel->GetCurrentDepth( << 1308     currentDepth = pPVModel->GetCurrentDepth();
1414   }                                           << 1309   }
1415                                               << 1310   
1416 #ifdef G4HEPREPFILEDEBUG                      << 1311 #ifdef G4HEPREPFILEDEBUG
1417   G4cout << "pCurrentPV:" << pCurrentPV       << 1312   G4cout <<
1418          << ", readyForTransients:" << fReady << 1313     "pCurrentPV:" << pCurrentPV << ", readyForTransients:" << fReadyForTransients
1419 #endif                                        << 1314     << G4endl;
1420                                               << 1315 #endif
1421   if(drawingTraj || drawingHit)               << 1316   
1422   {                                           << 1317   if (drawingTraj || drawingHit) {
1423     // In this case, HepRep type, layer and i << 1318     // In this case, HepRep type, layer and instance were already created
1424     // in the AddCompound method.             << 1319     // in the AddCompound method.
1425   }                                           << 1320   }
1426   else if(fReadyForTransients)                << 1321   else if (fReadyForTransients) {
1427   {                                           << 1322     if (strcmp("Event Data",hepRepXMLWriter->prevTypeName[0])!=0) {
1428     if(strcmp("Event Data", hepRepXMLWriter-> << 1323       hepRepXMLWriter->addType("Event Data",0);
1429     {                                         << 1324       hepRepXMLWriter->addInstance();
1430       hepRepXMLWriter->addType("Event Data",  << 1325     }
1431       hepRepXMLWriter->addInstance();         << 1326     
1432     }                                         << 1327     // Applications have the option of either calling AddSolid(G4VTrajectory&) and
1433                                               << 1328     // AddSolid(G4VHits&), or of just decomposing these into simpler primitives.
1434     // Applications have the option of either << 1329     // In the former case, drawing will be handled above and will include setting of
1435     // and AddSolid(G4VHits&), or of just dec << 1330     // physics attributes.
1436     // primitives. In the former case, drawin << 1331     // In the latter case, which is an older style of working, we end up drawing the
1437     // include setting of physics attributes. << 1332     // trajectories and hits here, where we have no access to physics attributes. 
1438     // older style of working, we end up draw << 1333     // We receive primitives here.  We can figure out that these are transients, but we
1439     // where we have no access to physics att << 1334     // have to guess exactly what these transients represent.
1440     // here.  We can figure out that these ar << 1335     // We assume the primitives are being used as in G4VTrajectory, hence we assume:
1441     // exactly what these transients represen << 1336     // Lines are Trajectories
1442     // being used as in G4VTrajectory, hence  << 1337     // Squares that come after we've seen trajectories are Auxiliary Points
1443     // Squares that come after we've seen tra << 1338     // Circles that come after we've seen trajectories are Step Points
1444     // Circles that come after we've seen tra << 1339     // Other primitives are Hits
1445     // Other primitives are Hits              << 1340     
1446                                               << 1341     int layer;
1447     int layer;                                << 1342     
1448                                               << 1343     if (strcmp("Text",primName)==0) {
1449     if(strcmp("Text", primName) == 0)         << 1344       hepRepXMLWriter->addType("EventID",1);
1450     {                                         << 1345     } else {
1451       hepRepXMLWriter->addType("EventID", 1); << 1346       if (strcmp("Line",primName)==0) {
1452     }                                         << 1347         hepRepXMLWriter->addType("TransientPolylines",1);
1453     else                                      << 1348         layer = 100;
1454     {                                         << 1349       } else {
1455       if(strcmp("Line", primName) == 0)       << 1350         if (strcmp(hepRepXMLWriter->prevTypeName[1],"TransientPolylines")==0 &&
1456       {                                       << 1351           strcmp("Square",primName)==0)
1457         hepRepXMLWriter->addType("TransientPo << 1352         {
1458         layer = 100;                          << 1353           hepRepXMLWriter->addType("AuxiliaryPoints",2);
1459       }                                       << 1354           layer = 110;
1460       else                                    << 1355         } else {
1461       {                                       << 1356           if (strcmp(hepRepXMLWriter->prevTypeName[1],"TransientPolylines")==0 &&
1462         if(strcmp(hepRepXMLWriter->prevTypeNa << 1357             strcmp("Circle",primName)==0)
1463              0 &&                             << 1358           {
1464            strcmp("Square", primName) == 0)   << 1359             hepRepXMLWriter->addType("StepPoints",2);
1465         {                                     << 1360             layer = 120;
1466           hepRepXMLWriter->addType("Auxiliary << 1361           } else {
1467           layer = 110;                        << 1362             hepRepXMLWriter->addType("Hits",1);
1468         }                                     << 1363             layer = 130;
1469         else                                  << 1364           }
1470         {                                     << 1365         }
1471           if(strcmp(hepRepXMLWriter->prevType << 1366       }
1472                0 &&                           << 1367       hepRepXMLWriter->addAttValue("Layer",layer);
1473              strcmp("Circle", primName) == 0) << 1368     }
1474           {                                   << 1369     
1475             hepRepXMLWriter->addType("StepPoi << 1370     hepRepXMLWriter->addInstance();
1476             layer = 120;                      << 1371     
1477           }                                   << 1372     // Handle Type declaration for Axes, Ruler, etc.
1478           else                                << 1373   } else if (pCurrentPV==0) {
1479           {                                   << 1374     if (strcmp("AxesEtc",hepRepXMLWriter->prevTypeName[0])!=0) {
1480             hepRepXMLWriter->addType("Hits",  << 1375       hepRepXMLWriter->addType("AxesEtc",0);
1481             layer = 130;                      << 1376       hepRepXMLWriter->addInstance();
1482           }                                   << 1377     }
1483         }                                     << 1378     
1484       }                                       << 1379     int layer;
1485       hepRepXMLWriter->addAttValue("Layer", l << 1380     
1486     }                                         << 1381     if (strcmp("Text",primName)==0) {
1487                                               << 1382       hepRepXMLWriter->addType("Text",1);
1488     hepRepXMLWriter->addInstance();           << 1383     } else {
1489                                               << 1384       if (strcmp("Line",primName)==0) {
1490     // Handle Type declaration for Axes, Rule << 1385         hepRepXMLWriter->addType("Polylines",1);
1491   }                                           << 1386         layer = 100;
1492   else if(pCurrentPV == 0)                    << 1387       } else {
1493   {                                           << 1388         hepRepXMLWriter->addType("Points",1);
1494     if(strcmp("AxesEtc", hepRepXMLWriter->pre << 1389         layer = 130;
1495     {                                         << 1390       }
1496       hepRepXMLWriter->addType("AxesEtc", 0); << 1391       hepRepXMLWriter->addAttValue("Layer",layer);
1497       hepRepXMLWriter->addInstance();         << 1392     }
1498     }                                         << 1393     
1499                                               << 1394     hepRepXMLWriter->addInstance();
1500     int layer;                                << 1395     
1501                                               << 1396     // Handle Type declaration for Detector Geometry,
1502     if(strcmp("Text", primName) == 0)         << 1397     // replacing G4's top geometry level name "worldPhysical" with the
1503     {                                         << 1398     // name "Detector Geometry".
1504       hepRepXMLWriter->addType("Text", 1);    << 1399   } else {
1505     }                                         << 1400     //G4cout << "CurrentDepth" << currentDepth << G4endl;
1506     else                                      << 1401     //G4cout << "currentName" << pCurrentPV->GetName() << G4endl;
1507     {                                         << 1402     if (strcmp("Detector Geometry",hepRepXMLWriter->prevTypeName[0])!=0) {
1508       if(strcmp("Line", primName) == 0)       << 1403       //G4cout << "Adding Det Geom type" << G4endl;
1509       {                                       << 1404       hepRepXMLWriter->addType("Detector Geometry",0);
1510         hepRepXMLWriter->addType("Polylines", << 1405       hepRepXMLWriter->addInstance();
1511         layer = 100;                          << 1406     }
1512       }                                       << 1407     
1513       else                                    << 1408     // Re-insert any layers of the hierarchy that were removed by G4's culling process.
1514       {                                       << 1409     // Don't bother checking if same type name as last instance.
1515         hepRepXMLWriter->addType("Points", 1) << 1410     if(strcmp(hepRepXMLWriter->prevTypeName[currentDepth+1],pCurrentPV->GetName())!=0) {
1516         layer = 130;                          << 1411       //G4cout << "Looking for mother of:" << pCurrentLV->GetName() << G4endl;
1517       }                                       << 1412       typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID;
1518       hepRepXMLWriter->addAttValue("Layer", l << 1413       typedef std::vector<PVNodeID> PVPath;
1519     }                                         << 1414       const PVPath& drawnPVPath = pPVModel->GetDrawnPVPath();
1520                                               << 1415       PVPath::const_reverse_iterator ri = ++drawnPVPath.rbegin();
1521     hepRepXMLWriter->addInstance();           << 1416       G4int drawnMotherDepth;
1522                                               << 1417       if (ri != drawnPVPath.rend()) {
1523     // Handle Type declaration for Detector G << 1418         // This volume has a mother.
1524     // replacing G4's top geometry level name << 1419         drawnMotherDepth = ri->GetNonCulledDepth();
1525     // name "Detector Geometry".              << 1420         //G4cout << "drawnMotherDepth" << drawnMotherDepth << G4endl;
1526   }                                           << 1421       } else {
1527   else                                        << 1422         // This volume has no mother.  Must be a top level volume.
1528   {                                           << 1423         drawnMotherDepth = -1;
1529     // G4cout << "CurrentDepth" << currentDep << 1424         //G4cout << "Mother must be very top" << G4endl;
1530     // G4cout << "currentName" << pCurrentPV- << 1425       }
1531     if(strcmp("Detector Geometry", hepRepXMLW << 1426       
1532     {                                         << 1427       while (drawnMotherDepth < (currentDepth-1)) {
1533       // G4cout << "Adding Det Geom type" <<  << 1428         G4String culledParentName = "Culled parent of " + pCurrentPV->GetName();
1534       hepRepXMLWriter->addType("Detector Geom << 1429         //G4cout << "Inserting culled layer " << culledParentName << " at depth:" << drawnMotherDepth+2 << G4endl;
1535       hepRepXMLWriter->addInstance();         << 1430         hepRepXMLWriter->addType(culledParentName, drawnMotherDepth+2);
1536     }                                         << 1431         hepRepXMLWriter->addInstance();
1537                                               << 1432         drawnMotherDepth ++;
1538     // Re-insert any layers of the hierarchy  << 1433       }
1539     // process. Don't bother checking if same << 1434     }
1540     if(strcmp(hepRepXMLWriter->prevTypeName[c << 1435     
1541               pCurrentPV->GetName()) != 0)    << 1436     // Add the HepRepType for the current volume.
1542     {                                         << 1437     hepRepXMLWriter->addType(pCurrentPV->GetName(),currentDepth+1);
1543       // G4cout << "Looking for mother of:" < << 1438     hepRepXMLWriter->addInstance();
1544       typedef G4PhysicalVolumeModel::G4Physic << 1439     
1545       typedef std::vector<PVNodeID> PVPath;   << 1440     G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
1546       const PVPath& drawnPVPath         = pPV << 1441     
1547       PVPath::const_reverse_iterator ri = ++d << 1442     if (fpVisAttribs && (fpVisAttribs->IsVisible()==0) && messenger->getCullInvisibles())
1548       G4int drawnMotherDepth;                 << 1443       return;
1549       if(ri != drawnPVPath.rend())            << 1444     
1550       {                                       << 1445     // Additional attributes.
1551         // This volume has a mother.          << 1446     hepRepXMLWriter->addAttValue("Layer",hepRepXMLWriter->typeDepth);
1552         drawnMotherDepth = ri->GetNonCulledDe << 1447     hepRepXMLWriter->addAttValue("LVol", pCurrentLV->GetName());
1553         // G4cout << "drawnMotherDepth" << dr << 1448     G4Region* region = pCurrentLV->GetRegion();
1554       }                                       << 1449     G4String regionName = region? region->GetName(): G4String("No region");
1555       else                                    << 1450     hepRepXMLWriter->addAttValue("Region", regionName);
1556       {                                       << 1451     hepRepXMLWriter->addAttValue("RootRegion", pCurrentLV->IsRootRegion());
1557         // This volume has no mother.  Must b << 1452     hepRepXMLWriter->addAttValue("Solid", pCurrentLV->GetSolid()->GetName());
1558         drawnMotherDepth = -1;                << 1453     hepRepXMLWriter->addAttValue("EType", pCurrentLV->GetSolid()->GetEntityType());
1559         // G4cout << "Mother must be very top << 1454     G4Material * material = pPVModel->GetCurrentMaterial();
1560       }                                       << 1455     G4String matName = material? material->GetName(): G4String("No material");
1561                                               << 1456     hepRepXMLWriter->addAttValue("Material", matName);
1562       while(drawnMotherDepth < (currentDepth  << 1457     G4double matDensity = material? material->GetDensity(): 0.;
1563       {                                       << 1458     hepRepXMLWriter->addAttValue("Density", matDensity*m3/kg);
1564         G4String culledParentName = "Culled p << 1459     G4State matState = material? material->GetState(): kStateUndefined;
1565         // G4cout << "Inserting culled layer  << 1460     hepRepXMLWriter->addAttValue("State", matState);
1566         // depth:" << drawnMotherDepth+2 << G << 1461     G4double matRadlen = material? material->GetRadlen(): 0.;
1567         hepRepXMLWriter->addType(culledParent << 1462     hepRepXMLWriter->addAttValue("Radlen", matRadlen/m);
1568         hepRepXMLWriter->addInstance();       << 1463   }
1569         drawnMotherDepth++;                   << 1464   
1570       }                                       << 1465   hepRepXMLWriter->addAttValue("DrawAs",primName);
1571     }                                         << 1466   
1572                                               << 1467   // Handle color and visibility attributes.
1573     // Add the HepRepType for the current vol << 1468   float redness;
1574     hepRepXMLWriter->addType(pCurrentPV->GetN << 1469   float greenness;
1575     hepRepXMLWriter->addInstance();           << 1470   float blueness;
1576                                               << 1471   G4bool isVisible; 
1577     G4HepRepMessenger* messenger = G4HepRepMe << 1472   
1578                                               << 1473   if (fpVisAttribs || haveVisible) {
1579     if(fpVisAttribs && (fpVisAttribs->IsVisib << 1474     G4Colour colour;
1580        messenger->getCullInvisibles())        << 1475     
1581       return;                                 << 1476     if (fpVisAttribs) {
1582                                               << 1477       colour = fpVisAttribs->GetColour();
1583     // Additional attributes.                 << 1478       isVisible = fpVisAttribs->IsVisible();
1584     hepRepXMLWriter->addAttValue("Layer", hep << 1479     } else {
1585     hepRepXMLWriter->addAttValue("LVol", pCur << 1480       colour = GetColour(visible);
1586     G4Region* region    = pCurrentLV->GetRegi << 1481       isVisible = fpViewer->
1587     G4String regionName = region ? region->Ge << 1482         GetApplicableVisAttributes(visible.GetVisAttributes())->IsVisible();
1588     hepRepXMLWriter->addAttValue("Region", re << 1483     }
1589     hepRepXMLWriter->addAttValue("RootRegion" << 1484     
1590     hepRepXMLWriter->addAttValue("Solid", pCu << 1485     redness = colour.GetRed();
1591     hepRepXMLWriter->addAttValue("EType",     << 1486     greenness = colour.GetGreen();
1592                                  pCurrentLV-> << 1487     blueness = colour.GetBlue();
1593     G4Material* material = pPVModel->GetCurre << 1488     
1594     G4String matName = material ? material->G << 1489     // Avoiding drawing anything black on black.  
1595     hepRepXMLWriter->addAttValue("Material",  << 1490     if (redness==0. && greenness==0. && blueness==0.) {
1596     G4double matDensity = material ? material << 1491       redness = 1.;
1597     hepRepXMLWriter->addAttValue("Density", m << 1492       greenness = 1.;
1598     G4State matState = material ? material->G << 1493       blueness = 1.;
1599     hepRepXMLWriter->addAttValue("State", mat << 1494     }
1600     G4double matRadlen = material ? material- << 1495   } else {
1601     hepRepXMLWriter->addAttValue("Radlen", ma << 1496 #ifdef G4HEPREPFILEDEBUG
1602   }                                           << 1497     G4cout <<
1603                                               << 1498     "G4HepRepFileSceneHandler::AddHepRepInstance using default colour."
1604   hepRepXMLWriter->addAttValue("DrawAs", prim << 1499     << G4endl;
1605                                               << 1500 #endif
1606   // Handle color and visibility attributes.  << 1501     redness = 1.;
1607   float redness;                              << 1502     greenness = 1.;
1608   float greenness;                            << 1503     blueness = 1.;
1609   float blueness;                             << 1504     isVisible = true;
1610   G4bool isVisible;                           << 1505   }
1611                                               << 1506   
1612   if(fpVisAttribs || haveVisible)             << 1507   if (strcmp(primName,"Point")==0)
1613   {                                           << 1508     hepRepXMLWriter->addAttValue("MarkColor",redness,greenness,blueness);
1614     G4Colour colour;                          << 1509   else
1615                                               << 1510     hepRepXMLWriter->addAttValue("LineColor",redness,greenness,blueness);
1616     if(fpVisAttribs)                          << 1511   
1617     {                                         << 1512   hepRepXMLWriter->addAttValue("Visibility",isVisible);
1618       colour    = fpVisAttribs->GetColour();  << 1513 }
1619       isVisible = fpVisAttribs->IsVisible();  << 1514 
1620     }                                         << 1515 
1621     else                                      << 1516 void G4HepRepFileSceneHandler::CheckFileOpen() {
1622     {                                         << 1517 #ifdef G4HEPREPFILEDEBUG
1623       colour = visible.GetVisAttributes()->Ge << 1518   G4cout <<
1624       isVisible =                             << 1519     "G4HepRepFileSceneHandler::CheckFileOpen called."
1625         fpViewer->GetApplicableVisAttributes( << 1520   << G4endl;
1626           ->IsVisible();                      << 1521 #endif
1627     }                                         << 1522   
1628                                               << 1523   if (!hepRepXMLWriter->isOpen) {
1629     redness   = colour.GetRed();              << 1524     G4String newFileSpec;
1630     greenness = colour.GetGreen();            << 1525 
1631     blueness  = colour.GetBlue();             << 1526     G4HepRepMessenger* messenger = G4HepRepMessenger::GetInstance();
1632                                               << 1527     
1633     // Avoiding drawing anything black on bla << 1528     if (messenger->getOverwrite()) {
1634     if(redness == 0. && greenness == 0. && bl << 1529       newFileSpec = messenger->getFileDir()+messenger->getFileName()+".heprep";
1635     {                                         << 1530     } else {
1636       redness   = 1.;                         << 1531       newFileSpec = messenger->getFileDir()+messenger->getFileName()+G4UIcommand::ConvertToString(fileCounter)+".heprep";
1637       greenness = 1.;                         << 1532     }
1638       blueness  = 1.;                         << 1533     
1639     }                                         << 1534     G4cout << "HepRepFile writing to " << newFileSpec << G4endl;
1640   }                                           << 1535     
1641   else                                        << 1536     hepRepXMLWriter->open(newFileSpec);
1642   {                                           << 1537     
1643 #ifdef G4HEPREPFILEDEBUG                      << 1538     if (!messenger->getOverwrite())
1644     G4cout                                    << 1539       fileCounter++;
1645       << "G4HepRepFileSceneHandler::AddHepRep << 1540     
1646       << G4endl;                              << 1541     hepRepXMLWriter->addAttDef("Generator", "HepRep Data Generator", "Physics","");
1647 #endif                                        << 1542     G4String versionString = G4Version;
1648     redness   = 1.;                           << 1543     versionString = versionString.substr(1,versionString.size()-2);
1649     greenness = 1.;                           << 1544     versionString = " Geant4 version " + versionString + "   " + G4Date;
1650     blueness  = 1.;                           << 1545     hepRepXMLWriter->addAttValue("Generator", versionString);
1651     isVisible = true;                         << 1546     
1652   }                                           << 1547     hepRepXMLWriter->addAttDef("LVol", "Logical Volume", "Physics","");
1653                                               << 1548     hepRepXMLWriter->addAttDef("Region", "Cuts Region", "Physics","");
1654   if(strcmp(primName, "Point") == 0)          << 1549     hepRepXMLWriter->addAttDef("RootRegion", "Root Region", "Physics","");
1655     hepRepXMLWriter->addAttValue("MarkColor", << 1550     hepRepXMLWriter->addAttDef("Solid", "Solid Name", "Physics","");
1656   else                                        << 1551     hepRepXMLWriter->addAttDef("EType", "Entity Type", "Physics","");
1657     hepRepXMLWriter->addAttValue("LineColor", << 1552     hepRepXMLWriter->addAttDef("Material", "Material Name", "Physics","");
1658                                               << 1553     hepRepXMLWriter->addAttDef("Density", "Material Density", "Physics","kg/m3");
1659   hepRepXMLWriter->addAttValue("Visibility",  << 1554     hepRepXMLWriter->addAttDef("State", "Material State", "Physics","");
1660 }                                             << 1555     hepRepXMLWriter->addAttDef("Radlen", "Material Radiation Length", "Physics","m");
1661                                               << 1556   }
1662 void G4HepRepFileSceneHandler::CheckFileOpen( << 1557 }
1663 {                                             << 1558 
1664 #ifdef G4HEPREPFILEDEBUG                      << 1559 
1665   G4cout << "G4HepRepFileSceneHandler::CheckF << 1560 void G4HepRepFileSceneHandler::ClearTransientStore() {
1666 #endif                                        << 1561   G4VSceneHandler::ClearTransientStore();
1667                                               << 1562   // This is typically called after an update and before drawing hits
1668   if(!hepRepXMLWriter->isOpen)                << 1563   // of the next event.  To simulate the clearing of "transients"
1669   {                                           << 1564   // (hits, etc.) the detector is redrawn...
1670     G4String newFileSpec;                     << 1565   if (fpViewer) {
1671                                               << 1566     fpViewer -> SetView();
1672     G4HepRepMessenger* messenger = G4HepRepMe << 1567     fpViewer -> ClearView();
1673                                               << 1568     fpViewer -> DrawView();
1674     if(messenger->getOverwrite())             << 1569   }
1675     {                                         << 
1676       newFileSpec =                           << 
1677         messenger->getFileDir() + messenger-> << 
1678     }                                         << 
1679     else                                      << 
1680     {                                         << 
1681       newFileSpec = messenger->getFileDir() + << 
1682                     G4UIcommand::ConvertToStr << 
1683     }                                         << 
1684                                               << 
1685     G4cout << "HepRepFile writing to " << new << 
1686                                               << 
1687     hepRepXMLWriter->open(newFileSpec);       << 
1688                                               << 
1689     if(!messenger->getOverwrite())            << 
1690       fileCounter++;                          << 
1691                                               << 
1692     hepRepXMLWriter->addAttDef("Generator", " << 
1693                                "");           << 
1694     G4String versionString = G4Version;       << 
1695     versionString          = versionString.su << 
1696     versionString = " Geant4 version " + vers << 
1697     hepRepXMLWriter->addAttValue("Generator", << 
1698                                               << 
1699     hepRepXMLWriter->addAttDef("LVol", "Logic << 
1700     hepRepXMLWriter->addAttDef("Region", "Cut << 
1701     hepRepXMLWriter->addAttDef("RootRegion",  << 
1702     hepRepXMLWriter->addAttDef("Solid", "Soli << 
1703     hepRepXMLWriter->addAttDef("EType", "Enti << 
1704     hepRepXMLWriter->addAttDef("Material", "M << 
1705     hepRepXMLWriter->addAttDef("Density", "Ma << 
1706                                "kg/m3");      << 
1707     hepRepXMLWriter->addAttDef("State", "Mate << 
1708     hepRepXMLWriter->addAttDef("Radlen", "Mat << 
1709                                "m");          << 
1710   }                                           << 
1711 }                                             << 
1712                                               << 
1713 void G4HepRepFileSceneHandler::ClearTransient << 
1714 {                                             << 
1715   // This is typically called after an update << 
1716   // of the next event.  To simulate the clea << 
1717   // (hits, etc.) the detector is redrawn...  << 
1718   if(fpViewer)                                << 
1719   {                                           << 
1720     fpViewer->SetView();                      << 
1721     fpViewer->ClearView();                    << 
1722     fpViewer->DrawView();                     << 
1723   }                                           << 
1724 }                                                1570 }
1725                                                  1571