Geant4 11.3.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// 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#if QT_VERSION < 0x060000
131 static G4OpenInventorQtExaminerViewer* viewer;
132 QString* fName;
133#else
134 QString fName;
135#endif
136
137#if QT_VERSION < 0x060000
138 int OWwidth, OWheight;
139
140 void (*escapeCallback)();
141 void* examinerObject;
142#endif
143
144 SbBool lshiftdown, rshiftdown, lctrldown, rctrldown;
145
146 QFont* font;
147 QMenuBar* menubar;
148 QMenu* filemenu;
149 QMenu* toolsmenu;
150 QMenu* etcmenu;
151 QMenu* helpmenu;
152 QMessageBox* helpmsgbox;
153
154 bool externalQtApp;
155
156 QAction* FileOpenBookmark;
157 QAction* FileNewBookmark;
158 QAction* FileLoadRefPath;
159 QAction* FileSaveRefPath;
160 QAction* FileLoadSceneGraph;
161 QAction* FileSaveSceneGraph;
162
163 QAction* ToolsAnimateRefParticle;
164 QAction* ToolsRefPathStart;
165 QAction* ToolsRefPathInvert;
166
167 // KEEP in the viewer
168 QAction* HelpControls;
169
170 // Added viewer buttons
171 QPushButton* saveViewPtButton;
172 QPushButton* nextViewPtButton;
173 QPushButton* prevViewPtButton;
174 QPushButton* abbrOutputButton;
175 QPushButton* pickRefPathButton;
176 QPushButton* switchWireFrameButton;
177 QPushButton* switchAxesButton;
178 QPushButton* detachButton;
179
180 QListWidgetItem* saveViewPtItem;
181
182 Ui_Dialog* AuxWindowDialog;
183 QDialog* AuxWindow;
184
185 G4UIQt* uiQt;
186#if QT_VERSION < 0x060000
187 QWidget* viewerParent;
188 QWidget* viewerParent2;
189 int uiQtTabIndex;
190#endif
191
192 int processSoEventCount;
193#if QT_VERSION < 0x060000
194 G4String empty = "";
195#endif
196
197public:
198
199 G4OpenInventorQtExaminerViewer(QWidget* parent = NULL,
200 const char* name = NULL,
201 SbBool embed = TRUE,
202 SoQtFullViewer::BuildFlag flag = BUILD_ALL,
203 SoQtViewer::Type type = BROWSER);
204
206
207 template <class T> void parseString(T &t, const std::string &s, bool &error);
208
209#if QT_VERSION < 0x060000
210 G4UIQt* GetUIQt() {return uiQt;}
211
212 // In case the viewer is embedded and then detached:
213 void setOrigWindowSize(int w, int h) { OWwidth = w; OWheight = h; }
214#endif
215
216 // Menubar information needed by G4OpenInventorQtViewer
217 // for common menu items:
218 QMenuBar* getMenubar() { return menubar; }
219 QMenu* getFileMenu() { return filemenu; }
220 QMenu* getEtcMenu() { return etcmenu; }
221 QFont* getFont() { return font; };
222
223 void setExternalQtApp() { externalQtApp = TRUE; }
224
225#if QT_VERSION < 0x060000
226 // Needed?
229
230 void addEscapeCallback(void (*cb)());
231#endif
232
236
237#if 0x060000 <= QT_VERSION
238 void addInTab();
239#endif
240
241protected:
242 // FWJ Constructor with build flag added (as in parent)
243 // Need for this TBD.
244 // G4OpenInventorQtExaminerViewer(QWidget parent,
245 // const char *name,
246 // SbBool embed,
247 // SoQtFullViewer::BuildFlag flag,
248 // SoQtViewer::Type type,
249 // SbBool build);
250
251 void construct(const SbBool build);
252 void buildWidget(QWidget* parent);
253
254#if QT_VERSION < 0x060000
255 virtual void afterRealizeHook();
256#else
257 void setupSceneGraph();
258#endif
259
261 friend class HookEventProcState;
263
264 static void sceneChangeCB(void*, SoSensor*);
265
266 SbBool processSoEvent(const SoEvent* const event);
267
268 void saveViewPt(char* name);
269 bool loadViewPts();
270 void addViewPoints();
271 void setViewPt();
272 void writeViewPtIdx();
274 void deleteViewPt(char *vpName = NULL);
275 void renameViewPt(char *vpName);
276 void sortViewPts(std::vector<std::string>);
277
278 void zoom(const float);
279 void moveCamera(float dist = 0, bool lookdown = false);
280 std::string curEltName;
281 SbVec3f camUpVec;
282 SbVec3f camDir;
283 void rotateCamera();
284 void updateViewParams(SoKeyboardEvent::Key);
285
286 static void mouseoverCB(void *aThis, SoEventCallback *eventCB);
287 static void pickingCB(void *aThis, SoEventCallback *eventCB);
288
289
290 // Animation
291 static void animateRefParticleCB();
292 static void animateSensorCB(void *, SoSensor *);
293 static void animateSensorRotationCB(void *, SoSensor *);
294 void animateRefParticle();
295 void saveCurCamera();
296 void restoreCamera();
298 void incSpeed();
299 void decSpeed();
300
301 SoTimerSensor *animateSensor;
302 SoTimerSensor *animateSensorRotation;
303 SoNodeSensor *sceneChangeSensor;
306
307 void setReferencePath(SoLineSet*, SoCoordinate3*, bool append = false);
309 void findAndSetRefPath();
310 SoCoordinate3* getCoordsNode(SoFullPath *path);
311 void getSceneElements(); // reads elements from the scene graph
312 float sqrlen(const SbVec3f&);
313 void distanceToTrajectory(const SbVec3f&, float&, SbVec3f&, int&);
314 void sortElements();
315 void createElementsList();
316 // static void closeMainWindowCB(Widget, XtPointer, XtPointer);
318
319 // static void gotoRefPathStartCB(Widget, XtPointer, XtPointer);
320 void gotoRefPathStart();
321 // static void invertRefPathCB(Widget, XtPointer, XtPointer);
322 void invertRefPath();
323
324
338
339 // For storing the view point
340 struct viewPtData {
341#if QT_VERSION < 0x060000
342 char* viewPtName{nullptr};
343#else
344 std::string viewPtName;
345#endif
347 SbVec3f position{0.0, 0.0, 0.0} ;
348 SbRotation orientation{};
349 float aspectRatio{0.0};
350 float nearDistance{0.0};
351 float farDistance{0.0};
352 float focalDistance{0.0};
354 float height{0.0};
355 };
356
358 std::string name;
359 SoFullPath* path;
360 SbVec3f center;
362 };
363
369 std::string name;
370
372 {
374 return true;
376 return false;
377
378 // otherwise closestPointZCoord == other.closestPointZCoord.
379 // Compare the distances from the center of the element to
380 // the start of the beamline.
382 return true;
384 return false;
385
386 // In case both closestPointZCoord and smallestDistance are
387 // equal, we have two exactly overlapping elements, if so
388 // the order doesn't matter
389 return true;
390 }
391 };
392
394
395 std::vector<sceneElement> sceneElements;
396 std::vector<viewPtData> viewPtList;
397 std::string fileName;
398 std::ifstream fileIn;
399 std::ofstream fileOut;
403
404 // For storing coordinate points of the reference particle
405 std::vector<SbVec3f> refParticleTrajectory;
406 // For displaying distance during anim and beamline modes
407 std::vector<float> refZPositions;
408
411 float distance;
413#if QT_VERSION < 0x060000
415#else
416 std::string curViewPtName;
417#endif
418
419 int step;
420 SbVec3f prevPt;
423
427 SoCamera* myCam;
430 SbVec3f rotAxis; // For 90 degree rotations
431 int rotCnt; // # of steps rotation is split into
432
433 std::string viewPtAutoName();
434
435 ////////////////////////ANIM_SPEED_INDICATOR///////////////////////
436
437 SoSearchAction * searcher;
438
440 SoCoordinate3 * sgeometry;
441 SoScale * sscale;
442
443 SoTranslation * stranslation;
444 SoTranslation * curInfoTrans;
445 SoTranslation * mouseOverTransSolid;
446 SoTranslation * mouseOverTransMaterial;
447 SoTranslation * mouseOverTransLogName;
448 SoTranslation * mouseOverTransZPos;
449
450 // Used for 2 similar purposes: 1. Displays z position during animation
451 // 2. Displays name of the current viewpoint
452 SoText2 * curInfoText;
453
454 // Need to use many different fields for mouseover
455 // because newlines are ignored when the scene is rendered
460
461 SoFont* curInfoFont;
466 SoSwitch* axisSwitch;
469 SoSwitch* curInfoSwitch;
470
471 SoNode* getSuperimpositionNode(SoNode*, const char* name);
472
473 void superimpositionEvent(SoAction* action);
474 static void superimpositionCB(void* closure, SoAction* action);
475
476
477 virtual void actualRedraw(void);
478 void updateSpeedIndicator(void);
479
480 float maxSpeed;
481
482 ////////////////////////ANIM_SPEED_INDICATOR///////////////////////
483
484 // FWJ added for Ortho camera
487 // FWJ add look-ahead for animation tracking on curves
489
490 // Used by G4 app during element rotations, stores previous view
493
494 SoSeparator* newSceneGraph;
495
496};
497
498#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 *)
G4VStateDependent(G4bool bottom=false)
virtual G4bool Notify(G4ApplicationState requestedState)
HookEventProcState(G4OpenInventorQtExaminerViewer *)
#define TRUE
Definition globals.hh:41
G4bool operator<(elementForSorting const &other) const