Geant4  10.00.p01
G4OpenInventorXtExaminerViewer.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // Open Inventor Xt Extended Viewer - 30 Oct 2012
27 // Rastislav Ondrasek, Pierre-Luc Gagnon, Frederick Jones TRIUMF
28 
29 #ifndef HookEventProcState_H
30 #define HookEventProcState_H 1
31 #include "G4VStateDependent.hh"
32 
35 {
36 private:
38 public:
41 
42  virtual G4bool Notify(G4ApplicationState requiredState);
43 };
44 #endif /* HookEventProcState_H */
45 
46 
47 #ifndef G4OPENINVENTORXTEXAMINERVIEWER_HH
48 #define G4OPENINVENTORXTEXAMINERVIEWER_HH
49 
50 #include <map>
51 #include <vector>
52 #include <fstream>
53 #include <Inventor/SbLinear.h>
54 #include <Inventor/nodes/SoLineSet.h>
55 #include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
56 #include <Inventor/events/SoKeyboardEvent.h>
57 
58 class SoCoordinate3;
59 class SoFont;
60 class SoText2;
61 class SoPointSet;
62 
63 class G4OpenInventorXtExaminerViewer : public SoXtExaminerViewer {
64 private:
70 
72  void (*escapeCallback)(void *);
75 
76 public:
77 
78  // Same constructor as the ExaminerViewer
79  G4OpenInventorXtExaminerViewer(Widget parent = NULL,
80  const char *name = NULL,
81  SbBool embed = TRUE,
82  SoXtFullViewer::BuildFlag flag = BUILD_ALL,
83  SoXtViewer::Type type = BROWSER);
84 
86  template <class T> void parseString(T &t, const std::string &s, bool &error);
87  Widget addMenu(std::string name);
88  void addButton(Widget menu, std::string name, XtCallbackProc);
89  Widget getMenuBar() { return menuBar; }
90  Widget getMenu() { return fileMenu; }
91  void warningMsgDialog(std::string, String, XtCallbackProc);
93 
96  std::string saveRefCoordsFileName;
98 
99  Widget createScale(Widget, char *, int, float);
100  void addEscapeCallback(void (*cb)(void *), void *);
104 
105 protected:
106  // Same constructor as the ExaminerViewer
107  G4OpenInventorXtExaminerViewer(Widget parent,
108  const char *name,
109  SbBool embed,
110  SoXtFullViewer::BuildFlag flag,
111  SoXtViewer::Type type,
112  SbBool build);
113 
114  // Overloaded for adding the MenuBar
115  Widget buildWidget(Widget parent);
116  // Overloaded so additional buttons can be added
117  virtual void createViewerButtons (Widget parent, SbPList * buttonlist);
118  // Overloaded for catching various keyboard events
119  virtual SbBool processSoEvent(const SoEvent * const event);
120  void moveCamera(float dist = 0, bool lookdown = false);
121  std::string curEltName;
122  SbVec3f camUpVec;
123  SbVec3f camDir;
124  void rotateCamera();
125  void updateViewParams(SoKeyboardEvent::Key);
126  bool loadViewPts();
127  virtual void afterRealizeHook();
128 
129 private:
130  // Each constructor calls this generic constructor
131  void constructor(const SbBool build);
132 
134 
136  friend class HookEventProcState;
137  bool newEvents;
138  static void sceneChangeCB(void *, SoSensor *);
139 
140  void setViewPt();
141  void writeViewPtIdx();
142  void cleanUpAfterPrevFile();
143 
144  void popUpFileSelDialog(Widget&, std::string, std::string, XtCallbackProc);
145  static void cancelFileSelDialogCB(Widget, XtPointer, XtPointer);
146  static void openViewPtFileCB(Widget, XtPointer, XtPointer);
147  static void viewPtFileSelectedCB(Widget, XtPointer, XtPointer);
148  static void newViewPtFileCB(Widget, XtPointer, XtPointer);
149  static void createNewVPFileCB(Widget, XtPointer, XtPointer);
150  static void overwriteFileCB(Widget, XtPointer, XtPointer);
151  static void loadRefCoordsDialogCB(Widget, XtPointer, XtPointer); //pop file dialog
152  static void loadRefCoordsCB(Widget, XtPointer, XtPointer); //execute loading
153  static void saveRefCoordsDialogCB(Widget, XtPointer, XtPointer); //pop file dialog
154  static void saveRefCoordsCB(Widget, XtPointer, XtPointer); //execute saving
155  static void saveRefCoordsOverWriteCB(Widget, XtPointer, XtPointer);
156  static void loadSceneGraphDialogCB(Widget, XtPointer, XtPointer);
157  static void loadSceneGraphCB(Widget, XtPointer, XtPointer);
158  static void saveSceneGraphDialogCB(Widget, XtPointer, XtPointer);
159  static void saveSceneGraphCB(Widget, XtPointer, XtPointer);
160  static void saveSceneGraphOverWriteCB(Widget, XtPointer, XtPointer);
161  static void mouseoverCB(void *aThis, SoEventCallback *eventCB);
162  static void pickingCB(void *aThis, SoEventCallback *eventCB);
163 
164 
165  // Viewpoint operations
166  void addViewPoints();
167  static void closeListsDialogCB(Widget, XtPointer, XtPointer);
168  static void loadBookmarkCB(Widget, XtPointer, XtPointer);
169  static void renameBookmarkCB(Widget, XtPointer, XtPointer);
170  void renameViewPt(char *vpName);
171  static void sortBookmarksCB(Widget, XtPointer, XtPointer);
172  void sortViewPts(std::vector<std::string>);
173  static void deleteBookmarkCB(Widget, XtPointer, XtPointer);
174  static void deleteViewPtCB(Widget, XtPointer, XtPointer);
175  void deleteViewPt(char *vpName = NULL);
176 
177  // Animation
178  static void animateRefParticleCB(Widget, XtPointer, XtPointer);
179  static void animateSensorCB(void *, SoSensor *);
180  static void animateSensorRotationCB(void *, SoSensor *);
181  void animateRefParticle();
182  void saveCurCamera();
183  void restoreCamera();
185  void incSpeed();
186  void decSpeed();
187 
188  SoTimerSensor *animateSensor;
189  SoTimerSensor *animateSensorRotation;
190  SoNodeSensor *sceneChangeSensor;
193 
194  static void prevViewPtCB(Widget, XtPointer, XtPointer);
195  static void nextViewPtCB(Widget, XtPointer, XtPointer);
196  static void saveViewPtCB(Widget, XtPointer, XtPointer);
197  static void abbrOutputCB(Widget, XtPointer, XtPointer);
198  static void pickRefPathCB(Widget, XtPointer, XtPointer);
199  static void constructListsDialog(Widget, XtPointer, XtPointer);
200  void saveViewPt(char *name);
201 
202 
203  static void lookAtSceneElementCB(Widget, XtPointer, XtPointer);
204  static void cancelSceneElementSelectionCB(Widget, XtPointer, XtPointer);
205 
206  void setReferencePath(SoLineSet*, SoCoordinate3*, bool append = false);
207  void setReferencePathZPos();
208  void findAndSetRefPath();
209  SoCoordinate3 *getCoordsNode(SoFullPath *path);
210  void getSceneElements(); // reads elements from the scene graph
211  float sqrlen(const SbVec3f&);
212  void distanceToTrajectory(const SbVec3f&, float&, SbVec3f&, int&);
213  void sortElements();
214  void createElementsList(Widget);
215  static void closeMainWindowCB(Widget, XtPointer, XtPointer);
216  void evenOutRefParticlePts();
217 
218  static void gotoRefPathStartCB(Widget, XtPointer, XtPointer);
219  void gotoRefPathStart();
220  static void invertRefPathCB(Widget, XtPointer, XtPointer);
221  void invertRefPath();
222 
223  enum CameraType {
226  };
227 
228 
229  enum State {
237  };
238 
239  // For storing the view point
240  struct viewPtData {
241  char* viewPtName;
243  SbVec3f position;
244  SbRotation orientation;
245  float aspectRatio;
247  float farDistance;
250  float height;
251  };
252 
253  // FWJ removed unneeded assignment operator
254  struct sceneElement {
255  std::string name;
256  SoFullPath* path;
257  SbVec3f center;
259  };
260 
263  SbVec3f closestPoint;
266  std::string name;
267 
268  bool operator<(elementForSorting const &other) const
269  {
270  if (closestPointZCoord < other.closestPointZCoord)
271  return true;
272  if (closestPointZCoord > other.closestPointZCoord)
273  return false;
274 
275  // otherwise closestPointZCoord == other.closestPointZCoord.
276  // Compare the distances from the center of the element to
277  // the start of the beamline.
278  if (distanceToBeamlineStart < other.distanceToBeamlineStart)
279  return true;
280  if (distanceToBeamlineStart > other.distanceToBeamlineStart)
281  return false;
282 
283  // In case both closestPointZCoord and smallestDistance are
284  // equal, we have two exactly overlapping elements, if so
285  // the order doesn't matter
286  return true;
287  }
288  };
289 
291 
292  std::vector<sceneElement> sceneElements;
293  std::vector<viewPtData> viewPtList;
294  std::string fileName;
295  std::ifstream fileIn;
296  std::ofstream fileOut;
300 
301  // For storing coordinate points of the reference particle
302  std::vector<SbVec3f> refParticleTrajectory;
303  // For displaying distance during anim and beamline modes
304  std::vector<float> refZPositions;
307  float distance;
310 
311  int step;
312  SbVec3f prevPt;
315 
319  SoCamera *myCam;
322  SbVec3f rotAxis; // For 90 degree rotations
323  int rotCnt; // # of steps rotation is split into
324 
325  static void getViewPtNameCB(Widget, XtPointer, XtPointer);
326  std::string viewPtAutoName();
327 
329  SoSearchAction * searcher;
330 
331  SoNode * superimposition;
332  SoCoordinate3 * sgeometry;
333  SoScale * sscale;
334 
335  SoTranslation * stranslation;
336  SoTranslation * curInfoTrans;
337  SoTranslation * mouseOverTransSolid;
338  SoTranslation * mouseOverTransMaterial;
339  SoTranslation * mouseOverTransLogName;
340  SoTranslation * mouseOverTransZPos;
341 
342  // Used for 2 similar purposes: 1. Displays z position during animation
343  // 2. Displays name of the current viewpoint
344  SoText2 * curInfoText;
345  /* Need to use many different fields for mouseover
346  * because newlines are ignored when the scene is rendered */
350  SoText2 * mouseOverTextZPos;
351 
352  SoFont * curInfoFont;
357  SoSwitch * axisSwitch;
359  SoSwitch * animSpeedSwitch;
360  SoSwitch * curInfoSwitch;
361 
362  SoNode * getSuperimpositionNode(SoNode *, const char * name);
363 
364  void superimpositionEvent(SoAction * action);
365  static void superimpositionCB(void * closure, SoAction * action);
366 
367  virtual void actualRedraw(void);
368  void updateSpeedIndicator(void);
369 
370  float maxSpeed;
372 
373  // FWJ added for Ortho camera
376 
377  // Used by G4 app during element rotations, stores previous view
379  bool rotUpVec;
380 
381  SoSeparator * newSceneGraph;
382 
383 
384 };
385 #endif /* G4OPENINVENTORXTEXAMINERVIEWER_HH */
static G4OpenInventorXtExaminerViewer * getObject()
static void loadSceneGraphDialogCB(Widget, XtPointer, XtPointer)
static void constructListsDialog(Widget, XtPointer, XtPointer)
static void saveRefCoordsOverWriteCB(Widget, XtPointer, XtPointer)
static void loadBookmarkCB(Widget, XtPointer, XtPointer)
static void saveViewPtCB(Widget, XtPointer, XtPointer)
G4OpenInventorXtExaminerViewer * viewer
void setReferencePath(SoLineSet *, SoCoordinate3 *, bool append=false)
static void sortBookmarksCB(Widget, XtPointer, XtPointer)
G4String name
Definition: TRTMaterials.hh:40
static void cancelSceneElementSelectionCB(Widget, XtPointer, XtPointer)
static void pickRefPathCB(Widget, XtPointer, XtPointer)
static void saveSceneGraphOverWriteCB(Widget, XtPointer, XtPointer)
static void lookAtSceneElementCB(Widget, XtPointer, XtPointer)
void updateViewParams(SoKeyboardEvent::Key)
static void overwriteFileCB(Widget, XtPointer, XtPointer)
static void closeListsDialogCB(Widget, XtPointer, XtPointer)
void parseString(T &t, const std::string &s, bool &error)
SoNode * getSuperimpositionNode(SoNode *, const char *name)
static void mouseoverCB(void *aThis, SoEventCallback *eventCB)
static void sceneChangeCB(void *, SoSensor *)
static G4OpenInventorXtExaminerViewer * viewer
void moveCamera(float dist=0, bool lookdown=false)
static void prevViewPtCB(Widget, XtPointer, XtPointer)
Widget createScale(Widget, char *, int, float)
virtual G4bool Notify(G4ApplicationState requiredState)
SoCoordinate3 * getCoordsNode(SoFullPath *path)
G4OpenInventorXtExaminerViewer(Widget parent=NULL, const char *name=NULL, SbBool embed=TRUE, SoXtFullViewer::BuildFlag flag=BUILD_ALL, SoXtViewer::Type type=BROWSER)
static const double s
Definition: G4SIunits.hh:150
static void animateSensorRotationCB(void *, SoSensor *)
static void invertRefPathCB(Widget, XtPointer, XtPointer)
static void abbrOutputCB(Widget, XtPointer, XtPointer)
static void saveSceneGraphDialogCB(Widget, XtPointer, XtPointer)
static void createNewVPFileCB(Widget, XtPointer, XtPointer)
bool G4bool
Definition: G4Types.hh:79
void warningMsgDialog(std::string, String, XtCallbackProc)
static void saveSceneGraphCB(Widget, XtPointer, XtPointer)
static void superimpositionCB(void *closure, SoAction *action)
static void closeMainWindowCB(Widget, XtPointer, XtPointer)
static void gotoRefPathStartCB(Widget, XtPointer, XtPointer)
#define TRUE
Definition: globals.hh:55
static void renameBookmarkCB(Widget, XtPointer, XtPointer)
static void animateRefParticleCB(Widget, XtPointer, XtPointer)
void distanceToTrajectory(const SbVec3f &, float &, SbVec3f &, int &)
HookEventProcState(G4OpenInventorXtExaminerViewer *)
static void saveRefCoordsDialogCB(Widget, XtPointer, XtPointer)
void popUpFileSelDialog(Widget &, std::string, std::string, XtCallbackProc)
void addButton(Widget menu, std::string name, XtCallbackProc)
static void viewPtFileSelectedCB(Widget, XtPointer, XtPointer)
static void cancelFileSelDialogCB(Widget, XtPointer, XtPointer)
static void newViewPtFileCB(Widget, XtPointer, XtPointer)
static void deleteViewPtCB(Widget, XtPointer, XtPointer)
static void animateSensorCB(void *, SoSensor *)
static void nextViewPtCB(Widget, XtPointer, XtPointer)
bool operator<(elementForSorting const &other) const
static void deleteBookmarkCB(Widget, XtPointer, XtPointer)
static void getViewPtNameCB(Widget, XtPointer, XtPointer)
static void openViewPtFileCB(Widget, XtPointer, XtPointer)
static PROLOG_HANDLER error
Definition: xmlrole.cc:108
static void pickingCB(void *aThis, SoEventCallback *eventCB)
virtual SbBool processSoEvent(const SoEvent *const event)
static void loadRefCoordsCB(Widget, XtPointer, XtPointer)
void sortViewPts(std::vector< std::string >)
static void loadSceneGraphCB(Widget, XtPointer, XtPointer)
static void saveRefCoordsCB(Widget, XtPointer, XtPointer)
void addEscapeCallback(void(*cb)(void *), void *)
G4ApplicationState
static void loadRefCoordsDialogCB(Widget, XtPointer, XtPointer)
virtual void createViewerButtons(Widget parent, SbPList *buttonlist)