# SoTransformerDragger.h

    00001 #ifndef COIN_SOTRANSFORMERDRAGGER_H
    00002 #define COIN_SOTRANSFORMERDRAGGER_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/draggers/SoDragger.h>
    00028 #include <Inventor/fields/SoSFRotation.h>
    00029 #include <Inventor/fields/SoSFVec3f.h>
    00030 #include <Inventor/fields/SoSFFloat.h>
    00031 #include <Inventor/lists/SoNodeList.h>
    00032
    00033 class SoSensor;
    00034 class SoFieldSensor;
    00035
    00036
    00037 class COIN_DLL_API SoTransformerDragger : public SoDragger {
    00038   typedef SoDragger inherited;
    00039
    00040   SO_KIT_HEADER(SoTransformerDragger);
    00041
    00042   SO_KIT_CATALOG_ENTRY_HEADER(axisFeedbackLocation);
    00043   SO_KIT_CATALOG_ENTRY_HEADER(axisFeedbackSep);
    00044   SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackAntiSquish);
    00045   SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackSep);
    00046   SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackTransform);
    00047   SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackTransformSwitch);
    00048   SO_KIT_CATALOG_ENTRY_HEADER(negXRoundWallFeedback);
    00049   SO_KIT_CATALOG_ENTRY_HEADER(negXWallFeedback);
    00050   SO_KIT_CATALOG_ENTRY_HEADER(negXWallFeedbackSwitch);
    00051   SO_KIT_CATALOG_ENTRY_HEADER(negYRoundWallFeedback);
    00052   SO_KIT_CATALOG_ENTRY_HEADER(negYWallFeedback);
    00053   SO_KIT_CATALOG_ENTRY_HEADER(negYWallFeedbackSwitch);
    00054   SO_KIT_CATALOG_ENTRY_HEADER(negZRoundWallFeedback);
    00055   SO_KIT_CATALOG_ENTRY_HEADER(negZWallFeedback);
    00056   SO_KIT_CATALOG_ENTRY_HEADER(negZWallFeedbackSwitch);
    00057   SO_KIT_CATALOG_ENTRY_HEADER(overallStyle);
    00058   SO_KIT_CATALOG_ENTRY_HEADER(posXRoundWallFeedback);
    00059   SO_KIT_CATALOG_ENTRY_HEADER(posXWallFeedback);
    00060   SO_KIT_CATALOG_ENTRY_HEADER(posXWallFeedbackSwitch);
    00061   SO_KIT_CATALOG_ENTRY_HEADER(posYRoundWallFeedback);
    00062   SO_KIT_CATALOG_ENTRY_HEADER(posYWallFeedback);
    00063   SO_KIT_CATALOG_ENTRY_HEADER(posYWallFeedbackSwitch);
    00064   SO_KIT_CATALOG_ENTRY_HEADER(posZRoundWallFeedback);
    00065   SO_KIT_CATALOG_ENTRY_HEADER(posZWallFeedback);
    00066   SO_KIT_CATALOG_ENTRY_HEADER(posZWallFeedbackSwitch);
    00067   SO_KIT_CATALOG_ENTRY_HEADER(radialFeedback);
    00068   SO_KIT_CATALOG_ENTRY_HEADER(radialFeedbackSwitch);
    00069   SO_KIT_CATALOG_ENTRY_HEADER(rotator1);
    00070   SO_KIT_CATALOG_ENTRY_HEADER(rotator1Active);
    00071   SO_KIT_CATALOG_ENTRY_HEADER(rotator1LocateGroup);
    00072   SO_KIT_CATALOG_ENTRY_HEADER(rotator1Switch);
    00073   SO_KIT_CATALOG_ENTRY_HEADER(rotator2);
    00074   SO_KIT_CATALOG_ENTRY_HEADER(rotator2Active);
    00075   SO_KIT_CATALOG_ENTRY_HEADER(rotator2LocateGroup);
    00076   SO_KIT_CATALOG_ENTRY_HEADER(rotator2Switch);
    00077   SO_KIT_CATALOG_ENTRY_HEADER(rotator3);
    00078   SO_KIT_CATALOG_ENTRY_HEADER(rotator3Active);
    00079   SO_KIT_CATALOG_ENTRY_HEADER(rotator3LocateGroup);
    00080   SO_KIT_CATALOG_ENTRY_HEADER(rotator3Switch);
    00081   SO_KIT_CATALOG_ENTRY_HEADER(rotator4);
    00082   SO_KIT_CATALOG_ENTRY_HEADER(rotator4Active);
    00083   SO_KIT_CATALOG_ENTRY_HEADER(rotator4LocateGroup);
    00084   SO_KIT_CATALOG_ENTRY_HEADER(rotator4Switch);
    00085   SO_KIT_CATALOG_ENTRY_HEADER(rotator5);
    00086   SO_KIT_CATALOG_ENTRY_HEADER(rotator5Active);
    00087   SO_KIT_CATALOG_ENTRY_HEADER(rotator5LocateGroup);
    00088   SO_KIT_CATALOG_ENTRY_HEADER(rotator5Switch);
    00089   SO_KIT_CATALOG_ENTRY_HEADER(rotator6);
    00090   SO_KIT_CATALOG_ENTRY_HEADER(rotator6Active);
    00091   SO_KIT_CATALOG_ENTRY_HEADER(rotator6LocateGroup);
    00092   SO_KIT_CATALOG_ENTRY_HEADER(rotator6Switch);
    00093   SO_KIT_CATALOG_ENTRY_HEADER(rotatorSep);
    00094   SO_KIT_CATALOG_ENTRY_HEADER(scale1);
    00095   SO_KIT_CATALOG_ENTRY_HEADER(scale1Active);
    00096   SO_KIT_CATALOG_ENTRY_HEADER(scale1LocateGroup);
    00097   SO_KIT_CATALOG_ENTRY_HEADER(scale1Switch);
    00098   SO_KIT_CATALOG_ENTRY_HEADER(scale2);
    00099   SO_KIT_CATALOG_ENTRY_HEADER(scale2Active);
    00100   SO_KIT_CATALOG_ENTRY_HEADER(scale2LocateGroup);
    00101   SO_KIT_CATALOG_ENTRY_HEADER(scale2Switch);
    00102   SO_KIT_CATALOG_ENTRY_HEADER(scale3);
    00103   SO_KIT_CATALOG_ENTRY_HEADER(scale3Active);
    00104   SO_KIT_CATALOG_ENTRY_HEADER(scale3LocateGroup);
    00105   SO_KIT_CATALOG_ENTRY_HEADER(scale3Switch);
    00106   SO_KIT_CATALOG_ENTRY_HEADER(scale4);
    00107   SO_KIT_CATALOG_ENTRY_HEADER(scale4Active);
    00108   SO_KIT_CATALOG_ENTRY_HEADER(scale4LocateGroup);
    00109   SO_KIT_CATALOG_ENTRY_HEADER(scale4Switch);
    00110   SO_KIT_CATALOG_ENTRY_HEADER(scale5);
    00111   SO_KIT_CATALOG_ENTRY_HEADER(scale5Active);
    00112   SO_KIT_CATALOG_ENTRY_HEADER(scale5LocateGroup);
    00113   SO_KIT_CATALOG_ENTRY_HEADER(scale5Switch);
    00114   SO_KIT_CATALOG_ENTRY_HEADER(scale6);
    00115   SO_KIT_CATALOG_ENTRY_HEADER(scale6Active);
    00116   SO_KIT_CATALOG_ENTRY_HEADER(scale6LocateGroup);
    00117   SO_KIT_CATALOG_ENTRY_HEADER(scale6Switch);
    00118   SO_KIT_CATALOG_ENTRY_HEADER(scale7);
    00119   SO_KIT_CATALOG_ENTRY_HEADER(scale7Active);
    00120   SO_KIT_CATALOG_ENTRY_HEADER(scale7LocateGroup);
    00121   SO_KIT_CATALOG_ENTRY_HEADER(scale7Switch);
    00122   SO_KIT_CATALOG_ENTRY_HEADER(scale8);
    00123   SO_KIT_CATALOG_ENTRY_HEADER(scale8Active);
    00124   SO_KIT_CATALOG_ENTRY_HEADER(scale8LocateGroup);
    00125   SO_KIT_CATALOG_ENTRY_HEADER(scale8Switch);
    00126   SO_KIT_CATALOG_ENTRY_HEADER(scaleBoxFeedback);
    00127   SO_KIT_CATALOG_ENTRY_HEADER(scaleBoxFeedbackSwitch);
    00128   SO_KIT_CATALOG_ENTRY_HEADER(scaleSep);
    00129   SO_KIT_CATALOG_ENTRY_HEADER(surroundScale);
    00130   SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedback);
    00131   SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedbackRotation);
    00132   SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedbackSep);
    00133   SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedbackSwitch);
    00134   SO_KIT_CATALOG_ENTRY_HEADER(translator1);
    00135   SO_KIT_CATALOG_ENTRY_HEADER(translator1Active);
    00136   SO_KIT_CATALOG_ENTRY_HEADER(translator1LocateGroup);
    00137   SO_KIT_CATALOG_ENTRY_HEADER(translator1Switch);
    00138   SO_KIT_CATALOG_ENTRY_HEADER(translator2);
    00139   SO_KIT_CATALOG_ENTRY_HEADER(translator2Active);
    00140   SO_KIT_CATALOG_ENTRY_HEADER(translator2LocateGroup);
    00141   SO_KIT_CATALOG_ENTRY_HEADER(translator2Switch);
    00142   SO_KIT_CATALOG_ENTRY_HEADER(translator3);
    00143   SO_KIT_CATALOG_ENTRY_HEADER(translator3Active);
    00144   SO_KIT_CATALOG_ENTRY_HEADER(translator3LocateGroup);
    00145   SO_KIT_CATALOG_ENTRY_HEADER(translator3Switch);
    00146   SO_KIT_CATALOG_ENTRY_HEADER(translator4);
    00147   SO_KIT_CATALOG_ENTRY_HEADER(translator4Active);
    00148   SO_KIT_CATALOG_ENTRY_HEADER(translator4LocateGroup);
    00149   SO_KIT_CATALOG_ENTRY_HEADER(translator4Switch);
    00150   SO_KIT_CATALOG_ENTRY_HEADER(translator5);
    00151   SO_KIT_CATALOG_ENTRY_HEADER(translator5Active);
    00152   SO_KIT_CATALOG_ENTRY_HEADER(translator5LocateGroup);
    00153   SO_KIT_CATALOG_ENTRY_HEADER(translator5Switch);
    00154   SO_KIT_CATALOG_ENTRY_HEADER(translator6);
    00155   SO_KIT_CATALOG_ENTRY_HEADER(translator6Active);
    00156   SO_KIT_CATALOG_ENTRY_HEADER(translator6LocateGroup);
    00157   SO_KIT_CATALOG_ENTRY_HEADER(translator6Switch);
    00158   SO_KIT_CATALOG_ENTRY_HEADER(translatorSep);
    00159   SO_KIT_CATALOG_ENTRY_HEADER(xAxisFeedbackActive);
    00160   SO_KIT_CATALOG_ENTRY_HEADER(xAxisFeedbackSelect);
    00161   SO_KIT_CATALOG_ENTRY_HEADER(xAxisFeedbackSwitch);
    00162   SO_KIT_CATALOG_ENTRY_HEADER(xCircleFeedback);
    00163   SO_KIT_CATALOG_ENTRY_HEADER(xCircleFeedbackSwitch);
    00164   SO_KIT_CATALOG_ENTRY_HEADER(xCrosshairFeedback);
    00165   SO_KIT_CATALOG_ENTRY_HEADER(yAxisFeedbackActive);
    00166   SO_KIT_CATALOG_ENTRY_HEADER(yAxisFeedbackSelect);
    00167   SO_KIT_CATALOG_ENTRY_HEADER(yAxisFeedbackSwitch);
    00168   SO_KIT_CATALOG_ENTRY_HEADER(yCircleFeedback);
    00169   SO_KIT_CATALOG_ENTRY_HEADER(yCircleFeedbackSwitch);
    00170   SO_KIT_CATALOG_ENTRY_HEADER(yCrosshairFeedback);
    00171   SO_KIT_CATALOG_ENTRY_HEADER(zAxisFeedbackActive);
    00172   SO_KIT_CATALOG_ENTRY_HEADER(zAxisFeedbackSelect);
    00173   SO_KIT_CATALOG_ENTRY_HEADER(zAxisFeedbackSwitch);
    00174   SO_KIT_CATALOG_ENTRY_HEADER(zCircleFeedback);
    00175   SO_KIT_CATALOG_ENTRY_HEADER(zCircleFeedbackSwitch);
    00176   SO_KIT_CATALOG_ENTRY_HEADER(zCrosshairFeedback);
    00177
    00178
    00179 public:
    00180   static void initClass(void);
    00181   SoTransformerDragger(void);
    00182
    00183   SoSFRotation rotation;
    00184   SoSFVec3f translation;
    00185   SoSFVec3f scaleFactor;
    00186   SoSFFloat minDiscRotDot;
    00187
    00188   enum State {
    00189     INACTIVE,
    00190
    00191     RIT_X_ROTATE,
    00192     TOP_Y_ROTATE,
    00193     FNT_Z_ROTATE,
    00194     LFT_X_ROTATE,
    00195     BOT_Y_ROTATE,
    00196     BAK_Z_ROTATE,
    00197
    00198     PX_PY_PZ_3D_SCALE,
    00199     PX_PY_NZ_3D_SCALE,
    00200     PX_NY_PZ_3D_SCALE,
    00201     PX_NY_NZ_3D_SCALE,
    00202     NX_PY_PZ_3D_SCALE,
    00203     NX_PY_NZ_3D_SCALE,
    00204     NX_NY_PZ_3D_SCALE,
    00205     NX_NY_NZ_3D_SCALE,
    00206
    00207     RIT_TRANSLATE,
    00208     TOP_TRANSLATE,
    00209     FNT_TRANSLATE,
    00210     LFT_TRANSLATE,
    00211     BOT_TRANSLATE,
    00212     BAK_TRANSLATE
    00213   };
    00214
    00215   State getCurrentState(void);
    00216
    00217   void unsquishKnobs(void);
    00218
    00219   SbBool isLocateHighlighting(void);
    00220   void setLocateHighlighting(SbBool onoff);
    00221
    00222   static void setColinearThreshold(int newval);
    00223   static int getColinearThreshold(void);
    00224
    00225   SbVec3f getBoxPointInWorldSpace(const SbVec3f & pointonunitbox);
    00226   SbVec3f getBoxDirInWorldSpace(const SbVec3f & dironunitbox);
    00227   SbVec3f getWorldPointInBoxSpace(const SbVec3f & pointinworldspace);
    00228   SbVec2f getWorldPointInPixelSpace(const SbVec3f & thepoint);
    00229
    00230   SbVec3f getInteractiveCenterInBoxSpace(void);
    00231
    00232 protected:
    00233   ~SoTransformerDragger();
    00234   virtual SbBool setUpConnections(SbBool onoff, SbBool doitalways = FALSE);
    00235   virtual void setDefaultOnNonWritingFields(void);
    00236
    00237   static void startCB(void * f, SoDragger * d);
    00238   static void motionCB(void * f, SoDragger * d);
    00239   static void finishCB(void * f, SoDragger * d);
    00240   static void metaKeyChangeCB(void *, SoDragger *);
    00241   static void fieldSensorCB(void * f, SoSensor * s);
    00242   static void valueChangedCB(void * f, SoDragger * d);
    00243
    00244   void dragStart(void);
    00245   void drag(void);
    00246   void dragFinish(void);
    00247
    00248   void updateAntiSquishList(void);
    00249   void setAllPartSwitches(int scalewhich, int rotatewhich, int translatewhich);
    00250   int getMouseGestureDirection(SbBool x_ok, SbBool y_ok, SbBool z_ok);
    00251   static int getIgnoreAxis(SbVec2f axis[3][2],
    00252                            SbBool x_ok, SbBool y_ok, SbBool z_ok);
    00253   static void makeMinorAxisPerpendicularIfColinear(SbVec2f origin, SbVec2f axisends[3][2], int index_a, int index_b);
    00254   static SbBool isColinear(SbVec2f a1[2], SbVec2f a2[2], int pixels);
    00255
    00256   SoFieldSensor * translFieldSensor;
    00257   SoFieldSensor * scaleFieldSensor;
    00258   SoFieldSensor * rotateFieldSensor;
    00259   SoNodeList antiSquishList;
    00260
    00261 private:
    00262   void getSurroundScaleMatrices(SbMatrix &matrix, SbMatrix &inv);
    00263   SoNode *getNodeFieldNode(const char *fieldname);
    00264
    00265   void build_catalog1(void);
    00266   void build_catalog2(void);
    00267   void build_catalog3(void);
    00268   void build_catalog4(void);
    00269   void build_catalog5(void);
    00270   void build_catalog6(void);
    00271
    00272   SbMatrix getWorkingToWorldMatrix(void);
    00273   SbMatrix getWorldToWorkingMatrix(void);
    00274   SbVec3f localToWorking(const SbVec3f &v);
    00275   SbVec3f workingToLocal(const SbVec3f &v);
    00276   SbVec3f calcCtrlOffset(const SbVec3f &startpt);
    00277   void setSwitchValue(const char *str, const int which);
    00278
    00279   SbBool setDynamicTranslatorSwitches(const SoEvent *event);
    00280   SbBool setDynamicRotatorSwitches(const SoEvent *event);
    00281   SbBool setDynamicScaleSwitches(const SoEvent *event);
    00282
    00283   void dragTranslate();
    00284   void dragScale();
    00285   void dragRotate();
    00286
    00287   class SbPlaneProjector *planeProj;
    00288   class SbLineProjector *lineProj;
    00289   class SbSphereProjector *sphereProj;
    00290   class SbCylinderProjector *cylProj;
    00291
    00292   State state;
    00293
    00294   class SoTransformerDraggerP * pimpl;
    00295   friend class SoTransformerDraggerP;
    00296 };
    00297
    00298 #endif // !COIN_SOTRANSFORMERDRAGGER_H