Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/OpenInventor/src/G4OpenInventorQtExaminerViewer.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/OpenInventor/src/G4OpenInventorQtExaminerViewer.cc (Version 11.3.0) and /visualization/OpenInventor/src/G4OpenInventorQtExaminerViewer.cc (Version 11.0)


  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                                                    26 
 27 // Frederick Jones TRIUMF 07 January 2018          27 // Frederick Jones TRIUMF 07 January 2018
 28                                                    28 
 29 #include "G4OpenInventorQtExaminerViewer.hh"       29 #include "G4OpenInventorQtExaminerViewer.hh"
 30                                                    30 
 31 #include "ui_OIQtListsDialog.h"                    31 #include "ui_OIQtListsDialog.h"
 32                                                    32 
 33 #include "saveViewPt.h"                            33 #include "saveViewPt.h"
 34 #include "pickext.h"                               34 #include "pickext.h"
 35 #include "pickref.h"                               35 #include "pickref.h"
 36 #include "wireframe.h"                             36 #include "wireframe.h"
 37                                                    37 
 38 #include <algorithm> // For using sort on a ve     38 #include <algorithm> // For using sort on a vector
 39                                                    39 
 40 #include "G4ios.hh"                                40 #include "G4ios.hh"
 41 #include "G4UImanager.hh"                          41 #include "G4UImanager.hh"
 42 #include "G4UIQt.hh"                               42 #include "G4UIQt.hh"
 43                                                    43 
 44 #include <Inventor/Qt/SoQt.h>                      44 #include <Inventor/Qt/SoQt.h>
 45 #include <Inventor/Qt/SoQtCursor.h>                45 #include <Inventor/Qt/SoQtCursor.h>
 46 #include <Inventor/events/SoKeyboardEvent.h>       46 #include <Inventor/events/SoKeyboardEvent.h>
 47 #include <Inventor/events/SoMouseButtonEvent.h     47 #include <Inventor/events/SoMouseButtonEvent.h>
 48 #include <Inventor/events/SoLocation2Event.h>      48 #include <Inventor/events/SoLocation2Event.h>
 49 #include <Inventor/nodes/SoSeparator.h>            49 #include <Inventor/nodes/SoSeparator.h>
 50 #include <Inventor/nodes/SoOrthographicCamera.     50 #include <Inventor/nodes/SoOrthographicCamera.h>
 51 #include <Inventor/nodes/SoPerspectiveCamera.h     51 #include <Inventor/nodes/SoPerspectiveCamera.h>
 52                                                    52 
 53 // FWJ moved to header file                        53 // FWJ moved to header file
 54 //#include <Inventor/nodes/SoEventCallback.h>      54 //#include <Inventor/nodes/SoEventCallback.h>
 55 #include <Inventor/nodes/SoLineSet.h>              55 #include <Inventor/nodes/SoLineSet.h>
 56 #include <Inventor/nodes/SoMaterial.h>             56 #include <Inventor/nodes/SoMaterial.h>
 57 #include <Inventor/errors/SoDebugError.h>          57 #include <Inventor/errors/SoDebugError.h>
 58 #include <Inventor/SoPickedPoint.h>                58 #include <Inventor/SoPickedPoint.h>
 59 #include <Inventor/actions/SoWriteAction.h>        59 #include <Inventor/actions/SoWriteAction.h>
 60 #include <Inventor/projectors/SbPlaneProjector     60 #include <Inventor/projectors/SbPlaneProjector.h>
 61                                                    61 
 62 #include <Inventor/sensors/SoTimerSensor.h>        62 #include <Inventor/sensors/SoTimerSensor.h>   // Animation
 63 #include <Inventor/sensors/SoNodeSensor.h>         63 #include <Inventor/sensors/SoNodeSensor.h>    // Detect start of run
 64                                                    64 
 65 #include "Geant4_SoPolyhedron.h"                   65 #include "Geant4_SoPolyhedron.h"
 66 #include "G4TrajectoryPoint.hh"                    66 #include "G4TrajectoryPoint.hh"
 67 #include "G4AttHolder.hh"                          67 #include "G4AttHolder.hh"
 68 #include "G4AttCheck.hh"                           68 #include "G4AttCheck.hh"
 69 #if 0x060000 <= QT_VERSION                     << 
 70 #include "G4StateManager.hh"                   << 
 71 #endif                                         << 
 72                                                    69 
 73 #include <Inventor/nodes/SoCallback.h>             70 #include <Inventor/nodes/SoCallback.h>
 74 #include <Inventor/nodes/SoSwitch.h>               71 #include <Inventor/nodes/SoSwitch.h>
 75 #include <Inventor/nodes/SoScale.h>                72 #include <Inventor/nodes/SoScale.h>
 76 #include <Inventor/nodes/SoTranslation.h>          73 #include <Inventor/nodes/SoTranslation.h>
 77 #include <Inventor/actions/SoSearchAction.h>       74 #include <Inventor/actions/SoSearchAction.h>
 78 #include <Inventor/actions/SoGetBoundingBoxAct     75 #include <Inventor/actions/SoGetBoundingBoxAction.h>
 79                                                    76 
 80 #include <Inventor/nodes/SoCoordinate3.h>          77 #include <Inventor/nodes/SoCoordinate3.h>
 81 // For rendering distance during animation:        78 // For rendering distance during animation:
 82 #include <Inventor/nodes/SoText2.h>                79 #include <Inventor/nodes/SoText2.h>
 83 #include <Inventor/nodes/SoFont.h>                 80 #include <Inventor/nodes/SoFont.h>
 84 #include <Inventor/nodes/SoPointSet.h>             81 #include <Inventor/nodes/SoPointSet.h>
 85 #include <Inventor/nodes/SoDrawStyle.h>            82 #include <Inventor/nodes/SoDrawStyle.h>
 86 #include <Inventor/nodes/SoBaseColor.h>            83 #include <Inventor/nodes/SoBaseColor.h>
 87                                                    84 
 88 // For searching for nodes within kits:            85 // For searching for nodes within kits:
 89 #include <Inventor/nodekits/SoBaseKit.h>           86 #include <Inventor/nodekits/SoBaseKit.h>
 90                                                    87 
 91 #include <QMenuBar>                                88 #include <QMenuBar>
 92 #include <QPushButton>                             89 #include <QPushButton>
 93 #include <QRadioButton>                            90 #include <QRadioButton>
 94 #include <QToolButton>                             91 #include <QToolButton>
 95 #include <QListWidget>                             92 #include <QListWidget>
 96 #include <QListWidgetItem>                         93 #include <QListWidgetItem>
 97 #include <QInputDialog>                            94 #include <QInputDialog>
 98 #include <QMessageBox>                             95 #include <QMessageBox>
 99 #include <QFileDialog>                             96 #include <QFileDialog>
