00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef HookEventProcState_H
00030 #define HookEventProcState_H 1
00031 #include "G4VStateDependent.hh"
00032
00033 class G4OpenInventorXtExaminerViewer;
00034 class HookEventProcState : public G4VStateDependent
00035 {
00036 private:
00037 G4OpenInventorXtExaminerViewer *viewer;
00038 public:
00039 HookEventProcState(G4OpenInventorXtExaminerViewer*);
00040 ~HookEventProcState();
00041
00042 virtual G4bool Notify(G4ApplicationState requiredState);
00043 };
00044 #endif
00045
00046
00047 #ifndef G4OPENINVENTORXTEXAMINERVIEWER_HH
00048 #define G4OPENINVENTORXTEXAMINERVIEWER_HH
00049
00050 #include <map>
00051 #include <vector>
00052 #include <fstream>
00053 #include <Inventor/SbLinear.h>
00054 #include <Inventor/nodes/SoLineSet.h>
00055 #include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
00056 #include <Inventor/events/SoKeyboardEvent.h>
00057
00058 class SoCoordinate3;
00059 class SoFont;
00060 class SoText2;
00061 class SoPointSet;
00062
00063 class G4OpenInventorXtExaminerViewer : public SoXtExaminerViewer {
00064 private:
00065 Widget prevViewPtButton, nextViewPtButton;
00066 Widget menuBar, fileMenu, openFileDialog, newFileDialog,
00067 loadRefCoordsDialog, saveRefCoordsDialog,
00068 loadSceneGraphDialog, saveSceneGraphDialog,
00069 viewPtSelection, listsDialog, myShellDialog, myViewPtList, myElementList;
00070
00071 static G4OpenInventorXtExaminerViewer *viewer;
00072 void (*escapeCallback)(void *);
00073 void * examinerObject;
00074 SbBool lshiftdown, rshiftdown, lctrldown, rctrldown;
00075
00076 public:
00077
00078
00079 G4OpenInventorXtExaminerViewer(Widget parent = NULL,
00080 const char *name = NULL,
00081 SbBool embed = TRUE,
00082 SoXtFullViewer::BuildFlag flag = BUILD_ALL,
00083 SoXtViewer::Type type = BROWSER);
00084
00085 ~G4OpenInventorXtExaminerViewer();
00086 template <class T> void parseString(T &t, const std::string &s, bool &error);
00087 Widget addMenu(std::string name);
00088 void addButton(Widget menu, std::string name, XtCallbackProc);
00089 Widget getMenuBar() { return menuBar; }
00090 Widget getMenu() { return fileMenu; }
00091 void warningMsgDialog(std::string, String, XtCallbackProc);
00092 bool warningFlag;
00093
00094 std::string saveScenegraphFileName;
00095 Widget saveScenegraphWidget;
00096 std::string saveRefCoordsFileName;
00097 Widget saveRefCoordsWidget;
00098
00099 Widget createScale(Widget, char *, int, float);
00100 void addEscapeCallback(void (*cb)(void *), void *);
00101 bool abbrOutputFlag;
00102 bool pickRefPathFlag;
00103 bool viewingBeforePickRef;
00104
00105 protected:
00106
00107 G4OpenInventorXtExaminerViewer(Widget parent,
00108 const char *name,
00109 SbBool embed,
00110 SoXtFullViewer::BuildFlag flag,
00111 SoXtViewer::Type type,
00112 SbBool build);
00113
00114
00115 Widget buildWidget(Widget parent);
00116
00117 virtual void createViewerButtons (Widget parent, SbPList * buttonlist);
00118
00119 virtual SbBool processSoEvent(const SoEvent * const event);
00120 void moveCamera(float dist = 0, bool lookdown = false);
00121 std::string curEltName;
00122 SbVec3f camUpVec;
00123 SbVec3f camDir;
00124 void rotateCamera();
00125 void updateViewParams(SoKeyboardEvent::Key);
00126 bool loadViewPts();
00127 virtual void afterRealizeHook();
00128
00129 private:
00130
00131 void constructor(const SbBool build);
00132
00133 static G4OpenInventorXtExaminerViewer *getObject();
00134
00135 HookEventProcState *hookBeamOn;
00136 friend class HookEventProcState;
00137 bool newEvents;
00138 static void sceneChangeCB(void *, SoSensor *);
00139
00140 void setViewPt();
00141 void writeViewPtIdx();
00142 void cleanUpAfterPrevFile();
00143
00144 void popUpFileSelDialog(Widget&, std::string, std::string, XtCallbackProc);
00145 static void cancelFileSelDialogCB(Widget, XtPointer, XtPointer);
00146 static void openViewPtFileCB(Widget, XtPointer, XtPointer);
00147 static void viewPtFileSelectedCB(Widget, XtPointer, XtPointer);
00148 static void newViewPtFileCB(Widget, XtPointer, XtPointer);
00149 static void createNewVPFileCB(Widget, XtPointer, XtPointer);
00150 static void overwriteFileCB(Widget, XtPointer, XtPointer);
00151 static void loadRefCoordsDialogCB(Widget, XtPointer, XtPointer);
00152 static void loadRefCoordsCB(Widget, XtPointer, XtPointer);
00153 static void saveRefCoordsDialogCB(Widget, XtPointer, XtPointer);
00154 static void saveRefCoordsCB(Widget, XtPointer, XtPointer);
00155 static void saveRefCoordsOverWriteCB(Widget, XtPointer, XtPointer);
00156 static void loadSceneGraphDialogCB(Widget, XtPointer, XtPointer);
00157 static void loadSceneGraphCB(Widget, XtPointer, XtPointer);
00158 static void saveSceneGraphDialogCB(Widget, XtPointer, XtPointer);
00159 static void saveSceneGraphCB(Widget, XtPointer, XtPointer);
00160 static void saveSceneGraphOverWriteCB(Widget, XtPointer, XtPointer);
00161 static void mouseoverCB(void *aThis, SoEventCallback *eventCB);
00162 static void pickingCB(void *aThis, SoEventCallback *eventCB);
00163
00164
00165
00166 void addViewPoints();
00167 static void closeListsDialogCB(Widget, XtPointer, XtPointer);
00168 static void loadBookmarkCB(Widget, XtPointer, XtPointer);
00169 static void renameBookmarkCB(Widget, XtPointer, XtPointer);
00170 void renameViewPt(char *vpName);
00171 static void sortBookmarksCB(Widget, XtPointer, XtPointer);
00172 void sortViewPts(std::vector<std::string>);
00173 static void deleteBookmarkCB(Widget, XtPointer, XtPointer);
00174 static void deleteViewPtCB(Widget, XtPointer, XtPointer);
00175 void deleteViewPt(char *vpName = NULL);
00176
00177
00178 static void animateRefParticleCB(Widget, XtPointer, XtPointer);
00179 static void animateSensorCB(void *, SoSensor *);
00180 static void animateSensorRotationCB(void *, SoSensor *);
00181 void animateRefParticle();
00182 void saveCurCamera();
00183 void restoreCamera();
00184 double animateBtwPtsPeriod, speedStep;
00185 void incSpeed();
00186 void decSpeed();
00187
00188 SoTimerSensor *animateSensor;
00189 SoTimerSensor *animateSensorRotation;
00190 SoNodeSensor *sceneChangeSensor;
00191 SbVec3f camStartPos, camEndPos;
00192 SbRotation camStartOrient, camEndOrient;
00193
00194 static void prevViewPtCB(Widget, XtPointer, XtPointer);
00195 static void nextViewPtCB(Widget, XtPointer, XtPointer);
00196 static void saveViewPtCB(Widget, XtPointer, XtPointer);
00197 static void abbrOutputCB(Widget, XtPointer, XtPointer);
00198 static void pickRefPathCB(Widget, XtPointer, XtPointer);
00199 static void constructListsDialog(Widget, XtPointer, XtPointer);
00200 void saveViewPt(char *name);
00201
00202
00203 static void lookAtSceneElementCB(Widget, XtPointer, XtPointer);
00204 static void cancelSceneElementSelectionCB(Widget, XtPointer, XtPointer);
00205
00206 void setReferencePath(SoLineSet*, SoCoordinate3*, bool append = false);
00207 void setReferencePathZPos();
00208 void findAndSetRefPath();
00209 SoCoordinate3 *getCoordsNode(SoFullPath *path);
00210 void getSceneElements();
00211 float sqrlen(const SbVec3f&);
00212 void distanceToTrajectory(const SbVec3f&, float&, SbVec3f&, int&);
00213 void sortElements();
00214 void createElementsList(Widget);
00215 static void closeMainWindowCB(Widget, XtPointer, XtPointer);
00216 void evenOutRefParticlePts();
00217
00218 static void gotoRefPathStartCB(Widget, XtPointer, XtPointer);
00219 void gotoRefPathStart();
00220 static void invertRefPathCB(Widget, XtPointer, XtPointer);
00221 void invertRefPath();
00222
00223 enum CameraType {
00224 PERSPECTIVE,
00225 ORTHOGRAPHIC
00226 };
00227
00228
00229 enum State {
00230 GENERAL,
00231 BEAMLINE,
00232 VIEWPOINT,
00233 ANIMATION,
00234 REVERSED_ANIMATION,
00235 PAUSED_ANIMATION,
00236 ROTATING
00237 };
00238
00239
00240 struct viewPtData {
00241 char* viewPtName;
00242 int viewportMapping;
00243 SbVec3f position;
00244 SbRotation orientation;
00245 float aspectRatio;
00246 float nearDistance;
00247 float farDistance;
00248 float focalDistance;
00249 CameraType camType;
00250 float height;
00251 };
00252
00253 struct sceneElement {
00254 std::string name;
00255 SoFullPath * path;
00256 SbVec3f center;
00257 float closestPointZCoord;
00258
00259 sceneElement operator=(sceneElement const &rhs) const {
00260 sceneElement el;
00261 el.name = rhs.name;
00262 el.path = rhs.path;
00263 el.center = rhs.center;
00264 el.closestPointZCoord = rhs.closestPointZCoord;
00265
00266 return el;
00267 }
00268 };
00269
00270 struct elementForSorting {
00271 float closestPointZCoord;
00272 SbVec3f closestPoint;
00273 float smallestDistance;
00274 float distanceToBeamlineStart;
00275 std::string name;
00276
00277 bool operator<(elementForSorting const &other) const
00278 {
00279 if (closestPointZCoord < other.closestPointZCoord)
00280 return true;
00281 if (closestPointZCoord > other.closestPointZCoord)
00282 return false;
00283
00284
00285
00286
00287 if (distanceToBeamlineStart < other.distanceToBeamlineStart)
00288 return true;
00289 if (distanceToBeamlineStart > other.distanceToBeamlineStart)
00290 return false;
00291
00292
00293
00294
00295 return true;
00296 }
00297 };
00298
00299 bool zcoordSetFlag;
00300
00301 std::vector<sceneElement> sceneElements;
00302 std::vector<viewPtData> viewPtList;
00303 std::string fileName;
00304 std::ifstream fileIn;
00305 std::ofstream fileOut;
00306 int viewPtIdx;
00307 int MAX_VP_IDX;
00308 int MAX_VP_NAME;
00309
00310
00311 std::vector<SbVec3f> refParticleTrajectory;
00312
00313 std::vector<float> refZPositions;
00314 int refParticleIdx;
00315 int prevRefIdx;
00316 float distance;
00317 State currentState, prevState, beforePausing;
00318 char *curViewPtName;
00319
00320 int step;
00321 SbVec3f prevPt;
00322 SbVec3f prevParticleDir;
00323 void * prevColorField;
00324
00325 viewPtData camB4Animation;
00326 bool returnToSaveVP;
00327 bool returnToAnim;
00328 SoCamera *myCam;
00329 void setStartingPtForAnimation();
00330 float left_right, up_down;
00331 SbVec3f rotAxis;
00332 int rotCnt;
00333
00334 static void getViewPtNameCB(Widget, XtPointer, XtPointer);
00335 std::string viewPtAutoName();
00336
00338 SoSearchAction * searcher;
00339
00340 SoNode * superimposition;
00341 SoCoordinate3 * sgeometry;
00342 SoScale * sscale;
00343
00344 SoTranslation * stranslation;
00345 SoTranslation * curInfoTrans;
00346 SoTranslation * mouseOverTransSolid;
00347 SoTranslation * mouseOverTransMaterial;
00348 SoTranslation * mouseOverTransLogName;
00349 SoTranslation * mouseOverTransZPos;
00350
00351
00352
00353 SoText2 * curInfoText;
00354
00355
00356 SoText2 * mouseOverTextSolid;
00357 SoText2 * mouseOverTextMaterial;
00358 SoText2 * mouseOverTextLogName;
00359 SoText2 * mouseOverTextZPos;
00360
00361 SoFont * curInfoFont;
00362 SoFont * mouseOverFontSolid;
00363 SoFont * mouseOverFontMaterial;
00364 SoFont * mouseOverFontLogName;
00365 SoFont * mouseOverFontZPos;
00366 SoSwitch * axisSwitch;
00367 SoSwitch * animSpeedOutlineSwitch;
00368 SoSwitch * animSpeedSwitch;
00369 SoSwitch * curInfoSwitch;
00370
00371 SoNode * getSuperimpositionNode(SoNode *, const char * name);
00372
00373 void superimpositionEvent(SoAction * action);
00374 static void superimpositionCB(void * closure, SoAction * action);
00375
00376 virtual void actualRedraw(void);
00377 void updateSpeedIndicator(void);
00378
00379 float maxSpeed;
00381
00382
00383 float defaultHeight;
00384 float defaultHeightAngle;
00385
00386
00387 SbVec3f upVector, offsetFromCenter, center;
00388 bool rotUpVec;
00389
00390 SoSeparator * newSceneGraph;
00391
00392
00393 };
00394 #endif