ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4OpenInventorXtExaminerViewer.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4OpenInventorXtExaminerViewer.hh
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  // FWJ
70 
71 private:
77 
79  void (*escapeCallback)(void *);
82 
83 public:
84 
85  // Same constructor as the ExaminerViewer
86  G4OpenInventorXtExaminerViewer(Widget parent = NULL,
87  const char *name = NULL,
88  SbBool embed = TRUE,
89  SoXtFullViewer::BuildFlag flag = BUILD_ALL,
90  SoXtViewer::Type type = BROWSER);
91 
93 
94  template <class T> void parseString(T &t, const std::string &s, bool &error);
95 
96  Widget addMenu(std::string name);
97  void addButton(Widget menu, std::string name, XtCallbackProc);
98  Widget getMenuBar() { return menuBar; }
99  Widget getMenu() { return fileMenu; }
100  void warningMsgDialog(std::string, String, XtCallbackProc);
102 
107 
108  Widget createScale(Widget, char *, int, float);
109  void addEscapeCallback(void (*cb)(void *), void *);
113  // FWJ
114  // SoNode * superimposition;
115 
116 protected:
117  // Same constructor as the ExaminerViewer
118  G4OpenInventorXtExaminerViewer(Widget parent,
119  const char *name,
120  SbBool embed,
121  SoXtFullViewer::BuildFlag flag,
122  SoXtViewer::Type type,
123  SbBool build);
124 
125  // Overloaded for adding the MenuBar
126  Widget buildWidget(Widget parent);
127  // Overloaded so additional buttons can be added
128  virtual void createViewerButtons (Widget parent, SbPList * buttonlist);
129  // Overloaded for catching various keyboard events
130  virtual SbBool processSoEvent(const SoEvent * const event);
131  void moveCamera(float dist = 0, bool lookdown = false);
132  std::string curEltName;
133  SbVec3f camUpVec;
134  SbVec3f camDir;
135  void rotateCamera();
136  void updateViewParams(SoKeyboardEvent::Key);
137  bool loadViewPts();
138  virtual void afterRealizeHook();
139 
140 private:
141  // Each constructor calls this generic constructor
142  void constructor(const SbBool build);
143 
144  // FWJ DISABLED
145  // static G4OpenInventorXtExaminerViewer *getObject();
146 
148  friend class HookEventProcState;
149  bool newEvents;
150  static void sceneChangeCB(void *, SoSensor *);
151 
152  void setViewPt();
153  void writeViewPtIdx();
154  void cleanUpAfterPrevFile();
155 
156  void popUpFileSelDialog(Widget&, std::string, std::string, XtCallbackProc);
157  static void cancelFileSelDialogCB(Widget, XtPointer, XtPointer);
158  static void openViewPtFileCB(Widget, XtPointer, XtPointer);
159  static void viewPtFileSelectedCB(Widget, XtPointer, XtPointer);
160  static void newViewPtFileCB(Widget, XtPointer, XtPointer);
161  static void createNewVPFileCB(Widget, XtPointer, XtPointer);
162  static void overwriteFileCB(Widget, XtPointer, XtPointer);
163  static void loadRefCoordsDialogCB(Widget, XtPointer, XtPointer); //pop file dialog
164  static void loadRefCoordsCB(Widget, XtPointer, XtPointer); //execute loading
165  static void saveRefCoordsDialogCB(Widget, XtPointer, XtPointer); //pop file dialog
166  static void saveRefCoordsCB(Widget, XtPointer, XtPointer); //execute saving
167  static void saveRefCoordsOverWriteCB(Widget, XtPointer, XtPointer);
168  static void loadSceneGraphDialogCB(Widget, XtPointer, XtPointer);
169  static void loadSceneGraphCB(Widget, XtPointer, XtPointer);
170  static void saveSceneGraphDialogCB(Widget, XtPointer, XtPointer);
171  static void saveSceneGraphCB(Widget, XtPointer, XtPointer);
172  static void saveSceneGraphOverWriteCB(Widget, XtPointer, XtPointer);
173  static void mouseoverCB(void *aThis, SoEventCallback *eventCB);
174  static void pickingCB(void *aThis, SoEventCallback *eventCB);
175 
176 
177  // Viewpoint operations
178  void addViewPoints();
179  static void closeListsDialogCB(Widget, XtPointer, XtPointer);
180  static void loadBookmarkCB(Widget, XtPointer, XtPointer);
181  static void renameBookmarkCB(Widget, XtPointer, XtPointer);
182  void renameViewPt(char *vpName);
183  static void sortBookmarksCB(Widget, XtPointer, XtPointer);
184  void sortViewPts(std::vector<std::string>);
185  static void deleteBookmarkCB(Widget, XtPointer, XtPointer);
186  static void deleteViewPtCB(Widget, XtPointer, XtPointer);
187  void deleteViewPt(char *vpName = NULL);
188 
189  // Animation
190  static void animateRefParticleCB(Widget, XtPointer, XtPointer);
191  static void animateSensorCB(void *, SoSensor *);
192  static void animateSensorRotationCB(void *, SoSensor *);
193  void animateRefParticle();
194  void saveCurCamera();
195  void restoreCamera();
197  void incSpeed();
198  void decSpeed();
199 
200  SoTimerSensor *animateSensor;
201  SoTimerSensor *animateSensorRotation;
202  SoNodeSensor *sceneChangeSensor;
205 
206  static void prevViewPtCB(Widget, XtPointer, XtPointer);
207  static void nextViewPtCB(Widget, XtPointer, XtPointer);
208  static void saveViewPtCB(Widget, XtPointer, XtPointer);
209  static void abbrOutputCB(Widget, XtPointer, XtPointer);
210  static void pickRefPathCB(Widget, XtPointer, XtPointer);
211  static void switchWireFrameCB(Widget, XtPointer, XtPointer);
212  static void constructListsDialog(Widget, XtPointer, XtPointer);
213  void saveViewPt(char *name);
214 
215 
216  static void lookAtSceneElementCB(Widget, XtPointer, XtPointer);
217  static void cancelSceneElementSelectionCB(Widget, XtPointer, XtPointer);
218 
219  void setReferencePath(SoLineSet*, SoCoordinate3*, bool append = false);
220  void setReferencePathZPos();
221  void findAndSetRefPath();
222  SoCoordinate3* getCoordsNode(SoFullPath *path);
223  void getSceneElements(); // reads elements from the scene graph
224  float sqrlen(const SbVec3f&);
225  void distanceToTrajectory(const SbVec3f&, float&, SbVec3f&, int&);
226  void sortElements();
227  void createElementsList(Widget);
228  static void closeMainWindowCB(Widget, XtPointer, XtPointer);
229  void evenOutRefParticlePts();
230 
231  static void gotoRefPathStartCB(Widget, XtPointer, XtPointer);
232  void gotoRefPathStart();
233  static void invertRefPathCB(Widget, XtPointer, XtPointer);
234  void invertRefPath();
235 
236  enum CameraType {
239  };
240 
241 
242  enum State {
250  };
251 
252  // For storing the view point
253  struct viewPtData {
254  char* viewPtName;
256  SbVec3f position;
257  SbRotation orientation;
258  float aspectRatio;
260  float farDistance;
263  float height;
264  };
265 
266  // FWJ removed unneeded assignment operator
267  struct sceneElement {
268  std::string name;
269  SoFullPath* path;
270  SbVec3f center;
272  };
273 
276  SbVec3f closestPoint;
279  std::string name;
280 
281  G4bool operator<(elementForSorting const &other) const
282  {
284  return true;
286  return false;
287 
288  // otherwise closestPointZCoord == other.closestPointZCoord.
289  // Compare the distances from the center of the element to
290  // the start of the beamline.
292  return true;
294  return false;
295 
296  // In case both closestPointZCoord and smallestDistance are
297  // equal, we have two exactly overlapping elements, if so
298  // the order doesn't matter
299  return true;
300  }
301  };
302 
304 
305  std::vector<sceneElement> sceneElements;
306  std::vector<viewPtData> viewPtList;
307  std::string fileName;
308  std::ifstream fileIn;
309  std::ofstream fileOut;
313 
314  // For storing coordinate points of the reference particle
315  std::vector<SbVec3f> refParticleTrajectory;
316  // For displaying distance during anim and beamline modes
317  std::vector<float> refZPositions;
318 
321  float distance;
324 
325  int step;
326  SbVec3f prevPt;
329 
333  SoCamera* myCam;
336  SbVec3f rotAxis; // For 90 degree rotations
337  int rotCnt; // # of steps rotation is split into
338 
339  static void getViewPtNameCB(Widget, XtPointer, XtPointer);
340  static void getViewPtNameCancelCB(Widget, XtPointer, XtPointer);
341  std::string viewPtAutoName();
342 
344  SoSearchAction * searcher;
345 
346  SoNode * superimposition;
347  SoCoordinate3 * sgeometry;
348  SoScale * sscale;
349 
350  SoTranslation * stranslation;
351  SoTranslation * curInfoTrans;
352  SoTranslation * mouseOverTransSolid;
353  SoTranslation * mouseOverTransMaterial;
354  SoTranslation * mouseOverTransLogName;
355  SoTranslation * mouseOverTransZPos;
356 
357  // Used for 2 similar purposes: 1. Displays z position during animation
358  // 2. Displays name of the current viewpoint
359  SoText2 * curInfoText;
360  /* Need to use many different fields for mouseover
361  * because newlines are ignored when the scene is rendered */
365  SoText2 * mouseOverTextZPos;
366 
367  SoFont * curInfoFont;
372  SoSwitch * axisSwitch;
374  SoSwitch * animSpeedSwitch;
375  SoSwitch * curInfoSwitch;
376 
377  SoNode * getSuperimpositionNode(SoNode *, const char * name);
378 
379  void superimpositionEvent(SoAction * action);
380  static void superimpositionCB(void * closure, SoAction * action);
381 
382  virtual void actualRedraw(void);
383  void updateSpeedIndicator(void);
384 
385  float maxSpeed;
387 
388  // FWJ added for Ortho camera
391  // FWJ add look-ahead for animation tracking on curves
393 
394  // Used by G4 app during element rotations, stores previous view
396  bool rotUpVec;
397 
398  SoSeparator* newSceneGraph;
399 
400 
401 };
402 #endif /* G4OPENINVENTORXTEXAMINERVIEWER_HH */