MeVisLabToolboxReference
MeVisLab/Standard/Sources/Inventor/SoView2D/SoView2DExtension.h
Go to the documentation of this file.
00001 #ifndef __SoView2DExtension_H
00002 #define __SoView2DExtension_H
00003 //----------------------------------------------------------------------------------
00004 // **InsertLicense** code
00005 //----------------------------------------------------------------------------------
00008 
00014 //----------------------------------------------------------------------------------
00015 
00016 #ifndef __SoView2DSystem_H
00017 #include "SoView2DSystem.h"
00018 #endif
00019 
00020 #include "XVEnterScope.h"
00021 #include <Inventor/nodes/SoNode.h>
00022 #include <Inventor/nodes/SoSubNode.h>
00023 #include <Inventor/fields/SoSFFloat.h>
00024 #include <Inventor/fields/SoSFBool.h>
00025 #include <Inventor/fields/SoSFTrigger.h>
00026 #include <Inventor/fields/SoSFEnum.h>
00027 #include <Inventor/fields/SoSFColor.h>
00028 #include <Inventor/sensors/SoNodeSensor.h>
00029 #include <Inventor/nodes/SoGroup.h>
00030 #include <Inventor/events/SoEvent.h>
00031 #include <Inventor/events/SoMouseButtonEvent.h>
00032 #include <Inventor/events/SoSpaceballButtonEvent.h>
00033 #include <Inventor/events/SoKeyboardEvent.h>
00034 #include <Inventor/events/SoLocation2Event.h>
00035 #include <Inventor/events/SoMotion3Event.h>
00036 #include "XVLeaveScope.h"
00037 
00038 #include <SoInteractionProviderNode.h>
00039 
00040 class SoSFMLImage;
00041 
00042 
00043 #ifndef TRISTATE
00044 #define TRISTATE
00045 
00046 typedef enum { IGNORED, PRESSED, RELEASED } tristateType;
00047 
00049 
00059 #define TEST_STATE(state,flag) (((state)==IGNORED)?TRUE:(((state)==PRESSED)==((flag)!=0)))
00060 
00061 #endif
00062 
00063 //--------- disable VC++ warnings---------
00064 #ifdef WIN32
00065 #pragma warning (disable : 4355)
00066 #pragma warning (disable : 4275)
00067 #pragma warning (disable : 4251)
00068 #pragma warning (disable : 4138)
00069 #pragma warning (disable : 4800)
00070 #endif
00071 
00072 class View2DSliceList;
00073 class View2DSlice;
00074 class SoView2D;
00075 
00078 typedef enum _View2DEventPhase {
00079     EVENT_START,  
00080     EVENT_MOTION, 
00081     EVENT_RELEASE,
00082     EVENT_KEY_PRESSED, 
00083     EVENT_KEY_RELEASED,
00084     EVENT_ANY, 
00085     EVENT_MOUSEWHEEL, 
00086     EVENT_MOUSEOVER_UPDATE 
00087 } View2DEventPhase;
00088 
00089 //==============================================================
00091 //==============================================================
00092 class View2DEvent {
00093 public:
00095   View2DEvent();
00096   View2DEvent(bool sh,     bool ct, bool al,
00097     bool pr,     bool mo, bool re,
00098     bool b1,     bool b2, bool b3,
00099     int   dpx,    int dpy,
00100     int   button,
00101     bool isKP,   bool isKR,
00102     bool iVK,    int kk,
00103     bool iVSP,   float spx, float spy, float spz,
00104     long  secs,   long usecs, const SoEvent* event);
00105 
00106   void setValues(bool sh,     bool ct, bool al,
00107     bool pr,     bool mo, bool re,
00108     bool b1,     bool b2, bool b3,
00109     int   dpx,    int dpy,
00110     int   button,
00111     bool isKP,   bool isKR,
00112     bool iVK,    int kk,
00113     bool iVSP,   float spx, float spy, float spz,
00114     long  secs,   long usecs, const SoEvent* event);
00115 
00117   void print();
00118 
00120   bool checkDoubleClick(View2DEvent& ec);
00121 
00123   bool sliceHit() { return isValidSlicePos; }
00124 
00126 
00128   bool shift, ctrl, alt;
00129 
00131   bool press;
00133   bool motion;
00135   bool release;
00137   bool mouseOverUpdate;
00138 
00140   bool button1, button2, button3;
00141 
00143   int   button;
00144 
00146   bool isKeyPressed;
00148   bool isKeyReleased;
00150   bool isValidKey;
00152   int   keyCode;
00153 
00155   int   devicePosX;
00157   int   devicePosY;
00158 
00160   bool isValidSlicePos;
00162   float slicePosX;
00163   float slicePosY;
00164   float slicePosZ;
00165 
00167   long  second;
00168   long  usecond;
00169 
00171   const SoEvent* soevent;
00172 
00174   bool  handled;
00176   bool  doubleclick;
00177 };
00178 
00180 #define EventContainer View2DEvent
00181 #define EventPhase View2DEventPhase
00182 
00183 //=============================================================
00188 //=============================================================
00189 class SOVIEW2D_API SoView2DExtension : public SoInteractionProviderNode 
00190 {
00191 
00192   SO_NODE_HEADER(SoView2DExtension);
00193 
00194 public:
00196   SoSFColor color;
00198   SoSFBool  drawingOn;
00200   SoSFBool  editingOn;
00201 
00203   SoSFBool maskValid;
00204   
00206   SoSFFloat selectionTolerance;
00207 
00210   SoSFBool wantsAllEvents;
00212   SoSFBool wantsKeyEvents;
00214   SoSFBool wantsMouseWheelEvents;
00215 
00217   SoSFBool setEventHandled;
00219   SoSFBool ignoreHandledEvents;
00220 
00221 
00223   SoSFEnum button1;
00225   SoSFEnum button2;
00227   SoSFEnum button3;
00229   SoSFEnum shift;
00231   SoSFEnum control;
00233   SoSFEnum alt;
00234 
00236   SoSFBool  needsValidVoxel;
00237 
00239   SoSFBool  renderOnSlab;
00240 
00242   SoSFBool    createNewMode;
00243   SoSFTrigger createNewModeRequest;
00244 
00246   SoSFBool clipToSlice;
00247 
00250   SoSFEnum cursorShape;
00251 
00253 
00255   SoSFBool  fixZOn;
00256 
00258   static void   initClass();
00259 
00261   SoView2DExtension();
00262 
00264   void init();
00265 
00267   virtual void updateValues();
00268 
00270 
00274   virtual void   draw(View2DSliceList *slicelist,View2DSlice* slice, int sliceZ);
00275 
00277 
00283   virtual bool  evalEvent(SoView2D* view2d, View2DSliceList* slicelist,
00284     View2DEvent* ec, View2DEventPhase phase);
00285 
00288   virtual void   startDrawing(View2DSliceList * /*slicelist*/){};
00289 
00291   virtual void   endDrawing(View2DSliceList * /*slicelist*/){};
00292 
00293 
00295   View2DEvent* getEvent();
00296 
00298   float  getSelectDist();
00299 
00302   bool isPointInsideDeviceRect(float pointX, float pointY, float centerX, float centerY, float hitRectangleSize=0.0);
00303 
00305   virtual void   drawMiniRect(float x, float y);
00307   virtual void   drawMiniRect(float xp, float yp, float ext);
00309   virtual void   drawFilledMiniRect(float xp, float yp, float ext);
00311   virtual void   drawMiniCircle(float xp, float yp, float ext);
00312 
00314   void drawVoxelBorder(View2DSlice* slice, float vx,float vy,float vz);
00315 
00317   int getX();
00318 
00320   int getY();
00321 
00323   virtual bool  isDrawingOn()        { return drawingOn.getValue(); };
00325   virtual bool  isEditingOn()        { return editingOn.getValue(); };
00327   virtual bool  isFixZOn()           { return fixZOn.getValue(); };
00329   virtual bool  isClipToSlice()      { return clipToSlice.getValue(); };
00330 
00332   static  void fieldChangedCB(void *data, SoSensor *sensor);
00334   virtual void fieldChanged(SoSensor* sensor);
00335 
00337   bool isCreateNewMode();
00339   void setCreateNewMode(bool flag);
00340 
00342   bool isCreateNewModeRequest();
00344   void setCreateNewModeRequest(bool flag);
00345 
00347   virtual bool isActive();
00348 
00350   virtual void deleteSelectedObject();
00351 
00353   virtual void getStatusString(SbString& status);
00354 
00356 
00361   static void    getAxisOrientation(int axis, SbMatrix &matrix, char &negativeResult, char &positiveResult);
00362 
00364   static float pointToLineDistance(SbVec3f point, SbVec3f line1, SbVec3f line2);
00366   static float pointToLineDistance(SbVec2f point, SbVec2f line1, SbVec2f line2);
00367 
00369   typedef enum { ZERO, NEGATIVE, POSITIVE } Sign;
00370 
00372   static Sign edgeIntersectWithPlane(const SbVec3f &v1,
00373     const SbVec3f &v2,
00374     const SbPlane &plane,
00375     SbVec3f &intersect);
00376 
00378 
00383   virtual bool  evaluateEvent(SoView2D *view2d, View2DEvent* ec);
00384 
00386   static bool isImageParallel (SoSFMLImage* image, View2DSliceList *dsl);
00387 
00389   virtual bool ignoreEvent(View2DEvent* ec);
00390 
00392   bool wantsMouseOverUpdates() const { return _wantsMouseOverUpdateEvents; }
00393 
00395   virtual void consumeEvent(View2DEvent* ec, bool handled = TRUE);
00396 
00399   int getSelectedModifierMask();
00400   int getSelectedIgnoreMask();
00401 
00403   SoPointingAction::Trigger getPointingActionTriggerFromFields();
00404 
00408   virtual bool implementsManagedInteractionAndClassicEventHandling() const { return false; }
00409 
00410 protected:
00412   virtual void     GLRender(SoGLRenderAction *action);
00413   virtual void     callback(SoCallbackAction *action);
00414   virtual void     handleEvent(SoHandleEventAction *action);
00415   virtual void     getMatrix(SoGetMatrixAction *action);
00416   virtual void     getBoundingBox(SoGetBoundingBoxAction *action);
00417   virtual void     pick(SoPickAction *action);
00418   virtual void     doAction(SoAction *action);
00419 #ifndef SGIOIV
00420   virtual void     getPrimitiveCount(SoGetPrimitiveCountAction * action);
00421 #endif
00422 
00423 
00425   SoNodeSensor* _nodeSensor;
00426 
00428   float _rgbColor[4];
00429 
00431   bool  _wantsMouseOverUpdateEvents;
00432 
00434   virtual  ~SoView2DExtension();
00435 
00436 private:
00437 
00439   bool      _active;
00441   SoView2D* _activeView2D;
00442 
00444   View2DEvent *_ec;
00445 
00447   bool _createNewModeRequest;
00448 };
00449 
00450 #endif