Geant4 11.2.2
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// Set up notification of event processing
34
35#include "G4VStateDependent.hh"
36
38
48
49
50#include "G4String.hh"
51
52//#include "G4OpenInventorViewer.hh"
53
54#include <map>
55#include <vector>
56#include <fstream>
57#include <Inventor/SbLinear.h>
58#include <Inventor/nodes/SoLineSet.h>
59#include <Inventor/nodes/SoEventCallback.h>
60#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
61#include <Inventor/events/SoKeyboardEvent.h>
62
63#include <qobject.h>
64
65class G4UIQt;
66
67class SoCoordinate3;
68class SoFont;
69class SoText2;
70class SoPointSet;
71
72class QWidget;
73class QDialog;
74class QMenuBar;
75class QMenu;
76class QAction;
77class QListWidgetItem;
78class QPushButton;
79class QRadioButton;
80class QMessageBox;
81class QFont;
82
83// The Aux Window dialog created with Qt Designer:
84class Ui_Dialog;
85
86
87class G4OpenInventorQtExaminerViewer: public QObject,
88 public SoQtExaminerViewer {
89
90 Q_OBJECT
91
92 // friend class G4OpenInventorQtExaminerViewerMessenger;
93 // FWJ
95
96private Q_SLOTS :
97
98 void FileOpenBookmarkCB();
99 void FileNewBookmarkCB();
100 void FileLoadRefPathCB();
101 void FileSaveRefPathCB();
102 void FileLoadSceneGraphCB();
103 void FileSaveSceneGraphCB();
104
105 void ToolsAnimateRefParticleCB();
106 void ToolsRefPathStartCB();
107 void ToolsRefPathInvertCB();
108
109 void HelpControlsCB();
110
111 // For added viewer buttons
112 void SaveViewPtCB();
113 void NextViewPtCB();
114 void PrevViewPtCB();
115 void AbbrOutputCB(bool); // Includes mouse-over fcns
116 void PickRefPathCB();
117 void SwitchWireFrameCB(bool);
118 void SwitchAxesCB(bool);
119 void DetachCB();
120
121 // Lists Window
122 void LoadBookmarkCB(QListWidgetItem*);
123 void DeleteBookmarkCB();
124 void RenameBookmarkCB();
125 void SortBookmarksCB();
126 void LookAtSceneElementCB(QListWidgetItem*);
127
128private:
129
130 static G4OpenInventorQtExaminerViewer* viewer;
131 QString* fName;
132
133 int OWwidth, OWheight;
134
135 void (*escapeCallback)();
136
137 void* examinerObject;
138 SbBool lshiftdown, rshiftdown, lctrldown, rctrldown;
139
140 QFont* font;
141 QMenuBar* menubar;
142 QMenu* filemenu;
143 QMenu* toolsmenu;
144 QMenu* etcmenu;
145 QMenu* helpmenu;
146 QMessageBox* helpmsgbox;
147
148 bool externalQtApp;
149
150 QAction* FileOpenBookmark;
151 QAction* FileNewBookmark;
152 QAction* FileLoadRefPath;
153 QAction* FileSaveRefPath;
154 QAction* FileLoadSceneGraph;
155 QAction* FileSaveSceneGraph;
156
157 QAction* ToolsAnimateRefParticle;
158 QAction* ToolsRefPathStart;
159 QAction* ToolsRefPathInvert;
160
161 // KEEP in the viewer
162 QAction* HelpControls;
163
164 // Added viewer buttons
165 QPushButton* saveViewPtButton;
166 QPushButton* nextViewPtButton;
167 QPushButton* prevViewPtButton;
168 QPushButton* abbrOutputButton;
169 QPushButton* pickRefPathButton;
170 QPushButton* switchWireFrameButton;
171 QPushButton* switchAxesButton;
172 QPushButton* detachButton;
173
174 QListWidgetItem* saveViewPtItem;
175
176 Ui_Dialog* AuxWindowDialog;
177 QDialog* AuxWindow;
178
179 G4UIQt* uiQt;
180 QWidget* viewerParent;
181 QWidget* viewerParent2;
182 int uiQtTabIndex;
183
184 int processSoEventCount;
185 G4String empty = "";
186
187public:
188
189 G4OpenInventorQtExaminerViewer(QWidget* parent = NULL,
190 const char* name = NULL,
191 SbBool embed = TRUE,
192 SoQtFullViewer::BuildFlag flag = BUILD_ALL,
193 SoQtViewer::Type type = BROWSER);
194
196
197 G4UIQt* GetUIQt() {return uiQt;}
198
199 template <class T> void parseString(T &t, const std::string &s, bool &error);
200
201 // In case the viewer is embedded and then detached:
202 void setOrigWindowSize(int w, int h) { OWwidth = w; OWheight = h; }
203
204 // Menubar information needed by G4OpenInventorQtViewer
205 // for common menu items:
206 QMenuBar* getMenubar() { return menubar; }
207 QMenu* getFileMenu() { return filemenu; }
208 QMenu* getEtcMenu() { return etcmenu; }
209 QFont* getFont() { return font; };
210
211 void setExternalQtApp() { externalQtApp = TRUE; }
212
213 // Needed?
216
217 void addEscapeCallback(void (*cb)());
218
222
223
224protected:
225 // FWJ Constructor with build flag added (as in parent)
226 // Need for this TBD.
227 // G4OpenInventorQtExaminerViewer(QWidget parent,
228 // const char *name,
229 // SbBool embed,
230 // SoQtFullViewer::BuildFlag flag,
231 // SoQtViewer::Type type,
232 // SbBool build);
233
234 void construct(const SbBool build);
235 void buildWidget(QWidget* parent);
236
237 virtual void afterRealizeHook();
238
240 friend class HookEventProcState;
242
243 static void sceneChangeCB(void*, SoSensor*);
244
245 SbBool processSoEvent(const SoEvent* const event);
246
247 void saveViewPt(char* name);
248 bool loadViewPts();
249 void addViewPoints();
250 void setViewPt();
251 void writeViewPtIdx();
253 void deleteViewPt(char *vpName = NULL);
254 void renameViewPt(char *vpName);
255 void sortViewPts(std::vector<std::string>);
256
257 void zoom(const float);
258 void moveCamera(float dist = 0, bool lookdown = false);
259 std::string curEltName;
260 SbVec3f camUpVec;
261 SbVec3f camDir;
262 void rotateCamera();
263 void updateViewParams(SoKeyboardEvent::Key);
264
265 static void mouseoverCB(void *aThis, SoEventCallback *eventCB);
266 static void pickingCB(void *aThis, SoEventCallback *eventCB);
267
268
269 // Animation
270 static void animateRefParticleCB();
271 static void animateSensorCB(void *, SoSensor *);
272 static void animateSensorRotationCB(void *, SoSensor *);
273 void animateRefParticle();
274 void saveCurCamera();
275 void restoreCamera();
277 void incSpeed();
278 void decSpeed();
279
280 SoTimerSensor *animateSensor;
281 SoTimerSensor *animateSensorRotation;
282 SoNodeSensor *sceneChangeSensor;
285
286 void setReferencePath(SoLineSet*, SoCoordinate3*, bool append = false);
288 void findAndSetRefPath();
289 SoCoordinate3* getCoordsNode(SoFullPath *path);
290 void getSceneElements(); // reads elements from the scene graph
291 float sqrlen(const SbVec3f&);
292 void distanceToTrajectory(const SbVec3f&, float&, SbVec3f&, int&);
293 void sortElements();
294 void createElementsList();
295 // static void closeMainWindowCB(Widget, XtPointer, XtPointer);
297
298 // static void gotoRefPathStartCB(Widget, XtPointer, XtPointer);
299 void gotoRefPathStart();
300 // static void invertRefPathCB(Widget, XtPointer, XtPointer);
301 void invertRefPath();
302
303
317
318 // For storing the view point
319 struct viewPtData {
320 char* viewPtName{nullptr};
322 SbVec3f position{0.0, 0.0, 0.0} ;
323 SbRotation orientation{};
324 float aspectRatio{0.0};
325 float nearDistance{0.0};
326 float farDistance{0.0};
327 float focalDistance{0.0};
329 float height{0.0};
330 };
331
333 std::string name;
334 SoFullPath* path;
335 SbVec3f center;
337 };
338
344 std::string name;
345
347 {
349 return true;
351 return false;
352
353 // otherwise closestPointZCoord == other.closestPointZCoord.
354 // Compare the distances from the center of the element to
355 // the start of the beamline.
357 return true;
359 return false;
360
361 // In case both closestPointZCoord and smallestDistance are
362 // equal, we have two exactly overlapping elements, if so
363 // the order doesn't matter
364 return true;
365 }
366 };
367
369
370 std::vector<sceneElement> sceneElements;
371 std::vector<viewPtData> viewPtList;
372 std::string fileName;
373 std::ifstream fileIn;
374 std::ofstream fileOut;
378
379 // For storing coordinate points of the reference particle
380 std::vector<SbVec3f> refParticleTrajectory;
381 // For displaying distance during anim and beamline modes
382 std::vector<float> refZPositions;
383
386 float distance;
389
390 int step;
391 SbVec3f prevPt;
394
398 SoCamera* myCam;
401 SbVec3f rotAxis; // For 90 degree rotations
402 int rotCnt; // # of steps rotation is split into
403
404 std::string viewPtAutoName();
405
406 ////////////////////////ANIM_SPEED_INDICATOR///////////////////////
407
408 SoSearchAction * searcher;
409
411 SoCoordinate3 * sgeometry;
412 SoScale * sscale;
413
414 SoTranslation * stranslation;
415 SoTranslation * curInfoTrans;
416 SoTranslation * mouseOverTransSolid;
417 SoTranslation * mouseOverTransMaterial;
418 SoTranslation * mouseOverTransLogName;
419 SoTranslation * mouseOverTransZPos;
420
421 // Used for 2 similar purposes: 1. Displays z position during animation
422 // 2. Displays name of the current viewpoint
423 SoText2 * curInfoText;
424
425 // Need to use many different fields for mouseover
426 // because newlines are ignored when the scene is rendered
431
432 SoFont* curInfoFont;
437 SoSwitch* axisSwitch;
440 SoSwitch* curInfoSwitch;
441
442 SoNode* getSuperimpositionNode(SoNode*, const char* name);
443
444 void superimpositionEvent(SoAction* action);
445 static void superimpositionCB(void* closure, SoAction* action);
446
447
448 virtual void actualRedraw(void);
449 void updateSpeedIndicator(void);
450
451 float maxSpeed;
452
453 ////////////////////////ANIM_SPEED_INDICATOR///////////////////////
454
455 // FWJ added for Ortho camera
458 // FWJ add look-ahead for animation tracking on curves
460
461 // Used by G4 app during element rotations, stores previous view
464
465 SoSeparator* newSceneGraph;
466
467};
468
469#endif /* G4OPENINVENTORQTEXAMINERVIEWER_HH */
G4ApplicationState
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
static void mouseoverCB(void *aThis, SoEventCallback *eventCB)
SoCoordinate3 * getCoordsNode(SoFullPath *path)
static void superimpositionCB(void *closure, SoAction *action)
static void animateSensorRotationCB(void *, SoSensor *)
void moveCamera(float dist=0, bool lookdown=false)
SoNode * getSuperimpositionNode(SoNode *, const char *name)
void parseString(T &t, const std::string &s, bool &error)
static void pickingCB(void *aThis, SoEventCallback *eventCB)
static void sceneChangeCB(void *, SoSensor *)
SbBool processSoEvent(const SoEvent *const event)
G4OpenInventorQtExaminerViewer(QWidget *parent=NULL, const char *name=NULL, SbBool embed=TRUE, SoQtFullViewer::BuildFlag flag=BUILD_ALL, SoQtViewer::Type type=BROWSER)
void sortViewPts(std::vector< std::string >)
void updateViewParams(SoKeyboardEvent::Key)
void setReferencePath(SoLineSet *, SoCoordinate3 *, bool append=false)
void distanceToTrajectory(const SbVec3f &, float &, SbVec3f &, int &)
static void animateSensorCB(void *, SoSensor *)
virtual G4bool Notify(G4ApplicationState requestedState)
HookEventProcState(G4OpenInventorQtExaminerViewer *)
#define TRUE
Definition globals.hh:41
G4bool operator<(elementForSorting const &other) const