Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
SoTransformerDragger.h
1 #ifndef COIN_SOTRANSFORMERDRAGGER_H
2 #define COIN_SOTRANSFORMERDRAGGER_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 
37 #include <Inventor/tools/SbPimplPtr.h>
38 #include <Inventor/fields/SoSFRotation.h>
39 #include <Inventor/fields/SoSFVec3f.h>
40 #include <Inventor/fields/SoSFFloat.h>
41 #include <Inventor/lists/SoNodeList.h>
42 
43 class SoSensor;
44 class SoFieldSensor;
45 class SoTransformerDraggerP;
46 
47 class COIN_DLL_API SoTransformerDragger : public SoDragger {
48  typedef SoDragger inherited;
49 
50  SO_KIT_HEADER(SoTransformerDragger);
51 
52  SO_KIT_CATALOG_ENTRY_HEADER(axisFeedbackLocation);
53  SO_KIT_CATALOG_ENTRY_HEADER(axisFeedbackSep);
54  SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackAntiSquish);
55  SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackSep);
56  SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackTransform);
57  SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackTransformSwitch);
58  SO_KIT_CATALOG_ENTRY_HEADER(negXRoundWallFeedback);
59  SO_KIT_CATALOG_ENTRY_HEADER(negXWallFeedback);
60  SO_KIT_CATALOG_ENTRY_HEADER(negXWallFeedbackSwitch);
61  SO_KIT_CATALOG_ENTRY_HEADER(negYRoundWallFeedback);
62  SO_KIT_CATALOG_ENTRY_HEADER(negYWallFeedback);
63  SO_KIT_CATALOG_ENTRY_HEADER(negYWallFeedbackSwitch);
64  SO_KIT_CATALOG_ENTRY_HEADER(negZRoundWallFeedback);
65  SO_KIT_CATALOG_ENTRY_HEADER(negZWallFeedback);
66  SO_KIT_CATALOG_ENTRY_HEADER(negZWallFeedbackSwitch);
67  SO_KIT_CATALOG_ENTRY_HEADER(overallStyle);
68  SO_KIT_CATALOG_ENTRY_HEADER(posXRoundWallFeedback);
69  SO_KIT_CATALOG_ENTRY_HEADER(posXWallFeedback);
70  SO_KIT_CATALOG_ENTRY_HEADER(posXWallFeedbackSwitch);
71  SO_KIT_CATALOG_ENTRY_HEADER(posYRoundWallFeedback);
72  SO_KIT_CATALOG_ENTRY_HEADER(posYWallFeedback);
73  SO_KIT_CATALOG_ENTRY_HEADER(posYWallFeedbackSwitch);
74  SO_KIT_CATALOG_ENTRY_HEADER(posZRoundWallFeedback);
75  SO_KIT_CATALOG_ENTRY_HEADER(posZWallFeedback);
76  SO_KIT_CATALOG_ENTRY_HEADER(posZWallFeedbackSwitch);
77  SO_KIT_CATALOG_ENTRY_HEADER(radialFeedback);
78  SO_KIT_CATALOG_ENTRY_HEADER(radialFeedbackSwitch);
79  SO_KIT_CATALOG_ENTRY_HEADER(rotator1);
80  SO_KIT_CATALOG_ENTRY_HEADER(rotator1Active);
81  SO_KIT_CATALOG_ENTRY_HEADER(rotator1LocateGroup);
82  SO_KIT_CATALOG_ENTRY_HEADER(rotator1Switch);
83  SO_KIT_CATALOG_ENTRY_HEADER(rotator2);
84  SO_KIT_CATALOG_ENTRY_HEADER(rotator2Active);
85  SO_KIT_CATALOG_ENTRY_HEADER(rotator2LocateGroup);
86  SO_KIT_CATALOG_ENTRY_HEADER(rotator2Switch);
87  SO_KIT_CATALOG_ENTRY_HEADER(rotator3);
88  SO_KIT_CATALOG_ENTRY_HEADER(rotator3Active);
89  SO_KIT_CATALOG_ENTRY_HEADER(rotator3LocateGroup);
90  SO_KIT_CATALOG_ENTRY_HEADER(rotator3Switch);
91  SO_KIT_CATALOG_ENTRY_HEADER(rotator4);
92  SO_KIT_CATALOG_ENTRY_HEADER(rotator4Active);
93  SO_KIT_CATALOG_ENTRY_HEADER(rotator4LocateGroup);
94  SO_KIT_CATALOG_ENTRY_HEADER(rotator4Switch);
95  SO_KIT_CATALOG_ENTRY_HEADER(rotator5);
96  SO_KIT_CATALOG_ENTRY_HEADER(rotator5Active);
97  SO_KIT_CATALOG_ENTRY_HEADER(rotator5LocateGroup);
98  SO_KIT_CATALOG_ENTRY_HEADER(rotator5Switch);
99  SO_KIT_CATALOG_ENTRY_HEADER(rotator6);
100  SO_KIT_CATALOG_ENTRY_HEADER(rotator6Active);
101  SO_KIT_CATALOG_ENTRY_HEADER(rotator6LocateGroup);
102  SO_KIT_CATALOG_ENTRY_HEADER(rotator6Switch);
103  SO_KIT_CATALOG_ENTRY_HEADER(rotatorSep);
104  SO_KIT_CATALOG_ENTRY_HEADER(scale1);
105  SO_KIT_CATALOG_ENTRY_HEADER(scale1Active);
106  SO_KIT_CATALOG_ENTRY_HEADER(scale1LocateGroup);
107  SO_KIT_CATALOG_ENTRY_HEADER(scale1Switch);
108  SO_KIT_CATALOG_ENTRY_HEADER(scale2);
109  SO_KIT_CATALOG_ENTRY_HEADER(scale2Active);
110  SO_KIT_CATALOG_ENTRY_HEADER(scale2LocateGroup);
111  SO_KIT_CATALOG_ENTRY_HEADER(scale2Switch);
112  SO_KIT_CATALOG_ENTRY_HEADER(scale3);
113  SO_KIT_CATALOG_ENTRY_HEADER(scale3Active);
114  SO_KIT_CATALOG_ENTRY_HEADER(scale3LocateGroup);
115  SO_KIT_CATALOG_ENTRY_HEADER(scale3Switch);
116  SO_KIT_CATALOG_ENTRY_HEADER(scale4);
117  SO_KIT_CATALOG_ENTRY_HEADER(scale4Active);
118  SO_KIT_CATALOG_ENTRY_HEADER(scale4LocateGroup);
119  SO_KIT_CATALOG_ENTRY_HEADER(scale4Switch);
120  SO_KIT_CATALOG_ENTRY_HEADER(scale5);
121  SO_KIT_CATALOG_ENTRY_HEADER(scale5Active);
122  SO_KIT_CATALOG_ENTRY_HEADER(scale5LocateGroup);
123  SO_KIT_CATALOG_ENTRY_HEADER(scale5Switch);
124  SO_KIT_CATALOG_ENTRY_HEADER(scale6);
125  SO_KIT_CATALOG_ENTRY_HEADER(scale6Active);
126  SO_KIT_CATALOG_ENTRY_HEADER(scale6LocateGroup);
127  SO_KIT_CATALOG_ENTRY_HEADER(scale6Switch);
128  SO_KIT_CATALOG_ENTRY_HEADER(scale7);
129  SO_KIT_CATALOG_ENTRY_HEADER(scale7Active);
130  SO_KIT_CATALOG_ENTRY_HEADER(scale7LocateGroup);
131  SO_KIT_CATALOG_ENTRY_HEADER(scale7Switch);
132  SO_KIT_CATALOG_ENTRY_HEADER(scale8);
133  SO_KIT_CATALOG_ENTRY_HEADER(scale8Active);
134  SO_KIT_CATALOG_ENTRY_HEADER(scale8LocateGroup);
135  SO_KIT_CATALOG_ENTRY_HEADER(scale8Switch);
136  SO_KIT_CATALOG_ENTRY_HEADER(scaleBoxFeedback);
137  SO_KIT_CATALOG_ENTRY_HEADER(scaleBoxFeedbackSwitch);
138  SO_KIT_CATALOG_ENTRY_HEADER(scaleSep);
139  SO_KIT_CATALOG_ENTRY_HEADER(surroundScale);
140  SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedback);
141  SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedbackRotation);
142  SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedbackSep);
143  SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedbackSwitch);
144  SO_KIT_CATALOG_ENTRY_HEADER(translator1);
145  SO_KIT_CATALOG_ENTRY_HEADER(translator1Active);
146  SO_KIT_CATALOG_ENTRY_HEADER(translator1LocateGroup);
147  SO_KIT_CATALOG_ENTRY_HEADER(translator1Switch);
148  SO_KIT_CATALOG_ENTRY_HEADER(translator2);
149  SO_KIT_CATALOG_ENTRY_HEADER(translator2Active);
150  SO_KIT_CATALOG_ENTRY_HEADER(translator2LocateGroup);
151  SO_KIT_CATALOG_ENTRY_HEADER(translator2Switch);
152  SO_KIT_CATALOG_ENTRY_HEADER(translator3);
153  SO_KIT_CATALOG_ENTRY_HEADER(translator3Active);
154  SO_KIT_CATALOG_ENTRY_HEADER(translator3LocateGroup);
155  SO_KIT_CATALOG_ENTRY_HEADER(translator3Switch);
156  SO_KIT_CATALOG_ENTRY_HEADER(translator4);
157  SO_KIT_CATALOG_ENTRY_HEADER(translator4Active);
158  SO_KIT_CATALOG_ENTRY_HEADER(translator4LocateGroup);
159  SO_KIT_CATALOG_ENTRY_HEADER(translator4Switch);
160  SO_KIT_CATALOG_ENTRY_HEADER(translator5);
161  SO_KIT_CATALOG_ENTRY_HEADER(translator5Active);
162  SO_KIT_CATALOG_ENTRY_HEADER(translator5LocateGroup);
163  SO_KIT_CATALOG_ENTRY_HEADER(translator5Switch);
164  SO_KIT_CATALOG_ENTRY_HEADER(translator6);
165  SO_KIT_CATALOG_ENTRY_HEADER(translator6Active);
166  SO_KIT_CATALOG_ENTRY_HEADER(translator6LocateGroup);
167  SO_KIT_CATALOG_ENTRY_HEADER(translator6Switch);
168  SO_KIT_CATALOG_ENTRY_HEADER(translatorSep);
169  SO_KIT_CATALOG_ENTRY_HEADER(xAxisFeedbackActive);
170  SO_KIT_CATALOG_ENTRY_HEADER(xAxisFeedbackSelect);
171  SO_KIT_CATALOG_ENTRY_HEADER(xAxisFeedbackSwitch);
172  SO_KIT_CATALOG_ENTRY_HEADER(xCircleFeedback);
173  SO_KIT_CATALOG_ENTRY_HEADER(xCircleFeedbackSwitch);
174  SO_KIT_CATALOG_ENTRY_HEADER(xCrosshairFeedback);
175  SO_KIT_CATALOG_ENTRY_HEADER(yAxisFeedbackActive);
176  SO_KIT_CATALOG_ENTRY_HEADER(yAxisFeedbackSelect);
177  SO_KIT_CATALOG_ENTRY_HEADER(yAxisFeedbackSwitch);
178  SO_KIT_CATALOG_ENTRY_HEADER(yCircleFeedback);
179  SO_KIT_CATALOG_ENTRY_HEADER(yCircleFeedbackSwitch);
180  SO_KIT_CATALOG_ENTRY_HEADER(yCrosshairFeedback);
181  SO_KIT_CATALOG_ENTRY_HEADER(zAxisFeedbackActive);
182  SO_KIT_CATALOG_ENTRY_HEADER(zAxisFeedbackSelect);
183  SO_KIT_CATALOG_ENTRY_HEADER(zAxisFeedbackSwitch);
184  SO_KIT_CATALOG_ENTRY_HEADER(zCircleFeedback);
185  SO_KIT_CATALOG_ENTRY_HEADER(zCircleFeedbackSwitch);
186  SO_KIT_CATALOG_ENTRY_HEADER(zCrosshairFeedback);
187 
188 public:
189  static void initClass(void);
190  SoTransformerDragger(void);
191 
195  SoSFFloat minDiscRotDot;
196 
197  enum State {
198  INACTIVE,
199 
200  RIT_X_ROTATE,
201  TOP_Y_ROTATE,
202  FNT_Z_ROTATE,
203  LFT_X_ROTATE,
204  BOT_Y_ROTATE,
205  BAK_Z_ROTATE,
206 
207  PX_PY_PZ_3D_SCALE,
208  PX_PY_NZ_3D_SCALE,
209  PX_NY_PZ_3D_SCALE,
210  PX_NY_NZ_3D_SCALE,
211  NX_PY_PZ_3D_SCALE,
212  NX_PY_NZ_3D_SCALE,
213  NX_NY_PZ_3D_SCALE,
214  NX_NY_NZ_3D_SCALE,
215 
216  RIT_TRANSLATE,
217  TOP_TRANSLATE,
218  FNT_TRANSLATE,
219  LFT_TRANSLATE,
220  BOT_TRANSLATE,
221  BAK_TRANSLATE
222  };
223 
224  State getCurrentState(void);
225 
226  void unsquishKnobs(void);
227 
228  SbBool isLocateHighlighting(void);
229  void setLocateHighlighting(SbBool onoff);
230 
231  static void setColinearThreshold(int newval);
232  static int getColinearThreshold(void);
233 
234  SbVec3f getBoxPointInWorldSpace(const SbVec3f & pointonunitbox);
235  SbVec3f getBoxDirInWorldSpace(const SbVec3f & dironunitbox);
236  SbVec3f getWorldPointInBoxSpace(const SbVec3f & pointinworldspace);
237  SbVec2f getWorldPointInPixelSpace(const SbVec3f & thepoint);
238 
239  SbVec3f getInteractiveCenterInBoxSpace(void);
240 
241 protected:
242  virtual ~SoTransformerDragger(void);
243  virtual SbBool setUpConnections(SbBool onoff, SbBool doitalways = FALSE);
244  virtual void setDefaultOnNonWritingFields(void);
245 
246  static void startCB(void * f, SoDragger * d);
247  static void motionCB(void * f, SoDragger * d);
248  static void finishCB(void * f, SoDragger * d);
249  static void metaKeyChangeCB(void *, SoDragger *);
250  static void fieldSensorCB(void * f, SoSensor * s);
251  static void valueChangedCB(void * f, SoDragger * d);
252 
253  void dragStart(void);
254  void drag(void);
255  void dragFinish(void);
256 
257  void updateAntiSquishList(void);
258  void setAllPartSwitches(int scalewhich, int rotatewhich, int translatewhich);
259  int getMouseGestureDirection(SbBool x_ok, SbBool y_ok, SbBool z_ok);
260  static int getIgnoreAxis(SbVec2f axis[3][2],
261  SbBool x_ok, SbBool y_ok, SbBool z_ok);
262  static void makeMinorAxisPerpendicularIfColinear(SbVec2f origin, SbVec2f axisends[3][2], int index_a, int index_b);
263  static SbBool isColinear(SbVec2f a1[2], SbVec2f a2[2], int pixels);
264 
269 
270 private:
271  void getSurroundScaleMatrices(SbMatrix &matrix, SbMatrix &inv);
272  SoNode *getNodeFieldNode(const char *fieldname);
273 
274  void build_catalog1(void);
275  void build_catalog2(void);
276  void build_catalog3(void);
277  void build_catalog4(void);
278  void build_catalog5(void);
279  void build_catalog6(void);
280 
281  SbMatrix getWorkingToWorldMatrix(void);
282  SbMatrix getWorldToWorkingMatrix(void);
283  SbVec3f localToWorking(const SbVec3f &v);
284  SbVec3f workingToLocal(const SbVec3f &v);
285  SbVec3f calcCtrlOffset(const SbVec3f &startpt);
286  void setSwitchValue(const char *str, const int which);
287 
288  SbBool setDynamicTranslatorSwitches(const SoEvent *event);
289  SbBool setDynamicRotatorSwitches(const SoEvent *event);
290  SbBool setDynamicScaleSwitches(const SoEvent *event);
291 
292  void dragTranslate();
293  void dragScale();
294  void dragRotate();
295 
296  class SbPlaneProjector *planeProj;
297  class SbLineProjector *lineProj;
298  class SbSphereProjector *sphereProj;
299  class SbCylinderProjector *cylProj;
300 
301  State state;
302 
303 private:
305  friend class SoTransformerDraggerP;
306 
307  // NOT IMPLEMENTED:
309  SoTransformerDragger & operator = (const SoTransformerDragger & rhs);
310 }; // SoTransformerDragger
311 
312 #endif // !COIN_SOTRANSFORMERDRAGGER_H
The SbVec2f class is a 2 dimensional vector with floating point coordinates.
Definition: SbVec2f.h:49
The SoTransformerDragger provides geometry for translation, scaling and rotations.
Definition: SoTransformerDragger.h:47
static void fieldSensorCB(void *, SoSensor *)
Definition: SoInteractionKit.cpp:752
The SoSFRotation class is a container for an SbRotation.
Definition: SoSFRotation.h:40
static void setSwitchValue(SoNode *node, const int newVal)
Definition: SoInteractionKit.cpp:385
SoFieldSensor * scaleFieldSensor
Definition: SoTransformerDragger.h:266
The SbSphereProjector class is the abstract base class for mapping to spherical surfaces.
Definition: SbSphereProjector.h:40
The SoNode class is the base class for nodes used in scene graphs.
Definition: SoNode.h:56
The SoInteractionKit class is a base class for draggers.
Definition: SoInteractionKit.h:50
SoNodeList antiSquishList
Definition: SoTransformerDragger.h:268
SoSFRotation rotation
Definition: SoTransformerDragger.h:192
The SoDragger class is the base class for all draggers.
Definition: SoDragger.h:64
The SoSensor class is the abstract base class for all sensors.
Definition: SoSensor.h:43
static void initClass(void)
Definition: SoDragger.cpp:409
The SbVec3f class is a 3 dimensional vector with floating point coordinates.
Definition: SbVec3f.h:51
SoFieldSensor * translFieldSensor
Definition: SoTransformerDragger.h:265
The SoFieldSensor class detects changes to a field.
Definition: SoFieldSensor.h:38
SoFieldSensor * rotateFieldSensor
Definition: SoTransformerDragger.h:267
The SbMatrix class is a 4x4 dimensional representation of a matrix.
Definition: SbMatrix.h:47
The SbPlaneProjector class projects 2D points to 3D points in a plane.
Definition: SbPlaneProjector.h:40
State
Definition: SoTransformerDragger.h:197
The SoSFFloat class is a container for a floating point value.
Definition: SoSFFloat.h:39
The SoNodeList class is a container for pointers to SoNode objects.
Definition: SoNodeList.h:40
The SoEvent class is the base class for all Coin events.
Definition: SoEvent.h:45
The SoSFVec3f class is a container for an SbVec3f vector.
Definition: SoSFVec3f.h:40
The SbLineProjector class projects 2D points to 3D points along a line.
Definition: SbLineProjector.h:41
virtual SbBool setUpConnections(SbBool onoff, SbBool doitalways=FALSE)
Definition: SoInteractionKit.cpp:675
SoSFVec3f translation
Definition: SoTransformerDragger.h:193
SoSFVec3f scaleFactor
Definition: SoTransformerDragger.h:194
The SbCylinderProjector class is the abstract base class for mapping to cylindrical surfaces...
Definition: SbCylinderProjector.h:39
virtual void setDefaultOnNonWritingFields(void)
Definition: SoDragger.cpp:1829