Index: snovis/trunk/source/G4Lab/cxx/SoG4Trajectories.cxx
===================================================================
--- snovis/trunk/source/G4Lab/cxx/SoG4Trajectories.cxx	(revision 233)
+++ snovis/trunk/source/G4Lab/cxx/SoG4Trajectories.cxx	(revision 288)
@@ -23,5 +23,4 @@
 // Geant4 :
 #include <G4RunManager.hh>
-#include <G4Trajectory.hh>
 
 // G4Lab :
@@ -47,5 +46,6 @@
 SoG4Trajectories::SoG4Trajectories(
 )
-:fContainer(0)
+:fRunManager(0)
+,fContainer(0)
 ,fSensor(0)
 //////////////////////////////////////////////////////////////////////////////
@@ -78,4 +78,39 @@
 }
 //////////////////////////////////////////////////////////////////////////////
+SoG4Trajectories::SoG4Trajectories(
+ G4RunManager* aRunManager
+)
+:fRunManager(aRunManager)
+,fContainer(0)
+,fSensor(0)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  SO_NODE_CONSTRUCTOR(SoG4Trajectories);
+  SO_NODE_ADD_FIELD(model,(ALL));
+  SO_NODE_ADD_FIELD(timeStart,(0));
+  SO_NODE_ADD_FIELD(timeInterval,(0.05F));
+  SO_NODE_ADD_FIELD(timeSteps,(100));
+  SO_NODE_ADD_FIELD(timeIndex,(0));
+
+  SO_NODE_ADD_FIELD(timeMin,(0));
+  SO_NODE_ADD_FIELD(timeMax,(0));
+  SO_NODE_ADD_FIELD(verbose,(FALSE));
+  
+  SO_NODE_ADD_FIELD(alternateRep,(NULL));
+
+  SO_NODE_DEFINE_ENUM_VALUE(Model,ALL);
+  SO_NODE_DEFINE_ENUM_VALUE(Model,TIMED);
+  
+  SO_NODE_SET_SF_ENUM_TYPE(model,Model);
+
+  fSensor = new SoFieldSensor(sensorCB,this);
+  fSensor->attach(&timeInterval);
+
+  timeSteps.addAuditor(&timeInterval,SoNotRec::FIELD);
+  timeStart.addAuditor(&timeInterval,SoNotRec::FIELD);
+
+}
+//////////////////////////////////////////////////////////////////////////////
 SoG4Trajectories::~SoG4Trajectories(
 )
