Geant4 11.1.1
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
40{
41public:
44 virtual G4bool Notify(G4ApplicationState requestedState);
45private:
47};
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 template <class T> void parseString(T &t, const std::string &s, bool &error);
198
199 // In case the viewer is embedded and then detached:
200 void setOrigWindowSize(int w, int h) { OWwidth = w; OWheight = h; }
201
202 // Menubar information needed by G4OpenInventorQtViewer
203 // for common menu items:
204 QMenuBar* getMenubar() { return menubar; }
205 QMenu* getFileMenu() { return filemenu; }
206 QMenu* getEtcMenu() { return etcmenu; }
207 QFont* getFont() { return font; };
208
209 void setExternalQtApp() { externalQtApp = TRUE; }
210
211 // Needed?
214
215 void addEscapeCallback(void (*cb)());
216
220
221
222protected:
223 // FWJ Constructor with build flag added (as in parent)
224 // Need for this TBD.
225 // G4OpenInventorQtExaminerViewer(QWidget parent,
226 // const char *name,
227 // SbBool embed,
228 // SoQtFullViewer::BuildFlag flag,
229 // SoQtViewer::Type type,
230 // SbBool build);
231
232 void construct(const SbBool build);
233 void buildWidget(QWidget* parent);
234
235 virtual void afterRealizeHook();
236
238 friend class HookEventProcState;
240
241 static void sceneChangeCB(void*, SoSensor*);
242
243 SbBool processSoEvent(const SoEvent* const event);
244
245 void saveViewPt(char* name);
246 bool loadViewPts();
247 void addViewPoints();
248 void setViewPt();
249 void writeViewPtIdx();
251 void deleteViewPt(char *vpName = NULL);
252 void renameViewPt(char *vpName);
253 void sortViewPts(std::vector<std::string>);
254
255 void zoom(const float);
256 void moveCamera(float dist = 0, bool lookdown = false);
257 std::string curEltName;
258 SbVec3f camUpVec;
259 SbVec3f camDir;
260 void rotateCamera();
261 void updateViewParams(SoKeyboardEvent::Key);
262
263 static void mouseoverCB(void *aThis, SoEventCallback *eventCB);
264 static void pickingCB(void *aThis, SoEventCallback *eventCB);
265
266
267 // Animation
268 static void animateRefParticleCB();
269 static void animateSensorCB(void *, SoSensor *);
270 static void animateSensorRotationCB(void *, SoSensor *);
271 void animateRefParticle();
272 void saveCurCamera();
273 void restoreCamera();
275 void incSpeed();
276 void decSpeed();
277
278 SoTimerSensor *animateSensor;
279 SoTimerSensor *animateSensorRotation;
280 SoNodeSensor *sceneChangeSensor;
283
284 void setReferencePath(SoLineSet*, SoCoordinate3*, bool append = false);
286 void findAndSetRefPath();
287 SoCoordinate3* getCoordsNode(SoFullPath *path);
288 void getSceneElements(); // reads elements from the scene graph
289 float sqrlen(const SbVec3f&);
290 void distanceToTrajectory(const SbVec3f&, float&, SbVec3f&, int&);
291 void sortElements();
292 void createElementsList();
293 // static void closeMainWindowCB(Widget, XtPointer, XtPointer);
295
296 // static void gotoRefPathStartCB(Widget, XtPointer, XtPointer);
297 void gotoRefPathStart();
298 // static void invertRefPathCB(Widget, XtPointer, XtPointer);
299 void invertRefPath();
300
301
305 };
306 enum State {
314 };
315
316 // For storing the view point
317 struct viewPtData {
320 SbVec3f position;
321 SbRotation orientation;
327 float height;
328 };
329
331 std::string name;
332 SoFullPath* path;
333 SbVec3f center;
335 };
336
342 std::string name;
343
345 {
347 return true;
349 return false;
350
351 // otherwise closestPointZCoord == other.closestPointZCoord.
352 // Compare the distances from the center of the element to
353 // the start of the beamline.
355 return true;
357 return false;
358
359 // In case both closestPointZCoord and smallestDistance are
360 // equal, we have two exactly overlapping elements, if so
361 // the order doesn't matter
362 return true;
363 }
364 };
365
367
368 std::vector<sceneElement> sceneElements;
369 std::vector<viewPtData> viewPtList;
370 std::string fileName;
371 std::ifstream fileIn;
372 std::ofstream fileOut;
376
377 // For storing coordinate points of the reference particle
378 std::vector<SbVec3f> refParticleTrajectory;
379 // For displaying distance during anim and beamline modes
380 std::vector<float> refZPositions;
381
384 float distance;
387
388 int step;
389 SbVec3f prevPt;
392
396 SoCamera* myCam;
399 SbVec3f rotAxis; // For 90 degree rotations
400 int rotCnt; // # of steps rotation is split into
401
402 std::string viewPtAutoName();
403
404 ////////////////////////ANIM_SPEED_INDICATOR///////////////////////
405
406 SoSearchAction * searcher;
407
409 SoCoordinate3 * sgeometry;
410 SoScale * sscale;
411
412 SoTranslation * stranslation;
413 SoTranslation * curInfoTrans;
414 SoTranslation * mouseOverTransSolid;
415 SoTranslation * mouseOverTransMaterial;
416 SoTranslation * mouseOverTransLogName;
417 SoTranslation * mouseOverTransZPos;
418
419 // Used for 2 similar purposes: 1. Displays z position during animation
420 // 2. Displays name of the current viewpoint
421 SoText2 * curInfoText;
422
423 // Need to use many different fields for mouseover
424 // because newlines are ignored when the scene is rendered
429
430 SoFont* curInfoFont;
435 SoSwitch* axisSwitch;
438 SoSwitch* curInfoSwitch;
439
440 SoNode* getSuperimpositionNode(SoNode*, const char* name);
441
442 void superimpositionEvent(SoAction* action);
443 static void superimpositionCB(void* closure, SoAction* action);
444
445
446 virtual void actualRedraw(void);
447 void updateSpeedIndicator(void);
448
449 float maxSpeed;
450
451 ////////////////////////ANIM_SPEED_INDICATOR///////////////////////
452
453 // FWJ added for Ortho camera
456 // FWJ add look-ahead for animation tracking on curves
458
459 // Used by G4 app during element rotations, stores previous view
462
463 SoSeparator* newSceneGraph;
464
465};
466
467#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)
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)
#define TRUE
Definition: globals.hh:41
G4bool operator<(elementForSorting const &other) const