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.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 
 37 class G4OpenInventorQtExaminerViewer;
 38 
 39 class HookEventProcState : public G4VStateDependent
 40 {
 41 public:
 42    HookEventProcState(G4OpenInventorQtExaminerViewer*);
 43    ~HookEventProcState();
 44    virtual G4bool Notify(G4ApplicationState requestedState);
 45 private:
 46    G4OpenInventorQtExaminerViewer* viewer;
 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 
 65 class G4UIQt;
 66 
 67 class SoCoordinate3;
 68 class SoFont;
 69 class SoText2;
 70 class SoPointSet;
 71 
 72 class QWidget;
 73 class QDialog;
 74 class QMenuBar;
 75 class QMenu;
 76 class QAction;
 77 class QListWidgetItem;
 78 class QPushButton;
 79 class QRadioButton;
 80 class QMessageBox;
 81 class QFont;
 82 
 83 // The Aux Window dialog created with Qt Designer:
 84 class Ui_Dialog;
 85 
 86 
 87 class G4OpenInventorQtExaminerViewer: public QObject,
 88                                       public SoQtExaminerViewer {
 89 
 90   Q_OBJECT 
 91 
 92   //  friend class G4OpenInventorQtExaminerViewerMessenger;
 93   // FWJ
 94  friend class G4OpenInventorQtViewer;
 95 
 96 private 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 
128 private:
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 
197 public:
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 
205    ~G4OpenInventorQtExaminerViewer();
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?
227    std::string saveScenegraphFileName;
228    std::string saveRefCoordsFileName;
229 
230    void addEscapeCallback(void (*cb)());
231 #endif
232 
233    bool abbrOutputFlag;
234    bool pickRefPathFlag;
235    bool viewingBeforePickRef;
236 
237 #if 0x060000 <= QT_VERSION
238    void addInTab();
239 #endif
240 
241 protected:
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 
260    HookEventProcState* hookBeamOn;
261    friend class HookEventProcState;
262    bool newEvents;
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();
273    void cleanUpAfterPrevFile();
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();
297    double animateBtwPtsPeriod, speedStep;
298    void incSpeed();
299    void decSpeed();
300   
301    SoTimerSensor *animateSensor;
302    SoTimerSensor *animateSensorRotation;
303    SoNodeSensor *sceneChangeSensor;
304    SbVec3f camStartPos, camEndPos;
305    SbRotation camStartOrient, camEndOrient;
306 
307    void setReferencePath(SoLineSet*, SoCoordinate3*, bool append = false);
308    void setReferencePathZPos();
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);
317    void evenOutRefParticlePts();
318 
319    //  static void gotoRefPathStartCB(Widget, XtPointer, XtPointer);
320    void gotoRefPathStart();
321    //  static void invertRefPathCB(Widget, XtPointer, XtPointer);
322    void invertRefPath();
323 
324 
325    enum CameraType {
326       PERSPECTIVE,
327       ORTHOGRAPHIC
328    };
329    enum State {
330       GENERAL,
331       BEAMLINE,
332       VIEWPOINT,
333       ANIMATION,
334       REVERSED_ANIMATION,
335       PAUSED_ANIMATION,
336       ROTATING
337    };
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
346     int viewportMapping{0};
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};
353     CameraType camType{PERSPECTIVE};
354     float height{0.0};
355    };
356 
357    struct sceneElement {
358       std::string name;
359       SoFullPath* path;
360       SbVec3f center;
361       float closestPointZCoord;
362    };
363 
364    struct elementForSorting {
365       float closestPointZCoord;
366       SbVec3f closestPoint;
367       float smallestDistance;
368       float distanceToBeamlineStart;
369       std::string name;
370 
371       G4bool operator<(elementForSorting const &other) const
372       {
373          if (closestPointZCoord < other.closestPointZCoord)
374             return true;
375          if (closestPointZCoord > other.closestPointZCoord)
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.
381          if (distanceToBeamlineStart < other.distanceToBeamlineStart)
382             return true;
383          if (distanceToBeamlineStart > other.distanceToBeamlineStart)
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 
393    bool zcoordSetFlag;
394 
395    std::vector<sceneElement> sceneElements;
396    std::vector<viewPtData> viewPtList;
397    std::string fileName;
398    std::ifstream fileIn;
399    std::ofstream fileOut; 
400    int viewPtIdx;
401    int MAX_VP_IDX;
402    int MAX_VP_NAME;
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 
409    int refParticleIdx;
410    int prevRefIdx;
411    float distance;
412    State currentState, prevState, beforePausing;
413 #if QT_VERSION < 0x060000
414    char* curViewPtName;
415 #else
416    std::string curViewPtName;
417 #endif
418   
419    int step;
420    SbVec3f prevPt;
421    SbVec3f prevParticleDir;
422    void* prevColorField;
423   
424    viewPtData camB4Animation;
425    bool returnToSaveVP;
426    bool returnToAnim;
427    SoCamera* myCam;
428    void setStartingPtForAnimation(); 
429    float left_right, up_down;    
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 
439    SoNode * superimposition;
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
456    SoText2* mouseOverTextSolid;
457    SoText2* mouseOverTextMaterial;
458    SoText2* mouseOverTextLogName;
459    SoText2* mouseOverTextZPos;
460 
461    SoFont* curInfoFont;
462    SoFont* mouseOverFontSolid;
463    SoFont* mouseOverFontMaterial;
464    SoFont* mouseOverFontLogName;
465    SoFont* mouseOverFontZPos;
466    SoSwitch* axisSwitch;
467    SoSwitch* animSpeedOutlineSwitch;
468    SoSwitch* animSpeedSwitch;
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
485    float defaultHeight;
486    float defaultHeightAngle;
487    // FWJ add look-ahead for animation tracking on curves
488    G4int pathLookahead;
489   
490    // Used by G4 app during element rotations, stores previous view
491    SbVec3f upVector, offsetFromCenter, center;   
492    bool rotUpVec;
493 
494    SoSeparator* newSceneGraph;
495 
496 };
497 
498 #endif /* G4OPENINVENTORQTEXAMINERVIEWER_HH */
499