Geant4-11
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{
37private:
39public:
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
60class SoCoordinate3;
61class SoFont;
62class SoText2;
63class SoPointSet;
64
65class G4OpenInventorXtExaminerViewer : public SoXtExaminerViewer {
66
68 // FWJ
70
71private:
77
79 void (*escapeCallback)(void *);
82
83public:
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
116protected:
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
140private:
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;
150 static void sceneChangeCB(void *, SoSensor *);
151
152 void setViewPt();
153 void writeViewPtIdx();
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);
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);
230
231 static void gotoRefPathStartCB(Widget, XtPointer, XtPointer);
232 void gotoRefPathStart();
233 static void invertRefPathCB(Widget, XtPointer, XtPointer);
234 void invertRefPath();
235
239 };
240
241
242 enum State {
250 };
251
252 // For storing the view point
253 struct viewPtData {
256 SbVec3f position;
257 SbRotation orientation;
263 float height;
264 };
265
266 // FWJ removed unneeded assignment operator
268 std::string name;
269 SoFullPath* path;
270 SbVec3f center;
272 };
273
279 std::string name;
280
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
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 */
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
397
398 SoSeparator* newSceneGraph;
399
400
401};
402#endif /* G4OPENINVENTORXTEXAMINERVIEWER_HH */
G4ApplicationState
G4ProfileType Type
static constexpr double s
Definition: G4SIunits.hh:154
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define TRUE
Definition: Globals.hh:27
static void viewPtFileSelectedCB(Widget, XtPointer, XtPointer)
static void saveSceneGraphDialogCB(Widget, XtPointer, XtPointer)
static void loadRefCoordsDialogCB(Widget, XtPointer, XtPointer)
static void closeListsDialogCB(Widget, XtPointer, XtPointer)
void warningMsgDialog(std::string, String, XtCallbackProc)
static void animateRefParticleCB(Widget, XtPointer, XtPointer)
static void saveSceneGraphCB(Widget, XtPointer, XtPointer)
static void closeMainWindowCB(Widget, XtPointer, XtPointer)
static void loadSceneGraphCB(Widget, XtPointer, XtPointer)
static void loadRefCoordsCB(Widget, XtPointer, XtPointer)
static void constructListsDialog(Widget, XtPointer, XtPointer)
static void mouseoverCB(void *aThis, SoEventCallback *eventCB)
static void saveViewPtCB(Widget, XtPointer, XtPointer)
void sortViewPts(std::vector< std::string >)
virtual SbBool processSoEvent(const SoEvent *const event)
void distanceToTrajectory(const SbVec3f &, float &, SbVec3f &, int &)
static void animateSensorCB(void *, SoSensor *)
static void deleteViewPtCB(Widget, XtPointer, XtPointer)
SoCoordinate3 * getCoordsNode(SoFullPath *path)
static void lookAtSceneElementCB(Widget, XtPointer, XtPointer)
static void renameBookmarkCB(Widget, XtPointer, XtPointer)
static void invertRefPathCB(Widget, XtPointer, XtPointer)
static void openViewPtFileCB(Widget, XtPointer, XtPointer)
static void gotoRefPathStartCB(Widget, XtPointer, XtPointer)
static void prevViewPtCB(Widget, XtPointer, XtPointer)
static void sortBookmarksCB(Widget, XtPointer, XtPointer)
void setReferencePath(SoLineSet *, SoCoordinate3 *, bool append=false)
void addButton(Widget menu, std::string name, XtCallbackProc)
static void pickingCB(void *aThis, SoEventCallback *eventCB)
static void superimpositionCB(void *closure, SoAction *action)
static void getViewPtNameCB(Widget, XtPointer, XtPointer)
static void saveSceneGraphOverWriteCB(Widget, XtPointer, XtPointer)
G4OpenInventorXtExaminerViewer(Widget parent=NULL, const char *name=NULL, SbBool embed=TRUE, SoXtFullViewer::BuildFlag flag=BUILD_ALL, SoXtViewer::Type type=BROWSER)
virtual void createViewerButtons(Widget parent, SbPList *buttonlist)
Widget createScale(Widget, char *, int, float)
static void abbrOutputCB(Widget, XtPointer, XtPointer)
void updateViewParams(SoKeyboardEvent::Key)
static void saveRefCoordsOverWriteCB(Widget, XtPointer, XtPointer)
static void switchWireFrameCB(Widget, XtPointer, XtPointer)
static void getViewPtNameCancelCB(Widget, XtPointer, XtPointer)
static void overwriteFileCB(Widget, XtPointer, XtPointer)
void addEscapeCallback(void(*cb)(void *), void *)
static void createNewVPFileCB(Widget, XtPointer, XtPointer)
static void loadBookmarkCB(Widget, XtPointer, XtPointer)
void moveCamera(float dist=0, bool lookdown=false)
static void deleteBookmarkCB(Widget, XtPointer, XtPointer)
static void animateSensorRotationCB(void *, SoSensor *)
static void sceneChangeCB(void *, SoSensor *)
static void nextViewPtCB(Widget, XtPointer, XtPointer)
static void saveRefCoordsDialogCB(Widget, XtPointer, XtPointer)
static G4OpenInventorXtExaminerViewer * viewer
SoNode * getSuperimpositionNode(SoNode *, const char *name)
static void newViewPtFileCB(Widget, XtPointer, XtPointer)
void parseString(T &t, const std::string &s, bool &error)
static void saveRefCoordsCB(Widget, XtPointer, XtPointer)
static void loadSceneGraphDialogCB(Widget, XtPointer, XtPointer)
void popUpFileSelDialog(Widget &, std::string, std::string, XtCallbackProc)
static void pickRefPathCB(Widget, XtPointer, XtPointer)
static void cancelFileSelDialogCB(Widget, XtPointer, XtPointer)
static void cancelSceneElementSelectionCB(Widget, XtPointer, XtPointer)
G4OpenInventorXtExaminerViewer * viewer
virtual G4bool Notify(G4ApplicationState requiredState)
HookEventProcState(G4OpenInventorQtExaminerViewer *)
const char * name(G4int ptype)
G4bool operator<(elementForSorting const &other) const
static PROLOG_HANDLER error
Definition: xmlrole.cc:127