100 #include <QStyle>                                  97 #include <QStyle>
101 #include <QCommonStyle>                            98 #include <QCommonStyle>
102 //#include <QMainWindow>                           99 //#include <QMainWindow>
103                                                   100 
104 #ifndef G4GMAKE                                   101 #ifndef G4GMAKE
105 #include "moc_G4OpenInventorQtExaminerViewer.c    102 #include "moc_G4OpenInventorQtExaminerViewer.cpp"
106 #endif                                            103 #endif
107                                                   104 
108 #define G4warn G4cout                          << 
109                                                << 
110 #if QT_VERSION < 0x060000                      << 
111 G4OpenInventorQtExaminerViewer* G4OpenInventor    105 G4OpenInventorQtExaminerViewer* G4OpenInventorQtExaminerViewer::viewer = 0;
112 #endif                                         << 
113                                                   106 
114 #define MIN_SPEED  2.1        // Lower number     107 #define MIN_SPEED  2.1        // Lower number means faster
115 #define START_STEP 0.3                            108 #define START_STEP 0.3
116 #define SPEED_INDICATOR_STEP 0.045                109 #define SPEED_INDICATOR_STEP 0.045
117 #define MAX_SPEED_INDICATOR  0.81                 110 #define MAX_SPEED_INDICATOR  0.81
118 // Number of steps 90 degree rotation around a    111 // Number of steps 90 degree rotation around an element is split into
119 #define ROT_CNT 6                                 112 #define ROT_CNT 6
120                                                   113 
121                                                   114 
122 // Constructor                                    115 // Constructor
123 G4OpenInventorQtExaminerViewer::                  116 G4OpenInventorQtExaminerViewer::
124 G4OpenInventorQtExaminerViewer(QWidget* parent    117 G4OpenInventorQtExaminerViewer(QWidget* parent, const char* name, SbBool embed,
125                                SoQtFullViewer:    118                                SoQtFullViewer::BuildFlag flag,
126                                SoQtViewer::Typ    119                                SoQtViewer::Type type)
127    : SoQtExaminerViewer(parent, name, embed, f    120    : SoQtExaminerViewer(parent, name, embed, flag, type),
128 #if 0x060000 <= QT_VERSION                     << 
129      fName(name),                              << 
130 #endif                                         << 
131      externalQtApp(0), processSoEventCount(0)     121      externalQtApp(0), processSoEventCount(0)
132 {                                                 122 {
133    // FWJ DEBUG                                   123    // FWJ DEBUG
134    //  G4cout << "G4OpenInventorQtExaminerView    124    //  G4cout << "G4OpenInventorQtExaminerViewer CONSTRUCTOR CALLED" << G4endl;
135    //  G4cout << "G4OpenInventorQtExaminerView    125    //  G4cout << "G4OpenInventorQtExaminerViewer parent=" << parent << G4endl;
136                                                   126 
137    // FWJ THIS DOESN'T WORK APPARENTLY NO MAIN    127    // FWJ THIS DOESN'T WORK APPARENTLY NO MAINWINDOW
138    //   QMenuBar* menubar = ((QMainWindow*)par    128    //   QMenuBar* menubar = ((QMainWindow*)parent)->menuBar();
139                                                   129 
140 #if QT_VERSION < 0x060000                      << 
141    fName = new QString(name);                     130    fName = new QString(name);
142    viewer = this;                                 131    viewer = this;
143 #endif                                         << 
144    construct(TRUE);                               132    construct(TRUE);
145 }                                                 133 }
146                                                   134 
147 // Destructor                                     135 // Destructor
148 G4OpenInventorQtExaminerViewer::~G4OpenInvento    136 G4OpenInventorQtExaminerViewer::~G4OpenInventorQtExaminerViewer()
149 {                                                 137 {
150    //   if (superimposition != NULL) {            138    //   if (superimposition != NULL) {
151    //      removeSuperimposition(superimpositi    139    //      removeSuperimposition(superimposition);
152    //      superimposition->unref();              140    //      superimposition->unref();
153    //      superimposition = NULL;                141    //      superimposition = NULL;
154    //   }                                         142    //   }
155    //   if (animateSensor->isScheduled())         143    //   if (animateSensor->isScheduled())
156    //      animateSensor->unschedule();           144    //      animateSensor->unschedule();
157    //   delete animateSensor;                     145    //   delete animateSensor;
158    //   delete sceneChangeSensor;                 146    //   delete sceneChangeSensor;
159    //   delete[] curViewPtName;                   147    //   delete[] curViewPtName;
160    //   delete searcher;                          148    //   delete searcher;
161                                                   149 
162 #if QT_VERSION < 0x060000                      << 
163    viewer = 0;                                    150    viewer = 0;
164 #else                                          << 
165    delete hookBeamOn;                          << 
166 #endif                                         << 
167 }                                                 151 }
168                                                   152 
169                                                   153 
170 void G4OpenInventorQtExaminerViewer::construct    154 void G4OpenInventorQtExaminerViewer::construct(const SbBool)
171 {                                                 155 {
172    setFeedbackSize(40);                           156    setFeedbackSize(40);
173                                                   157 
174    hookBeamOn = new HookEventProcState(this);     158    hookBeamOn = new HookEventProcState(this);
175    newEvents = false;                             159    newEvents = false;
176                                                   160 
177    buildWidget(getParentWidget());                161    buildWidget(getParentWidget());
178                                                   162 
179    fileName = "bookmarkFile"; // Default viewp    163    fileName = "bookmarkFile"; // Default viewpoint file name
180    viewPtIdx = -1; // index of the most recent    164    viewPtIdx = -1; // index of the most recent viewpoint in viewPtList vector
181                                                   165 
182    animateSensor = new SoTimerSensor(animateSe    166    animateSensor = new SoTimerSensor(animateSensorCB, this);
183    animateSensorRotation = new SoTimerSensor(a    167    animateSensorRotation = new SoTimerSensor(animateSensorRotationCB, this);
184    animateBtwPtsPeriod = MIN_SPEED;               168    animateBtwPtsPeriod = MIN_SPEED;
185                                                   169 
186    currentState = GENERAL;                        170    currentState = GENERAL;
187    myCam = new SoPerspectiveCamera;               171    myCam = new SoPerspectiveCamera;
188    MAX_VP_IDX = 3;                                172    MAX_VP_IDX = 3;
189    MAX_VP_NAME = 35; // Max length of a viewpo    173    MAX_VP_NAME = 35; // Max length of a viewpoint name, padded with spaces
190 #if QT_VERSION < 0x060000                      << 
191    curViewPtName = new char[MAX_VP_NAME + 1];     174    curViewPtName = new char[MAX_VP_NAME + 1];
192 #else                                          << 
193    curViewPtName.clear();                      << 
194 #endif                                         << 
195    left_right = up_down = 0; // For movements     175    left_right = up_down = 0; // For movements around the beam during animation
196    speedStep = START_STEP; // For smoother ani    176    speedStep = START_STEP; // For smoother animation speed increase/decrease
197    rotUpVec = false; // Used during scene elem    177    rotUpVec = false; // Used during scene element rotations
198    step = 1;  //By default                        178    step = 1;  //By default
199    // Used for moving along the beam with the     179    // Used for moving along the beam with the
200    // mouse instead of rotating the view          180    // mouse instead of rotating the view
201    lshiftdown = rshiftdown = false;               181    lshiftdown = rshiftdown = false;
202    // Used for rotating the view with the came    182    // Used for rotating the view with the camera
203    // staying in place                            183    // staying in place
204    lctrldown = rctrldown = false;                 184    lctrldown = rctrldown = false;
205    // Used to send abbreviated output to the c    185    // Used to send abbreviated output to the console when
206    abbrOutputFlag = false;                        186    abbrOutputFlag = false;
207    pickRefPathFlag = false;                       187    pickRefPathFlag = false;
208    prevColorField = NULL;                         188    prevColorField = NULL;
209    //   warningFlag = false; // We come from t    189    //   warningFlag = false; // We come from the warning dialog
210    //   myElementList = NULL;                     190    //   myElementList = NULL;
211    // FWJ default path look-ahead                 191    // FWJ default path look-ahead
212    pathLookahead = 5;                             192    pathLookahead = 5;
213                                                   193 
214    newSceneGraph = NULL;                          194    newSceneGraph = NULL;
215    zcoordSetFlag = false;                         195    zcoordSetFlag = false;
216                                                   196 
217    //////////////////////////SUPERIMPOSED SCEN    197    //////////////////////////SUPERIMPOSED SCENE//////////////////////////
218    searcher = NULL;                               198    searcher = NULL;
219    // Used in animation; progressively scaled     199    // Used in animation; progressively scaled for gradual speed change
220    maxSpeed = 0.0f;                               200    maxSpeed = 0.0f;
221                                                   201 
222    static const char * superimposed[] = {         202    static const char * superimposed[] = {
223       "#Inventor V2.1 ascii", "",                 203       "#Inventor V2.1 ascii", "",
224       "Separator ",                               204       "Separator ",
225       "{",                                        205       "{",
226       " MaterialBinding ",                        206       " MaterialBinding ",
227       " {",                                       207       " {",
228       "         value OVERALL",                   208       "         value OVERALL",
229       " }",                                       209       " }",
230       "         OrthographicCamera ",             210       "         OrthographicCamera ",
231       " {",                                       211       " {",
232       "         height 1",                        212       "         height 1",
233       "         nearDistance 0",                  213       "         nearDistance 0",
234       "         farDistance 1",                   214       "         farDistance 1",
235       " }",                                       215       " }",
236       "         DEF soxt->callback Callback {     216       "         DEF soxt->callback Callback { }",
237       "         Separator ",                      217       "         Separator ",
238       " {",                                       218       " {",
239       "         DEF soxt->translation Translat    219       "         DEF soxt->translation Translation ",
240       "         {",                               220       "         {",
241       "                 translation 0 0 0",       221       "                 translation 0 0 0",
242       "     }",                                   222       "     }",
243       "     DEF soxt->scale Scale ",              223       "     DEF soxt->scale Scale ",
244       "         {",                               224       "         {",
245       "                 scaleFactor 1 1 1",       225       "                 scaleFactor 1 1 1",
246       "     }",                                   226       "     }",
247       "         DEF soxt->geometry Coordinate3    227       "         DEF soxt->geometry Coordinate3 ",
248       "         {",                               228       "         {",
249       "             point ",                      229       "             point ",
250       "                 [",                       230       "                 [",
251       "                         -0.81   -0.04     231       "                         -0.81   -0.04   0,      -0.81   0             0,",
252       "                 -0.81   0.04    0,        232       "                 -0.81   0.04    0,      0       -0.04   0,",
253       "                 0       0       0,  0     233       "                 0       0       0,  0       0.04        0,",
254       "                 0.81    -0.04   0,  0.    234       "                 0.81    -0.04   0,  0.81        0           0,",
255       "                 0.81    0.04    0,",      235       "                 0.81    0.04    0,",
256       "                 0       0.02    0,", /    236       "                 0       0.02    0,", // idx 9
257       "                 0.81    0.02    0,  0.    237       "                 0.81    0.02    0,  0.81        -0.02   0,",
258       "                 0       -0.02   0,",      238       "                 0       -0.02   0,",
259       "                 0       0.01    0,", /    239       "                 0       0.01    0,", // idx 13
260       "                 0.4     0.01    0,  0.    240       "                 0.4     0.01    0,  0.4         -0.01   0,",
261       "                 0       -0.01   0",       241       "                 0       -0.01   0",
262       "                 ]",                       242       "                 ]",
263       "         }",                               243       "         }",
264       // current speed indicator (outline)        244       // current speed indicator (outline)
265       "         DEF soxt->animSpeedOutlineSwit    245       "         DEF soxt->animSpeedOutlineSwitch Switch ",
266       "         {",                               246       "         {",
267       "                 whichChild -3",           247       "                 whichChild -3",
268       "                 Material ",               248       "                 Material ",
269       "                 {",                       249       "                 {",
270       "                    emissiveColor 0 0 0    250       "                    emissiveColor 0 0 0",
271       "             }",                           251       "             }",
272       "                 IndexedFaceSet ",         252       "                 IndexedFaceSet ",
273       "                 {",                       253       "                 {",
274       "                 coordIndex ",             254       "                 coordIndex ",
275       "                         [",               255       "                         [",
276       "                                 12, 11    256       "                                 12, 11, 10, 9, -1",
277       "                         ]",               257       "                         ]",
278       "         }",                               258       "         }",
279       "                  }",                      259       "                  }",
280       // the coordinate system                    260       // the coordinate system
281       "         DEF soxt->axisSwitch Switch ",    261       "         DEF soxt->axisSwitch Switch ",
282       "         {",                               262       "         {",
283       "                 whichChild -3",           263       "                 whichChild -3",
284       "                 BaseColor ",              264       "                 BaseColor ",
285       "                 {",                       265       "                 {",
286       "                     rgb 1 1 1",           266       "                     rgb 1 1 1",
287       "                 }",                       267       "                 }",
288       "                 IndexedLineSet ",         268       "                 IndexedLineSet ",
289       "                 {",                       269       "                 {",
290       "                         coordIndex ",     270       "                         coordIndex ",
291       "                         [",               271       "                         [",
292       "                                 0, 2,     272       "                                 0, 2, -1,",
293       "                                 3, 5,     273       "                                 3, 5, -1,",
294       "                                 6, 8,     274       "                                 6, 8, -1,",
295       "                                 1, 7,     275       "                                 1, 7, -1",
296       "                         ]",               276       "                         ]",
297       "                     }",                   277       "                     }",
298       "                 }",                       278       "                 }",
299       // current speed indicator                  279       // current speed indicator
300       "         DEF soxt->animSpeedSwitch Swit    280       "         DEF soxt->animSpeedSwitch Switch ",
301       "         {",                               281       "         {",
302       "                     whichChild -3",       282       "                     whichChild -3",
303       "                 Material ",               283       "                 Material ",
304       "                 {",                       284       "                 {",
305       "                 emissiveColor 0 1 0",     285       "                 emissiveColor 0 1 0",
306       "         }",                               286       "         }",
307       "                 IndexedFaceSet ",         287       "                 IndexedFaceSet ",
308       "                 {",                       288       "                 {",
309       "                 coordIndex ",             289       "                 coordIndex ",
310       "                         [",               290       "                         [",
311       "                                 16, 15    291       "                                 16, 15, 14, 13, -1",
312       "                         ]",               292       "                         ]",
313       "                 }",                       293       "                 }",
314       "         }",                               294       "         }",
315       "         }",                               295       "         }",
316       // For displaying either z position (dur    296       // For displaying either z position (during animation) or current viewpoint name
317       " DEF soxt->curInfoSwitch Switch ",         297       " DEF soxt->curInfoSwitch Switch ",
318       " {",                                       298       " {",
319       "         whichChild -3",                   299       "         whichChild -3",
320       "         DEF soxt->curInfoTrans Transla    300       "         DEF soxt->curInfoTrans Translation ",
321       "         {",                               301       "         {",
322       "                 translation 0 0 0    "    302       "                 translation 0 0 0    ",
323       //      "                 translation 10    303       //      "                 translation 10 20 30    ",
324       "         }",                               304       "         }",
325       "         DEF soxt->curInfoFont Font ",     305       "         DEF soxt->curInfoFont Font ",
326       "         {",                               306       "         {",
327       "                 name defaultFont:Bold"    307       "                 name defaultFont:Bold",
328       "                 size 16",                 308       "                 size 16",
329       "                 }",                       309       "                 }",
330       "         DEF soxt->curInfoText Text2 ",    310       "         DEF soxt->curInfoText Text2 ",
331       "         {",                               311       "         {",
332       "                 string Hello",            312       "                 string Hello",
333       "     }",                                   313       "     }",
334       " }",                                       314       " }",
335       // Need to use different fields for mous    315       // Need to use different fields for mouseover
336       // because newlines are ignored when the    316       // because newlines are ignored when the scene is rendered
337       " Separator ",                              317       " Separator ",
338       " {",                                       318       " {",
339       "         DEF soxt->mouseOverTransLogNam    319       "         DEF soxt->mouseOverTransLogName Translation ",
340       "         {",                               320       "         {",
341       "                 translation 0 0 0    "    321       "                 translation 0 0 0    ",
342       "         }",                               322       "         }",
343       "         DEF soxt->mouseOverFontLogName    323       "         DEF soxt->mouseOverFontLogName Font ",
344       "         {",                               324       "         {",
345       "                 name defaultFont:Bold"    325       "                 name defaultFont:Bold",
346       "                 size 16",                 326       "                 size 16",
347       "                 }",                       327       "                 }",
348       "         DEF soxt->mouseOverTextLogName    328       "         DEF soxt->mouseOverTextLogName Text2 { } ",
349       " }",                                       329       " }",
350       " Separator ",                              330       " Separator ",
351       " {",                                       331       " {",
352       "         DEF soxt->mouseOverTransSolid     332       "         DEF soxt->mouseOverTransSolid Translation ",
353       "         {",                               333       "         {",
354       "                 translation 0 0 0    "    334       "                 translation 0 0 0    ",
355       "         }",                               335       "         }",
356       "         DEF soxt->mouseOverFontSolid F    336       "         DEF soxt->mouseOverFontSolid Font ",
357       "         {",                               337       "         {",
358       "                 name defaultFont:Bold"    338       "                 name defaultFont:Bold",
359       "                 size 16",                 339       "                 size 16",
360       "                 }",                       340       "                 }",
361       "         DEF soxt->mouseOverTextSolid T    341       "         DEF soxt->mouseOverTextSolid Text2 { } ",
362       " }",                                       342       " }",
363       " Separator ",                              343       " Separator ",
364       " {",                                       344       " {",
365       "         DEF soxt->mouseOverTransMateri    345       "         DEF soxt->mouseOverTransMaterial Translation ",
366       "         {",                               346       "         {",
367       "                 translation 0 0 0    "    347       "                 translation 0 0 0    ",
368       "         }",                               348       "         }",
369       "         DEF soxt->mouseOverFontMateria    349       "         DEF soxt->mouseOverFontMaterial Font ",
370       "         {",                               350       "         {",
371       "                 name defaultFont:Bold"    351       "                 name defaultFont:Bold",
372       "                 size 16",                 352       "                 size 16",
373       "                 }",                       353       "                 }",
374       "         DEF soxt->mouseOverTextMateria    354       "         DEF soxt->mouseOverTextMaterial Text2 { } ",
375       " }",                                       355       " }",
376       " Separator ",                              356       " Separator ",
377       " {",                                       357       " {",
378       "         DEF soxt->mouseOverTransZPos T    358       "         DEF soxt->mouseOverTransZPos Translation ",
379       "         {",                               359       "         {",
380       "                 translation 0 0 0    "    360       "                 translation 0 0 0    ",
381       "         }",                               361       "         }",
382       "         DEF soxt->mouseOverFontZPos Fo    362       "         DEF soxt->mouseOverFontZPos Font ",
383       "         {",                               363       "         {",
384       "                 name defaultFont:Bold"    364       "                 name defaultFont:Bold",
385       "                 size 16",                 365       "                 size 16",
386       "                 }",                       366       "                 }",
387       "         DEF soxt->mouseOverTextZPos Te    367       "         DEF soxt->mouseOverTextZPos Text2 { } ",
388       " }",                                       368       " }",
389       "}", NULL                                   369       "}", NULL
390    };                                             370    };
391                                                   371 
392    int i, bufsize;                                372    int i, bufsize;
393    for (i = bufsize = 0; superimposed[i]; i++)    373    for (i = bufsize = 0; superimposed[i]; i++)
394       bufsize += strlen(superimposed[i]) + 1;     374       bufsize += strlen(superimposed[i]) + 1;
395    char * buf = new char[bufsize + 1];            375    char * buf = new char[bufsize + 1];
396    for (i = bufsize = 0; superimposed[i]; i++)    376    for (i = bufsize = 0; superimposed[i]; i++) {
397       strcpy(buf + bufsize, superimposed[i]);     377       strcpy(buf + bufsize, superimposed[i]);
398       bufsize += strlen(superimposed[i]);         378       bufsize += strlen(superimposed[i]);
399       buf[bufsize] = '\n';                        379       buf[bufsize] = '\n';
400       bufsize++;                                  380       bufsize++;
401    }                                              381    }
402    SoInput * input = new SoInput;                 382    SoInput * input = new SoInput;
403    input->setBuffer(buf, bufsize);                383    input->setBuffer(buf, bufsize);
404    SbBool ok = SoDB::read(input, superimpositi    384    SbBool ok = SoDB::read(input, superimposition);
405    (void)ok;   // FWJ added to avoid compiler     385    (void)ok;   // FWJ added to avoid compiler warning
406    assert(ok);                                    386    assert(ok);
407    delete input;                                  387    delete input;
408    delete[] buf;                                  388    delete[] buf;
409    superimposition->ref();                        389    superimposition->ref();
410                                                   390 
411    sscale = (SoScale *) getSuperimpositionNode    391    sscale = (SoScale *) getSuperimpositionNode(superimposition, "soxt->scale");
412    stranslation = (SoTranslation *) getSuperim    392    stranslation = (SoTranslation *) getSuperimpositionNode(superimposition, "soxt->translation");
413    sgeometry = (SoCoordinate3 *) getSuperimpos    393    sgeometry = (SoCoordinate3 *) getSuperimpositionNode(superimposition, "soxt->geometry");
414    axisSwitch = (SoSwitch *) getSuperimpositio    394    axisSwitch = (SoSwitch *) getSuperimpositionNode(superimposition, "soxt->axisSwitch");
415    animSpeedOutlineSwitch = (SoSwitch *) getSu    395    animSpeedOutlineSwitch = (SoSwitch *) getSuperimpositionNode(superimposition, "soxt->animSpeedOutlineSwitch");
416    animSpeedSwitch = (SoSwitch *) getSuperimpo    396    animSpeedSwitch = (SoSwitch *) getSuperimpositionNode(superimposition, "soxt->animSpeedSwitch");
417    curInfoSwitch = (SoSwitch *) getSuperimposi    397    curInfoSwitch = (SoSwitch *) getSuperimpositionNode(superimposition, "soxt->curInfoSwitch");
418    curInfoTrans = (SoTranslation *) getSuperim    398    curInfoTrans = (SoTranslation *) getSuperimpositionNode(superimposition, "soxt->curInfoTrans");
419    curInfoFont = (SoFont *) getSuperimposition    399    curInfoFont = (SoFont *) getSuperimpositionNode(superimposition, "soxt->curInfoFont");
420    curInfoText = (SoText2 *) getSuperimpositio    400    curInfoText = (SoText2 *) getSuperimpositionNode(superimposition, "soxt->curInfoText");
421    mouseOverTransLogName = (SoTranslation*)get    401    mouseOverTransLogName = (SoTranslation*)getSuperimpositionNode(superimposition, "soxt->mouseOverTransLogName");
422    mouseOverFontLogName = (SoFont *) getSuperi    402    mouseOverFontLogName = (SoFont *) getSuperimpositionNode(superimposition, "soxt->mouseOverFontLogName");
423    mouseOverTextLogName = (SoText2 *) getSuper    403    mouseOverTextLogName = (SoText2 *) getSuperimpositionNode(superimposition, "soxt->mouseOverTextLogName");
424    mouseOverTransSolid = (SoTranslation *) get    404    mouseOverTransSolid = (SoTranslation *) getSuperimpositionNode(superimposition, "soxt->mouseOverTransSolid");
425    mouseOverFontSolid = (SoFont *) getSuperimp    405    mouseOverFontSolid = (SoFont *) getSuperimpositionNode(superimposition, "soxt->mouseOverFontSolid");
426    mouseOverTextSolid = (SoText2 *) getSuperim    406    mouseOverTextSolid = (SoText2 *) getSuperimpositionNode(superimposition, "soxt->mouseOverTextSolid");
427    mouseOverTransMaterial = (SoTranslation*)ge    407    mouseOverTransMaterial = (SoTranslation*)getSuperimpositionNode(superimposition, "soxt->mouseOverTransMaterial");
428    mouseOverFontMaterial = (SoFont *) getSuper    408    mouseOverFontMaterial = (SoFont *) getSuperimpositionNode(superimposition, "soxt->mouseOverFontMaterial");
429    mouseOverTextMaterial = (SoText2 *) getSupe    409    mouseOverTextMaterial = (SoText2 *) getSuperimpositionNode(superimposition, "soxt->mouseOverTextMaterial");
430    mouseOverTransZPos = (SoTranslation *) getS    410    mouseOverTransZPos = (SoTranslation *) getSuperimpositionNode(superimposition, "soxt->mouseOverTransZPos");
431    mouseOverFontZPos = (SoFont *) getSuperimpo    411    mouseOverFontZPos = (SoFont *) getSuperimpositionNode(superimposition, "soxt->mouseOverFontZPos");
432    mouseOverTextZPos = (SoText2 *) getSuperimp    412    mouseOverTextZPos = (SoText2 *) getSuperimpositionNode(superimposition, "soxt->mouseOverTextZPos");
433                                                   413 
434    SoCallback * cb = (SoCallback *) getSuperim    414    SoCallback * cb = (SoCallback *) getSuperimpositionNode(superimposition, "soxt->callback");
435    cb->setCallback(superimpositionCB, this);      415    cb->setCallback(superimpositionCB, this);
436                                                   416 
437    addSuperimposition(superimposition);           417    addSuperimposition(superimposition);
438    setSuperimpositionEnabled(superimposition,     418    setSuperimpositionEnabled(superimposition, FALSE);
439    axisSwitch->whichChild.setValue(SO_SWITCH_N    419    axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
440    animSpeedOutlineSwitch->whichChild.setValue    420    animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
441    animSpeedSwitch->whichChild.setValue(SO_SWI    421    animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
442                                                   422 
443    /////////////////////\SUPERIMPOSED SCENE///    423    /////////////////////\SUPERIMPOSED SCENE///////////////////////////////////
444                                                   424 
445 }                                                 425 }
446                                                   426 
447                                                   427 
448 // Adds a menu bar and menu items to the viewe    428 // Adds a menu bar and menu items to the viewer.
449 void G4OpenInventorQtExaminerViewer::buildWidg    429 void G4OpenInventorQtExaminerViewer::buildWidget(QWidget* parent)
450 {                                                 430 {
451    if (!parent)                                   431    if (!parent)
452       SoDebugError::post("G4OpenInventorQtExam    432       SoDebugError::post("G4OpenInventorQtExaminerViewer::buildWidget",
453                          "Error: Parent is nul    433                          "Error: Parent is null.");
454                                                   434 
455    // Common font for (almost) all widgets        435    // Common font for (almost) all widgets
456    font = new QFont;                              436    font = new QFont;
457    font->setPointSize(12);                        437    font->setPointSize(12);
458    // This font setting does not propagate to     438    // This font setting does not propagate to added child widgets - Why?
459    parent->setFont(*font);                        439    parent->setFont(*font);
460    // This propagates everywhere but would aff    440    // This propagates everywhere but would affect UIQt!
461    //   QApplication::setFont(*font);             441    //   QApplication::setFont(*font);
462                                                   442 
463 // MENU BAR                                       443 // MENU BAR
464                                                   444 
465 #if QT_VERSION < 0x060000                      << 
466    menubar = new QMenuBar(getRenderAreaWidget(    445    menubar = new QMenuBar(getRenderAreaWidget());
467 #else                                          << 
468    menubar = new QMenuBar();                   << 
469    menubar->setNativeMenuBar(false);           << 
470    addAppPushButton(menubar);                  << 
471 #endif                                         << 
472    // FWJ DEBUG                                   446    // FWJ DEBUG
473    //   G4cout << "G4OpenInventorQtExaminerVie    447    //   G4cout << "G4OpenInventorQtExaminerViewer: GOT A menubar=" <<
474    //      menubar << G4endl;                     448    //      menubar << G4endl; 
475                                                   449    
476    filemenu = new QMenu("File");                  450    filemenu = new QMenu("File");
477    menubar->addMenu(filemenu);                    451    menubar->addMenu(filemenu); 
478                                                   452 
479    FileOpenBookmark = new QAction("Open Bookma    453    FileOpenBookmark = new QAction("Open Bookmark File", this);
480    FileOpenBookmark->setFont(*font);              454    FileOpenBookmark->setFont(*font);
481    connect(FileOpenBookmark, SIGNAL(triggered(    455    connect(FileOpenBookmark, SIGNAL(triggered()), this,
482            SLOT(FileOpenBookmarkCB()));           456            SLOT(FileOpenBookmarkCB()));
483    filemenu->addAction(FileOpenBookmark);         457    filemenu->addAction(FileOpenBookmark);
484                                                   458 
485    FileNewBookmark = new QAction("New Bookmark    459    FileNewBookmark = new QAction("New Bookmark File", this);
486    FileNewBookmark->setFont(*font);               460    FileNewBookmark->setFont(*font);
487    connect(FileNewBookmark, SIGNAL(triggered()    461    connect(FileNewBookmark, SIGNAL(triggered()), this,
488            SLOT(FileNewBookmarkCB()));            462            SLOT(FileNewBookmarkCB()));
489    filemenu->addAction(FileNewBookmark);          463    filemenu->addAction(FileNewBookmark);
490                                                   464 
491    FileLoadRefPath = new QAction("Load Referen    465    FileLoadRefPath = new QAction("Load Reference Path", this);
492    FileLoadRefPath->setFont(*font);               466    FileLoadRefPath->setFont(*font);
493    connect(FileLoadRefPath, SIGNAL(triggered()    467    connect(FileLoadRefPath, SIGNAL(triggered()), this,
494            SLOT(FileLoadRefPathCB()));            468            SLOT(FileLoadRefPathCB()));
495    filemenu->addAction(FileLoadRefPath);          469    filemenu->addAction(FileLoadRefPath);
496                                                   470 
497    FileSaveRefPath = new QAction("Save Referen    471    FileSaveRefPath = new QAction("Save Reference Path", this);
498    FileSaveRefPath->setFont(*font);               472    FileSaveRefPath->setFont(*font);
499    connect(FileSaveRefPath, SIGNAL(triggered()    473    connect(FileSaveRefPath, SIGNAL(triggered()), this,
500            SLOT(FileSaveRefPathCB()));            474            SLOT(FileSaveRefPathCB()));
501    filemenu->addAction(FileSaveRefPath);          475    filemenu->addAction(FileSaveRefPath);
502                                                   476 
503    FileLoadSceneGraph = new QAction("Load scen    477    FileLoadSceneGraph = new QAction("Load scene graph", this);
504    FileLoadSceneGraph->setFont(*font);            478    FileLoadSceneGraph->setFont(*font);
505    connect(FileLoadSceneGraph, SIGNAL(triggere    479    connect(FileLoadSceneGraph, SIGNAL(triggered()), this,
506            SLOT(FileLoadSceneGraphCB()));         480            SLOT(FileLoadSceneGraphCB()));
507    filemenu->addAction(FileLoadSceneGraph);       481    filemenu->addAction(FileLoadSceneGraph);
508                                                   482 
509    FileSaveSceneGraph = new QAction("Save scen    483    FileSaveSceneGraph = new QAction("Save scene graph", this);
510    FileSaveSceneGraph->setFont(*font);            484    FileSaveSceneGraph->setFont(*font);
511    connect(FileSaveSceneGraph, SIGNAL(triggere    485    connect(FileSaveSceneGraph, SIGNAL(triggered()), this,
512            SLOT(FileSaveSceneGraphCB()));         486            SLOT(FileSaveSceneGraphCB()));
513    filemenu->addAction(FileSaveSceneGraph);       487    filemenu->addAction(FileSaveSceneGraph);
514                                                   488 
515    // Rest of File menu is done in G4OpenInven    489    // Rest of File menu is done in G4OpenInventorQtViewer
516                                                   490 
517    toolsmenu = new QMenu("Tools");                491    toolsmenu = new QMenu("Tools");
518    menubar->addMenu(toolsmenu);                   492    menubar->addMenu(toolsmenu); 
519                                                   493 
520    ToolsAnimateRefParticle = new QAction("Fly     494    ToolsAnimateRefParticle = new QAction("Fly on Ref Path", this);
521    ToolsAnimateRefParticle->setFont(*font);       495    ToolsAnimateRefParticle->setFont(*font);
522    connect(ToolsAnimateRefParticle, SIGNAL(tri    496    connect(ToolsAnimateRefParticle, SIGNAL(triggered()), this,
523            SLOT(ToolsAnimateRefParticleCB()));    497            SLOT(ToolsAnimateRefParticleCB()));
524    toolsmenu->addAction(ToolsAnimateRefParticl    498    toolsmenu->addAction(ToolsAnimateRefParticle);
525                                                   499 
526    ToolsRefPathStart = new QAction("Go to star    500    ToolsRefPathStart = new QAction("Go to start of Ref Path", this);
527    ToolsRefPathStart->setFont(*font);             501    ToolsRefPathStart->setFont(*font);
528    connect(ToolsRefPathStart, SIGNAL(triggered    502    connect(ToolsRefPathStart, SIGNAL(triggered()), this,
529            SLOT(ToolsRefPathStartCB()));          503            SLOT(ToolsRefPathStartCB()));
530    toolsmenu->addAction(ToolsRefPathStart);       504    toolsmenu->addAction(ToolsRefPathStart);
531                                                   505 
532    ToolsRefPathInvert = new QAction("Invert Re    506    ToolsRefPathInvert = new QAction("Invert Ref Path", this);
533    ToolsRefPathInvert->setFont(*font);            507    ToolsRefPathInvert->setFont(*font);
534    connect(ToolsRefPathInvert, SIGNAL(triggere    508    connect(ToolsRefPathInvert, SIGNAL(triggered()), this,
535            SLOT(ToolsRefPathInvertCB()));         509            SLOT(ToolsRefPathInvertCB()));
536    toolsmenu->addAction(ToolsRefPathInvert);      510    toolsmenu->addAction(ToolsRefPathInvert);
537                                                   511 
538    etcmenu = new QMenu("Etc");                    512    etcmenu = new QMenu("Etc");
539    menubar->addMenu(etcmenu);                     513    menubar->addMenu(etcmenu); 
540                                                   514 
541    // All Etc menu items are done in G4OpenInv    515    // All Etc menu items are done in G4OpenInventorQtViewer
542                                                   516 
543    helpmenu = new QMenu("Help");                  517    helpmenu = new QMenu("Help");
544    menubar->addMenu(helpmenu);                    518    menubar->addMenu(helpmenu); 
545                                                   519 
546    HelpControls = new QAction("Controls", this    520    HelpControls = new QAction("Controls", this);
547    HelpControls->setFont(*font);                  521    HelpControls->setFont(*font);
548    connect(HelpControls, SIGNAL(triggered()),     522    connect(HelpControls, SIGNAL(triggered()), this, SLOT(HelpControlsCB()));
549    helpmenu->addAction(HelpControls);             523    helpmenu->addAction(HelpControls);
550                                                   524 
551 #if QT_VERSION < 0x060000                      << 
552    menubar->show();                               525    menubar->show();
553 #endif                                         << 
554                                                   526 
555    //   SoQtExaminerViewer::buildWidget(parent    527    //   SoQtExaminerViewer::buildWidget(parent);
556                                                   528 
557    // APP VIEWER BUTTONS have their own box on    529    // APP VIEWER BUTTONS have their own box on upper left
558    // The built in viewer button list is PRIVA    530    // The built in viewer button list is PRIVATE
559                                                   531 
560    saveViewPtButton = new QPushButton;            532    saveViewPtButton = new QPushButton;
561    saveViewPtButton->setIcon(QPixmap((const ch    533    saveViewPtButton->setIcon(QPixmap((const char **)saveViewPt_xpm));
562    saveViewPtButton->setIconSize(QSize(24,24))    534    saveViewPtButton->setIconSize(QSize(24,24));
563    saveViewPtButton->setToolTip("Bookmark this    535    saveViewPtButton->setToolTip("Bookmark this view");
564    connect(saveViewPtButton, SIGNAL(clicked())    536    connect(saveViewPtButton, SIGNAL(clicked()), this,
565            SLOT(SaveViewPtCB()));                 537            SLOT(SaveViewPtCB()));
566    addAppPushButton(saveViewPtButton);            538    addAppPushButton(saveViewPtButton);
567                                                   539 
568    nextViewPtButton = new QPushButton;            540    nextViewPtButton = new QPushButton;
569    nextViewPtButton->setIconSize(QSize(24,24))    541    nextViewPtButton->setIconSize(QSize(24,24));
570    QCommonStyle style;                            542    QCommonStyle style;
571    nextViewPtButton->setIcon(style.standardIco    543    nextViewPtButton->setIcon(style.standardIcon(QStyle::SP_ArrowRight));
572    nextViewPtButton->setToolTip("Next bookmark    544    nextViewPtButton->setToolTip("Next bookmark");
573    connect(nextViewPtButton, SIGNAL(clicked())    545    connect(nextViewPtButton, SIGNAL(clicked()), this,
574            SLOT(NextViewPtCB()));                 546            SLOT(NextViewPtCB()));
575    addAppPushButton(nextViewPtButton);            547    addAppPushButton(nextViewPtButton);
576                                                   548 
577    prevViewPtButton = new QPushButton;            549    prevViewPtButton = new QPushButton;
578    prevViewPtButton->setIconSize(QSize(24,24))    550    prevViewPtButton->setIconSize(QSize(24,24));
579    prevViewPtButton->setIcon(style.standardIco    551    prevViewPtButton->setIcon(style.standardIcon(QStyle::SP_ArrowLeft));
580    prevViewPtButton->setToolTip("Previous book    552    prevViewPtButton->setToolTip("Previous bookmark");
581    connect(prevViewPtButton, SIGNAL(clicked())    553    connect(prevViewPtButton, SIGNAL(clicked()), this,
582            SLOT(PrevViewPtCB()));                 554            SLOT(PrevViewPtCB()));
583    addAppPushButton(prevViewPtButton);            555    addAppPushButton(prevViewPtButton);
584                                                   556 
585    abbrOutputButton = new QPushButton;            557    abbrOutputButton = new QPushButton;
586    abbrOutputButton->setCheckable(true);          558    abbrOutputButton->setCheckable(true);
587    abbrOutputButton->setIconSize(QSize(24,24))    559    abbrOutputButton->setIconSize(QSize(24,24));
588    abbrOutputButton->setIcon(QPixmap((const ch    560    abbrOutputButton->setIcon(QPixmap((const char **)pickext_xpm));
589    abbrOutputButton->setToolTip("Extended pick    561    abbrOutputButton->setToolTip("Extended picking & readout");
590    connect(abbrOutputButton, SIGNAL(toggled(bo    562    connect(abbrOutputButton, SIGNAL(toggled(bool)), this,
591            SLOT(AbbrOutputCB(bool)));             563            SLOT(AbbrOutputCB(bool)));
592    addAppPushButton(abbrOutputButton);            564    addAppPushButton(abbrOutputButton);
593                                                   565 
594    pickRefPathButton = new QPushButton;           566    pickRefPathButton = new QPushButton;
595    pickRefPathButton->setIconSize(QSize(24,24)    567    pickRefPathButton->setIconSize(QSize(24,24));
596    pickRefPathButton->setIcon(QPixmap((const c    568    pickRefPathButton->setIcon(QPixmap((const char **)pickref_xpm));
597    pickRefPathButton->setToolTip("Pick ref tra    569    pickRefPathButton->setToolTip("Pick ref trajectory");
598    connect(pickRefPathButton, SIGNAL(clicked()    570    connect(pickRefPathButton, SIGNAL(clicked()), this,
599            SLOT(PickRefPathCB()));                571            SLOT(PickRefPathCB()));
600    addAppPushButton(pickRefPathButton);           572    addAppPushButton(pickRefPathButton);
601                                                   573 
602    switchWireFrameButton = new QPushButton;       574    switchWireFrameButton = new QPushButton;
603    switchWireFrameButton->setCheckable(true);     575    switchWireFrameButton->setCheckable(true);
604    switchWireFrameButton->setIconSize(QSize(24    576    switchWireFrameButton->setIconSize(QSize(24,24));
605    switchWireFrameButton->setIcon(QPixmap((con    577    switchWireFrameButton->setIcon(QPixmap((const char **)wireframe_xpm));
606    switchWireFrameButton->setToolTip("Switch w    578    switchWireFrameButton->setToolTip("Switch wireframe/solid");
607    connect(switchWireFrameButton, SIGNAL(toggl    579    connect(switchWireFrameButton, SIGNAL(toggled(bool)), this,
608            SLOT(SwitchWireFrameCB(bool)));        580            SLOT(SwitchWireFrameCB(bool)));
609    addAppPushButton(switchWireFrameButton);       581    addAppPushButton(switchWireFrameButton);
610                                                   582 
611    switchAxesButton = new QPushButton;            583    switchAxesButton = new QPushButton;
612    switchAxesButton->setCheckable(true);          584    switchAxesButton->setCheckable(true);
613    switchAxesButton->setText(QString("A"));       585    switchAxesButton->setText(QString("A"));
614    switchAxesButton->setToolTip("Axes on/off")    586    switchAxesButton->setToolTip("Axes on/off");
615    connect(switchAxesButton, SIGNAL(toggled(bo    587    connect(switchAxesButton, SIGNAL(toggled(bool)), this,
616            SLOT(SwitchAxesCB(bool)));             588            SLOT(SwitchAxesCB(bool)));
617    addAppPushButton(switchAxesButton);            589    addAppPushButton(switchAxesButton);
618                                                   590 
619    detachButton = new QPushButton;                591    detachButton = new QPushButton;
620    detachButton->setIconSize(QSize(24,24));       592    detachButton->setIconSize(QSize(24,24));
621    detachButton->setIcon(style.standardIcon(QS    593    detachButton->setIcon(style.standardIcon(QStyle::SP_CommandLink));
622    detachButton->setToolTip("Detach viewer win    594    detachButton->setToolTip("Detach viewer window");
623    connect(detachButton, SIGNAL(clicked()), th    595    connect(detachButton, SIGNAL(clicked()), this,
624            SLOT(DetachCB()));                     596            SLOT(DetachCB()));
625    // Used for UIQt only so check and add late    597    // Used for UIQt only so check and add later
626    //   addAppPushButton(detachButton);           598    //   addAppPushButton(detachButton);
627                                                   599 
628    // HELP WINDOW                                 600    // HELP WINDOW
629                                                   601 
630    helpmsgbox = new QMessageBox(getParentWidge    602    helpmsgbox = new QMessageBox(getParentWidget());
631    helpmsgbox->setWindowTitle("OIQt Controls")    603    helpmsgbox->setWindowTitle("OIQt Controls");
632    helpmsgbox->setFont(*font);                    604    helpmsgbox->setFont(*font);
633    QString messagetxt =                           605    QString messagetxt =
634 "\nVIEWING mode (Hand cursor):\n\n\               606 "\nVIEWING mode (Hand cursor):\n\n\
635    Left-button + pointer move:  rotate\n\         607    Left-button + pointer move:  rotate\n\
636    Shift+Left-button + pointer move:  pan\n\      608    Shift+Left-button + pointer move:  pan\n\
637    Middle-button + pointer move:  pan\n\          609    Middle-button + pointer move:  pan\n\
638    Ctrl+Shift+Left-button + pointer move:  zoo    610    Ctrl+Shift+Left-button + pointer move:  zoom\n\
639    Mouse wheel:  zoom\n\                          611    Mouse wheel:  zoom\n\
640    Right-button:  popup menu\n\n\                 612    Right-button:  popup menu\n\n\
641 PICKING mode (Arrow cursor):\n\n\                 613 PICKING mode (Arrow cursor):\n\n\
642    Click on a volume:  geometry readout\n\        614    Click on a volume:  geometry readout\n\
643    Click on a trajectory:  particle & trajecto    615    Click on a trajectory:  particle & trajectory readout\n\
644    Ctrl + click on a volume:  see daughters.\n    616    Ctrl + click on a volume:  see daughters.\n\
645    Shift + click on a volume:  see mother.\n\n    617    Shift + click on a volume:  see mother.\n\n\
646 EXTENDED PICKING mode (Arrow+ viewer button):\    618 EXTENDED PICKING mode (Arrow+ viewer button):\n\n\
647    Hover the mouse over a volume or trajectory    619    Hover the mouse over a volume or trajectory for\n\
648    overlayed readout.\n\n\                        620    overlayed readout.\n\n\
649 ELEMENT NAVIGATION (requires Reference Path):\    621 ELEMENT NAVIGATION (requires Reference Path):\n\n\
650    Click on element in list:  centers view on     622    Click on element in list:  centers view on element\n\
651    Arrow keys:  rotate in 90 degree steps arou    623    Arrow keys:  rotate in 90 degree steps around element  \n\
652    Shift + Right Arrow:  move to next element\    624    Shift + Right Arrow:  move to next element\n\
653    Shift + Left Arrow:  move to previous eleme    625    Shift + Left Arrow:  move to previous element\n\n\
654 FLY mode (requires Reference Path):\n\n\          626 FLY mode (requires Reference Path):\n\n\
655    Page Up:  Increase speed\n\                    627    Page Up:  Increase speed\n\
656    Page Down:  Decrease speed (& reverse if wa    628    Page Down:  Decrease speed (& reverse if wanted)\n\
657    Up Arrow:  raise camera above path\n\          629    Up Arrow:  raise camera above path\n\
658    Down Arror:  lower camera below path\n\        630    Down Arror:  lower camera below path\n\
659    Escape:  Exit fly mode";                       631    Escape:  Exit fly mode";
660    helpmsgbox->setText(messagetxt);               632    helpmsgbox->setText(messagetxt);
661    helpmsgbox->setModal(false);                   633    helpmsgbox->setModal(false);
662    //   helpmsgbox->setWindowModality(Qt::NonM    634    //   helpmsgbox->setWindowModality(Qt::NonModal);
663                                                   635 
664    // AUXILIARY LISTS WINDOW                      636    // AUXILIARY LISTS WINDOW
665                                                   637 
666    // Bypass the namespace in order to make a     638    // Bypass the namespace in order to make a persistent object
667    AuxWindowDialog = new Ui_Dialog;               639    AuxWindowDialog = new Ui_Dialog;
668    AuxWindow = new QDialog(parent);               640    AuxWindow = new QDialog(parent);
669    AuxWindowDialog->setupUi(AuxWindow);           641    AuxWindowDialog->setupUi(AuxWindow);
670                                                   642 
671    // SIGNALS                                     643    // SIGNALS
672    connect(AuxWindowDialog->listWidget, SIGNAL    644    connect(AuxWindowDialog->listWidget, SIGNAL(itemClicked(QListWidgetItem*)),
673            this, SLOT(LoadBookmarkCB(QListWidg    645            this, SLOT(LoadBookmarkCB(QListWidgetItem*)));
674    connect(AuxWindowDialog->listWidget1, SIGNA    646    connect(AuxWindowDialog->listWidget1, SIGNAL(itemClicked(QListWidgetItem*)),
675            this, SLOT(LookAtSceneElementCB(QLi    647            this, SLOT(LookAtSceneElementCB(QListWidgetItem*)));
676    connect(AuxWindowDialog->pushButton_2, SIGN    648    connect(AuxWindowDialog->pushButton_2, SIGNAL(clicked()),
677            this, SLOT(DeleteBookmarkCB()));       649            this, SLOT(DeleteBookmarkCB()));
678    connect(AuxWindowDialog->pushButton_3, SIGN    650    connect(AuxWindowDialog->pushButton_3, SIGNAL(clicked()),
679            this, SLOT(RenameBookmarkCB()));       651            this, SLOT(RenameBookmarkCB()));
680    connect(AuxWindowDialog->pushButton, SIGNAL    652    connect(AuxWindowDialog->pushButton, SIGNAL(clicked()),
681            this, SLOT(SortBookmarksCB()));        653            this, SLOT(SortBookmarksCB()));
682                                                   654    
683    // FWJ Better to do this after viewer windo    655    // FWJ Better to do this after viewer window is realized
684    //   AuxWindow->show();                        656    //   AuxWindow->show();
685    //   AuxWindow->raise();                       657    //   AuxWindow->raise();
686    //   AuxWindow->activateWindow();              658    //   AuxWindow->activateWindow();
687 }                                                 659 }
688                                                   660 
689                                                   661 
690 #if QT_VERSION < 0x060000                      << 
691 // Called right after buttons and widgets get     662 // Called right after buttons and widgets get realized.
692 // It sets the viewpoint last accessed.           663 // It sets the viewpoint last accessed.
693 void G4OpenInventorQtExaminerViewer::afterReal    664 void G4OpenInventorQtExaminerViewer::afterRealizeHook()
694 {                                                 665 {
695    SoQtExaminerViewer::afterRealizeHook();        666    SoQtExaminerViewer::afterRealizeHook();
696 #else                                          << 667 
697 void G4OpenInventorQtExaminerViewer::setupScen << 
698 {                                              << 
699 #endif                                         << 
700    // Default height is used when selecting an    668    // Default height is used when selecting and viewing scene elements
701    // FWJ Added defaultHeight for Ortho camera    669    // FWJ Added defaultHeight for Ortho camera
702    SoCamera *cam = getCamera();                   670    SoCamera *cam = getCamera();
703    if (cam) {                                     671    if (cam) {
704       if (cam->isOfType(SoPerspectiveCamera::g    672       if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
705          defaultHeightAngle =                     673          defaultHeightAngle =
706             ((SoPerspectiveCamera *) cam)->hei    674             ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
707          toggleCameraType();                      675          toggleCameraType();
708          defaultHeight =                          676          defaultHeight =
709             ((SoOrthographicCamera *) cam)->he    677             ((SoOrthographicCamera *) cam)->height.getValue();
710          toggleCameraType();                      678          toggleCameraType();
711       } else {                                    679       } else {
712          defaultHeight =                          680          defaultHeight =
713             ((SoOrthographicCamera *) cam)->he    681             ((SoOrthographicCamera *) cam)->height.getValue();
714          toggleCameraType();                      682          toggleCameraType();
715          cam = getCamera();                       683          cam = getCamera();
716          if (cam->isOfType(SoPerspectiveCamera    684          if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
717             defaultHeightAngle =                  685             defaultHeightAngle =
718                ((SoPerspectiveCamera *) cam)->    686                ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
719          toggleCameraType();                      687          toggleCameraType();
720       }                                           688       }
721    }                                              689    }
722                                                   690 
723    // Open the default bookmark file              691    // Open the default bookmark file
724    fileIn.open(fileName.c_str());                 692    fileIn.open(fileName.c_str());
725    if (!fileIn.fail()) {                          693    if (!fileIn.fail()) {
726       if (!loadViewPts()) {                       694       if (!loadViewPts()) {
727          QMessageBox msgbox;                      695          QMessageBox msgbox;
728          msgbox.setFont(*font);                   696          msgbox.setFont(*font);
729          QString messagetxt = "Error reading b    697          QString messagetxt = "Error reading bookmark file ";
730          messagetxt.append(QString(fileName.c_    698          messagetxt.append(QString(fileName.c_str()));
731          msgbox.setText(messagetxt);              699          msgbox.setText(messagetxt);
732          msgbox.exec();                           700          msgbox.exec();
733       } else {                                    701       } else {
734          // Opens a file without erasing it       702          // Opens a file without erasing it
735          fileOut.open(fileName.c_str(), std::i    703          fileOut.open(fileName.c_str(), std::ios::in);
736          fileOut.seekp(0, std::ios::end); // F    704          fileOut.seekp(0, std::ios::end); // For appending new data to the end
737          // FWJ DEBUG                             705          // FWJ DEBUG
738          // G4cout << "afterRealizeHook: opene    706          // G4cout << "afterRealizeHook: opened EXISTING bookmark file"
739          //        << G4endl;                     707          //        << G4endl;
740          if (viewPtList.size()) {                 708          if (viewPtList.size()) {
741             // FWJ disabled auto-selection of     709             // FWJ disabled auto-selection of first viewpoint.
742             // Initial view should be user-con    710             // Initial view should be user-controllable & not forced
743             //    setViewPt();                    711             //    setViewPt();
744             addViewPoints();                      712             addViewPoints();
745          }                                        713          }
746       }                                           714       }
747       fileIn.close();                             715       fileIn.close();
748    } else {                                       716    } else {
749       // Creates a new default bookmark file      717       // Creates a new default bookmark file
750       fileOut.open(fileName.c_str());             718       fileOut.open(fileName.c_str());
751       // FWJ DEBUG                                719       // FWJ DEBUG
752       // G4cout << "afterRealizeHook: Opened a    720       // G4cout << "afterRealizeHook: Opened a NEW bookmark file" << G4endl;
753    }                                              721    }
754                                                   722 
755    fileIn.clear();                                723    fileIn.clear();
756                                                   724 
757    SoSeparator* root = (SoSeparator*) (getScen    725    SoSeparator* root = (SoSeparator*) (getSceneManager()->getSceneGraph());
758    if (root == NULL)                              726    if (root == NULL)
759       SoDebugError::post("G4OpenInventorQtExam    727       SoDebugError::post("G4OpenInventorQtExaminerViewer::afterRealizeHook", "Root is null.");
760    else {                                         728    else {
761       root->addChild(myCam); // For position/o    729       root->addChild(myCam); // For position/orientation calculation during animation
762    }                                              730    }
763                                                   731 
764 #if 0x060000 <= QT_VERSION                     << 
765    if(root!=nullptr) {                         << 
766 #endif                                         << 
767    sceneChangeSensor = new SoNodeSensor;          732    sceneChangeSensor = new SoNodeSensor;
768    sceneChangeSensor->setFunction(sceneChangeC    733    sceneChangeSensor->setFunction(sceneChangeCB);
769    sceneChangeSensor->attach(root);               734    sceneChangeSensor->attach(root);
770    sceneChangeSensor->setData(this);              735    sceneChangeSensor->setData(this);
771                                                   736 
772    ///////////////////////////// MOUSEOVER & P    737    ///////////////////////////// MOUSEOVER & PICK /////////////////////
773                                                   738 
774    // Monitor mouseover events for displaying     739    // Monitor mouseover events for displaying the name of scene elements
775    // An SoEventCallback is needed instead of     740    // An SoEventCallback is needed instead of using the default processSoEvent
776    // because that last one does not provide u    741    // because that last one does not provide us with an SoPath to the object
777    // that was picked                             742    // that was picked
778    SoEventCallback *moCB = new SoEventCallback    743    SoEventCallback *moCB = new SoEventCallback;
779    moCB->addEventCallback(                        744    moCB->addEventCallback(
780                           SoLocation2Event::ge    745                           SoLocation2Event::getClassTypeId(),
781                           mouseoverCB, static_    746                           mouseoverCB, static_cast<void *>(this));
782    root->addChild(moCB);                          747    root->addChild(moCB);
783                                                   748 
784    // Override the default picking mechanism p    749    // Override the default picking mechanism present in G4OpenInventorViewer
785    // because we want abbreviated output when     750    // because we want abbreviated output when picking a trajectory
786    SoEventCallback *pickCB = new SoEventCallba    751    SoEventCallback *pickCB = new SoEventCallback;
787    pickCB->addEventCallback(                      752    pickCB->addEventCallback(
788                             SoMouseButtonEvent    753                             SoMouseButtonEvent::getClassTypeId(),
789                             pickingCB, static_    754                             pickingCB, static_cast<void *>(this));
790    root->addChild(pickCB);                        755    root->addChild(pickCB);
791 #if 0x060000 <= QT_VERSION                     << 
792    }                                           << 
793 #endif                                         << 
794                                                   756 
795    ///////////////////////////// MOUSEOVER & P    757    ///////////////////////////// MOUSEOVER & PICK /////////////////////
796                                                   758 
797 #if QT_VERSION < 0x060000                      << 
798    AuxWindow->show();                             759    AuxWindow->show();
799    AuxWindow->raise();                            760    AuxWindow->raise();
800    AuxWindow->activateWindow();                   761    AuxWindow->activateWindow();
801                                                   762 
802    auto UI = G4UImanager::GetUIpointer();         763    auto UI = G4UImanager::GetUIpointer();
803    uiQt = dynamic_cast<G4UIQt*>(UI->GetG4UIWin    764    uiQt = dynamic_cast<G4UIQt*>(UI->GetG4UIWindow());
804    // This explicitly sets the TabWidget as pa    765    // This explicitly sets the TabWidget as parent before addTab():
805    if (uiQt) {                                    766    if (uiQt) {
806       viewerParent = getParentWidget();           767       viewerParent = getParentWidget();
807       viewerParent2 = viewerParent->parentWidg    768       viewerParent2 = viewerParent->parentWidget();
808       uiQt->AddTabWidget(getParentWidget(), *f    769       uiQt->AddTabWidget(getParentWidget(), *fName);
809       uiQtTabIndex = uiQt->GetViewerTabWidget(    770       uiQtTabIndex = uiQt->GetViewerTabWidget()->currentIndex();
810       //      attached = TRUE;                    771       //      attached = TRUE;
811       addAppPushButton(detachButton);             772       addAppPushButton(detachButton);
812    }                                              773    }
813 #else                                          << 
814    //G.Barrand: map the AuxWindow "at need", i << 
815    //           Having one appearing for each  << 
816    //           Also, if "closing" the AuxWind << 
817    //           way to map it again. Moreover, << 
818    //           it inactivates the Apple menu  << 
819    //           AuxWindow per viewer, why not  << 
820    //           tab widget? It will go toward  << 
821 #endif                                         << 
822 }                                                 774 }
823                                                   775 
824 #if 0x060000 <= QT_VERSION                     << 
825 void G4OpenInventorQtExaminerViewer::addInTab( << 
826   auto UI = G4UImanager::GetUIpointer();       << 
827   uiQt = dynamic_cast<G4UIQt*>(UI->GetG4UIWind << 
828   if(uiQt) {                                   << 
829     uiQt->AddTabWidget(getParentWidget(),fName << 
830     addAppPushButton(detachButton);            << 
831   }                                            << 
832 }                                              << 
833 #endif                                         << 
834                                                   776 
835 // This method locates a named node in the sup    777 // This method locates a named node in the superimposed or original scene.
836 // FWJ RENAME THIS                                778 // FWJ RENAME THIS
837 SoNode*                                           779 SoNode*
838 G4OpenInventorQtExaminerViewer::getSuperimposi    780 G4OpenInventorQtExaminerViewer::getSuperimpositionNode(SoNode* root,
839                                                   781                                                        const char* name)
840 {                                                 782 {
841    if (!searcher)                                 783    if (!searcher)
842       searcher = new SoSearchAction;              784       searcher = new SoSearchAction;
843    searcher->reset();                             785    searcher->reset();
844    searcher->setName(SbName(name));               786    searcher->setName(SbName(name));
845    searcher->setInterest(SoSearchAction::FIRST    787    searcher->setInterest(SoSearchAction::FIRST);
846    searcher->setSearchingAll(TRUE);               788    searcher->setSearchingAll(TRUE);
847    searcher->apply(root);                         789    searcher->apply(root);
848    assert(searcher->getPath());                   790    assert(searcher->getPath());
849    return searcher->getPath()->getTail();         791    return searcher->getPath()->getTail();
850 }                                                 792 }
851                                                   793 
852                                                   794 
853 // FWJ don't know why userdata is called "clos    795 // FWJ don't know why userdata is called "closure"
854 // It contains the this pointer!                  796 // It contains the this pointer!
855 void G4OpenInventorQtExaminerViewer::superimpo    797 void G4OpenInventorQtExaminerViewer::superimpositionCB(void * closure,
856                                                   798                                                        SoAction * action)
857 {                                                 799 {
858    if (closure)                                   800    if (closure)
859       ((G4OpenInventorQtExaminerViewer*)closur    801       ((G4OpenInventorQtExaminerViewer*)closure)->superimpositionEvent(action);
860 }                                                 802 }
861                                                   803 
862                                                   804 
863 // Renders and positions speed indicator and l    805 // Renders and positions speed indicator and longitudinal
864 // distance/viewpoint name on the drawing canv    806 // distance/viewpoint name on the drawing canvas
865 void G4OpenInventorQtExaminerViewer::superimpo    807 void G4OpenInventorQtExaminerViewer::superimpositionEvent(SoAction * action)
866 {                                                 808 {
867                                                   809 
868    if (!action->isOfType(SoGLRenderAction::get    810    if (!action->isOfType(SoGLRenderAction::getClassTypeId()))
869       return;                                     811       return;
870    SbViewportRegion vpRegion =                    812    SbViewportRegion vpRegion =
871       ((SoGLRenderAction*)action)->getViewport    813       ((SoGLRenderAction*)action)->getViewportRegion();
872    SbVec2s viewportSize = vpRegion.getViewport    814    SbVec2s viewportSize = vpRegion.getViewportSizePixels();
873                                                   815    
874    // Aspect is WIDTH/HEIGHT                      816    // Aspect is WIDTH/HEIGHT
875    float aspect = float(viewportSize[0]) / flo    817    float aspect = float(viewportSize[0]) / float(viewportSize[1]);
876                                                   818 
877    // FWJ DEBUG                                   819    // FWJ DEBUG
878    //   G4cout << "SPEVENT X0 Y0 DX DY aspect:    820    //   G4cout << "SPEVENT X0 Y0 DX DY aspect: " << vpRegion.getViewportOrigin()[0] <<
879    //      " " << vpRegion.getViewportOrigin()    821    //      " " << vpRegion.getViewportOrigin()[1] <<
880    //      " " << viewportSize[0] <<              822    //      " " << viewportSize[0] <<
881    //      " " << viewportSize()[1] <<            823    //      " " << viewportSize()[1] <<
882    //      " " << aspect << G4endl;               824    //      " " << aspect << G4endl;
883                                                   825 
884    // Translation and scale factor for animati    826    // Translation and scale factor for animation speed indicator...
885                                                   827 
886    float factorx = 1.0f / float(viewportSize[1    828    float factorx = 1.0f / float(viewportSize[1]) * 220.0f;
887    float factory = factorx;                       829    float factory = factorx;
888                                                   830 
889    if (aspect > 1.0f) {                           831    if (aspect > 1.0f) {
890       stranslation->translation.setValue(SbVec    832       stranslation->translation.setValue(SbVec3f(0.0f, -0.4f, 0.0f));
891    } else {                                       833    } else {
892       stranslation->translation.setValue(SbVec    834       stranslation->translation.setValue(SbVec3f(0.0f, -0.4f / aspect, 0.0f));
893       factorx /= aspect;                          835       factorx /= aspect;
894       factory /= aspect;                          836       factory /= aspect;
895    }                                              837    }
896    if (viewportSize[0] > 500)                     838    if (viewportSize[0] > 500)
897       factorx *= 500.0f / 400.0f;                 839       factorx *= 500.0f / 400.0f;
898    else                                           840    else
899       factorx *= float(viewportSize[0]) / 400.    841       factorx *= float(viewportSize[0]) / 400.0f;
900                                                   842 
901    sscale->scaleFactor.setValue(SbVec3f(factor    843    sscale->scaleFactor.setValue(SbVec3f(factorx, factory, 1.0f));
902                                                   844 
903    // TEXT OVERLAY...                             845    // TEXT OVERLAY...
904                                                   846 
905    // FWJ Simplified and rewrote the following    847    // FWJ Simplified and rewrote the following section to ease problems
906    // with the overlayed text after a viewer w    848    // with the overlayed text after a viewer window resize.
907    // Result is now readable but needs further    849    // Result is now readable but needs further refinement of the scaling.
908                                                   850 
909    float xInfo, yInfo, xLogName, yLogName, xSo    851    float xInfo, yInfo, xLogName, yLogName, xSolid, ySolid,
910       xMaterial, yMaterial, xZPos, yZPos;         852       xMaterial, yMaterial, xZPos, yZPos;
911                                                   853 
912    // Base point for navigation distance or vi    854    // Base point for navigation distance or viewpoint name
913    // Origin is at center of render area.         855    // Origin is at center of render area.
914    xInfo = -.475;                                 856    xInfo = -.475;
915    yInfo = .475;                                  857    yInfo = .475;
916    // Menu bar height in same coordinates:        858    // Menu bar height in same coordinates:
917    float mbgap = 0.03;                            859    float mbgap = 0.03;
918    if (aspect > 1.) xInfo = xInfo*aspect;         860    if (aspect > 1.) xInfo = xInfo*aspect;
919    if (aspect < 1.) yInfo = yInfo/aspect;         861    if (aspect < 1.) yInfo = yInfo/aspect;
920    yInfo = yInfo - mbgap*aspect;                  862    yInfo = yInfo - mbgap*aspect;
921                                                   863 
922    // Following are relative to above base poi    864    // Following are relative to above base point
923    xLogName = 0.0;                                865    xLogName = 0.0;
924    yLogName = -.88 + mbgap*aspect;                866    yLogName = -.88 + mbgap*aspect;
925    xSolid = 0.0;                                  867    xSolid = 0.0;
926    ySolid = -.91 + mbgap*aspect;                  868    ySolid = -.91 + mbgap*aspect;
927    xMaterial = 0.0;                               869    xMaterial = 0.0;
928    yMaterial = -.94 + mbgap*aspect;               870    yMaterial = -.94 + mbgap*aspect;
929    xZPos = 0.0;                                   871    xZPos = 0.0;
930    yZPos = -.97 + mbgap*aspect;                   872    yZPos = -.97 + mbgap*aspect;
931                                                   873 
932    // Top line                                    874    // Top line
933    curInfoTrans->translation.setValue(SbVec3f(    875    curInfoTrans->translation.setValue(SbVec3f(xInfo, yInfo, 0.0));
934                                                   876 
935    // Bottom lines                                877    // Bottom lines
936    mouseOverTransLogName->translation.setValue    878    mouseOverTransLogName->translation.setValue(SbVec3f(xLogName, yLogName, 0.0));
937    mouseOverTransSolid->translation.setValue(S    879    mouseOverTransSolid->translation.setValue(SbVec3f(xSolid, ySolid, 0.0));
938    mouseOverTransMaterial->translation.setValu    880    mouseOverTransMaterial->translation.setValue(SbVec3f(xMaterial, yMaterial, 0.0));
939    mouseOverTransZPos->translation.setValue(Sb    881    mouseOverTransZPos->translation.setValue(SbVec3f(xZPos, yZPos, 0.0));
940                                                   882 
941    if (currentState == VIEWPOINT) { // Display    883    if (currentState == VIEWPOINT) { // Displaying viewpoint name
942       curInfoFont->size.setValue(15);             884       curInfoFont->size.setValue(15);
943       curInfoFont->name.setValue("defaultFont:    885       curInfoFont->name.setValue("defaultFont:Italic");
944 #if QT_VERSION < 0x060000                      << 
945       curInfoText->string.setValue(SbString(cu    886       curInfoText->string.setValue(SbString(curViewPtName));
946 #else                                          << 
947       curInfoText->string.setValue(SbString(cu << 
948 #endif                                         << 
949    }                                              887    }
950    else if(currentState == GENERAL) { // Displ    888    else if(currentState == GENERAL) { // Displaying longitudinal distance
951       curInfoFont->size.setValue(16);             889       curInfoFont->size.setValue(16);
952       curInfoFont->name.setValue("defaultFont:    890       curInfoFont->name.setValue("defaultFont:Bold");
953       curInfoText->string.setValue(SbString(""    891       curInfoText->string.setValue(SbString(""));
954    }                                              892    }
955    else {                                         893    else {
956       if (refParticleIdx < (int) refParticleTr    894       if (refParticleIdx < (int) refParticleTrajectory.size() - 1) {
957          curInfoFont->size.setValue(16);          895          curInfoFont->size.setValue(16);
958          curInfoFont->name.setValue("defaultFo    896          curInfoFont->name.setValue("defaultFont:Bold");
959          char zPos[20];                           897          char zPos[20];
960          // FWJ need a better format here         898          // FWJ need a better format here
961          snprintf(zPos, sizeof zPos, "%-7.2f [ << 899          sprintf(zPos, "%-7.2f [m]", refZPositions[refParticleIdx] / 1000);
                                                   >> 900          // sprintf(zPos, "%7.2f [m]", refZPositions[refParticleIdx] / 1000);
962          curInfoText->string.setValue(SbString    901          curInfoText->string.setValue(SbString(zPos));
963       }                                           902       }
964    }                                              903    }
965 }                                                 904 }
966                                                   905 
967                                                   906 
968 //  Loads view point data from a file into a v    907 //  Loads view point data from a file into a vector.
969                                                   908 
970 bool G4OpenInventorQtExaminerViewer::loadViewP    909 bool G4OpenInventorQtExaminerViewer::loadViewPts() 
971 {                                                 910 {
972    bool error = false;                            911    bool error = false;
973    viewPtData tmp;                                912    viewPtData tmp;
974    std::string token;                             913    std::string token;
975    SbVec3f axis;                                  914    SbVec3f axis;
976    SbRotation orient;                             915    SbRotation orient;
977    float x{0.0}, y{0.0}, z{0.0}, angle{0.0};   << 916    float x, y, z, angle;
978                                                   917 
979    // Gets the last view point accessed, store    918    // Gets the last view point accessed, stored in the first line of the data file.
980    fileIn >> token;                               919    fileIn >> token;
981    parseString<int>(viewPtIdx, token, error);     920    parseString<int>(viewPtIdx, token, error);
982    getline(fileIn, token); // Remove "\n"         921    getline(fileIn, token); // Remove "\n"
983    // Converts data from string type into nece    922    // Converts data from string type into necessary types
984    while (getline(fileIn, token)) {               923    while (getline(fileIn, token)) {
985                                                   924 
986       std::size_t end = token.find_last_not_of << 925       int end = token.find_last_not_of(' '); // Remove padded spaces
987       token = token.substr(0, end + 1);           926       token = token.substr(0, end + 1);
988                                                   927 
989 #if QT_VERSION < 0x060000                      << 
990       char *vpName = new char[token.size() + 1    928       char *vpName = new char[token.size() + 1];
991       strcpy(vpName, token.c_str());              929       strcpy(vpName, token.c_str());
992       tmp.viewPtName = vpName;                    930       tmp.viewPtName = vpName;
993 #else                                          << 
994       tmp.viewPtName = token;                  << 
995 #endif                                         << 
996       fileIn >> token;                            931       fileIn >> token;
997                                                   932 
998       parseString<float>(x, token, error);        933       parseString<float>(x, token, error);
999       fileIn >> token;                            934       fileIn >> token;
1000       parseString<float>(y, token, error);       935       parseString<float>(y, token, error);
1001       fileIn >> token;                           936       fileIn >> token;
1002       parseString<float>(z, token, error);       937       parseString<float>(z, token, error);
1003       fileIn >> token;                           938       fileIn >> token;
1004       tmp.position = axis.setValue(x, y, z);     939       tmp.position = axis.setValue(x, y, z);
1005                                                  940 
1006       parseString<float>(x, token, error);       941       parseString<float>(x, token, error);
1007       fileIn >> token;                           942       fileIn >> token;
1008       parseString<float>(y, token, error);       943       parseString<float>(y, token, error);
1009       fileIn >> token;                           944       fileIn >> token;
1010       parseString<float>(z, token, error);       945       parseString<float>(z, token, error);
1011       fileIn >> token;                           946       fileIn >> token;
1012       parseString<float>(angle, token, error)    947       parseString<float>(angle, token, error);
1013       fileIn >> token;                           948       fileIn >> token;
1014       orient.setValue(axis.setValue(x, y, z),    949       orient.setValue(axis.setValue(x, y, z), angle);
1015       tmp.orientation = orient.getValue();       950       tmp.orientation = orient.getValue();
1016                                                  951 
1017       int camType{0};                         << 952       int camType;
1018       parseString<int>(camType, token, error)    953       parseString<int>(camType, token, error);
1019       fileIn >> token;                           954       fileIn >> token;
1020       tmp.camType = (CameraType) camType;        955       tmp.camType = (CameraType) camType;
1021                                                  956 
1022       parseString<float>(tmp.height, token, e    957       parseString<float>(tmp.height, token, error);
1023       fileIn >> token;                           958       fileIn >> token;
1024       parseString<float>(tmp.focalDistance, t    959       parseString<float>(tmp.focalDistance, token, error);
1025       fileIn >> token;                           960       fileIn >> token;
1026       parseString<float>(tmp.nearDistance, to    961       parseString<float>(tmp.nearDistance, token, error);
1027       fileIn >> token;                           962       fileIn >> token;
1028       parseString<float>(tmp.farDistance, tok    963       parseString<float>(tmp.farDistance, token, error);
1029       fileIn >> token;                           964       fileIn >> token;
1030       parseString<int>(tmp.viewportMapping, t    965       parseString<int>(tmp.viewportMapping, token, error);
1031       fileIn >> token;                           966       fileIn >> token;
1032       parseString<float>(tmp.aspectRatio, tok    967       parseString<float>(tmp.aspectRatio, token, error);
1033                                                  968 
1034       getline(fileIn, token); // To remove "\    969       getline(fileIn, token); // To remove "\n" characters
1035       getline(fileIn, token);                    970       getline(fileIn, token);
1036                                                  971 
1037       if (error) {                               972       if (error) {
1038 #if QT_VERSION < 0x060000                     << 
1039          viewPtIdx = 0;                          973          viewPtIdx = 0;
1040 #else                                         << 
1041          viewPtIdx = -1;                      << 
1042 #endif                                        << 
1043          viewPtList.clear();                     974          viewPtList.clear();
1044          return false;                           975          return false;
1045       }                                          976       }
1046       viewPtList.push_back(tmp);                 977       viewPtList.push_back(tmp);
1047    }                                             978    }
1048                                                  979 
1049    return true;                                  980    return true;
1050 }                                                981 }
1051                                                  982 
1052                                                  983 
1053 // Rotates camera 90 degrees around a scene e    984 // Rotates camera 90 degrees around a scene element.
1054 // Rotation is animated for smoothness.          985 // Rotation is animated for smoothness.
1055 void G4OpenInventorQtExaminerViewer::rotateCa    986 void G4OpenInventorQtExaminerViewer::rotateCamera()
1056 {                                                987 {
1057    SoCamera *cam = getCamera();                  988    SoCamera *cam = getCamera();
1058                                                  989 
1059    SbRotation rot(rotAxis, M_PI / (2 * ROT_CN    990    SbRotation rot(rotAxis, M_PI / (2 * ROT_CNT));
1060    rot.multVec(camDir, camDir);                  991    rot.multVec(camDir, camDir);
1061    rot.multVec(camUpVec, camUpVec);              992    rot.multVec(camUpVec, camUpVec);
1062                                                  993 
1063    SbVec3f camPosNew = prevPt - (camDir*dista    994    SbVec3f camPosNew = prevPt - (camDir*distance);
1064    cam->position = camPosNew;                    995    cam->position = camPosNew;
1065    cam->pointAt(prevPt, camUpVec);               996    cam->pointAt(prevPt, camUpVec);
1066    cam->focalDistance = (prevPt - camPosNew).    997    cam->focalDistance = (prevPt - camPosNew).length();
1067                                                  998 
1068    rotCnt--;                                     999    rotCnt--;
1069                                                  1000 
1070    if (animateSensorRotation->isScheduled())     1001    if (animateSensorRotation->isScheduled()) {
1071       animateSensorRotation->unschedule();       1002       animateSensorRotation->unschedule();
1072    }                                             1003    }
1073                                                  1004 
1074    animateSensorRotation->setBaseTime(SbTime:    1005    animateSensorRotation->setBaseTime(SbTime::getTimeOfDay());
1075    animateSensorRotation->setInterval(SbTime(    1006    animateSensorRotation->setInterval(SbTime(0.02));
1076    animateSensorRotation->schedule();            1007    animateSensorRotation->schedule();
1077                                                  1008 
1078 }                                                1009 }
1079                                                  1010 
1080                                                  1011 
1081 // Slides camera along the beamline.             1012 // Slides camera along the beamline.
1082 void G4OpenInventorQtExaminerViewer::moveCame    1013 void G4OpenInventorQtExaminerViewer::moveCamera(float dist, bool lookdown)
1083 {                                                1014 {
1084                                                  1015 
1085    SoCamera *cam = getCamera();                  1016    SoCamera *cam = getCamera();
1086    SbVec3f p1, p2;   // The particle moves fr    1017    SbVec3f p1, p2;   // The particle moves from p1 to p2
1087    SbVec3f particleDir;  // Direction vector     1018    SbVec3f particleDir;  // Direction vector from p1 to p2
1088    SbVec3f camPosNew{0.0f, 0.0f, 0.0f};  // N << 1019    SbVec3f camPosNew;  // New position of the camera
1089                                                  1020 
1090    if(refParticleTrajectory.size() == 0) {       1021    if(refParticleTrajectory.size() == 0) {
1091       //refParticleTrajectory hasn't been set    1022       //refParticleTrajectory hasn't been set yet
1092       if(dist)                                   1023       if(dist)
1093          distance = dist;                        1024          distance = dist;
1094       else                                       1025       else
1095          distance = (cam->position.getValue()    1026          distance = (cam->position.getValue() - center).length();
1096                                                  1027 
1097       cam->position.setValue(center + offsetF    1028       cam->position.setValue(center + offsetFromCenter*distance);
1098       cam->focalDistance = (cam->position.get    1029       cam->focalDistance = (cam->position.getValue() - center).length();
1099       cam->pointAt(center, upVector);            1030       cam->pointAt(center, upVector);
1100    }                                             1031    }
1101    else {                                        1032    else {
1102                                                  1033 
1103       // If we move forward past the last tra    1034       // If we move forward past the last trajectory point,
1104       // go back to the beginning                1035       // go back to the beginning
1105       if (refParticleIdx >= (int) refParticle    1036       if (refParticleIdx >= (int) refParticleTrajectory.size() - 1) {
1106          prevPt = refParticleTrajectory[refPa    1037          prevPt = refParticleTrajectory[refParticleIdx - step];
1107          dist = (prevPt - cam->position.getVa    1038          dist = (prevPt - cam->position.getValue()).length();
1108          refParticleIdx = 0;                     1039          refParticleIdx = 0;
1109       }                                          1040       }
1110       // If we move backward past the beginni    1041       // If we move backward past the beginning,
1111       // go to the last trajectory point         1042       // go to the last trajectory point
1112       if (refParticleIdx < 0) {                  1043       if (refParticleIdx < 0) {
1113          prevPt = refParticleTrajectory[refPa    1044          prevPt = refParticleTrajectory[refParticleIdx + step];
1114          dist = (prevPt - cam->position.getVa    1045          dist = (prevPt - cam->position.getValue()).length();
1115          refParticleIdx = (int) refParticleTr << 1046          refParticleIdx = refParticleTrajectory.size() - 2;
1116       }                                          1047       }
1117                                                  1048 
1118       // Set start and end points                1049       // Set start and end points
1119       p1 = refParticleTrajectory[refParticleI    1050       p1 = refParticleTrajectory[refParticleIdx];
1120       p2 = refParticleTrajectory[refParticleI    1051       p2 = refParticleTrajectory[refParticleIdx + step];
1121                                                  1052 
1122       // Get the direction from p1 to p2         1053       // Get the direction from p1 to p2
1123       particleDir = p2 - p1;                     1054       particleDir = p2 - p1;
1124       particleDir.normalize();                   1055       particleDir.normalize();
1125                                                  1056 
1126       if(prevParticleDir == SbVec3f(0,0,0)) {    1057       if(prevParticleDir == SbVec3f(0,0,0)) {
1127          // First time entering BEAMLINE mode    1058          // First time entering BEAMLINE mode, look at
1128          // the element from the front, with     1059          // the element from the front, with camera upright
1129          if(lookdown)                            1060          if(lookdown)
1130             camDir = SbVec3f(0,0,1);             1061             camDir = SbVec3f(0,0,1);
1131          else                                    1062          else
1132             camDir = SbVec3f(1,0,0);             1063             camDir = SbVec3f(1,0,0);
1133          camUpVec = SbVec3f(0,1,0);              1064          camUpVec = SbVec3f(0,1,0);
1134                                                  1065 
1135          // In case the start of the goes in     1066          // In case the start of the goes in a
1136          // direction other than +z, rotate t    1067          // direction other than +z, rotate the camera accordingly
1137          SbRotation rot(SbVec3f(0,0,1), parti    1068          SbRotation rot(SbVec3f(0,0,1), particleDir);
1138          rot.multVec(camDir, camDir);            1069          rot.multVec(camDir, camDir);
1139          rot.multVec(camUpVec, camUpVec);        1070          rot.multVec(camUpVec, camUpVec);
1140                                                  1071 
1141       }                                          1072       }
1142       else if(particleDir != prevParticleDir)    1073       else if(particleDir != prevParticleDir) {
1143          // The beamline has changed directio    1074          // The beamline has changed direction
1144                                                  1075 
1145          SbRotation rot(prevParticleDir, part    1076          SbRotation rot(prevParticleDir, particleDir);
1146          rot.multVec(camDir, camDir);            1077          rot.multVec(camDir, camDir);
1147          rot.multVec(camUpVec, camUpVec);        1078          rot.multVec(camUpVec, camUpVec);
1148                                                  1079 
1149       }                                          1080       }
1150                                                  1081 
1151       if (cam->isOfType(SoPerspectiveCamera::    1082       if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1152          if (!dist)                              1083          if (!dist)
1153             distance = (prevPt - cam->positio    1084             distance = (prevPt - cam->position.getValue()).length();
1154          else                                    1085          else
1155             distance = dist;                     1086             distance = dist;
1156       }                                          1087       }
1157                                                  1088 
1158       // FWJ distance not relevant -- use foc    1089       // FWJ distance not relevant -- use focalDistance
1159       // if (cam->isOfType(SoOrthographicCame    1090       // if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
1160       //    if (!dist)                           1091       //    if (!dist)
1161       //       distance = (prevPt - cam->posi    1092       //       distance = (prevPt - cam->position.getValue()).length();
1162       //    else                                 1093       //    else
1163       //       distance = dist;                  1094       //       distance = dist;
1164       // }                                       1095       // }
1165                                                  1096 
1166                                                  1097 
1167       float x,y,z;                               1098       float x,y,z;
1168       prevPt.getValue(x,y,z);                    1099       prevPt.getValue(x,y,z);
1169                                                  1100 
1170                                                  1101 
1171       if (cam->isOfType(SoPerspectiveCamera::    1102       if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1172          camPosNew = p2 - (camDir*distance);     1103          camPosNew = p2 - (camDir*distance);
1173       }                                          1104       }
1174       if (cam->isOfType(SoOrthographicCamera:    1105       if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
1175          // FWJ maintain focal distance          1106          // FWJ maintain focal distance
1176          camPosNew = p2 - (camDir*cam->focalD    1107          camPosNew = p2 - (camDir*cam->focalDistance.getValue());
1177          //         camPosNew = p2 - (camDir)    1108          //         camPosNew = p2 - (camDir);
1178       }                                          1109       }
1179                                                  1110 
1180       cam->position = camPosNew;                 1111       cam->position = camPosNew;
1181       cam->pointAt(p2, camUpVec);                1112       cam->pointAt(p2, camUpVec);
1182       cam->focalDistance = (p2 - camPosNew).l    1113       cam->focalDistance = (p2 - camPosNew).length();
1183                                                  1114 
1184       p2.getValue(x,y,z);                        1115       p2.getValue(x,y,z);
1185       camPosNew.getValue(x,y,z);                 1116       camPosNew.getValue(x,y,z);
1186                                                  1117 
1187       prevParticleDir = particleDir;             1118       prevParticleDir = particleDir;
1188       prevPt = p1; // For accurate distance c    1119       prevPt = p1; // For accurate distance calculation
1189                                                  1120 
1190    }                                             1121    }
1191                                                  1122 
1192 }                                                1123 }
1193                                                  1124 
1194                                                  1125 
1195 void G4OpenInventorQtExaminerViewer::pickingC    1126 void G4OpenInventorQtExaminerViewer::pickingCB(void *aThis, 
1196                                                  1127                                                SoEventCallback *eventCB)
1197 {                                                1128 {
1198    SoHandleEventAction* action = eventCB->get    1129    SoHandleEventAction* action = eventCB->getAction();
1199    const SoPickedPoint *pp = action->getPicke    1130    const SoPickedPoint *pp = action->getPickedPoint();
1200    G4OpenInventorQtExaminerViewer* This = (G4    1131    G4OpenInventorQtExaminerViewer* This = (G4OpenInventorQtExaminerViewer*)aThis;
1201                                                  1132 
1202    if(pp != NULL) {                              1133    if(pp != NULL) {
1203                                                  1134 
1204       SoPath* path = pp->getPath();              1135       SoPath* path = pp->getPath();
1205       SoNode* node = ((SoFullPath*)path)->get    1136       SoNode* node = ((SoFullPath*)path)->getTail();
1206                                                  1137 
1207       if(node->getTypeId() == SoLineSet::getC    1138       if(node->getTypeId() == SoLineSet::getClassTypeId()) {
1208                                                  1139 
1209          if(This->pickRefPathFlag) {             1140          if(This->pickRefPathFlag) {
1210             This->pickRefPathFlag = false;       1141             This->pickRefPathFlag = false;
1211             if(This->viewingBeforePickRef !=     1142             if(This->viewingBeforePickRef != This->isViewing())
1212                This->setViewing(This->viewing    1143                This->setViewing(This->viewingBeforePickRef);
1213             else                                 1144             else
1214                This->setComponentCursor(SoQtC    1145                This->setComponentCursor(SoQtCursor(SoQtCursor::DEFAULT));
1215                                                  1146 
1216             // The trajectory is a set of lin    1147             // The trajectory is a set of lines stored in a LineSet
1217             SoLineSet * trajectory = (SoLineS    1148             SoLineSet * trajectory = (SoLineSet *)node;
1218             // FWJ DEBUG                         1149             // FWJ DEBUG
1219             // G4cout << "FOUND trajectory Li    1150             // G4cout << "FOUND trajectory LineSet" << trajectory << G4endl;
1220                                                  1151 
1221        // The set of all trajectories is stor    1152        // The set of all trajectories is stored in a Seperator group node
1222        // one level above the LineSet that wa    1153        // one level above the LineSet that was picked. The nodes under that
1223        // seperator are as follows (in this o    1154        // seperator are as follows (in this order): Material, LightModel,
1224        // ResetTransform, MatrixTransform, Co    1155        // ResetTransform, MatrixTransform, Coordinate3, DrawStyle, LineSet
1225             SoSeparator * grpNode =              1156             SoSeparator * grpNode = 
1226                (SoSeparator*)(((SoFullPath*)p    1157                (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
1227                                                  1158 
1228    // The node that contains the coordinates     1159    // The node that contains the coordinates for the trajectory is a
1229    // Coordinate3 node which occurs before th    1160    // Coordinate3 node which occurs before the LineSet node.  We iterate
1230    // back through the nodes in the group unt    1161    // back through the nodes in the group until we find the Coordinate3 node
1231             int nodeIndex = grpNode->findChil    1162             int nodeIndex = grpNode->findChild(trajectory);
1232             SoNode * tmpNode;                    1163             SoNode * tmpNode;
1233             // FWJ needs initialization          1164             // FWJ needs initialization
1234             SoCoordinate3 * coords = 0;          1165             SoCoordinate3 * coords = 0;
1235             //            SoCoordinate3 * coo    1166             //            SoCoordinate3 * coords;
1236             // We allow only 100 iterations,     1167             // We allow only 100 iterations, in case the node isn't found
1237             // (should take only a few iterat    1168             // (should take only a few iterations)
1238             for(int i = 0; i < 100; ++i) {       1169             for(int i = 0; i < 100; ++i) {
1239                --nodeIndex;                      1170                --nodeIndex;
1240                                                  1171 
1241                tmpNode = grpNode->getChild(no    1172                tmpNode = grpNode->getChild(nodeIndex);
1242                if(tmpNode->getTypeId() == SoC    1173                if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()) {
1243                   //node found                   1174                   //node found
1244                   coords = (SoCoordinate3 *)t    1175                   coords = (SoCoordinate3 *)tmpNode;
1245                   break;                         1176                   break;
1246                }                                 1177                }
1247             }                                    1178             }
1248                                                  1179 
1249             if(coords == NULL) {                 1180             if(coords == NULL) {
1250                G4warn << "Could not find the  << 1181                G4cout << "Could not find the coordinates node"
1251                   " for the picked trajectory    1182                   " for the picked trajectory." << G4endl;
1252                G4warn << " Reference trajecto << 1183                G4cout << " Reference trajectory not set" << G4endl;
1253                return;                           1184                return;
1254             }                                    1185             }
1255             // FWJ DEBUG                         1186             // FWJ DEBUG
1256             // G4cout << "FOUND SoCoordinate3    1187             // G4cout << "FOUND SoCoordinate3 node " << coords << G4endl;
1257                                                  1188 
1258                                                  1189 
1259             if ((This->lshiftdown)  || (This-    1190             if ((This->lshiftdown)  || (This->rshiftdown))
1260                This->setReferencePath(traject    1191                This->setReferencePath(trajectory, coords, true);  //APPENDING
1261             else                                 1192             else
1262                This->setReferencePath(traject    1193                This->setReferencePath(trajectory, coords, false);
1263                                                  1194 
1264             return;                              1195             return;
1265                                                  1196 
1266          }                                       1197          }
1267          else if(This->abbrOutputFlag) {         1198          else if(This->abbrOutputFlag) {
1268                                                  1199 
1269             G4AttHolder* attHolder = dynamic_    1200             G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(node);
1270             if(attHolder && attHolder->GetAtt    1201             if(attHolder && attHolder->GetAttDefs().size()) {
1271                                                  1202 
1272                std::string strTrajPoint = "G4    1203                std::string strTrajPoint = "G4TrajectoryPoint:";
1273                std::ostringstream oss;           1204                std::ostringstream oss;
1274                for (std::size_t i = 0; i < at << 1205                for (size_t i = 0; i < attHolder->GetAttDefs().size(); ++i) {
1275                   G4cout << G4AttCheck(attHol    1206                   G4cout << G4AttCheck(attHolder->GetAttValues()[i],
1276                                        attHol    1207                                        attHolder->GetAttDefs()[i]);
1277                   oss << G4AttCheck(attHolder    1208                   oss << G4AttCheck(attHolder->GetAttValues()[i],
1278                                     attHolder    1209                                     attHolder->GetAttDefs()[i]);
1279                   if(oss.str().find(strTrajPo    1210                   if(oss.str().find(strTrajPoint) != std::string::npos) {
1280                                                  1211 
1281            // Last attribute displayed was a     1212            // Last attribute displayed was a trajectory point.  Since we
1282            // want abbreviated output, displa    1213            // want abbreviated output, display the last one and exit
1283            // (unless we're already at the la    1214            // (unless we're already at the last (and only) trajectory point)
1284                      if(i != attHolder->GetAt    1215                      if(i != attHolder->GetAttDefs().size()-1) {
1285                         G4cout << G4AttCheck(    1216                         G4cout << G4AttCheck(
1286               attHolder->GetAttValues()[attHo    1217               attHolder->GetAttValues()[attHolder->GetAttDefs().size()-1],
1287               attHolder->GetAttDefs()[attHold    1218               attHolder->GetAttDefs()[attHolder->GetAttDefs().size()-1]);
1288                      }                           1219                      }
1289                      break;                      1220                      break;
1290                   }                              1221                   }
1291                }                                 1222                }
1292             } else {                             1223             } else {
1293                G4String name((char*)node->get    1224                G4String name((char*)node->getName().getString());
1294                G4String cls((char*)node->getT    1225                G4String cls((char*)node->getTypeId().getName().getString());
1295                G4warn << "SoNode : " << node  << 1226                G4cout << "SoNode : " << node
1296                       << " SoType : " << cls     1227                       << " SoType : " << cls
1297                       << " name : " << name      1228                       << " name : " << name
1298                       << G4endl;                 1229                       << G4endl;
1299                G4warn << "No attributes attac << 1230                G4cout << "No attributes attached." << G4endl;
1300             }                                    1231             }
1301                                                  1232 
1302             return;                              1233             return;
1303          }                                       1234          }
1304          else{                                   1235          else{
1305             //Go to default behavior             1236             //Go to default behavior
1306          }                                       1237          }
1307       }                                          1238       }
1308       else {                                     1239       else {
1309          //Go to default behavior                1240          //Go to default behavior
1310       }                                          1241       }
1311                                                  1242 
1312       // Default behavior in G4OpenInventorVi    1243       // Default behavior in G4OpenInventorViewer::SelectionCB
1313       G4AttHolder* attHolder = dynamic_cast<G    1244       G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(node);
1314       if(attHolder && attHolder->GetAttDefs()    1245       if(attHolder && attHolder->GetAttDefs().size()) {
1315          for (std::size_t i = 0; i < attHolde << 1246          for (size_t i = 0; i < attHolder->GetAttDefs().size(); ++i) {
1316             G4cout << G4AttCheck(attHolder->G    1247             G4cout << G4AttCheck(attHolder->GetAttValues()[i],
1317                                  attHolder->G    1248                                  attHolder->GetAttDefs()[i]);
1318          }                                       1249          }
1319       } else {                                   1250       } else {
1320          G4String name((char*)node->getName()    1251          G4String name((char*)node->getName().getString());
1321          G4String cls((char*)node->getTypeId(    1252          G4String cls((char*)node->getTypeId().getName().getString());
1322          G4warn << "SoNode : " << node        << 1253          G4cout << "SoNode : " << node
1323                 << " SoType : " << cls           1254                 << " SoType : " << cls
1324                 << " name : " << name            1255                 << " name : " << name
1325                 << G4endl;                       1256                 << G4endl;
1326          G4warn << "No attributes attached."  << 1257          G4cout << "No attributes attached." << G4endl;
1327       }                                          1258       }
1328                                                  1259 
1329       //Suppress other event handlers            1260       //Suppress other event handlers
1330       eventCB->setHandled();                     1261       eventCB->setHandled();
1331    }                                             1262    }
1332 }                                                1263 }
1333                                                  1264 
1334                                                  1265 
1335 void G4OpenInventorQtExaminerViewer::mouseove    1266 void G4OpenInventorQtExaminerViewer::mouseoverCB(void *aThis, SoEventCallback *eventCB)
1336 {                                                1267 {
1337    SoHandleEventAction* action = eventCB->get    1268    SoHandleEventAction* action = eventCB->getAction();
1338    const SoPickedPoint* pp = action->getPicke    1269    const SoPickedPoint* pp = action->getPickedPoint();
1339    G4OpenInventorQtExaminerViewer* This = (G4    1270    G4OpenInventorQtExaminerViewer* This = (G4OpenInventorQtExaminerViewer*)aThis;
1340                                                  1271 
1341    if(!This->abbrOutputFlag)                     1272    if(!This->abbrOutputFlag)
1342       return;                                    1273       return;
1343                                                  1274 
1344    if(pp != NULL) {                              1275    if(pp != NULL) {
1345                                                  1276 
1346       const SbViewportRegion & viewportRegion    1277       const SbViewportRegion & viewportRegion = action->getViewportRegion();
1347                                                  1278 
1348       std::string sLogName;                      1279       std::string sLogName;
1349       float x,y,z;                               1280       float x,y,z;
1350       std::stringstream ssZPos;                  1281       std::stringstream ssZPos;
1351       std::stringstream ssSolids;                1282       std::stringstream ssSolids;
1352       std::stringstream ssMaterials;             1283       std::stringstream ssMaterials;
1353       SoPath * path = pp->getPath();             1284       SoPath * path = pp->getPath();
1354       SoNode* node = ((SoFullPath*)path)->get    1285       SoNode* node = ((SoFullPath*)path)->getTail();
1355                                                  1286 
1356       if(node->getTypeId() == Geant4_SoPolyhe    1287       if(node->getTypeId() == Geant4_SoPolyhedron::getClassTypeId()) {
1357                                                  1288 
1358          sLogName = "Logical Volume:  ";         1289          sLogName = "Logical Volume:  ";
1359          sLogName += ((Geant4_SoPolyhedron *)    1290          sLogName += ((Geant4_SoPolyhedron *)node)->getName().getString();
1360                                                  1291 
1361          SoGetBoundingBoxAction bAction(viewp    1292          SoGetBoundingBoxAction bAction(viewportRegion);
1362          bAction.apply((SoFullPath*)path);       1293          bAction.apply((SoFullPath*)path);
1363          SbBox3f bBox = bAction.getBoundingBo    1294          SbBox3f bBox = bAction.getBoundingBox();
1364          SbVec3f centr = bBox.getCenter();    << 1295          SbVec3f center = bBox.getCenter();
1365          centr.getValue(x,y,z);               << 1296          center.getValue(x,y,z);
1366          ssZPos << "Pos:  " << x << "  " << y    1297          ssZPos << "Pos:  " << x << "  " << y << "  " << z;
1367                                                  1298 
1368          G4AttHolder* attHolder = dynamic_cas    1299          G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(node);
1369          if(attHolder && attHolder->GetAttDef    1300          if(attHolder && attHolder->GetAttDefs().size()) {
1370                                                  1301 
1371             std::vector<const std::map<G4Stri    1302             std::vector<const std::map<G4String,G4AttDef>*> vecDefs =
1372                attHolder->GetAttDefs();          1303                attHolder->GetAttDefs();
1373             std::vector<const std::vector<G4A    1304             std::vector<const std::vector<G4AttValue>*> vecVals =
1374                attHolder->GetAttValues();        1305                attHolder->GetAttValues();
1375             for (std::size_t i = 0; i < vecDe << 1306             for (size_t i = 0; i < vecDefs.size(); ++i) {
1376                const std::vector<G4AttValue>     1307                const std::vector<G4AttValue> * vals = vecVals[i];
1377                                                  1308 
1378                std::vector<G4AttValue>::const    1309                std::vector<G4AttValue>::const_iterator iValue;
1379                                                  1310 
1380                for (iValue = vals->begin(); i    1311                for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1381                   const G4String& valueName =    1312                   const G4String& valueName = iValue->GetName();
1382                   const G4String& value = iVa    1313                   const G4String& value = iValue->GetValue();
1383                                                  1314 
1384                   if(valueName == "Solid") {     1315                   if(valueName == "Solid") {
1385                      if(ssSolids.str() == "")    1316                      if(ssSolids.str() == "")
1386                         ssSolids << "Solid Na    1317                         ssSolids << "Solid Name:  " << value;
1387                      else                        1318                      else
1388                         ssSolids << ", " << v    1319                         ssSolids << ", " << value;
1389                   }                              1320                   }
1390                                                  1321 
1391                   if(valueName == "Material")    1322                   if(valueName == "Material") {
1392                      if(ssMaterials.str() ==     1323                      if(ssMaterials.str() == "")
1393                         ssMaterials << "Mater    1324                         ssMaterials << "Material Name:  " << value;
1394                      else                        1325                      else
1395                         ssMaterials << ", " <    1326                         ssMaterials << ", " << value;
1396                   }                              1327                   }
1397                }                                 1328                }
1398             }                                    1329             }
1399          }                                       1330          }
1400       }                                          1331       }
1401       // FWJ Mouseover for trajectories          1332       // FWJ Mouseover for trajectories
1402       else if(node->getTypeId() == SoLineSet:    1333       else if(node->getTypeId() == SoLineSet::getClassTypeId()) {
1403          // G4cout << "Trajectory!!!!!!!!!!!!    1334          // G4cout << "Trajectory!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl;
1404          G4AttHolder* attHolder = dynamic_cas    1335          G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(node);
1405          if(attHolder && attHolder->GetAttDef    1336          if(attHolder && attHolder->GetAttDefs().size()) {
1406             std::string strTrajPoint = "G4Tra    1337             std::string strTrajPoint = "G4TrajectoryPoint:";
1407             std::ostringstream oss;              1338             std::ostringstream oss;
1408             G4String t1, t1Ch, t2, t3, t4;       1339             G4String t1, t1Ch, t2, t3, t4;
1409             for (std::size_t i = 0; i < attHo << 1340             for (size_t i = 0; i < attHolder->GetAttDefs().size(); ++i) {
1410                // G4cout << "Getting index "     1341                // G4cout << "Getting index " << i << " from attHolder" << G4endl;
1411                // No, returns a vector!          1342                // No, returns a vector!
1412                //   G4AttValue* attValue = at    1343                //   G4AttValue* attValue = attHolder->GetAttValues()[i];
1413                const std::vector<G4AttValue>*    1344                const std::vector<G4AttValue>* vals = attHolder->GetAttValues()[i];
1414                std::vector<G4AttValue>::const    1345                std::vector<G4AttValue>::const_iterator iValue;
1415                for (iValue = vals->begin(); i    1346                for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1416                   const G4String& valueName =    1347                   const G4String& valueName = iValue->GetName();
1417                   const G4String& value = iVa    1348                   const G4String& value = iValue->GetValue();
1418                   // G4cout << "  valueName =    1349                   // G4cout << "  valueName = " << valueName << G4endl;
1419                   // G4cout << "  value = " <    1350                   // G4cout << "  value = " << value << G4endl;
1420                   // LINE 1                      1351                   // LINE 1
1421                   if (valueName == "PN") t1 =    1352                   if (valueName == "PN") t1 = value;
1422                   if (valueName == "Ch") {       1353                   if (valueName == "Ch") {
1423                      if (atof(value.c_str())     1354                      if (atof(value.c_str()) > 0)
1424                         t1Ch = "    +";          1355                         t1Ch = "    +";
1425                      else                        1356                      else
1426                         t1Ch = "    ";           1357                         t1Ch = "    ";
1427                      t1Ch += value;              1358                      t1Ch += value;
1428                   }                              1359                   }
1429                   if (valueName == "PDG") {      1360                   if (valueName == "PDG") {
1430                      t1 += "    ";               1361                      t1 += "    ";
1431                      t1 += value;                1362                      t1 += value;
1432                      t1 += t1Ch;                 1363                      t1 += t1Ch;
1433                      This->mouseOverTextLogNa    1364                      This->mouseOverTextLogName->string.setValue(t1);
1434                   }                              1365                   }
1435                   //                  G4cout     1366                   //                  G4cout << "  t1 = " << t1 << G4endl;
1436                   // LINE 2                      1367                   // LINE 2
1437                   if (valueName == "EventID")    1368                   if (valueName == "EventID") t2 = "Evt " + value;
1438                   if (valueName == "ID") t2 +    1369                   if (valueName == "ID") t2 += "    Trk " + value;
1439                   if (valueName == "PID") {      1370                   if (valueName == "PID") {
1440                      t2 += "    Prt " + value    1371                      t2 += "    Prt " + value;
1441                      This->mouseOverTextSolid    1372                      This->mouseOverTextSolid->string.setValue(t2);
1442                   }                              1373                   }
1443                   // LINE 3                      1374                   // LINE 3
1444                   if (valueName == "IKE") t3     1375                   if (valueName == "IKE") t3 = "KE " + value;
1445                   if (valueName == "IMom") {     1376                   if (valueName == "IMom") {
1446                      // Remove units             1377                      // Remove units
1447                      std::size_t ipos = value << 1378                      unsigned ipos = value.rfind(" ");
1448                      G4String value1 = value;    1379                      G4String value1 = value;
1449                      value1.erase(ipos);         1380                      value1.erase(ipos);
1450                      t3 += "    P (" + value1    1381                      t3 += "    P (" + value1 + ")";
1451                   }                              1382                   }
1452                   if (valueName == "IMag") {     1383                   if (valueName == "IMag") {
1453                      t3 += " " + value + "/c"    1384                      t3 += " " + value + "/c";
1454                      //                     t    1385                      //                     t3 += " " + value;
1455                      This->mouseOverTextMater    1386                      This->mouseOverTextMaterial->string.setValue(t3);
1456                   }                              1387                   }
1457                   // LINE 4                      1388                   // LINE 4
1458                   if (valueName == "NTP") {      1389                   if (valueName == "NTP") {
1459                      std::ostringstream t4oss    1390                      std::ostringstream t4oss;
1460                      t4oss << "TrjPts " <<  v    1391                      t4oss << "TrjPts " <<  value;
1461                      t4oss << "    Pos " << p    1392                      t4oss << "    Pos " << pp->getPoint()[0] << " " << pp->getPoint()[1] <<
1462                         " " << pp->getPoint()    1393                         " " << pp->getPoint()[2];
1463                      This->mouseOverTextZPos-    1394                      This->mouseOverTextZPos->string.setValue(SbString(t4oss.str().c_str()));
1464                   }                              1395                   }
1465                }                                 1396                }
1466 //             G4cout << "  NOW CALLING G4Att    1397 //             G4cout << "  NOW CALLING G4AttCheck" << G4endl;
1467 //             G4cout << G4AttCheck(attHolder    1398 //             G4cout << G4AttCheck(attHolder->GetAttValues()[i],
1468 //                                     attHol    1399 //                                     attHolder->GetAttDefs()[i]);
1469 //             oss << G4AttCheck(attHolder->G    1400 //             oss << G4AttCheck(attHolder->GetAttValues()[i],
1470 //                                  attHolder    1401 //                                  attHolder->GetAttDefs()[i]);
1471 //             if(oss.str().find(strTrajPoint    1402 //             if(oss.str().find(strTrajPoint) != std::string::npos) {
1472 //                // Last attribute displayed    1403 //                // Last attribute displayed was a trajectory point.  Since we
1473 //                // want abbreviated output,    1404 //                // want abbreviated output, display the last one and exit
1474 //                // (unless we're already at    1405 //                // (unless we're already at the last (and only) trajectory point)
1475 //                if(i != attHolder->GetAttDe    1406 //                if(i != attHolder->GetAttDefs().size()-1) {
1476 //                   G4cout << G4AttCheck(       1407 //                   G4cout << G4AttCheck(
1477 //                      attHolder->GetAttValu    1408 //                      attHolder->GetAttValues()[attHolder->GetAttDefs().size()-1],
1478 //                      attHolder->GetAttDefs    1409 //                      attHolder->GetAttDefs()[attHolder->GetAttDefs().size()-1]);
1479 //                   }                           1410 //                   }
1480 //                   break;                      1411 //                   break;
1481 //                }                              1412 //                }
1482             }                                    1413             }
1483          }                                       1414          }
1484          This->setSuperimpositionEnabled(This    1415          This->setSuperimpositionEnabled(This->superimposition, TRUE);
1485          This->scheduleRedraw();                 1416          This->scheduleRedraw();
1486          eventCB->setHandled();                  1417          eventCB->setHandled();
1487          return;                                 1418          return;
1488       }                                          1419       }
1489                                                  1420 
1490       bool redraw = false;                       1421       bool redraw = false;
1491       if(std::string(This->mouseOverTextLogNa    1422       if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) != sLogName) {
1492          This->mouseOverTextLogName->string.s    1423          This->mouseOverTextLogName->string.setValue(SbString(sLogName.c_str()));
1493          redraw = true;                          1424          redraw = true;
1494       }                                          1425       }
1495       if(std::string(This->mouseOverTextSolid    1426       if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) != ssSolids.str()) {
1496          This->mouseOverTextSolid->string.set    1427          This->mouseOverTextSolid->string.setValue(SbString(ssSolids.str().c_str()));
1497          redraw = true;                          1428          redraw = true;
1498       }                                          1429       }
1499       if(std::string(This->mouseOverTextMater    1430       if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) != ssMaterials.str()) {
1500          This->mouseOverTextMaterial->string.    1431          This->mouseOverTextMaterial->string.setValue(SbString(ssMaterials.str().c_str()));
1501          redraw = true;                          1432          redraw = true;
1502       }                                          1433       }
1503       if(std::string(This->mouseOverTextZPos-    1434       if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) != ssZPos.str()) {
1504          This->mouseOverTextZPos->string.setV    1435          This->mouseOverTextZPos->string.setValue(SbString(ssZPos.str().c_str()));
1505          redraw = true;                          1436          redraw = true;
1506       }                                          1437       }
1507                                                  1438 
1508       if(redraw) {                               1439       if(redraw) {
1509          This->setSuperimpositionEnabled(This    1440          This->setSuperimpositionEnabled(This->superimposition, TRUE);
1510          This->scheduleRedraw();                 1441          This->scheduleRedraw();
1511       }                                          1442       }
1512                                                  1443 
1513       eventCB->setHandled();                     1444       eventCB->setHandled();
1514    }                                             1445    }
1515    else {                                        1446    else {
1516       if(std::string(This->mouseOverTextLogNa    1447       if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) != "") {
1517          This->mouseOverTextLogName->string.s    1448          This->mouseOverTextLogName->string.setValue(SbString(""));
1518          This->scheduleRedraw();                 1449          This->scheduleRedraw();
1519       }                                          1450       }
1520       if(std::string(This->mouseOverTextSolid    1451       if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) != "") {
1521          This->mouseOverTextSolid->string.set    1452          This->mouseOverTextSolid->string.setValue(SbString(""));
1522          This->scheduleRedraw();                 1453          This->scheduleRedraw();
1523       }                                          1454       }
1524       if(std::string(This->mouseOverTextMater    1455       if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) != "") {
1525          This->mouseOverTextMaterial->string.    1456          This->mouseOverTextMaterial->string.setValue(SbString(""));
1526          This->scheduleRedraw();                 1457          This->scheduleRedraw();
1527       }                                          1458       }
1528       if(std::string(This->mouseOverTextZPos-    1459       if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) != "") {
1529          This->mouseOverTextZPos->string.setV    1460          This->mouseOverTextZPos->string.setValue(SbString(""));
1530          This->scheduleRedraw();                 1461          This->scheduleRedraw();
1531       }                                          1462       }
1532    }                                             1463    }
1533 }                                                1464 }
1534                                                  1465 
1535                                                  1466 
1536 // Called by hitting PageUp during animation.    1467 // Called by hitting PageUp during animation.
1537 void G4OpenInventorQtExaminerViewer::incSpeed    1468 void G4OpenInventorQtExaminerViewer::incSpeed() {
1538    if (std::ceil(animateBtwPtsPeriod * 100) >    1469    if (std::ceil(animateBtwPtsPeriod * 100) >= 4) {
1539       if (speedStep > 0.08)                      1470       if (speedStep > 0.08)
1540          speedStep -= 0.02;                      1471          speedStep -= 0.02;
1541       else                                       1472       else
1542          speedStep = 0.02;                       1473          speedStep = 0.02;
1543       animateBtwPtsPeriod -= speedStep;          1474       animateBtwPtsPeriod -= speedStep;
1544    } else                                        1475    } else
1545       animateBtwPtsPeriod = 0.0;                 1476       animateBtwPtsPeriod = 0.0;
1546                                                  1477 
1547    if (currentState != PAUSED_ANIMATION) {       1478    if (currentState != PAUSED_ANIMATION) {
1548       int lastIdx = (int) refParticleTrajecto << 1479       int lastIdx = refParticleTrajectory.size() - 1;
1549       if (refParticleIdx < lastIdx && !animat    1480       if (refParticleIdx < lastIdx && !animateSensor->isScheduled())
1550          animateRefParticle();                   1481          animateRefParticle();
1551    }                                             1482    }
1552 }                                                1483 }
1553                                                  1484 
1554 // Called by hitting PageDown during animatio    1485 // Called by hitting PageDown during animation.
1555 void G4OpenInventorQtExaminerViewer::decSpeed    1486 void G4OpenInventorQtExaminerViewer::decSpeed() {
1556    animateBtwPtsPeriod += speedStep;             1487    animateBtwPtsPeriod += speedStep;
1557    if (animateBtwPtsPeriod < MIN_SPEED) {        1488    if (animateBtwPtsPeriod < MIN_SPEED) {
1558       if (std::floor(animateBtwPtsPeriod * 10    1489       if (std::floor(animateBtwPtsPeriod * 100) == 12) { // Errors in double representation
1559     speedStep = 0.08;                            1490     speedStep = 0.08;
1560       } else if (animateBtwPtsPeriod > 0.12)     1491       } else if (animateBtwPtsPeriod > 0.12)
1561          speedStep += 0.02;                      1492          speedStep += 0.02;
1562    } else {                                      1493    } else {
1563       animateBtwPtsPeriod = MIN_SPEED;           1494       animateBtwPtsPeriod = MIN_SPEED;
1564       speedStep = START_STEP;                    1495       speedStep = START_STEP;
1565       maxSpeed = 0.0f;                           1496       maxSpeed = 0.0f;
1566       if (animateSensor->isScheduled())          1497       if (animateSensor->isScheduled())
1567          animateSensor->unschedule();            1498          animateSensor->unschedule();
1568    }                                             1499    }
1569 }                                                1500 }
1570                                                  1501 
1571                                                  1502 
1572 // Based on the user's interaction the speed     1503 // Based on the user's interaction the speed indicator bar needs to be adjusted
1573                                                  1504 
1574 void G4OpenInventorQtExaminerViewer::updateSp    1505 void G4OpenInventorQtExaminerViewer::updateSpeedIndicator(void)
1575 {                                                1506 {
1576    assert(this->sgeometry != NULL);              1507    assert(this->sgeometry != NULL);
1577                                                  1508 
1578    SbVec3f * points = this->sgeometry->point.    1509    SbVec3f * points = this->sgeometry->point.startEditing();
1579                                                  1510 
1580    if (points[10][0] == 0.0f)                    1511    if (points[10][0] == 0.0f)
1581       this->animSpeedOutlineSwitch->whichChil    1512       this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_ALL);
1582    if (points[14][0] == 0.0f)                    1513    if (points[14][0] == 0.0f)
1583       this->animSpeedSwitch->whichChild.setVa    1514       this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_ALL);
1584    points[10][0] = this->maxSpeed;               1515    points[10][0] = this->maxSpeed;
1585    points[11][0] = this->maxSpeed;               1516    points[11][0] = this->maxSpeed;
1586    points[14][0] = this->maxSpeed;               1517    points[14][0] = this->maxSpeed;
1587    points[15][0] = this->maxSpeed;               1518    points[15][0] = this->maxSpeed;
1588    this->sgeometry->point.finishEditing();       1519    this->sgeometry->point.finishEditing();
1589                                                  1520 
1590    if (this->maxSpeed == 0.0f) {                 1521    if (this->maxSpeed == 0.0f) {
1591       this->animSpeedOutlineSwitch->whichChil    1522       this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
1592       this->animSpeedSwitch->whichChild.setVa    1523       this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1593    }                                             1524    }
1594 }                                                1525 }
1595                                                  1526 
1596                                                  1527 
1597 void G4OpenInventorQtExaminerViewer::actualRe    1528 void G4OpenInventorQtExaminerViewer::actualRedraw(void) {
1598   switch (currentState) {                        1529   switch (currentState) {
1599   case ANIMATION:                                1530   case ANIMATION:
1600   case REVERSED_ANIMATION:                       1531   case REVERSED_ANIMATION:
1601   case PAUSED_ANIMATION:                         1532   case PAUSED_ANIMATION:
1602     updateSpeedIndicator();                      1533     updateSpeedIndicator();
1603     SoQtExaminerViewer::actualRedraw();          1534     SoQtExaminerViewer::actualRedraw();
1604     break;                                       1535     break;
1605   default:                                       1536   default:
1606     SoQtExaminerViewer::actualRedraw();          1537     SoQtExaminerViewer::actualRedraw();
1607     break;                                       1538     break;
1608   }                                              1539   }
1609 }                                                1540 }
1610                                                  1541 
1611                                                  1542 
1612 void G4OpenInventorQtExaminerViewer::setRefer    1543 void G4OpenInventorQtExaminerViewer::setReferencePath(SoLineSet *lineset,
1613        SoCoordinate3 *coords, bool append)       1544        SoCoordinate3 *coords, bool append)
1614 {                                                1545 {
1615    // TODO:  Color the reference path            1546    // TODO:  Color the reference path
1616    // Disable the color stuff for now: change    1547    // Disable the color stuff for now: changes all trajectories
1617    // FWJ See G4OpenInventorXtExaminerViewer.    1548    // FWJ See G4OpenInventorXtExaminerViewer.cc for test code
1618                                                  1549 
1619    // The trajectory is composed of all the p    1550    // The trajectory is composed of all the polyline segments in the
1620    // multiple value field (SoMFInt32) numVer    1551    // multiple value field (SoMFInt32) numVertices.
1621    // For each of the numVertices.getNum()* p    1552    // For each of the numVertices.getNum()* polyline segments,
1622    // retrieve the points from the SoCoordina    1553    // retrieve the points from the SoCoordinate3 node
1623                                                  1554 
1624    SbVec3f refParticlePt;                        1555    SbVec3f refParticlePt;
1625                                                  1556 
1626    if(!append)                                   1557    if(!append)
1627       refParticleTrajectory.clear();             1558       refParticleTrajectory.clear();
1628                                                  1559 
1629    for(int i = 0; i < lineset->numVertices.ge    1560    for(int i = 0; i < lineset->numVertices.getNum(); ++i) {
1630       for(int j = 0; j < lineset->numVertices    1561       for(int j = 0; j < lineset->numVertices[i]; ++j) {
1631          refParticlePt = coords->point[j];       1562          refParticlePt = coords->point[j];
1632          refParticleTrajectory.push_back(refP    1563          refParticleTrajectory.push_back(refParticlePt);
1633       }                                          1564       }
1634    }                                             1565    }
1635    // Remove points that are too close to eac    1566    // Remove points that are too close to each other
1636    evenOutRefParticlePts();                      1567    evenOutRefParticlePts();
1637    setReferencePathZPos();                       1568    setReferencePathZPos();
1638    getSceneElements();                           1569    getSceneElements();
1639    sortElements();                               1570    sortElements();
1640 }                                                1571 }
1641                                                  1572 
1642                                                  1573 
1643 void G4OpenInventorQtExaminerViewer::setRefer    1574 void G4OpenInventorQtExaminerViewer::setReferencePathZPos()
1644 {                                                1575 {
1645    refZPositions.clear();                        1576    refZPositions.clear();
1646    refZPositions.push_back(0);                   1577    refZPositions.push_back(0);
1647    float dist;                                   1578    float dist;
1648    for(unsigned int i=0; i < refParticleTraje    1579    for(unsigned int i=0; i < refParticleTrajectory.size() - 1; ++i) {
1649       dist = (refParticleTrajectory[i] -         1580       dist = (refParticleTrajectory[i] - 
1650               refParticleTrajectory[i + 1]).l    1581               refParticleTrajectory[i + 1]).length();
1651       refZPositions.push_back(refZPositions[i    1582       refZPositions.push_back(refZPositions[i] + dist);
1652    }                                             1583    }
1653 }                                                1584 }
1654                                                  1585 
1655                                                  1586 
1656 void G4OpenInventorQtExaminerViewer::findAndS    1587 void G4OpenInventorQtExaminerViewer::findAndSetRefPath()
1657 {                                                1588 {
1658    SoSearchAction action;                        1589    SoSearchAction action;
1659    action.setType(SoLineSet::getClassTypeId()    1590    action.setType(SoLineSet::getClassTypeId(),false);
1660    action.setInterest(SoSearchAction::ALL);      1591    action.setInterest(SoSearchAction::ALL);
1661    action.apply(getSceneGraph());                1592    action.apply(getSceneGraph());
1662                                                  1593 
1663    SoPathList &pathList = action.getPaths();     1594    SoPathList &pathList = action.getPaths();
1664                                                  1595 
1665    if(pathList.getLength() != 0) {               1596    if(pathList.getLength() != 0) {
1666                                                  1597 
1667       SoCoordinate3 * coords = NULL;             1598       SoCoordinate3 * coords = NULL;
1668       std::vector<SoCoordinate3 *> coordvec;     1599       std::vector<SoCoordinate3 *> coordvec;
1669       std::vector<SoLineSet *> linevec;          1600       std::vector<SoLineSet *> linevec;
1670                                                  1601 
1671       bool refPathFound = false;                 1602       bool refPathFound = false;
1672       for(int i = 0; i < pathList.getLength()    1603       for(int i = 0; i < pathList.getLength(); ++i) {
1673          SoFullPath *path = (SoFullPath *)pat    1604          SoFullPath *path = (SoFullPath *)pathList[i];
1674                                                  1605 
1675          G4AttHolder* attHolder = dynamic_cas    1606          G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(path->getTail());
1676          if(attHolder != nullptr)             << 1607          for (size_t j = 0; j < attHolder->GetAttDefs().size(); ++j) {
1677          {                                    << 
1678          for (std::size_t j = 0; j < attHolde << 
1679             std::ostringstream oss;              1608             std::ostringstream oss;
1680             oss << G4AttCheck(attHolder->GetA    1609             oss << G4AttCheck(attHolder->GetAttValues()[j],
1681                               attHolder->GetA    1610                               attHolder->GetAttDefs()[j]);
1682                                                  1611 
1683             std::string findStr = "Type of tr    1612             std::string findStr = "Type of trajectory (Type): ";
1684             std::string compareValue = "REFER    1613             std::string compareValue = "REFERENCE";
1685             std::size_t idx = oss.str().find( << 1614             size_t idx = oss.str().find(findStr);
1686                                                  1615 
1687             if(idx != std::string::npos) {       1616             if(idx != std::string::npos) {
1688                if(oss.str().substr(idx + find    1617                if(oss.str().substr(idx + findStr.size(),
1689                                    compareVal    1618                                    compareValue.size()) == compareValue) {
1690                   coords = getCoordsNode(path    1619                   coords = getCoordsNode(path);
1691                   if(coords != NULL) {           1620                   if(coords != NULL) {
1692                      refPathFound = true;        1621                      refPathFound = true;
1693                      coordvec.push_back(coord    1622                      coordvec.push_back(coords);
1694                      linevec.push_back((SoLin    1623                      linevec.push_back((SoLineSet *)path->getTail());
1695                   }                              1624                   }
1696                   break;                         1625                   break;
1697                }                                 1626                }
1698             }                                    1627             }
1699                                                  1628 
1700             findStr = "Track ID (ID): ";         1629             findStr = "Track ID (ID): ";
1701             idx = oss.str().find(findStr);       1630             idx = oss.str().find(findStr);
1702             if(idx != std::string::npos) {       1631             if(idx != std::string::npos) {
1703                //index all primary tracks        1632                //index all primary tracks
1704                std::string tmpstr = oss.str()    1633                std::string tmpstr = oss.str().substr(idx + findStr.size(),1);
1705                std::istringstream buffer(tmps    1634                std::istringstream buffer(tmpstr);
1706                int num;                          1635                int num;
1707                buffer >> num;                    1636                buffer >> num;
1708                if(num == 1) {                    1637                if(num == 1) {
1709                                                  1638 
1710                   // Check if next character     1639                   // Check if next character is a number, 
1711                   // in which case we don't h    1640                   // in which case we don't have Track ID 1
1712                   // FWJ attempt to fix Cover    1641                   // FWJ attempt to fix Coverity issue.
1713                   char nextChar = oss.str().a    1642                   char nextChar = oss.str().at(idx+findStr.size()+1);
1714                   // const char * nextChar =     1643                   // const char * nextChar = 
1715                   // oss.str().substr(idx + f    1644                   // oss.str().substr(idx + findStr.size() + 1,1).c_str();
1716                   if(std::isdigit(nextChar))     1645                   if(std::isdigit(nextChar))
1717                      break; //Not a primary t    1646                      break; //Not a primary track, continue with next track
1718                                                  1647 
1719                   coords = getCoordsNode(path    1648                   coords = getCoordsNode(path);
1720                   if(coords != NULL) {           1649                   if(coords != NULL) {
1721                      coordvec.push_back(coord    1650                      coordvec.push_back(coords);
1722                      linevec.push_back((SoLin    1651                      linevec.push_back((SoLineSet *)path->getTail());
1723                      break; //Found coords no    1652                      break; //Found coords node, continue with next track
1724                   }                              1653                   }
1725                }                                 1654                }
1726                else                              1655                else
1727                   break;  //Not a primary tra    1656                   break;  //Not a primary track, continue with next track
1728             }                                    1657             }
1729             else{                                1658             else{
1730                //Not a Track ID attribute, fa    1659                //Not a Track ID attribute, fall through
1731             }                                    1660             }
1732          }                                       1661          }
1733          }                                    << 
1734                                                  1662 
1735          if(refPathFound)                        1663          if(refPathFound)
1736             break;                               1664             break;
1737       }                                          1665       }
1738                                                  1666 
1739       if(coordvec.empty())                       1667       if(coordvec.empty())
1740          return;    //No track with a Coordin    1668          return;    //No track with a Coordinate3 node found
1741                                                  1669 
1742       if(refPathFound) {                         1670       if(refPathFound) {
1743          //set ref path to last traj, coord i    1671          //set ref path to last traj, coord in the vecs
1744          setReferencePath(linevec.back(), coo    1672          setReferencePath(linevec.back(), coordvec.back());
1745          return;                                 1673          return;
1746       }                                          1674       }
1747       //else                                     1675       //else
1748                                                  1676 
1749       int longestIdx = 0;                        1677       int longestIdx = 0;
1750       float longestLength = 0.0;                 1678       float longestLength = 0.0;
1751       // For all paths                           1679       // For all paths
1752       for(unsigned int i=0;i < linevec.size()    1680       for(unsigned int i=0;i < linevec.size(); ++i) {
1753                                                  1681 
1754          //First generate a vector with all t    1682          //First generate a vector with all the points in this lineset
1755          std::vector<SbVec3f> trajectory;        1683          std::vector<SbVec3f> trajectory;
1756          // For all lines in the i path          1684          // For all lines in the i path
1757          for(int j=0; j < linevec[i]->numVert    1685          for(int j=0; j < linevec[i]->numVertices.getNum(); ++j) {
1758             // For all points in line j          1686             // For all points in line j
1759             for(int k=0; k < linevec[i]->numV    1687             for(int k=0; k < linevec[i]->numVertices[j]; ++k) {
1760                trajectory.push_back(coordvec[    1688                trajectory.push_back(coordvec[i]->point[k]);
1761             }                                    1689             }
1762          }                                       1690          }
1763                                                  1691 
1764          // Then calculate the total length      1692          // Then calculate the total length
1765          float tmpLength=0.0;                    1693          float tmpLength=0.0;
1766          for(unsigned int j=0; j < trajectory    1694          for(unsigned int j=0; j < trajectory.size() - 1; ++j) {
1767             tmpLength += (trajectory[j] - tra    1695             tmpLength += (trajectory[j] - trajectory[j + 1]).length();
1768          }                                       1696          }
1769                                                  1697 
1770          if(tmpLength > longestLength) {         1698          if(tmpLength > longestLength) {
1771             longestIdx = i;                      1699             longestIdx = i;
1772             longestLength = tmpLength;           1700             longestLength = tmpLength;
1773          }                                       1701          }
1774       }                                          1702       }
1775                                                  1703 
1776       // Set the longest path as the referenc    1704       // Set the longest path as the reference path
1777       setReferencePath(linevec[longestIdx], c    1705       setReferencePath(linevec[longestIdx], coordvec[longestIdx]);
1778    }                                             1706    }
1779 }                                                1707 }
1780                                                  1708 
1781                                                  1709 
1782 SoCoordinate3 * G4OpenInventorQtExaminerViewe    1710 SoCoordinate3 * G4OpenInventorQtExaminerViewer::getCoordsNode(SoFullPath *path)
1783 {                                                1711 {
1784    SoLineSet *trajectory = (SoLineSet *)path-    1712    SoLineSet *trajectory = (SoLineSet *)path->getTail();
1785    SoSeparator * grpNode = (SoSeparator*)(((S    1713    SoSeparator * grpNode = (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
1786    int nodeIndex = grpNode->findChild(traject    1714    int nodeIndex = grpNode->findChild(trajectory);
1787    SoNode * tmpNode;                             1715    SoNode * tmpNode;
1788                                                  1716 
1789    // We allow only 100 iterations, in case t    1717    // We allow only 100 iterations, in case the node isn't found
1790    // (should take only a few iterations)        1718    // (should take only a few iterations)
1791    for (int i = 0; i < 100; ++i) {               1719    for (int i = 0; i < 100; ++i) {
1792       --nodeIndex;                               1720       --nodeIndex;
1793                                                  1721 
1794       tmpNode = grpNode->getChild(nodeIndex);    1722       tmpNode = grpNode->getChild(nodeIndex);
1795       if(tmpNode->getTypeId() == SoCoordinate    1723       if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()) {
1796          //node found                            1724          //node found
1797          return (SoCoordinate3 *)tmpNode;        1725          return (SoCoordinate3 *)tmpNode;
1798       }                                          1726       }
1799    }                                             1727    }
1800    return NULL; //coords node not found          1728    return NULL; //coords node not found
1801 }                                                1729 }
1802                                                  1730 
1803                                                  1731 
1804 // Displays scene elements on the right side     1732 // Displays scene elements on the right side of listsDialog.
1805 // else: scene graph is searched for Geant4_S    1733 // else: scene graph is searched for Geant4_SoPolyhedron type nodes
1806 void G4OpenInventorQtExaminerViewer::getScene    1734 void G4OpenInventorQtExaminerViewer::getSceneElements()
1807 {                                                1735 {
1808    std::string field, eltName;                   1736    std::string field, eltName;
1809                                                  1737 
1810    std::map<std::string, int> duplicates;        1738    std::map<std::string, int> duplicates;
1811    std::map<std::string, int> sceneElts;         1739    std::map<std::string, int> sceneElts;
1812    SoSearchAction search;                        1740    SoSearchAction search;
1813    Geant4_SoPolyhedron *node;                    1741    Geant4_SoPolyhedron *node;
1814    SoGroup *root = (SoGroup *)getSceneManager    1742    SoGroup *root = (SoGroup *)getSceneManager()->getSceneGraph();
1815                                                  1743 
1816    SoBaseKit::setSearchingChildren(TRUE);        1744    SoBaseKit::setSearchingChildren(TRUE);
1817                                                  1745 
1818    search.reset();                               1746    search.reset();
1819    search.setSearchingAll(TRUE);                 1747    search.setSearchingAll(TRUE);
1820    search.setInterest(SoSearchAction::ALL);      1748    search.setInterest(SoSearchAction::ALL);
1821    search.setType(Geant4_SoPolyhedron::getCla    1749    search.setType(Geant4_SoPolyhedron::getClassTypeId(), 0);
1822                                                  1750 
1823    // FWJ DEBUG                                  1751    // FWJ DEBUG
1824    //   G4cout << "Searching for elements....    1752    //   G4cout << "Searching for elements....." << G4endl;
1825    search.apply(root);                           1753    search.apply(root);
1826                                                  1754 
1827    SoPathList &pl = search.getPaths();           1755    SoPathList &pl = search.getPaths();
1828                                                  1756 
1829                                                  1757 
1830    // First find which names occur more than     1758    // First find which names occur more than once so we can append a counter to them
1831    for (int i = 0; i < pl.getLength(); i++) {    1759    for (int i = 0; i < pl.getLength(); i++) {
1832       SoFullPath *path = (SoFullPath *)pl[i];    1760       SoFullPath *path = (SoFullPath *)pl[i];
1833       node = (Geant4_SoPolyhedron *)path->get    1761       node = (Geant4_SoPolyhedron *)path->getTail();
1834       eltName = node->getName();                 1762       eltName = node->getName();
1835       //      G4cout << "  FOUND " << i << "     1763       //      G4cout << "  FOUND " << i << "  " << eltName << G4endl;
1836       if(duplicates.count(eltName))              1764       if(duplicates.count(eltName))
1837          duplicates[eltName]++;                  1765          duplicates[eltName]++;
1838       else                                       1766       else
1839          duplicates[eltName] = 1;                1767          duplicates[eltName] = 1;
1840    }                                             1768    }
1841                                                  1769 
1842    for(int i = 0; i < pl.getLength(); i++) {     1770    for(int i = 0; i < pl.getLength(); i++) {
1843       float x,y,z;                               1771       float x,y,z;
1844       std::stringstream ssCount;                 1772       std::stringstream ssCount;
1845       SoFullPath *path = (SoFullPath *)pl[i];    1773       SoFullPath *path = (SoFullPath *)pl[i];
1846       node = (Geant4_SoPolyhedron *)path->get    1774       node = (Geant4_SoPolyhedron *)path->getTail();
1847       eltName = node->getName();                 1775       eltName = node->getName();
1848       field = eltName;                           1776       field = eltName;
1849       if(duplicates[eltName] == 1)               1777       if(duplicates[eltName] == 1)
1850          ssCount << "";//duplicates[field]       1778          ssCount << "";//duplicates[field]
1851       else {                                     1779       else {
1852          if(sceneElts.count(eltName))            1780          if(sceneElts.count(eltName))
1853             sceneElts[eltName]++;                1781             sceneElts[eltName]++;
1854          else                                    1782          else
1855             sceneElts[eltName] = 1;              1783             sceneElts[eltName] = 1;
1856                                                  1784 
1857          ssCount << sceneElts[eltName];          1785          ssCount << sceneElts[eltName];
1858          field += "_";                           1786          field += "_";
1859       }                                          1787       }
1860                                                  1788 
1861       field += ssCount.str();                    1789       field += ssCount.str();
1862                                                  1790 
1863       SoGetBoundingBoxAction bAction(getViewp    1791       SoGetBoundingBoxAction bAction(getViewportRegion());
1864       bAction.apply(path);                       1792       bAction.apply(path);
1865       SbBox3f bBox = bAction.getBoundingBox()    1793       SbBox3f bBox = bAction.getBoundingBox();
1866                                                  1794 
1867       SbVec3f centr = bBox.getCenter();          1795       SbVec3f centr = bBox.getCenter();
1868       centr.getValue(x,y,z);                     1796       centr.getValue(x,y,z);
1869                                                  1797 
1870       path->ref();                               1798       path->ref();
1871       sceneElement el = { field, path, centr,    1799       sceneElement el = { field, path, centr, 0.0 };
1872       sceneElements.push_back(el);               1800       sceneElements.push_back(el);
1873    }                                             1801    }
1874 }                                                1802 }
1875                                                  1803 
1876                                                  1804 
1877 float G4OpenInventorQtExaminerViewer::sqrlen(    1805 float G4OpenInventorQtExaminerViewer::sqrlen(const SbVec3f &a)
1878 {                                                1806 {
1879    float x,y,z;                                  1807    float x,y,z;
1880    a.getValue(x,y,z);                            1808    a.getValue(x,y,z);
1881    return x*x + y*y + z*z;                       1809    return x*x + y*y + z*z;
1882 }                                                1810 }
1883                                                  1811 
1884                                                  1812 
1885 void G4OpenInventorQtExaminerViewer::distance    1813 void G4OpenInventorQtExaminerViewer::distanceToTrajectory(const SbVec3f &q,
1886                                                  1814                                                           float &dist,
1887                                                  1815                                                 SbVec3f &closestPoint,
1888                                                  1816                                                           int &index)
1889 {                                                1817 {
1890    // a : Previous point on trajectory           1818    // a : Previous point on trajectory
1891    // b : Next point on trajectory               1819    // b : Next point on trajectory
1892    // q : the point in space                     1820    // q : the point in space
1893    // dab, daq, dbq: distance between a & b,     1821    // dab, daq, dbq: distance between a & b, a & q, b & q
1894    //                                            1822    //    
1895    // Theory:  A point p on a line ab is defi    1823    // Theory:  A point p on a line ab is defined as:
1896    //                                            1824    //
1897    //         p(t) = a+t?(b?a)                   1825    //         p(t) = a+t?(b?a)
1898    //                                            1826    //
1899    //       note: All are vectors except the     1827    //       note: All are vectors except the parameter t
1900    //                                            1828    //
1901    // When t is between 0 and 1 the point p i    1829    // When t is between 0 and 1 the point p is situated between a and b on ab.
1902    // The point p is defined in terms of the     1830    // The point p is defined in terms of the parameter t, subsequently so does
1903    // the distance from the query point q to     1831    // the distance from the query point q to the point p. To find the minimum
1904    // of that distance we differentiate it an    1832    // of that distance we differentiate it and set equal to zero:
1905    //                                            1833    //
1906    //       diff(Norm(p(t)- q)) = 0              1834    //       diff(Norm(p(t)- q)) = 0
1907    //                                            1835    //
1908    //     note: diff means taking the derivat    1836    //     note: diff means taking the derivative with regard to t
1909    //                                            1837    //
1910    // The resulting t is given in the code be    1838    // The resulting t is given in the code below. The square of the distance
1911    // between p and q is given by:               1839    // between p and q is given by:
1912    //                                            1840    //
1913    //       d^2 = (Norm(p(t)-q))^2               1841    //       d^2 = (Norm(p(t)-q))^2
1914    //                                            1842    //
1915    // The expression found is given in the co    1843    // The expression found is given in the code below (current_dist)
1916    //                                            1844    //
1917    // Ref: http://programmizm.sourceforge.net    1845    // Ref: http://programmizm.sourceforge.net/blog/2012/
1918    //           distance-from-a-point-to-a-po    1846    //           distance-from-a-point-to-a-polyline
1919    //                                            1847    //
1920    //    --PLG                                   1848    //    --PLG
1921                                                  1849 
1922    const std::size_t count = refParticleTraje << 1850    const size_t count = refParticleTrajectory.size();
1923    assert(count>0);                              1851    assert(count>0);
1924                                                  1852 
1925    SbVec3f b = refParticleTrajectory[0];         1853    SbVec3f b = refParticleTrajectory[0];
1926    SbVec3f dbq = b - q;                          1854    SbVec3f dbq = b - q;
1927    float sqrDist = sqrlen(dbq);                  1855    float sqrDist = sqrlen(dbq);
1928    closestPoint = b;                             1856    closestPoint = b;
1929    index = 0;                                    1857    index = 0;
1930    for (std::size_t i = 1; i < count; ++i) {  << 1858    for (size_t i = 1; i < count; ++i) {
1931       const SbVec3f a = b;                       1859       const SbVec3f a = b;
1932       const SbVec3f daq = dbq;                   1860       const SbVec3f daq = dbq;
1933       b = refParticleTrajectory[i];              1861       b = refParticleTrajectory[i];
1934       dbq = b - q;                               1862       dbq = b - q;
1935       const SbVec3f dab = a - b;                 1863       const SbVec3f dab = a - b;
1936                                                  1864 
1937       float dab_x, dab_y, dab_z;                 1865       float dab_x, dab_y, dab_z;
1938       dab.getValue(dab_x,dab_y,dab_z);           1866       dab.getValue(dab_x,dab_y,dab_z);
1939       float daq_x, daq_y, daq_z;                 1867       float daq_x, daq_y, daq_z;
1940       daq.getValue(daq_x, daq_y, daq_z);         1868       daq.getValue(daq_x, daq_y, daq_z);
1941       float dbq_x, dbq_y, dbq_z;                 1869       float dbq_x, dbq_y, dbq_z;
1942       dbq.getValue(dbq_x, dbq_y, dbq_z);         1870       dbq.getValue(dbq_x, dbq_y, dbq_z);
1943                                                  1871 
1944       const float inv_sqrlen = 1./sqrlen(dab)    1872       const float inv_sqrlen = 1./sqrlen(dab);
1945       const float t = (dab_x*daq_x + dab_y*da    1873       const float t = (dab_x*daq_x + dab_y*daq_y + dab_z*daq_z)*inv_sqrlen;
1946                                                  1874 
1947       if (t<0.) {                                1875       if (t<0.) {
1948          // The trajectory point occurs befor    1876          // The trajectory point occurs before point a
1949          // Go to the next point                 1877          // Go to the next point
1950          continue;                               1878          continue;
1951       }                                          1879       }
1952       float current_dist;                        1880       float current_dist;
1953       if (t<=1.) {                               1881       if (t<=1.) {
1954          // The trajectory point occurs betwe    1882          // The trajectory point occurs between a and b.
1955          // Compute the distance to that poin    1883          // Compute the distance to that point
1956          current_dist = daq_x*daq_x + daq_y*d    1884          current_dist = daq_x*daq_x + daq_y*daq_y + daq_z*daq_z
1957             - t*(daq_x*dab_x + daq_y*dab_y +     1885             - t*(daq_x*dab_x + daq_y*dab_y + daq_z*dab_z)
1958             + t*t*(dab_x*dab_x + dab_y*dab_y     1886             + t*t*(dab_x*dab_x + dab_y*dab_y + dab_z*dab_z);
1959       }                                          1887       }
1960       else { //t>1.                              1888       else { //t>1.
1961          // The trajectory point occurs after    1889          // The trajectory point occurs after b.
1962          // Get the distance to point b          1890          // Get the distance to point b
1963          current_dist = sqrlen(dbq);             1891          current_dist = sqrlen(dbq);
1964       }                                          1892       }
1965                                                  1893 
1966       if (current_dist < sqrDist) {              1894       if (current_dist < sqrDist) {
1967          sqrDist = current_dist;                 1895          sqrDist = current_dist;
1968          closestPoint = a + t*(b-a);             1896          closestPoint = a + t*(b-a);
1969          index = (int) i;                     << 1897          index = i;
1970       }                                          1898       }
1971    }                                             1899    }
1972                                                  1900 
1973    dist = std::sqrt(sqrDist);                    1901    dist = std::sqrt(sqrDist);
1974 }                                                1902 }
1975                                                  1903 
1976                                                  1904 
1977 void G4OpenInventorQtExaminerViewer::sortElem    1905 void G4OpenInventorQtExaminerViewer::sortElements()
1978 {                                                1906 {
1979    if(refParticleTrajectory.empty())             1907    if(refParticleTrajectory.empty())
1980       return;                                    1908       return;
1981                                                  1909 
1982    float * trajLength = new float[refParticle    1910    float * trajLength = new float[refParticleTrajectory.size()];
1983    typedef std::map<elementForSorting, sceneE    1911    typedef std::map<elementForSorting, sceneElement> sortedMap;
1984    sortedMap sorted;                             1912    sortedMap sorted;
1985                                                  1913 
1986    // For every point on the reference trajec    1914    // For every point on the reference trajectory, compute
1987    // the total length from the start            1915    // the total length from the start
1988    SbVec3f prevPoint;                            1916    SbVec3f prevPoint;
1989    std::vector<SbVec3f>::iterator itRef = ref    1917    std::vector<SbVec3f>::iterator itRef = refParticleTrajectory.begin();
1990    int trajIndex = 0;                            1918    int trajIndex = 0;
1991    prevPoint = *itRef;                           1919    prevPoint = *itRef;
1992    trajLength[trajIndex] = 0.0;                  1920    trajLength[trajIndex] = 0.0;
1993    ++itRef;                                      1921    ++itRef;
1994    ++trajIndex;                                  1922    ++trajIndex;
1995    for(; itRef != refParticleTrajectory.end()    1923    for(; itRef != refParticleTrajectory.end(); ++itRef, ++trajIndex) {
1996       trajLength[trajIndex] = trajLength[traj    1924       trajLength[trajIndex] = trajLength[trajIndex-1] + (*itRef - prevPoint).length();
1997       prevPoint = *itRef;                        1925       prevPoint = *itRef;
1998    }                                             1926    }
1999                                                  1927 
2000    // Compute the smallest distance between t    1928    // Compute the smallest distance between the element
2001    // and the reference trajectory (find the     1929    // and the reference trajectory (find the closest point),
2002    // then map the element to the trajectory     1930    // then map the element to the trajectory length of that
2003    // point (calculated above)                   1931    // point (calculated above)
2004    SoGetBoundingBoxAction bAction(getViewport    1932    SoGetBoundingBoxAction bAction(getViewportRegion());
2005    SbVec3f elementCoord;                         1933    SbVec3f elementCoord;
2006    std::vector<sceneElement>::iterator itEl;     1934    std::vector<sceneElement>::iterator itEl;
2007    int elementIndex;                             1935    int elementIndex;
2008    elementForSorting el;                         1936    elementForSorting el;
2009    for(itEl = sceneElements.begin(), elementI    1937    for(itEl = sceneElements.begin(), elementIndex = 0;
2010        itEl != sceneElements.end(); ++itEl, +    1938        itEl != sceneElements.end(); ++itEl, ++elementIndex) {
2011       bAction.apply(itEl->path);                 1939       bAction.apply(itEl->path);
2012                                                  1940 
2013       // FWJ sceneElement already has a cente    1941       // FWJ sceneElement already has a center
2014       elementCoord = itEl->center;               1942       elementCoord = itEl->center;
2015       // ... and this sometimes returns an em    1943       // ... and this sometimes returns an empty box!
2016       //      elementCoord = bAction.getBound    1944       //      elementCoord = bAction.getBoundingBox().getCenter();
2017       //      if (bAction.getBoundingBox().is    1945       //      if (bAction.getBoundingBox().isEmpty()) {
2018       //         G4cout << "sortElements: Box    1946       //         G4cout << "sortElements: Box is empty!" << G4endl;
2019       //         G4cout << "   element name="    1947       //         G4cout << "   element name=" << itEl->name << G4endl;
2020       //      }                                  1948       //      }
2021                                                  1949 
2022       int index;                                 1950       int index;
2023       distanceToTrajectory(elementCoord, el.s    1951       distanceToTrajectory(elementCoord, el.smallestDistance, el.closestPoint, index);
2024       itEl->closestPointZCoord = el.closestPo    1952       itEl->closestPointZCoord = el.closestPointZCoord = trajLength[index];
2025       el.distanceToBeamlineStart = (itEl->cen    1953       el.distanceToBeamlineStart = (itEl->center - refParticleTrajectory[0]).length();
2026                                                  1954 
2027       // This map of the scene elements (or t    1955       // This map of the scene elements (or their coordinates rather)
2028       // is automatically sorted by trajector    1956       // is automatically sorted by trajectory length (Z coord), then
2029       // by the distance between the element     1957       // by the distance between the element and the point in case the Z coord
2030       // is the same as another element.  Thi    1958       // is the same as another element.  This is done by using as a key
2031       // an element structure which implement    1959       // an element structure which implements the operator for weak ordering
2032       sorted.insert(std::make_pair(el,*itEl))    1960       sorted.insert(std::make_pair(el,*itEl));
2033    }                                             1961    }
2034                                                  1962 
2035    // store the sorted elements into the vect    1963    // store the sorted elements into the vector field
2036    sceneElements.clear();                        1964    sceneElements.clear();
2037                                                  1965 
2038    sortedMap::iterator itSorted = sorted.begi    1966    sortedMap::iterator itSorted = sorted.begin();
2039    for(; itSorted != sorted.end(); itSorted++    1967    for(; itSorted != sorted.end(); itSorted++)
2040       sceneElements.push_back(itSorted->secon    1968       sceneElements.push_back(itSorted->second);
2041                                                  1969 
2042    zcoordSetFlag = true;                         1970    zcoordSetFlag = true;
2043                                                  1971 
2044    createElementsList();                         1972    createElementsList();
2045                                                  1973 
2046    delete[] trajLength;                          1974    delete[] trajLength;
2047 }                                                1975 }
2048                                                  1976 
2049                                                  1977 
2050 void G4OpenInventorQtExaminerViewer::createEl    1978 void G4OpenInventorQtExaminerViewer::createElementsList()
2051 {                                                1979 {
2052    // FWJ DEBUG                                  1980    // FWJ DEBUG
2053    //   G4cout << "Populating ELEMENT LIST...    1981    //   G4cout << "Populating ELEMENT LIST..." << G4endl;
2054                                                  1982 
2055    AuxWindowDialog->listWidget1->clear();        1983    AuxWindowDialog->listWidget1->clear();
2056    //   int size = sceneElements.size();         1984    //   int size = sceneElements.size();
2057                                                  1985 
2058    std::vector<sceneElement>::const_iterator     1986    std::vector<sceneElement>::const_iterator it;
2059    std::stringstream ss;                         1987    std::stringstream ss;
2060                                                  1988 
2061    for(it=sceneElements.begin(); it!=sceneEle    1989    for(it=sceneElements.begin(); it!=sceneElements.end(); ++it) {
2062       ss << it->name;                            1990       ss << it->name;
2063       if(zcoordSetFlag)                          1991       if(zcoordSetFlag)
2064          ss << " [" << it->closestPointZCoord    1992          ss << " [" << it->closestPointZCoord << "]";
2065                                                  1993 
2066       new QListWidgetItem(ss.str().c_str(), A    1994       new QListWidgetItem(ss.str().c_str(), AuxWindowDialog->listWidget1); 
2067       ss.str("");                                1995       ss.str("");
2068    }                                             1996    }
2069 }                                                1997 }
2070                                                  1998 
2071                                                  1999 
2072 // Called when user clicks a scene element in    2000 // Called when user clicks a scene element in listsDialog.
2073 // Zooms onto that element.                      2001 // Zooms onto that element.
2074 void                                             2002 void
2075 G4OpenInventorQtExaminerViewer::LookAtSceneEl    2003 G4OpenInventorQtExaminerViewer::LookAtSceneElementCB(QListWidgetItem* item)
2076 {                                                2004 {
                                                   >> 2005    char* value;
                                                   >> 2006    std::string elementField;
                                                   >> 2007 
2077    // FWJ DEBUG                                  2008    // FWJ DEBUG
2078    //   G4cout << "AuxWindow: listWidget1 sel    2009    //   G4cout << "AuxWindow: listWidget1 select element CALLBACK" << G4endl;
2079                                                  2010 
2080    SoCamera * cam = getCamera();                 2011    SoCamera * cam = getCamera();
2081                                                  2012 
2082    if (SoQtExaminerViewer::isAnimating())        2013    if (SoQtExaminerViewer::isAnimating())
2083       stopAnimating();                           2014       stopAnimating();
2084                                                  2015 
                                                   >> 2016    value = strdup(qPrintable(item->text()));
                                                   >> 2017    //   G4cout << "LOOKING FOR BOOKMARK " << value << G4endl;
                                                   >> 2018 
2085    if (currentState == ANIMATION || currentSt    2019    if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
2086        || currentState == PAUSED_ANIMATION )     2020        || currentState == PAUSED_ANIMATION ) {
2087       if (animateSensor->isScheduled())          2021       if (animateSensor->isScheduled())
2088          animateSensor->unschedule();            2022          animateSensor->unschedule();
2089       setSuperimpositionEnabled(superimpositi    2023       setSuperimpositionEnabled(superimposition, FALSE);
2090       maxSpeed = 0.0f;                           2024       maxSpeed = 0.0f;
2091       scheduleRedraw();                          2025       scheduleRedraw();
2092       restoreCamera();                           2026       restoreCamera();
2093       currentState = prevState;                  2027       currentState = prevState;
2094    } else if (currentState == VIEWPOINT)         2028    } else if (currentState == VIEWPOINT)
2095       setSuperimpositionEnabled(superimpositi    2029       setSuperimpositionEnabled(superimposition, FALSE);
2096                                                  2030 
2097    std::string elementField = qPrintable(item << 2031    elementField = value;
2098                                                  2032 
2099    std::size_t idx = elementField.find_last_o << 2033    int idx = elementField.find_last_of("[");
2100    if(idx == std::string::npos)               << 2034    if(idx == -1)
2101       idx = elementField.size(); //if "[" not    2035       idx = elementField.size(); //if "[" not found for whatever reason (list not sorted)
2102    else                                          2036    else
2103       idx--; // To get rid of the space that     2037       idx--; // To get rid of the space that is between the name and '['
2104                                                  2038 
2105    bool error = false;                           2039    bool error = false;
2106    SoFullPath *path;                             2040    SoFullPath *path;
2107    SoSearchAction search;                        2041    SoSearchAction search;
2108    SoNode *root = getSceneManager()->getScene    2042    SoNode *root = getSceneManager()->getSceneGraph();
2109    int counter = 0;                           << 2043    int counter, idxUnderscore = elementField.find_last_of("_");
2110    std::size_t idxUnderscore = elementField.f << 
2111                                                  2044 
2112    parseString<int>(counter,                     2045    parseString<int>(counter, 
2113                           elementField.substr    2046                           elementField.substr(idxUnderscore + 1, idx), error);
2114                                                  2047 
2115    SoBaseKit::setSearchingChildren(TRUE);        2048    SoBaseKit::setSearchingChildren(TRUE);
2116    search.reset();                               2049    search.reset();
2117    search.setSearchingAll(TRUE);                 2050    search.setSearchingAll(TRUE);
2118                                                  2051 
2119    // G4cout << "  Starting search for elemen    2052    // G4cout << "  Starting search for elementField " << elementField 
2120    //        << G4endl;                          2053    //        << G4endl;
2121                                                  2054 
2122    if(error) { // No counter is present => el    2055    if(error) { // No counter is present => element name was not modified
2123       curEltName = elementField.substr(0, idx    2056       curEltName = elementField.substr(0, idx);
2124       search.setName(curEltName.c_str());        2057       search.setName(curEltName.c_str());
2125       search.apply(root);                        2058       search.apply(root);
2126                                                  2059 
2127       path = (SoFullPath *)search.getPath();     2060       path = (SoFullPath *)search.getPath();
2128    }                                             2061    }
2129    else {                                        2062    else {
2130       curEltName = elementField.substr(0, idx    2063       curEltName = elementField.substr(0, idxUnderscore);
2131       search.setInterest(SoSearchAction::ALL)    2064       search.setInterest(SoSearchAction::ALL);
2132       search.setName(curEltName.c_str());        2065       search.setName(curEltName.c_str());
2133       search.apply(root);                        2066       search.apply(root);
2134                                                  2067 
2135       SoPathList &pl = search.getPaths();        2068       SoPathList &pl = search.getPaths();
2136       path = (SoFullPath *)pl[counter - 1]; /    2069       path = (SoFullPath *)pl[counter - 1]; // Since counter starts at 1, not 0
2137    }                                             2070    }
2138                                                  2071 
2139    G4ThreeVector global;                         2072    G4ThreeVector global;
2140                                                  2073 
2141    // FWJ FLIP THIS                              2074    // FWJ FLIP THIS
2142    if ((idx > 0) && (path)) {                    2075    if ((idx > 0) && (path)) {
2143                                                  2076 
2144       if(!refParticleTrajectory.empty()) {       2077       if(!refParticleTrajectory.empty()) {
2145                                                  2078 
2146          SoGetBoundingBoxAction bAction(getVi    2079          SoGetBoundingBoxAction bAction(getViewportRegion());
2147          bAction.apply(path);                    2080          bAction.apply(path);
2148          SbBox3f bBox = bAction.getBoundingBo    2081          SbBox3f bBox = bAction.getBoundingBox();
2149          SbVec3f elementCoord = bBox.getCente    2082          SbVec3f elementCoord = bBox.getCenter();
2150                                                  2083 
2151          refParticleIdx = 0;                     2084          refParticleIdx = 0;
2152          SbVec3f p;                              2085          SbVec3f p;
2153                                                  2086 
2154          float absLengthNow, absLengthMin;       2087          float absLengthNow, absLengthMin;
2155          int maxIdx = (int) refParticleTrajec << 2088          int maxIdx = refParticleTrajectory.size() - 2;
2156          int targetIdx = 0;                      2089          int targetIdx = 0;
2157          SbVec3f dir;                            2090          SbVec3f dir;
2158                                                  2091 
2159          p = refParticleTrajectory[refParticl    2092          p = refParticleTrajectory[refParticleIdx];
2160          absLengthMin = (p - elementCoord).le    2093          absLengthMin = (p - elementCoord).length();
2161          refParticleIdx++;                       2094          refParticleIdx++;
2162                                                  2095 
2163          // Find a ref. particle's point clos    2096          // Find a ref. particle's point closest to element's global coords
2164          while (refParticleIdx < maxIdx) {       2097          while (refParticleIdx < maxIdx) {
2165             p = refParticleTrajectory[refPart    2098             p = refParticleTrajectory[refParticleIdx];
2166             absLengthNow = (p - elementCoord)    2099             absLengthNow = (p - elementCoord).length();
2167                                                  2100 
2168             if (absLengthNow < absLengthMin)     2101             if (absLengthNow < absLengthMin) {
2169                absLengthMin = absLengthNow;      2102                absLengthMin = absLengthNow;
2170                targetIdx = refParticleIdx;       2103                targetIdx = refParticleIdx;
2171             }                                    2104             }
2172             refParticleIdx++;                    2105             refParticleIdx++;
2173          }                                       2106          }
2174                                                  2107 
2175          if (currentState != BEAMLINE) { // S    2108          if (currentState != BEAMLINE) { // Set up default zoom
2176             SbVec3f p1, pN;                      2109             SbVec3f p1, pN;
2177             currentState = BEAMLINE;             2110             currentState = BEAMLINE;
2178             prevParticleDir = SbVec3f(0,0,0);    2111             prevParticleDir = SbVec3f(0,0,0); //so that moveCamera() knows sets default parameters
2179                                                  2112             
2180             p1 = prevPt = refParticleTrajecto    2113             p1 = prevPt = refParticleTrajectory[0];
2181             pN = refParticleTrajectory[refPar    2114             pN = refParticleTrajectory[refParticleTrajectory.size() - 1];
2182             distance = (pN - p1).length() / 1    2115             distance = (pN - p1).length() / 10;
2183                                                  2116 
2184             // FWJ Rather than switching to a    2117             // FWJ Rather than switching to a default height, it is more flexible
2185             // to keep the same height(magnif    2118             // to keep the same height(magnification) while moving the camera.
2186             // if (cam->isOfType(SoOrthograph    2119             // if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2187             //    ((SoOrthographicCamera *) c    2120             //    ((SoOrthographicCamera *) cam)->height.setValue(defaultHeight);
2188             // // FWJ Restore the default hei    2121             // // FWJ Restore the default height instead of hard-wired value
2189             // // ((SoOrthographicCamera *) c    2122             // // ((SoOrthographicCamera *) cam)->height.setValue(10000.0f);
2190             // }                                 2123             // }
2191             // else if (cam->isOfType(SoPersp    2124             // else if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2192                                                  2125 
2193             // FWJ required to avoid extreme     2126             // FWJ required to avoid extreme perspective after camera move:
2194             if (cam->isOfType(SoPerspectiveCa    2127             if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2195                ((SoPerspectiveCamera*)cam)->h    2128                ((SoPerspectiveCamera*)cam)->heightAngle.setValue(defaultHeightAngle);
2196                                                  2129 
2197          } else {                                2130          } else {
2198             if (cam->isOfType(SoPerspectiveCa    2131             if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2199                distance = (prevPt - cam->posi    2132                distance = (prevPt - cam->position.getValue()).length();
2200          }                                       2133          }
2201          refParticleIdx = targetIdx;             2134          refParticleIdx = targetIdx;
2202                                                  2135 
2203          ////////////////////////////////////    2136          //////////////////////////////////////////////////////////////
2204          setSuperimpositionEnabled(superimpos    2137          setSuperimpositionEnabled(superimposition, TRUE);
2205          axisSwitch->whichChild.setValue(SO_S    2138          axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2206          animSpeedOutlineSwitch->whichChild.s    2139          animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
2207          animSpeedSwitch->whichChild.setValue    2140          animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
2208          scheduleRedraw();                       2141          scheduleRedraw();
2209          ////////////////////////////////////    2142          //////////////////////////////////////////////////////////////
2210                                                  2143 
2211          moveCamera(distance);                   2144          moveCamera(distance);
2212                                                  2145 
2213       }                                          2146       }
2214                                                  2147       
2215       else {                                     2148       else {
2216          offsetFromCenter.setValue(0, 0, 1);     2149          offsetFromCenter.setValue(0, 0, 1);
2217          distance = 50;// small number since     2150          distance = 50;// small number since using viewAll() for default zoom
2218          upVector.setValue(0, 1, 0);             2151          upVector.setValue(0, 1, 0);
2219          moveCamera(distance);                   2152          moveCamera(distance);
2220          cam->viewAll(path, getViewportRegion    2153          cam->viewAll(path, getViewportRegion());
2221       }                                          2154       }
2222    }                                             2155    }
2223                                                  2156 
2224 }                                                2157 }
2225                                                  2158 
2226                                                  2159 
2227 void G4OpenInventorQtExaminerViewer::FileLoad    2160 void G4OpenInventorQtExaminerViewer::FileLoadRefPathCB()
2228 {                                                2161 {
2229    //   G4cout << "File: Load Ref Path CALLBA    2162    //   G4cout << "File: Load Ref Path CALLBACK" << G4endl;
2230                                                  2163 
2231    QFileDialog filedialog(getParentWidget(),     2164    QFileDialog filedialog(getParentWidget(), tr("Load Reference Path"));
2232    filedialog.setFileMode(QFileDialog::AnyFil    2165    filedialog.setFileMode(QFileDialog::AnyFile);
2233    filedialog.setFont(*font);                    2166    filedialog.setFont(*font);
2234    if (!filedialog.exec()) return;               2167    if (!filedialog.exec()) return;
2235    QStringList filenameinlist = filedialog.se    2168    QStringList filenameinlist = filedialog.selectedFiles();
2236    QString filenamein = filenameinlist[0];       2169    QString filenamein = filenameinlist[0];
2237                                                  2170 
2238    std::ifstream ifs(qPrintable(filenamein)); << 2171    //   G4cout << "Input file name is " << qPrintable(filenamein) << G4endl;
                                                   >> 2172 
                                                   >> 2173    char* filename = new char[filenamein.size()+1];
                                                   >> 2174    filename = strdup(qPrintable(filenamein));
                                                   >> 2175    //   G4cout << "char[] file name is " << filename << G4endl;
                                                   >> 2176 
                                                   >> 2177    std::ifstream ifs(filename);
2239    if(ifs.is_open()) {                           2178    if(ifs.is_open()) {
2240       refParticleTrajectory.clear();             2179       refParticleTrajectory.clear();
2241       float x,y,z;                               2180       float x,y,z;
2242       while(ifs >> x >> y >> z) {                2181       while(ifs >> x >> y >> z) {
2243          refParticleTrajectory.push_back(SbVe    2182          refParticleTrajectory.push_back(SbVec3f(x,y,z));
2244       }                                          2183       }
2245       ifs.close();                               2184       ifs.close();
2246    } else {                                      2185    } else {
2247       QMessageBox msgbox;                        2186       QMessageBox msgbox;
2248       msgbox.setFont(*font);                     2187       msgbox.setFont(*font);
2249       QString messagetxt = "Reference Path fi    2188       QString messagetxt = "Reference Path file not found: ";
2250       messagetxt.append(filenamein);             2189       messagetxt.append(filenamein);
2251       msgbox.setText(messagetxt);                2190       msgbox.setText(messagetxt);
2252       msgbox.exec();                             2191       msgbox.exec();
2253       return;                                    2192       return;
2254    }                                             2193    }
2255    if (refParticleTrajectory.size() < 2) {       2194    if (refParticleTrajectory.size() < 2) {
2256       QMessageBox msgbox;                        2195       QMessageBox msgbox;
2257       msgbox.setFont(*font);                     2196       msgbox.setFont(*font);
2258       QString messagetxt = "Invalid Reference    2197       QString messagetxt = "Invalid Reference Path";
2259       msgbox.setText(messagetxt);                2198       msgbox.setText(messagetxt);
2260       msgbox.exec();                             2199       msgbox.exec();
2261       return;                                    2200       return;
2262    }                                             2201    }
2263    // Following setReferencePath() ...           2202    // Following setReferencePath() ...
2264    evenOutRefParticlePts();                      2203    evenOutRefParticlePts();
2265    setReferencePathZPos();                       2204    setReferencePathZPos();
2266    getSceneElements();                           2205    getSceneElements();
2267    sortElements();                               2206    sortElements();
2268 }                                                2207 }
2269                                                  2208 
2270                                                  2209 
2271 void G4OpenInventorQtExaminerViewer::FileSave    2210 void G4OpenInventorQtExaminerViewer::FileSaveRefPathCB()
2272 {                                                2211 {
2273    //   G4cout << "File: Save Ref Path CALLBA    2212    //   G4cout << "File: Save Ref Path CALLBACK" << G4endl;
2274                                                  2213 
2275    QFileDialog filedialog(getParentWidget(),     2214    QFileDialog filedialog(getParentWidget(), tr("Save Reference Path"));
2276    filedialog.setFileMode(QFileDialog::AnyFil    2215    filedialog.setFileMode(QFileDialog::AnyFile);
2277    // To enable confirmation of overwriting      2216    // To enable confirmation of overwriting
2278    filedialog.setAcceptMode(QFileDialog::Acce    2217    filedialog.setAcceptMode(QFileDialog::AcceptSave);
2279    filedialog.setFont(*font);                    2218    filedialog.setFont(*font);
2280    if (!filedialog.exec()) return;               2219    if (!filedialog.exec()) return;
2281    QStringList filenameinlist = filedialog.se    2220    QStringList filenameinlist = filedialog.selectedFiles();
2282    QString filenamein = filenameinlist[0];       2221    QString filenamein = filenameinlist[0];
2283                                                  2222 
2284    std::ofstream ofs(qPrintable(filenamein)); << 2223    //   G4cout << "Input file name is " << qPrintable(filenamein) << G4endl;
                                                   >> 2224 
                                                   >> 2225    char* filename = new char[filenamein.size()+1];
                                                   >> 2226    filename = strdup(qPrintable(filenamein));
                                                   >> 2227    //   G4cout << "char[] file name is " << filename << G4endl;
                                                   >> 2228 
                                                   >> 2229    std::ofstream ofs(filename);
2285    if (ofs.is_open()) {                          2230    if (ofs.is_open()) {
2286       float x,y,z;                               2231       float x,y,z;
2287       for (unsigned int i=0; i < refParticleT    2232       for (unsigned int i=0; i < refParticleTrajectory.size(); ++i) {
2288          refParticleTrajectory[i].getValue(x,    2233          refParticleTrajectory[i].getValue(x,y,z);
2289          ofs << x << " " << y << " " << z <<     2234          ofs << x << " " << y << " " << z << "\n";
2290       }                                          2235       }
2291       ofs.close();                               2236       ofs.close();
2292    } else {                                      2237    } else {
2293       QMessageBox msgbox;                        2238       QMessageBox msgbox;
2294       msgbox.setFont(*font);                     2239       msgbox.setFont(*font);
2295       QString messagetxt = "Error opening fil    2240       QString messagetxt = "Error opening file ";
2296       messagetxt.append(filenamein);             2241       messagetxt.append(filenamein);
2297       msgbox.setText(messagetxt);                2242       msgbox.setText(messagetxt);
2298       msgbox.exec();                             2243       msgbox.exec();
2299    }                                             2244    }
2300                                                  2245 
2301 }                                                2246 }
2302                                                  2247 
2303 void G4OpenInventorQtExaminerViewer::evenOutR    2248 void G4OpenInventorQtExaminerViewer::evenOutRefParticlePts()
2304 {                                                2249 {
2305    if(refParticleTrajectory.empty())             2250    if(refParticleTrajectory.empty())
2306       return;                                    2251       return;
2307                                                  2252 
2308    SbVec3f p1, p2, p3, dirNow, dirNxt, dir, p    2253    SbVec3f p1, p2, p3, dirNow, dirNxt, dir, p2_tmp, p_start, p_corner, p_nxt;
2309    float avgDistBtwPts = 0;                      2254    float avgDistBtwPts = 0;
2310    float totalDistBtwPts = 0;                    2255    float totalDistBtwPts = 0;
2311    std::vector<SbVec3f> newRefParticleTraject    2256    std::vector<SbVec3f> newRefParticleTrajectory;
2312    SbVec3f refPoint;                             2257    SbVec3f refPoint;
2313    std::size_t size = refParticleTrajectory.s << 2258    int size = refParticleTrajectory.size() - 1;
2314    int numOfPts = 0;                             2259    int numOfPts = 0;
2315    for (std::size_t i = 0; i < size; ++i) {   << 2260    for (int i = 0; i < size; i++) {
2316       p1 = refParticleTrajectory[i];             2261       p1 = refParticleTrajectory[i];
2317       p2 = refParticleTrajectory[i + 1];         2262       p2 = refParticleTrajectory[i + 1];
2318       if (p1 == p2)                              2263       if (p1 == p2)
2319          continue;                               2264          continue;
2320       numOfPts++;                                2265       numOfPts++;
2321       totalDistBtwPts += (p2 - p1).length();     2266       totalDistBtwPts += (p2 - p1).length();
2322    }                                             2267    }
2323    // Nothing useful to do (and fix Coverity)    2268    // Nothing useful to do (and fix Coverity)
2324    if (numOfPts <= 2) return;                    2269    if (numOfPts <= 2) return;
2325                                                  2270 
2326    avgDistBtwPts = totalDistBtwPts / numOfPts    2271    avgDistBtwPts = totalDistBtwPts / numOfPts;
2327    float minDistAllowed = 0.75 * avgDistBtwPt    2272    float minDistAllowed = 0.75 * avgDistBtwPts;
2328    // float maxDistAllowed = 1.25 * avgDistBt    2273    // float maxDistAllowed = 1.25 * avgDistBtwPts; // Pts tend to be close not far
2329                                                  2274 
2330    float x, y, z;                                2275    float x, y, z;
2331    std::size_t i = 0, j = 0;                  << 2276    int i = 0, j = 0;
2332    while (i < size) {                            2277    while (i < size) {
2333       p1 = refParticleTrajectory[i];             2278       p1 = refParticleTrajectory[i];
2334       p2 = refParticleTrajectory[i + 1];         2279       p2 = refParticleTrajectory[i + 1];
2335                                                  2280 
2336       refPoint = p1;                             2281       refPoint = p1;
2337       p1.getValue(x, y, z);                      2282       p1.getValue(x, y, z);
2338                                                  2283 
2339       newRefParticleTrajectory.push_back(refP    2284       newRefParticleTrajectory.push_back(refPoint);
2340                                                  2285 
2341       j = i;                                     2286       j = i;
2342       while ((p2 - p1).length() < minDistAllo    2287       while ((p2 - p1).length() < minDistAllowed && j < (size - 1)) {
2343          j++;                                    2288          j++;
2344                                                  2289 
2345          p1 = refParticleTrajectory[j];          2290          p1 = refParticleTrajectory[j];
2346          p2 = refParticleTrajectory[j + 1];      2291          p2 = refParticleTrajectory[j + 1];
2347       }                                          2292       }
2348       if (j != i)                                2293       if (j != i)
2349          i = j + 1;                              2294          i = j + 1;
2350       else                                       2295       else
2351          i++;                                    2296          i++;
2352    }                                             2297    }
2353                                                  2298 
2354    refParticleTrajectory.clear();                2299    refParticleTrajectory.clear();
2355    refParticleTrajectory = newRefParticleTraj    2300    refParticleTrajectory = newRefParticleTrajectory;
2356 }                                                2301 }
2357                                                  2302 
2358                                                  2303 
2359 void G4OpenInventorQtExaminerViewer::saveCurC    2304 void G4OpenInventorQtExaminerViewer::saveCurCamera()
2360 {                                                2305 {
2361    SoCamera *cam = getCamera();                  2306    SoCamera *cam = getCamera();
2362    camB4Animation.viewportMapping = cam->view    2307    camB4Animation.viewportMapping = cam->viewportMapping.getValue();
2363    camB4Animation.position = cam->position.ge    2308    camB4Animation.position = cam->position.getValue();
2364    camB4Animation.orientation = cam->orientat    2309    camB4Animation.orientation = cam->orientation.getValue();
2365    camB4Animation.aspectRatio = cam->aspectRa    2310    camB4Animation.aspectRatio = cam->aspectRatio.getValue();
2366    camB4Animation.nearDistance = cam->nearDis    2311    camB4Animation.nearDistance = cam->nearDistance.getValue();
2367    camB4Animation.farDistance = cam->farDista    2312    camB4Animation.farDistance = cam->farDistance.getValue();
2368    camB4Animation.focalDistance = cam->focalD    2313    camB4Animation.focalDistance = cam->focalDistance.getValue();
2369                                                  2314 
2370    if (cam->isOfType(SoPerspectiveCamera::get    2315    if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2371       camB4Animation.height =                    2316       camB4Animation.height =
2372          ((SoPerspectiveCamera *) cam)->heigh    2317          ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
2373       camB4Animation.camType = PERSPECTIVE;      2318       camB4Animation.camType = PERSPECTIVE;
2374    } else if (cam->isOfType(SoOrthographicCam    2319    } else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2375       camB4Animation.height =                    2320       camB4Animation.height =
2376          ((SoOrthographicCamera *) cam)->heig    2321          ((SoOrthographicCamera *) cam)->height.getValue();
2377       camB4Animation.camType = ORTHOGRAPHIC;     2322       camB4Animation.camType = ORTHOGRAPHIC;
2378    }                                             2323    }
2379 }                                                2324 }
2380                                                  2325 
2381                                                  2326 
2382 void G4OpenInventorQtExaminerViewer::restoreC    2327 void G4OpenInventorQtExaminerViewer::restoreCamera()
2383 {                                                2328 {
2384    SoCamera *cam = getCamera();                  2329    SoCamera *cam = getCamera();
2385                                                  2330 
2386    cam->viewportMapping = camB4Animation.view    2331    cam->viewportMapping = camB4Animation.viewportMapping;
2387    cam->position = camB4Animation.position;      2332    cam->position = camB4Animation.position;
2388    cam->orientation = camB4Animation.orientat    2333    cam->orientation = camB4Animation.orientation;
2389    cam->aspectRatio = camB4Animation.aspectRa    2334    cam->aspectRatio = camB4Animation.aspectRatio;
2390    cam->nearDistance = camB4Animation.nearDis    2335    cam->nearDistance = camB4Animation.nearDistance;
2391    cam->farDistance = camB4Animation.farDista    2336    cam->farDistance = camB4Animation.farDistance;
2392    cam->focalDistance = camB4Animation.focalD    2337    cam->focalDistance = camB4Animation.focalDistance;
2393                                                  2338 
2394    if (cam->isOfType(SoPerspectiveCamera::get    2339    if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2395       if (camB4Animation.camType == ORTHOGRAP    2340       if (camB4Animation.camType == ORTHOGRAPHIC) {
2396          toggleCameraType();                     2341          toggleCameraType();
2397          cam = getCamera();                      2342          cam = getCamera();
2398          ((SoOrthographicCamera *) cam)->heig    2343          ((SoOrthographicCamera *) cam)->height.setValue(
2399                                                  2344                                                          camB4Animation.height);
2400       } else                                     2345       } else
2401          ((SoPerspectiveCamera *) cam)->heigh    2346          ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
2402                                                  2347                                                              camB4Animation.height);
2403    } else if (cam->isOfType(SoOrthographicCam    2348    } else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2404       if (camB4Animation.camType == PERSPECTI    2349       if (camB4Animation.camType == PERSPECTIVE) {
2405          toggleCameraType();                     2350          toggleCameraType();
2406          cam = getCamera();                      2351          cam = getCamera();
2407          ((SoPerspectiveCamera *) cam)->heigh    2352          ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
2408                                                  2353                                                              camB4Animation.height);
2409       } else                                     2354       } else
2410          ((SoOrthographicCamera *) cam)->heig    2355          ((SoOrthographicCamera *) cam)->height.setValue(
2411                                                  2356                                                          camB4Animation.height);
2412    }                                             2357    }
2413 }                                                2358 }
2414                                                  2359 
2415                                                  2360 
2416 void G4OpenInventorQtExaminerViewer::animateS    2361 void G4OpenInventorQtExaminerViewer::animateSensorRotationCB(void *data, 
2417                                                  2362                                                              SoSensor *sensor)
2418 {                                                2363 {
2419    SbTime curTime = SbTime::getTimeOfDay();      2364    SbTime curTime = SbTime::getTimeOfDay();
2420    G4OpenInventorQtExaminerViewer* This = (G4    2365    G4OpenInventorQtExaminerViewer* This = (G4OpenInventorQtExaminerViewer*) data;
2421                                                  2366 
2422    SoTimerSensor* s = (SoTimerSensor*) sensor    2367    SoTimerSensor* s = (SoTimerSensor*) sensor;
2423                                                  2368 
2424    float t = float((curTime - s->getBaseTime(    2369    float t = float((curTime - s->getBaseTime()).getValue())
2425       / This->animateBtwPtsPeriod;               2370       / This->animateBtwPtsPeriod;
2426                                                  2371 
2427    if ((t > 1.0f) || (t + s->getInterval().ge    2372    if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
2428       t = 1.0f;                                  2373       t = 1.0f;
2429    SbBool end = (t == 1.0f);                     2374    SbBool end = (t == 1.0f);
2430                                                  2375 
2431    if (end) {                                    2376    if (end) {
2432       This->animateSensorRotation->unschedule    2377       This->animateSensorRotation->unschedule();
2433       if(This->rotCnt) {                         2378       if(This->rotCnt) {
2434          // rotations left                       2379          // rotations left
2435          This->rotateCamera();                   2380          This->rotateCamera();
2436       }                                          2381       }
2437       else {                                     2382       else {
2438          // rotation over                        2383          // rotation over
2439          This->currentState = This->prevState    2384          This->currentState = This->prevState;
2440          return;                                 2385          return;
2441       }                                          2386       }
2442    }                                             2387    }
2443                                                  2388 
2444 }                                                2389 }
2445                                                  2390 
2446                                                  2391 
2447 // Called repeatedly during reference particl    2392 // Called repeatedly during reference particle animation
2448                                                  2393 
2449 void G4OpenInventorQtExaminerViewer::animateS    2394 void G4OpenInventorQtExaminerViewer::animateSensorCB(void *data, 
2450                                                  2395                                                      SoSensor *sensor)
2451 {                                                2396 {
2452    SbTime curTime = SbTime::getTimeOfDay();      2397    SbTime curTime = SbTime::getTimeOfDay();
2453    G4OpenInventorQtExaminerViewer* This = (G4    2398    G4OpenInventorQtExaminerViewer* This = (G4OpenInventorQtExaminerViewer*) data;
2454    SoCamera *cam = This->getCamera();            2399    SoCamera *cam = This->getCamera();
2455    SoTimerSensor* s = (SoTimerSensor*) sensor    2400    SoTimerSensor* s = (SoTimerSensor*) sensor;
2456                                                  2401 
2457    float t = float((curTime - s->getBaseTime(    2402    float t = float((curTime - s->getBaseTime()).getValue())
2458       / This->animateBtwPtsPeriod;               2403       / This->animateBtwPtsPeriod;
2459                                                  2404 
2460    if ((t > 1.0f) || (t + s->getInterval().ge    2405    if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
2461       t = 1.0f;                                  2406       t = 1.0f;
2462    SbBool end = (t == 1.0f);                     2407    SbBool end = (t == 1.0f);
2463                                                  2408 
2464    cam->orientation = SbRotation::slerp(This-    2409    cam->orientation = SbRotation::slerp(This->camStartOrient, This->camEndOrient, t);
2465    cam->position = This->camStartPos + (This-    2410    cam->position = This->camStartPos + (This->camEndPos - This->camStartPos) * t;
2466                                                  2411 
2467    if (end) {                                    2412    if (end) {
2468       This->animateSensor->unschedule();         2413       This->animateSensor->unschedule();
2469                                                  2414 
2470       if (This->currentState == ANIMATION) {     2415       if (This->currentState == ANIMATION) {
2471          if (This->refParticleIdx < (int) (Th    2416          if (This->refParticleIdx < (int) (This->refParticleTrajectory.size() - 1))
2472             This->animateRefParticle();          2417             This->animateRefParticle();
2473          else {                                  2418          else {
2474             This->animateBtwPtsPeriod = MIN_S    2419             This->animateBtwPtsPeriod = MIN_SPEED;
2475             This->speedStep = START_STEP;        2420             This->speedStep = START_STEP;
2476          }                                       2421          }
2477       }                                          2422       }
2478       if (This->currentState == REVERSED_ANIM    2423       if (This->currentState == REVERSED_ANIMATION) {
2479          if (This->refParticleIdx >= 1)          2424          if (This->refParticleIdx >= 1)
2480             This->animateRefParticle();          2425             This->animateRefParticle();
2481          else {                                  2426          else {
2482             This->animateBtwPtsPeriod = MIN_S    2427             This->animateBtwPtsPeriod = MIN_SPEED;
2483             This->speedStep = START_STEP;        2428             This->speedStep = START_STEP;
2484          }                                       2429          }
2485       }                                          2430       }
2486    }                                             2431    }
2487 }                                                2432 }
2488                                                  2433 
2489                                                  2434 
2490 void G4OpenInventorQtExaminerViewer::setStart    2435 void G4OpenInventorQtExaminerViewer::setStartingPtForAnimation()
2491 {                                                2436 {
2492    if (SoQtExaminerViewer::isAnimating())        2437    if (SoQtExaminerViewer::isAnimating())
2493       stopAnimating();                           2438       stopAnimating();
2494                                                  2439 
2495    SbRotation rot;                               2440    SbRotation rot;
2496    SbVec3f p1{0.0, 0.0, 0.0}, p2{0.0, 0.0, 0. << 2441    SbVec3f p1, p2, p2_tmp, camUpV, camD, camD_tmp, leftRightAxis;
2497    float x1, y1, z1, x2, y2, z2;                 2442    float x1, y1, z1, x2, y2, z2;
2498                                                  2443 
2499    if (currentState == ANIMATION) {              2444    if (currentState == ANIMATION) {
2500       p1 = refParticleTrajectory[refParticleI    2445       p1 = refParticleTrajectory[refParticleIdx];
2501       p2 = refParticleTrajectory[++(refPartic    2446       p2 = refParticleTrajectory[++(refParticleIdx)];
2502    } else if (currentState == REVERSED_ANIMAT    2447    } else if (currentState == REVERSED_ANIMATION) {
2503       p2 = refParticleTrajectory[refParticleI    2448       p2 = refParticleTrajectory[refParticleIdx];
2504       p1 = refParticleTrajectory[--(refPartic    2449       p1 = refParticleTrajectory[--(refParticleIdx)];
2505    } else if (currentState == PAUSED_ANIMATIO    2450    } else if (currentState == PAUSED_ANIMATION) {
2506       if (refParticleIdx < (int) refParticleT    2451       if (refParticleIdx < (int) refParticleTrajectory.size()) {
2507          p1 = refParticleTrajectory[refPartic    2452          p1 = refParticleTrajectory[refParticleIdx];
2508          p2 = refParticleTrajectory[refPartic    2453          p2 = refParticleTrajectory[refParticleIdx + 1];
2509       } else {                                   2454       } else {
2510          p1 = refParticleTrajectory[refPartic    2455          p1 = refParticleTrajectory[refParticleIdx - 1];
2511          p2 = refParticleTrajectory[refPartic    2456          p2 = refParticleTrajectory[refParticleIdx];
2512       }                                          2457       }
2513    }                                             2458    }
2514    p1.getValue(x1, y1, z1);                      2459    p1.getValue(x1, y1, z1);
2515    p2.getValue(x2, y2, z2);                      2460    p2.getValue(x2, y2, z2);
2516                                                  2461 
2517    camD = p2 - p1;                               2462    camD = p2 - p1;
2518    camD.normalize();                             2463    camD.normalize();
2519                                                  2464 
2520    p2_tmp.setValue(x2, y1, z2);                  2465    p2_tmp.setValue(x2, y1, z2);
2521    camD_tmp = p2_tmp - p1;                       2466    camD_tmp = p2_tmp - p1;
2522    camD_tmp.normalize();                         2467    camD_tmp.normalize();
2523                                                  2468 
2524    camUpV.setValue(0, 1, 0);                     2469    camUpV.setValue(0, 1, 0);
2525    rot.setValue(camD_tmp, camD);                 2470    rot.setValue(camD_tmp, camD);
2526    rot.multVec(camUpV, camUpV);                  2471    rot.multVec(camUpV, camUpV);
2527                                                  2472 
2528    leftRightAxis = camD.cross(camUpV);           2473    leftRightAxis = camD.cross(camUpV);
2529                                                  2474 
2530    myCam->position = p1;                         2475    myCam->position = p1;
2531    myCam->pointAt(p2, camUpV);                   2476    myCam->pointAt(p2, camUpV);
2532                                                  2477 
2533    // Update camera position                     2478    // Update camera position
2534    p1 = p1 + (up_down * camUpV) + (left_right    2479    p1 = p1 + (up_down * camUpV) + (left_right * leftRightAxis);
2535    myCam->position = p1;                         2480    myCam->position = p1;
2536    // FWJ Try look-ahead here                    2481    // FWJ Try look-ahead here
2537    int idx = refParticleIdx + pathLookahead;     2482    int idx = refParticleIdx + pathLookahead;
2538    idx = std::min(idx, (int)refParticleTrajec    2483    idx = std::min(idx, (int)refParticleTrajectory.size() - 1);
2539    myCam->pointAt(refParticleTrajectory[idx],    2484    myCam->pointAt(refParticleTrajectory[idx], camUpV);
2540    //   myCam->pointAt(refParticleTrajectory[    2485    //   myCam->pointAt(refParticleTrajectory[idx], camUpVec);
2541    myCam->focalDistance = 0.1f;                  2486    myCam->focalDistance = 0.1f;
2542 }                                                2487 }
2543                                                  2488 
2544                                                  2489 
2545 void G4OpenInventorQtExaminerViewer::gotoRefP    2490 void G4OpenInventorQtExaminerViewer::gotoRefPathStart()
2546 {                                                2491 {
2547    G4OpenInventorQtExaminerViewer::ToolsRefPa    2492    G4OpenInventorQtExaminerViewer::ToolsRefPathStartCB();
2548 }                                                2493 }
2549                                                  2494 
2550                                                  2495 
2551 void G4OpenInventorQtExaminerViewer::ToolsRef    2496 void G4OpenInventorQtExaminerViewer::ToolsRefPathStartCB()
2552 {                                                2497 {
2553    if (!refParticleTrajectory.size()) {          2498    if (!refParticleTrajectory.size()) {
2554       QMessageBox msgbox;                        2499       QMessageBox msgbox;
2555       msgbox.setFont(*font);                     2500       msgbox.setFont(*font);
2556       QString messagetxt = "No current refere    2501       QString messagetxt = "No current reference path";
2557       msgbox.setText(messagetxt);                2502       msgbox.setText(messagetxt);
2558       msgbox.exec();                             2503       msgbox.exec();
2559       return;                                    2504       return;
2560    }                                             2505    }
2561                                                  2506 
2562    if (currentState == ROTATING)                 2507    if (currentState == ROTATING)
2563       return;                                    2508       return;
2564    if (currentState == ANIMATION || currentSt    2509    if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
2565        || currentState == PAUSED_ANIMATION) {    2510        || currentState == PAUSED_ANIMATION) {
2566       if (animateSensor->isScheduled())          2511       if (animateSensor->isScheduled())
2567          animateSensor->unschedule();            2512          animateSensor->unschedule();
2568       setSuperimpositionEnabled(superimpositi    2513       setSuperimpositionEnabled(superimposition, FALSE);
2569       maxSpeed = 0.0f;                           2514       maxSpeed = 0.0f;
2570       scheduleRedraw();                          2515       scheduleRedraw();
2571    } else {                                      2516    } else {
2572       saveCurCamera();                           2517       saveCurCamera();
2573       prevState = currentState;                  2518       prevState = currentState;
2574       prevRefIdx = refParticleIdx;               2519       prevRefIdx = refParticleIdx;
2575    }                                             2520    }
2576                                                  2521 
2577    if (SoQtExaminerViewer::isAnimating())        2522    if (SoQtExaminerViewer::isAnimating())
2578       stopAnimating();                           2523       stopAnimating();
2579                                                  2524 
2580    up_down = 0;                                  2525    up_down = 0;
2581    left_right = 0;                               2526    left_right = 0;
2582    step = 1;                                     2527    step = 1;
2583                                                  2528 
2584    refParticleIdx = 0;                           2529    refParticleIdx = 0;
2585    currentState = BEAMLINE;                      2530    currentState = BEAMLINE;
2586    setSuperimpositionEnabled(superimposition,    2531    setSuperimpositionEnabled(superimposition, TRUE);
2587    axisSwitch->whichChild.setValue(SO_SWITCH_    2532    axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2588    animSpeedOutlineSwitch->whichChild.setValu    2533    animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
2589    animSpeedSwitch->whichChild.setValue(SO_SW    2534    animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
2590    scheduleRedraw();                             2535    scheduleRedraw();
2591                                                  2536 
2592    // FWJ Disabled: this is set in moveCamera    2537    // FWJ Disabled: this is set in moveCamera()
2593    // Zoom in                                    2538    // Zoom in
2594    //   SoCamera *cam = getCamera();             2539    //   SoCamera *cam = getCamera();
2595    //   cam->focalDistance = 0.1f;               2540    //   cam->focalDistance = 0.1f;
2596                                                  2541 
2597    prevParticleDir = SbVec3f(0,0,0);             2542    prevParticleDir = SbVec3f(0,0,0);
2598                                                  2543 
2599    //Default zoom                                2544    //Default zoom
2600    SbVec3f p1 = refParticleTrajectory[0];        2545    SbVec3f p1 = refParticleTrajectory[0];
2601    SbVec3f pN = refParticleTrajectory[refPart    2546    SbVec3f pN = refParticleTrajectory[refParticleTrajectory.size() - 1];
2602    distance = (pN - p1).length() / 10;           2547    distance = (pN - p1).length() / 10;
2603                                                  2548 
2604    moveCamera(distance, true);                   2549    moveCamera(distance, true);
2605 }                                                2550 }
2606                                                  2551 
2607                                                  2552 
2608 void G4OpenInventorQtExaminerViewer::ToolsRef    2553 void G4OpenInventorQtExaminerViewer::ToolsRefPathInvertCB()
2609 {                                                2554 {
2610    invertRefPath();                              2555    invertRefPath();
2611 }                                                2556 }
2612                                                  2557 
2613                                                  2558 
2614 void G4OpenInventorQtExaminerViewer::invertRe    2559 void G4OpenInventorQtExaminerViewer::invertRefPath()
2615 {                                                2560 {
2616    std::reverse(refParticleTrajectory.begin()    2561    std::reverse(refParticleTrajectory.begin(),
2617                 refParticleTrajectory.end());    2562                 refParticleTrajectory.end());
2618    setReferencePathZPos();                       2563    setReferencePathZPos();
2619    sortElements();                               2564    sortElements();
2620 }                                                2565 }
2621                                                  2566 
2622                                                  2567 
2623 void G4OpenInventorQtExaminerViewer::animateR    2568 void G4OpenInventorQtExaminerViewer::animateRefParticle()
2624 {                                                2569 {
2625    SoCamera *cam = getCamera();                  2570    SoCamera *cam = getCamera();
2626                                                  2571 
2627    camStartPos = cam->position.getValue();       2572    camStartPos = cam->position.getValue();
2628    camStartOrient = cam->orientation.getValue    2573    camStartOrient = cam->orientation.getValue();
2629                                                  2574 
2630    if (currentState != BEAMLINE)                 2575    if (currentState != BEAMLINE)
2631       setStartingPtForAnimation();               2576       setStartingPtForAnimation();
2632                                                  2577 
2633    camEndPos = myCam->position.getValue();       2578    camEndPos = myCam->position.getValue();
2634    camEndOrient = myCam->orientation.getValue    2579    camEndOrient = myCam->orientation.getValue();
2635                                                  2580 
2636    if (animateSensor->isScheduled())             2581    if (animateSensor->isScheduled())
2637       animateSensor->unschedule();               2582       animateSensor->unschedule();
2638                                                  2583 
2639    animateSensor->setBaseTime(SbTime::getTime    2584    animateSensor->setBaseTime(SbTime::getTimeOfDay());
2640    animateSensor->setInterval(SbTime(0.02));     2585    animateSensor->setInterval(SbTime(0.02));
2641                                                  2586 
2642    animateSensor->schedule();                    2587    animateSensor->schedule();
2643 }                                                2588 }
2644                                                  2589 
2645                                                  2590 
2646 #if QT_VERSION < 0x060000                     << 
2647 void G4OpenInventorQtExaminerViewer::addEscap    2591 void G4OpenInventorQtExaminerViewer::addEscapeCallback(void (*callback)())
2648 {                                                2592 {
2649    escapeCallback = callback;                    2593    escapeCallback = callback;
2650 }                                                2594 }
2651 #endif                                        << 2595 
2652                                                  2596 
2653 void G4OpenInventorQtExaminerViewer::sceneCha    2597 void G4OpenInventorQtExaminerViewer::sceneChangeCB(void* userData, SoSensor*)
2654 {                                                2598 {
2655    // FWJ DEBUG                                  2599    // FWJ DEBUG
2656    //   G4cout << "SCENE CHANGE callback" <<     2600    //   G4cout << "SCENE CHANGE callback" << G4endl;
2657    // NOTE: could/should be disabled during a    2601    // NOTE: could/should be disabled during animation
2658                                                  2602 
2659    G4OpenInventorQtExaminerViewer* This =        2603    G4OpenInventorQtExaminerViewer* This =
2660       (G4OpenInventorQtExaminerViewer*)userDa    2604       (G4OpenInventorQtExaminerViewer*)userData;
2661    if(This->newEvents) {                         2605    if(This->newEvents) {
2662       This->findAndSetRefPath();                 2606       This->findAndSetRefPath();
2663       This->newEvents = false;                   2607       This->newEvents = false;
2664    }                                             2608    }
2665 }                                                2609 }
2666                                                  2610 
2667                                                  2611 
2668 //////////////////////////////////// BOOKMARK    2612 //////////////////////////////////// BOOKMARKS ///////////////////////////
2669                                                  2613 
2670 // Adds bookmarks to listsDialog.                2614 // Adds bookmarks to listsDialog.
2671                                                  2615 
2672 void G4OpenInventorQtExaminerViewer::addViewP    2616 void G4OpenInventorQtExaminerViewer::addViewPoints()
2673 {                                                2617 {
2674    std::size_t size = viewPtList.size();      << 2618    int size = viewPtList.size();
2675    if (!size) return;                            2619    if (!size) return;
2676                                                  2620 
2677    for (std::size_t i = 0; i < size; ++i) {   << 2621    for (int i = 0; i < size; i++) {
2678 #if QT_VERSION < 0x060000                     << 
2679       new QListWidgetItem(viewPtList[i].viewP    2622       new QListWidgetItem(viewPtList[i].viewPtName,
2680                           AuxWindowDialog->li << 2623                           AuxWindowDialog->listWidget); 
2681 #else                                         << 
2682       new QListWidgetItem(viewPtList[i].viewP << 
2683                           AuxWindowDialog->li << 
2684 #endif                                        << 
2685    }                                             2624    }
2686 }                                                2625 }
2687                                                  2626 
2688                                                  2627 
2689 // Converts a string type word into a float t    2628 // Converts a string type word into a float type.
2690                                                  2629 
2691 template<class T>                                2630 template<class T> 
2692 void G4OpenInventorQtExaminerViewer::parseStr    2631 void G4OpenInventorQtExaminerViewer::parseString(T &t, const std::string &s,
2693                                                  2632                                                  bool &error) 
2694 {                                                2633 {
2695    std::istringstream str(s);                    2634    std::istringstream str(s);
2696    if ((str >> t).fail())                        2635    if ((str >> t).fail())
2697       error = true;                              2636       error = true;
2698 }                                                2637 }
2699                                                  2638 
2700                                                  2639 
2701 void                                             2640 void
2702 G4OpenInventorQtExaminerViewer::FileOpenBookm    2641 G4OpenInventorQtExaminerViewer::FileOpenBookmarkCB()
2703 {                                                2642 {
2704    // FWJ DEBUG                                  2643    // FWJ DEBUG
2705    //   G4cout << "File: Open Bookmark File C    2644    //   G4cout << "File: Open Bookmark File CALLBACK" << G4endl;
2706    QFileDialog filedialog(getParentWidget(),     2645    QFileDialog filedialog(getParentWidget(), tr("Open bookmark file"));
2707    filedialog.setFileMode(QFileDialog::Existi    2646    filedialog.setFileMode(QFileDialog::ExistingFile);
2708    filedialog.setFont(*font);                    2647    filedialog.setFont(*font);
2709    if (!filedialog.exec()) return;               2648    if (!filedialog.exec()) return;
2710    QStringList filenameinlist = filedialog.se    2649    QStringList filenameinlist = filedialog.selectedFiles();
2711    QString filenamein = filenameinlist[0];       2650    QString filenamein = filenameinlist[0];
2712                                                  2651 
                                                   >> 2652    char* filename = new char[filenamein.size()+1];
                                                   >> 2653    filename = strdup(qPrintable(filenamein));
                                                   >> 2654    //   G4cout << "char[] file name is " << filename << G4endl;
                                                   >> 2655 
2713    fileIn.close();                               2656    fileIn.close();
2714    fileIn.open(qPrintable(filenamein));       << 2657    fileIn.open(filename);
2715    if (fileIn.fail()) {                          2658    if (fileIn.fail()) {
2716       QMessageBox msgbox;                        2659       QMessageBox msgbox;
2717       msgbox.setFont(*font);                     2660       msgbox.setFont(*font);
2718       QString messagetxt = "Error opening fil    2661       QString messagetxt = "Error opening file: ";
2719       messagetxt.append(filenamein);             2662       messagetxt.append(filenamein);
2720       msgbox.setText(messagetxt);                2663       msgbox.setText(messagetxt);
2721       msgbox.exec();                             2664       msgbox.exec();
2722       //      G4cout << "ERROR opening file "    2665       //      G4cout << "ERROR opening file " << filename << G4endl;
2723       fileIn.clear();                            2666       fileIn.clear();
2724       return;                                    2667       return;
2725    }                                             2668    }
2726    // Opens a file without erasing it            2669    // Opens a file without erasing it
2727    cleanUpAfterPrevFile();                       2670    cleanUpAfterPrevFile();
2728                                                  2671 
2729    if (!loadViewPts()) {                         2672    if (!loadViewPts()) {
2730       QMessageBox msgbox;                        2673       QMessageBox msgbox;
2731       msgbox.setFont(*font);                     2674       msgbox.setFont(*font);
2732       QString messagetxt = "Error reading boo    2675       QString messagetxt = "Error reading bookmark file: ";
2733       messagetxt.append(filenamein);             2676       messagetxt.append(filenamein);
2734       msgbox.setText(messagetxt);                2677       msgbox.setText(messagetxt);
2735       msgbox.exec();                             2678       msgbox.exec();
2736       //      G4cout << "ERROR reading bookma    2679       //      G4cout << "ERROR reading bookmark file " << filename << G4endl;
2737       fileIn.clear();                            2680       fileIn.clear();
2738       return;                                    2681       return;
2739    }                                             2682    }
2740                                                  2683 
2741    fileName = qPrintable(filenamein);         << 2684    fileName = filename;
2742    fileOut.open(fileName.c_str(), std::ios::i    2685    fileOut.open(fileName.c_str(), std::ios::in);
2743    fileOut.seekp(0, std::ios::end);              2686    fileOut.seekp(0, std::ios::end);
2744                                                  2687 
2745    addViewPoints();                              2688    addViewPoints();
2746                                                  2689 
2747    // LATER: display filename in lists window    2690    // LATER: display filename in lists window
2748                                                  2691 
2749    fileIn.close();                               2692    fileIn.close();
2750    fileIn.clear();                               2693    fileIn.clear();
2751 }                                                2694 }
2752                                                  2695 
2753 // Called before loading a new viewpoint file    2696 // Called before loading a new viewpoint file. 
2754 // Resets member fields to default values.       2697 // Resets member fields to default values.
2755                                                  2698 
2756 void G4OpenInventorQtExaminerViewer::cleanUpA    2699 void G4OpenInventorQtExaminerViewer::cleanUpAfterPrevFile()
2757 {                                                2700 {
2758    viewPtIdx = -1;                               2701    viewPtIdx = -1;
2759    viewPtList.clear();                           2702    viewPtList.clear();
2760    //   setSuperimpositionEnabled(superimposi    2703    //   setSuperimpositionEnabled(superimposition, FALSE);
2761    //   scheduleRedraw();                        2704    //   scheduleRedraw();
2762    currentState = GENERAL;                       2705    currentState = GENERAL;
2763    if (fileOut.is_open()) fileOut.close();       2706    if (fileOut.is_open()) fileOut.close();
2764                                                  2707 
2765    AuxWindowDialog->listWidget->clear();         2708    AuxWindowDialog->listWidget->clear();   
2766    AuxWindowDialog->lineEdit->setText(QString    2709    AuxWindowDialog->lineEdit->setText(QString(""));
2767 }                                                2710 }
2768                                                  2711 
2769                                                  2712 
2770 void                                             2713 void
2771 G4OpenInventorQtExaminerViewer::FileNewBookma    2714 G4OpenInventorQtExaminerViewer::FileNewBookmarkCB()
2772 {                                                2715 {
2773    //   G4cout << "File: Open New Bookmark Fi    2716    //   G4cout << "File: Open New Bookmark File CALLBACK" << G4endl;
2774    QFileDialog filedialog(getParentWidget(),     2717    QFileDialog filedialog(getParentWidget(), tr("Open new bookmark file"));
2775    filedialog.setFileMode(QFileDialog::AnyFil    2718    filedialog.setFileMode(QFileDialog::AnyFile);
2776    // To enable confirmation of overwriting      2719    // To enable confirmation of overwriting
2777    filedialog.setAcceptMode(QFileDialog::Acce    2720    filedialog.setAcceptMode(QFileDialog::AcceptSave);
2778    // But change the "Save" button text          2721    // But change the "Save" button text
2779    filedialog.setLabelText(QFileDialog::Accep    2722    filedialog.setLabelText(QFileDialog::Accept, QString("New"));
2780    filedialog.setFont(*font);                    2723    filedialog.setFont(*font);
2781    if (!filedialog.exec()) return;               2724    if (!filedialog.exec()) return;
2782    QStringList filenameinlist = filedialog.se    2725    QStringList filenameinlist = filedialog.selectedFiles();
2783    QString filenamein = filenameinlist[0];       2726    QString filenamein = filenameinlist[0];
2784                                                  2727 
                                                   >> 2728    //   G4cout << "Input file name is " << qPrintable(filenamein) << G4endl;
                                                   >> 2729 
                                                   >> 2730    char* filename = new char[filenamein.size()+1];
                                                   >> 2731    filename = strdup(qPrintable(filenamein));
                                                   >> 2732    //   G4cout << "char[] file name is " << filename << G4endl;
                                                   >> 2733 
2785    cleanUpAfterPrevFile();                       2734    cleanUpAfterPrevFile();
2786    fileName = qPrintable(filenamein);         << 2735    fileName = filename;
2787    fileOut.open(fileName.c_str());               2736    fileOut.open(fileName.c_str());
2788    if (fileOut.fail()) {                         2737    if (fileOut.fail()) {
2789       QMessageBox msgbox;                        2738       QMessageBox msgbox;
2790       msgbox.setFont(*font);                     2739       msgbox.setFont(*font);
2791       QString messagetxt = "Error opening new    2740       QString messagetxt = "Error opening new bookmark file: ";
2792       messagetxt.append(filenamein);             2741       messagetxt.append(filenamein);
2793       msgbox.setText(messagetxt);                2742       msgbox.setText(messagetxt);
2794       msgbox.exec();                             2743       msgbox.exec();
2795       // G4cout << "ERROR opening new bookmar    2744       // G4cout << "ERROR opening new bookmark file " << filename << G4endl;
2796    }                                             2745    }
2797 }                                                2746 }
2798                                                  2747 
2799                                                  2748 
2800 void                                             2749 void
2801 G4OpenInventorQtExaminerViewer::ToolsAnimateR    2750 G4OpenInventorQtExaminerViewer::ToolsAnimateRefParticleCB()
2802 {                                                2751 {
2803    //   G4cout << "Tools: Animate Ref Particl    2752    //   G4cout << "Tools: Animate Ref Particle CALLBACK" << G4endl;
2804    if (!refParticleTrajectory.size()) {          2753    if (!refParticleTrajectory.size()) {
2805       returnToAnim = true;                       2754       returnToAnim = true;
2806       G4warn << "No Reference Trajectory" <<  << 2755       G4cout << "No Reference Trajectory" << G4endl;
2807       return;                                    2756       return;
2808    }                                             2757    }
2809                                                  2758 
2810    //////////////////////////////////////////    2759    ///////////////////////////////////////////////////////////////
2811    setSuperimpositionEnabled(superimposition,    2760    setSuperimpositionEnabled(superimposition, TRUE);
2812    maxSpeed = SPEED_INDICATOR_STEP;              2761    maxSpeed = SPEED_INDICATOR_STEP;
2813    axisSwitch->whichChild.setValue(SO_SWITCH_    2762    axisSwitch->whichChild.setValue(SO_SWITCH_ALL);
2814    animSpeedOutlineSwitch->whichChild.setValu    2763    animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_ALL);
2815    animSpeedSwitch->whichChild.setValue(SO_SW    2764    animSpeedSwitch->whichChild.setValue(SO_SWITCH_ALL);
2816    scheduleRedraw();                             2765    scheduleRedraw();
2817    //////////////////////////////////////////    2766    ///////////////////////////////////////////////////////////////
2818                                                  2767 
2819    SoCamera *cam = getCamera();                  2768    SoCamera *cam = getCamera();
2820    //   SbVec3f camDirOld, camDirNew, camDirN    2769    //   SbVec3f camDirOld, camDirNew, camDirNew_tmp, camUpVec, P0, P1, P1_tmp;
2821                                                  2770 
2822    if (currentState == ANIMATION || currentSt    2771    if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
2823        || currentState == ROTATING)              2772        || currentState == ROTATING)
2824       return;                                    2773       return;
2825                                                  2774 
2826    if (currentState != PAUSED_ANIMATION) {       2775    if (currentState != PAUSED_ANIMATION) {
2827                                                  2776 
2828       saveCurCamera();                           2777       saveCurCamera();
2829       prevState = currentState;                  2778       prevState = currentState;
2830       prevRefIdx = refParticleIdx;               2779       prevRefIdx = refParticleIdx;
2831                                                  2780 
2832       if (cam->isOfType(SoOrthographicCamera:    2781       if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2833          toggleCameraType();                     2782          toggleCameraType();
2834          cam = getCamera();                      2783          cam = getCamera();
2835       }                                          2784       }
2836                                                  2785 
2837       refParticleIdx = 0; // Set the camera t    2786       refParticleIdx = 0; // Set the camera to the starting point of the animation
2838       animateBtwPtsPeriod = MIN_SPEED;           2787       animateBtwPtsPeriod = MIN_SPEED;
2839       speedStep = START_STEP;                    2788       speedStep = START_STEP;
2840       left_right = up_down = 0;                  2789       left_right = up_down = 0;
2841                                                  2790 
2842       cam->focalDistance = 0.1f;                 2791       cam->focalDistance = 0.1f;
2843       ((SoPerspectiveCamera *) cam)->heightAn    2792       ((SoPerspectiveCamera *) cam)->heightAngle = 0.50f;
2844    }                                             2793    }
2845                                                  2794 
2846    currentState = ANIMATION;                     2795    currentState = ANIMATION;
2847    setStartingPtForAnimation();                  2796    setStartingPtForAnimation();
2848                                                  2797 
2849    cam->position = (myCam)->position.getValue    2798    cam->position = (myCam)->position.getValue();
2850    cam->orientation = (myCam)->orientation.ge    2799    cam->orientation = (myCam)->orientation.getValue();
2851    animateRefParticle(); // Animate the camer    2800    animateRefParticle(); // Animate the camera
2852 }                                                2801 }
2853                                                  2802 
2854                                                  2803 
2855 void                                             2804 void
2856 G4OpenInventorQtExaminerViewer::SaveViewPtCB(    2805 G4OpenInventorQtExaminerViewer::SaveViewPtCB()
2857 {                                                2806 {
2858    //   G4cout << "AppButton: Save Viewpoint     2807    //   G4cout << "AppButton: Save Viewpoint CALLBACK" << G4endl;
2859    // First get viewpoint name ...               2808    // First get viewpoint name ...
2860    // EMULATING getViewPtNameCB ...              2809    // EMULATING getViewPtNameCB ...
2861    //   bool ok;                                 2810    //   bool ok;
2862    // Note QString() returns an empty string     2811    // Note QString() returns an empty string
2863 #if 0x060000 <= QT_VERSION                    << 2812    
2864    //G.Barrand: map the AuxWindow here. Then  << 
2865    //           and not systematically when c << 
2866    //           Moreover, if "closing" the Au << 
2867    //           it permits to map it back.    << 
2868    AuxWindow->show();                         << 
2869    AuxWindow->raise();                        << 
2870    AuxWindow->activateWindow();               << 
2871 #endif                                        << 
2872                                               << 
2873    // NONE OF THE FOLLOWING CHANGES THE FONT:    2813    // NONE OF THE FOLLOWING CHANGES THE FONT: FORGET IT FOR NOW
2874    QInputDialog* inputdialog = new QInputDial    2814    QInputDialog* inputdialog = new QInputDialog(getParentWidget());
2875    inputdialog->setFont(*font);                  2815    inputdialog->setFont(*font);
2876    inputdialog->setWindowTitle(tr("Enter a na    2816    inputdialog->setWindowTitle(tr("Enter a name for the bookmark"));
2877    inputdialog->setLabelText("Bookmark name")    2817    inputdialog->setLabelText("Bookmark name");
2878    //   inputdialog->setTextEchoMode(QLineEdi    2818    //   inputdialog->setTextEchoMode(QLineEdit::Normal);
2879    inputdialog->adjustSize();                    2819    inputdialog->adjustSize();
2880    QString namein;                               2820    QString namein;
2881    if (inputdialog->exec() == QDialog::Accept    2821    if (inputdialog->exec() == QDialog::Accepted)
2882       namein=inputdialog->textValue().trimmed    2822       namein=inputdialog->textValue().trimmed();
2883    else                                          2823    else
2884       return;                                    2824       return;
2885    if (namein.isEmpty()) return;                 2825    if (namein.isEmpty()) return;
2886                                                  2826 
2887    // This easier approach failed: unable to     2827    // This easier approach failed: unable to set font size
2888    //   QString namein =                         2828    //   QString namein = 
2889    //      QInputDialog::getText(getParentWid    2829    //      QInputDialog::getText(getParentWidget(),
2890    //                            tr("Enter a     2830    //                            tr("Enter a name for the bookmark"),
2891    //                            tr("Bookmark    2831    //                            tr("Bookmark name"), QLineEdit::Normal,
2892    //                            QString(), &    2832    //                            QString(), &ok);
2893                                                  2833 
                                                   >> 2834    const int nVPName = MAX_VP_NAME + 1;
                                                   >> 2835    char* name = new char[nVPName];
                                                   >> 2836    //   strncpy(name, strName.c_str(), nVPName);
2894    namein.truncate(MAX_VP_NAME);                 2837    namein.truncate(MAX_VP_NAME);
2895                                                  2838 
2896    char* name = strdup(qPrintable(namein));   << 2839    QByteArray ba = namein.toLocal8Bit();
                                                   >> 2840    name = strdup(ba.constData());
                                                   >> 2841    // name = strdup(qPrintable(namein))
2897                                                  2842 
2898    // FWJ DEBUG                                  2843    // FWJ DEBUG
2899    //   G4cout << "QString is " << qPrintable    2844    //   G4cout << "QString is " << qPrintable(namein) << G4endl;
2900    //   G4cout << "char[] is  " << name << G4    2845    //   G4cout << "char[] is  " << name << G4endl;
2901                                                  2846 
2902    for (int i = 0; i < (int)viewPtList.size()    2847    for (int i = 0; i < (int)viewPtList.size(); i++) {
2903 #if QT_VERSION < 0x060000                     << 
2904       if (!strcmp(name, viewPtList[i].viewPtN    2848       if (!strcmp(name, viewPtList[i].viewPtName)) {
2905 #else                                         << 
2906       if (!strcmp(name, viewPtList[i].viewPtN << 
2907 #endif                                        << 
2908          QMessageBox msgbox;                     2849          QMessageBox msgbox;
2909          msgbox.setText("Bookmark name is alr    2850          msgbox.setText("Bookmark name is already in use");
2910          msgbox.exec();                          2851          msgbox.exec();
2911          free(name);                          << 
2912          return;                                 2852          return;
2913       }                                          2853       }
2914    }                                             2854    }
2915                                                  2855 
2916    if (viewPtIdx == -1) viewPtIdx = 0;           2856    if (viewPtIdx == -1) viewPtIdx = 0;
2917    saveViewPt(name);                             2857    saveViewPt(name);
2918                                                  2858 
2919    saveViewPtItem = new QListWidgetItem(namei    2859    saveViewPtItem = new QListWidgetItem(namein,
2920                                         AuxWi    2860                                         AuxWindowDialog->listWidget);
2921    AuxWindowDialog->listWidget->setCurrentIte    2861    AuxWindowDialog->listWidget->setCurrentItem(saveViewPtItem);
2922    AuxWindowDialog->lineEdit->setText(namein)    2862    AuxWindowDialog->lineEdit->setText(namein);
2923    free(name);                                << 
2924 }                                                2863 }
2925                                                  2864 
2926                                                  2865 
2927 // Saves current camera parameters to a viewp    2866 // Saves current camera parameters to a viewpoint file.
2928                                                  2867 
2929 void G4OpenInventorQtExaminerViewer::saveView    2868 void G4OpenInventorQtExaminerViewer::saveViewPt(char *name)
2930 {                                                2869 {
2931    SbVec3f axis;                                 2870    SbVec3f axis;
2932    viewPtData tmp;                               2871    viewPtData tmp;
2933    float x, y, z, angle;                         2872    float x, y, z, angle;
2934    SoCamera* camera = getCamera();               2873    SoCamera* camera = getCamera();
2935                                                  2874 
2936    // NOTE: Xt VSN increments this at end of     2875    // NOTE: Xt VSN increments this at end of procedure
2937    //   viewPtIdx++;                             2876    //   viewPtIdx++;
2938                                                  2877 
2939    //  FWJ DEBUG                                 2878    //  FWJ DEBUG
2940    //   G4cout << "saveViewPt: saving bookmar    2879    //   G4cout << "saveViewPt: saving bookmark " << viewPtIdx << " " << name
2941    //          << G4endl;                        2880    //          << G4endl;
2942                                                  2881 
2943    if (viewPtList.size() == 0) {                 2882    if (viewPtList.size() == 0) {
2944       writeViewPtIdx();                          2883       writeViewPtIdx();
2945    }                                             2884    }
2946                                                  2885 
2947 #if QT_VERSION < 0x060000                     << 
2948    tmp.viewPtName = name;                        2886    tmp.viewPtName = name;
2949 #else                                         << 
2950    tmp.viewPtName = std::string(name);        << 
2951 #endif                                        << 
2952    tmp.viewportMapping = camera->viewportMapp    2887    tmp.viewportMapping = camera->viewportMapping.getValue();
2953    tmp.position = camera->position.getValue()    2888    tmp.position = camera->position.getValue();
2954    tmp.orientation = camera->orientation.getV    2889    tmp.orientation = camera->orientation.getValue();
2955    tmp.aspectRatio = camera->aspectRatio.getV    2890    tmp.aspectRatio = camera->aspectRatio.getValue();
2956    tmp.nearDistance = camera->nearDistance.ge    2891    tmp.nearDistance = camera->nearDistance.getValue();
2957    tmp.farDistance = camera->farDistance.getV    2892    tmp.farDistance = camera->farDistance.getValue();
2958    tmp.focalDistance = camera->focalDistance.    2893    tmp.focalDistance = camera->focalDistance.getValue();
2959                                                  2894 
2960    // Save camera height (changed by zooming)    2895    // Save camera height (changed by zooming)
2961    if (camera->isOfType(SoPerspectiveCamera::    2896    if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2962       tmp.height = ((SoPerspectiveCamera *) c    2897       tmp.height = ((SoPerspectiveCamera *) camera)->heightAngle.getValue();
2963       tmp.camType = PERSPECTIVE;                 2898       tmp.camType = PERSPECTIVE;
2964    } else if (camera->isOfType(SoOrthographic    2899    } else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
2965       tmp.height = ((SoOrthographicCamera *)     2900       tmp.height = ((SoOrthographicCamera *) camera)->height.getValue();
2966       tmp.camType = ORTHOGRAPHIC;                2901       tmp.camType = ORTHOGRAPHIC;
2967    } else {                                      2902    } else {
2968       SoDebugError::post("G4OpenInventorQtExa    2903       SoDebugError::post("G4OpenInventorQtExaminerViewer::saveViewPtCB",
2969                          "Only Perspective an    2904                          "Only Perspective and Orthographic cameras are supported.");
2970       return;                                    2905       return;
2971    }                                             2906    }
2972                                                  2907 
2973    viewPtList.push_back(tmp);                    2908    viewPtList.push_back(tmp);
2974                                                  2909 
2975    // Now save the view point to a .txt file     2910    // Now save the view point to a .txt file
2976    // FWJ DEBUG                                  2911    // FWJ DEBUG
2977    // G4cout << "saveViewPt: writing to Bookm    2912    // G4cout << "saveViewPt: writing to Bookmark file " << fileName << G4endl;
2978                                                  2913 
2979    std::string vpName = name;                    2914    std::string vpName = name;
2980                                                  2915 
2981    while ((int) vpName.size() <= MAX_VP_NAME)    2916    while ((int) vpName.size() <= MAX_VP_NAME)
2982       vpName += " ";                             2917       vpName += " ";
2983                                                  2918 
2984    fileOut << vpName << std::endl;               2919    fileOut << vpName << std::endl;
2985    tmp.position.getValue(x, y, z);               2920    tmp.position.getValue(x, y, z);
2986    fileOut << x << " " << y << " " << z << st    2921    fileOut << x << " " << y << " " << z << std::endl;
2987                                                  2922 
2988    // Reusing x, y and z for storing the axis    2923    // Reusing x, y and z for storing the axis
2989    tmp.orientation.getValue(axis, angle);        2924    tmp.orientation.getValue(axis, angle);
2990    axis.getValue(x, y, z);                       2925    axis.getValue(x, y, z);
2991    fileOut << x << " " << y << " " << z << "     2926    fileOut << x << " " << y << " " << z << " " << angle << std::endl;
2992                                                  2927 
2993    fileOut << tmp.camType << " " << tmp.heigh    2928    fileOut << tmp.camType << " " << tmp.height << std::endl;
2994    fileOut << tmp.focalDistance << " ";          2929    fileOut << tmp.focalDistance << " ";
2995    fileOut << tmp.nearDistance << " ";           2930    fileOut << tmp.nearDistance << " ";
2996    fileOut << tmp.farDistance << std::endl;      2931    fileOut << tmp.farDistance << std::endl;
2997    fileOut << tmp.viewportMapping << " ";        2932    fileOut << tmp.viewportMapping << " ";
2998    fileOut << tmp.aspectRatio << "\n" << std:    2933    fileOut << tmp.aspectRatio << "\n" << std::endl;
2999    fileOut.flush();                              2934    fileOut.flush();
3000                                                  2935 
3001    viewPtIdx++;                                  2936    viewPtIdx++;
3002                                                  2937 
3003    // FWJ DEBUG                                  2938    // FWJ DEBUG
3004    //   G4cout << "saveViewPt: finished writi    2939    //   G4cout << "saveViewPt: finished writing to file" << G4endl <<
3005    //      "  Next viewPtIdx is " << viewPtId    2940    //      "  Next viewPtIdx is " << viewPtIdx << G4endl;
3006 }                                                2941 }
3007                                                  2942 
3008                                                  2943 
3009 // Updates the viewPtIdx in a viewpoint file.    2944 // Updates the viewPtIdx in a viewpoint file.
3010                                                  2945 
3011 void G4OpenInventorQtExaminerViewer::writeVie    2946 void G4OpenInventorQtExaminerViewer::writeViewPtIdx()
3012 {                                                2947 {
3013    std::string idxStr;                           2948    std::string idxStr;
3014    std::stringstream out;                        2949    std::stringstream out;
3015                                                  2950 
3016    out << viewPtIdx;                             2951    out << viewPtIdx;
3017    idxStr = out.str();                           2952    idxStr = out.str();
3018    fileOut.seekp(0, std::ios::beg);              2953    fileOut.seekp(0, std::ios::beg);
3019                                                  2954 
3020    while ((int) idxStr.length() < MAX_VP_IDX)    2955    while ((int) idxStr.length() < MAX_VP_IDX) {
3021       idxStr += " ";                             2956       idxStr += " ";
3022    }                                             2957    }
3023                                                  2958 
3024    // FWJ DEBUG                                  2959    // FWJ DEBUG
3025    //   G4cout << "writeViewPtIdx: " << viewP    2960    //   G4cout << "writeViewPtIdx: " << viewPtIdx << G4endl;
3026    fileOut << idxStr << "\n";                    2961    fileOut << idxStr << "\n";
3027    fileOut.flush();                              2962    fileOut.flush();
3028    fileOut.seekp(0, std::ios::end);              2963    fileOut.seekp(0, std::ios::end);
3029 }                                                2964 }
3030                                                  2965 
3031                                                  2966 
3032 // Receives the name of the bookmark clicked     2967 // Receives the name of the bookmark clicked and searches for it in viewPtList.
3033                                                  2968 
3034 void G4OpenInventorQtExaminerViewer::LoadBook    2969 void G4OpenInventorQtExaminerViewer::LoadBookmarkCB(QListWidgetItem* item)
3035 {                                                2970 {
3036    // FWJ DEBUG                                  2971    // FWJ DEBUG
3037    //   G4cout << "AuxWindow: listWidget Load    2972    //   G4cout << "AuxWindow: listWidget LoadBookmark CALLBACK" << G4endl;
3038                                                  2973 
                                                   >> 2974    const int nVPName = MAX_VP_NAME + 1;
                                                   >> 2975    char* vpName = new char[nVPName];
                                                   >> 2976 
                                                   >> 2977    vpName = strdup(qPrintable(item->text()));
                                                   >> 2978    //   G4cout << "LOOKING FOR BOOKMARK " << vpName << G4endl;
                                                   >> 2979 
3039    for (int i = 0; i < (int)viewPtList.size()    2980    for (int i = 0; i < (int)viewPtList.size(); i++) {
3040 #if QT_VERSION < 0x060000                     << 2981       if (!strcmp(viewPtList[i].viewPtName, vpName)) {
3041       if (!strcmp(viewPtList[i].viewPtName, q << 
3042 #else                                         << 
3043       if (!strcmp(viewPtList[i].viewPtName.c_ << 
3044 #endif                                        << 
3045          viewPtIdx = i;                          2982          viewPtIdx = i;
3046          break;                                  2983          break;
3047       }                                          2984       }
3048    }                                             2985    }
3049    //   G4cout << "  FOUND viewPtIdx " << vie    2986    //   G4cout << "  FOUND viewPtIdx " << viewPtIdx << G4endl;
3050                                                  2987 
3051    writeViewPtIdx();                             2988    writeViewPtIdx();
3052    setViewPt();                                  2989    setViewPt();
3053    AuxWindowDialog->lineEdit->setText(item->t    2990    AuxWindowDialog->lineEdit->setText(item->text());
3054 }                                                2991 }
3055                                                  2992 
3056                                                  2993 
3057 // Sets the viewpoint based on camera data th    2994 // Sets the viewpoint based on camera data that viewPtIdx is pointing to.
3058                                                  2995 
3059 void G4OpenInventorQtExaminerViewer::setViewP    2996 void G4OpenInventorQtExaminerViewer::setViewPt()
3060 {                                                2997 {
3061    if (currentState == ANIMATION || currentSt    2998    if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
3062        || currentState == ROTATING) {            2999        || currentState == ROTATING) {
3063       if (animateSensor->isScheduled()) anima    3000       if (animateSensor->isScheduled()) animateSensor->unschedule();
3064       setSuperimpositionEnabled(superimpositi    3001       setSuperimpositionEnabled(superimposition, FALSE);
3065       maxSpeed = 0.0f;                           3002       maxSpeed = 0.0f;
3066       scheduleRedraw();                          3003       scheduleRedraw();
3067    }                                             3004    }
3068                                                  3005 
3069    SoCamera * camera = getCamera();              3006    SoCamera * camera = getCamera();
3070    if (camera == NULL) {                         3007    if (camera == NULL) {
3071       G4warn << "setViewPt: Camera is null. U << 3008       G4cout << "setViewPt: Camera is null. Unable to set the viewpoint." <<
3072          G4endl;                                 3009          G4endl;
3073       //      String dialogName = (char *) "M    3010       //      String dialogName = (char *) "Missing Camera Node";
3074       //      std::string msg = "Camera is nu    3011       //      std::string msg = "Camera is null. Unable to set the viewpoint.";
3075       //      warningMsgDialog(msg, dialogNam    3012       //      warningMsgDialog(msg, dialogName, NULL);
3076       return;                                    3013       return;
3077    }                                             3014    }
3078                                                  3015 
3079    if (!viewPtList.size()) {                     3016    if (!viewPtList.size()) {
3080       G4warn << "setViewPt: There are no view << 3017       G4cout << "setViewPt: There are no viewpoints to load." << G4endl;
3081       //      String dialogName = (char *) "M    3018       //      String dialogName = (char *) "Missing Viewpoints";
3082       //      std::string msg = "There are no    3019       //      std::string msg = "There are no viewpoints to load.";
3083       //      warningMsgDialog(msg, dialogNam    3020       //      warningMsgDialog(msg, dialogName, NULL);
3084       return;                                    3021       return;
3085    }                                             3022    }
3086                                                  3023 
3087    if (SoQtExaminerViewer::isAnimating()) sto    3024    if (SoQtExaminerViewer::isAnimating()) stopAnimating();
3088                                                  3025 
3089    if (currentState != VIEWPOINT) {              3026    if (currentState != VIEWPOINT) {
3090       currentState = VIEWPOINT;                  3027       currentState = VIEWPOINT;
3091       ///////////////////////////////////////    3028       //////////////////////////////////////////////////////////////
3092       setSuperimpositionEnabled(superimpositi    3029       setSuperimpositionEnabled(superimposition, TRUE);
3093       axisSwitch->whichChild.setValue(SO_SWIT    3030       axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
3094       animSpeedOutlineSwitch->whichChild.setV    3031       animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
3095       animSpeedSwitch->whichChild.setValue(SO    3032       animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
3096       scheduleRedraw();                          3033       scheduleRedraw();
3097       ///////////////////////////////////////    3034       ///////////////////////////////////////////////////////////////
3098    }                                             3035    }
3099                                                  3036 
3100 #if QT_VERSION < 0x060000                     << 
3101 #else                                         << 
3102    if((viewPtIdx<0)||(viewPtIdx>=int(viewPtLi << 
3103      G4warn << "setViewPt: inconsitent viewPt << 
3104      return;                                  << 
3105    }                                          << 
3106 #endif                                        << 
3107                                               << 
3108    curViewPtName = viewPtList[viewPtIdx].view    3037    curViewPtName = viewPtList[viewPtIdx].viewPtName;
3109    camera->viewportMapping = viewPtList[viewP    3038    camera->viewportMapping = viewPtList[viewPtIdx].viewportMapping;
3110    camera->position = viewPtList[viewPtIdx].p    3039    camera->position = viewPtList[viewPtIdx].position;
3111    camera->orientation = viewPtList[viewPtIdx    3040    camera->orientation = viewPtList[viewPtIdx].orientation;
3112    camera->aspectRatio = viewPtList[viewPtIdx    3041    camera->aspectRatio = viewPtList[viewPtIdx].aspectRatio;
3113    camera->nearDistance = viewPtList[viewPtId    3042    camera->nearDistance = viewPtList[viewPtIdx].nearDistance;
3114    camera->farDistance = viewPtList[viewPtIdx    3043    camera->farDistance = viewPtList[viewPtIdx].farDistance;
3115    camera->focalDistance = viewPtList[viewPtI    3044    camera->focalDistance = viewPtList[viewPtIdx].focalDistance;
3116                                                  3045 
3117    // Restore camera height (changed by zoomi    3046    // Restore camera height (changed by zooming)
3118    if (camera->isOfType(SoPerspectiveCamera::    3047    if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3119       if (viewPtList[viewPtIdx].camType == OR    3048       if (viewPtList[viewPtIdx].camType == ORTHOGRAPHIC) {
3120          toggleCameraType();                     3049          toggleCameraType();
3121          camera = getCamera();                   3050          camera = getCamera();
3122          ((SoOrthographicCamera *) camera)->h    3051          ((SoOrthographicCamera *) camera)->height.setValue(
3123                                                  3052                                                             viewPtList[viewPtIdx].height);
3124       } else                                     3053       } else
3125          ((SoPerspectiveCamera *) camera)->he    3054          ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3126                                                  3055                                                                 viewPtList[viewPtIdx].height);
3127    } else if (camera->isOfType(SoOrthographic    3056    } else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
3128       if (viewPtList[viewPtIdx].camType == PE    3057       if (viewPtList[viewPtIdx].camType == PERSPECTIVE) {
3129          toggleCameraType();                     3058          toggleCameraType();
3130          camera = getCamera();                   3059          camera = getCamera();
3131          ((SoPerspectiveCamera *) camera)->he    3060          ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3132                                                  3061                                                                 viewPtList[viewPtIdx].height);
3133       } else                                     3062       } else
3134          ((SoOrthographicCamera *) camera)->h    3063          ((SoOrthographicCamera *) camera)->height.setValue(
3135                                                  3064                                                             viewPtList[viewPtIdx].height);
3136    } else {                                      3065    } else {
3137       SoDebugError::post("G4OpenInventorQtExa    3066       SoDebugError::post("G4OpenInventorQtExaminerViewer::setViewPt",
3138                          "Only Perspective an    3067                          "Only Perspective and Orthographic cameras are supported.");
3139       return;                                    3068       return;
3140    }                                             3069    }
3141                                                  3070 
3142 }                                                3071 }
3143                                                  3072 
3144                                                  3073 
3145 void G4OpenInventorQtExaminerViewer::NextView    3074 void G4OpenInventorQtExaminerViewer::NextViewPtCB()
3146 {                                                3075 {
3147    // FWJ DEBUG                                  3076    // FWJ DEBUG
3148    //   G4cout << "App Button: nextViewPt CAL    3077    //   G4cout << "App Button: nextViewPt CALLBACK" << G4endl;
3149                                                  3078 
3150    if (!viewPtList.size()) return;               3079    if (!viewPtList.size()) return;
3151    if (viewPtIdx >= (int)viewPtList.size() -     3080    if (viewPtIdx >= (int)viewPtList.size() - 1)
3152       viewPtIdx = 0;                             3081       viewPtIdx = 0;
3153 #if 0x060000 <= QT_VERSION                    << 
3154    else if (viewPtIdx<0)                      << 
3155       viewPtIdx = 0;                          << 
3156 #endif                                        << 
3157    else                                          3082    else
3158       viewPtIdx++;                               3083       viewPtIdx++;
3159                                                  3084 
3160    writeViewPtIdx();                             3085    writeViewPtIdx();
3161    setViewPt();                                  3086    setViewPt();
3162 #if QT_VERSION < 0x060000                     << 
3163    char* viewptname = viewPtList[viewPtIdx].v    3087    char* viewptname = viewPtList[viewPtIdx].viewPtName;
3164    AuxWindowDialog->lineEdit->setText(QString    3088    AuxWindowDialog->lineEdit->setText(QString(viewptname));
3165 #else                                         << 
3166    AuxWindowDialog->lineEdit->setText(QString << 
3167 #endif                                        << 
3168 }                                                3089 }
3169                                                  3090 
3170 void G4OpenInventorQtExaminerViewer::PrevView    3091 void G4OpenInventorQtExaminerViewer::PrevViewPtCB()
3171 {                                                3092 {
3172    // FWJ DEBUG                                  3093    // FWJ DEBUG
3173    //   G4cout << "App Button: prevViewPt CAL    3094    //   G4cout << "App Button: prevViewPt CALLBACK" << G4endl;
3174                                                  3095 
3175    if (!viewPtList.size()) return;               3096    if (!viewPtList.size()) return;
3176 #if QT_VERSION < 0x060000                     << 
3177    if (viewPtIdx == 0)                           3097    if (viewPtIdx == 0)
3178 #else                                         << 3098       viewPtIdx = viewPtList.size() - 1;
3179    if (viewPtIdx <= 0)                        << 
3180 #endif                                        << 
3181       viewPtIdx = (int) viewPtList.size() - 1 << 
3182    else                                          3099    else
3183       viewPtIdx--;                               3100       viewPtIdx--;
3184                                                  3101 
3185    writeViewPtIdx();                             3102    writeViewPtIdx();
3186    setViewPt();                                  3103    setViewPt();
3187 #if QT_VERSION < 0x060000                     << 
3188    char* viewptname = viewPtList[viewPtIdx].v    3104    char* viewptname = viewPtList[viewPtIdx].viewPtName;
3189    AuxWindowDialog->lineEdit->setText(QString    3105    AuxWindowDialog->lineEdit->setText(QString(viewptname));
3190 #else                                         << 
3191    AuxWindowDialog->lineEdit->setText(QString << 
3192 #endif                                        << 
3193 }                                                3106 }
3194                                                  3107 
3195                                                  3108 
3196 void G4OpenInventorQtExaminerViewer::AbbrOutp    3109 void G4OpenInventorQtExaminerViewer::AbbrOutputCB(bool checked)
3197 {                                                3110 {
3198    // FWJ DEBUG                                  3111    // FWJ DEBUG
3199    //   G4cout << "App Button: abbrOutput CAL    3112    //   G4cout << "App Button: abbrOutput CALLBACK" << G4endl;
3200                                                  3113 
3201    abbrOutputFlag = checked;                     3114    abbrOutputFlag = checked;
3202 }                                                3115 }
3203                                                  3116 
3204                                                  3117 
3205 void G4OpenInventorQtExaminerViewer::PickRefP    3118 void G4OpenInventorQtExaminerViewer::PickRefPathCB()
3206 {                                                3119 {
3207    // FWJ DEBUG                                  3120    // FWJ DEBUG
3208    //   G4cout << "App Button: pickRefPath CA    3121    //   G4cout << "App Button: pickRefPath CALLBACK" << G4endl;
3209                                                  3122 
3210    // Save viewing state and go to picking mo    3123    // Save viewing state and go to picking mode
3211    viewingBeforePickRef = isViewing();           3124    viewingBeforePickRef = isViewing();
3212    if(isViewing())                               3125    if(isViewing())
3213       setViewing(false);                         3126       setViewing(false);
3214    setComponentCursor(SoQtCursor(SoQtCursor::    3127    setComponentCursor(SoQtCursor(SoQtCursor::CROSSHAIR));
3215    pickRefPathFlag = true;                       3128    pickRefPathFlag = true;
3216 }                                                3129 }
3217                                                  3130 
3218                                                  3131 
3219 void G4OpenInventorQtExaminerViewer::SwitchWi    3132 void G4OpenInventorQtExaminerViewer::SwitchWireFrameCB(bool checked)
3220 {                                                3133 {
3221    // FWJ DEBUG                                  3134    // FWJ DEBUG
3222    //   G4cout << "App Button: switchWireFram    3135    //   G4cout << "App Button: switchWireFrame CALLBACK" << G4endl;
3223                                                  3136 
3224    //   if (switchWireFrameButton->isDown())     3137    //   if (switchWireFrameButton->isDown()) {
3225    if (checked) {                                3138    if (checked) {
3226       setDrawStyle(SoQtViewer::STILL, SoQtVie    3139       setDrawStyle(SoQtViewer::STILL, SoQtViewer::VIEW_LINE);
3227       setDrawStyle(SoQtViewer::INTERACTIVE, S    3140       setDrawStyle(SoQtViewer::INTERACTIVE, SoQtViewer::VIEW_LINE);
3228    } else {                                      3141    } else {
3229       setDrawStyle(SoQtViewer::STILL, SoQtVie    3142       setDrawStyle(SoQtViewer::STILL, SoQtViewer::VIEW_AS_IS);
3230       setDrawStyle(SoQtViewer::INTERACTIVE,      3143       setDrawStyle(SoQtViewer::INTERACTIVE,
3231                          SoQtViewer::VIEW_SAM    3144                          SoQtViewer::VIEW_SAME_AS_STILL);
3232    }                                             3145    }
3233 }                                                3146 }
3234                                                  3147 
3235                                                  3148 
3236 void G4OpenInventorQtExaminerViewer::SwitchAx    3149 void G4OpenInventorQtExaminerViewer::SwitchAxesCB(bool checked)
3237 {                                                3150 {
3238    // FWJ DEBUG                                  3151    // FWJ DEBUG
3239    //   G4cout << "App Button: switchAxes CAL    3152    //   G4cout << "App Button: switchAxes CALLBACK" << G4endl;
3240    setFeedbackVisibility(checked);               3153    setFeedbackVisibility(checked);
3241    //   if (checked) {                           3154    //   if (checked) {
3242    //      setFeedbackVisibility(TRUE);          3155    //      setFeedbackVisibility(TRUE);
3243    //   } else {                                 3156    //   } else {
3244    //      setFeedbackVisibility(FALSE);         3157    //      setFeedbackVisibility(FALSE);
3245    //   }                                        3158    //   }
3246 }                                                3159 }
3247                                                  3160 
3248                                                  3161 
3249 void G4OpenInventorQtExaminerViewer::DetachCB    3162 void G4OpenInventorQtExaminerViewer::DetachCB()
3250 {                                                3163 {
3251 #if QT_VERSION < 0x060000                     << 
3252    //   FWJ DEBUG                                3164    //   FWJ DEBUG
3253    //   G4cout << "App Button: detach CALLBAC    3165    //   G4cout << "App Button: detach CALLBACK" << G4endl;
3254    uiQt->GetViewerTabWidget()->removeTab(uiQt    3166    uiQt->GetViewerTabWidget()->removeTab(uiQtTabIndex);
3255    viewerParent->setParent(viewerParent2);       3167    viewerParent->setParent(viewerParent2);
3256    removeAppPushButton(detachButton);            3168    removeAppPushButton(detachButton);
3257    show();                                       3169    show();
3258 #else                                         << 
3259    //G.Barrand: have the viewer in a detached << 
3260    //           We have the title window refl << 
3261    //           it comes from, then "Detached << 
3262    //           Ask to destroy the detached v << 
3263    //           of closing the window with th << 
3264    //           we have a dandling hidden vie << 
3265    //           to map it again.              << 
3266    G4int index = -1;                          << 
3267   {int tabn = uiQt->GetViewerTabWidget()->cou << 
3268    for (G4int c = 0; c < tabn; ++c) {         << 
3269      if (uiQt->GetViewerTabWidget()->tabText( << 
3270        index = c;                             << 
3271      }                                        << 
3272    }}                                         << 
3273    if(index==(-1)) return;                    << 
3274    removeAppPushButton(detachButton);         << 
3275    uiQt->GetViewerTabWidget()->removeTab(inde << 
3276   {short w,h;                                 << 
3277    getSize().getValue(w,h);                   << 
3278    QWidget* dialog = new QDialog();           << 
3279    dialog->setWindowTitle(QString("Detached " << 
3280    dialog->setAttribute(Qt::WA_DeleteOnClose) << 
3281   {QHBoxLayout* layout = new QHBoxLayout();   << 
3282    layout->setContentsMargins(0,0,0,0);       << 
3283    layout->setSpacing(0);                     << 
3284    layout->addWidget(getParentWidget());      << 
3285    dialog->setLayout(layout);}                << 
3286    dialog->resize(w,h);                       << 
3287    getParentWidget()->show();                 << 
3288    dialog->show();                            << 
3289   }                                           << 
3290 #endif                                        << 
3291 }                                                3170 }
3292                                                  3171 
3293                                                  3172 
3294 void G4OpenInventorQtExaminerViewer::DeleteBo    3173 void G4OpenInventorQtExaminerViewer::DeleteBookmarkCB()
3295 {                                                3174 {
3296    // FWJ DEBUG                                  3175    // FWJ DEBUG
3297    //   G4cout << "Delete Button: DeleteBookm    3176    //   G4cout << "Delete Button: DeleteBookmark CALLBACK" << G4endl;
3298                                                  3177 
3299    // Maybe nothing selected yet                 3178    // Maybe nothing selected yet
3300    QListWidgetItem* listitem = AuxWindowDialo    3179    QListWidgetItem* listitem = AuxWindowDialog->listWidget->currentItem();
3301    if (!listitem) return;                        3180    if (!listitem) return;
3302    if (!(listitem->isSelected())) return;        3181    if (!(listitem->isSelected())) return;
3303                                                  3182 
3304    QString vpnamein = listitem->text();          3183    QString vpnamein = listitem->text();
3305                                                  3184 
3306    char* vpName = strdup(qPrintable(vpnamein) << 3185    const int nVPName = MAX_VP_NAME + 1;
                                                   >> 3186    char* vpName = new char[nVPName];
                                                   >> 3187    vpName = strdup(qPrintable(vpnamein));
3307    //   G4cout << "DELETING bookmark " << vpN    3188    //   G4cout << "DELETING bookmark " << vpName << G4endl;
3308                                                  3189 
3309    deleteViewPt(vpName);                         3190    deleteViewPt(vpName);
3310    delete listitem;                              3191    delete listitem;
3311    free(vpName);                              << 
3312 }                                                3192 }
3313                                                  3193 
3314 // Deletes current viewpoint the user is look    3194 // Deletes current viewpoint the user is looking at.
3315 // Updates the input file and bookmarks as we    3195 // Updates the input file and bookmarks as well.
3316                                                  3196 
3317 void G4OpenInventorQtExaminerViewer::deleteVi    3197 void G4OpenInventorQtExaminerViewer::deleteViewPt(char *vpName)
3318 {                                                3198 {
3319    std::string line;                             3199    std::string line;
3320    std::size_t end;                           << 3200    int end;
3321    fileIn.open(fileName.c_str());                3201    fileIn.open(fileName.c_str());
3322    std::ofstream out("temporaryFile.txt");       3202    std::ofstream out("temporaryFile.txt");
3323                                                  3203 
3324 #if QT_VERSION < 0x060000                     << 
3325    if (!vpName)                                  3204    if (!vpName)
3326       vpName = viewPtList[viewPtIdx].viewPtNa    3205       vpName = viewPtList[viewPtIdx].viewPtName;
3327 #endif                                        << 
3328                                                  3206 
3329    getline(fileIn, line); // Printing the vie    3207    getline(fileIn, line); // Printing the viewpoint idx
3330    out << line << "\n";                          3208    out << line << "\n";
3331                                                  3209 
3332    while (getline(fileIn, line)) {               3210    while (getline(fileIn, line)) {
3333       end = line.find_last_not_of(' ');          3211       end = line.find_last_not_of(' ');
3334       line = line.substr(0, end + 1);            3212       line = line.substr(0, end + 1);
3335       if (!strcmp(line.c_str(), vpName)) { //    3213       if (!strcmp(line.c_str(), vpName)) { // Equal
3336          while (line.size()) {                   3214          while (line.size()) {
3337             getline(fileIn, line);               3215             getline(fileIn, line);
3338          }                                       3216          }
3339                                                  3217 
3340          while (getline(fileIn, line))           3218          while (getline(fileIn, line))
3341             out << line << "\n";                 3219             out << line << "\n";
3342       } else {                                   3220       } else {
3343          while (line.size()) {                   3221          while (line.size()) {
3344             out << line << "\n";                 3222             out << line << "\n";
3345             getline(fileIn, line);               3223             getline(fileIn, line);
3346          }                                       3224          }
3347          out << "\n";                            3225          out << "\n";
3348       }                                          3226       }
3349    }                                             3227    }
3350                                                  3228 
3351    std::size_t idx = 0; // Remove viewpoint f << 3229    int idx = 0; // Remove viewpoint from the vector
3352    std::size_t size = viewPtList.size();      << 3230    int size = viewPtList.size();
3353    while (idx < size) {                          3231    while (idx < size) {
3354 #if QT_VERSION < 0x060000                     << 
3355       if (!strcmp(viewPtList[idx].viewPtName,    3232       if (!strcmp(viewPtList[idx].viewPtName, vpName)) {
3356 #else                                         << 
3357       if (!strcmp(viewPtList[idx].viewPtName. << 
3358 #endif                                        << 
3359          viewPtList.erase(viewPtList.begin()     3233          viewPtList.erase(viewPtList.begin() + idx);
3360          break;                                  3234          break;
3361       }                                          3235       }
3362       idx++;                                     3236       idx++;
3363    }                                             3237    }
3364                                                  3238 
3365    out.close();                                  3239    out.close();
3366    fileOut.close();                              3240    fileOut.close();
3367    fileIn.clear();                               3241    fileIn.clear();
3368    fileIn.close();                               3242    fileIn.close();
3369                                                  3243 
3370    // FWJ check return status: error popups n    3244    // FWJ check return status: error popups needed here
3371    int istat = remove(fileName.c_str());         3245    int istat = remove(fileName.c_str());
3372    if (istat == -1) {                            3246    if (istat == -1) {
3373       QMessageBox msgbox;                        3247       QMessageBox msgbox;
3374       msgbox.setFont(*font);                     3248       msgbox.setFont(*font);
3375       QString messagetxt = "Error removing bo    3249       QString messagetxt = "Error removing bookmarks file";
3376       //      messagetxt.append(filenamein);     3250       //      messagetxt.append(filenamein);
3377       msgbox.setText(messagetxt);                3251       msgbox.setText(messagetxt);
3378       msgbox.exec();                             3252       msgbox.exec();
3379       //      G4cout << "Error removing bookm    3253       //      G4cout << "Error removing bookmarks file" << G4endl;
3380    }                                             3254    }
3381    istat = rename("temporaryFile.txt", fileNa    3255    istat = rename("temporaryFile.txt", fileName.c_str());
3382    if (istat == -1) {                            3256    if (istat == -1) {
3383       QMessageBox msgbox;                        3257       QMessageBox msgbox;
3384       msgbox.setFont(*font);                     3258       msgbox.setFont(*font);
3385       QString messagetxt = "Error renaming bo    3259       QString messagetxt = "Error renaming bookmarks file";
3386       //      messagetxt.append(filenamein);     3260       //      messagetxt.append(filenamein);
3387       msgbox.setText(messagetxt);                3261       msgbox.setText(messagetxt);
3388       msgbox.exec();                             3262       msgbox.exec();
3389       //      G4cout << "Error renaming bookm    3263       //      G4cout << "Error renaming bookmarks file" << G4endl;
3390    }                                             3264    }
3391    fileOut.open(fileName.c_str(), std::ios::i    3265    fileOut.open(fileName.c_str(), std::ios::in);
3392    fileOut.seekp(0, std::ios::end);              3266    fileOut.seekp(0, std::ios::end);
3393                                                  3267 
3394    if (!viewPtList.size()) { // viewPtList is    3268    if (!viewPtList.size()) { // viewPtList is empty
3395 #if QT_VERSION < 0x060000                     << 3269       curViewPtName = (char *) "";
3396       curViewPtName = (char *) empty.c_str(); << 
3397 #else                                         << 
3398       curViewPtName.clear();                  << 
3399 #endif                                        << 
3400       scheduleRedraw();                          3270       scheduleRedraw();
3401    } else {                                      3271    } else {
3402       if (viewPtIdx >= (int) viewPtList.size(    3272       if (viewPtIdx >= (int) viewPtList.size())
3403          viewPtIdx--;                            3273          viewPtIdx--;
3404       writeViewPtIdx();                          3274       writeViewPtIdx();
3405       setViewPt();                               3275       setViewPt();
3406    }                                             3276    }
3407 }                                                3277 }
3408                                                  3278 
3409                                                  3279 
3410 void G4OpenInventorQtExaminerViewer::RenameBo    3280 void G4OpenInventorQtExaminerViewer::RenameBookmarkCB()
3411 {                                                3281 {
3412    // FWJ DEBUG                                  3282    // FWJ DEBUG
3413    //   G4cout << "Rename Button: RenameBookm    3283    //   G4cout << "Rename Button: RenameBookmark CALLBACK" << G4endl;
3414    // Maybe nothing selected yet                 3284    // Maybe nothing selected yet
3415    QListWidgetItem* listitem = AuxWindowDialo    3285    QListWidgetItem* listitem = AuxWindowDialog->listWidget->currentItem();
3416    if (!listitem) return;                        3286    if (!listitem) return;
3417    if (!(listitem->isSelected())) return;        3287    if (!(listitem->isSelected())) return;
3418                                                  3288 
3419    QString vpnamein = listitem->text();          3289    QString vpnamein = listitem->text();
3420                                                  3290 
                                                   >> 3291    const int nVPName = MAX_VP_NAME + 1;
                                                   >> 3292    //   char* vpName = new char[nVPName];
                                                   >> 3293    //   vpName = strdup(qPrintable(vpnamein));
                                                   >> 3294    //   G4cout << "RENAMING bookmark " << vpName << G4endl;
                                                   >> 3295 
3421    QInputDialog* inputdialog = new QInputDial    3296    QInputDialog* inputdialog = new QInputDialog(getParentWidget());
3422    inputdialog->setFont(*font);                  3297    inputdialog->setFont(*font);
3423    inputdialog->setWindowTitle(tr("Enter"));     3298    inputdialog->setWindowTitle(tr("Enter"));
3424    inputdialog->setLabelText("New bookmark na    3299    inputdialog->setLabelText("New bookmark name");
3425    inputdialog->adjustSize();                    3300    inputdialog->adjustSize();
3426    QString newnamein;                            3301    QString newnamein;
3427    if (inputdialog->exec() == QDialog::Accept    3302    if (inputdialog->exec() == QDialog::Accepted)
3428       newnamein=inputdialog->textValue().trim    3303       newnamein=inputdialog->textValue().trimmed();
3429    else                                          3304    else
3430       return;                                    3305       return;
3431    if (newnamein.isEmpty()) return;              3306    if (newnamein.isEmpty()) return;
3432                                                  3307 
3433    char* newname = strdup(qPrintable(newnamei << 3308    char* newname = new char[nVPName];
                                                   >> 3309    newname = strdup(qPrintable(newnamein));
3434                                                  3310 
3435    std::size_t size = viewPtList.size();      << 3311    int size = viewPtList.size();
3436    for (std::size_t i = 0; i < size; ++i) {   << 3312    for (int i = 0; i < size; i++) {
3437 #if QT_VERSION < 0x060000                     << 
3438       if (!strcmp(newname, viewPtList[i].view    3313       if (!strcmp(newname, viewPtList[i].viewPtName)) {
3439 #else                                         << 
3440       if (!strcmp(newname, viewPtList[i].view << 
3441 #endif                                        << 
3442          QMessageBox msgbox;                     3314          QMessageBox msgbox;
3443          msgbox.setFont(*font);                  3315          msgbox.setFont(*font);
3444          msgbox.setText("Bookmark name is alr    3316          msgbox.setText("Bookmark name is already in use");
3445          msgbox.exec();                          3317          msgbox.exec();
3446       }                                          3318       }
3447    }                                             3319    }
3448                                                  3320 
3449    //   G4cout << "RENAMING to " << newname <    3321    //   G4cout << "RENAMING to " << newname << G4endl;
3450    renameViewPt(newname);                        3322    renameViewPt(newname);
3451    listitem->setText(QString(newname));          3323    listitem->setText(QString(newname));
3452    AuxWindowDialog->lineEdit->setText(newname    3324    AuxWindowDialog->lineEdit->setText(newname);
3453    //   if (currentState == VIEWPOINT)           3325    //   if (currentState == VIEWPOINT)
3454    //      scheduleRedraw();                     3326    //      scheduleRedraw();
3455                                                  3327 
3456    free(newname);                             << 3328    delete[] newname;
3457 }                                                3329 }
3458                                                  3330 
3459 // Renames currently selected viewpoint.         3331 // Renames currently selected viewpoint.
3460                                                  3332 
3461 void G4OpenInventorQtExaminerViewer::renameVi    3333 void G4OpenInventorQtExaminerViewer::renameViewPt(char *vpName)
3462 {                                                3334 {
3463    std::size_t idx = 0, end, pos;             << 3335    int idx = 0, end, pos;
3464    std::size_t size = viewPtList.size();      << 3336    int size = viewPtList.size();
3465    std::string line, newName;                    3337    std::string line, newName;
3466    fileIn.open(fileName.c_str());                3338    fileIn.open(fileName.c_str());
3467                                                  3339 
3468    newName = vpName;                             3340    newName = vpName;
3469    while ((int) newName.size() < MAX_VP_NAME)    3341    while ((int) newName.size() < MAX_VP_NAME)
3470       newName += " ";                            3342       newName += " ";
3471                                                  3343 
3472    getline(fileIn, line);                        3344    getline(fileIn, line);
3473    pos = fileIn.tellg();                         3345    pos = fileIn.tellg();
3474    while (getline(fileIn, line)) {               3346    while (getline(fileIn, line)) {
3475       end = line.find_last_not_of(' ');          3347       end = line.find_last_not_of(' ');
3476       line = line.substr(0, end + 1);            3348       line = line.substr(0, end + 1);
3477 #if QT_VERSION < 0x060000                     << 
3478       if (!strcmp(line.c_str(), curViewPtName    3349       if (!strcmp(line.c_str(), curViewPtName)) {
3479 #else                                         << 
3480       if (!strcmp(line.c_str(), curViewPtName << 
3481 #endif                                        << 
3482          fileOut.seekp(pos);                     3350          fileOut.seekp(pos);
3483          fileOut << newName;                     3351          fileOut << newName;
3484          fileOut.seekp(0, std::ios::end); //     3352          fileOut.seekp(0, std::ios::end); // Set the file pointer to the end of the file
3485          break;                                  3353          break;
3486       }                                          3354       }
3487       while (line.size())                        3355       while (line.size())
3488          getline(fileIn, line);                  3356          getline(fileIn, line);
3489       pos = fileIn.tellg();                      3357       pos = fileIn.tellg();
3490    }                                             3358    }
3491                                                  3359 
3492    fileIn.close();                               3360    fileIn.close();
3493    fileIn.clear();                               3361    fileIn.clear();
3494                                                  3362 
3495    while (idx < size) {                          3363    while (idx < size) {
3496 #if QT_VERSION < 0x060000                     << 
3497       if (!strcmp(viewPtList[idx].viewPtName,    3364       if (!strcmp(viewPtList[idx].viewPtName, curViewPtName)) {
3498          strcpy(viewPtList[idx].viewPtName, v    3365          strcpy(viewPtList[idx].viewPtName, vpName);
3499 #else                                         << 
3500       if (!strcmp(viewPtList[idx].viewPtName. << 
3501          viewPtList[idx].viewPtName = std::st << 
3502 #endif                                        << 
3503          break;                                  3366          break;
3504       }                                          3367       }
3505       idx++;                                     3368       idx++;
3506    }                                             3369    }
3507 }                                                3370 }
3508                                                  3371 
3509                                                  3372 
3510 void G4OpenInventorQtExaminerViewer::SortBook    3373 void G4OpenInventorQtExaminerViewer::SortBookmarksCB()
3511 {                                                3374 {
3512    // FWJ NOTE: Xt version of this does not w    3375    // FWJ NOTE: Xt version of this does not work (does nothing)
3513                                                  3376 
3514    //   G4cout << "Sort Button: SortBookmarks    3377    //   G4cout << "Sort Button: SortBookmarks CALLBACK" << G4endl;
3515                                                  3378 
3516    // FWJ List for sorting                       3379    // FWJ List for sorting
3517    // The dialog list and bookmark file will     3380    // The dialog list and bookmark file will be rewritten.
3518    // Simpler to populate this list from the     3381    // Simpler to populate this list from the data structure.
3519                                                  3382 
3520    std::vector<std::string> charList;            3383    std::vector<std::string> charList;
3521                                                  3384 
3522    if (viewPtList.size() < 2) return;            3385    if (viewPtList.size() < 2) return;
3523                                                  3386 
3524    // Get current entries from the list          3387    // Get current entries from the list
3525                                                  3388 
3526    for (int i = 0; i < (int)viewPtList.size()    3389    for (int i = 0; i < (int)viewPtList.size(); i++) {
3527                                                  3390 
3528       charList.push_back(viewPtList[i].viewPt    3391       charList.push_back(viewPtList[i].viewPtName);
3529       //      G4cout << "  Pushed " << i << "    3392       //      G4cout << "  Pushed " << i << " " << charList[i] << G4endl;
3530    }                                             3393    }
3531                                                  3394 
3532    std::sort(charList.begin(), charList.end()    3395    std::sort(charList.begin(), charList.end());
3533                                                  3396 
3534    // FWJ POPULATE the new dialog list           3397    // FWJ POPULATE the new dialog list
3535    //   G4cout << "  Populating Bookmark list    3398    //   G4cout << "  Populating Bookmark listWidget..." << G4endl;
3536    AuxWindowDialog->listWidget->clear();         3399    AuxWindowDialog->listWidget->clear();
3537                                                  3400 
3538    for (int i = 0; i < (int)viewPtList.size()    3401    for (int i = 0; i < (int)viewPtList.size(); i++) {
3539       // viewPtIdx has to be changed to accou    3402       // viewPtIdx has to be changed to account for a different order in viewPtList
3540 #if QT_VERSION < 0x060000                     << 
3541       if (!strcmp(charList[i].c_str(), curVie    3403       if (!strcmp(charList[i].c_str(), curViewPtName))
3542 #else                                         << 
3543       if (!strcmp(charList[i].c_str(), curVie << 
3544 #endif                                        << 
3545          viewPtIdx = i;                          3404          viewPtIdx = i;
3546       new QListWidgetItem(charList[i].c_str()    3405       new QListWidgetItem(charList[i].c_str(), AuxWindowDialog->listWidget); 
3547                                                  3406 
3548    }                                             3407    }
3549                                                  3408 
3550    sortViewPts(charList);                        3409    sortViewPts(charList);
3551                                                  3410 
3552 }                                                3411 }
3553                                                  3412 
3554 // Rewrites entire viewpoint file with sorted    3413 // Rewrites entire viewpoint file with sorted viewpoints.
3555                                                  3414 
3556 void G4OpenInventorQtExaminerViewer::sortView    3415 void G4OpenInventorQtExaminerViewer::sortViewPts(std::vector<std::string> sortedViewPts) 
3557 {                                                3416 {
3558    SbVec3f axis;                                 3417    SbVec3f axis;
3559    float x, y, z, angle;                         3418    float x, y, z, angle;
3560    std::size_t sortIdx = 0, unsortIdx = 0;    << 3419    int sortIdx = 0, unsortIdx = 0;
3561                                                  3420 
3562    if (fileOut.is_open())                        3421    if (fileOut.is_open())
3563       fileOut.close();                           3422       fileOut.close();
3564                                                  3423 
3565    fileOut.open(fileName.c_str()); // Erase c    3424    fileOut.open(fileName.c_str()); // Erase current viewpoint file
3566                                                  3425 
3567    writeViewPtIdx();                             3426    writeViewPtIdx();
3568                                                  3427 
3569    std::size_t size = sortedViewPts.size();   << 3428    int size = sortedViewPts.size();
3570    while (sortIdx < size) {                      3429    while (sortIdx < size) {
3571       while (strcmp(sortedViewPts[sortIdx].c_    3430       while (strcmp(sortedViewPts[sortIdx].c_str(),
3572 #if QT_VERSION < 0x060000                     << 
3573                     viewPtList[unsortIdx].vie    3431                     viewPtList[unsortIdx].viewPtName))
3574 #else                                         << 
3575                     viewPtList[unsortIdx].vie << 
3576 #endif                                        << 
3577          unsortIdx++;                            3432          unsortIdx++;
3578                                                  3433 
3579       std::string vpName = viewPtList[unsortI    3434       std::string vpName = viewPtList[unsortIdx].viewPtName;
3580                                                  3435 
3581       while ((int) vpName.size() < MAX_VP_NAM    3436       while ((int) vpName.size() < MAX_VP_NAME)
3582          vpName += " ";                          3437          vpName += " ";
3583       fileOut << vpName << std::endl;            3438       fileOut << vpName << std::endl;
3584       viewPtList[unsortIdx].position.getValue    3439       viewPtList[unsortIdx].position.getValue(x, y, z);
3585       fileOut << x << " " << y << " " << z <<    3440       fileOut << x << " " << y << " " << z << std::endl;
3586                                                  3441 
3587       // Reusing x, y and z for storing the a    3442       // Reusing x, y and z for storing the axis
3588       viewPtList[unsortIdx].orientation.getVa    3443       viewPtList[unsortIdx].orientation.getValue(axis, angle);
3589       axis.getValue(x, y, z);                    3444       axis.getValue(x, y, z);
3590       fileOut << x << " " << y << " " << z <<    3445       fileOut << x << " " << y << " " << z << " " << angle << std::endl;
3591                                                  3446 
3592       fileOut << viewPtList[unsortIdx].camTyp    3447       fileOut << viewPtList[unsortIdx].camType << " "
3593               << viewPtList[unsortIdx].height    3448               << viewPtList[unsortIdx].height << std::endl;
3594       fileOut << viewPtList[unsortIdx].focalD    3449       fileOut << viewPtList[unsortIdx].focalDistance << " ";
3595                                                  3450 
3596       fileOut << viewPtList[unsortIdx].nearDi    3451       fileOut << viewPtList[unsortIdx].nearDistance << " ";
3597                                                  3452 
3598       fileOut << viewPtList[unsortIdx].farDis    3453       fileOut << viewPtList[unsortIdx].farDistance << std::endl;
3599                                                  3454 
3600       fileOut << viewPtList[unsortIdx].viewpo    3455       fileOut << viewPtList[unsortIdx].viewportMapping << " ";
3601       fileOut << viewPtList[unsortIdx].aspect    3456       fileOut << viewPtList[unsortIdx].aspectRatio << "\n" << std::endl;
3602       fileOut.flush();                           3457       fileOut.flush();
3603                                                  3458 
3604       unsortIdx = 0;                             3459       unsortIdx = 0;
3605       sortIdx++;                                 3460       sortIdx++;
3606    }                                             3461    }
3607 }                                                3462 }
3608                                                  3463 
3609 // Needed to implement mouse wheel zoom direc << 3464 
3610 // Does not work with MacOS trackpad: use Coi << 
3611 // Emulating private method SoGuiFullViewerP:    3465 // Emulating private method SoGuiFullViewerP::zoom()
3612 #ifndef __APPLE__                             << 
3613 void                                             3466 void
3614 G4OpenInventorQtExaminerViewer::zoom(const fl    3467 G4OpenInventorQtExaminerViewer::zoom(const float diffvalue)
3615 {                                                3468 {
3616    float multiplicator = float(std::exp(diffv    3469    float multiplicator = float(std::exp(diffvalue));
3617    SoCamera *cam = getCamera();                  3470    SoCamera *cam = getCamera();
3618                                                  3471 
3619    if (cam->isOfType(SoPerspectiveCamera::get    3472    if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3620       const float oldfocaldist = cam->focalDi    3473       const float oldfocaldist = cam->focalDistance.getValue();
3621       const float newfocaldist = oldfocaldist    3474       const float newfocaldist = oldfocaldist * multiplicator;
3622                                                  3475 
3623       SbVec3f direction;                         3476       SbVec3f direction;
3624       cam->orientation.getValue().multVec(SbV    3477       cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction);
3625                                                  3478 
3626       const SbVec3f oldpos = cam->position.ge    3479       const SbVec3f oldpos = cam->position.getValue();
3627       const SbVec3f newpos = oldpos + (newfoc    3480       const SbVec3f newpos = oldpos + (newfocaldist - oldfocaldist) * -direction;
3628       cam->position = newpos;                    3481       cam->position = newpos;
3629       cam->focalDistance = newfocaldist;         3482       cam->focalDistance = newfocaldist;
3630    } else if (cam->isOfType(SoOrthographicCam    3483    } else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
3631       SoOrthographicCamera * oc = (SoOrthogra    3484       SoOrthographicCamera * oc = (SoOrthographicCamera *)cam;
3632       oc->height = oc->height.getValue() * mu    3485       oc->height = oc->height.getValue() * multiplicator;
3633    }                                             3486    }
3634 }                                                3487 }
3635 #endif                                        << 3488 
3636                                                  3489 
3637 // Handling mouse and keyboard events            3490 // Handling mouse and keyboard events
3638                                                  3491 
3639 SbBool                                           3492 SbBool
3640 G4OpenInventorQtExaminerViewer::processSoEven    3493 G4OpenInventorQtExaminerViewer::processSoEvent(const SoEvent* const ev)
3641 {                                                3494 {
3642                                                  3495 
3643    // FWJ DEBUG                                  3496    // FWJ DEBUG
3644    //   G4cout << "processSoEvent ###########    3497    //   G4cout << "processSoEvent ############" << ++processSoEventCount << G4endl;
3645                                                  3498 
3646    SoCamera *cam = getCamera();                  3499    SoCamera *cam = getCamera();
3647    const SoType type(ev->getTypeId());           3500    const SoType type(ev->getTypeId());
3648                                                  3501 
3649 // Needed to implement mouse wheel zoom direc << 
3650 // Does not work with MacOS trackpad: use Coi << 
3651 #ifndef __APPLE__                             << 
3652    if (type.isDerivedFrom(SoMouseButtonEvent:    3502    if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
3653       SoMouseButtonEvent * me = (SoMouseButto    3503       SoMouseButtonEvent * me = (SoMouseButtonEvent *) ev;
3654                                                  3504 
3655       //      if (currentState == ANIMATION |    3505       //      if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
3656       //          || currentState == PAUSED_A    3506       //          || currentState == PAUSED_ANIMATION) {
3657                                                  3507 
3658       switch (me->getButton()) {                 3508       switch (me->getButton()) {
3659                                                  3509 
3660          case SoMouseButtonEvent::BUTTON4: //    3510          case SoMouseButtonEvent::BUTTON4: // Scroll wheel up
3661             if (me->getState() == SoButtonEve    3511             if (me->getState() == SoButtonEvent::DOWN) {
3662                //               G4cout << "SC    3512                //               G4cout << "SCROLL WHEEL UP" << G4endl;
3663                zoom(-0.1f);                      3513                zoom(-0.1f);
3664                return TRUE;                      3514                return TRUE;
3665             }                                    3515             }
3666             break;                               3516             break;
3667                                                  3517 
3668          case SoMouseButtonEvent::BUTTON5: //    3518          case SoMouseButtonEvent::BUTTON5: // Scroll wheel down
3669             if (me->getState() == SoButtonEve    3519             if (me->getState() == SoButtonEvent::DOWN) {
3670                //               G4cout << "SC    3520                //               G4cout << "SCROLL WHEEL DOWN" << G4endl;
3671                zoom(0.1f);                       3521                zoom(0.1f);
3672                return TRUE;                      3522                return TRUE;
3673             }                                    3523             }
3674             break;                               3524             break;
3675                                               << 
3676          default:                                3525          default:
3677             break;                               3526             break;
3678       }                                       << 3527          }
3679          //      }                               3528          //      }
3680       if (currentState == GENERAL) {             3529       if (currentState == GENERAL) {
3681                                                  3530 
3682       }                                          3531       }
3683    }                                             3532    }
3684 #endif                                        << 3533 
3685                                                  3534 
3686    if (type.isDerivedFrom(SoKeyboardEvent::ge    3535    if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
3687       SoKeyboardEvent* ke = (SoKeyboardEvent*    3536       SoKeyboardEvent* ke = (SoKeyboardEvent*)ev;
3688                                                  3537 
3689       if (SoKeyboardEvent::isKeyPressEvent(ev    3538       if (SoKeyboardEvent::isKeyPressEvent(ev, ke->getKey())) {
3690          switch (ke->getKey()) {                 3539          switch (ke->getKey()) {
3691          case SoKeyboardEvent::E:                3540          case SoKeyboardEvent::E:
3692             if (externalQtApp) {                 3541             if (externalQtApp) {
3693                // G4cout << "E KEY PRESSED" <    3542                // G4cout << "E KEY PRESSED" << G4endl;
3694                return TRUE;                      3543                return TRUE;
3695             } else {                             3544             } else {
3696                G4cout <<                         3545                G4cout <<
3697                   "E KEY PRESSED, EXITING OIQ    3546                   "E KEY PRESSED, EXITING OIQT VIEWER SECONDARY LOOP" <<
3698                   G4endl;                        3547                   G4endl;
3699                SoQt::exitMainLoop();             3548                SoQt::exitMainLoop();
3700             //            escapeCallback();      3549             //            escapeCallback();
3701                return TRUE;                      3550                return TRUE;
3702             }                                    3551             }
3703          case SoKeyboardEvent::LEFT_SHIFT:       3552          case SoKeyboardEvent::LEFT_SHIFT:
3704             this->lshiftdown = true;             3553             this->lshiftdown = true;
3705             return TRUE;                         3554             return TRUE;
3706          case SoKeyboardEvent::RIGHT_SHIFT:      3555          case SoKeyboardEvent::RIGHT_SHIFT:
3707             this->rshiftdown = true;             3556             this->rshiftdown = true;
3708             return TRUE;                         3557             return TRUE;
3709          case SoKeyboardEvent::LEFT_CONTROL:     3558          case SoKeyboardEvent::LEFT_CONTROL:
3710             this->lctrldown = true;              3559             this->lctrldown = true;
3711             return TRUE;                         3560             return TRUE;
3712          case SoKeyboardEvent::RIGHT_CONTROL:    3561          case SoKeyboardEvent::RIGHT_CONTROL:
3713             this->rctrldown = true;              3562             this->rctrldown = true;
3714             return TRUE;                         3563             return TRUE;
3715          case SoKeyboardEvent::SPACE:            3564          case SoKeyboardEvent::SPACE:
3716             if (currentState == ANIMATION        3565             if (currentState == ANIMATION
3717                 || currentState == REVERSED_A    3566                 || currentState == REVERSED_ANIMATION) {
3718                beforePausing = currentState;     3567                beforePausing = currentState;
3719                currentState = PAUSED_ANIMATIO    3568                currentState = PAUSED_ANIMATION;
3720                if (animateSensor->isScheduled    3569                if (animateSensor->isScheduled())
3721                   animateSensor->unschedule()    3570                   animateSensor->unschedule();
3722                return TRUE;                      3571                return TRUE;
3723             } else if (currentState == PAUSED    3572             } else if (currentState == PAUSED_ANIMATION) {
3724                if (maxSpeed) {                   3573                if (maxSpeed) {
3725                   if ((beforePausing == ANIMA    3574                   if ((beforePausing == ANIMATION
3726                        && refParticleIdx         3575                        && refParticleIdx
3727                        < (int) refParticleTra    3576                        < (int) refParticleTrajectory.size() - 1)
3728                       || (beforePausing == RE    3577                       || (beforePausing == REVERSED_ANIMATION
3729                           && refParticleIdx >    3578                           && refParticleIdx > 0)) {
3730                      currentState = beforePau    3579                      currentState = beforePausing;
3731                      animateRefParticle();       3580                      animateRefParticle();
3732                   }                              3581                   }
3733                }                                 3582                }
3734                return TRUE;                      3583                return TRUE;
3735             }                                    3584             }
3736             break;                               3585             break;
3737          case SoKeyboardEvent::ESCAPE:           3586          case SoKeyboardEvent::ESCAPE:
3738             if (currentState == ANIMATION        3587             if (currentState == ANIMATION
3739                 || currentState == REVERSED_A    3588                 || currentState == REVERSED_ANIMATION
3740                 || currentState == PAUSED_ANI    3589                 || currentState == PAUSED_ANIMATION) {
3741                                                  3590 
3742                if (animateSensor->isScheduled    3591                if (animateSensor->isScheduled())
3743                   animateSensor->unschedule()    3592                   animateSensor->unschedule();
3744                currentState = prevState;         3593                currentState = prevState;
3745                refParticleIdx = prevRefIdx;      3594                refParticleIdx = prevRefIdx;
3746                setSuperimpositionEnabled(supe    3595                setSuperimpositionEnabled(superimposition, FALSE);
3747                maxSpeed = 0.0f;                  3596                maxSpeed = 0.0f;
3748                step = 1;                         3597                step = 1;
3749                                                  3598 
3750                scheduleRedraw();                 3599                scheduleRedraw();
3751                if (currentState == VIEWPOINT)    3600                if (currentState == VIEWPOINT) {
3752                   setSuperimpositionEnabled(s    3601                   setSuperimpositionEnabled(superimposition, TRUE);
3753                   axisSwitch->whichChild.setV    3602                   axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
3754                   animSpeedOutlineSwitch->whi    3603                   animSpeedOutlineSwitch->whichChild.setValue(
3755                                                  3604                                                               SO_SWITCH_NONE);
3756                   animSpeedSwitch->whichChild    3605                   animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
3757                                                  3606 
3758                   scheduleRedraw();              3607                   scheduleRedraw();
3759                }                                 3608                }
3760                restoreCamera();                  3609                restoreCamera();
3761                return TRUE;                      3610                return TRUE;
3762             }                                    3611             }
3763             break;                               3612             break;
3764          case SoKeyboardEvent::DELETE:           3613          case SoKeyboardEvent::DELETE:
3765             if (viewPtList.size()                3614             if (viewPtList.size()
3766                 && (currentState != ANIMATION    3615                 && (currentState != ANIMATION
3767                     && currentState != REVERS    3616                     && currentState != REVERSED_ANIMATION
3768                     && currentState != PAUSED    3617                     && currentState != PAUSED_ANIMATION)) {
3769                // FWJ IMPLEMENT LATER            3618                // FWJ IMPLEMENT LATER
3770                // String dialogName = (char *    3619                // String dialogName = (char *) "Delete Viewpoint";
3771                // std::string msg = "Are you     3620                // std::string msg = "Are you sure you want to delete current viewpoint?";
3772                // warningMsgDialog(msg, dialo    3621                // warningMsgDialog(msg, dialogName, deleteViewPtCB);
3773                return TRUE;                      3622                return TRUE;
3774             }                                    3623             }
3775             break;                               3624             break;
3776          case SoKeyboardEvent::LEFT_ARROW:       3625          case SoKeyboardEvent::LEFT_ARROW:
3777             switch (currentState) {              3626             switch (currentState) {
3778             case BEAMLINE:                       3627             case BEAMLINE:
3779                if ((this->lshiftdown)   || (t    3628                if ((this->lshiftdown)   || (this->rshiftdown)) {
3780                   refParticleIdx -= step;        3629                   refParticleIdx -= step;
3781                   moveCamera();                  3630                   moveCamera();
3782                }                                 3631                }
3783                else if ((this->lctrldown)        3632                else if ((this->lctrldown)       || (this->rctrldown)) {
3784                   if (SoQtExaminerViewer::isA    3633                   if (SoQtExaminerViewer::isAnimating())
3785                      stopAnimating();            3634                      stopAnimating();
3786                   prevState = currentState;      3635                   prevState = currentState;
3787                   currentState = ROTATING;       3636                   currentState = ROTATING;
3788                   animateBtwPtsPeriod = 0.08f    3637                   animateBtwPtsPeriod = 0.08f;
3789                                                  3638 
3790                   SbVec3f tmp = camDir;          3639                   SbVec3f tmp = camDir;
3791                   tmp.negate();                  3640                   tmp.negate();
3792                   rotAxis = tmp;                 3641                   rotAxis = tmp;
3793                                                  3642 
3794                   rotCnt = ROT_CNT;              3643                   rotCnt = ROT_CNT;
3795                   moveCamera(); // To make su    3644                   moveCamera(); // To make sure camera is perpendicular to the beamline
3796                   rotateCamera();                3645                   rotateCamera();
3797                }                                 3646                }
3798                else {                            3647                else {
3799                   if (SoQtExaminerViewer::isA    3648                   if (SoQtExaminerViewer::isAnimating())
3800                      stopAnimating();            3649                      stopAnimating();
3801                   prevState = currentState;      3650                   prevState = currentState;
3802                   currentState = ROTATING;       3651                   currentState = ROTATING;
3803                   animateBtwPtsPeriod = 0.08f    3652                   animateBtwPtsPeriod = 0.08f;
3804                                                  3653 
3805                   SbVec3f tmp = camUpVec;        3654                   SbVec3f tmp = camUpVec;
3806                   tmp.negate();                  3655                   tmp.negate();
3807                   rotAxis = tmp;                 3656                   rotAxis = tmp;
3808                                                  3657 
3809                   rotCnt = ROT_CNT;              3658                   rotCnt = ROT_CNT;
3810                   moveCamera(); // To make su    3659                   moveCamera(); // To make sure camera is perpendicular to the beamline
3811                   rotateCamera();                3660                   rotateCamera();
3812                                                  3661 
3813                }                                 3662                }
3814                return TRUE;                      3663                return TRUE;
3815                                                  3664 
3816             case ANIMATION:                      3665             case ANIMATION:
3817             case REVERSED_ANIMATION:             3666             case REVERSED_ANIMATION:
3818                left_right -= 1.5f;               3667                left_right -= 1.5f;
3819                return TRUE;                      3668                return TRUE;
3820             case PAUSED_ANIMATION:               3669             case PAUSED_ANIMATION:
3821                left_right -= 1.5f;               3670                left_right -= 1.5f;
3822                setStartingPtForAnimation();      3671                setStartingPtForAnimation();
3823                cam->position = myCam->positio    3672                cam->position = myCam->position;
3824                return TRUE;                      3673                return TRUE;
3825             case GENERAL:                        3674             case GENERAL:
3826             case VIEWPOINT:                      3675             case VIEWPOINT:
3827                if ((!this->lshiftdown) && (!t    3676                if ((!this->lshiftdown) && (!this->rshiftdown)) {
3828                   // Using this allows us to     3677                   // Using this allows us to look around without
3829                   // changing the camera para    3678                   // changing the camera parameters (camDir, camUpVec)
3830                   this->bottomWheelMotion(       3679                   this->bottomWheelMotion(
3831                                           thi    3680                                           this->getBottomWheelValue() + 0.1f);
3832                                                  3681 
3833                   return TRUE;                   3682                   return TRUE;
3834                }                                 3683                }
3835                break;                            3684                break;
3836             case ROTATING:                       3685             case ROTATING:
3837                // For this state, let the key    3686                // For this state, let the keyboard event
3838                // be handled by superclass       3687                // be handled by superclass
3839                break;                            3688                break;
3840             default:                             3689             default:
3841                SoDebugError::post("G4OpenInve    3690                SoDebugError::post("G4OpenInventorQtExaminerViewer::processSoEvent",
3842                                   "Unhandled     3691                                   "Unhandled viewer state");
3843                break;                            3692                break;
3844             }                                    3693             }
3845             break;                               3694             break;
3846                                                  3695 
3847          case SoKeyboardEvent::RIGHT_ARROW:      3696          case SoKeyboardEvent::RIGHT_ARROW:
3848             switch(currentState) {               3697             switch(currentState) {
3849             case BEAMLINE:                       3698             case BEAMLINE:
3850                if ((this->lshiftdown)   || (t    3699                if ((this->lshiftdown)   || (this->rshiftdown)) {
3851                   refParticleIdx += step;        3700                   refParticleIdx += step;
3852                   moveCamera();                  3701                   moveCamera();
3853                }                                 3702                }
3854                else if ((this->lctrldown)        3703                else if ((this->lctrldown)       || (this->rctrldown)) {
3855                   if (SoQtExaminerViewer::isA    3704                   if (SoQtExaminerViewer::isAnimating())
3856                      stopAnimating();            3705                      stopAnimating();
3857                   prevState = currentState;      3706                   prevState = currentState;
3858                   currentState = ROTATING;       3707                   currentState = ROTATING;
3859                   animateBtwPtsPeriod = 0.08f    3708                   animateBtwPtsPeriod = 0.08f;
3860                                                  3709 
3861                   rotAxis = camDir;              3710                   rotAxis = camDir;
3862                                                  3711 
3863                   rotCnt = ROT_CNT;              3712                   rotCnt = ROT_CNT;
3864                   moveCamera(); // To make su    3713                   moveCamera(); // To make sure camera is perpendicular to the beamline
3865                   rotateCamera();                3714                   rotateCamera();
3866                }                                 3715                }
3867                else{                             3716                else{
3868                   if (SoQtExaminerViewer::isA    3717                   if (SoQtExaminerViewer::isAnimating())
3869                      stopAnimating();            3718                      stopAnimating();
3870                   prevState = currentState;      3719                   prevState = currentState;
3871                   currentState = ROTATING;       3720                   currentState = ROTATING;
3872                   animateBtwPtsPeriod = 0.08f    3721                   animateBtwPtsPeriod = 0.08f;
3873                                                  3722 
3874                   rotAxis = camUpVec;            3723                   rotAxis = camUpVec;
3875                                                  3724 
3876                   rotCnt = ROT_CNT;              3725                   rotCnt = ROT_CNT;
3877                   moveCamera(); // To make su    3726                   moveCamera(); // To make sure camera is perpendicular to the beamline
3878                   rotateCamera();                3727                   rotateCamera();
3879                }                                 3728                }
3880                return TRUE;                      3729                return TRUE;
3881                                                  3730 
3882             case ANIMATION:                      3731             case ANIMATION:
3883             case REVERSED_ANIMATION:             3732             case REVERSED_ANIMATION:
3884                left_right += 1.5f;               3733                left_right += 1.5f;
3885                return TRUE;                      3734                return TRUE;
3886             case PAUSED_ANIMATION:               3735             case PAUSED_ANIMATION:
3887                left_right += 1.5f;               3736                left_right += 1.5f;
3888                setStartingPtForAnimation();      3737                setStartingPtForAnimation();
3889                cam->position = myCam->positio    3738                cam->position = myCam->position;
3890                return TRUE;                      3739                return TRUE;
3891             case GENERAL:                        3740             case GENERAL:
3892             case VIEWPOINT:                      3741             case VIEWPOINT:
3893                if ((!this->lshiftdown) && (!t    3742                if ((!this->lshiftdown) && (!this->rshiftdown)) {
3894                   // Using this allows us to     3743                   // Using this allows us to look around without
3895                   // changing the camera para    3744                   // changing the camera parameters (camDir, camUpVec)
3896                   this->bottomWheelMotion(       3745                   this->bottomWheelMotion(
3897                                           thi    3746                                           this->getBottomWheelValue() - 0.1f);
3898                   return TRUE;                   3747                   return TRUE;
3899                }                                 3748                }
3900                break;                            3749                break;
3901             case ROTATING:                       3750             case ROTATING:
3902                // For this state, let the key    3751                // For this state, let the keyboard event
3903                // be handled by superclass       3752                // be handled by superclass
3904                break;                            3753                break;
3905             default:                             3754             default:
3906                SoDebugError::post("G4OpenInve    3755                SoDebugError::post("G4OpenInventorQtExaminerViewer::processSoEvent",
3907                                   "Unhandled     3756                                   "Unhandled viewer state");
3908                break;                            3757                break;
3909             }                                    3758             }
3910             break;                               3759             break;
3911                                                  3760 
3912          case SoKeyboardEvent::DOWN_ARROW:       3761          case SoKeyboardEvent::DOWN_ARROW:
3913             switch(currentState) {               3762             switch(currentState) {
3914             case BEAMLINE:                       3763             case BEAMLINE:
3915                                                  3764 
3916                if ((this->lshiftdown)   || (t    3765                if ((this->lshiftdown)   || (this->rshiftdown)) {
3917                   refParticleIdx -= step;        3766                   refParticleIdx -= step;
3918                   moveCamera();                  3767                   moveCamera();
3919                }                                 3768                }
3920                else{                             3769                else{
3921                   if (SoQtExaminerViewer::isA    3770                   if (SoQtExaminerViewer::isAnimating())
3922                      stopAnimating();            3771                      stopAnimating();
3923                   prevState = currentState;      3772                   prevState = currentState;
3924                   currentState = ROTATING;       3773                   currentState = ROTATING;
3925                   animateBtwPtsPeriod = 0.08f    3774                   animateBtwPtsPeriod = 0.08f;
3926                                                  3775 
3927                   rotAxis = camDir.cross(camU    3776                   rotAxis = camDir.cross(camUpVec);
3928                                                  3777 
3929                   rotCnt = ROT_CNT;              3778                   rotCnt = ROT_CNT;
3930                   moveCamera(); // To make su    3779                   moveCamera(); // To make sure camera is perpendicular to the beamline
3931                   rotateCamera();                3780                   rotateCamera();
3932                                                  3781 
3933                }                                 3782                }
3934                return TRUE;                      3783                return TRUE;
3935                                                  3784 
3936             case ANIMATION:                      3785             case ANIMATION:
3937             case REVERSED_ANIMATION:             3786             case REVERSED_ANIMATION:
3938                up_down -= 1.5f;                  3787                up_down -= 1.5f;
3939                return TRUE;                      3788                return TRUE;
3940             case PAUSED_ANIMATION:               3789             case PAUSED_ANIMATION:
3941                up_down -= 1.5f;                  3790                up_down -= 1.5f;
3942                setStartingPtForAnimation();      3791                setStartingPtForAnimation();
3943                cam->position = myCam->positio    3792                cam->position = myCam->position;
3944                return TRUE;                      3793                return TRUE;
3945             case GENERAL:                        3794             case GENERAL:
3946             case VIEWPOINT:                      3795             case VIEWPOINT:
3947                // Using this allows us to loo    3796                // Using this allows us to look around without
3948                // changing the camera paramet    3797                // changing the camera parameters (camDir, camUpVec)
3949                if ((!this->lshiftdown) && (!t    3798                if ((!this->lshiftdown) && (!this->rshiftdown)) {
3950                   this->leftWheelMotion(this-    3799                   this->leftWheelMotion(this->getLeftWheelValue() - 0.1f);
3951                   return TRUE;                   3800                   return TRUE;
3952                }                                 3801                }
3953                break;                            3802                break;
3954             case ROTATING:                       3803             case ROTATING:
3955                // For this state, let the key    3804                // For this state, let the keyboard event
3956                // be handled by superclass       3805                // be handled by superclass
3957                break;                            3806                break;
3958             default:                             3807             default:
3959                SoDebugError::post("G4OpenInve    3808                SoDebugError::post("G4OpenInventorQtExaminerViewer::processSoEvent",
3960                                   "Unhandled     3809                                   "Unhandled viewer state");
3961                break;                            3810                break;
3962             }                                    3811             }
3963             break;                               3812             break;
3964                                                  3813 
3965          case SoKeyboardEvent::UP_ARROW:         3814          case SoKeyboardEvent::UP_ARROW:
3966             switch(currentState) {               3815             switch(currentState) {
3967             case BEAMLINE:                       3816             case BEAMLINE:
3968                if ((this->lshiftdown)   || (t    3817                if ((this->lshiftdown)   || (this->rshiftdown)) {
3969                   refParticleIdx -= step;        3818                   refParticleIdx -= step;
3970                   moveCamera();                  3819                   moveCamera();
3971                }                                 3820                }
3972                else{                             3821                else{
3973                   if (SoQtExaminerViewer::isA    3822                   if (SoQtExaminerViewer::isAnimating())
3974                      stopAnimating();            3823                      stopAnimating();
3975                   prevState = currentState;      3824                   prevState = currentState;
3976                   currentState = ROTATING;       3825                   currentState = ROTATING;
3977                   animateBtwPtsPeriod = 0.08f    3826                   animateBtwPtsPeriod = 0.08f;
3978                                                  3827 
3979                   rotAxis = camUpVec.cross(ca    3828                   rotAxis = camUpVec.cross(camDir);
3980                                                  3829 
3981                   rotCnt = ROT_CNT;              3830                   rotCnt = ROT_CNT;
3982                   moveCamera();                  3831                   moveCamera();
3983                                                  3832 
3984                   rotateCamera();                3833                   rotateCamera();
3985                                                  3834 
3986                                                  3835 
3987                }                                 3836                }
3988                return TRUE;                      3837                return TRUE;
3989             case ANIMATION:                      3838             case ANIMATION:
3990             case REVERSED_ANIMATION:             3839             case REVERSED_ANIMATION:
3991                up_down += 1.5f;                  3840                up_down += 1.5f;
3992                return TRUE;                      3841                return TRUE;
3993             case PAUSED_ANIMATION:               3842             case PAUSED_ANIMATION:
3994                up_down += 1.5f;                  3843                up_down += 1.5f;
3995                setStartingPtForAnimation();      3844                setStartingPtForAnimation();
3996                cam->position = myCam->positio    3845                cam->position = myCam->position;
3997                return TRUE;                      3846                return TRUE;
3998             case GENERAL:                        3847             case GENERAL:
3999             case VIEWPOINT:                      3848             case VIEWPOINT:
4000                // Using this allows us to loo    3849                // Using this allows us to look around without
4001                // changing the camera paramet    3850                // changing the camera parameters (camDir, camUpVec)
4002                if ((!this->lshiftdown) && (!t    3851                if ((!this->lshiftdown) && (!this->rshiftdown)) {
4003                   this->leftWheelMotion(this-    3852                   this->leftWheelMotion(this->getLeftWheelValue() + 0.1f);
4004                   return TRUE;                   3853                   return TRUE;
4005                }                                 3854                }
4006                break;                            3855                break;
4007             case ROTATING:                       3856             case ROTATING:
4008                // For this state, let the key    3857                // For this state, let the keyboard event
4009                // be handled by superclass       3858                // be handled by superclass
4010                break;                            3859                break;
4011             default:                             3860             default:
4012                SoDebugError::post("G4OpenInve    3861                SoDebugError::post("G4OpenInventorQtExaminerViewer::processSoEvent",
4013                                   "Unhandled     3862                                   "Unhandled viewer state");
4014                break;                            3863                break;
4015             }                                    3864             }
4016             break;                               3865             break;
4017                                                  3866 
4018          case SoKeyboardEvent::PAGE_UP:          3867          case SoKeyboardEvent::PAGE_UP:
4019             switch(currentState) {               3868             switch(currentState) {
4020             case BEAMLINE:                       3869             case BEAMLINE:
4021                if (step < (int) refParticleTr    3870                if (step < (int) refParticleTrajectory.size() / 5) // Magic number
4022                   step++;                        3871                   step++;
4023                return TRUE;                      3872                return TRUE;
4024             case ANIMATION:                      3873             case ANIMATION:
4025                incSpeed();                       3874                incSpeed();
4026                maxSpeed += SPEED_INDICATOR_ST    3875                maxSpeed += SPEED_INDICATOR_STEP;
4027                if (maxSpeed > 0.8)               3876                if (maxSpeed > 0.8)
4028                   maxSpeed = MAX_SPEED_INDICA    3877                   maxSpeed = MAX_SPEED_INDICATOR;
4029                scheduleRedraw();                 3878                scheduleRedraw();
4030                                                  3879 
4031                return TRUE;                      3880                return TRUE;
4032             case REVERSED_ANIMATION:             3881             case REVERSED_ANIMATION:
4033                if(!animateSensor->isScheduled    3882                if(!animateSensor->isScheduled()) {
4034                   currentState = ANIMATION;      3883                   currentState = ANIMATION;
4035                   if (refParticleIdx             3884                   if (refParticleIdx
4036                       < (int) refParticleTraj    3885                       < (int) refParticleTrajectory.size() - 1) {
4037                      refParticleIdx++;           3886                      refParticleIdx++;
4038                      maxSpeed = SPEED_INDICAT    3887                      maxSpeed = SPEED_INDICATOR_STEP;
4039                      scheduleRedraw();           3888                      scheduleRedraw();
4040                      animateRefParticle();       3889                      animateRefParticle();
4041                   }                              3890                   }
4042                }                                 3891                }
4043                else{                             3892                else{
4044                   maxSpeed += SPEED_INDICATOR    3893                   maxSpeed += SPEED_INDICATOR_STEP;
4045                   decSpeed();                    3894                   decSpeed();
4046                   scheduleRedraw();              3895                   scheduleRedraw();
4047                }                                 3896                }
4048                return TRUE;                      3897                return TRUE;
4049             case PAUSED_ANIMATION:               3898             case PAUSED_ANIMATION:
4050                maxSpeed += SPEED_INDICATOR_ST    3899                maxSpeed += SPEED_INDICATOR_STEP;
4051                if (maxSpeed > 0.8)               3900                if (maxSpeed > 0.8)
4052                   maxSpeed = MAX_SPEED_INDICA    3901                   maxSpeed = MAX_SPEED_INDICATOR;
4053                                                  3902 
4054                if (beforePausing == ANIMATION    3903                if (beforePausing == ANIMATION) {
4055                   incSpeed();                    3904                   incSpeed();
4056                } else {                          3905                } else {
4057                   decSpeed();                    3906                   decSpeed();
4058                   if (animateBtwPtsPeriod >=     3907                   if (animateBtwPtsPeriod >= MIN_SPEED)
4059                      beforePausing = ANIMATIO    3908                      beforePausing = ANIMATION;
4060                }                                 3909                }
4061                                                  3910 
4062                scheduleRedraw();                 3911                scheduleRedraw();
4063                return TRUE;                      3912                return TRUE;
4064             default:    //fall through           3913             default:    //fall through
4065                break;                            3914                break;
4066             }                                    3915             }
4067             break;                               3916             break;
4068                                                  3917 
4069          case SoKeyboardEvent::PAGE_DOWN:        3918          case SoKeyboardEvent::PAGE_DOWN:
4070             switch(currentState) {               3919             switch(currentState) {
4071             case BEAMLINE:                       3920             case BEAMLINE:
4072                if (step > 1)                     3921                if (step > 1)
4073                   step--;                        3922                   step--;
4074                return TRUE;                      3923                return TRUE;
4075             case ANIMATION:                      3924             case ANIMATION:
4076                if(!animateSensor->isScheduled    3925                if(!animateSensor->isScheduled()) {
4077                   currentState = REVERSED_ANI    3926                   currentState = REVERSED_ANIMATION;
4078                   if (refParticleIdx > 1) {      3927                   if (refParticleIdx > 1) {
4079                      refParticleIdx--;           3928                      refParticleIdx--;
4080                      maxSpeed = -SPEED_INDICA    3929                      maxSpeed = -SPEED_INDICATOR_STEP;
4081                      scheduleRedraw();           3930                      scheduleRedraw();
4082                      animateRefParticle();       3931                      animateRefParticle();
4083                   }                              3932                   }
4084                }                                 3933                }
4085                else{                             3934                else{
4086                   maxSpeed -= SPEED_INDICATOR    3935                   maxSpeed -= SPEED_INDICATOR_STEP;
4087                   decSpeed();                    3936                   decSpeed();
4088                   scheduleRedraw();              3937                   scheduleRedraw();
4089                }                                 3938                }
4090                return TRUE;                      3939                return TRUE;
4091             case REVERSED_ANIMATION:             3940             case REVERSED_ANIMATION:
4092                incSpeed();                       3941                incSpeed();
4093                maxSpeed -= SPEED_INDICATOR_ST    3942                maxSpeed -= SPEED_INDICATOR_STEP;
4094                if (maxSpeed < -0.8)              3943                if (maxSpeed < -0.8)
4095                   maxSpeed = -MAX_SPEED_INDIC    3944                   maxSpeed = -MAX_SPEED_INDICATOR;
4096                scheduleRedraw();                 3945                scheduleRedraw();
4097                return TRUE;                      3946                return TRUE;
4098             case PAUSED_ANIMATION:               3947             case PAUSED_ANIMATION:
4099                maxSpeed -= SPEED_INDICATOR_ST    3948                maxSpeed -= SPEED_INDICATOR_STEP;
4100                if (maxSpeed < -0.8)              3949                if (maxSpeed < -0.8)
4101                   maxSpeed = -MAX_SPEED_INDIC    3950                   maxSpeed = -MAX_SPEED_INDICATOR;
4102                if (beforePausing == REVERSED_    3951                if (beforePausing == REVERSED_ANIMATION) {
4103                   incSpeed();                    3952                   incSpeed();
4104                } else {                          3953                } else {
4105                   decSpeed();                    3954                   decSpeed();
4106                   if (animateBtwPtsPeriod >=     3955                   if (animateBtwPtsPeriod >= MIN_SPEED)
4107                      beforePausing = REVERSED    3956                      beforePausing = REVERSED_ANIMATION;
4108                }                                 3957                }
4109                scheduleRedraw();                 3958                scheduleRedraw();
4110                return TRUE;                      3959                return TRUE;
4111             default:                             3960             default:
4112                //fall through                    3961                //fall through
4113                break;                            3962                break;
4114             }                                    3963             }
4115             break;                               3964             break;
4116                                                  3965 
4117             // FROM XT VIEWER                    3966             // FROM XT VIEWER
4118             //         case SoKeyboardEvent::    3967             //         case SoKeyboardEvent::E:
4119             //            this->escapeCallbac    3968             //            this->escapeCallback(this->examinerObject);
4120             //            break;                 3969             //            break;
4121                                                  3970 
4122          default:                                3971          default:
4123             break; // To get rid of compiler     3972             break; // To get rid of compiler warnings
4124          }                                       3973          }
4125       }                                          3974       }
4126       if (SoKeyboardEvent::isKeyReleaseEvent(    3975       if (SoKeyboardEvent::isKeyReleaseEvent(ev, ke->getKey())) {
4127          switch (ke->getKey()) {                 3976          switch (ke->getKey()) {
4128          case SoKeyboardEvent::LEFT_SHIFT:       3977          case SoKeyboardEvent::LEFT_SHIFT:
4129             this->lshiftdown = false;            3978             this->lshiftdown = false;
4130             return TRUE;                         3979             return TRUE;
4131          case SoKeyboardEvent::RIGHT_SHIFT:      3980          case SoKeyboardEvent::RIGHT_SHIFT:
4132             this->rshiftdown = false;            3981             this->rshiftdown = false;
4133             return TRUE;                         3982             return TRUE;
4134          case SoKeyboardEvent::LEFT_CONTROL:     3983          case SoKeyboardEvent::LEFT_CONTROL:
4135             this->lctrldown = false;             3984             this->lctrldown = false;
4136             return TRUE;                         3985             return TRUE;
4137          case SoKeyboardEvent::RIGHT_CONTROL:    3986          case SoKeyboardEvent::RIGHT_CONTROL:
4138             this->rctrldown = false;             3987             this->rctrldown = false;
4139             return TRUE;                         3988             return TRUE;
4140          default:                                3989          default:
4141             break;                               3990             break;
4142          }                                       3991          }
4143       }                                          3992       }
4144    }                                             3993    }
4145                                                  3994 
4146    // Pass the event on to the viewer            3995    // Pass the event on to the viewer
4147    // Need some checks here as in Xt viewer?     3996    // Need some checks here as in Xt viewer?
4148                                                  3997 
4149    if (currentState == ANIMATION || currentSt    3998    if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
4150        || currentState == ROTATING)              3999        || currentState == ROTATING)
4151       return FALSE;                              4000       return FALSE;
4152    else                                          4001    else
4153       return SoQtExaminerViewer::processSoEve    4002       return SoQtExaminerViewer::processSoEvent(ev);
4154 }                                                4003 }
4155                                                  4004 
4156                                                  4005 
4157 // REMAINDER OF MENU BAR FUNCTIONS...            4006 // REMAINDER OF MENU BAR FUNCTIONS...
4158                                                  4007 
4159                                                  4008 
4160 void G4OpenInventorQtExaminerViewer::FileLoad    4009 void G4OpenInventorQtExaminerViewer::FileLoadSceneGraphCB()
4161 {                                                4010 {
4162    //   G4cout << "File: Load scene graph CAL    4011    //   G4cout << "File: Load scene graph CALLBACK" << G4endl;
4163                                                  4012 
4164    QFileDialog filedialog(getParentWidget(),     4013    QFileDialog filedialog(getParentWidget(), tr("Load Scene Graph"));
4165    filedialog.setFileMode(QFileDialog::AnyFil    4014    filedialog.setFileMode(QFileDialog::AnyFile);
4166    filedialog.setFont(*font);                    4015    filedialog.setFont(*font);
4167    if (!filedialog.exec()) return;               4016    if (!filedialog.exec()) return;
4168    QStringList filenameinlist = filedialog.se    4017    QStringList filenameinlist = filedialog.selectedFiles();
4169    QString filenamein = filenameinlist[0];       4018    QString filenamein = filenameinlist[0];
4170                                                  4019 
                                                   >> 4020    //   G4cout << "Entered file name is " << qPrintable(filenamein) << G4endl;
                                                   >> 4021 
                                                   >> 4022    char* filename = new char[filenamein.size()+1];
                                                   >> 4023    filename = strdup(qPrintable(filenamein));
                                                   >> 4024    //   G4cout << "char[] file name is " << filename << G4endl;
                                                   >> 4025 
4171    SoInput sceneInput;                           4026    SoInput sceneInput;
4172                                                  4027 
4173    if (sceneInput.openFile(qPrintable(filenam << 4028    if (sceneInput.openFile(filename)) {
4174       // Read the whole file into the databas    4029       // Read the whole file into the database
4175       newSceneGraph = SoDB::readAll(&sceneInp    4030       newSceneGraph = SoDB::readAll(&sceneInput);
4176       if (newSceneGraph == NULL) {               4031       if (newSceneGraph == NULL) {
4177          QMessageBox msgbox;                     4032          QMessageBox msgbox;
4178          msgbox.setFont(*font);                  4033          msgbox.setFont(*font);
4179          QString messagetxt = "Error reading     4034          QString messagetxt = "Error reading scene graph file ";
4180          messagetxt.append(filenamein);          4035          messagetxt.append(filenamein);
4181          msgbox.setText(messagetxt);             4036          msgbox.setText(messagetxt);
4182          msgbox.exec();                          4037          msgbox.exec();
4183          sceneInput.closeFile();                 4038          sceneInput.closeFile();
4184          return;                                 4039          return;
4185       }                                          4040       }
4186    } else {                                      4041    } else {
4187       QMessageBox msgbox;                        4042       QMessageBox msgbox;
4188       msgbox.setFont(*font);                     4043       msgbox.setFont(*font);
4189       QString messagetxt = "Error opening sce    4044       QString messagetxt = "Error opening scene graph file ";
4190       messagetxt.append(filenamein);             4045       messagetxt.append(filenamein);
4191       msgbox.setText(messagetxt);                4046       msgbox.setText(messagetxt);
4192       msgbox.exec();                             4047       msgbox.exec();
4193       return;                                    4048       return;
4194    }                                             4049    }
4195                                                  4050 
4196    SoSeparator* root = (SoSeparator*)getScene    4051    SoSeparator* root = (SoSeparator*)getSceneGraph();
4197    root->unref();                                4052    root->unref();
4198    newSceneGraph->ref();                         4053    newSceneGraph->ref();
4199    setSceneGraph(newSceneGraph);                 4054    setSceneGraph(newSceneGraph);
4200 }                                                4055 }
4201                                                  4056 
4202 void G4OpenInventorQtExaminerViewer::FileSave    4057 void G4OpenInventorQtExaminerViewer::FileSaveSceneGraphCB()
4203 {                                                4058 {
4204    //   G4cout << "File: Save scene graph CAL    4059    //   G4cout << "File: Save scene graph CALLBACK" << G4endl;
4205                                                  4060 
4206    QFileDialog filedialog(getParentWidget(),     4061    QFileDialog filedialog(getParentWidget(), tr("Save scene graph"));
4207    filedialog.setFileMode(QFileDialog::AnyFil    4062    filedialog.setFileMode(QFileDialog::AnyFile);
4208    // To enable confirmation of overwriting      4063    // To enable confirmation of overwriting
4209    filedialog.setAcceptMode(QFileDialog::Acce    4064    filedialog.setAcceptMode(QFileDialog::AcceptSave);
4210    filedialog.setFont(*font);                    4065    filedialog.setFont(*font);
4211    if (!filedialog.exec()) return;               4066    if (!filedialog.exec()) return;
4212    QStringList filenameinlist = filedialog.se    4067    QStringList filenameinlist = filedialog.selectedFiles();
4213    QString filenamein = filenameinlist[0];       4068    QString filenamein = filenameinlist[0];
4214                                                  4069 
                                                   >> 4070    //   G4cout << "Entered file name is " << qPrintable(filenamein) << G4endl;
                                                   >> 4071 
                                                   >> 4072    char* filename = new char[filenamein.size()+1];
                                                   >> 4073    filename = strdup(qPrintable(filenamein));
                                                   >> 4074    //   G4cout << "char[] file name is " << filename << G4endl;
                                                   >> 4075 
4215    SoWriteAction writeAction;                    4076    SoWriteAction writeAction;
4216    SoSeparator* root = (SoSeparator*)getScene    4077    SoSeparator* root = (SoSeparator*)getSceneGraph();
4217                                                  4078 
4218    SoOutput* out = writeAction.getOutput();      4079    SoOutput* out = writeAction.getOutput();
4219                                                  4080 
4220    if (out->openFile(qPrintable(filenamein))) << 4081    if (out->openFile(filename)) {
4221       out->setBinary(FALSE);                     4082       out->setBinary(FALSE);
4222       writeAction.apply(root);                   4083       writeAction.apply(root);
4223       out->closeFile();                          4084       out->closeFile();
4224    } else {                                      4085    } else {
4225       QMessageBox msgbox;                        4086       QMessageBox msgbox;
4226       msgbox.setFont(*font);                     4087       msgbox.setFont(*font);
4227       QString messagetxt = "Error opening fil    4088       QString messagetxt = "Error opening file ";
4228       messagetxt.append(filenamein);             4089       messagetxt.append(filenamein);
4229       msgbox.setText(messagetxt);                4090       msgbox.setText(messagetxt);
4230       msgbox.exec();                             4091       msgbox.exec();
4231    }                                             4092    }
4232 }                                                4093 }
4233                                                  4094 
4234                                                  4095 
4235 void G4OpenInventorQtExaminerViewer::HelpCont    4096 void G4OpenInventorQtExaminerViewer::HelpControlsCB()
4236 {                                                4097 {
4237    //   G4cout << "Help: Help Controls CALLBA    4098    //   G4cout << "Help: Help Controls CALLBACK" << G4endl;
4238    helpmsgbox->show();                           4099    helpmsgbox->show();
4239 }                                                4100 }
4240                                                  4101 
4241                                                  4102 
4242 HookEventProcState::HookEventProcState(G4Open    4103 HookEventProcState::HookEventProcState(G4OpenInventorQtExaminerViewer* vwr)
4243 {                                                4104 {
4244    viewer = vwr;                                 4105    viewer = vwr;
4245 }                                                4106 }
4246                                                  4107 
4247 HookEventProcState::~HookEventProcState()        4108 HookEventProcState::~HookEventProcState()
4248 {;}                                              4109 {;}
4249                                                  4110 
4250 G4bool HookEventProcState::Notify(G4Applicati    4111 G4bool HookEventProcState::Notify(G4ApplicationState requestedState)
4251 {                                                4112 {
4252 #if QT_VERSION < 0x060000                     << 
4253    if (requestedState == G4State_EventProc) v << 
4254 #else                                         << 
4255 #ifdef G4MULTITHREADED                        << 
4256    //G.Barrand: on the master thread, we are  << 
4257    //           we raise the newEvents flag o << 
4258    G4StateManager* stateManager = G4StateMana << 
4259    G4ApplicationState previousState = stateMa << 
4260  //if (previousState == G4State_Idle       && << 
4261  //if (previousState == G4State_GeomClosed && << 
4262  //if (previousState == G4State_EventProc  && << 
4263    if (previousState == G4State_GeomClosed && << 
4264      viewer->newEvents = true;                << 
4265    }                                          << 
4266 #else                                         << 
4267    if (requestedState == G4State_EventProc) v    4113    if (requestedState == G4State_EventProc) viewer->newEvents = true;
4268 #endif                                        << 
4269 #endif                                        << 
4270    return true;                                  4114    return true;
4271 }                                                4115 }
4272                                                  4116