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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 // Open Inventor Xt Extended Viewer - 30 Oct 2012
 27 // Rastislav Ondrasek, Pierre-Luc Gagnon, Frederick Jones TRIUMF
 28 
 29 #ifndef HookEventProcState_H
 30 #define HookEventProcState_H 1
 31 #include "G4VStateDependent.hh"
 32 
 33 class G4OpenInventorXtExaminerViewer;
 34 
 35 class HookEventProcState : public G4VStateDependent
 36 {
 37 private:
 38    G4OpenInventorXtExaminerViewer *viewer;
 39 public:
 40    HookEventProcState(G4OpenInventorXtExaminerViewer*);
 41    ~HookEventProcState();
 42 
 43    virtual G4bool Notify(G4ApplicationState requiredState);
 44 };
 45 #endif /* HookEventProcState_H */
 46 
 47 
 48 #ifndef G4OPENINVENTORXTEXAMINERVIEWER_HH
 49 #define G4OPENINVENTORXTEXAMINERVIEWER_HH
 50 
 51 #include <map>
 52 #include <vector>
 53 #include <fstream>
 54 #include <Inventor/SbLinear.h>
 55 #include <Inventor/nodes/SoLineSet.h>
 56 #include <Inventor/nodes/SoEventCallback.h>
 57 #include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
 58 #include <Inventor/events/SoKeyboardEvent.h>
 59 
 60 class SoCoordinate3;
 61 class SoFont;
 62 class SoText2;
 63 class SoPointSet;
 64 
 65 class G4OpenInventorXtExaminerViewer : public SoXtExaminerViewer {
 66 
 67   friend class G4OpenInventorXtExaminerViewerMessenger;
 68   // FWJ
 69   friend class G4OpenInventorXtExtendedViewer;
 70 
 71 private:
 72   Widget prevViewPtButton, nextViewPtButton;
 73   Widget menuBar, fileMenu, openFileDialog, newFileDialog,
 74   loadRefCoordsDialog, saveRefCoordsDialog,
 75   loadSceneGraphDialog, saveSceneGraphDialog,
 76   viewPtSelection, listsDialog, myShellDialog, myViewPtList, myElementList;
 77 
 78   static G4OpenInventorXtExaminerViewer *viewer;
 79   void (*escapeCallback)(void *);
 80   void * examinerObject;
 81   SbBool lshiftdown, rshiftdown, lctrldown, rctrldown;
 82   
 83 public:
 84 
 85   // Same constructor as the ExaminerViewer
 86   G4OpenInventorXtExaminerViewer(Widget parent = NULL,
 87        const char *name = NULL,
 88        SbBool embed = TRUE, 
 89        SoXtFullViewer::BuildFlag flag = BUILD_ALL,
 90        SoXtViewer::Type type = BROWSER);
 91 
 92   ~G4OpenInventorXtExaminerViewer();
 93 
 94   template <class T> void parseString(T &t, const std::string &s, bool &error);
 95 
 96   Widget addMenu(std::string name);
 97   void addButton(Widget menu, std::string name, XtCallbackProc);
 98   Widget getMenuBar() { return menuBar; }
 99   Widget getMenu() { return fileMenu; }
100   void warningMsgDialog(std::string, String, XtCallbackProc);
101   bool warningFlag;
102 
103   std::string saveScenegraphFileName;
104   Widget saveScenegraphWidget;
105   std::string saveRefCoordsFileName;
106   Widget saveRefCoordsWidget;
107 
108   Widget createScale(Widget, char *, int, float);
109   void addEscapeCallback(void (*cb)(void *), void *);
110   bool abbrOutputFlag;
111   bool pickRefPathFlag;
112   bool viewingBeforePickRef;
113    // FWJ
114    //  SoNode * superimposition;
115          
116 protected:
117   // Same constructor as the ExaminerViewer 
118   G4OpenInventorXtExaminerViewer(Widget parent,
119        const char *name,
120        SbBool embed,
121        SoXtFullViewer::BuildFlag flag,
122        SoXtViewer::Type type,
123        SbBool build);
124 
125   // Overloaded for adding the MenuBar
126   Widget buildWidget(Widget parent);
127   // Overloaded so additional buttons can be added
128   virtual void createViewerButtons (Widget parent, SbPList * buttonlist);
129   // Overloaded for catching various keyboard events  
130   virtual SbBool processSoEvent(const SoEvent * const event);
131   void moveCamera(float dist = 0, bool lookdown = false);
132   std::string curEltName;
133   SbVec3f camUpVec;
134   SbVec3f camDir;
135   void rotateCamera();
136   void updateViewParams(SoKeyboardEvent::Key);
137   bool loadViewPts();
138   virtual void afterRealizeHook();
139 
140 private:
141   // Each constructor calls this generic constructor
142   void constructor(const SbBool build);
143 
144   // FWJ DISABLED
145   //  static G4OpenInventorXtExaminerViewer *getObject();
146 
147   HookEventProcState *hookBeamOn;
148   friend class HookEventProcState;
149   bool newEvents;
150   static void sceneChangeCB(void *, SoSensor *);
151     
152   void setViewPt();
153   void writeViewPtIdx();
154   void cleanUpAfterPrevFile();
155   
156   void popUpFileSelDialog(Widget&, std::string, std::string, XtCallbackProc);
157   static void cancelFileSelDialogCB(Widget, XtPointer, XtPointer);
158   static void openViewPtFileCB(Widget, XtPointer, XtPointer);
159   static void viewPtFileSelectedCB(Widget, XtPointer, XtPointer);
160   static void newViewPtFileCB(Widget, XtPointer, XtPointer);
161   static void createNewVPFileCB(Widget, XtPointer, XtPointer);
162   static void overwriteFileCB(Widget, XtPointer, XtPointer);
163   static void loadRefCoordsDialogCB(Widget, XtPointer, XtPointer);  //pop file dialog
164   static void loadRefCoordsCB(Widget, XtPointer, XtPointer);      //execute loading
165   static void saveRefCoordsDialogCB(Widget, XtPointer, XtPointer);  //pop file dialog
166   static void saveRefCoordsCB(Widget, XtPointer, XtPointer);      //execute saving
167   static void saveRefCoordsOverWriteCB(Widget, XtPointer, XtPointer);
168   static void loadSceneGraphDialogCB(Widget, XtPointer, XtPointer);
169   static void loadSceneGraphCB(Widget, XtPointer, XtPointer);
170   static void saveSceneGraphDialogCB(Widget, XtPointer, XtPointer);
171   static void saveSceneGraphCB(Widget, XtPointer, XtPointer);
172   static void saveSceneGraphOverWriteCB(Widget, XtPointer, XtPointer);
173   static void mouseoverCB(void *aThis, SoEventCallback *eventCB);
174   static void pickingCB(void *aThis, SoEventCallback *eventCB);
175 
176            
177   // Viewpoint operations
178   void addViewPoints();
179   static void closeListsDialogCB(Widget, XtPointer, XtPointer);
180   static void loadBookmarkCB(Widget, XtPointer, XtPointer);
181   static void renameBookmarkCB(Widget, XtPointer, XtPointer);
182   void renameViewPt(char *vpName);
183   static void sortBookmarksCB(Widget, XtPointer, XtPointer);
184   void sortViewPts(std::vector<std::string>);
185   static void deleteBookmarkCB(Widget, XtPointer, XtPointer);
186   static void deleteViewPtCB(Widget, XtPointer, XtPointer);
187   void deleteViewPt(char *vpName = NULL);
188     
189   // Animation
190   static void animateRefParticleCB(Widget, XtPointer, XtPointer);
191   static void animateSensorCB(void *, SoSensor *);
192   static void animateSensorRotationCB(void *, SoSensor *);
193   void animateRefParticle();
194   void saveCurCamera();
195   void restoreCamera();
196   double animateBtwPtsPeriod, speedStep;
197   void incSpeed();
198   void decSpeed();
199   
200   SoTimerSensor *animateSensor;
201   SoTimerSensor *animateSensorRotation;
202   SoNodeSensor *sceneChangeSensor;
203   SbVec3f camStartPos, camEndPos;
204   SbRotation camStartOrient, camEndOrient;
205   
206   static void prevViewPtCB(Widget, XtPointer, XtPointer);
207   static void nextViewPtCB(Widget, XtPointer, XtPointer);
208   static void saveViewPtCB(Widget, XtPointer, XtPointer);
209   static void abbrOutputCB(Widget, XtPointer, XtPointer);
210   static void pickRefPathCB(Widget, XtPointer, XtPointer);
211   static void switchWireFrameCB(Widget, XtPointer, XtPointer);
212   static void constructListsDialog(Widget, XtPointer, XtPointer);
213   void saveViewPt(char *name);
214   
215 
216   static void lookAtSceneElementCB(Widget, XtPointer, XtPointer);
217   static void cancelSceneElementSelectionCB(Widget, XtPointer, XtPointer);
218 
219   void setReferencePath(SoLineSet*, SoCoordinate3*, bool append = false);
220   void setReferencePathZPos();
221   void findAndSetRefPath();
222   SoCoordinate3* getCoordsNode(SoFullPath *path);
223   void getSceneElements(); // reads elements from the scene graph
224   float sqrlen(const SbVec3f&);
225   void distanceToTrajectory(const SbVec3f&, float&, SbVec3f&, int&);
226   void sortElements();
227   void createElementsList(Widget);
228   static void closeMainWindowCB(Widget, XtPointer, XtPointer);
229   void evenOutRefParticlePts();
230 
231   static void gotoRefPathStartCB(Widget, XtPointer, XtPointer);
232   void gotoRefPathStart();
233   static void invertRefPathCB(Widget, XtPointer, XtPointer);
234   void invertRefPath();
235 
236   enum CameraType {
237     PERSPECTIVE,
238     ORTHOGRAPHIC
239   };
240 
241     
242   enum State {
243     GENERAL,
244     BEAMLINE,
245     VIEWPOINT,
246     ANIMATION,
247     REVERSED_ANIMATION,
248     PAUSED_ANIMATION,
249     ROTATING
250   };
251 
252   // For storing the view point
253   struct viewPtData {
254     char* viewPtName;
255     int viewportMapping;
256     SbVec3f position;
257     SbRotation orientation;
258     float aspectRatio;
259     float nearDistance;
260     float farDistance;
261     float focalDistance;
262     CameraType camType;
263     float height;
264   };
265 
266    // FWJ removed unneeded assignment operator
267    struct sceneElement {
268       std::string name;
269       SoFullPath* path;
270       SbVec3f center;
271       float closestPointZCoord;
272    };
273 
274    struct elementForSorting {
275       float closestPointZCoord;
276       SbVec3f closestPoint;
277       float smallestDistance;
278       float distanceToBeamlineStart;
279       std::string name;
280 
281       G4bool operator<(elementForSorting const &other) const
282       {
283          if (closestPointZCoord < other.closestPointZCoord)
284             return true;
285          if (closestPointZCoord > other.closestPointZCoord)
286             return false;
287 
288          // otherwise closestPointZCoord == other.closestPointZCoord.
289          // Compare the distances from the center of the element to
290          // the start of the beamline.
291          if (distanceToBeamlineStart < other.distanceToBeamlineStart)
292             return true;
293          if (distanceToBeamlineStart > other.distanceToBeamlineStart)
294             return false;
295 
296          // In case both closestPointZCoord and smallestDistance are
297          // equal, we have two exactly overlapping elements, if so
298          // the order doesn't matter
299          return true;
300       }
301   };
302 
303   bool zcoordSetFlag;
304 
305   std::vector<sceneElement> sceneElements;
306   std::vector<viewPtData> viewPtList;
307   std::string fileName;
308   std::ifstream fileIn;
309   std::ofstream fileOut; 
310   int viewPtIdx;
311   int MAX_VP_IDX;
312   int MAX_VP_NAME;
313   
314   // For storing coordinate points of the reference particle
315   std::vector<SbVec3f> refParticleTrajectory;
316   // For displaying distance during anim and beamline modes
317   std::vector<float> refZPositions;
318 
319   int refParticleIdx;
320   int prevRefIdx;
321   float distance;
322   State currentState, prevState, beforePausing;
323   char* curViewPtName;
324   
325   int step;
326   SbVec3f prevPt;
327   SbVec3f prevParticleDir;
328   void* prevColorField;
329   
330   viewPtData camB4Animation;
331   bool returnToSaveVP;
332   bool returnToAnim;
333   SoCamera* myCam;
334   void setStartingPtForAnimation(); 
335   float left_right, up_down;    
336   SbVec3f rotAxis; // For 90 degree rotations
337   int rotCnt;  // # of steps rotation is split into
338 
339   static void getViewPtNameCB(Widget, XtPointer, XtPointer);
340   static void getViewPtNameCancelCB(Widget, XtPointer, XtPointer);
341   std::string viewPtAutoName();
342 
343   ////////////////////////ANIM_SPEED_INDICATOR///////////////////////
344   SoSearchAction * searcher;
345 
346   SoNode * superimposition;
347   SoCoordinate3 * sgeometry;
348   SoScale * sscale;
349   
350   SoTranslation * stranslation;
351   SoTranslation * curInfoTrans;
352   SoTranslation * mouseOverTransSolid;
353   SoTranslation * mouseOverTransMaterial;
354   SoTranslation * mouseOverTransLogName;
355   SoTranslation * mouseOverTransZPos;
356 
357   // Used for 2 similar purposes: 1. Displays z position during animation
358   //                              2. Displays name of the current viewpoint
359   SoText2 * curInfoText;
360   /* Need to use many different fields for mouseover
361    * because newlines are ignored when the scene is rendered */
362   SoText2 * mouseOverTextSolid;
363   SoText2 * mouseOverTextMaterial;
364   SoText2 * mouseOverTextLogName;
365   SoText2 * mouseOverTextZPos;
366    
367   SoFont * curInfoFont;
368   SoFont * mouseOverFontSolid;
369   SoFont * mouseOverFontMaterial;
370   SoFont * mouseOverFontLogName;
371   SoFont * mouseOverFontZPos;
372   SoSwitch * axisSwitch;
373   SoSwitch * animSpeedOutlineSwitch; 
374   SoSwitch * animSpeedSwitch;
375   SoSwitch * curInfoSwitch;
376     
377   SoNode * getSuperimpositionNode(SoNode *, const char * name);
378 
379   void superimpositionEvent(SoAction * action);
380   static void superimpositionCB(void * closure, SoAction * action);
381 
382   virtual void actualRedraw(void);
383   void updateSpeedIndicator(void);
384 
385   float maxSpeed; 
386   ////////////////////////ANIM_SPEED_INDICATOR///////////////////////
387 
388   // FWJ added for Ortho camera
389   float defaultHeight;
390   float defaultHeightAngle;
391   // FWJ add look-ahead for animation tracking on curves
392   G4int pathLookahead;
393   
394   // Used by G4 app during element rotations, stores previous view
395   SbVec3f upVector, offsetFromCenter, center;   
396   bool rotUpVec;
397 
398   SoSeparator* newSceneGraph;
399 
400 
401 };
402 #endif /* G4OPENINVENTORXTEXAMINERVIEWER_HH */
403