Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4OpenInventorQtExaminerViewer.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
27// Frederick Jones TRIUMF 07 January 2018
28
29
30#ifndef G4OPENINVENTORQTEXAMINERVIEWER_HH
31#define G4OPENINVENTORQTEXAMINERVIEWER_HH
32
33#if defined (G4VIS_BUILD_OIQT_DRIVER) || defined (G4VIS_USE_OIQT)
34
35
36// Set up notification of event processing
37
38#include "G4VStateDependent.hh"
39
40class G4OpenInventorQtExaminerViewer;
41
43{
44public:
45 HookEventProcState(G4OpenInventorQtExaminerViewer*);
47 virtual G4bool Notify(G4ApplicationState requestedState);
48private:
49 G4OpenInventorQtExaminerViewer* viewer;
50};
51
52
53#include "G4Types.hh"
54
55//#include "G4OpenInventorViewer.hh"
56
57#include <map>
58#include <vector>
59#include <fstream>
60#include <Inventor/SbLinear.h>
61#include <Inventor/nodes/SoLineSet.h>
62#include <Inventor/nodes/SoEventCallback.h>
63#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
64#include <Inventor/events/SoKeyboardEvent.h>
65
66#include <qobject.h>
67
68class SoCoordinate3;
69class SoFont;
70class SoText2;
71class SoPointSet;
72
73class QWidget;
74class QDialog;
75class QMenuBar;
76class QMenu;
77class QAction;
78class QListWidgetItem;
79class QPushButton;
80class QRadioButton;
81class QMessageBox;
82class QFont;
83
84// The Aux Window dialog created with Qt Designer:
85class Ui_Dialog;
86
87
88class G4OpenInventorQtExaminerViewer: public QObject,
89 public SoQtExaminerViewer {
90
91 Q_OBJECT
92
93 // friend class G4OpenInventorQtExaminerViewerMessenger;
94 // FWJ
95 friend class G4OpenInventorQtViewer;
96
97private Q_SLOTS :
98
99 void FileOpenBookmarkCB();
100 void FileNewBookmarkCB();
101 void FileLoadRefPathCB();
102 void FileSaveRefPathCB();
103 void FileLoadSceneGraphCB();
104 void FileSaveSceneGraphCB();
105
106 void ToolsAnimateRefParticleCB();
107 void ToolsRefPathStartCB();
108 void ToolsRefPathInvertCB();
109
110 void HelpControlsCB();
111
112 // For added viewer buttons
113 void SaveViewPtCB();
114 void NextViewPtCB();
115 void PrevViewPtCB();
116 void AbbrOutputCB(bool); // Includes mouse-over fcns
117 void PickRefPathCB();
118 void SwitchWireFrameCB(bool);
119
120 // Lists Window
121 void LoadBookmarkCB(QListWidgetItem*);
122 void DeleteBookmarkCB();
123 void RenameBookmarkCB();
124 void SortBookmarksCB();
125 void LookAtSceneElementCB(QListWidgetItem*);
126
127private:
128
129 static G4OpenInventorQtExaminerViewer* viewer;
130
131 void (*escapeCallback)();
132 // void (*escapeCallback)(void*);
133 void* examinerObject;
134 SbBool lshiftdown, rshiftdown, lctrldown, rctrldown;
135
136 QFont* font;
137 QMenuBar* menubar;
138 QMenu* filemenu;
139 QMenu* toolsmenu;
140 QMenu* etcmenu;
141 QMenu* helpmenu;
142 QMessageBox* helpmsgbox;
143
144 bool externalQtApp;
145
146 QAction* FileOpenBookmark;
147 QAction* FileNewBookmark;
148 QAction* FileLoadRefPath;
149 QAction* FileSaveRefPath;
150 QAction* FileLoadSceneGraph;
151 QAction* FileSaveSceneGraph;
152
153 QAction* ToolsAnimateRefParticle;
154 QAction* ToolsRefPathStart;
155 QAction* ToolsRefPathInvert;
156
157 // KEEP in the viewer
158 QAction* HelpControls;
159
160 // Added viewer buttons
161 QPushButton* saveViewPtButton;
162 QPushButton* nextViewPtButton;
163 QPushButton* prevViewPtButton;
164 QPushButton* abbrOutputButton;
165 // QRadioButton* abbrOutputButton;
166 QPushButton* pickRefPathButton;
167 QPushButton* switchWireFrameButton;
168 // QRadioButton* switchWireFrameButton;
169
170 QListWidgetItem* saveViewPtItem;
171
172 Ui_Dialog* AuxWindowDialog;
173 QDialog* AuxWindow;
174
175public:
176
177 G4OpenInventorQtExaminerViewer(QWidget* parent = NULL,
178 const char* name = NULL,
179 SbBool embed = TRUE,
180 SoQtFullViewer::BuildFlag flag = BUILD_ALL,
181 SoQtViewer::Type type = BROWSER);
182
183 ~G4OpenInventorQtExaminerViewer();
184
185 template <class T> void parseString(T &t, const std::string &s, bool &error);
186
187 // Menubar information needed by G4OpenInventorQtViewer
188 // for common menu items:
189 QMenuBar* getMenubar() { return menubar; }
190 QMenu* getFileMenu() { return filemenu; }
191 QMenu* getEtcMenu() { return etcmenu; }
192 QFont* getFont() { return font; };
193
194 void setExternalQtApp() { externalQtApp = TRUE; }
195
196 // Needed?
197 std::string saveScenegraphFileName;
198 std::string saveRefCoordsFileName;
199
200 void addEscapeCallback(void (*cb)());
201 // void addEscapeCallback(void (*cb)(void *), void *);
202
203 bool abbrOutputFlag;
204 bool pickRefPathFlag;
205 bool viewingBeforePickRef;
206
207
208protected:
209 // FWJ Constructor with build flag added (as in parent)
210 // Need for this TBD.
211 // G4OpenInventorQtExaminerViewer(QWidget parent,
212 // const char *name,
213 // SbBool embed,
214 // SoQtFullViewer::BuildFlag flag,
215 // SoQtViewer::Type type,
216 // SbBool build);
217
218 void construct(const SbBool build);
219 void buildWidget(QWidget* parent);
220
221 virtual void afterRealizeHook();
222
223 HookEventProcState* hookBeamOn;
224 friend class HookEventProcState;
225 bool newEvents;
226
227 static void sceneChangeCB(void*, SoSensor*);
228
229 // FWJ try to handle events as in XtExaminerViewer
230 SbBool processSoEvent(const SoEvent* const event);
231
232 void saveViewPt(char* name);
233 bool loadViewPts();
234 void addViewPoints();
235 void setViewPt();
236 void writeViewPtIdx();
237 void cleanUpAfterPrevFile();
238 void deleteViewPt(char *vpName = NULL);
239 void renameViewPt(char *vpName);
240 void sortViewPts(std::vector<std::string>);
241
242 void moveCamera(float dist = 0, bool lookdown = false);
243 std::string curEltName;
244 SbVec3f camUpVec;
245 SbVec3f camDir;
246 void rotateCamera();
247 void updateViewParams(SoKeyboardEvent::Key);
248
249 static void mouseoverCB(void *aThis, SoEventCallback *eventCB);
250 static void pickingCB(void *aThis, SoEventCallback *eventCB);
251
252
253 // Animation
254 static void animateRefParticleCB();
255 static void animateSensorCB(void *, SoSensor *);
256 static void animateSensorRotationCB(void *, SoSensor *);
257 void animateRefParticle();
258 void saveCurCamera();
259 void restoreCamera();
260 double animateBtwPtsPeriod, speedStep;
261 void incSpeed();
262 void decSpeed();
263
264 SoTimerSensor *animateSensor;
265 SoTimerSensor *animateSensorRotation;
266 SoNodeSensor *sceneChangeSensor;
267 SbVec3f camStartPos, camEndPos;
268 SbRotation camStartOrient, camEndOrient;
269
270 void setReferencePath(SoLineSet*, SoCoordinate3*, bool append = false);
271 void setReferencePathZPos();
272 void findAndSetRefPath();
273 SoCoordinate3* getCoordsNode(SoFullPath *path);
274 void getSceneElements(); // reads elements from the scene graph
275 float sqrlen(const SbVec3f&);
276 void distanceToTrajectory(const SbVec3f&, float&, SbVec3f&, int&);
277 void sortElements();
278 void createElementsList();
279 // static void closeMainWindowCB(Widget, XtPointer, XtPointer);
280 void evenOutRefParticlePts();
281
282 // static void gotoRefPathStartCB(Widget, XtPointer, XtPointer);
283 void gotoRefPathStart();
284 // static void invertRefPathCB(Widget, XtPointer, XtPointer);
285 void invertRefPath();
286
287
288 enum CameraType {
289 PERSPECTIVE,
290 ORTHOGRAPHIC
291 };
292 enum State {
293 GENERAL,
294 BEAMLINE,
295 VIEWPOINT,
296 ANIMATION,
297 REVERSED_ANIMATION,
298 PAUSED_ANIMATION,
299 ROTATING
300 };
301
302 // For storing the view point
303 struct viewPtData {
304 char* viewPtName;
305 int viewportMapping;
306 SbVec3f position;
307 SbRotation orientation;
308 float aspectRatio;
309 float nearDistance;
310 float farDistance;
311 float focalDistance;
312 CameraType camType;
313 float height;
314 };
315
316 struct sceneElement {
317 std::string name;
318 SoFullPath* path;
319 SbVec3f center;
320 float closestPointZCoord;
321 };
322
323 struct elementForSorting {
324 float closestPointZCoord;
325 SbVec3f closestPoint;
326 float smallestDistance;
327 float distanceToBeamlineStart;
328 std::string name;
329
330 G4bool operator<(elementForSorting const &other) const
331 {
332 if (closestPointZCoord < other.closestPointZCoord)
333 return true;
334 if (closestPointZCoord > other.closestPointZCoord)
335 return false;
336
337 // otherwise closestPointZCoord == other.closestPointZCoord.
338 // Compare the distances from the center of the element to
339 // the start of the beamline.
340 if (distanceToBeamlineStart < other.distanceToBeamlineStart)
341 return true;
342 if (distanceToBeamlineStart > other.distanceToBeamlineStart)
343 return false;
344
345 // In case both closestPointZCoord and smallestDistance are
346 // equal, we have two exactly overlapping elements, if so
347 // the order doesn't matter
348 return true;
349 }
350 };
351
352 bool zcoordSetFlag;
353
354 std::vector<sceneElement> sceneElements;
355 std::vector<viewPtData> viewPtList;
356 std::string fileName;
357 std::ifstream fileIn;
358 std::ofstream fileOut;
359 int viewPtIdx;
360 int MAX_VP_IDX;
361 int MAX_VP_NAME;
362
363 // For storing coordinate points of the reference particle
364 std::vector<SbVec3f> refParticleTrajectory;
365 // For displaying distance during anim and beamline modes
366 std::vector<float> refZPositions;
367
368 int refParticleIdx;
369 int prevRefIdx;
370 float distance;
371 State currentState, prevState, beforePausing;
372 char* curViewPtName;
373
374 int step;
375 SbVec3f prevPt;
376 SbVec3f prevParticleDir;
377 void* prevColorField;
378
379 viewPtData camB4Animation;
380 bool returnToSaveVP;
381 bool returnToAnim;
382 SoCamera* myCam;
383 void setStartingPtForAnimation();
384 float left_right, up_down;
385 SbVec3f rotAxis; // For 90 degree rotations
386 int rotCnt; // # of steps rotation is split into
387
388 std::string viewPtAutoName();
389
390 ////////////////////////ANIM_SPEED_INDICATOR///////////////////////
391
392 SoSearchAction * searcher;
393
394 SoNode * superimposition;
395 SoCoordinate3 * sgeometry;
396 SoScale * sscale;
397
398 SoTranslation * stranslation;
399 SoTranslation * curInfoTrans;
400 SoTranslation * mouseOverTransSolid;
401 SoTranslation * mouseOverTransMaterial;
402 SoTranslation * mouseOverTransLogName;
403 SoTranslation * mouseOverTransZPos;
404
405 // Used for 2 similar purposes: 1. Displays z position during animation
406 // 2. Displays name of the current viewpoint
407 SoText2 * curInfoText;
408
409 // Need to use many different fields for mouseover
410 // because newlines are ignored when the scene is rendered
411 SoText2* mouseOverTextSolid;
412 SoText2* mouseOverTextMaterial;
413 SoText2* mouseOverTextLogName;
414 SoText2* mouseOverTextZPos;
415
416 SoFont* curInfoFont;
417 SoFont* mouseOverFontSolid;
418 SoFont* mouseOverFontMaterial;
419 SoFont* mouseOverFontLogName;
420 SoFont* mouseOverFontZPos;
421 SoSwitch* axisSwitch;
422 SoSwitch* animSpeedOutlineSwitch;
423 SoSwitch* animSpeedSwitch;
424 SoSwitch* curInfoSwitch;
425
426 SoNode* getSuperimpositionNode(SoNode*, const char* name);
427
428 void superimpositionEvent(SoAction* action);
429 static void superimpositionCB(void* closure, SoAction* action);
430
431
432 virtual void actualRedraw(void);
433 void updateSpeedIndicator(void);
434
435 float maxSpeed;
436
437 ////////////////////////ANIM_SPEED_INDICATOR///////////////////////
438
439 // FWJ added for Ortho camera
440 float defaultHeight;
441 float defaultHeightAngle;
442 // FWJ add look-ahead for animation tracking on curves
443 G4int pathLookahead;
444
445 // Used by G4 app during element rotations, stores previous view
446 SbVec3f upVector, offsetFromCenter, center;
447 bool rotUpVec;
448
449 SoSeparator* newSceneGraph;
450
451};
452
453#endif
454
455#endif /* G4OPENINVENTORQTEXAMINERVIEWER_HH */
G4ApplicationState
#define State(X)
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define TRUE
Definition: Globals.hh:27
virtual G4bool Notify(G4ApplicationState requiredState)
bool operator<(const HepRotation &r, const HepLorentzRotation &lt)
const char * name(G4int ptype)
#define position
Definition: xmlparse.cc:622