Coin Logo http://www.sim.no
http://www.coin3d.org

SoTransformerDragger.h
1 #ifndef COIN_SOTRANSFORMERDRAGGER_H
2 #define COIN_SOTRANSFORMERDRAGGER_H
3 
4 /**************************************************************************\
5  *
6  * This file is part of the Coin 3D visualization library.
7  * Copyright (C) 1998-2007 by Systems in Motion. All rights reserved.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * ("GPL") version 2 as published by the Free Software Foundation.
12  * See the file LICENSE.GPL at the root directory of this source
13  * distribution for additional information about the GNU GPL.
14  *
15  * For using Coin with software that can not be combined with the GNU
16  * GPL, and for taking advantage of the additional benefits of our
17  * support services, please contact Systems in Motion about acquiring
18  * a Coin Professional Edition License.
19  *
20  * See http://www.coin3d.org/ for more information.
21  *
22  * Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
23  * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24  *
25 \**************************************************************************/
26 
27 #include <Inventor/draggers/SoDragger.h>
28 #include <Inventor/fields/SoSFRotation.h>
29 #include <Inventor/fields/SoSFVec3f.h>
30 #include <Inventor/fields/SoSFFloat.h>
31 #include <Inventor/lists/SoNodeList.h>
32 
33 class SoSensor;
34 class SoFieldSensor;
35 
36 
37 class COIN_DLL_API SoTransformerDragger : public SoDragger {
38  typedef SoDragger inherited;
39 
40  SO_KIT_HEADER(SoTransformerDragger);
41 
42  SO_KIT_CATALOG_ENTRY_HEADER(axisFeedbackLocation);
43  SO_KIT_CATALOG_ENTRY_HEADER(axisFeedbackSep);
44  SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackAntiSquish);
45  SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackSep);
46  SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackTransform);
47  SO_KIT_CATALOG_ENTRY_HEADER(circleFeedbackTransformSwitch);
48  SO_KIT_CATALOG_ENTRY_HEADER(negXRoundWallFeedback);
49  SO_KIT_CATALOG_ENTRY_HEADER(negXWallFeedback);
50  SO_KIT_CATALOG_ENTRY_HEADER(negXWallFeedbackSwitch);
51  SO_KIT_CATALOG_ENTRY_HEADER(negYRoundWallFeedback);
52  SO_KIT_CATALOG_ENTRY_HEADER(negYWallFeedback);
53  SO_KIT_CATALOG_ENTRY_HEADER(negYWallFeedbackSwitch);
54  SO_KIT_CATALOG_ENTRY_HEADER(negZRoundWallFeedback);
55  SO_KIT_CATALOG_ENTRY_HEADER(negZWallFeedback);
56  SO_KIT_CATALOG_ENTRY_HEADER(negZWallFeedbackSwitch);
57  SO_KIT_CATALOG_ENTRY_HEADER(overallStyle);
58  SO_KIT_CATALOG_ENTRY_HEADER(posXRoundWallFeedback);
59  SO_KIT_CATALOG_ENTRY_HEADER(posXWallFeedback);
60  SO_KIT_CATALOG_ENTRY_HEADER(posXWallFeedbackSwitch);
61  SO_KIT_CATALOG_ENTRY_HEADER(posYRoundWallFeedback);
62  SO_KIT_CATALOG_ENTRY_HEADER(posYWallFeedback);
63  SO_KIT_CATALOG_ENTRY_HEADER(posYWallFeedbackSwitch);
64  SO_KIT_CATALOG_ENTRY_HEADER(posZRoundWallFeedback);
65  SO_KIT_CATALOG_ENTRY_HEADER(posZWallFeedback);
66  SO_KIT_CATALOG_ENTRY_HEADER(posZWallFeedbackSwitch);
67  SO_KIT_CATALOG_ENTRY_HEADER(radialFeedback);
68  SO_KIT_CATALOG_ENTRY_HEADER(radialFeedbackSwitch);
69  SO_KIT_CATALOG_ENTRY_HEADER(rotator1);
70  SO_KIT_CATALOG_ENTRY_HEADER(rotator1Active);
71  SO_KIT_CATALOG_ENTRY_HEADER(rotator1LocateGroup);
72  SO_KIT_CATALOG_ENTRY_HEADER(rotator1Switch);
73  SO_KIT_CATALOG_ENTRY_HEADER(rotator2);
74  SO_KIT_CATALOG_ENTRY_HEADER(rotator2Active);
75  SO_KIT_CATALOG_ENTRY_HEADER(rotator2LocateGroup);
76  SO_KIT_CATALOG_ENTRY_HEADER(rotator2Switch);
77  SO_KIT_CATALOG_ENTRY_HEADER(rotator3);
78  SO_KIT_CATALOG_ENTRY_HEADER(rotator3Active);
79  SO_KIT_CATALOG_ENTRY_HEADER(rotator3LocateGroup);
80  SO_KIT_CATALOG_ENTRY_HEADER(rotator3Switch);
81  SO_KIT_CATALOG_ENTRY_HEADER(rotator4);
82  SO_KIT_CATALOG_ENTRY_HEADER(rotator4Active);
83  SO_KIT_CATALOG_ENTRY_HEADER(rotator4LocateGroup);
84  SO_KIT_CATALOG_ENTRY_HEADER(rotator4Switch);
85  SO_KIT_CATALOG_ENTRY_HEADER(rotator5);
86  SO_KIT_CATALOG_ENTRY_HEADER(rotator5Active);
87  SO_KIT_CATALOG_ENTRY_HEADER(rotator5LocateGroup);
88  SO_KIT_CATALOG_ENTRY_HEADER(rotator5Switch);
89  SO_KIT_CATALOG_ENTRY_HEADER(rotator6);
90  SO_KIT_CATALOG_ENTRY_HEADER(rotator6Active);
91  SO_KIT_CATALOG_ENTRY_HEADER(rotator6LocateGroup);
92  SO_KIT_CATALOG_ENTRY_HEADER(rotator6Switch);
93  SO_KIT_CATALOG_ENTRY_HEADER(rotatorSep);
94  SO_KIT_CATALOG_ENTRY_HEADER(scale1);
95  SO_KIT_CATALOG_ENTRY_HEADER(scale1Active);
96  SO_KIT_CATALOG_ENTRY_HEADER(scale1LocateGroup);
97  SO_KIT_CATALOG_ENTRY_HEADER(scale1Switch);
98  SO_KIT_CATALOG_ENTRY_HEADER(scale2);
99  SO_KIT_CATALOG_ENTRY_HEADER(scale2Active);
100  SO_KIT_CATALOG_ENTRY_HEADER(scale2LocateGroup);
101  SO_KIT_CATALOG_ENTRY_HEADER(scale2Switch);
102  SO_KIT_CATALOG_ENTRY_HEADER(scale3);
103  SO_KIT_CATALOG_ENTRY_HEADER(scale3Active);
104  SO_KIT_CATALOG_ENTRY_HEADER(scale3LocateGroup);
105  SO_KIT_CATALOG_ENTRY_HEADER(scale3Switch);
106  SO_KIT_CATALOG_ENTRY_HEADER(scale4);
107  SO_KIT_CATALOG_ENTRY_HEADER(scale4Active);
108  SO_KIT_CATALOG_ENTRY_HEADER(scale4LocateGroup);
109  SO_KIT_CATALOG_ENTRY_HEADER(scale4Switch);
110  SO_KIT_CATALOG_ENTRY_HEADER(scale5);
111  SO_KIT_CATALOG_ENTRY_HEADER(scale5Active);
112  SO_KIT_CATALOG_ENTRY_HEADER(scale5LocateGroup);
113  SO_KIT_CATALOG_ENTRY_HEADER(scale5Switch);
114  SO_KIT_CATALOG_ENTRY_HEADER(scale6);
115  SO_KIT_CATALOG_ENTRY_HEADER(scale6Active);
116  SO_KIT_CATALOG_ENTRY_HEADER(scale6LocateGroup);
117  SO_KIT_CATALOG_ENTRY_HEADER(scale6Switch);
118  SO_KIT_CATALOG_ENTRY_HEADER(scale7);
119  SO_KIT_CATALOG_ENTRY_HEADER(scale7Active);
120  SO_KIT_CATALOG_ENTRY_HEADER(scale7LocateGroup);
121  SO_KIT_CATALOG_ENTRY_HEADER(scale7Switch);
122  SO_KIT_CATALOG_ENTRY_HEADER(scale8);
123  SO_KIT_CATALOG_ENTRY_HEADER(scale8Active);
124  SO_KIT_CATALOG_ENTRY_HEADER(scale8LocateGroup);
125  SO_KIT_CATALOG_ENTRY_HEADER(scale8Switch);
126  SO_KIT_CATALOG_ENTRY_HEADER(scaleBoxFeedback);
127  SO_KIT_CATALOG_ENTRY_HEADER(scaleBoxFeedbackSwitch);
128  SO_KIT_CATALOG_ENTRY_HEADER(scaleSep);
129  SO_KIT_CATALOG_ENTRY_HEADER(surroundScale);
130  SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedback);
131  SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedbackRotation);
132  SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedbackSep);
133  SO_KIT_CATALOG_ENTRY_HEADER(translateBoxFeedbackSwitch);
134  SO_KIT_CATALOG_ENTRY_HEADER(translator1);
135  SO_KIT_CATALOG_ENTRY_HEADER(translator1Active);
136  SO_KIT_CATALOG_ENTRY_HEADER(translator1LocateGroup);
137  SO_KIT_CATALOG_ENTRY_HEADER(translator1Switch);
138  SO_KIT_CATALOG_ENTRY_HEADER(translator2);
139  SO_KIT_CATALOG_ENTRY_HEADER(translator2Active);
140  SO_KIT_CATALOG_ENTRY_HEADER(translator2LocateGroup);
141  SO_KIT_CATALOG_ENTRY_HEADER(translator2Switch);
142  SO_KIT_CATALOG_ENTRY_HEADER(translator3);
143  SO_KIT_CATALOG_ENTRY_HEADER(translator3Active);
144  SO_KIT_CATALOG_ENTRY_HEADER(translator3LocateGroup);
145  SO_KIT_CATALOG_ENTRY_HEADER(translator3Switch);
146  SO_KIT_CATALOG_ENTRY_HEADER(translator4);
147  SO_KIT_CATALOG_ENTRY_HEADER(translator4Active);
148  SO_KIT_CATALOG_ENTRY_HEADER(translator4LocateGroup);
149  SO_KIT_CATALOG_ENTRY_HEADER(translator4Switch);
150  SO_KIT_CATALOG_ENTRY_HEADER(translator5);
151  SO_KIT_CATALOG_ENTRY_HEADER(translator5Active);
152  SO_KIT_CATALOG_ENTRY_HEADER(translator5LocateGroup);
153  SO_KIT_CATALOG_ENTRY_HEADER(translator5Switch);
154  SO_KIT_CATALOG_ENTRY_HEADER(translator6);
155  SO_KIT_CATALOG_ENTRY_HEADER(translator6Active);
156  SO_KIT_CATALOG_ENTRY_HEADER(translator6LocateGroup);
157  SO_KIT_CATALOG_ENTRY_HEADER(translator6Switch);
158  SO_KIT_CATALOG_ENTRY_HEADER(translatorSep);
159  SO_KIT_CATALOG_ENTRY_HEADER(xAxisFeedbackActive);
160  SO_KIT_CATALOG_ENTRY_HEADER(xAxisFeedbackSelect);
161  SO_KIT_CATALOG_ENTRY_HEADER(xAxisFeedbackSwitch);
162  SO_KIT_CATALOG_ENTRY_HEADER(xCircleFeedback);
163  SO_KIT_CATALOG_ENTRY_HEADER(xCircleFeedbackSwitch);
164  SO_KIT_CATALOG_ENTRY_HEADER(xCrosshairFeedback);
165  SO_KIT_CATALOG_ENTRY_HEADER(yAxisFeedbackActive);
166  SO_KIT_CATALOG_ENTRY_HEADER(yAxisFeedbackSelect);
167  SO_KIT_CATALOG_ENTRY_HEADER(yAxisFeedbackSwitch);
168  SO_KIT_CATALOG_ENTRY_HEADER(yCircleFeedback);
169  SO_KIT_CATALOG_ENTRY_HEADER(yCircleFeedbackSwitch);
170  SO_KIT_CATALOG_ENTRY_HEADER(yCrosshairFeedback);
171  SO_KIT_CATALOG_ENTRY_HEADER(zAxisFeedbackActive);
172  SO_KIT_CATALOG_ENTRY_HEADER(zAxisFeedbackSelect);
173  SO_KIT_CATALOG_ENTRY_HEADER(zAxisFeedbackSwitch);
174  SO_KIT_CATALOG_ENTRY_HEADER(zCircleFeedback);
175  SO_KIT_CATALOG_ENTRY_HEADER(zCircleFeedbackSwitch);
176  SO_KIT_CATALOG_ENTRY_HEADER(zCrosshairFeedback);
177 
178 
179 public:
180  static void initClass(void);
181  SoTransformerDragger(void);
182 
186  SoSFFloat minDiscRotDot;
187 
188  enum State {
189  INACTIVE,
190 
191  RIT_X_ROTATE,
192  TOP_Y_ROTATE,
193  FNT_Z_ROTATE,
194  LFT_X_ROTATE,
195  BOT_Y_ROTATE,
196  BAK_Z_ROTATE,
197 
198  PX_PY_PZ_3D_SCALE,
199  PX_PY_NZ_3D_SCALE,
200  PX_NY_PZ_3D_SCALE,
201  PX_NY_NZ_3D_SCALE,
202  NX_PY_PZ_3D_SCALE,
203  NX_PY_NZ_3D_SCALE,
204  NX_NY_PZ_3D_SCALE,
205  NX_NY_NZ_3D_SCALE,
206 
207  RIT_TRANSLATE,
208  TOP_TRANSLATE,
209  FNT_TRANSLATE,
210  LFT_TRANSLATE,
211  BOT_TRANSLATE,
212  BAK_TRANSLATE
213  };
214 
215  State getCurrentState(void);
216 
217  void unsquishKnobs(void);
218 
219  SbBool isLocateHighlighting(void);
220  void setLocateHighlighting(SbBool onoff);
221 
222  static void setColinearThreshold(int newval);
223  static int getColinearThreshold(void);
224 
225  SbVec3f getBoxPointInWorldSpace(const SbVec3f & pointonunitbox);
226  SbVec3f getBoxDirInWorldSpace(const SbVec3f & dironunitbox);
227  SbVec3f getWorldPointInBoxSpace(const SbVec3f & pointinworldspace);
228  SbVec2f getWorldPointInPixelSpace(const SbVec3f & thepoint);
229 
230  SbVec3f getInteractiveCenterInBoxSpace(void);
231 
232 protected:
234  virtual SbBool setUpConnections(SbBool onoff, SbBool doitalways = FALSE);
235  virtual void setDefaultOnNonWritingFields(void);
236 
237  static void startCB(void * f, SoDragger * d);
238  static void motionCB(void * f, SoDragger * d);
239  static void finishCB(void * f, SoDragger * d);
240  static void metaKeyChangeCB(void *, SoDragger *);
241  static void fieldSensorCB(void * f, SoSensor * s);
242  static void valueChangedCB(void * f, SoDragger * d);
243 
244  void dragStart(void);
245  void drag(void);
246  void dragFinish(void);
247 
248  void updateAntiSquishList(void);
249  void setAllPartSwitches(int scalewhich, int rotatewhich, int translatewhich);
250  int getMouseGestureDirection(SbBool x_ok, SbBool y_ok, SbBool z_ok);
251  static int getIgnoreAxis(SbVec2f axis[3][2],
252  SbBool x_ok, SbBool y_ok, SbBool z_ok);
253  static void makeMinorAxisPerpendicularIfColinear(SbVec2f origin, SbVec2f axisends[3][2], int index_a, int index_b);
254  static SbBool isColinear(SbVec2f a1[2], SbVec2f a2[2], int pixels);
255 
260 
261 private:
262  void getSurroundScaleMatrices(SbMatrix &matrix, SbMatrix &inv);
263  SoNode *getNodeFieldNode(const char *fieldname);
264 
265  void build_catalog1(void);
266  void build_catalog2(void);
267  void build_catalog3(void);
268  void build_catalog4(void);
269  void build_catalog5(void);
270  void build_catalog6(void);
271 
272  SbMatrix getWorkingToWorldMatrix(void);
273  SbMatrix getWorldToWorkingMatrix(void);
274  SbVec3f localToWorking(const SbVec3f &v);
275  SbVec3f workingToLocal(const SbVec3f &v);
276  SbVec3f calcCtrlOffset(const SbVec3f &startpt);
277  void setSwitchValue(const char *str, const int which);
278 
279  SbBool setDynamicTranslatorSwitches(const SoEvent *event);
280  SbBool setDynamicRotatorSwitches(const SoEvent *event);
281  SbBool setDynamicScaleSwitches(const SoEvent *event);
282 
283  void dragTranslate();
284  void dragScale();
285  void dragRotate();
286 
287  class SbPlaneProjector *planeProj;
288  class SbLineProjector *lineProj;
289  class SbSphereProjector *sphereProj;
290  class SbCylinderProjector *cylProj;
291 
292  State state;
293 
294  class SoTransformerDraggerP * pimpl;
295  friend class SoTransformerDraggerP;
296 };
297 
298 #endif // !COIN_SOTRANSFORMERDRAGGER_H
The SbVec2f class is a 2 dimensional vector with floating point coordinates.
Definition: SbVec2f.h:36
The SoTransformerDragger provides geometry for translation, scaling and rotations.Here&#39;s how the dragger looks with its default geometry in the inactive state:
Definition: SoTransformerDragger.h:37
static void fieldSensorCB(void *, SoSensor *)
Definition: SoInteractionKit.cpp:725
The SoSFRotation class is a container for an SbRotation.This field is used where nodes, engines or other field containers needs to store a single rotation definition.
Definition: SoSFRotation.h:31
static void setSwitchValue(SoNode *node, const int newVal)
Definition: SoInteractionKit.cpp:358
SoFieldSensor * scaleFieldSensor
Definition: SoTransformerDragger.h:257
The SbSphereProjector class is the abstract base class for mapping to spherical surfaces.The sphere projectors map 2D points to various surface types based on spherical shapes.
Definition: SbSphereProjector.h:31
The SoNode class is the base class for nodes used in scene graphs.Coin is a retained mode 3D visualiz...
Definition: SoNode.h:47
The SoInteractionKit class is a base class for draggers.This nodekit class makes it possible to set s...
Definition: SoInteractionKit.h:41
SoNodeList antiSquishList
Definition: SoTransformerDragger.h:259
SoSFRotation rotation
Definition: SoTransformerDragger.h:183
The SoDragger class is the base class for all draggers.Draggers is a mechanism used for letting the e...
Definition: SoDragger.h:53
The SoSensor class is the abstract base class for all sensors.Sensors is a mechanism in Coin for sche...
Definition: SoSensor.h:34
static void initClass(void)
Definition: SoDragger.cpp:388
virtual SbBool setUpConnections(SbBool onoff, SbBool doitalways=0)
Definition: SoInteractionKit.cpp:648
The SbVec3f class is a 3 dimensional vector with floating point coordinates.
Definition: SbVec3f.h:37
SoFieldSensor * translFieldSensor
Definition: SoTransformerDragger.h:256
The SoFieldSensor class detects changes to a field.Attach a field to a sensor of this type to put it ...
Definition: SoFieldSensor.h:29
SoFieldSensor * rotateFieldSensor
Definition: SoTransformerDragger.h:258
The SbMatrix class is a 4x4 dimensional representation of a matrix.SbMatrix is used by many other cla...
Definition: SbMatrix.h:37
The SbPlaneProjector class projects 2D points to 3D points in a plane.The 3D projection of the 2D coo...
Definition: SbPlaneProjector.h:31
State
Definition: SoTransformerDragger.h:188
The SoSFFloat class is a container for a floating point value.This field is used where nodes...
Definition: SoSFFloat.h:30
The SoNodeList class is a container for pointers to SoNode objects.As this class inherits SoBaseList...
Definition: SoNodeList.h:31
The SoEvent class is the base class for all Coin events.Coin contains its own set of event classes...
Definition: SoEvent.h:34
The SoSFVec3f class is a container for an SbVec3f vector.This field is used where nodes...
Definition: SoSFVec3f.h:31
The SbLineProjector class projects 2D points to 3D points along a line.The 3D projection of the 2D co...
Definition: SbLineProjector.h:32
SoSFVec3f translation
Definition: SoTransformerDragger.h:184
SoSFVec3f scaleFactor
Definition: SoTransformerDragger.h:185
The SbCylinderProjector class is the abstract base class for mapping to cylindrical surfaces...
Definition: SbCylinderProjector.h:30
virtual void setDefaultOnNonWritingFields(void)
Definition: SoDragger.cpp:1743

Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.

Generated on Fri Jul 20 2018 for Coin by Doxygen. 1.8.14