diff --git a/src/Gui/Inventor/Draggers/SoLinearDragger.cpp b/src/Gui/Inventor/Draggers/SoLinearDragger.cpp index e65b739391..c4c2d99c3c 100644 --- a/src/Gui/Inventor/Draggers/SoLinearDragger.cpp +++ b/src/Gui/Inventor/Draggers/SoLinearDragger.cpp @@ -84,7 +84,6 @@ SoLinearDragger::SoLinearDragger() FC_ADD_CATALOG_ENTRY(secondaryColor, SoBaseColor, activeSwitch); FC_ADD_CATALOG_ENTRY(coneSeparator, SoSeparator, translator); FC_ADD_CATALOG_ENTRY(cylinderSeparator, SoSeparator, translator); - // For some reason changing the whichChild parameter of this switch doesn't hide the label FC_ADD_CATALOG_ENTRY(labelSwitch, SoSwitch, translator); FC_ADD_CATALOG_ENTRY(labelSeparator, SoSeparator, labelSwitch); @@ -101,10 +100,10 @@ SoLinearDragger::SoLinearDragger() SO_KIT_INIT_INSTANCE(); setupGeometryCalculator(); - SoInteractionKit::setPart("cylinderSeparator", buildCylinderGeometry()); - SoInteractionKit::setPart("coneSeparator", buildConeGeometry()); - SoInteractionKit::setPart("labelSeparator", buildLabelGeometry()); - SoInteractionKit::setPart("secondaryColor", buildActiveColor()); + setPart("cylinderSeparator", buildCylinderGeometry()); + setPart("coneSeparator", buildConeGeometry()); + setPart("labelSeparator", buildLabelGeometry()); + setPart("secondaryColor", buildActiveColor()); FC_SET_SWITCH("activeSwitch", SO_SWITCH_NONE); setLabelVisibility(true); @@ -427,8 +426,8 @@ SoLinearDraggerContainer::SoLinearDraggerContainer() SO_KIT_INIT_INSTANCE(); - SoInteractionKit::setPart("baseColor", buildColor()); - SoInteractionKit::setPart("transform", buildTransform()); + setPart("baseColor", buildColor()); + setPart("transform", buildTransform()); setVisibility(true); } diff --git a/src/Gui/Inventor/Draggers/SoRotationDragger.cpp b/src/Gui/Inventor/Draggers/SoRotationDragger.cpp index 3d62d3af52..2bda576f76 100644 --- a/src/Gui/Inventor/Draggers/SoRotationDragger.cpp +++ b/src/Gui/Inventor/Draggers/SoRotationDragger.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #endif #include @@ -55,7 +56,7 @@ #include "SoRotationDragger.h" #include "MainWindow.h" -#include "SoFCDB.h" +#include "Utilities.h" #include @@ -75,30 +76,26 @@ SoRotationDragger::SoRotationDragger() this->ref(); #endif - SO_KIT_ADD_CATALOG_ENTRY(rotatorSwitch, SoSwitch, TRUE, geomSeparator, "", TRUE); - SO_KIT_ADD_CATALOG_ENTRY(rotator, SoSeparator, TRUE, rotatorSwitch, "", TRUE); - SO_KIT_ADD_CATALOG_ENTRY(rotatorActive, SoSeparator, TRUE, rotatorSwitch, "", TRUE); - - arcRadius = 8.0; - - if (SO_KIT_IS_FIRST_INSTANCE()) { - buildFirstInstance(); - } + FC_ADD_CATALOG_ENTRY(activeSwitch, SoSwitch, geomSeparator); + FC_ADD_CATALOG_ENTRY(secondaryColor, SoBaseColor, activeSwitch); + FC_ADD_CATALOG_ENTRY(rotator, SoSeparator, geomSeparator); SO_KIT_ADD_FIELD(rotation, (SbVec3f(0.0, 0.0, 1.0), 0.0)); SO_KIT_ADD_FIELD(rotationIncrement, (std::numbers::pi / 8.0)); SO_KIT_ADD_FIELD(rotationIncrementCount, (0)); + SO_KIT_ADD_FIELD(activeColor, (1, 1, 0)); + SO_KIT_ADD_FIELD(arcRadius, (8.0)); + SO_KIT_ADD_FIELD(arcAngle, (std::numbers::pi_v / 2.0f)); + SO_KIT_ADD_FIELD(sphereRadius, (0.8)); + SO_KIT_ADD_FIELD(arcThickness, (4.0)); SO_KIT_INIT_INSTANCE(); - // initialize default parts. - // first is from 'SO_KIT_CATALOG_ENTRY_HEADER' macro - // second is unique name from buildFirstInstance(). - this->setPartAsDefault("rotator", "CSysDynamics_RDragger_Rotator"); - this->setPartAsDefault("rotatorActive", "CSysDynamics_RDragger_RotatorActive"); + setupGeometryCalculator(); + setPart("secondaryColor", buildActiveColor()); + setPart("rotator", buildGeometry()); - SoSwitch* sw = SO_GET_ANY_PART(this, "rotatorSwitch", SoSwitch); - SoInteractionKit::setSwitchValue(sw, 0); + FC_SET_SWITCH("activeSwitch", SO_SWITCH_NONE); this->addStartCallback(&SoRotationDragger::startCB); this->addMotionCallback(&SoRotationDragger::motionCB); @@ -118,50 +115,28 @@ SoRotationDragger::~SoRotationDragger() fieldSensor.setData(nullptr); fieldSensor.detach(); + arcRadiusSensor.setData(nullptr); + arcRadiusSensor.detach(); + arcAngleSensor.setData(nullptr); + arcAngleSensor.detach(); + this->removeStartCallback(&SoRotationDragger::startCB); this->removeMotionCallback(&SoRotationDragger::motionCB); this->removeFinishCallback(&SoRotationDragger::finishCB); removeValueChangedCallback(&SoRotationDragger::valueChangedCB); } -void SoRotationDragger::buildFirstInstance() +SoSeparator* SoRotationDragger::buildGeometry() { - SoGroup* geometryGroup = buildGeometry(); + auto root = new SoSeparator(); - auto localRotator = new SoSeparator(); - localRotator->setName("CSysDynamics_RDragger_Rotator"); - localRotator->addChild(geometryGroup); - SoFCDB::getStorage()->addChild(localRotator); - - auto localRotatorActive = new SoSeparator(); - localRotatorActive->setName("CSysDynamics_RDragger_RotatorActive"); - auto colorActive = new SoBaseColor(); - colorActive->rgb.setValue(1.0, 1.0, 0.0); - localRotatorActive->addChild(colorActive); - localRotatorActive->addChild(geometryGroup); - SoFCDB::getStorage()->addChild(localRotatorActive); -} - -SoGroup* SoRotationDragger::buildGeometry() -{ - auto root = new SoGroup(); - - // arc auto coordinates = new SoCoordinate3(); - - unsigned int segments = 15; - - float angleIncrement = (std::numbers::pi_v / 2.f) / static_cast(segments); - SbRotation rotation(SbVec3f(0.0, 0.0, 1.0), angleIncrement); - SbVec3f point(arcRadius, 0.0, 0.0); - for (unsigned int index = 0; index <= segments; ++index) { - coordinates->point.set1Value(index, point); - rotation.multVec(point, point); - } + this->coordinates = coordinates; + setupArcSensors(); root->addChild(coordinates); auto drawStyle = new SoDrawStyle(); - drawStyle->lineWidth = 4.0; + drawStyle->lineWidth.connectFrom(&arcThickness); root->addChild(drawStyle); auto lightModel = new SoLightModel(); @@ -178,20 +153,67 @@ SoGroup* SoRotationDragger::buildGeometry() root->addChild(pickStyle); // sphere. - SbVec3f origin(1.0, 1.0, 0.0); - origin.normalize(); - origin *= arcRadius; auto sphereTranslation = new SoTranslation(); - sphereTranslation->translation.setValue(origin); + sphereTranslation->translation.connectFrom(&calculator->oA); root->addChild(sphereTranslation); auto sphere = new SoSphere(); - sphere->radius.setValue(0.8F); + sphere->radius.connectFrom(&sphereRadius); root->addChild(sphere); return root; } +void SoRotationDragger::arcSensorCB(void* userdata, SoSensor*) +{ + auto sudoThis = static_cast(userdata); + assert(sudoThis->coordinates); + auto coordinates = sudoThis->coordinates; + float angleIncrement = sudoThis->arcAngle.getValue() / static_cast(segments); + SbRotation rotation(SbVec3f(0.0, 0.0, 1.0), angleIncrement); + SbVec3f point(sudoThis->arcRadius.getValue(), 0.0, 0.0); + for (unsigned int index = 0; index <= segments; ++index) { + coordinates->point.set1Value(index, point); + rotation.multVec(point, point); + } +} + +SoBaseColor* SoRotationDragger::buildActiveColor() +{ + auto color = new SoBaseColor; + color->rgb.connectFrom(&activeColor); + + return color; +} + +void SoRotationDragger::setupGeometryCalculator() +{ + calculator = new SoCalculator; + // Recalculate the corresponding variables in the left hand side whenever any of the variables in the right hand side change + // oA -> sphereTranslation + // a -> arcRadius + // b -> arcAngle + calculator->expression = "oA = vec3f(a * cos(b / 2), a * sin(b / 2), 0)"; + + calculator->a.connectFrom(&arcRadius); + calculator->b.connectFrom(&arcAngle); +} + +void SoRotationDragger::setupArcSensors() +{ + arcRadiusSensor.setFunction(arcSensorCB); + arcRadiusSensor.setData(this); + arcRadiusSensor.setPriority(0); + arcRadiusSensor.attach(&arcRadius); + arcRadius.touch(); + + arcAngleSensor.setFunction(arcSensorCB); + arcAngleSensor.setData(this); + arcAngleSensor.setPriority(0); + arcAngleSensor.attach(&arcAngle); + arcAngle.touch(); +} + void SoRotationDragger::startCB(void*, SoDragger* d) { auto sudoThis = static_cast(d); @@ -232,10 +254,7 @@ void SoRotationDragger::valueChangedCB(void*, SoDragger* d) assert(sudoThis); SbMatrix matrix = sudoThis->getMotionMatrix(); // clazy:exclude=rule-of-two-soft - // all this just to get the translation? - SbVec3f translationDummy, scaleDummy; - SbRotation localRotation, scaleOrientationDummy; - matrix.getTransform(translationDummy, localRotation, scaleDummy, scaleOrientationDummy); + SbRotation localRotation = getMatrixTransform(matrix).rotation; sudoThis->fieldSensor.detach(); if (sudoThis->rotation.getValue() != localRotation) { @@ -246,9 +265,7 @@ void SoRotationDragger::valueChangedCB(void*, SoDragger* d) void SoRotationDragger::dragStart() { - SoSwitch* sw; - sw = SO_GET_ANY_PART(this, "rotatorSwitch", SoSwitch); - SoInteractionKit::setSwitchValue(sw, 1); + FC_SET_SWITCH("activeSwitch", SO_SWITCH_ALL); projector.setViewVolume(this->getViewVolume()); projector.setWorkingSpace(this->getLocalToWorldMatrix()); @@ -320,9 +337,7 @@ void SoRotationDragger::drag() void SoRotationDragger::dragFinish() { - SoSwitch* sw; - sw = SO_GET_ANY_PART(this, "rotatorSwitch", SoSwitch); - SoInteractionKit::setSwitchValue(sw, 0); + FC_SET_SWITCH("activeSwitch", SO_SWITCH_NONE); } SbBool SoRotationDragger::setUpConnections(SbBool onoff, SbBool doitalways) @@ -365,3 +380,81 @@ int SoRotationDragger::roundIncrement(const float& radiansIn) return rCount; } + +SO_KIT_SOURCE(SoRotationDraggerContainer) + +void SoRotationDraggerContainer::initClass() +{ + SoRotationDragger::initClass(); + SO_KIT_INIT_CLASS(SoRotationDraggerContainer, SoInteractionKit, "InteractionKit"); +} + +SoRotationDraggerContainer::SoRotationDraggerContainer() +{ + SO_KIT_CONSTRUCTOR(SoRotationDraggerContainer); + +#if defined(Q_OS_MACOS) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) + this->ref(); +#endif + + FC_ADD_CATALOG_ENTRY(draggerSwitch, SoSwitch, geomSeparator); + FC_ADD_CATALOG_ENTRY(baseColor, SoBaseColor, draggerSwitch); + FC_ADD_CATALOG_ENTRY(transform, SoTransform, draggerSwitch); + FC_ADD_CATALOG_ENTRY(dragger, SoRotationDragger, draggerSwitch); + + SO_KIT_ADD_FIELD(rotation, (0, 0, 0, 0)); + SO_KIT_ADD_FIELD(color, (0, 0, 0)); + SO_KIT_ADD_FIELD(translation, (0, 0, 0)); + + SO_KIT_INIT_INSTANCE(); + + setPart("baseColor", buildColor()); + setPart("transform", buildTransform()); + + setVisibility(true); +} + +SoBaseColor* SoRotationDraggerContainer::buildColor() +{ + auto color = new SoBaseColor; + color->rgb.connectFrom(&this->color); + + return color; +} + +SoTransform* SoRotationDraggerContainer::buildTransform() { + auto transform = new SoTransform; + transform->translation.connectFrom(&this->translation); + transform->rotation.connectFrom(&this->rotation); + + return transform; +} + +void SoRotationDraggerContainer::setVisibility(bool visible) +{ + FC_SET_SWITCH("draggerSwitch", visible? SO_SWITCH_ALL : SO_SWITCH_NONE); +} + +bool SoRotationDraggerContainer::isVisible() { + auto* sw = SO_GET_ANY_PART(this, "draggerSwitch", SoSwitch); + return sw->whichChild.getValue() == SO_SWITCH_ALL; +} + +SoRotationDragger* SoRotationDraggerContainer::getDragger() +{ + return SO_GET_PART(this, "dragger", SoRotationDragger); +} + +void Gui::SoRotationDraggerContainer::setPointerDirection(const Base::Vector3d& dir) +{ + // This is the direction of normal from the origin to the spherical handle of + // the dragger in its local space + float arcAngle = getDragger()->arcAngle.getValue(); + Base::Vector3d draggerDir{std::cos(arcAngle), std::sin(arcAngle), 0}; + + Base::Vector3d axis = draggerDir.Cross(dir).Normalize(); + double ang = draggerDir.GetAngleOriented(dir, axis); + + SbRotation rot{Base::convertTo(axis), static_cast(ang)}; + rotation.setValue(rot); +} diff --git a/src/Gui/Inventor/Draggers/SoRotationDragger.h b/src/Gui/Inventor/Draggers/SoRotationDragger.h index b19af13f73..292b47ca98 100644 --- a/src/Gui/Inventor/Draggers/SoRotationDragger.h +++ b/src/Gui/Inventor/Draggers/SoRotationDragger.h @@ -33,6 +33,11 @@ #include #include #include +#include + +class SoTransform; +class SoCalculator; +class SoCoordinate3; namespace Gui { @@ -46,16 +51,22 @@ namespace Gui class SoRotationDragger : public SoDragger { SO_KIT_HEADER(SoRotationDragger); - SO_KIT_CATALOG_ENTRY_HEADER(rotatorSwitch); SO_KIT_CATALOG_ENTRY_HEADER(rotator); - SO_KIT_CATALOG_ENTRY_HEADER(rotatorActive); + SO_KIT_CATALOG_ENTRY_HEADER(activeSwitch); + SO_KIT_CATALOG_ENTRY_HEADER(secondaryColor); + public: static void initClass(); SoRotationDragger(); + SoSFRotation rotation; //!< set from outside and used from outside for single precision. SoSFDouble rotationIncrement; //!< set from outside and used for rounding. SoSFInt32 rotationIncrementCount; //!< number of steps. used from outside. - SoSFColor color; //!< set from outside. non-active color. + SoSFColor activeColor; + SoSFFloat arcRadius; + SoSFFloat arcAngle; //!< in radians + SoSFFloat sphereRadius; + SoSFFloat arcThickness; protected: ~SoRotationDragger() override; @@ -73,15 +84,53 @@ protected: SoFieldSensor fieldSensor; SbPlaneProjector projector; - float arcRadius; private: - void buildFirstInstance(); + SoCalculator* calculator; + SoCoordinate3* coordinates = nullptr; + SoFieldSensor arcRadiusSensor; + SoFieldSensor arcAngleSensor; + constexpr static int segments = 10; //!< segments of the arc per arcAngle + int roundIncrement(const float &radiansIn); - SoGroup* buildGeometry(); + SoSeparator* buildGeometry(); + static void arcSensorCB(void* userdata, SoSensor*); + SoBaseColor* buildActiveColor(); + void setupGeometryCalculator(); + void setupArcSensors(); + using inherited = SoDragger; }; +class SoRotationDraggerContainer: public SoInteractionKit +{ + SO_KIT_HEADER(SoRotationDraggerContainer); + SO_KIT_CATALOG_ENTRY_HEADER(draggerSwitch); + SO_KIT_CATALOG_ENTRY_HEADER(baseColor); + SO_KIT_CATALOG_ENTRY_HEADER(transform); + SO_KIT_CATALOG_ENTRY_HEADER(dragger); + +public: + static void initClass(); + SoRotationDraggerContainer(); + + SoSFRotation rotation; + SoSFColor color; + SoSFVec3f translation; + + void setVisibility(bool visible); + bool isVisible(); + void setPointerDirection(const Base::Vector3d& dir); + + SoRotationDragger* getDragger(); + +private: + SoBaseColor* buildColor(); + SoTransform* buildTransform(); + + using inherited = SoInteractionKit; +}; + } #endif /* GUI_ROTATION_DRAGGER_H */ diff --git a/src/Gui/Inventor/Draggers/SoTransformDragger.cpp b/src/Gui/Inventor/Draggers/SoTransformDragger.cpp index f44ee2e3c9..d253237b6c 100644 --- a/src/Gui/Inventor/Draggers/SoTransformDragger.cpp +++ b/src/Gui/Inventor/Draggers/SoTransformDragger.cpp @@ -96,7 +96,7 @@ void SoTransformDragger::initClass() { SoLinearDraggerContainer::initClass(); SoPlanarDragger::initClass(); - SoRotationDragger::initClass(); + SoRotationDraggerContainer::initClass(); SO_KIT_INIT_CLASS(SoTransformDragger, SoDragger, "Dragger"); } @@ -201,26 +201,9 @@ SoTransformDragger::SoTransformDragger() TRUE); // Rotator - - SO_KIT_ADD_CATALOG_ENTRY(xRotatorSwitch, SoSwitch, TRUE, annotation, "", TRUE); - SO_KIT_ADD_CATALOG_ENTRY(yRotatorSwitch, SoSwitch, TRUE, annotation, "", TRUE); - SO_KIT_ADD_CATALOG_ENTRY(zRotatorSwitch, SoSwitch, TRUE, annotation, "", TRUE); - - SO_KIT_ADD_CATALOG_ENTRY(xRotatorSeparator, SoSeparator, TRUE, xRotatorSwitch, "", TRUE); - SO_KIT_ADD_CATALOG_ENTRY(yRotatorSeparator, SoSeparator, TRUE, yRotatorSwitch, "", TRUE); - SO_KIT_ADD_CATALOG_ENTRY(zRotatorSeparator, SoSeparator, TRUE, zRotatorSwitch, "", TRUE); - - SO_KIT_ADD_CATALOG_ENTRY(xRotatorColor, SoBaseColor, TRUE, xRotatorSeparator, "", TRUE); - SO_KIT_ADD_CATALOG_ENTRY(yRotatorColor, SoBaseColor, TRUE, yRotatorSeparator, "", TRUE); - SO_KIT_ADD_CATALOG_ENTRY(zRotatorColor, SoBaseColor, TRUE, zRotatorSeparator, "", TRUE); - - SO_KIT_ADD_CATALOG_ENTRY(xRotatorRotation, SoRotation, TRUE, xRotatorSeparator, "", TRUE); - SO_KIT_ADD_CATALOG_ENTRY(yRotatorRotation, SoRotation, TRUE, yRotatorSeparator, "", TRUE); - SO_KIT_ADD_CATALOG_ENTRY(zRotatorRotation, SoRotation, TRUE, zRotatorSeparator, "", TRUE); - - SO_KIT_ADD_CATALOG_ENTRY(xRotatorDragger, SoRotationDragger, TRUE, xRotatorSeparator, "", TRUE); - SO_KIT_ADD_CATALOG_ENTRY(yRotatorDragger, SoRotationDragger, TRUE, yRotatorSeparator, "", TRUE); - SO_KIT_ADD_CATALOG_ENTRY(zRotatorDragger, SoRotationDragger, TRUE, zRotatorSeparator, "", TRUE); + SO_KIT_ADD_CATALOG_ENTRY(xRotatorDragger, SoRotationDraggerContainer, TRUE, annotation, "", TRUE); + SO_KIT_ADD_CATALOG_ENTRY(yRotatorDragger, SoRotationDraggerContainer, TRUE, annotation, "", TRUE); + SO_KIT_ADD_CATALOG_ENTRY(zRotatorDragger, SoRotationDraggerContainer, TRUE, annotation, "", TRUE); // Other SO_KIT_ADD_FIELD(translation, (0.0, 0.0, 0.0)); @@ -269,17 +252,9 @@ SoTransformDragger::SoTransformDragger() tPlanarDragger->autoScaleResult.connectFrom(&this->autoScaleResult); translationIncrementCountX.appendConnection(&tPlanarDragger->translationIncrementXCount); translationIncrementCountZ.appendConnection(&tPlanarDragger->translationIncrementYCount); + // Rotator - SoRotationDragger* rDragger; - rDragger = SO_GET_ANY_PART(this, "xRotatorDragger", SoRotationDragger); - rDragger->rotationIncrement.connectFrom(&this->rotationIncrement); - rotationIncrementCountX.connectFrom(&rDragger->rotationIncrementCount); - rDragger = SO_GET_ANY_PART(this, "yRotatorDragger", SoRotationDragger); - rDragger->rotationIncrement.connectFrom(&this->rotationIncrement); - rotationIncrementCountY.connectFrom(&rDragger->rotationIncrementCount); - rDragger = SO_GET_ANY_PART(this, "zRotatorDragger", SoRotationDragger); - rDragger->rotationIncrement.connectFrom(&this->rotationIncrement); - rotationIncrementCountZ.connectFrom(&rDragger->rotationIncrementCount); + setupRotationDraggers(); // Switches SoSwitch* sw; @@ -290,13 +265,6 @@ SoTransformDragger::SoTransformDragger() SoInteractionKit::setSwitchValue(sw, SO_SWITCH_ALL); sw = SO_GET_ANY_PART(this, "zxPlanarTranslatorSwitch", SoSwitch); SoInteractionKit::setSwitchValue(sw, SO_SWITCH_ALL); - // Rotator - sw = SO_GET_ANY_PART(this, "xRotatorSwitch", SoSwitch); - SoInteractionKit::setSwitchValue(sw, SO_SWITCH_ALL); - sw = SO_GET_ANY_PART(this, "yRotatorSwitch", SoSwitch); - SoInteractionKit::setSwitchValue(sw, SO_SWITCH_ALL); - sw = SO_GET_ANY_PART(this, "zRotatorSwitch", SoSwitch); - SoInteractionKit::setSwitchValue(sw, SO_SWITCH_ALL); // Rotations @@ -311,16 +279,17 @@ SoTransformDragger::SoTransformDragger() localRotation = SO_GET_ANY_PART(this, "zxPlanarTranslatorRotation", SoRotation); localRotation->rotation.setValue(SbVec3f(1.0, 0.0, 0.0), angle); // Rotator - localRotation = SO_GET_ANY_PART(this, "xRotatorRotation", SoRotation); + SoRotationDraggerContainer* rDragger; + rDragger = SO_GET_ANY_PART(this, "xRotatorDragger", SoRotationDraggerContainer); tempRotation = SbRotation(SbVec3f(1.0, 0.0, 0.0), angle); tempRotation *= SbRotation(SbVec3f(0.0, 0.0, 1.0), angle); - localRotation->rotation.setValue(tempRotation); - localRotation = SO_GET_ANY_PART(this, "yRotatorRotation", SoRotation); + rDragger->rotation.setValue(tempRotation); + rDragger = SO_GET_ANY_PART(this, "yRotatorDragger", SoRotationDraggerContainer); tempRotation = SbRotation(SbVec3f(0.0, -1.0, 0.0), angle); tempRotation *= SbRotation(SbVec3f(0.0, 0.0, -1.0), angle); - localRotation->rotation.setValue(tempRotation); - localRotation = SO_GET_ANY_PART(this, "zRotatorRotation", SoRotation); - localRotation->rotation.setValue(SbRotation::identity()); + rDragger->rotation.setValue(tempRotation); + rDragger = SO_GET_ANY_PART(this, "zRotatorDragger", SoRotationDraggerContainer); + rDragger->rotation.setValue(SbRotation::identity()); // this is for non-autoscale mode. this will be disconnected for autoscale // and won't be used. see setUpAutoScale. @@ -387,9 +356,9 @@ SbBool SoTransformDragger::setUpConnections(SbBool onoff, SbBool doitalways) SO_GET_ANY_PART(this, "yzPlanarTranslatorDragger", SoPlanarDragger); SoPlanarDragger* tPlanarDraggerZX = SO_GET_ANY_PART(this, "zxPlanarTranslatorDragger", SoPlanarDragger); - SoRotationDragger* rDraggerX = SO_GET_ANY_PART(this, "xRotatorDragger", SoRotationDragger); - SoRotationDragger* rDraggerY = SO_GET_ANY_PART(this, "yRotatorDragger", SoRotationDragger); - SoRotationDragger* rDraggerZ = SO_GET_ANY_PART(this, "zRotatorDragger", SoRotationDragger); + auto rDraggerX = SO_GET_ANY_PART(this, "xRotatorDragger", SoRotationDraggerContainer); + auto rDraggerY = SO_GET_ANY_PART(this, "yRotatorDragger", SoRotationDraggerContainer); + auto rDraggerZ = SO_GET_ANY_PART(this, "zRotatorDragger", SoRotationDraggerContainer); if (onoff) { inherited::setUpConnections(onoff, doitalways); @@ -400,9 +369,9 @@ SbBool SoTransformDragger::setUpConnections(SbBool onoff, SbBool doitalways) registerChildDragger(tPlanarDraggerXZ); registerChildDragger(tPlanarDraggerYZ); registerChildDragger(tPlanarDraggerZX); - registerChildDragger(rDraggerX); - registerChildDragger(rDraggerY); - registerChildDragger(rDraggerZ); + registerChildDragger(rDraggerX->getDragger()); + registerChildDragger(rDraggerY->getDragger()); + registerChildDragger(rDraggerZ->getDragger()); translationSensorCB(this, nullptr); if (this->translationSensor.getAttachedField() != &this->translation) { @@ -421,9 +390,9 @@ SbBool SoTransformDragger::setUpConnections(SbBool onoff, SbBool doitalways) unregisterChildDragger(tPlanarDraggerXZ); unregisterChildDragger(tPlanarDraggerYZ); unregisterChildDragger(tPlanarDraggerZX); - unregisterChildDragger(rDraggerX); - unregisterChildDragger(rDraggerY); - unregisterChildDragger(rDraggerZ); + unregisterChildDragger(rDraggerX->getDragger()); + unregisterChildDragger(rDraggerY->getDragger()); + unregisterChildDragger(rDraggerZ->getDragger()); inherited::setUpConnections(onoff, doitalways); @@ -642,12 +611,13 @@ void SoTransformDragger::setAxisColors(unsigned long x, unsigned long y, unsigne color = SO_GET_ANY_PART(this, "zxPlanarTranslatorColor", SoBaseColor); color->rgb.setValue(colorY[0], colorY[1], colorY[2]); // Rotator - color = SO_GET_ANY_PART(this, "xRotatorColor", SoBaseColor); - color->rgb.setValue(colorX[0], colorX[1], colorX[2]); - color = SO_GET_ANY_PART(this, "yRotatorColor", SoBaseColor); - color->rgb.setValue(colorY[0], colorY[1], colorY[2]); - color = SO_GET_ANY_PART(this, "zRotatorColor", SoBaseColor); - color->rgb.setValue(colorZ[0], colorZ[1], colorZ[2]); + SoRotationDraggerContainer* rDragger; + rDragger = SO_GET_ANY_PART(this, "xRotatorDragger", SoRotationDraggerContainer); + rDragger->color.setValue(colorX[0], colorX[1], colorX[2]); + rDragger = SO_GET_ANY_PART(this, "yRotatorDragger", SoRotationDraggerContainer); + rDragger->color.setValue(colorY[0], colorY[1], colorY[2]); + rDragger = SO_GET_ANY_PART(this, "zRotatorDragger", SoRotationDraggerContainer); + rDragger->color.setValue(colorZ[0], colorZ[1], colorZ[2]); } // Visibility API Functions @@ -769,66 +739,50 @@ bool SoTransformDragger::isHiddenPlanarTranslationZX() // Rotator void SoTransformDragger::showRotationX() { - SoSwitch* sw = SO_GET_ANY_PART(this, "xRotatorSwitch", SoSwitch); - SoInteractionKit::setSwitchValue(sw, SO_SWITCH_ALL); + SoRotationDraggerContainer* rDragger = SO_GET_ANY_PART(this, "xRotatorDragger", SoRotationDraggerContainer); + rDragger->setVisibility(true); } void SoTransformDragger::showRotationY() { - SoSwitch* sw = SO_GET_ANY_PART(this, "yRotatorSwitch", SoSwitch); - SoInteractionKit::setSwitchValue(sw, SO_SWITCH_ALL); + SoRotationDraggerContainer* rDragger = SO_GET_ANY_PART(this, "yRotatorDragger", SoRotationDraggerContainer); + rDragger->setVisibility(true); } void SoTransformDragger::showRotationZ() { - SoSwitch* sw = SO_GET_ANY_PART(this, "zRotatorSwitch", SoSwitch); - SoInteractionKit::setSwitchValue(sw, SO_SWITCH_ALL); + SoRotationDraggerContainer* rDragger = SO_GET_ANY_PART(this, "zRotatorDragger", SoRotationDraggerContainer); + rDragger->setVisibility(true); } void SoTransformDragger::hideRotationX() { - SoSwitch* sw = SO_GET_ANY_PART(this, "xRotatorSwitch", SoSwitch); - SoInteractionKit::setSwitchValue(sw, SO_SWITCH_NONE); + SoRotationDraggerContainer* rDragger = SO_GET_ANY_PART(this, "xRotatorDragger", SoRotationDraggerContainer); + rDragger->setVisibility(false); } void SoTransformDragger::hideRotationY() { - SoSwitch* sw = SO_GET_ANY_PART(this, "yRotatorSwitch", SoSwitch); - SoInteractionKit::setSwitchValue(sw, SO_SWITCH_NONE); + SoRotationDraggerContainer* rDragger = SO_GET_ANY_PART(this, "yRotatorDragger", SoRotationDraggerContainer); + rDragger->setVisibility(false); } void SoTransformDragger::hideRotationZ() { - SoSwitch* sw = SO_GET_ANY_PART(this, "zRotatorSwitch", SoSwitch); - SoInteractionKit::setSwitchValue(sw, SO_SWITCH_NONE); + SoRotationDraggerContainer* rDragger = SO_GET_ANY_PART(this, "zRotatorDragger", SoRotationDraggerContainer); + rDragger->setVisibility(false); } bool SoTransformDragger::isShownRotationX() { - SoSwitch* sw = SO_GET_ANY_PART(this, "xRotatorSwitch", SoSwitch); - return (sw->whichChild.getValue() == SO_SWITCH_ALL); + SoRotationDraggerContainer* rDragger = SO_GET_ANY_PART(this, "xRotatorDragger", SoRotationDraggerContainer); + return rDragger->isVisible(); } bool SoTransformDragger::isShownRotationY() { - SoSwitch* sw = SO_GET_ANY_PART(this, "yRotatorSwitch", SoSwitch); - return (sw->whichChild.getValue() == SO_SWITCH_ALL); + SoRotationDraggerContainer* rDragger = SO_GET_ANY_PART(this, "yRotatorDragger", SoRotationDraggerContainer); + return rDragger->isVisible(); } bool SoTransformDragger::isShownRotationZ() { - SoSwitch* sw = SO_GET_ANY_PART(this, "zRotatorSwitch", SoSwitch); - return (sw->whichChild.getValue() == SO_SWITCH_ALL); -} - -bool SoTransformDragger::isHiddenRotationX() -{ - SoSwitch* sw = SO_GET_ANY_PART(this, "xRotatorSwitch", SoSwitch); - return (sw->whichChild.getValue() == SO_SWITCH_NONE); -} -bool SoTransformDragger::isHiddenRotationY() -{ - SoSwitch* sw = SO_GET_ANY_PART(this, "yRotatorSwitch", SoSwitch); - return (sw->whichChild.getValue() == SO_SWITCH_NONE); -} -bool SoTransformDragger::isHiddenRotationZ() -{ - SoSwitch* sw = SO_GET_ANY_PART(this, "zRotatorSwitch", SoSwitch); - return (sw->whichChild.getValue() == SO_SWITCH_NONE); + SoRotationDraggerContainer* rDragger = SO_GET_ANY_PART(this, "zRotatorDragger", SoRotationDraggerContainer); + return rDragger->isVisible(); } void SoTransformDragger::setupTranslationDraggers() @@ -850,3 +804,19 @@ void SoTransformDragger::setupTranslationDragger(const std::string& name, SoSFSt draggerContainer->setPointerDirection(Base::convertTo(rotDir)); } + +void SoTransformDragger::setupRotationDraggers() +{ + setupRotationDragger("xRotatorDragger", rotationIncrementCountX); + setupRotationDragger("yRotatorDragger", rotationIncrementCountY); + setupRotationDragger("zRotatorDragger", rotationIncrementCountZ); +} + +void SoTransformDragger::setupRotationDragger(const std::string& name, SoSFInt32& incrementCount) +{ + SoRotationDraggerContainer* draggerContainer = SO_GET_ANY_PART(this, name.c_str(), SoRotationDraggerContainer); + SoRotationDragger* dragger = draggerContainer->getDragger(); + + dragger->rotationIncrement.connectFrom(&this->rotationIncrement); + incrementCount.connectFrom(&dragger->rotationIncrementCount); +} diff --git a/src/Gui/Inventor/Draggers/SoTransformDragger.h b/src/Gui/Inventor/Draggers/SoTransformDragger.h index 27199421fa..cde2038aa0 100644 --- a/src/Gui/Inventor/Draggers/SoTransformDragger.h +++ b/src/Gui/Inventor/Draggers/SoTransformDragger.h @@ -82,18 +82,6 @@ class GuiExport SoTransformDragger : public SoDragger SO_KIT_CATALOG_ENTRY_HEADER(yzPlanarTranslatorDragger); SO_KIT_CATALOG_ENTRY_HEADER(zxPlanarTranslatorDragger); // Rotator - SO_KIT_CATALOG_ENTRY_HEADER(xRotatorSwitch); - SO_KIT_CATALOG_ENTRY_HEADER(yRotatorSwitch); - SO_KIT_CATALOG_ENTRY_HEADER(zRotatorSwitch); - SO_KIT_CATALOG_ENTRY_HEADER(xRotatorSeparator); - SO_KIT_CATALOG_ENTRY_HEADER(yRotatorSeparator); - SO_KIT_CATALOG_ENTRY_HEADER(zRotatorSeparator); - SO_KIT_CATALOG_ENTRY_HEADER(xRotatorColor); - SO_KIT_CATALOG_ENTRY_HEADER(yRotatorColor); - SO_KIT_CATALOG_ENTRY_HEADER(zRotatorColor); - SO_KIT_CATALOG_ENTRY_HEADER(xRotatorRotation); - SO_KIT_CATALOG_ENTRY_HEADER(yRotatorRotation); - SO_KIT_CATALOG_ENTRY_HEADER(zRotatorRotation); SO_KIT_CATALOG_ENTRY_HEADER(xRotatorDragger); SO_KIT_CATALOG_ENTRY_HEADER(yRotatorDragger); SO_KIT_CATALOG_ENTRY_HEADER(zRotatorDragger); @@ -168,9 +156,6 @@ public: bool isShownRotationX(); //!< is x rotation dragger shown. bool isShownRotationY(); //!< is x rotation dragger shown. bool isShownRotationZ(); //!< is x rotation dragger shown. - bool isHiddenRotationX(); //!< is x rotation dragger hidden. - bool isHiddenRotationY(); //!< is x rotation dragger hidden. - bool isHiddenRotationZ(); //!< is x rotation dragger hidden. //@} void GLRender(SoGLRenderAction * action) override; @@ -202,6 +187,8 @@ private: void setupTranslationDraggers(); void setupTranslationDragger(const std::string& name, SoSFString* label, SoSFInt32& incrementCount, const SbVec3d& rotDir); + void setupRotationDraggers(); + void setupRotationDragger(const std::string& name, SoSFInt32& incrementCount); using inherited = SoDragger; };