Geant4  10.02
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 
34 
36 {
37 private:
39 public:
42 
43  virtual G4bool Notify(G4ApplicationState requiredState);
44 };
45 #endif /* HookEventProcState_H */
46 
47 
48 #ifndef G4OPENINVENTORXTEXAMINERVIEWER_HH
49 #define G4OPENINVENTORXTEXAMINERVIEWER_HH
50 
51 #include <map>
52 #include <vector>
53 #include <fstream>
54 #include <Inventor/SbLinear.h>
55 #include <Inventor/nodes/SoLineSet.h>
56 #include <Inventor/nodes/SoEventCallback.h>
57 #include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
58 #include <Inventor/events/SoKeyboardEvent.h>
59 
60 class SoCoordinate3;
61 class SoFont;
62 class SoText2;
63 class SoPointSet;
64 
65 class G4OpenInventorXtExaminerViewer : public SoXtExaminerViewer {
66 
68 
69 private:
75 
77  void (*escapeCallback)(void *);
80 
81 public:
82 
83  // Same constructor as the ExaminerViewer
84  G4OpenInventorXtExaminerViewer(Widget parent = NULL,
85  const char *name = NULL,
86  SbBool embed = TRUE,
87  SoXtFullViewer::BuildFlag flag = BUILD_ALL,
88  SoXtViewer::Type type = BROWSER);
89 
91 
92  template <class T> void parseString(T &t, const std::string &s, bool &error);
93 
94  Widget addMenu(std::string name);
95  void addButton(Widget menu, std::string name, XtCallbackProc);
96  Widget getMenuBar() { return menuBar; }
97  Widget getMenu() { return fileMenu; }
98  void warningMsgDialog(std::string, String, XtCallbackProc);
100 
105 
106  Widget createScale(Widget, char *, int, float);
107  void addEscapeCallback(void (*cb)(void *), void *);
111 
112 protected:
113  // Same constructor as the ExaminerViewer
114  G4OpenInventorXtExaminerViewer(Widget parent,
115  const char *name,
116  SbBool embed,
117  SoXtFullViewer::BuildFlag flag,
118  SoXtViewer::Type type,
119  SbBool build);
120 
121  // Overloaded for adding the MenuBar
122  Widget buildWidget(Widget parent);
123  // Overloaded so additional buttons can be added
124  virtual void createViewerButtons (Widget parent, SbPList * buttonlist);
125  // Overloaded for catching various keyboard events
126  virtual SbBool processSoEvent(const SoEvent * const event);
127  void moveCamera(float dist = 0, bool lookdown = false);
128  std::string curEltName;
129  SbVec3f camUpVec;
130  SbVec3f camDir;
131  void rotateCamera();
132  void updateViewParams(SoKeyboardEvent::Key);
133  bool loadViewPts();
134  virtual void afterRealizeHook();
135 
136 private:
137  // Each constructor calls this generic constructor
138  void constructor(const SbBool build);
139 
140  // FWJ DISABLED
141  // static G4OpenInventorXtExaminerViewer *getObject();
142 
144  friend class HookEventProcState;
145  bool newEvents;
146  static void sceneChangeCB(void *, SoSensor *);
147 
148  void setViewPt();
149  void writeViewPtIdx();
150  void cleanUpAfterPrevFile();
151 
152  void popUpFileSelDialog(Widget&, std::string, std::string, XtCallbackProc);
153  static void cancelFileSelDialogCB(Widget, XtPointer, XtPointer);
154  static void openViewPtFileCB(Widget, XtPointer, XtPointer);
155  static void viewPtFileSelectedCB(Widget, XtPointer, XtPointer);
156  static void newViewPtFileCB(Widget, XtPointer, XtPointer);
157  static void createNewVPFileCB(Widget, XtPointer, XtPointer);
158  static void overwriteFileCB(Widget, XtPointer, XtPointer);
159  static void loadRefCoordsDialogCB(Widget, XtPointer, XtPointer); //pop file dialog
160  static void loadRefCoordsCB(Widget, XtPointer, XtPointer); //execute loading
161  static void saveRefCoordsDialogCB(Widget, XtPointer, XtPointer); //pop file dialog
162  static void saveRefCoordsCB(Widget, XtPointer, XtPointer); //execute saving
163  static void saveRefCoordsOverWriteCB(Widget, XtPointer, XtPointer);
164  static void loadSceneGraphDialogCB(Widget, XtPointer, XtPointer);
165  static void loadSceneGraphCB(Widget, XtPointer, XtPointer);
166  static void saveSceneGraphDialogCB(Widget, XtPointer, XtPointer);
167  static void saveSceneGraphCB(Widget, XtPointer, XtPointer);
168  static void saveSceneGraphOverWriteCB(Widget, XtPointer, XtPointer);
169  static void mouseoverCB(void *aThis, SoEventCallback *eventCB);
170  static void pickingCB(void *aThis, SoEventCallback *eventCB);
171 
172 
173  // Viewpoint operations
174  void addViewPoints();
175  static void closeListsDialogCB(Widget, XtPointer, XtPointer);
176  static void loadBookmarkCB(Widget, XtPointer, XtPointer);
177  static void renameBookmarkCB(Widget, XtPointer, XtPointer);
178  void renameViewPt(char *vpName);
179  static void sortBookmarksCB(Widget, XtPointer, XtPointer);
180  void sortViewPts(std::vector<std::string>);
181  static void deleteBookmarkCB(Widget, XtPointer, XtPointer);
182  static void deleteViewPtCB(Widget, XtPointer, XtPointer);
183  void deleteViewPt(char *vpName = NULL);
184 
185  // Animation
186  static void animateRefParticleCB(Widget, XtPointer, XtPointer);
187  static void animateSensorCB(void *, SoSensor *);
188  static void animateSensorRotationCB(void *, SoSensor *);
189  void animateRefParticle();
190  void saveCurCamera();
191  void restoreCamera();
193  void incSpeed();
194  void decSpeed();
195 
196  SoTimerSensor *animateSensor;
197  SoTimerSensor *animateSensorRotation;
198  SoNodeSensor *sceneChangeSensor;
201 
202  static void prevViewPtCB(Widget, XtPointer, XtPointer);
203  static void nextViewPtCB(Widget, XtPointer, XtPointer);
204  static void saveViewPtCB(Widget, XtPointer, XtPointer);
205  static void abbrOutputCB(Widget, XtPointer, XtPointer);
206  static void pickRefPathCB(Widget, XtPointer, XtPointer);
207  static void constructListsDialog(Widget, XtPointer, XtPointer);
208  void saveViewPt(char *name);
209 
210 
211  static void lookAtSceneElementCB(Widget, XtPointer, XtPointer);
212  static void cancelSceneElementSelectionCB(Widget, XtPointer, XtPointer);
213 
214  void setReferencePath(SoLineSet*, SoCoordinate3*, bool append = false);
215  void setReferencePathZPos();
216  void findAndSetRefPath();
217  SoCoordinate3* getCoordsNode(SoFullPath *path);
218  void getSceneElements(); // reads elements from the scene graph
219  float sqrlen(const SbVec3f&);
220  void distanceToTrajectory(const SbVec3f&, float&, SbVec3f&, int&);
221  void sortElements();
222  void createElementsList(Widget);
223  static void closeMainWindowCB(Widget, XtPointer, XtPointer);
224  void evenOutRefParticlePts();
225 
226  static void gotoRefPathStartCB(Widget, XtPointer, XtPointer);
227  void gotoRefPathStart();
228  static void invertRefPathCB(Widget, XtPointer, XtPointer);
229  void invertRefPath();
230 
231  enum CameraType {
234  };
235 
236 
237  enum State {
245  };
246 
247  // For storing the view point
248  struct viewPtData {
249  char* viewPtName;
251  SbVec3f position;
252  SbRotation orientation;
253  float aspectRatio;
255  float farDistance;
258  float height;
259  };
260 
261  // FWJ removed unneeded assignment operator
262  struct sceneElement {
263  std::string name;
264  SoFullPath* path;
265  SbVec3f center;
267  };
268 
271  SbVec3f closestPoint;
274  std::string name;
275 
276  bool operator<(elementForSorting const &other) const
277  {
278  if (closestPointZCoord < other.closestPointZCoord)
279  return true;
280  if (closestPointZCoord > other.closestPointZCoord)
281  return false;
282 
283  // otherwise closestPointZCoord == other.closestPointZCoord.
284  // Compare the distances from the center of the element to
285  // the start of the beamline.
286  if (distanceToBeamlineStart < other.distanceToBeamlineStart)
287  return true;
288  if (distanceToBeamlineStart > other.distanceToBeamlineStart)
289  return false;
290 
291  // In case both closestPointZCoord and smallestDistance are
292  // equal, we have two exactly overlapping elements, if so
293  // the order doesn't matter
294  return true;
295  }
296  };
297 
299 
300  std::vector<sceneElement> sceneElements;
301  std::vector<viewPtData> viewPtList;
302  std::string fileName;
303  std::ifstream fileIn;
304  std::ofstream fileOut;
308 
309  // For storing coordinate points of the reference particle
310  std::vector<SbVec3f> refParticleTrajectory;
311  // For displaying distance during anim and beamline modes
312  std::vector<float> refZPositions;
313 
316  float distance;
319 
320  int step;
321  SbVec3f prevPt;
324 
328  SoCamera* myCam;
331  SbVec3f rotAxis; // For 90 degree rotations
332  int rotCnt; // # of steps rotation is split into
333 
334  static void getViewPtNameCB(Widget, XtPointer, XtPointer);
335  std::string viewPtAutoName();
336 
338  SoSearchAction * searcher;
339 
340  SoNode * superimposition;
341  SoCoordinate3 * sgeometry;
342  SoScale * sscale;
343 
344  SoTranslation * stranslation;
345  SoTranslation * curInfoTrans;
346  SoTranslation * mouseOverTransSolid;
347  SoTranslation * mouseOverTransMaterial;
348  SoTranslation * mouseOverTransLogName;
349  SoTranslation * mouseOverTransZPos;
350 
351  // Used for 2 similar purposes: 1. Displays z position during animation
352  // 2. Displays name of the current viewpoint
353  SoText2 * curInfoText;
354  /* Need to use many different fields for mouseover
355  * because newlines are ignored when the scene is rendered */
359  SoText2 * mouseOverTextZPos;
360 
361  SoFont * curInfoFont;
366  SoSwitch * axisSwitch;
368  SoSwitch * animSpeedSwitch;
369  SoSwitch * curInfoSwitch;
370 
371  SoNode * getSuperimpositionNode(SoNode *, const char * name);
372 
373  void superimpositionEvent(SoAction * action);
374  static void superimpositionCB(void * closure, SoAction * action);
375 
376  virtual void actualRedraw(void);
377  void updateSpeedIndicator(void);
378 
379  float maxSpeed;
381 
382  // FWJ added for Ortho camera
385  // FWJ add look-ahead for animation tracking on curves
387 
388  // Used by G4 app during element rotations, stores previous view
390  bool rotUpVec;
391 
392  SoSeparator* newSceneGraph;
393 
394 
395 };
396 #endif /* G4OPENINVENTORXTEXAMINERVIEWER_HH */
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)
int G4int
Definition: G4Types.hh:78
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:168
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:112
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)