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
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef _SO_TRANSFORMER_DRAGGER_
00051 #define _SO_TRANSFORMER_DRAGGER_
00052
00053 #include <Inventor/SoLists.h>
00054 #include <Inventor/draggers/SoDragger.h>
00055 #include <Inventor/fields/SoSFFloat.h>
00056 #include <Inventor/fields/SoSFRotation.h>
00057 #include <Inventor/fields/SoSFVec3f.h>
00058 #include <Inventor/sensors/SoSensor.h>
00059
00060 class SbDict;
00061 class SbPlaneProjector;
00062 class SbLineProjector;
00063 class SbSphereSectionProjector;
00064 class SbCylinderPlaneProjector;
00065 class SoFieldSensor;
00066
00068
00069
00070
00071
00072
00074
00690 class SoTransformerDragger : public SoDragger {
00691
00692 SO_KIT_HEADER(SoTransformerDragger);
00693
00694 SO_KIT_CATALOG_ENTRY_HEADER(overallStyle);
00695
00696
00697 SO_KIT_CATALOG_ENTRY_HEADER(surroundScale);
00698
00699 SO_KIT_CATALOG_ENTRY_HEADER(translatorSep);
00700 SO_KIT_CATALOG_ENTRY_HEADER(translator1Switch);
00701 SO_KIT_CATALOG_ENTRY_HEADER(translator1LocateGroup);
00702 SO_KIT_CATALOG_ENTRY_HEADER(translator1);
00703 SO_KIT_CATALOG_ENTRY_HEADER(translator1Active);
00704 SO_KIT_CATALOG_ENTRY_HEADER(translator2Switch);
00705 SO_KIT_CATALOG_ENTRY_HEADER(translator2LocateGroup);
00706 SO_KIT_CATALOG_ENTRY_HEADER(translator2);
00707 SO_KIT_CATALOG_ENTRY_HEADER(translator2Active);
00708 SO_KIT_CATALOG_ENTRY_HEADER(translator3Switch);
00709 SO_KIT_CATALOG_ENTRY_HEADER(translator3LocateGroup);
00710 SO_KIT_CATALOG_ENTRY_HEADER(translator3);
00711 SO_KIT_CATALOG_ENTRY_HEADER(translator3Active);
00712 SO_KIT_CATALOG_ENTRY_HEADER(translator4Switch);
00713 SO_KIT_CATALOG_ENTRY_HEADER(translator4LocateGroup);
00714 SO_KIT_CATALOG_ENTRY_HEADER(translator4);
00715 SO_KIT_CATALOG_ENTRY_HEADER(translator4Active);
00716 SO_KIT_CATALOG_ENTRY_HEADER(translator5Switch);
00717 SO_KIT_CATALOG_ENTRY_HEADER(translator5LocateGroup);
00718 SO_KIT_CATALOG_ENTRY_HEADER(translator5);
00719 SO_KIT_CATALOG_ENTRY_HEADER(translator5Active);
00720 SO_KIT_CATALOG_ENTRY_HEADER(translator6Switch);
00721 SO_KIT_CATALOG_ENTRY_HEADER(translator6LocateGroup);
00722 SO_KIT_CATALOG_ENTRY_HEADER(translator6);
00723 SO_KIT_CATALOG_ENTRY_HEADER(translator6Active);
00724
00725
00726 SO_KIT_CATALOG_ENTRY_HEADER(rotatorSep);
00727 SO_KIT_CATALOG_ENTRY_HEADER(rotator1Switch);
00728 SO_KIT_CATALOG_ENTRY_HEADER(rotator1LocateGroup);
00729 SO_KIT_CATALOG_ENTRY_HEADER(rotator1);
00730 SO_KIT_CATALOG_ENTRY_HEADER(rotator1Active);
00731 SO_KIT_CATALOG_ENTRY_HEADER(rotator2Switch);
00732 SO_KIT_CATALOG_ENTRY_HEADER(rotator2LocateGroup);
00733 SO_KIT_CATALOG_ENTRY_HEADER(rotator2);
00734 SO_KIT_CATALOG_ENTRY_HEADER(rotator2Active);
00735 SO_KIT_CATALOG_ENTRY_HEADER(rotator3Switch);
00736 SO_KIT_CATALOG_ENTRY_HEADER(rotator3LocateGroup);
00737 SO_KIT_CATALOG_ENTRY_HEADER(rotator3);
00738 SO_KIT_CATALOG_ENTRY_HEADER(rotator3Active);
00739 SO_KIT_CATALOG_ENTRY_HEADER(rotator4Switch);
00740 SO_KIT_CATALOG_ENTRY_HEADER(rotator4LocateGroup);
00741 SO_KIT_CATALOG_ENTRY_HEADER(rotator4);
00742 SO_KIT_CATALOG_ENTRY_HEADER(rotator4Active);
00743 SO_KIT_CATALOG_ENTRY_HEADER(rotator5Switch);
00744 SO_KIT_CATALOG_ENTRY_HEADER(rotator5LocateGroup);
00745 SO_KIT_CATALOG_ENTRY_HEADER(rotator5);
00746 SO_KIT_CATALOG_ENTRY_HEADER(rotator5Active);
00747 SO_KIT_CATALOG_ENTRY_HEADER(rotator6Switch);
00748 SO_KIT_CATALOG_ENTRY_HEADER(rotator6LocateGroup);
00749 SO_KIT_CATALOG_ENTRY_HEADER(rotator6);
00750 SO_KIT_CATALOG_ENTRY_HEADER(rotator6Active);
00751
00752 SO_KIT_CATALOG_ENTRY_HEADER(scaleSep);
00753 SO_KIT_CATALOG_ENTRY_HEADER(scale1Switch);
00754 SO_KIT_CATALOG_ENTRY_HEADER(scale1LocateGroup);
00755 SO_KIT_CATALOG_ENTRY_HEADER(scale1);
00756 SO_KIT_CATALOG_ENTRY_HEADER(scale1Active);
00757 SO_KIT_CATALOG_ENTRY_HEADER(scale2Switch);
00758 SO_KIT_CATALOG_ENTRY_HEADER(scale2LocateGroup);
00759 SO_KIT_CATALOG_ENTRY_HEADER(scale2);
00760 SO_KIT_CATALOG_ENTRY_HEADER(scale2Active);
00761 SO_KIT_CATALOG_ENTRY_HEADER(scale3Switch);
00762 SO_KIT_CATALOG_ENTRY_HEADER(scale3LocateGroup);
00763 SO_KIT_CATALOG_ENTRY_HEADER(scale3);
00764 SO_KIT_CATALOG_ENTRY_HEADER(scale3Active);
00765 SO_KIT_CATALOG_ENTRY_HEADER(scale4Switch);
00766 SO_KIT_CATALOG_ENTRY_HEADER(scale4LocateGroup);
00767 SO_KIT_CATALOG_ENTRY_HEADER(scale4);
00768 SO_KIT_CATALOG_ENTRY_HEADER(scale4Active);
00769 SO_KIT_CATALOG_ENTRY_HEADER(scale5Switch);
00770 SO_KIT_CATALOG_ENTRY_HEADER(scale5LocateGroup);
00771 SO_KIT_CATALOG_ENTRY_HEADER(scale5);
00772 SO_KIT_CATALOG_ENTRY_HEADER(scale5Active);
00773 SO_KIT_CATALOG_ENTRY_HEADER(scale6Switch);
00774 SO_KIT_CATALOG_ENTRY_HEADER(scale6LocateGroup);
00775 SO_KIT_CATALOG_ENTRY_HEADER(scale6);
00776 SO_KIT_CATALOG_ENTRY_HEADER(scale6Active);
00777 SO_KIT_CATALOG_ENTRY_HEADER(scale7Switch);
00778 SO_KIT_CATALOG_ENTRY_HEADER(scale7LocateGroup);
00779 SO_KIT_CATALOG_ENTRY_HEADER(scale7);
00780 SO_KIT_CATALOG_ENTRY_HEADER(scale7Active);
00781 SO_KIT_CATALOG_ENTRY_HEADER(scale8Switch);
00782 SO_KIT_CATALOG_ENTRY_HEADER(scale8LocateGroup);
00783 SO_KIT_CATALOG_ENTRY_HEADER(scale8);
00784 SO_KIT_CATALOG_ENTRY_HEADER(scale8Active);
00785
00786 SO_KIT_CATALOG_ENTRY_HEADER(axisFeedbackSep);
00787 SO_KIT_CATALOG_ENTRY_HEADER(axisFeedbackLocation);
00788 SO_KIT_CATALOG_ENTRY_HEADER(xAxisFeedbackSwitch);
00789 SO_KIT_CATALOG_ENTRY_HEADER(xAxisFeedbackActive);
00790 SO_KIT_CATALOG_ENTRY_HEADER(xAxisFeedbackSelect);
00791 SO_KIT_CATALOG_ENTRY_HEADER(xCrosshairFeedback);
00792 SO_KIT_CATALOG_ENTRY_HEADER(yAxisFeedbackSwitch);
00793 SO_KIT_CATALOG_ENTRY_HEADER(yAxisFeedbackActive);
00794 SO_KIT_CATALOG_ENTRY_HEADER(yAxisFeedbackSelect);
00795 SO_KIT_CATALOG_ENTRY_HEADER(yCrosshairFeedback);
00796 SO_KIT_CATALOG_ENTRY_HEADER(zAxisFeedbackSwitch);
00797 SO_KIT_CATALOG_ENTRY_HEADER(zAxisFeedbackActive);
00798 SO_KIT_CATALOG_ENTRY_HEADER(zAxisFeedbackSelect);
00799 SO_KIT_CATALOG_ENTRY_HEADER(zCrosshairFeedback);
00800
00801 SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedbackSep);
00802 SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedbackSwitch);
00803 SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedbackRotation);
00804 SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedback);
00805
00806 SO_KIT_CATALOG_ENTRY_HEADER(scaleBoxFeedbackSwitch);
00807 SO_KIT_CATALOG_ENTRY_HEADER(scaleBoxFeedback);
00808
00809 SO_KIT_CATALOG_ENTRY_HEADER(posXWallFeedbackSwitch);
00810 SO_KIT_CATALOG_ENTRY_HEADER(posXWallFeedback);
00811 SO_KIT_CATALOG_ENTRY_HEADER(posXRoundWallFeedback);
00812 SO_KIT_CATALOG_ENTRY_HEADER(posYWallFeedbackSwitch);
00813 SO_KIT_CATALOG_ENTRY_HEADER(posYWallFeedback);
00814 SO_KIT_CATALOG_ENTRY_HEADER(posYRoundWallFeedback);
00815 SO_KIT_CATALOG_ENTRY_HEADER(posZWallFeedbackSwitch);
00816 SO_KIT_CATALOG_ENTRY_HEADER(posZWallFeedback);
00817 SO_KIT_CATALOG_ENTRY_HEADER(posZRoundWallFeedback);
00818 SO_KIT_CATALOG_ENTRY_HEADER(negXWallFeedbackSwitch);
00819 SO_KIT_CATALOG_ENTRY_HEADER(negXWallFeedback);
00820 SO_KIT_CATALOG_ENTRY_HEADER(negXRoundWallFeedback);
00821 SO_KIT_CATALOG_ENTRY_HEADER(negYWallFeedbackSwitch);
00822 SO_KIT_CATALOG_ENTRY_HEADER(negYWallFeedback);
00823 SO_KIT_CATALOG_ENTRY_HEADER(negYRoundWallFeedback);
00824 SO_KIT_CATALOG_ENTRY_HEADER(negZWallFeedbackSwitch);
00825 SO_KIT_CATALOG_ENTRY_HEADER(negZWallFeedback);
00826 SO_KIT_CATALOG_ENTRY_HEADER(negZRoundWallFeedback);
00827
00828 SO_KIT_CATALOG_ENTRY_HEADER(radialFeedbackSwitch);
00829 SO_KIT_CATALOG_ENTRY_HEADER(radialFeedback);
00830
00831 SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackSep);
00832 SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackTransformSwitch);
00833 SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackAntiSquish);
00834 SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackTransform);
00835 SO_KIT_CATALOG_ENTRY_HEADER(xCircleFeedbackSwitch);
00836 SO_KIT_CATALOG_ENTRY_HEADER(xCircleFeedback);
00837 SO_KIT_CATALOG_ENTRY_HEADER(yCircleFeedbackSwitch);
00838 SO_KIT_CATALOG_ENTRY_HEADER(yCircleFeedback);
00839 SO_KIT_CATALOG_ENTRY_HEADER(zCircleFeedbackSwitch);
00840 SO_KIT_CATALOG_ENTRY_HEADER(zCircleFeedback);
00841
00842
00843 public:
00847 SoTransformerDragger();
00848
00853 SoSFRotation rotation;
00858 SoSFVec3f translation;
00863 SoSFVec3f scaleFactor;
00871 SoSFFloat minDiscRotDot;
00872
00879 void unsquishKnobs();
00880
00884 SbBool isLocateHighlighting() { return locateHighlightOn; }
00892 void setLocateHighlighting( SbBool onOff );
00893
00901 static void setColinearThreshold(int newVal);
00906 static int getColinearThreshold();
00907
00908 private:
00909
00910
00911
00912 SbVec3f getBoxPointInWorldSpace( const SbVec3f &pointOnUnitBox );
00913 SbVec3f getBoxDirInWorldSpace( const SbVec3f &dirOnUnitBox );
00914 SbVec3f getWorldPointInBoxSpace( const SbVec3f &pointInWorldSpace );
00915 SbVec2f getWorldPointInPixelSpace( const SbVec3f &thePoint );
00916
00917
00918
00919
00920
00921
00922 SbVec3f getInteractiveCenterInBoxSpace()
00923 { return interactiveCenterInBoxSpace; }
00924
00925 private:
00926 static void initClass();
00927 static void exitClass();
00928
00929 enum State
00930 { INACTIVE,
00931 RIT_X_ROTATE, TOP_Y_ROTATE, FNT_Z_ROTATE,
00932 LFT_X_ROTATE, BOT_Y_ROTATE, BAK_Z_ROTATE,
00933
00934 PX_PY_PZ_3D_SCALE, PX_PY_NZ_3D_SCALE, PX_NY_PZ_3D_SCALE,
00935 PX_NY_NZ_3D_SCALE, NX_PY_PZ_3D_SCALE, NX_PY_NZ_3D_SCALE,
00936 NX_NY_PZ_3D_SCALE, NX_NY_NZ_3D_SCALE,
00937
00938 RIT_TRANSLATE, TOP_TRANSLATE, FNT_TRANSLATE,
00939 LFT_TRANSLATE, BOT_TRANSLATE, BAK_TRANSLATE };
00940
00941 State getCurrentState() { return currentState; }
00942
00943 private:
00944
00945
00946 static void startCB( void *, SoDragger * );
00947 static void motionCB( void *, SoDragger * );
00948 static void finishCB( void *, SoDragger * );
00949
00950 SoFieldSensor *translFieldSensor;
00951 SoFieldSensor *scaleFieldSensor;
00952 SoFieldSensor *rotateFieldSensor;
00953 static void fieldSensorCB( void *, SoSensor * );
00954 static void valueChangedCB( void *, SoDragger * );
00955
00956
00957 static void metaKeyChangeCB( void *, SoDragger *);
00958
00959
00960 void dragStart();
00961 void drag();
00962 void dragFinish();
00963
00964
00965
00966 void setAllPartSwitches( int scaleAssemblyWhich,
00967 int rotateAssemblyWhich,
00968 int translateAssemblyWhich );
00969
00970
00971
00972
00973
00974
00975
00976 virtual SbBool setUpConnections( SbBool onOff, SbBool doItAlways = FALSE );
00977
00978 virtual void setDefaultOnNonWritingFields();
00979
00980 virtual ~SoTransformerDragger();
00981
00982
00983 void updateAntiSquishList();
00984
00985 SoNodeList antiSquishList;
00986
00987 int getMouseGestureDirection(SbBool xAllowed, SbBool yAllowed,
00988 SbBool zAllowed);
00989
00990 static int getIgnoreAxis(SbVec2f axis[3][2], SbBool xAllowed,
00991 SbBool yAllowed, SbBool zAllowed );
00992
00993 static void makeMinorAxisPerpendicularIfColinear( SbVec2f origin,
00994 SbVec2f axisEnds[3][2], int indexA, int indexB );
00995
00996 static SbBool isColinear(SbVec2f a1[2], SbVec2f a2[2], int pixels);
00997
00998 private:
00999
01000 State currentState;
01001 int currentDir;
01002
01003
01004
01005
01006 SbBool rotatingAsDisc;
01007
01008 SbPlaneProjector *planeProj;
01009 SbLineProjector *lineProj;
01010 SbSphereSectionProjector *sphereProj;
01011 SbCylinderPlaneProjector *cylProj;
01012
01013 State restartState;
01014 SbVec3f worldRestartPt;
01015
01016 SbMatrix prevMotionMatrix;
01017 SbVec3f prevWorldHitPt;
01018 SbVec3f interactiveCenterInBoxSpace;
01019
01020
01021
01022
01023 SbVec2f startNormalizedLocaterPosition;
01024
01025 SbBool altDown, ctlDown, shftDown;
01026
01027 SbBool constraining;
01028
01029
01030 void setHighlights();
01031 void setFeedback();
01032 void setFeedbackForTranslate();
01033 void setFeedbackForScale();
01034 void setFeedbackForRotate();
01035
01036 State getStateFromPick();
01037 SbBool translateInit();
01038 SbBool rotateInit();
01039 SbBool scaleInit();
01040
01041 SbBool translateDrag();
01042 SbBool scaleDrag();
01043
01044 SbBool rotateDrag();
01045 SbBool rotateConstrainedDrag();
01046 SbBool rotateConstrainedDiscDrag();
01047 SbBool rotateConstrainedCylindricalDrag();
01048
01049 void initSphereProjector();
01050 void initDiscProjector();
01051 void initCylinderProjector();
01052
01053 SbBool getShouldRotateAsDisc();
01054 int getConstrainedRotationAxis();
01055
01056
01057 static const char geomBuffer[];
01058
01059 void setAllDefaultParts();
01060
01061 SbBool locateHighlightOn;
01062
01063 static int colinearThreshold;
01064
01065
01066
01067
01068 void makeCatalog();
01069 void makeTranslaterCatalogParts();
01070 void makeRotaterCatalogParts();
01071 void makeScalerCatalogParts();
01072 void makeAxisFeedbackCatalogParts();
01073 void makeBoxFeedbackCatalogParts();
01074 void makeWallFeedbackCatalogParts();
01075 void makeRadialFeedbackCatalogParts();
01076 void makeCircleFeedbackCatalogParts();
01077
01078 };
01079
01080 #endif
01081
01082