Index: trunk/geant4/visualization/OpenInventor/src/G4OpenInventorSceneHandler.cc
===================================================================
--- trunk/geant4/visualization/OpenInventor/src/G4OpenInventorSceneHandler.cc	(revision 529)
+++ trunk/geant4/visualization/OpenInventor/src/G4OpenInventorSceneHandler.cc	(revision 593)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4OpenInventorSceneHandler.cc,v 1.50 2006/11/05 20:48:57 allison Exp $
-// GEANT4 tag $Name: geant4-08-02-patch-01 $
+// $Id: G4OpenInventorSceneHandler.cc,v 1.53 2007/04/03 13:35:48 allison Exp $
+// GEANT4 tag $Name: geant4-09-00-ref-01 $
 //
 // 
@@ -96,10 +96,4 @@
 #include "G4Trap.hh"
 #include "G4Trd.hh"
-#include "G4PhysicalVolumeModel.hh"
-#include "G4TrajectoriesModel.hh"
-#include "G4VTrajectory.hh"
-#include "G4VTrajectoryPoint.hh"
-#include "G4HitsModel.hh"
-#include "G4VHit.hh"
 #include "G4ModelingParameters.hh"
 #include "G4VPhysicalVolume.hh"
@@ -189,58 +183,11 @@
 }
 
-void G4OpenInventorSceneHandler::LoadAtts
-(const G4Visible& visible,
- G4AttHolder* holder)
-{
-  // Load G4Atts from G4VisAttributes, if any...
-  const std::map<G4String,G4AttDef>* vaDefs =
-    visible.GetVisAttributes()->GetAttDefs();
-  if (vaDefs) {
-    holder->AddAtts(visible.GetVisAttributes()->CreateAttValues(), vaDefs);
-  }
-
-  G4PhysicalVolumeModel* pPVModel =
-    dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
-  if (pPVModel) {
-    // Load G4Atts from G4PhysicalVolumeModel...
-    const std::map<G4String,G4AttDef>* defs = pPVModel->GetAttDefs();
-    if (defs) {
-      holder->AddAtts(pPVModel->CreateCurrentAttValues(), defs);
-    }
-  }
-
-  G4TrajectoriesModel* trajModel = dynamic_cast<G4TrajectoriesModel*>(fpModel);
-  if (trajModel) {
-    // Load G4Atts from trajectory...
-    const G4VTrajectory* traj = trajModel->GetCurrentTrajectory();
-    const std::map<G4String,G4AttDef>* defs = traj->GetAttDefs();
-    if (defs) {
-      holder->AddAtts(traj->CreateAttValues(), defs);
-    }
-    G4int nPoints = traj->GetPointEntries();
-    for (G4int i = 0; i < nPoints; ++i) {
-      G4VTrajectoryPoint* trajPoint = traj->GetPoint(i);
-      const std::map<G4String,G4AttDef>* defs = trajPoint->GetAttDefs();
-      if (defs) {
-	holder->AddAtts(trajPoint->CreateAttValues(), defs);
-      }
-    }
-  }
-
-  G4HitsModel* hitsModel = dynamic_cast<G4HitsModel*>(fpModel);
-  if (hitsModel) {
-    // Load G4Atts from hit...
-    const G4VHit* hit = hitsModel->GetCurrentHit();
-    const std::map<G4String,G4AttDef>* defs = hit->GetAttDefs();
-    if (defs) {
-      holder->AddAtts(hit->CreateAttValues(), defs);
-    }
-  }
-}
-
 //
 // Method for handling G4Polyline objects (from tracking).
 //
-void G4OpenInventorSceneHandler::AddPrimitive (const G4Polyline& line) {
+void G4OpenInventorSceneHandler::AddPrimitive (const G4Polyline& line)
+{
+  AddProperties(line.GetVisAttributes());  // Transformation, colour, etc.
+
   G4int nPoints = line.size();
   SbVec3f* pCoords = new SbVec3f[nPoints];
@@ -252,17 +199,4 @@
   }
 
-  // Don't understand why I have to do this again (done in
-  // GeneratePrerequisites) - JA.
-  //
-  // Color
-  //
-  const G4Colour& c = GetColour (line);
-  SoMaterial* material = 
-    fStyleCache->getMaterial((float)c.GetRed(),
-                             (float)c.GetGreen(),
-                             (float)c.GetBlue(),
-                             (float)(1-c.GetAlpha()));
-  fCurrentSeparator->addChild(material);
-  
   //
   // Point Set
@@ -281,5 +215,5 @@
 
   // Loads G4Atts for picking...
-  LoadAtts(line, pLine);
+  if (fpViewer->GetViewParameters().IsPicking()) LoadAtts(line, pLine);
 
 #ifdef INVENTOR2_0
@@ -294,5 +228,8 @@
 }
 
