| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
/* |
| 38 |
* Copyright (C) 1990,91,92 Silicon Graphics, Inc. |
| 39 |
* |
| 40 |
_______________________________________________________________________ |
| 41 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 42 |
| |
| 43 |
| $Revision: 1.1.1.1 $ |
| 44 |
| |
| 45 |
| Classes: |
| 46 |
| SoJackDragger |
| 47 |
| |
| 48 |
| Author(s): Paul Isaacs, Howard Look |
| 49 |
| |
| 50 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 51 |
_______________________________________________________________________ |
| 52 |
*/ |
| 53 |
|
| 54 |
|
| 55 |
#include <cstdio> |
| 56 |
#include <Inventor/SbLinear.h> |
| 57 |
#include <Inventor/SoDB.h> |
| 58 |
#include <Inventor/sensors/SoFieldSensor.h> |
| 59 |
|
| 60 |
#include <Inventor/nodes/SoSurroundScale.h> |
| 61 |
#include <Inventor/nodes/SoAntiSquish.h> |
| 62 |
#include <Inventor/nodes/SoTransform.h> |
| 63 |
|
| 64 |
#include <Inventor/draggers/SoDragPointDragger.h> |
| 65 |
#include <Inventor/draggers/SoJackDragger.h> |
| 66 |
#include <Inventor/draggers/SoRotateSphericalDragger.h> |
| 67 |
#include <Inventor/draggers/SoScaleUniformDragger.h> |
| 68 |
|
| 69 |
#include "geom/SoJackDraggerGeom.h" |
| 70 |
|
| 71 |
|
| 72 |
SO_KIT_SOURCE(SoJackDragger); |
| 73 |
|
| 74 |
|
| 75 |
//////////////////////////////////////////////////////////////////////// |
| 76 |
// |
| 77 |
// Description: |
| 78 |
// Constructors. Each constructor calls constructorSub(), which |
| 79 |
// does work that is common to each. |
| 80 |
// |
| 81 |
// Use: public |
| 82 |
// |
| 83 |
//////////////////////////////////////////////////////////////////////// |
| 84 |
|
| 85 |
// Default constructor. |
| 86 |
SoJackDragger::SoJackDragger() |
| 87 |
{ |
| 88 |
SO_KIT_CONSTRUCTOR(SoJackDragger); |
| 89 |
|
| 90 |
isBuiltIn = TRUE; |
| 91 |
|
| 92 |
// Don't create this by default. It's only really put into use |
| 93 |
// if this dragger is put inside a manipulator. |
| 94 |
SO_KIT_ADD_CATALOG_ENTRY(surroundScale, SoSurroundScale, |
| 95 |
TRUE, topSeparator, geomSeparator,TRUE); |
| 96 |
// Create an anti-squish node by default. |
| 97 |
SO_KIT_ADD_CATALOG_ENTRY(antiSquish, SoAntiSquish, |
| 98 |
FALSE, topSeparator, geomSeparator,TRUE); |
| 99 |
|
| 100 |
SO_KIT_ADD_CATALOG_ENTRY(scaler, SoScaleUniformDragger, |
| 101 |
TRUE, topSeparator, geomSeparator,TRUE); |
| 102 |
SO_KIT_ADD_CATALOG_ENTRY(rotator, SoRotateSphericalDragger, |
| 103 |
TRUE, topSeparator, geomSeparator,TRUE); |
| 104 |
SO_KIT_ADD_CATALOG_ENTRY(translator, SoDragPointDragger, |
| 105 |
TRUE, topSeparator, geomSeparator,TRUE); |
| 106 |
|
| 107 |
// Read the default geometry for this dragger |
| 108 |
if (SO_KIT_IS_FIRST_INSTANCE()) |
| 109 |
readDefaultParts( "jackDragger.iv", geomBuffer, sizeof(geomBuffer) ); |
| 110 |
|
| 111 |
SO_KIT_ADD_FIELD(rotation, (0.0, 0.0, 0.0, 1.0)); |
| 112 |
SO_KIT_ADD_FIELD(translation, (0.0, 0.0, 0.0)); |
| 113 |
SO_KIT_ADD_FIELD(scaleFactor, (1.0, 1.0, 1.0)); |
| 114 |
|
| 115 |
SO_KIT_INIT_INSTANCE(); |
| 116 |
|
| 117 |
// Make the anti-squish node surround the biggest dimension |
| 118 |
SoAntiSquish *as = SO_GET_ANY_PART( this,"antiSquish", SoAntiSquish ); |
| 119 |
as->sizing = SoAntiSquish::BIGGEST_DIMENSION; |
| 120 |
|
| 121 |
// CREATE THE CHILD DRAGGERS: |
| 122 |
SoDragger *sD = SO_GET_ANY_PART( this,"scaler", SoScaleUniformDragger ); |
| 123 |
SoDragger *rD = SO_GET_ANY_PART( this,"rotator", SoRotateSphericalDragger ); |
| 124 |
SoDragger *tD = SO_GET_ANY_PART( this,"translator", SoDragPointDragger ); |
| 125 |
|
| 126 |
// Update the rotation and scale fields when the motionMatrix is set. |
| 127 |
addValueChangedCallback( &SoJackDragger::valueChangedCB ); |
| 128 |
|
| 129 |
// Updates the motionMatrix when the scaleFactor field is set. |
| 130 |
rotFieldSensor = new SoFieldSensor(&SoJackDragger::fieldSensorCB, this); |
| 131 |
rotFieldSensor->setPriority( 0 ); |
| 132 |
|
| 133 |
// Updates the motionMatrix when the translationFactor field is set. |
| 134 |
translFieldSensor |
| 135 |
= new SoFieldSensor( &SoJackDragger::fieldSensorCB, this); |
| 136 |
translFieldSensor->setPriority( 0 ); |
| 137 |
|
| 138 |
// Updates the motionMatrix when the scaleFactor field is set. |
| 139 |
scaleFieldSensor |
| 140 |
= new SoFieldSensor( &SoJackDragger::fieldSensorCB, this); |
| 141 |
scaleFieldSensor->setPriority( 0 ); |
| 142 |
|
| 143 |
setUpConnections( TRUE, TRUE ); |
| 144 |
} |
| 145 |
|
| 146 |
//////////////////////////////////////////////////////////////////////// |
| 147 |
// |
| 148 |
// Description: |
| 149 |
// Destructor |
| 150 |
// |
| 151 |
SoJackDragger::~SoJackDragger() |
| 152 |
// |
| 153 |
//////////////////////////////////////////////////////////////////////// |
| 154 |
{ |
| 155 |
if (rotFieldSensor) |
| 156 |
delete rotFieldSensor; |
| 157 |
if (translFieldSensor ) |
| 158 |
delete translFieldSensor; |
| 159 |
if (scaleFieldSensor ) |
| 160 |
delete scaleFieldSensor; |
| 161 |
} |
| 162 |
|
| 163 |
// detach/attach any sensors, callbacks, and/or field connections. |
| 164 |
// Called by: start/end of SoBaseKit::readInstance |
| 165 |
// and on new copy by: start/end of SoBaseKit::copy. |
| 166 |
// Classes that redefine must call setUpConnections(TRUE,TRUE) |
| 167 |
// at end of constructor. |
| 168 |
// Returns the state of the node when this was called. |
| 169 |
SbBool |
| 170 |
SoJackDragger::setUpConnections( SbBool onOff, SbBool doItAlways ) |
| 171 |
{ |
| 172 |
if ( !doItAlways && connectionsSetUp == onOff) |
| 173 |
return onOff; |
| 174 |
|
| 175 |
if ( onOff ) { |
| 176 |
|
| 177 |
// We connect AFTER base class. |
| 178 |
SoDragger::setUpConnections( onOff, FALSE ); |
| 179 |
|
| 180 |
// Set up the parts and callbacks in the child dragger |
| 181 |
// Create a scaling dragger. |
| 182 |
SoDragger *sD = (SoDragger *) getAnyPart( "scaler", FALSE); |
| 183 |
if (sD) { |
| 184 |
sD->setPartAsDefault("scaler", "jackScalerScaler" ); |
| 185 |
sD->setPartAsDefault("scalerActive", "jackScalerScalerActive"); |
| 186 |
sD->setPartAsDefault("feedback", "jackScalerFeedback" ); |
| 187 |
sD->setPartAsDefault("feedbackActive", "jackScalerFeedbackActive"); |
| 188 |
sD->addStartCallback( |
| 189 |
&SoJackDragger::invalidateSurroundScaleCB, this); |
| 190 |
sD->addFinishCallback( |
| 191 |
&SoJackDragger::invalidateSurroundScaleCB,this); |
| 192 |
registerChildDragger( sD ); |
| 193 |
} |
| 194 |
|
| 195 |
// Create a spherical rotator. |
| 196 |
SoDragger *rD = (SoDragger *) getAnyPart( "rotator", FALSE ); |
| 197 |
if (rD) { |
| 198 |
rD->setPartAsDefault("rotator", "jackRotatorRotator" ); |
| 199 |
rD->setPartAsDefault("rotatorActive", "jackRotatorRotatorActive"); |
| 200 |
rD->setPartAsDefault("feedback", "jackRotatorFeedback" ); |
| 201 |
rD->setPartAsDefault("feedbackActive", "jackRotatorFeedbackActive"); |
| 202 |
rD->addStartCallback( |
| 203 |
&SoJackDragger::invalidateSurroundScaleCB, this); |
| 204 |
rD->addFinishCallback( |
| 205 |
&SoJackDragger::invalidateSurroundScaleCB,this); |
| 206 |
registerChildDragger( rD ); |
| 207 |
} |
| 208 |
|
| 209 |
// Create a translator with dragpoint. |
| 210 |
SoDragger *dD = (SoDragger *) getAnyPart( "translator", FALSE ); |
| 211 |
if (dD) { |
| 212 |
SoNode *n; |
| 213 |
n = SoNode::getByName("jackTranslatorLineTranslator"); |
| 214 |
dD->setPartAsDefault("xTranslator.translator", n ); |
| 215 |
dD->setPartAsDefault("yTranslator.translator", n ); |
| 216 |
dD->setPartAsDefault("zTranslator.translator", n ); |
| 217 |
|
| 218 |
n = SoNode::getByName("jackTranslatorLineTranslatorActive"); |
| 219 |
dD->setPartAsDefault("xTranslator.translatorActive", n ); |
| 220 |
dD->setPartAsDefault("yTranslator.translatorActive", n ); |
| 221 |
dD->setPartAsDefault("zTranslator.translatorActive", n ); |
| 222 |
|
| 223 |
n = SoNode::getByName("jackTranslatorPlaneTranslator"); |
| 224 |
dD->setPartAsDefault("yzTranslator.translator", n ); |
| 225 |
dD->setPartAsDefault("xzTranslator.translator", n ); |
| 226 |
dD->setPartAsDefault("xyTranslator.translator", n ); |
| 227 |
|
| 228 |
n = SoNode::getByName("jackTranslatorPlaneTranslatorActive"); |
| 229 |
dD->setPartAsDefault("yzTranslator.translatorActive", n ); |
| 230 |
dD->setPartAsDefault("xzTranslator.translatorActive", n ); |
| 231 |
dD->setPartAsDefault("xyTranslator.translatorActive", n ); |
| 232 |
|
| 233 |
dD->setPartAsDefault("xFeedback", "jackTranslatorXFeedback" ); |
| 234 |
dD->setPartAsDefault("yFeedback", "jackTranslatorYFeedback"); |
| 235 |
dD->setPartAsDefault("zFeedback", "jackTranslatorZFeedback" ); |
| 236 |
dD->setPartAsDefault("yzFeedback", "jackTranslatorYZFeedback" ); |
| 237 |
dD->setPartAsDefault("xzFeedback", "jackTranslatorXZFeedback" ); |
| 238 |
dD->setPartAsDefault("xyFeedback", "jackTranslatorXYFeedback" ); |
| 239 |
|
| 240 |
dD->addStartCallback( |
| 241 |
&SoJackDragger::invalidateSurroundScaleCB, this); |
| 242 |
dD->addFinishCallback( |
| 243 |
&SoJackDragger::invalidateSurroundScaleCB,this); |
| 244 |
|
| 245 |
registerChildDragger( dD ); |
| 246 |
} |
| 247 |
|
| 248 |
// Call the sensor CBs to make things are up-to-date. |
| 249 |
fieldSensorCB( this, NULL ); |
| 250 |
|
| 251 |
// Connect the field sensors |
| 252 |
if (rotFieldSensor->getAttachedField() != &rotation) |
| 253 |
rotFieldSensor->attach( &rotation ); |
| 254 |
if (translFieldSensor->getAttachedField() != &translation) |
| 255 |
translFieldSensor->attach( &translation ); |
| 256 |
if (scaleFieldSensor->getAttachedField() != &scaleFactor) |
| 257 |
scaleFieldSensor->attach( &scaleFactor ); |
| 258 |
} |
| 259 |
else { |
| 260 |
|
| 261 |
// We disconnect BEFORE base class. |
| 262 |
|
| 263 |
// Set up the parts and callbacks in the child dragger |
| 264 |
// Create a scaling dragger. |
| 265 |
SoDragger *sD = (SoDragger *) getAnyPart( "scaler", FALSE); |
| 266 |
if (sD) { |
| 267 |
sD->removeStartCallback( |
| 268 |
&SoJackDragger::invalidateSurroundScaleCB, this); |
| 269 |
sD->removeFinishCallback( |
| 270 |
&SoJackDragger::invalidateSurroundScaleCB,this); |
| 271 |
unregisterChildDragger( sD ); |
| 272 |
} |
| 273 |
|
| 274 |
// Create a spherical rotator. |
| 275 |
SoDragger *rD = (SoDragger *) getAnyPart( "rotator", FALSE ); |
| 276 |
if (rD) { |
| 277 |
rD->removeStartCallback( |
| 278 |
&SoJackDragger::invalidateSurroundScaleCB, this); |
| 279 |
rD->removeFinishCallback( |
| 280 |
&SoJackDragger::invalidateSurroundScaleCB,this); |
| 281 |
unregisterChildDragger( rD ); |
| 282 |
} |
| 283 |
|
| 284 |
// Create a translator with dragpoint. |
| 285 |
SoDragger *dD = (SoDragger *) getAnyPart( "translator", FALSE ); |
| 286 |
if (dD) { |
| 287 |
dD->setPartAsDefault("xFeedback", "jackTranslatorXFeedback" ); |
| 288 |
dD->setPartAsDefault("yFeedback", "jackTranslatorYFeedback"); |
| 289 |
dD->setPartAsDefault("zFeedback", "jackTranslatorZFeedback" ); |
| 290 |
dD->setPartAsDefault("yzFeedback", "jackTranslatorYZFeedback" ); |
| 291 |
dD->setPartAsDefault("xzFeedback", "jackTranslatorXZFeedback" ); |
| 292 |
dD->setPartAsDefault("xyFeedback", "jackTranslatorXYFeedback" ); |
| 293 |
|
| 294 |
dD->removeStartCallback( |
| 295 |
&SoJackDragger::invalidateSurroundScaleCB, this); |
| 296 |
dD->removeFinishCallback( |
| 297 |
&SoJackDragger::invalidateSurroundScaleCB,this); |
| 298 |
|
| 299 |
unregisterChildDragger( dD ); |
| 300 |
} |
| 301 |
|
| 302 |
// Disconnect the field sensors. |
| 303 |
if (rotFieldSensor->getAttachedField()) |
| 304 |
rotFieldSensor->detach(); |
| 305 |
if (translFieldSensor->getAttachedField()) |
| 306 |
translFieldSensor->detach(); |
| 307 |
if (scaleFieldSensor->getAttachedField()) |
| 308 |
scaleFieldSensor->detach(); |
| 309 |
|
| 310 |
SoDragger::setUpConnections( onOff, FALSE ); |
| 311 |
} |
| 312 |
|
| 313 |
return !(connectionsSetUp = onOff); |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
void |
| 318 |
SoJackDragger::valueChangedCB( void *, SoDragger *inDragger ) |
| 319 |
{ |
| 320 |
SoJackDragger *m = (SoJackDragger *) inDragger; |
| 321 |
SbMatrix motMat = m->getMotionMatrix(); |
| 322 |
|
| 323 |
SbVec3f trans, scale; |
| 324 |
SbRotation rot, scaleOrient; |
| 325 |
getTransformFast( motMat, trans, rot, scale, scaleOrient); |
| 326 |
|
| 327 |
// Disconnect the field sensors |
| 328 |
m->rotFieldSensor->detach(); |
| 329 |
m->translFieldSensor->detach(); |
| 330 |
m->scaleFieldSensor->detach(); |
| 331 |
|
| 332 |
if ( m->rotation.getValue() != rot ) |
| 333 |
m->rotation = rot; |
| 334 |
if ( m->translation.getValue() != trans ) |
| 335 |
m->translation = trans; |
| 336 |
if ( m->scaleFactor.getValue() != scale ) |
| 337 |
m->scaleFactor = scale; |
| 338 |
|
| 339 |
// Reconnect the field sensors |
| 340 |
m->rotFieldSensor->attach( &(m->rotation) ); |
| 341 |
m->translFieldSensor->attach( &(m->translation) ); |
| 342 |
m->scaleFieldSensor->attach( &(m->scaleFactor) ); |
| 343 |
} |
| 344 |
|
| 345 |
void |
| 346 |
SoJackDragger::fieldSensorCB( void *inDragger, SoSensor * ) |
| 347 |
{ |
| 348 |
SoJackDragger *dragger = (SoJackDragger *) inDragger; |
| 349 |
|
| 350 |
SbMatrix motMat = dragger->getMotionMatrix(); |
| 351 |
dragger->workFieldsIntoTransform( motMat ); |
| 352 |
|
| 353 |
dragger->setMotionMatrix( motMat ); |
| 354 |
} |
| 355 |
|
| 356 |
void |
| 357 |
SoJackDragger::invalidateSurroundScaleCB( void *parentAsVoid, SoDragger * ) |
| 358 |
{ |
| 359 |
SoJackDragger *jD = (SoJackDragger *) parentAsVoid; |
| 360 |
|
| 361 |
// Invalidate the surroundScale, if it exists. |
| 362 |
SoSurroundScale *ss = SO_CHECK_PART(jD, "surroundScale", SoSurroundScale ); |
| 363 |
if (ss != NULL) |
| 364 |
ss->invalidate(); |
| 365 |
} |
| 366 |
|
| 367 |
void |
| 368 |
SoJackDragger::setDefaultOnNonWritingFields() |
| 369 |
{ |
| 370 |
// These nodes may change after construction, but we still |
| 371 |
// don't want to write them out. |
| 372 |
surroundScale.setDefault(TRUE); |
| 373 |
antiSquish.setDefault(TRUE); |
| 374 |
|
| 375 |
// Try not to write out the sub-draggers. |
| 376 |
scaler.setDefault(TRUE); |
| 377 |
rotator.setDefault(TRUE); |
| 378 |
translator.setDefault(TRUE); |
| 379 |
|
| 380 |
// Call the base class... |
| 381 |
SoDragger::setDefaultOnNonWritingFields(); |
| 382 |
} |