Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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{
36private:
38public:
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
58class SoCoordinate3;
59class SoFont;
60class SoText2;
61class SoPointSet;
62
63class G4OpenInventorXtExaminerViewer : public SoXtExaminerViewer {
64private:
65 Widget prevViewPtButton, nextViewPtButton;
66 Widget menuBar, fileMenu, openFileDialog, newFileDialog,
67 loadRefCoordsDialog, saveRefCoordsDialog,
68 loadSceneGraphDialog, saveSceneGraphDialog,
69 viewPtSelection, listsDialog, myShellDialog, myViewPtList, myElementList;
70
71 static G4OpenInventorXtExaminerViewer *viewer;
72 void (*escapeCallback)(void *);
73 void * examinerObject;
74 SbBool lshiftdown, rshiftdown, lctrldown, rctrldown;
75
76public:
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
98
99 Widget createScale(Widget, char *, int, float);
100 void addEscapeCallback(void (*cb)(void *), void *);
104
105protected:
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
129private:
130 // Each constructor calls this generic constructor
131 void constructor(const SbBool build);
132
133 static G4OpenInventorXtExaminerViewer *getObject();
134
135 HookEventProcState *hookBeamOn;
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();
184 double animateBtwPtsPeriod, speedStep;
185 void incSpeed();
186 void decSpeed();
187
188 SoTimerSensor *animateSensor;
189 SoTimerSensor *animateSensorRotation;
190 SoNodeSensor *sceneChangeSensor;
191 SbVec3f camStartPos, camEndPos;
192 SbRotation camStartOrient, camEndOrient;
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 {
224 PERSPECTIVE,
225 ORTHOGRAPHIC
226 };
227
228
229 enum State {
230 GENERAL,
231 BEAMLINE,
232 VIEWPOINT,
233 ANIMATION,
234 REVERSED_ANIMATION,
235 PAUSED_ANIMATION,
236 ROTATING
237 };
238
239 // For storing the view point
240 struct viewPtData {
241 char* viewPtName;
242 int viewportMapping;
243 SbVec3f position;
244 SbRotation orientation;
245 float aspectRatio;
246 float nearDistance;
247 float farDistance;
248 float focalDistance;
249 CameraType camType;
250 float height;
251 };
252
253 struct sceneElement {
254 std::string name;
255 SoFullPath * path;
256 SbVec3f center;
257 float closestPointZCoord;
258
259 sceneElement operator=(sceneElement const &rhs) const {
260 sceneElement el;
261 el.name = rhs.name;
262 el.path = rhs.path;
263 el.center = rhs.center;
264 el.closestPointZCoord = rhs.closestPointZCoord;
265
266 return el;
267 }
268 };
269
270 struct elementForSorting {
271 float closestPointZCoord;
272 SbVec3f closestPoint;
273 float smallestDistance;
274 float distanceToBeamlineStart;
275 std::string name;
276
277 bool operator<(elementForSorting const &other) const
278 {
279 if (closestPointZCoord < other.closestPointZCoord)
280 return true;
281 if (closestPointZCoord > other.closestPointZCoord)
282 return false;
283
284 // otherwise closestPointZCoord == other.closestPointZCoord.
285 // Compare the distances from the center of the element to
286 // the start of the beamline.
287 if (distanceToBeamlineStart < other.distanceToBeamlineStart)
288 return true;
289 if (distanceToBeamlineStart > other.distanceToBeamlineStart)
290 return false;
291
292 // In case both closestPointZCoord and smallestDistance are
293 // equal, we have two exactly overlapping elements, if so
294 // the order doesn't matter
295 return true;
296 }
297 };
298
299 bool zcoordSetFlag;
300
301 std::vector<sceneElement> sceneElements;
302 std::vector<viewPtData> viewPtList;
303 std::string fileName;
304 std::ifstream fileIn;
305 std::ofstream fileOut;
306 int viewPtIdx;
307 int MAX_VP_IDX;
308 int MAX_VP_NAME;
309
310 // For storing coordinate points of the reference particle
311 std::vector<SbVec3f> refParticleTrajectory;
312 // For displaying distance during anim and beamline modes
313 std::vector<float> refZPositions;
314 int refParticleIdx;
315 int prevRefIdx;
316 float distance;
317 State currentState, prevState, beforePausing;
318 char *curViewPtName;
319
320 int step;
321 SbVec3f prevPt;
322 SbVec3f prevParticleDir;
323 void * prevColorField;
324
325 viewPtData camB4Animation;
326 bool returnToSaveVP;
327 bool returnToAnim;
328 SoCamera *myCam;
329 void setStartingPtForAnimation();
330 float left_right, up_down;
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
337 ////////////////////////ANIM_SPEED_INDICATOR///////////////////////
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 */
356 SoText2 * mouseOverTextSolid;
357 SoText2 * mouseOverTextMaterial;
358 SoText2 * mouseOverTextLogName;
359 SoText2 * mouseOverTextZPos;
360
361 SoFont * curInfoFont;
362 SoFont * mouseOverFontSolid;
363 SoFont * mouseOverFontMaterial;
364 SoFont * mouseOverFontLogName;
365 SoFont * mouseOverFontZPos;
366 SoSwitch * axisSwitch;
367 SoSwitch * animSpeedOutlineSwitch;
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;
380 ////////////////////////ANIM_SPEED_INDICATOR///////////////////////
381
382 // FWJ added for Ortho camera
383 float defaultHeight;
384 float defaultHeightAngle;
385
386 // Used by G4 app during element rotations, stores previous view
387 SbVec3f upVector, offsetFromCenter, center;
388 bool rotUpVec;
389
390 SoSeparator * newSceneGraph;
391
392
393};
394#endif /* G4OPENINVENTORXTEXAMINERVIEWER_HH */
G4ApplicationState
#define State(theXInfo)
bool G4bool
Definition: G4Types.hh:67
void warningMsgDialog(std::string, String, XtCallbackProc)
virtual SbBool processSoEvent(const SoEvent *const event)
void addButton(Widget menu, std::string name, XtCallbackProc)
virtual void createViewerButtons(Widget parent, SbPList *buttonlist)
Widget createScale(Widget, char *, int, float)
void updateViewParams(SoKeyboardEvent::Key)
void addEscapeCallback(void(*cb)(void *), void *)
void moveCamera(float dist=0, bool lookdown=false)
void parseString(T &t, const std::string &s, bool &error)
virtual G4bool Notify(G4ApplicationState requiredState)
#define TRUE
Definition: globals.hh:55
bool operator<(shared_ctrl_handle const &lhs, shared_ctrl_handle const &rhs)
Definition: memory.h:588