# SoDragger.h

    00001 #ifndef COIN_SODRAGGER_H
    00002 #define COIN_SODRAGGER_H
    00003
    00004 /**************************************************************************\
    00005  *
    00006  *  This file is part of the Coin 3D visualization library.
    00007  *  Copyright (C) 1998-2003 by Systems in Motion.  All rights reserved.
    00008  *
    00009  *  This library is free software; you can redistribute it and/or
    00010  *  modify it under the terms of the GNU General Public License
    00011  *  ("GPL") version 2 as published by the Free Software Foundation.
    00012  *  See the file LICENSE.GPL at the root directory of this source
    00013  *  distribution for additional information about the GNU GPL.
    00014  *
    00015  *  For using Coin with software that can not be combined with the GNU
    00016  *  GPL, and for taking advantage of the additional benefits of our
    00017  *  support services, please contact Systems in Motion about acquiring
    00018  *  a Coin Professional Edition License.
    00019  *
    00020  *  See <URL:http://www.coin3d.org> for  more information.
    00021  *
    00022  *  Systems in Motion, Teknobyen, Abels Gate 5, 7030 Trondheim, NORWAY.
    00023  *  <URL:http://www.sim.no>.
    00024  *
    00025 \**************************************************************************/
    00026
    00027 #include <Inventor/nodekits/SoInteractionKit.h>
    00028 #include <Inventor/fields/SoSFBool.h>
    00029 #include <Inventor/lists/SoCallbackList.h>
    00030 #include <Inventor/SbMatrix.h>
    00031 #include <Inventor/SbVec3f.h>
    00032 #include <Inventor/SbVec2s.h>
    00033 #include <Inventor/SbViewVolume.h>
    00034 #include <Inventor/SbViewportRegion.h>
    00035 #ifndef COIN_INTERNAL
    00036  // For Open Inventor compatibility.
    00037  #include <Inventor/nodes/SoScale.h>
    00038 #endif // COIN_INTERNAL
    00039
    00040
    00041 class SbRotation;
    00042 class SbVec2f;
    00043 class SbVec2s;
    00044 class SbViewVolume;
    00045 class SbViewportRegion;
    00046 class SoDragger;
    00047 class SoEvent;
    00048 class SoPickedPoint;
    00049
    00050 typedef void SoDraggerCB(void * data, SoDragger * dragger);
    00051
    00052
    00053 class COIN_DLL_API SoDragger : public SoInteractionKit {
    00054   typedef SoInteractionKit inherited;
    00055
    00056   SO_KIT_HEADER(SoDragger);
    00057
    00058   SO_KIT_CATALOG_ENTRY_HEADER(motionMatrix);
    00059
    00060 public:
    00061   SoSFBool isActive;
    00062
    00063   enum ProjectorFrontSetting { FRONT, BACK, USE_PICK };
    00064
    00065   // override these in case we decide to do some extra work later
    00066   virtual void callback(SoCallbackAction * action);
    00067   virtual void GLRender(SoGLRenderAction * action);
    00068   virtual void getMatrix(SoGetMatrixAction * action);
    00069   virtual void rayPick(SoRayPickAction * action);
    00070   virtual void search(SoSearchAction * action);
    00071   virtual void write(SoWriteAction * action);
    00072   virtual void getPrimitiveCount(SoGetPrimitiveCountAction * action);
    00073
    00074   void addStartCallback(SoDraggerCB * func, void * data = NULL);
    00075   void removeStartCallback(SoDraggerCB * func, void * data = NULL);
    00076   void addMotionCallback(SoDraggerCB * func, void * data = NULL);
    00077   void removeMotionCallback(SoDraggerCB * func, void * data = NULL);
    00078   void addFinishCallback(SoDraggerCB * func, void * data = NULL);
    00079   void removeFinishCallback(SoDraggerCB * func, void * data = NULL);
    00080   void addValueChangedCallback(SoDraggerCB * func, void * data = NULL);
    00081   void removeValueChangedCallback(SoDraggerCB * func, void * data = NULL);
    00082   void setMinGesture(int pixels);
    00083   int getMinGesture(void) const;
    00084   SbBool enableValueChangedCallbacks(SbBool newval);
    00085   const SbMatrix & getMotionMatrix(void);
    00086   void addOtherEventCallback(SoDraggerCB * func, void * data = NULL);
    00087   void removeOtherEventCallback(SoDraggerCB * func, void * data = NULL);
    00088   void registerChildDragger(SoDragger * child);
    00089   void unregisterChildDragger(SoDragger * child);
    00090   void registerChildDraggerMovingIndependently(SoDragger * child);
    00091   void unregisterChildDraggerMovingIndependently(SoDragger * child);
    00092   SbMatrix getLocalToWorldMatrix(void);
    00093   SbMatrix getWorldToLocalMatrix(void);
    00094   SbVec3f getLocalStartingPoint(void);
    00095   SbVec3f getWorldStartingPoint(void);
    00096   void getPartToLocalMatrix(const SbName & partname, SbMatrix & parttolocalmatrix, SbMatrix & localtopartmatrix);
    00097   void transformMatrixLocalToWorld(const SbMatrix & frommatrix, SbMatrix & tomatrix);
    00098   void transformMatrixWorldToLocal(const SbMatrix & frommatrix, SbMatrix & tomatrix);
    00099   void transformMatrixToLocalSpace(const SbMatrix & frommatrix, SbMatrix & tomatrix, const SbName & fromspacepartname);
    00100   void setMotionMatrix(const SbMatrix & newmatrix);
    00101   void valueChanged(void);
    00102   const SbMatrix & getStartMotionMatrix(void);
    00103   virtual void saveStartParameters(void);
    00104   const SoPath * getPickPath(void) const;
    00105   const SoEvent * getEvent(void) const;
    00106   SoPath * createPathToThis(void);
    00107   const SoPath * getSurrogatePartPickedOwner(void) const;
    00108   const SbName & getSurrogatePartPickedName(void) const;
    00109   const SoPath * getSurrogatePartPickedPath(void) const;
    00110   void setStartingPoint(const SoPickedPoint * newpoint);
    00111   void setStartingPoint(const SbVec3f & newpoint);
    00112   const SbViewVolume & getViewVolume(void);
    00113   void setViewVolume(const SbViewVolume & vol);
    00114   const SbViewportRegion & getViewportRegion(void);
    00115   void setViewportRegion(const SbViewportRegion & reg);
    00116   SoHandleEventAction * getHandleEventAction(void) const;
    00117   void setHandleEventAction(SoHandleEventAction * newAction);
    00118   void setTempPathToThis(const SoPath * somethingclose);
    00119   virtual void grabEventsSetup(void);
    00120   virtual void grabEventsCleanup(void);
    00121   void workFieldsIntoTransform(SbMatrix & mtx);
    00122   void setFrontOnProjector(ProjectorFrontSetting newval);
    00123   ProjectorFrontSetting getFrontOnProjector(void) const;
    00124
    00125   static void setMinScale(float newminscale);
    00126   static float getMinScale(void);
    00127   static void workValuesIntoTransform(SbMatrix & mtx, const SbVec3f * translationptr, const SbRotation * rotationptr, const SbVec3f * scalefactorptr, const SbRotation * scaleorientationptr, const SbVec3f * centerptr);
    00128   static void getTransformFast(SbMatrix & mtx, SbVec3f & translation, SbRotation & rotation, SbVec3f & scalefactor, SbRotation & scaleorientation, const SbVec3f & center);
    00129   static void getTransformFast(SbMatrix & mtx, SbVec3f & translation, SbRotation & rotation, SbVec3f & scalefactor, SbRotation & scaleorientation);
    00130   static SbMatrix appendTranslation(const SbMatrix & mtx, const SbVec3f & translation, const SbMatrix * conversion = NULL);
    00131   static SbMatrix appendScale(const SbMatrix & mtx, const SbVec3f & scale, const SbVec3f & scalecenter, const SbMatrix * conversion = NULL);
    00132   static SbMatrix appendRotation(const SbMatrix & mtx, const SbRotation & rot, const SbVec3f & rotcenter, const SbMatrix * conversion = NULL);
    00133   static void initClass(void);
    00134   static void initClasses(void);
    00135
    00136 protected:
    00137   SoDragger(void);
    00138   virtual ~SoDragger();
    00139
    00140   SbVec2f getNormalizedLocaterPosition(void);
    00141   SbVec2s getLocaterPosition(void);
    00142   SbVec2s getStartLocaterPosition(void) const;
    00143   void setStartLocaterPosition(SbVec2s p);
    00144   SbBool isAdequateConstraintMotion(void);
    00145   virtual SbBool shouldGrabBasedOnSurrogate(const SoPath * pickpath, const SoPath * surrogatepath);
    00146   void setCameraInfo(SoAction * action);
    00147   virtual void handleEvent(SoHandleEventAction * ha);
    00148   void transferMotion(SoDragger * child);
    00149   void setIgnoreInBbox(SbBool newval);
    00150   SbBool isIgnoreInBbox(void);
    00151   virtual void getBoundingBox(SoGetBoundingBoxAction * action);
    00152   void setActiveChildDragger(SoDragger * newchilddragger);
    00153   SoDragger * getActiveChildDragger(void) const;
    00154   virtual void setDefaultOnNonWritingFields(void);
    00155
    00156   static void childTransferMotionAndValueChangedCB(void *, SoDragger *);
    00157   static void childValueChangedCB(void *, SoDragger *);
    00158   static void childStartCB(void *, SoDragger *);
    00159   static void childMotionCB(void *, SoDragger *);
    00160   static void childFinishCB(void *, SoDragger *);
    00161   static void childOtherEventCB(void *, SoDragger *);
    00162
    00163   // This method is not present in Open Inventor. It was moved from
    00164   // being a private method to a protected method in Coin to make it
    00165   // possible to construct draggers which can handle Motion3 events.
    00166   void updateDraggerCache(const SoPath * path);
    00167
    00168 private:
    00169   void updateElements(class SoState * state);
    00170   SbBool isPicked(SoPath * path);
    00171   void eventHandled(const SoEvent * event, SoHandleEventAction * action);
    00172   static float minscale;
    00173
    00174   class SoDraggerP * pimpl;
    00175 };
    00176
    00177 #endif // !COIN_SODRAGGER_H