Open Inventor Reference
|
00001 /* 00002 * 00003 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * Further, this software is distributed without any warranty that it is 00016 * free of the rightful claim of any third person regarding infringement 00017 * or the like. Any license provided herein, whether implied or 00018 * otherwise, applies only to this software file. Patent licenses, if 00019 * any, provided herein do not apply to combinations of this program with 00020 * other software, or any other product whatsoever. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with this library; if not, write to the Free Software 00024 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 * 00026 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 00027 * Mountain View, CA 94043, or: 00028 * 00029 * http://www.sgi.com 00030 * 00031 * For further information regarding this notice, see: 00032 * 00033 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ 00034 * 00035 */ 00036 00037 00038 /* 00039 * Copyright (C) 1990,91 Silicon Graphics, Inc. 00040 * 00041 _______________________________________________________________________ 00042 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00043 | 00044 | $Revision: 1.1.1.1 $ 00045 | 00046 | Description: 00047 | This file defines the base class for draggers that 00048 | use a click-drag-release paradigm. 00049 | 00050 | NOTE TO DEVELOPERS: 00051 | For info about the structure of SoDragger: 00052 | [1] compile: /usr/share/src/Inventor/samples/ivNodeKitStructure 00053 | [2] type: ivNodeKitStructure SoDragger. 00054 | [3] The program prints a diagram of the scene graph and a table with 00055 | information about each part. 00056 | 00057 | Author(s): Paul Isaacs, David Mott, Howard Look 00058 | 00059 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00060 _______________________________________________________________________ 00061 */ 00062 00063 #ifndef _SO_DRAGGER_ 00064 #define _SO_DRAGGER_ 00065 00066 #include <Inventor/SbBox.h> 00067 #include <Inventor/SbViewportRegion.h> 00068 #include <Inventor/SbLinear.h> 00069 #include <Inventor/nodekits/SoInteractionKit.h> 00070 #include <Inventor/misc/SoCallbackList.h> 00071 #include <Inventor/fields/SoSFBool.h> 00072 #include <Inventor/nodes/SoMatrixTransform.h> 00073 #include <Inventor/nodes/SoScale.h> 00074 00075 00076 class SoPickedPoint; 00077 class SoAction; 00078 class SoHandleEventAction; 00079 class SoGetBoundingBoxAction; 00080 class SoEvent; 00081 class SoPath; 00082 class SoTempPath; 00083 class SbPList; 00084 00085 class SoDragger; 00086 00088 typedef void INVENTOR_API SoDraggerCB(void *userData, SoDragger *dragger ); 00089 00090 00093 00223 00224 00225 class INVENTOR_API SoDragger : public SoInteractionKit { 00226 00227 SO_KIT_HEADER(SoDragger); 00228 00229 SO_KIT_CATALOG_ENTRY_HEADER(motionMatrix); 00230 00231 public: 00232 00235 SoSFBool isActive; 00236 00240 void addStartCallback(SoDraggerCB *f, void *userData = NULL); 00242 void removeStartCallback(SoDraggerCB *f, void *userData = NULL); 00243 00246 void addMotionCallback(SoDraggerCB *f, void *userData = NULL); 00249 void removeMotionCallback(SoDraggerCB *f, void *userData = NULL); 00250 00253 void addFinishCallback(SoDraggerCB *f, void *userData = NULL); 00256 void removeFinishCallback(SoDraggerCB *f, void *userData = NULL); 00257 00261 void addValueChangedCallback(SoDraggerCB *f, void *userData = NULL); 00263 void removeValueChangedCallback(SoDraggerCB *f, void *userData = NULL); 00264 00267 void setMinGesture(int pixels) { minGesture = pixels; } 00270 int getMinGesture() const { return minGesture; } 00271 00275 static void setMinScale( float newMinScale ) { minScale = newMinScale; } 00277 static float getMinScale() { return minScale; } 00278 00288 SbBool enableValueChangedCallbacks( SbBool newVal ); 00289 00290 SoEXTENDER public: 00291 00297 const SbMatrix &getMotionMatrix(); 00298 00302 00307 void addOtherEventCallback(SoDraggerCB *f, void *userData = NULL); 00308 void removeOtherEventCallback(SoDraggerCB *f, void *userData = NULL); 00309 00315 void registerChildDragger(SoDragger *child); 00316 void unregisterChildDragger(SoDragger *child); 00322 void registerChildDraggerMovingIndependently(SoDragger *child); 00323 void unregisterChildDraggerMovingIndependently(SoDragger *child); 00324 00326 SbMatrix getLocalToWorldMatrix(); 00327 SbMatrix getWorldToLocalMatrix(); 00328 00330 SbVec3f getLocalStartingPoint(); 00332 SbVec3f getWorldStartingPoint(); 00333 00343 void getPartToLocalMatrix( const SbName &partName, 00344 SbMatrix &partToLocalMatrix, 00345 SbMatrix &localToPartMatrix); 00346 00348 void transformMatrixLocalToWorld( const SbMatrix &fromMatrix, 00349 SbMatrix &toMatrix); 00350 void transformMatrixWorldToLocal( const SbMatrix &fromMatrix, 00351 SbMatrix &toMatrix); 00352 void transformMatrixToLocalSpace( const SbMatrix &fromMatrix, 00353 SbMatrix &toMatrix, const SbName &fromSpacePartName); 00354 00357 void setMotionMatrix( const SbMatrix &newMatrix ); 00358 00365 void valueChanged(); 00366 00369 const SbMatrix &getStartMotionMatrix() { return startMotionMatrix; } 00374 virtual void saveStartParameters(); 00375 00377 const SoPath *getPickPath() const; 00378 const SoEvent *getEvent() const; 00383 SoPath *createPathToThis(); 00384 00391 const SoPath *getSurrogatePartPickedOwner() const 00392 { return pathToSurrogatePickOwner;} 00395 const SbName &getSurrogatePartPickedName() const 00396 { return surrogateNameInPickOwner; } 00401 const SoPath *getSurrogatePartPickedPath() const 00402 { return surrogatePathInPickOwner;} 00403 00406 void setStartingPoint( const SoPickedPoint *newPoint ); 00410 void setStartingPoint( const SbVec3f &newPoint ); 00411 00418 const SbViewVolume &getViewVolume() { return viewVolume; } 00419 void setViewVolume(const SbViewVolume &vol) { viewVolume = vol; } 00420 00421 const SbViewportRegion &getViewportRegion() { return vpRegion; } 00422 void setViewportRegion(const SbViewportRegion ®) { vpRegion = reg; } 00423 00425 SoHandleEventAction *getHandleEventAction() const 00426 { return handleEventAction; } 00427 void setHandleEventAction( SoHandleEventAction *newAction ); 00428 00432 void setTempPathToThis(const SoPath *somethingClose); 00433 00435 virtual void grabEventsSetup(); 00436 virtual void grabEventsCleanup(); 00437 00451 void workFieldsIntoTransform( SbMatrix &mtx ); 00454 static void workValuesIntoTransform( SbMatrix &mtx, 00455 const SbVec3f *translationPtr, 00456 const SbRotation *rotationPtr, 00457 const SbVec3f *scaleFactorPtr, 00458 const SbRotation *scaleOrientationPtr, 00459 const SbVec3f *centerPtr); 00460 00466 static void getTransformFast( SbMatrix &mtx, SbVec3f &translation, 00467 SbRotation &rotation, SbVec3f &scaleFactor, 00468 SbRotation &scaleOrientation, 00469 const SbVec3f ¢er); 00470 static void getTransformFast( SbMatrix &mtx, SbVec3f &translation, 00471 SbRotation &rotation, SbVec3f &scaleFactor, 00472 SbRotation &scaleOrientation); 00473 00477 static SbMatrix appendTranslation( const SbMatrix &mtx, 00478 const SbVec3f &translation, 00479 const SbMatrix *conversion = NULL ); 00480 static SbMatrix appendScale( const SbMatrix &mtx, 00481 const SbVec3f &scale, const SbVec3f &scaleCenter, 00482 const SbMatrix *conversion = NULL ); 00483 static SbMatrix appendRotation( const SbMatrix &mtx, 00484 const SbRotation &rot, const SbVec3f &rotCenter, 00485 const SbMatrix *conversion = NULL ); 00486 00487 SoINTERNAL public: 00488 static void initClass(); 00489 00491 static void initClasses(); 00492 00498 enum ProjectorFrontSetting { 00499 FRONT, BACK, USE_PICK 00500 }; 00501 void setFrontOnProjector( ProjectorFrontSetting newVal ) 00502 { projectorFrontSetting = newVal; } 00503 ProjectorFrontSetting getFrontOnProjector() const 00504 { return projectorFrontSetting;} 00505 00506 protected: 00507 00509 SoDragger(); 00510 00516 SbVec2f getNormalizedLocaterPosition(); 00517 SbVec2s getLocaterPosition(); 00518 00520 SbVec2s getStartLocaterPosition() const { return startLocater; } 00521 00525 void setStartLocaterPosition(SbVec2s p) { startLocater = p; } 00526 00529 SbBool isAdequateConstraintMotion(); 00530 00539 virtual SbBool shouldGrabBasedOnSurrogate( const SoPath *pickPath, 00540 const SoPath *surrogatePath ); 00541 00545 void setCameraInfo( SoAction *action ); 00546 00549 virtual void handleEvent(SoHandleEventAction *ha); 00550 00558 void transferMotion(SoDragger *child); 00559 00562 void setIgnoreInBbox( SbBool newVal ) { ignoreInBbox = newVal; } 00563 SbBool isIgnoreInBbox() { return ignoreInBbox; } 00564 00568 virtual void getBoundingBox(SoGetBoundingBoxAction *action); 00569 00572 static void childTransferMotionAndValueChangedCB(void *, SoDragger *); 00573 static void childValueChangedCB(void *, SoDragger *); 00574 static void childStartCB(void *, SoDragger *); 00575 static void childMotionCB(void *, SoDragger *); 00576 static void childFinishCB(void *, SoDragger *); 00577 static void childOtherEventCB(void *, SoDragger *); 00578 00582 void setActiveChildDragger( SoDragger *newChildDragger ); 00583 SoDragger *getActiveChildDragger() const { return activeChildDragger; } 00584 00603 virtual void setDefaultOnNonWritingFields(); 00604 00605 virtual ~SoDragger(); 00606 00607 private: 00608 00610 SoCallbackList *startCallbacks; 00611 SoCallbackList *motionCallbacks; 00612 SoCallbackList *finishCallbacks; 00613 SoCallbackList *valueChangedCallbacks; 00614 00615 SoCallbackList *otherEventCallbacks; 00616 00617 SbBool valueChangedCallbacksEnabled; 00618 SoDragger *activeChildDragger; 00619 00620 SoHandleEventAction *handleEventAction; 00621 00627 SbVec3f startingWorldPoint; 00628 00630 SbMatrix startMotionMatrix; 00631 00633 SbVec2s startLocater; 00634 00635 00637 void setPickPath(SoPath *newPickPath); 00638 SoPath *pickPath; 00639 00641 void setNoPickedSurrogate(); 00642 void setPickedSurrogate( SoPath *pathToOwner, SbName &nameUsedByOwner, 00643 SoPath *pathUsedByOwner ); 00644 00645 SbName surrogateNameInPickOwner; 00646 SoPath *pathToSurrogatePickOwner; 00647 SoPath *surrogatePathInPickOwner; 00648 00657 SoTempPath *tempPathToThis; 00658 SbPList *tempPathNumKidsHack; 00662 SbBool isTempPathToThisOk(); 00664 SoTempPath *createTempPathFromFullPath( const SoFullPath *fp ) const; 00665 00668 int minGesture; 00669 00673 static float minScale; 00674 00675 SbViewVolume viewVolume; 00676 SbViewportRegion vpRegion; 00677 00682 00684 void validateMatrices(); 00685 00692 SbBool cachedPathToThisValid; 00693 SbBool cachedMotionMatrixValid; 00694 SbMatrix cachedMotionMatrix; 00696 SbMatrix postMotionToWorldMatrix; 00697 SbMatrix worldToPostMotionMatrix; 00699 SbMatrix preMotionToWorldMatrix; 00700 SbMatrix worldToPreMotionMatrix; 00701 00704 SbBool ignoreInBbox; 00705 00708 SbBool mouseMovedYet; 00709 00710 ProjectorFrontSetting projectorFrontSetting; 00711 }; 00712 00713 #endif /* _SO_DRAGGER_ */