Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://coin3d.github.io
https://www.kongsberg.com/en/kogt/
SoDragger.h
1 #ifndef COIN_SODRAGGER_H
2 #define COIN_SODRAGGER_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <Inventor/nodekits/SoInteractionKit.h>
37 #include <Inventor/tools/SbPimplPtr.h>
38 #include <Inventor/fields/SoSFBool.h>
39 #include <Inventor/lists/SoCallbackList.h>
40 #include <Inventor/SbMatrix.h>
41 #include <Inventor/SbVec3f.h>
42 #include <Inventor/SbVec2s.h>
43 #include <Inventor/SbViewVolume.h>
44 #include <Inventor/SbViewportRegion.h>
45 #ifndef COIN_INTERNAL
46 // For Open Inventor compatibility.
47 #include <Inventor/nodes/SoScale.h>
48 #endif // !COIN_INTERNAL
49 
50 class SbRotation;
51 class SbVec2f;
52 class SbVec2s;
53 class SbViewVolume;
54 class SbViewportRegion;
55 class SoDragger;
56 class SoEvent;
57 class SoPickedPoint;
58 class SoDraggerP;
59 
60 typedef void SoDraggerCB(void * data, SoDragger * dragger);
61 
62 class COIN_DLL_API SoDragger : public SoInteractionKit {
64 
65  SO_KIT_HEADER(SoDragger);
66  SO_KIT_CATALOG_ENTRY_HEADER(motionMatrix);
67 
68 public:
70 
71  enum ProjectorFrontSetting { FRONT, BACK, USE_PICK };
72 
73  // override these in case we decide to do some extra work later
74  virtual void callback(SoCallbackAction * action);
75  virtual void GLRender(SoGLRenderAction * action);
76  virtual void getMatrix(SoGetMatrixAction * action);
77  virtual void rayPick(SoRayPickAction * action);
78  virtual void search(SoSearchAction * action);
79  virtual void write(SoWriteAction * action);
80  virtual void getPrimitiveCount(SoGetPrimitiveCountAction * action);
81 
82  void setProjectorEpsilon(const float epsilon);
83  float getProjectorEpsilon(void) const;
84 
85  void addStartCallback(SoDraggerCB * func, void * data = NULL);
86  void removeStartCallback(SoDraggerCB * func, void * data = NULL);
87  void addMotionCallback(SoDraggerCB * func, void * data = NULL);
88  void removeMotionCallback(SoDraggerCB * func, void * data = NULL);
89  void addFinishCallback(SoDraggerCB * func, void * data = NULL);
90  void removeFinishCallback(SoDraggerCB * func, void * data = NULL);
91  void addValueChangedCallback(SoDraggerCB * func, void * data = NULL);
92  void removeValueChangedCallback(SoDraggerCB * func, void * data = NULL);
93  void setMinGesture(int pixels);
94  int getMinGesture(void) const;
95  SbBool enableValueChangedCallbacks(SbBool newval);
96  const SbMatrix & getMotionMatrix(void);
97  void addOtherEventCallback(SoDraggerCB * func, void * data = NULL);
98  void removeOtherEventCallback(SoDraggerCB * func, void * data = NULL);
99  void registerChildDragger(SoDragger * child);
100  void unregisterChildDragger(SoDragger * child);
101  void registerChildDraggerMovingIndependently(SoDragger * child);
102  void unregisterChildDraggerMovingIndependently(SoDragger * child);
103  SbMatrix getLocalToWorldMatrix(void);
104  SbMatrix getWorldToLocalMatrix(void);
105  SbVec3f getLocalStartingPoint(void);
106  SbVec3f getWorldStartingPoint(void);
107  void getPartToLocalMatrix(const SbName & partname, SbMatrix & parttolocalmatrix, SbMatrix & localtopartmatrix);
108  void transformMatrixLocalToWorld(const SbMatrix & frommatrix, SbMatrix & tomatrix);
109  void transformMatrixWorldToLocal(const SbMatrix & frommatrix, SbMatrix & tomatrix);
110  void transformMatrixToLocalSpace(const SbMatrix & frommatrix, SbMatrix & tomatrix, const SbName & fromspacepartname);
111  virtual void setMotionMatrix(const SbMatrix & newmatrix);
112  void valueChanged(void);
113  const SbMatrix & getStartMotionMatrix(void);
114  virtual void saveStartParameters(void);
115  const SoPath * getPickPath(void) const;
116  const SoEvent * getEvent(void) const;
117  SoPath * createPathToThis(void);
118  const SoPath * getSurrogatePartPickedOwner(void) const;
119  const SbName & getSurrogatePartPickedName(void) const;
120  const SoPath * getSurrogatePartPickedPath(void) const;
121  void setStartingPoint(const SoPickedPoint * newpoint);
122  void setStartingPoint(const SbVec3f & newpoint);
123  const SbViewVolume & getViewVolume(void);
124  void setViewVolume(const SbViewVolume & vol);
125  const SbViewportRegion & getViewportRegion(void);
126  void setViewportRegion(const SbViewportRegion & reg);
127  SoHandleEventAction * getHandleEventAction(void) const;
128  void setHandleEventAction(SoHandleEventAction * newAction);
129  void setTempPathToThis(const SoPath * somethingclose);
130  virtual void grabEventsSetup(void);
131  virtual void grabEventsCleanup(void);
132  void workFieldsIntoTransform(SbMatrix & mtx);
133  void setFrontOnProjector(ProjectorFrontSetting newval);
134  ProjectorFrontSetting getFrontOnProjector(void) const;
135 
136  static void setMinScale(float newminscale);
137  static float getMinScale(void);
138  static void workValuesIntoTransform(SbMatrix & mtx, const SbVec3f * translationptr, const SbRotation * rotationptr, const SbVec3f * scalefactorptr, const SbRotation * scaleorientationptr, const SbVec3f * centerptr);
139  static void getTransformFast(SbMatrix & mtx, SbVec3f & translation, SbRotation & rotation, SbVec3f & scalefactor, SbRotation & scaleorientation, const SbVec3f & center);
140  static void getTransformFast(SbMatrix & mtx, SbVec3f & translation, SbRotation & rotation, SbVec3f & scalefactor, SbRotation & scaleorientation);
141  static SbMatrix appendTranslation(const SbMatrix & mtx, const SbVec3f & translation, const SbMatrix * conversion = NULL);
142  static SbMatrix appendScale(const SbMatrix & mtx, const SbVec3f & scale, const SbVec3f & scalecenter, const SbMatrix * conversion = NULL);
143  static SbMatrix appendRotation(const SbMatrix & mtx, const SbRotation & rot, const SbVec3f & rotcenter, const SbMatrix * conversion = NULL);
144  static void initClass(void);
145  static void initClasses(void);
146 
147 protected:
148  SoDragger(void);
149  virtual ~SoDragger(void);
150 
151  SbVec2f getNormalizedLocaterPosition(void);
152  SbVec2s getLocaterPosition(void);
153  SbVec2s getStartLocaterPosition(void) const;
154  void setStartLocaterPosition(SbVec2s p);
155  SbBool isAdequateConstraintMotion(void);
156  virtual SbBool shouldGrabBasedOnSurrogate(const SoPath * pickpath, const SoPath * surrogatepath);
157  void setCameraInfo(SoAction * action);
158  virtual void handleEvent(SoHandleEventAction * ha);
159  void transferMotion(SoDragger * child);
160  void setIgnoreInBbox(SbBool newval);
161  SbBool isIgnoreInBbox(void);
162  virtual void getBoundingBox(SoGetBoundingBoxAction * action);
163  void setActiveChildDragger(SoDragger * newchilddragger);
164  SoDragger * getActiveChildDragger(void) const;
165  virtual void setDefaultOnNonWritingFields(void);
166 
167  static void childTransferMotionAndValueChangedCB(void *, SoDragger *);
168  static void childValueChangedCB(void *, SoDragger *);
169  static void childStartCB(void *, SoDragger *);
170  static void childMotionCB(void *, SoDragger *);
171  static void childFinishCB(void *, SoDragger *);
172  static void childOtherEventCB(void *, SoDragger *);
173 
174  // This method is not present in Open Inventor. It was moved from
175  // being a private method to a protected method in Coin to make it
176  // possible to construct draggers which can handle Motion3 events.
177  void updateDraggerCache(const SoPath * path);
178 
179  virtual const SoPickedPoint* getPickedPointForStart(SoHandleEventAction* action);
180 
181 private:
182  void updateElements(class SoState * state);
183  SbBool isPicked(SoPath * path);
184  void eventHandled(const SoEvent * event, SoHandleEventAction * action);
185  static float minscale;
186 
187 private:
189 
190  // NOT IMPLEMENTED:
191  SoDragger(const SoDragger & rhs);
192  SoDragger & operator = (const SoDragger & rhs);
193 }; // SoDragger
194 
195 #endif // !COIN_SODRAGGER_H
The SbVec2f class is a 2 dimensional vector with floating point coordinates.
Definition: SbVec2f.h:49
virtual void search(SoSearchAction *action)
Definition: SoBaseKit.cpp:1084
SoSFBool isActive
Definition: SoDragger.h:69
The SoRayPickAction class does ray intersection with scene graphs.
Definition: SoRayPickAction.h:50
The SoGetMatrixAction class is an action for accumulating the transformation matrix of a subgraph...
Definition: SoGetMatrixAction.h:46
The SoSearchAction class provides methods for searching through scene graphs.
Definition: SoSearchAction.h:44
virtual void handleEvent(SoHandleEventAction *action)
Definition: SoBaseKit.cpp:1060
static void initClass(void)
Definition: SoInteractionKit.cpp:266
static void initClasses(void)
Definition: SoNode.cpp:604
virtual void getPrimitiveCount(SoGetPrimitiveCountAction *action)
Definition: SoBaseKit.cpp:1376
The SoState class manages the Coin scene graph traversal state data.
Definition: SoState.h:44
The SoInteractionKit class is a base class for draggers.
Definition: SoInteractionKit.h:50
The SoSFBool class is a container for an SbBool value.
Definition: SoSFBool.h:39
The SoPath class is a container class for traversal path descriptions.
Definition: SoPath.h:52
virtual void getMatrix(SoGetMatrixAction *action)
Definition: SoBaseKit.cpp:1038
The SoDragger class is the base class for all draggers.
Definition: SoDragger.h:62
The SbRotation class represents a rotation in 3D space.
Definition: SbRotation.h:44
virtual void GLRender(SoGLRenderAction *action)
Definition: SoBaseKit.cpp:1008
The SoAction class is the base class for all traversal actions.
Definition: SoAction.h:77
The SbVec3f class is a 3 dimensional vector with floating point coordinates.
Definition: SbVec3f.h:51
The SbMatrix class is a 4x4 dimensional representation of a matrix.
Definition: SbMatrix.h:47
The SoHandleEventAction class distributes user events to the scene.
Definition: SoHandleEventAction.h:46
ProjectorFrontSetting
Definition: SoDragger.h:71
The SoGetPrimitiveCountAction class counts the primitives in a scene.
Definition: SoGetPrimitiveCountAction.h:44
The SoGetBoundingBoxAction class calculates bounding boxes for nodes and subgraphs.
Definition: SoGetBoundingBoxAction.h:45
The SbViewVolume class is a viewing volume in 3D space.
Definition: SbViewVolume.h:50
The SoPickedPoint class is used for specifying picked points.
Definition: SoPickedPoint.h:48
The SoCallbackAction class invokes callbacks at specific nodes.
Definition: SoCallbackAction.h:80
The SoWriteAction class writes a scene graph to file.
Definition: SoWriteAction.h:42
The SoEvent class is the base class for all Coin events.
Definition: SoEvent.h:45
virtual void callback(SoCallbackAction *action)
Definition: SoBaseKit.cpp:1001
virtual void grabEventsSetup(void)
Definition: SoNode.cpp:1376
virtual void grabEventsCleanup(void)
Definition: SoNode.cpp:1385
The SbViewportRegion class is a viewport within a full window.
Definition: SbViewportRegion.h:40
virtual void getBoundingBox(SoGetBoundingBoxAction *action)
Definition: SoBaseKit.cpp:1015
virtual void write(SoWriteAction *action)
Definition: SoBaseKit.cpp:1116
virtual void rayPick(SoRayPickAction *action)
Definition: SoBaseKit.cpp:1067
virtual void setDefaultOnNonWritingFields()
Definition: SoInteractionKit.cpp:716
The SbVec2s class is a 2 dimensional vector with short integer coordinates.
Definition: SbVec2s.h:51
The SbName class stores strings by reference.
Definition: SbName.h:40
The SoGLRenderAction class renders the scene graph with OpenGL calls.
Definition: SoGLRenderAction.h:50