@@ -94,7 +129,6 @@
 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 {
-  G4RunManager* runManager = G4RunManager::GetRunManager();
-  if(!runManager) return;
-  const G4Event* event = runManager->GetCurrentEvent();
+  if(!fRunManager) return;
+  const G4Event* event = fRunManager->GetCurrentEvent();
   if(!event) return;
   G4TrajectoryContainer* trajectoryContainer = event->GetTrajectoryContainer();
@@ -146,10 +180,8 @@
           int itraj = ids[i].fTrajectory;
           int ipoint = ids[i].fPoint;
-          G4Trajectory* trajectory = 
-            (G4Trajectory*)(*trajectoryContainer)[(size_t)itraj];
+          G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)itraj];
           int pointn = trajectory->GetPointEntries();
           if( (pointn==1) || (ipoint==pointn-1) ) {
-            G4TrajectoryPoint* tp = 
-              (G4TrajectoryPoint*)(trajectory->GetPoint(ipoint));
+            G4VTrajectoryPoint* tp = trajectory->GetPoint(ipoint);
             G4ThreeVector pos = tp->GetPosition();
             glVertex3d(pos.x(),pos.y(),pos.z());
@@ -163,14 +195,12 @@
           int itraj = ids[i].fTrajectory;
           int ipoint = ids[i].fPoint;
-          G4Trajectory* trajectory = 
-            (G4Trajectory*)(*trajectoryContainer)[(size_t)itraj];
+          G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)itraj];
           int pointn = trajectory->GetPointEntries();
           if( (pointn==1) || (ipoint==pointn-1) ) {
           } else {
-            G4TrajectoryPoint* tp = 
-              (G4TrajectoryPoint*)(trajectory->GetPoint(ipoint));
+            G4VTrajectoryPoint* tp = trajectory->GetPoint(ipoint);
             G4ThreeVector pos = tp->GetPosition();
             glVertex3d(pos.x(),pos.y(),pos.z());
-            tp = (G4TrajectoryPoint*)(trajectory->GetPoint(ipoint+1));
+            tp = trajectory->GetPoint(ipoint+1);
             pos = tp->GetPosition();
             glVertex3d(pos.x(),pos.y(),pos.z());
@@ -185,10 +215,9 @@
     int number = trajectoryContainer->entries();
     for(int index=0;index<number;index++) {
-      G4Trajectory* trajectory = 
-        (G4Trajectory*)(*trajectoryContainer)[(size_t)index];
+      G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)index];
       int pointn = trajectory->GetPointEntries();
       if(pointn==1) {
         glBegin(GL_POINTS);
-        G4TrajectoryPoint* tp = (G4TrajectoryPoint*)(trajectory->GetPoint(0));
+        G4VTrajectoryPoint* tp = trajectory->GetPoint(0);
         G4ThreeVector pos = tp->GetPosition();
         glVertex3d(pos.x(),pos.y(),pos.z());
@@ -197,6 +226,5 @@
         glBegin(GL_LINE_STRIP);
         for (int i = 0; i < pointn ; i++) {
-          G4TrajectoryPoint* tp = 
-            (G4TrajectoryPoint*)(trajectory->GetPoint(i));
+          G4VTrajectoryPoint* tp = trajectory->GetPoint(i);
           G4ThreeVector pos = tp->GetPosition();
           glVertex3d(pos.x(),pos.y(),pos.z());
@@ -224,7 +252,6 @@
   aAction->setObjectSpace();
 
-  G4RunManager* runManager = G4RunManager::GetRunManager();
-  if(runManager) {
-    const G4Event* event = runManager->GetCurrentEvent();
+  if(fRunManager) {
+    const G4Event* event = fRunManager->GetCurrentEvent();
     if(event) {
       G4TrajectoryContainer* trajectoryContainer = 
@@ -233,15 +260,13 @@
         int number = trajectoryContainer->entries();
         for(int index=0;index<number;index++) {
-          G4Trajectory* trajectory = 
-            (G4Trajectory*)(*trajectoryContainer)[(size_t)index];
+          G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)index];
           int pointn = trajectory->GetPointEntries();
           if(!pointn) continue;
-          G4TrajectoryPoint* tp = 
-            (G4TrajectoryPoint*)(trajectory->GetPoint(0));
+          G4VTrajectoryPoint* tp = trajectory->GetPoint(0);
           G4ThreeVector pos = tp->GetPosition();
           SbVec3f v0;
           v0.setValue((float)pos.x(),(float)pos.y(),(float)pos.z());
           for (int i = 1; i < pointn ; i++) {
-            tp = (G4TrajectoryPoint*)(trajectory->GetPoint(i));
+            tp = trajectory->GetPoint(i);
             pos = tp->GetPosition();
             SbVec3f v1((float)pos.x(),(float)pos.y(),(float)pos.z());
@@ -271,7 +296,6 @@
 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 {
-  G4RunManager* runManager = G4RunManager::GetRunManager();
-  if(runManager) {
-    const G4Event* event = runManager->GetCurrentEvent();
+  if(fRunManager) {
+    const G4Event* event = fRunManager->GetCurrentEvent();
     if(event) {
       G4TrajectoryContainer* trajectoryContainer = 
@@ -287,10 +311,8 @@
         bool first = true;
         for(int index=0;index<number;index++) {
-          G4Trajectory* trajectory = 
-            (G4Trajectory*)(*trajectoryContainer)[(size_t)index];
+          G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)index];
           int pointn = trajectory->GetPointEntries();
           for (int i = 0; i < pointn ; i++) {
-            G4TrajectoryPoint* tp = 
-              (G4TrajectoryPoint*)(trajectory->GetPoint(i));
+            G4VTrajectoryPoint* tp = trajectory->GetPoint(i);
             G4ThreeVector pos = tp->GetPosition();
             if(first) {
@@ -336,22 +358,4 @@
 }
 //////////////////////////////////////////////////////////////////////////////
-bool SoG4Trajectories::isG4LabTrajectories(
- G4TrajectoryContainer* aContainer
-) 
-//////////////////////////////////////////////////////////////////////////////
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
-{
-  if(!aContainer) return false;
-
-  int number = aContainer->entries();
-  if(number<=0) return false;
-
-  // Check if G4Trajectory is a G4Lab::Trajectory :
-  G4Lab::Trajectory* trajectory = 
-    dynamic_cast<G4Lab::Trajectory*>((G4Trajectory*)(*aContainer)[(size_t)0]);
-
-  return (trajectory ? true : false);
-}
-//////////////////////////////////////////////////////////////////////////////
 void SoG4Trajectories::timeOrder(
  G4TrajectoryContainer* aContainer
@@ -366,6 +370,4 @@
 
   if(!aContainer) return;
-
-  if(!isG4LabTrajectories(aContainer)) return;
 
   int number = aContainer->entries();
@@ -377,9 +379,13 @@
   int numberOfPoints = 0;
   for(int index=0;index<number;index++) {
-    G4Lab::Trajectory* trajectory = 
-      (G4Lab::Trajectory*)(*aContainer)[(size_t)index];
-    int pointn = trajectory->GetPointEntries();
-    for (int i = 0; i < pointn ; i++) {
-      double globalTime = trajectory->GetPointGlobalTime(i);
+    IGeant4Trajectory* trajectory = 
+      dynamic_cast<IGeant4Trajectory*>((*aContainer)[(size_t)index]);
+    if(!trajectory) {
+      fTimeOrderedPoints.clear();
+      return;
+    }
+    unsigned int pointn = trajectory->pointEntries();
+    for (unsigned int i = 0; i < pointn ; i++) {
+      double globalTime = trajectory->pointGlobalTime(i);
       if(numberOfPoints==0) {
         minTime = globalTime;
@@ -392,4 +398,7 @@
     }
   }    
+
+
+
   SbBool flag = enableNotify(FALSE);
   timeMin.setValue((float)minTime);
@@ -409,9 +418,9 @@
       double tmax = tmin + deltaTime;
       for(int index=0;index<number;index++) {
-        G4Lab::Trajectory* trajectory = 
-          (G4Lab::Trajectory*)(*aContainer)[(size_t)index];
-        int pointn = trajectory->GetPointEntries();
-        for (int i = 0; i < pointn ; i++) {
-          double globalTime = trajectory->GetPointGlobalTime(i);
+        IGeant4Trajectory* trajectory = 
+          dynamic_cast<IGeant4Trajectory*>((*aContainer)[(size_t)index]);
+        unsigned int pointn = trajectory->pointEntries();
+        for (unsigned int i = 0; i < pointn ; i++) {
+          double globalTime = trajectory->pointGlobalTime(i);
           if((tmin<=globalTime) && (globalTime<tmax)) {
             ids.push_back(PointIdentifier(index,i));
@@ -446,13 +455,13 @@
 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 {
-  G4RunManager* runManager = G4RunManager::GetRunManager();
-  if(!runManager) return;
-  const G4Event* event = runManager->GetCurrentEvent();
+  SoG4Trajectories* This = (SoG4Trajectories*)aData;
+
+  if(!This->fRunManager) return;
+  const G4Event* event = This->fRunManager->GetCurrentEvent();
   if(!event) return;
+
   G4TrajectoryContainer* trajectoryContainer = 
     event->GetTrajectoryContainer();
   if(!trajectoryContainer) return;
-
-  SoG4Trajectories* This = (SoG4Trajectories*)aData;
 
   This->timeOrder(trajectoryContainer);
@@ -470,7 +479,6 @@
 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 {
-  G4RunManager* runManager = G4RunManager::GetRunManager();
-  if(!runManager) return;
-  const G4Event* event = runManager->GetCurrentEvent();
+  if(!fRunManager) return;
+  const G4Event* event = fRunManager->GetCurrentEvent();
   if(!event) return;
   G4TrajectoryContainer* trajectoryContainer = event->GetTrajectoryContainer();
@@ -480,12 +488,10 @@
   int number = trajectoryContainer->entries();
   for(int index=0;index<number;index++) {
-    G4Trajectory* trajectory = 
-      (G4Trajectory*)(*trajectoryContainer)[(size_t)index];
+    G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)index];
     int pointn = trajectory->GetPointEntries();
     if(pointn>=1) {
       SbVec3f* points = new SbVec3f[pointn];
       for (int i = 0; i < pointn ; i++) {
-        G4TrajectoryPoint* tp = 
-          (G4TrajectoryPoint*)(trajectory->GetPoint(i));
+        G4VTrajectoryPoint* tp = trajectory->GetPoint(i);
         G4ThreeVector pos = tp->GetPosition();
         points[i].setValue((float)pos.x(),(float)pos.y(),(float)pos.z());
@@ -513,6 +519,5 @@
  {int number = trajectoryContainer->entries();
   for(int index=0;index<number;index++) {
-    G4Trajectory* trajectory = 
-      (G4Trajectory*)(*trajectoryContainer)[(size_t)index];
+    G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)index];
     int pointn = trajectory->GetPointEntries();
     if(pointn>=1) {
@@ -531,11 +536,9 @@
   int number = trajectoryContainer->entries();
   for(int index=0;index<number;index++) {
-    G4Trajectory* trajectory = 
-      (G4Trajectory*)(*trajectoryContainer)[(size_t)index];
+    G4VTrajectory* trajectory = (*trajectoryContainer)[(size_t)index];
     int pointn = trajectory->GetPointEntries();
     if(pointn>=1) {
       for (int i = 0; i < pointn ; i++) {
-        G4TrajectoryPoint* tp = 
-          (G4TrajectoryPoint*)(trajectory->GetPoint(i));
+        G4VTrajectoryPoint* tp = trajectory->GetPoint(i);
         G4ThreeVector pos = tp->GetPosition();
         points[ipoint].setValue((float)pos.x(),(float)pos.y(),(float)pos.z());
