Geant4-11
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 "G4Types.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();
104
106 void ToolsRefPathStartCB();
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
131 QString* fName;
132
134
135 void (*escapeCallback)();
136
139
140 QFont* font;
141 QMenuBar* menubar;
142 QMenu* filemenu;
143 QMenu* toolsmenu;
144 QMenu* etcmenu;
145 QMenu* helpmenu;
146 QMessageBox* helpmsgbox;
147
149
156
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;
171 QPushButton* switchAxesButton;
172 QPushButton* detachButton;
173
174 QListWidgetItem* saveViewPtItem;
175
177 QDialog* AuxWindow;
178
180 QWidget* viewerParent;
183
185
186public:
187
188 G4OpenInventorQtExaminerViewer(QWidget* parent = NULL,
189 const char* name = NULL,
190 SbBool embed = TRUE,
191 SoQtFullViewer::BuildFlag flag = BUILD_ALL,
192 SoQtViewer::Type type = BROWSER);
193
195
196 template <class T> void parseString(T &t, const std::string &s, bool &error);
197
198 // In case the viewer is embedded and then detached:
199 void setOrigWindowSize(int w, int h) { OWwidth = w; OWheight = h; }
200
201 // Menubar information needed by G4OpenInventorQtViewer
202 // for common menu items:
203 QMenuBar* getMenubar() { return menubar; }
204 QMenu* getFileMenu() { return filemenu; }
205 QMenu* getEtcMenu() { return etcmenu; }
206 QFont* getFont() { return font; };
207
209
210 // Needed?
213
214 void addEscapeCallback(void (*cb)());
215
219
220
221protected:
222 // FWJ Constructor with build flag added (as in parent)
223 // Need for this TBD.
224 // G4OpenInventorQtExaminerViewer(QWidget parent,
225 // const char *name,
226 // SbBool embed,
227 // SoQtFullViewer::BuildFlag flag,
228 // SoQtViewer::Type type,
229 // SbBool build);
230
231 void construct(const SbBool build);
232 void buildWidget(QWidget* parent);
233
234 virtual void afterRealizeHook();
235
237 friend class HookEventProcState;
239
240 static void sceneChangeCB(void*, SoSensor*);
241
242 SbBool processSoEvent(const SoEvent* const event);
243
244 void saveViewPt(char* name);
245 bool loadViewPts();
246 void addViewPoints();
247 void setViewPt();
248 void writeViewPtIdx();
250 void deleteViewPt(char *vpName = NULL);
251 void renameViewPt(char *vpName);
252 void sortViewPts(std::vector<std::string>);
253
254 void zoom(const float);
255 void moveCamera(float dist = 0, bool lookdown = false);
256 std::string curEltName;
257 SbVec3f camUpVec;
258 SbVec3f camDir;
259 void rotateCamera();
260 void updateViewParams(SoKeyboardEvent::Key);
261
262 static void mouseoverCB(void *aThis, SoEventCallback *eventCB);
263 static void pickingCB(void *aThis, SoEventCallback *eventCB);
264
265
266 // Animation
267 static void animateRefParticleCB();
268 static void animateSensorCB(void *, SoSensor *);
269 static void animateSensorRotationCB(void *, SoSensor *);
270 void animateRefParticle();
271 void saveCurCamera();
272 void restoreCamera();
274 void incSpeed();
275 void decSpeed();
276
277 SoTimerSensor *animateSensor;
278 SoTimerSensor *animateSensorRotation;
279 SoNodeSensor *sceneChangeSensor;
282
283 void setReferencePath(SoLineSet*, SoCoordinate3*, bool append = false);
285 void findAndSetRefPath();
286 SoCoordinate3* getCoordsNode(SoFullPath *path);
287 void getSceneElements(); // reads elements from the scene graph
288 float sqrlen(const SbVec3f&);
289 void distanceToTrajectory(const SbVec3f&, float&, SbVec3f&, int&);
290 void sortElements();
291 void createElementsList();
292 // static void closeMainWindowCB(Widget, XtPointer, XtPointer);
294
295 // static void gotoRefPathStartCB(Widget, XtPointer, XtPointer);
296 void gotoRefPathStart();
297 // static void invertRefPathCB(Widget, XtPointer, XtPointer);
298 void invertRefPath();
299
300
304 };
305 enum State {
313 };
314
315 // For storing the view point
316 struct viewPtData {
319 SbVec3f position;
320 SbRotation orientation;
326 float height;
327 };
328
330 std::string name;
331 SoFullPath* path;
332 SbVec3f center;
334 };
335
341 std::string name;
342
344 {
346 return true;
348 return false;
349
350 // otherwise closestPointZCoord == other.closestPointZCoord.
351 // Compare the distances from the center of the element to
352 // the start of the beamline.
354 return true;
356 return false;
357
358 // In case both closestPointZCoord and smallestDistance are
359 // equal, we have two exactly overlapping elements, if so
360 // the order doesn't matter
361 return true;
362 }
363 };
364
366
367 std::vector<sceneElement> sceneElements;
368 std::vector<viewPtData> viewPtList;
369 std::string fileName;
370 std::ifstream fileIn;
371 std::ofstream fileOut;
375
376 // For storing coordinate points of the reference particle
377 std::vector<SbVec3f> refParticleTrajectory;
378 // For displaying distance during anim and beamline modes
379 std::vector<float> refZPositions;
380
383 float distance;
386
387 int step;
388 SbVec3f prevPt;
391
395 SoCamera* myCam;
398 SbVec3f rotAxis; // For 90 degree rotations
399 int rotCnt; // # of steps rotation is split into
400
401 std::string viewPtAutoName();
402
404
405 SoSearchAction * searcher;
406
408 SoCoordinate3 * sgeometry;
409 SoScale * sscale;
410
411 SoTranslation * stranslation;
412 SoTranslation * curInfoTrans;
413 SoTranslation * mouseOverTransSolid;
414 SoTranslation * mouseOverTransMaterial;
415 SoTranslation * mouseOverTransLogName;
416 SoTranslation * mouseOverTransZPos;
417
418 // Used for 2 similar purposes: 1. Displays z position during animation
419 // 2. Displays name of the current viewpoint
420 SoText2 * curInfoText;
421
422 // Need to use many different fields for mouseover
423 // because newlines are ignored when the scene is rendered
428
429 SoFont* curInfoFont;
434 SoSwitch* axisSwitch;
437 SoSwitch* curInfoSwitch;
438
439 SoNode* getSuperimpositionNode(SoNode*, const char* name);
440
441 void superimpositionEvent(SoAction* action);
442 static void superimpositionCB(void* closure, SoAction* action);
443
444
445 virtual void actualRedraw(void);
446 void updateSpeedIndicator(void);
447
448 float maxSpeed;
449
451
452 // FWJ added for Ortho camera
455 // FWJ add look-ahead for animation tracking on curves
457
458 // Used by G4 app during element rotations, stores previous view
461
462 SoSeparator* newSceneGraph;
463
464};
465
466#endif /* G4OPENINVENTORQTEXAMINERVIEWER_HH */
G4ApplicationState
G4ProfileType Type
static constexpr double s
Definition: G4SIunits.hh:154
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define TRUE
Definition: Globals.hh:27
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)
static G4OpenInventorQtExaminerViewer * viewer
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 *)
G4OpenInventorQtExaminerViewer * viewer
const char * name(G4int ptype)
G4bool operator<(elementForSorting const &other) const
static PROLOG_HANDLER error
Definition: xmlrole.cc:127