Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
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  bool 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  std::string viewPtAutoName();
341 
343  SoSearchAction * searcher;
344 
345  SoNode * superimposition;
346  SoCoordinate3 * sgeometry;
347  SoScale * sscale;
348 
349  SoTranslation * stranslation;
350  SoTranslation * curInfoTrans;
351  SoTranslation * mouseOverTransSolid;
352  SoTranslation * mouseOverTransMaterial;
353  SoTranslation * mouseOverTransLogName;
354  SoTranslation * mouseOverTransZPos;
355 
356  // Used for 2 similar purposes: 1. Displays z position during animation
357  // 2. Displays name of the current viewpoint
358  SoText2 * curInfoText;
359  /* Need to use many different fields for mouseover
360  * because newlines are ignored when the scene is rendered */
364  SoText2 * mouseOverTextZPos;
365 
366  SoFont * curInfoFont;
371  SoSwitch * axisSwitch;
373  SoSwitch * animSpeedSwitch;
374  SoSwitch * curInfoSwitch;
375 
376  SoNode * getSuperimpositionNode(SoNode *, const char * name);
377 
378  void superimpositionEvent(SoAction * action);
379  static void superimpositionCB(void * closure, SoAction * action);
380 
381  virtual void actualRedraw(void);
382  void updateSpeedIndicator(void);
383 
384  float maxSpeed;
386 
387  // FWJ added for Ortho camera
390  // FWJ add look-ahead for animation tracking on curves
392 
393  // Used by G4 app during element rotations, stores previous view
395  bool rotUpVec;
396 
397  SoSeparator* newSceneGraph;
398 
399 
400 };
401 #endif /* G4OPENINVENTORXTEXAMINERVIEWER_HH */
bool operator<(elementForSorting const &other) const
static void saveRefCoordsCB(Widget, XtPointer, XtPointer)
const XML_Char * name
Definition: expat.h:151
static G4OpenInventorXtExaminerViewer * viewer
static void loadRefCoordsCB(Widget, XtPointer, XtPointer)
static void cancelSceneElementSelectionCB(Widget, XtPointer, XtPointer)
void warningMsgDialog(std::string, String, XtCallbackProc)
static void abbrOutputCB(Widget, XtPointer, XtPointer)
void addEscapeCallback(void(*cb)(void *), void *)
static void animateSensorRotationCB(void *, SoSensor *)
static void loadSceneGraphCB(Widget, XtPointer, XtPointer)
void distanceToTrajectory(const SbVec3f &, float &, SbVec3f &, int &)
static void newViewPtFileCB(Widget, XtPointer, XtPointer)
static void saveSceneGraphCB(Widget, XtPointer, XtPointer)
virtual SbBool processSoEvent(const SoEvent *const event)
static void saveViewPtCB(Widget, XtPointer, XtPointer)
HookEventProcState(G4OpenInventorXtExaminerViewer *)
static void prevViewPtCB(Widget, XtPointer, XtPointer)
Widget createScale(Widget, char *, int, float)
static void saveSceneGraphOverWriteCB(Widget, XtPointer, XtPointer)
static void saveRefCoordsOverWriteCB(Widget, XtPointer, XtPointer)
static void nextViewPtCB(Widget, XtPointer, XtPointer)
void updateViewParams(SoKeyboardEvent::Key)
static void sortBookmarksCB(Widget, XtPointer, XtPointer)
void addButton(Widget menu, std::string name, XtCallbackProc)
static void loadRefCoordsDialogCB(Widget, XtPointer, XtPointer)
static void invertRefPathCB(Widget, XtPointer, XtPointer)
static void saveSceneGraphDialogCB(Widget, XtPointer, XtPointer)
static void getViewPtNameCB(Widget, XtPointer, XtPointer)
void setReferencePath(SoLineSet *, SoCoordinate3 *, bool append=false)
static void superimpositionCB(void *closure, SoAction *action)
const XML_Char * s
Definition: expat.h:262
bool G4bool
Definition: G4Types.hh:79
static void lookAtSceneElementCB(Widget, XtPointer, XtPointer)
static void constructListsDialog(Widget, XtPointer, XtPointer)
static void openViewPtFileCB(Widget, XtPointer, XtPointer)
static void pickRefPathCB(Widget, XtPointer, XtPointer)
static void deleteBookmarkCB(Widget, XtPointer, XtPointer)
static void gotoRefPathStartCB(Widget, XtPointer, XtPointer)
#define TRUE
Definition: globals.hh:55
static void overwriteFileCB(Widget, XtPointer, XtPointer)
static void deleteViewPtCB(Widget, XtPointer, XtPointer)
G4OpenInventorXtExaminerViewer(Widget parent=NULL, const char *name=NULL, SbBool embed=TRUE, SoXtFullViewer::BuildFlag flag=BUILD_ALL, SoXtViewer::Type type=BROWSER)
void popUpFileSelDialog(Widget &, std::string, std::string, XtCallbackProc)
static void closeListsDialogCB(Widget, XtPointer, XtPointer)
SoNode * getSuperimpositionNode(SoNode *, const char *name)
static void viewPtFileSelectedCB(Widget, XtPointer, XtPointer)
virtual void createViewerButtons(Widget parent, SbPList *buttonlist)
int G4int
Definition: G4Types.hh:78
static void cancelFileSelDialogCB(Widget, XtPointer, XtPointer)
static void switchWireFrameCB(Widget, XtPointer, XtPointer)
static void pickingCB(void *aThis, SoEventCallback *eventCB)
static void saveRefCoordsDialogCB(Widget, XtPointer, XtPointer)
static void renameBookmarkCB(Widget, XtPointer, XtPointer)
static void animateRefParticleCB(Widget, XtPointer, XtPointer)
static void loadBookmarkCB(Widget, XtPointer, XtPointer)
void parseString(T &t, const std::string &s, bool &error)
G4OpenInventorXtExaminerViewer * viewer
G4ApplicationState
static void loadSceneGraphDialogCB(Widget, XtPointer, XtPointer)
static PROLOG_HANDLER error
Definition: xmlrole.cc:112
static void animateSensorCB(void *, SoSensor *)
static void closeMainWindowCB(Widget, XtPointer, XtPointer)
void sortViewPts(std::vector< std::string >)
SoCoordinate3 * getCoordsNode(SoFullPath *path)
static void mouseoverCB(void *aThis, SoEventCallback *eventCB)
typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData
void moveCamera(float dist=0, bool lookdown=false)
virtual G4bool Notify(G4ApplicationState requiredState)
static void sceneChangeCB(void *, SoSensor *)
static void createNewVPFileCB(Widget, XtPointer, XtPointer)