-void G4OpenInventorSceneHandler::AddPrimitive (const G4Polymarker& polymarker) {
+void G4OpenInventorSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
+{
+  AddProperties(polymarker.GetVisAttributes()); // Transformation, colour, etc.
+
   G4int pointn = polymarker.size();
   if(pointn<=0) return;
@@ -305,14 +242,4 @@
   }
 
-  // Don't understand why I have to do this again (done in
-  // GeneratePrerequisites) - JA.
-  const G4Colour& c = GetColour (polymarker);
-  SoMaterial* material = 
-    fStyleCache->getMaterial((float)c.GetRed(),
-                             (float)c.GetGreen(),
-                             (float)c.GetBlue(),
-                             (float)(1-c.GetAlpha()));
-  fCurrentSeparator->addChild(material);
-  
   SoCoordinate3* coordinate3 = new SoCoordinate3;
   coordinate3->point.setValues(0,pointn,points);
@@ -336,5 +263,6 @@
 
   // Loads G4Atts for picking...
-  LoadAtts(polymarker, markerSet);
+  if (fpViewer->GetViewParameters().IsPicking())
+    LoadAtts(polymarker, markerSet);
 
   G4VMarker::FillStyle style = polymarker.GetFillStyle();
@@ -410,8 +338,11 @@
 // Method for handling G4Text objects
 //
-void G4OpenInventorSceneHandler::AddPrimitive (const G4Text& text) {
+void G4OpenInventorSceneHandler::AddPrimitive (const G4Text& text)
+{
+  AddProperties(text.GetVisAttributes());  // Transformation, colour, etc.
+
   //
   // Color.  Note: text colour is worked out differently.  This
-  // over-rides the colour added in GeneratePrerequisites...
+  // over-rides the colour added in AddProperties...
   //
   const G4Colour& c = GetTextColour (text);
@@ -476,18 +407,7 @@
 
 void G4OpenInventorSceneHandler::AddCircleSquare
-(G4OIMarker markerType, const G4VMarker& marker) {
-
-  // Don't understand why I have to do this again (done in
-  // GeneratePrerequisites) - JA.
-  //
-  // Color
-  //
-  const G4Colour& c = GetColour (marker);
-  SoMaterial* material = 
-    fStyleCache->getMaterial((float)c.GetRed(),
-                             (float)c.GetGreen(),
-                             (float)c.GetBlue(),
-                             (float)(1-c.GetAlpha()));
-  fCurrentSeparator->addChild(material);
+(G4OIMarker markerType, const G4VMarker& marker)
+{
+  AddProperties(marker.GetVisAttributes());  // Transformation, colour, etc.
 
   MarkerSizeType sizeType;
@@ -519,5 +439,5 @@
 
   // Loads G4Atts for picking...
-  LoadAtts(marker, markerSet);
+  if (fpViewer->GetViewParameters().IsPicking()) LoadAtts(marker, markerSet);
 
   G4VMarker::FillStyle style = marker.GetFillStyle();
@@ -574,11 +494,15 @@
 // Method for handling G4Polyhedron objects for drawing solids.
 //
-void G4OpenInventorSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
+void G4OpenInventorSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron)
+{
   if (polyhedron.GetNoFacets() == 0) return;
 
+  AddProperties(polyhedron.GetVisAttributes()); // Transformation, colour, etc.
+
   SoG4Polyhedron* soPolyhedron = new SoG4Polyhedron(polyhedron);
 
   // Loads G4Atts for picking...
-  LoadAtts(polyhedron, soPolyhedron);
+  if (fpViewer->GetViewParameters().IsPicking())
+    LoadAtts(polyhedron, soPolyhedron);
 
   SbString name = "Non-geometry";
@@ -600,4 +524,6 @@
 //
 void G4OpenInventorSceneHandler::AddPrimitive (const G4NURBS& nurb) {
+
+  AddProperties(nurb.GetVisAttributes()); // Transformation, colour, etc.
 
   G4float *u_knot_array, *u_knot_array_ptr;
@@ -618,15 +544,4 @@
   
   SoSeparator *surfSep = new SoSeparator();
-
-  //
-  // Color
-  //  
-  const G4Colour& c = GetColour (nurb);
-  SoMaterial* material = 
-    fStyleCache->getMaterial((float)c.GetRed(),
-                             (float)c.GetGreen(),
-                             (float)c.GetBlue(),
-                             (float)(1-c.GetAlpha()));
-  surfSep->addChild(material);
 
   //
@@ -686,33 +601,4 @@
   // location on in the scene database so that when the solid is
   // actually added (in addthis), it is put in the right place.
-
-  // Use the applicable vis attributes...
-  const G4VisAttributes* pApplicableVisAttribs =
-    fpViewer->GetApplicableVisAttributes (fpVisAttribs);
-
-  // First find the color attributes...
-  const G4Colour& g4Col =  pApplicableVisAttribs->GetColour ();
-  const double red = g4Col.GetRed ();
-  const double green = g4Col.GetGreen ();
-  const double blue = g4Col.GetBlue ();
-  double transparency = 1 - g4Col.GetAlpha();
-
-  // Drawing style...
-  G4ViewParameters::DrawingStyle drawing_style =
-    GetDrawingStyle(pApplicableVisAttribs);
-  switch (drawing_style) {
-  case (G4ViewParameters::wireframe):    
-    fModelingSolid = false;
-    break;
-  case (G4ViewParameters::hlr):
-  case (G4ViewParameters::hsr):
-  case (G4ViewParameters::hlhsr):
-    fModelingSolid = true;
-    break;
-  }	
-
-  // Edge visibility...
-  G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pApplicableVisAttribs);
-  fReducedWireFrame = !isAuxEdgeVisible;
 
   G4PhysicalVolumeModel* pPVModel =
@@ -771,4 +657,31 @@
       if(fPreviewAndFull) detectorTreeKit->setPreviewAndFull();
       else detectorTreeKit->setPreview(TRUE);
+
+      // Colour, etc., for SoDetectorTreeKit.  Treated differently to
+      // othere SoNodes(?).  Use fpVisAttribs stored away in
+      // PreAddSolid...
+      const G4VisAttributes* pApplicableVisAttribs =
+	fpViewer->GetApplicableVisAttributes (fpVisAttribs);
+
+      // First find the color attributes...
+      const G4Colour& g4Col =  pApplicableVisAttribs->GetColour ();
+      const double red = g4Col.GetRed ();
+      const double green = g4Col.GetGreen ();
+      const double blue = g4Col.GetBlue ();
+      double transparency = 1 - g4Col.GetAlpha();
+
+      // Drawing style...
+      G4ViewParameters::DrawingStyle drawing_style =
+	GetDrawingStyle(pApplicableVisAttribs);
+      switch (drawing_style) {
+      case (G4ViewParameters::wireframe):    
+	fModelingSolid = false;
+	break;
+      case (G4ViewParameters::hlr):
+      case (G4ViewParameters::hsr):
+      case (G4ViewParameters::hlhsr):
+	fModelingSolid = true;
+	break;
+      }
 
       SoMaterial* material = 
@@ -853,4 +766,36 @@
     }
   }
+}
+
+void G4OpenInventorSceneHandler::AddProperties(const G4VisAttributes* visAtts)
+{
+  // Use the applicable vis attributes...
+  const G4VisAttributes* pApplicableVisAttribs =
+    fpViewer->GetApplicableVisAttributes (visAtts);
+
+  // First find the color attributes...
+  const G4Colour& g4Col =  pApplicableVisAttribs->GetColour ();
+  const double red = g4Col.GetRed ();
+  const double green = g4Col.GetGreen ();
+  const double blue = g4Col.GetBlue ();
+  double transparency = 1 - g4Col.GetAlpha();
+
+  // Drawing style...
+  G4ViewParameters::DrawingStyle drawing_style =
+    GetDrawingStyle(pApplicableVisAttribs);
+  switch (drawing_style) {
+  case (G4ViewParameters::wireframe):    
+    fModelingSolid = false;
+    break;
+  case (G4ViewParameters::hlr):
+  case (G4ViewParameters::hsr):
+  case (G4ViewParameters::hlhsr):
+    fModelingSolid = true;
+    break;
+  }
+
+  // Edge visibility...
+  G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pApplicableVisAttribs);
+  fReducedWireFrame = !isAuxEdgeVisible;
 
   SoMaterial* material = 
@@ -883,4 +828,3 @@
   fCurrentSeparator->addChild(matrixTransform);
 }
-
 #endif
