Merge pull request #22119 from captain0xff/draggger-rework2
Gui: refactor SoRotationDragger
This commit is contained in:
@@ -1083,6 +1083,7 @@ SET(Inventor_CPP_SRCS
|
||||
Inventor/SoFCBoundingBox.cpp
|
||||
Inventor/SoMouseWheelEvent.cpp
|
||||
Inventor/SoFCTransform.cpp
|
||||
Inventor/SoToggleSwitch.cpp
|
||||
Inventor/Draggers/SoTransformDragger.cpp
|
||||
Inventor/Draggers/SoLinearDragger.cpp
|
||||
Inventor/Draggers/SoPlanarDragger.cpp
|
||||
@@ -1119,6 +1120,7 @@ SET(Inventor_SRCS
|
||||
Inventor/SoFCBoundingBox.h
|
||||
Inventor/SoMouseWheelEvent.h
|
||||
Inventor/SoFCTransform.h
|
||||
Inventor/SoToggleSwitch.h
|
||||
Inventor/Draggers/SoTransformDragger.h
|
||||
Inventor/Draggers/SoLinearDragger.h
|
||||
Inventor/Draggers/SoPlanarDragger.h
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
#include <Inventor/nodes/SoAnnotation.h>
|
||||
#include <Inventor/nodes/SoFontStyle.h>
|
||||
#include <Inventor/draggers/SoDragger.h>
|
||||
#include <Inventor/nodekits/SoSubKit.h>
|
||||
#endif
|
||||
|
||||
#include <Base/Quantity.h>
|
||||
@@ -61,9 +62,83 @@
|
||||
#include "Utilities.h"
|
||||
|
||||
#include <SoTextLabel.h>
|
||||
#include <Inventor/SoToggleSwitch.h>
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
SO_KIT_SOURCE(SoLinearGeometryKit)
|
||||
|
||||
void SoLinearGeometryKit::initClass()
|
||||
{
|
||||
SO_KIT_INIT_CLASS(SoLinearGeometryKit, SoBaseKit, "BaseKit");
|
||||
}
|
||||
|
||||
SoLinearGeometryKit::SoLinearGeometryKit()
|
||||
{
|
||||
SO_KIT_CONSTRUCTOR(SoLinearGeometryKit);
|
||||
|
||||
SO_KIT_ADD_FIELD(tipPosition, (0.0, 0.0, 0.0));
|
||||
|
||||
SO_KIT_INIT_INSTANCE();
|
||||
}
|
||||
|
||||
SO_KIT_SOURCE(SoArrowGeometry)
|
||||
|
||||
void SoArrowGeometry::initClass()
|
||||
{
|
||||
SO_KIT_INIT_CLASS(SoArrowGeometry, SoLinearGeometryKit, "LinearGeometryKit");
|
||||
}
|
||||
|
||||
SoArrowGeometry::SoArrowGeometry()
|
||||
{
|
||||
SO_KIT_CONSTRUCTOR(SoArrowGeometry);
|
||||
SO_KIT_ADD_CATALOG_ENTRY(lightModel, SoLightModel, false, this, "", false);
|
||||
SO_KIT_ADD_CATALOG_ENTRY(arrowBody, SoCylinder, false, this, "", true);
|
||||
SO_KIT_ADD_CATALOG_ENTRY(arrowTip, SoCone, false, this, "", true);
|
||||
|
||||
SO_KIT_ADD_CATALOG_ENTRY(_arrowBodyTranslation, SoTranslation, false, this, arrowBody, false);
|
||||
SO_KIT_ADD_CATALOG_ENTRY(_arrowTipTranslation, SoTranslation, false, this, arrowTip, false);
|
||||
|
||||
SO_KIT_ADD_FIELD(coneBottomRadius, (0.8));
|
||||
SO_KIT_ADD_FIELD(coneHeight, (2.5));
|
||||
SO_KIT_ADD_FIELD(cylinderHeight, (10.0));
|
||||
SO_KIT_ADD_FIELD(cylinderRadius, (0.1));
|
||||
|
||||
SO_KIT_INIT_INSTANCE();
|
||||
|
||||
auto arrowBody = SO_GET_ANY_PART(this, "arrowBody", SoCylinder);
|
||||
arrowBody->height.connectFrom(&cylinderHeight);
|
||||
arrowBody->radius.connectFrom(&cylinderRadius);
|
||||
|
||||
auto arrowTip = SO_GET_ANY_PART(this, "arrowTip", SoCone);
|
||||
arrowTip->height.connectFrom(&coneHeight);
|
||||
arrowTip->bottomRadius.connectFrom(&coneBottomRadius);
|
||||
|
||||
auto lightModel = SO_GET_ANY_PART(this, "lightModel", SoLightModel);
|
||||
lightModel->model = SoLightModel::BASE_COLOR;
|
||||
|
||||
// forces the notify method to get called so that the initial translations and tipPostion are set
|
||||
cylinderHeight.touch();
|
||||
}
|
||||
|
||||
void SoArrowGeometry::notify(SoNotList* notList)
|
||||
{
|
||||
assert(notList);
|
||||
SoField* lastField = notList->getLastField();
|
||||
|
||||
if (lastField == &cylinderHeight) {
|
||||
auto translation = SO_GET_ANY_PART(this, "_arrowBodyTranslation", SoTranslation);
|
||||
translation->translation = SbVec3f(0, cylinderHeight.getValue() / 2.0f, 0);
|
||||
}
|
||||
|
||||
if (lastField == &coneHeight || lastField == &cylinderHeight) {
|
||||
auto translation = SO_GET_ANY_PART(this, "_arrowTipTranslation", SoTranslation);
|
||||
translation->translation = SbVec3f(0, (cylinderHeight.getValue() + coneHeight.getValue()) / 2.0f, 0);
|
||||
|
||||
tipPosition = {0, cylinderHeight.getValue() + 1.5f * coneHeight.getValue(), 0};
|
||||
}
|
||||
}
|
||||
|
||||
SO_KIT_SOURCE(SoLinearDragger)
|
||||
|
||||
void SoLinearDragger::initClass()
|
||||
@@ -79,35 +154,31 @@ SoLinearDragger::SoLinearDragger()
|
||||
this->ref();
|
||||
#endif
|
||||
|
||||
FC_ADD_CATALOG_ENTRY(translator, SoSeparator, geomSeparator);
|
||||
FC_ADD_CATALOG_ENTRY(activeSwitch, SoSwitch, translator);
|
||||
FC_ADD_CATALOG_ENTRY(activeSwitch, SoToggleSwitch, geomSeparator);
|
||||
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(labelSwitch, SoToggleSwitch, geomSeparator);
|
||||
FC_ADD_CATALOG_ENTRY(labelSeparator, SoSeparator, labelSwitch);
|
||||
FC_ADD_CATALOG_ENTRY(scale, SoScale, geomSeparator);
|
||||
SO_KIT_ADD_CATALOG_ABSTRACT_ENTRY(arrow, SoLinearGeometryKit, SoArrowGeometry, true, geomSeparator, "", true);
|
||||
|
||||
SO_KIT_ADD_FIELD(translation, (0.0, 0.0, 0.0));
|
||||
SO_KIT_ADD_FIELD(translationIncrement, (1.0));
|
||||
SO_KIT_ADD_FIELD(translationIncrementCount, (0));
|
||||
SO_KIT_ADD_FIELD(autoScaleResult, (1.0));
|
||||
SO_KIT_ADD_FIELD(coneBottomRadius, (0.8));
|
||||
SO_KIT_ADD_FIELD(coneHeight, (2.5));
|
||||
SO_KIT_ADD_FIELD(cylinderHeight, (10.0));
|
||||
SO_KIT_ADD_FIELD(cylinderRadius, (0.1));
|
||||
SO_KIT_ADD_FIELD(activeColor, (1, 1, 0));
|
||||
SO_KIT_ADD_FIELD(labelVisible, (1));
|
||||
SO_KIT_ADD_FIELD(geometryScale, (1, 1, 1));
|
||||
|
||||
SO_KIT_INIT_INSTANCE();
|
||||
|
||||
setupGeometryCalculator();
|
||||
SoInteractionKit::setPart("cylinderSeparator", buildCylinderGeometry());
|
||||
SoInteractionKit::setPart("coneSeparator", buildConeGeometry());
|
||||
SoInteractionKit::setPart("labelSeparator", buildLabelGeometry());
|
||||
SoInteractionKit::setPart("secondaryColor", buildActiveColor());
|
||||
setPart("labelSeparator", buildLabelGeometry());
|
||||
setPart("secondaryColor", buildActiveColor());
|
||||
|
||||
FC_SET_SWITCH("activeSwitch", SO_SWITCH_NONE);
|
||||
setLabelVisibility(true);
|
||||
auto sw = SO_GET_ANY_PART(this, "labelSwitch", SoToggleSwitch);
|
||||
sw->on.connectFrom(&labelVisible);
|
||||
|
||||
auto scale = SO_GET_ANY_PART(this, "scale", SoScale);
|
||||
scale->scaleFactor.connectFrom(&geometryScale);
|
||||
|
||||
this->addStartCallback(&SoLinearDragger::startCB);
|
||||
this->addMotionCallback(&SoLinearDragger::motionCB);
|
||||
@@ -120,6 +191,8 @@ SoLinearDragger::SoLinearDragger()
|
||||
fieldSensor.setPriority(0);
|
||||
|
||||
this->setUpConnections(TRUE, TRUE);
|
||||
|
||||
FC_SET_TOGGLE_SWITCH("activeSwitch", false);
|
||||
}
|
||||
|
||||
SoLinearDragger::~SoLinearDragger()
|
||||
@@ -133,66 +206,15 @@ SoLinearDragger::~SoLinearDragger()
|
||||
removeValueChangedCallback(&SoLinearDragger::valueChangedCB);
|
||||
}
|
||||
|
||||
SoSeparator* SoLinearDragger::buildCylinderGeometry()
|
||||
{
|
||||
auto cylinderSeparator = new SoSeparator();
|
||||
|
||||
auto cylinderLightModel = new SoLightModel();
|
||||
cylinderLightModel->model = SoLightModel::BASE_COLOR;
|
||||
cylinderSeparator->addChild(cylinderLightModel);
|
||||
|
||||
auto cylinderTranslation = new SoTranslation();
|
||||
cylinderSeparator->addChild(cylinderTranslation);
|
||||
cylinderTranslation->translation.connectFrom(&calculator->oA);
|
||||
|
||||
auto cylinder = new SoCylinder();
|
||||
cylinder->radius.setValue(cylinderRadius.getValue());
|
||||
cylinder->height.setValue(cylinderHeight.getValue());
|
||||
cylinderSeparator->addChild(cylinder);
|
||||
|
||||
cylinder->radius.connectFrom(&cylinderRadius);
|
||||
cylinder->height.connectFrom(&cylinderHeight);
|
||||
calculator->a.connectFrom(&cylinder->height);
|
||||
|
||||
return cylinderSeparator;
|
||||
}
|
||||
|
||||
SoSeparator* SoLinearDragger::buildConeGeometry()
|
||||
{
|
||||
auto coneLightModel = new SoLightModel();
|
||||
coneLightModel->model = SoLightModel::BASE_COLOR;
|
||||
|
||||
auto coneSeparator = new SoSeparator();
|
||||
coneSeparator->addChild(coneLightModel);
|
||||
|
||||
auto pickStyle = new SoPickStyle();
|
||||
pickStyle->style.setValue(SoPickStyle::SHAPE_ON_TOP);
|
||||
pickStyle->setOverride(TRUE);
|
||||
coneSeparator->addChild(pickStyle);
|
||||
|
||||
auto coneTranslation = new SoTranslation();
|
||||
coneSeparator->addChild(coneTranslation);
|
||||
coneTranslation->translation.connectFrom(&calculator->oB);
|
||||
|
||||
auto cone = new SoCone();
|
||||
cone->bottomRadius.setValue(coneBottomRadius.getValue());
|
||||
cone->height.setValue(coneHeight.getValue());
|
||||
coneSeparator->addChild(cone);
|
||||
|
||||
cone->bottomRadius.connectFrom(&coneBottomRadius);
|
||||
cone->height.connectFrom(&coneHeight);
|
||||
calculator->b.connectFrom(&cone->height);
|
||||
|
||||
return coneSeparator;
|
||||
}
|
||||
|
||||
SoSeparator* SoLinearDragger::buildLabelGeometry()
|
||||
{
|
||||
auto labelSeparator = new SoSeparator;
|
||||
|
||||
auto labelTranslation = new SoTranslation();
|
||||
labelSeparator->addChild(labelTranslation);
|
||||
labelTranslation->translation.connectFrom(&calculator->oC);
|
||||
|
||||
auto arrow = SO_GET_PART(this, "arrow", SoLinearGeometryKit);
|
||||
labelTranslation->translation.connectFrom(&arrow->tipPosition);
|
||||
|
||||
auto label = new SoFrameLabel();
|
||||
label->string.connectFrom(&this->label);
|
||||
@@ -214,21 +236,6 @@ SoBaseColor* SoLinearDragger::buildActiveColor()
|
||||
return color;
|
||||
}
|
||||
|
||||
void SoLinearDragger::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 -> cylinderTranslation
|
||||
// oB -> coneTranslation
|
||||
// oC -> labelTranslation
|
||||
// a -> cylinderHeight
|
||||
// b -> coneHeight
|
||||
calculator->expression =
|
||||
"oA = vec3f(0, a * 0.5, 0); "
|
||||
"oB = vec3f(0, a + b * 0.5, 0); "
|
||||
"oC = vec3f(0, a + b * 1.5, 0); ";
|
||||
}
|
||||
|
||||
void SoLinearDragger::startCB(void*, SoDragger* d)
|
||||
{
|
||||
auto sudoThis = static_cast<SoLinearDragger*>(d);
|
||||
@@ -279,7 +286,7 @@ void SoLinearDragger::valueChangedCB(void*, SoDragger* d)
|
||||
|
||||
void SoLinearDragger::dragStart()
|
||||
{
|
||||
FC_SET_SWITCH("activeSwitch", SO_SWITCH_ALL);
|
||||
FC_SET_TOGGLE_SWITCH("activeSwitch", true);
|
||||
|
||||
// do an initial projection to eliminate discrepancies
|
||||
// in arrow head pick. we define the arrow in the y+ direction
|
||||
@@ -337,7 +344,7 @@ void SoLinearDragger::drag()
|
||||
|
||||
void SoLinearDragger::dragFinish()
|
||||
{
|
||||
FC_SET_SWITCH("activeSwitch", SO_SWITCH_NONE);
|
||||
FC_SET_TOGGLE_SWITCH("activeSwitch", false);
|
||||
}
|
||||
|
||||
SbBool SoLinearDragger::setUpConnections(SbBool onoff, SbBool doitalways)
|
||||
@@ -391,15 +398,6 @@ SbVec3f SoLinearDragger::roundTranslation(const SbVec3f& vecIn, float incrementI
|
||||
return out;
|
||||
}
|
||||
|
||||
void SoLinearDragger::setLabelVisibility(bool visible) {
|
||||
FC_SET_SWITCH("labelSwitch", visible? SO_SWITCH_ALL : SO_SWITCH_NONE);
|
||||
}
|
||||
|
||||
bool SoLinearDragger::isLabelVisible() {
|
||||
auto* sw = SO_GET_ANY_PART(this, "labelSwitch", SoSwitch);
|
||||
return sw->whichChild.getValue() == SO_SWITCH_ALL;
|
||||
}
|
||||
|
||||
SO_KIT_SOURCE(SoLinearDraggerContainer)
|
||||
|
||||
void SoLinearDraggerContainer::initClass()
|
||||
@@ -416,7 +414,7 @@ SoLinearDraggerContainer::SoLinearDraggerContainer()
|
||||
this->ref();
|
||||
#endif
|
||||
|
||||
FC_ADD_CATALOG_ENTRY(draggerSwitch, SoSwitch, geomSeparator);
|
||||
FC_ADD_CATALOG_ENTRY(draggerSwitch, SoToggleSwitch, geomSeparator);
|
||||
FC_ADD_CATALOG_ENTRY(baseColor, SoBaseColor, draggerSwitch);
|
||||
FC_ADD_CATALOG_ENTRY(transform, SoTransform, draggerSwitch);
|
||||
FC_ADD_CATALOG_ENTRY(dragger, SoLinearDragger, draggerSwitch);
|
||||
@@ -424,13 +422,15 @@ SoLinearDraggerContainer::SoLinearDraggerContainer()
|
||||
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_ADD_FIELD(visible, (1));
|
||||
|
||||
SO_KIT_INIT_INSTANCE();
|
||||
|
||||
SoInteractionKit::setPart("baseColor", buildColor());
|
||||
SoInteractionKit::setPart("transform", buildTransform());
|
||||
setPart("baseColor", buildColor());
|
||||
setPart("transform", buildTransform());
|
||||
|
||||
setVisibility(true);
|
||||
auto sw = SO_GET_ANY_PART(this, "draggerSwitch", SoToggleSwitch);
|
||||
sw->on.connectFrom(&visible);
|
||||
}
|
||||
|
||||
SoBaseColor* SoLinearDraggerContainer::buildColor()
|
||||
@@ -449,16 +449,6 @@ SoTransform* SoLinearDraggerContainer::buildTransform() {
|
||||
return transform;
|
||||
}
|
||||
|
||||
void SoLinearDraggerContainer::setVisibility(bool visible)
|
||||
{
|
||||
FC_SET_SWITCH("draggerSwitch", visible? SO_SWITCH_ALL : SO_SWITCH_NONE);
|
||||
}
|
||||
|
||||
bool SoLinearDraggerContainer::isVisible() {
|
||||
auto* sw = SO_GET_ANY_PART(this, "draggerSwitch", SoSwitch);
|
||||
return sw->whichChild.getValue() == SO_SWITCH_ALL;
|
||||
}
|
||||
|
||||
SoLinearDragger* SoLinearDraggerContainer::getDragger()
|
||||
{
|
||||
return SO_GET_PART(this, "dragger", SoLinearDragger);
|
||||
|
||||
@@ -43,6 +43,56 @@ class SoCalculator;
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
class SoLinearGeometryKit: public SoBaseKit
|
||||
{
|
||||
SO_KIT_HEADER(SoLinearGeometryKit);
|
||||
|
||||
public:
|
||||
static void initClass();
|
||||
|
||||
SoSFVec3f tipPosition;
|
||||
|
||||
protected:
|
||||
SoLinearGeometryKit();
|
||||
~SoLinearGeometryKit() override = default;
|
||||
|
||||
private:
|
||||
using inherited = SoBaseKit;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Arrow geometry
|
||||
*
|
||||
* A class to contain the geometry for SoLinearDragger
|
||||
*/
|
||||
class SoArrowGeometry: public SoLinearGeometryKit
|
||||
{
|
||||
SO_KIT_HEADER(SoArrowGeometry);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(lightModel);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(arrowBody);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(arrowTip);
|
||||
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(_arrowBodyTranslation);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(_arrowTipTranslation);
|
||||
|
||||
public:
|
||||
static void initClass();
|
||||
SoArrowGeometry();
|
||||
|
||||
SoSFFloat coneBottomRadius;
|
||||
SoSFFloat coneHeight;
|
||||
SoSFFloat cylinderHeight;
|
||||
SoSFFloat cylinderRadius;
|
||||
|
||||
protected:
|
||||
~SoArrowGeometry() override = default;
|
||||
|
||||
void notify(SoNotList* notList) override;
|
||||
|
||||
private:
|
||||
using inherited = SoLinearGeometryKit;
|
||||
};
|
||||
|
||||
/*! @brief Translation Dragger.
|
||||
*
|
||||
* used for translating along axis. Set the
|
||||
@@ -54,13 +104,12 @@ namespace Gui
|
||||
class SoLinearDragger : public SoDragger
|
||||
{
|
||||
SO_KIT_HEADER(SoLinearDragger);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(translator);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(activeSwitch);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(secondaryColor);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(cylinderSeparator);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(coneSeparator);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(labelSwitch);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(labelSeparator);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(scale);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(arrow);
|
||||
|
||||
public:
|
||||
static void initClass();
|
||||
@@ -71,14 +120,9 @@ public:
|
||||
SoSFDouble translationIncrement; //!< set from outside and used for rounding.
|
||||
SoSFInt32 translationIncrementCount; //!< number of steps. used from outside.
|
||||
SoSFFloat autoScaleResult; //!< set from parent dragger.
|
||||
SoSFFloat coneBottomRadius;
|
||||
SoSFFloat coneHeight;
|
||||
SoSFFloat cylinderHeight;
|
||||
SoSFFloat cylinderRadius;
|
||||
SoSFColor activeColor;
|
||||
|
||||
void setLabelVisibility(bool visible);
|
||||
bool isLabelVisible();
|
||||
SoSFColor activeColor; //!< colour of the dragger while being dragged
|
||||
SoSFBool labelVisible; //!< controls the visibility of the dragger label
|
||||
SoSFVec3f geometryScale; //!< the scale of the dragger geometry
|
||||
|
||||
protected:
|
||||
~SoLinearDragger() override;
|
||||
@@ -98,15 +142,10 @@ protected:
|
||||
SbLineProjector projector;
|
||||
|
||||
private:
|
||||
SoCalculator* calculator;
|
||||
|
||||
SbVec3f roundTranslation(const SbVec3f &vecIn, float incrementIn);
|
||||
|
||||
SoSeparator* buildCylinderGeometry();
|
||||
SoSeparator* buildConeGeometry();
|
||||
SoSeparator* buildLabelGeometry();
|
||||
SoBaseColor* buildActiveColor();
|
||||
void setupGeometryCalculator();
|
||||
|
||||
using inherited = SoDragger;
|
||||
};
|
||||
@@ -126,9 +165,8 @@ public:
|
||||
SoSFRotation rotation;
|
||||
SoSFColor color;
|
||||
SoSFVec3f translation;
|
||||
SoSFBool visible;
|
||||
|
||||
void setVisibility(bool visible);
|
||||
bool isVisible();
|
||||
void setPointerDirection(const Base::Vector3d& dir);
|
||||
|
||||
SoLinearDragger* getDragger();
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <Inventor/nodes/SoText2.h>
|
||||
#include <Inventor/nodes/SoAnnotation.h>
|
||||
#include <Inventor/nodes/SoFontStyle.h>
|
||||
#include <Inventor/engines/SoCalculator.h>
|
||||
#endif
|
||||
|
||||
#include <Base/Quantity.h>
|
||||
@@ -55,12 +56,96 @@
|
||||
#include "SoRotationDragger.h"
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include "SoFCDB.h"
|
||||
#include "Utilities.h"
|
||||
|
||||
#include <SoTextLabel.h>
|
||||
#include <Inventor/SoToggleSwitch.h>
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
SO_KIT_SOURCE(SoRotatorGeometryKit)
|
||||
|
||||
void SoRotatorGeometryKit::initClass()
|
||||
{
|
||||
SO_KIT_INIT_CLASS(SoRotatorGeometryKit, SoBaseKit, "BaseKit");
|
||||
}
|
||||
|
||||
SoRotatorGeometryKit::SoRotatorGeometryKit()
|
||||
{
|
||||
SO_KIT_CONSTRUCTOR(SoRotatorGeometryKit);
|
||||
|
||||
SO_KIT_ADD_FIELD(pivotPosition, (0.0, 0.0, 0.0));
|
||||
|
||||
SO_KIT_INIT_INSTANCE();
|
||||
}
|
||||
|
||||
SO_KIT_SOURCE(SoRotatorGeometry)
|
||||
|
||||
void SoRotatorGeometry::initClass()
|
||||
{
|
||||
SO_KIT_INIT_CLASS(SoRotatorGeometry, SoRotatorGeometryKit, "RotatorGeometryKit");
|
||||
}
|
||||
|
||||
SoRotatorGeometry::SoRotatorGeometry()
|
||||
{
|
||||
SO_KIT_CONSTRUCTOR(SoRotatorGeometry);
|
||||
SO_KIT_ADD_CATALOG_ENTRY(lightModel, SoLightModel, false, this, "", false);
|
||||
SO_KIT_ADD_CATALOG_ENTRY(drawStyle, SoDrawStyle, false, this, "", false);
|
||||
SO_KIT_ADD_CATALOG_ENTRY(arcCoords, SoCoordinate3, false, this, "", true);
|
||||
SO_KIT_ADD_CATALOG_ENTRY(arc, SoLineSet, false, this, "", true);
|
||||
SO_KIT_ADD_CATALOG_ENTRY(rotorPivot, SoSphere, false, this, "", true);
|
||||
|
||||
SO_KIT_ADD_CATALOG_ENTRY(_rotorPivotTranslation, SoTranslation, false, this, rotorPivot, false);
|
||||
|
||||
SO_KIT_ADD_FIELD(arcRadius, (8.0));
|
||||
SO_KIT_ADD_FIELD(arcAngle, (std::numbers::pi_v<float> / 2.0f));
|
||||
SO_KIT_ADD_FIELD(sphereRadius, (0.8));
|
||||
SO_KIT_ADD_FIELD(arcThickness, (4.0));
|
||||
|
||||
SO_KIT_INIT_INSTANCE();
|
||||
|
||||
auto rotorPivot = SO_GET_ANY_PART(this, "rotorPivot", SoSphere);
|
||||
rotorPivot->radius.connectFrom(&sphereRadius);
|
||||
|
||||
auto drawStyle = SO_GET_ANY_PART(this, "drawStyle", SoDrawStyle);
|
||||
drawStyle->lineWidth.connectFrom(&arcThickness);
|
||||
|
||||
auto translation = SO_GET_ANY_PART(this, "_rotorPivotTranslation", SoTranslation);
|
||||
pivotPosition.connectFrom(&translation->translation);
|
||||
|
||||
auto arc = SO_GET_ANY_PART(this, "arc", SoLineSet);
|
||||
arc->numVertices = segments + 1;
|
||||
|
||||
auto lightModel = SO_GET_ANY_PART(this, "lightModel", SoLightModel);
|
||||
lightModel->model = SoLightModel::BASE_COLOR;
|
||||
|
||||
// forces the notify method to get called so that the initial translations and other values are set
|
||||
arcRadius.touch();
|
||||
}
|
||||
|
||||
void SoRotatorGeometry::notify(SoNotList* notList)
|
||||
{
|
||||
assert(notList);
|
||||
SoField* lastField = notList->getLastField();
|
||||
|
||||
if (lastField == &arcRadius || lastField == &arcAngle) {
|
||||
float angle = arcAngle.getValue();
|
||||
float radius = arcRadius.getValue();
|
||||
|
||||
auto coordinates = SO_GET_ANY_PART(this, "arcCoords", SoCoordinate3);
|
||||
float angleIncrement = angle / static_cast<float>(segments);
|
||||
SbRotation rotation(SbVec3f(0.0, 0.0, 1.0), angleIncrement);
|
||||
SbVec3f point(radius, 0.0, 0.0);
|
||||
for (int index = 0; index <= segments; ++index) {
|
||||
coordinates->point.set1Value(index, point);
|
||||
rotation.multVec(point, point);
|
||||
}
|
||||
|
||||
auto translation = SO_GET_ANY_PART(this, "_rotorPivotTranslation", SoTranslation);
|
||||
translation->translation = {radius * cos(angle / 2.0f), radius * sin(angle / 2.0f), 0};
|
||||
}
|
||||
}
|
||||
|
||||
SO_KIT_SOURCE(SoRotationDragger)
|
||||
|
||||
void SoRotationDragger::initClass()
|
||||
@@ -75,30 +160,23 @@ 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, SoToggleSwitch, geomSeparator);
|
||||
FC_ADD_CATALOG_ENTRY(secondaryColor, SoBaseColor, activeSwitch);
|
||||
FC_ADD_CATALOG_ENTRY(scale, SoScale, geomSeparator);
|
||||
SO_KIT_ADD_CATALOG_ABSTRACT_ENTRY(rotator, SoRotatorGeometryKit, SoRotatorGeometry, false, geomSeparator, "", true);
|
||||
|
||||
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(geometryScale, (1, 1, 1));
|
||||
|
||||
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");
|
||||
setPart("secondaryColor", buildActiveColor());
|
||||
|
||||
SoSwitch* sw = SO_GET_ANY_PART(this, "rotatorSwitch", SoSwitch);
|
||||
SoInteractionKit::setSwitchValue(sw, 0);
|
||||
auto scale = SO_GET_ANY_PART(this, "scale", SoScale);
|
||||
scale->scaleFactor.connectFrom(&geometryScale);
|
||||
|
||||
this->addStartCallback(&SoRotationDragger::startCB);
|
||||
this->addMotionCallback(&SoRotationDragger::motionCB);
|
||||
@@ -111,6 +189,8 @@ SoRotationDragger::SoRotationDragger()
|
||||
fieldSensor.setPriority(0);
|
||||
|
||||
this->setUpConnections(TRUE, TRUE);
|
||||
|
||||
FC_SET_TOGGLE_SWITCH("activeSwitch", false);
|
||||
}
|
||||
|
||||
SoRotationDragger::~SoRotationDragger()
|
||||
@@ -124,72 +204,12 @@ SoRotationDragger::~SoRotationDragger()
|
||||
removeValueChangedCallback(&SoRotationDragger::valueChangedCB);
|
||||
}
|
||||
|
||||
void SoRotationDragger::buildFirstInstance()
|
||||
SoBaseColor* SoRotationDragger::buildActiveColor()
|
||||
{
|
||||
SoGroup* geometryGroup = buildGeometry();
|
||||
auto color = new SoBaseColor;
|
||||
color->rgb.connectFrom(&activeColor);
|
||||
|
||||
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<float> / 2.f) / static_cast<float>(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);
|
||||
}
|
||||
root->addChild(coordinates);
|
||||
|
||||
auto drawStyle = new SoDrawStyle();
|
||||
drawStyle->lineWidth = 4.0;
|
||||
root->addChild(drawStyle);
|
||||
|
||||
auto lightModel = new SoLightModel();
|
||||
lightModel->model = SoLightModel::BASE_COLOR;
|
||||
root->addChild(lightModel);
|
||||
|
||||
auto lineSet = new SoLineSet();
|
||||
lineSet->numVertices.setValue(segments + 1);
|
||||
root->addChild(lineSet);
|
||||
|
||||
auto pickStyle = new SoPickStyle();
|
||||
pickStyle->style.setValue(SoPickStyle::SHAPE_ON_TOP);
|
||||
pickStyle->setOverride(TRUE);
|
||||
root->addChild(pickStyle);
|
||||
|
||||
// sphere.
|
||||
SbVec3f origin(1.0, 1.0, 0.0);
|
||||
origin.normalize();
|
||||
origin *= arcRadius;
|
||||
auto sphereTranslation = new SoTranslation();
|
||||
sphereTranslation->translation.setValue(origin);
|
||||
root->addChild(sphereTranslation);
|
||||
|
||||
auto sphere = new SoSphere();
|
||||
sphere->radius.setValue(0.8F);
|
||||
root->addChild(sphere);
|
||||
|
||||
return root;
|
||||
return color;
|
||||
}
|
||||
|
||||
void SoRotationDragger::startCB(void*, SoDragger* d)
|
||||
@@ -232,10 +252,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 +263,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_TOGGLE_SWITCH("activeSwitch", true);
|
||||
|
||||
projector.setViewVolume(this->getViewVolume());
|
||||
projector.setWorkingSpace(this->getLocalToWorldMatrix());
|
||||
@@ -320,9 +335,7 @@ void SoRotationDragger::drag()
|
||||
|
||||
void SoRotationDragger::dragFinish()
|
||||
{
|
||||
SoSwitch* sw;
|
||||
sw = SO_GET_ANY_PART(this, "rotatorSwitch", SoSwitch);
|
||||
SoInteractionKit::setSwitchValue(sw, 0);
|
||||
FC_SET_TOGGLE_SWITCH("activeSwitch", false);
|
||||
}
|
||||
|
||||
SbBool SoRotationDragger::setUpConnections(SbBool onoff, SbBool doitalways)
|
||||
@@ -365,3 +378,73 @@ 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, SoToggleSwitch, 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_ADD_FIELD(visible, (1));
|
||||
|
||||
SO_KIT_INIT_INSTANCE();
|
||||
|
||||
setPart("baseColor", buildColor());
|
||||
setPart("transform", buildTransform());
|
||||
|
||||
auto sw = SO_GET_ANY_PART(this, "draggerSwitch", SoToggleSwitch);
|
||||
sw->on.connectFrom(&visible);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
SoRotationDragger* SoRotationDraggerContainer::getDragger()
|
||||
{
|
||||
return SO_GET_PART(this, "dragger", SoRotationDragger);
|
||||
}
|
||||
|
||||
void Gui::SoRotationDraggerContainer::setPointerDirection(const Base::Vector3d& dir)
|
||||
{
|
||||
// This is the direction from the origin to the spherical pivot of the rotator
|
||||
Base::Vector3d draggerDir = Base::convertTo<Base::Vector3d>(
|
||||
SO_GET_ANY_PART(this, "rotator", SoRotatorGeometryKit)->pivotPosition.getValue()
|
||||
);
|
||||
|
||||
Base::Vector3d axis = draggerDir.Cross(dir).Normalize();
|
||||
double ang = draggerDir.GetAngleOriented(dir, axis);
|
||||
|
||||
SbRotation rot{Base::convertTo<SbVec3f>(axis), static_cast<float>(ang)};
|
||||
rotation.setValue(rot);
|
||||
}
|
||||
|
||||
@@ -33,9 +33,67 @@
|
||||
#include <Inventor/projectors/SbLineProjector.h>
|
||||
#include <Inventor/projectors/SbPlaneProjector.h>
|
||||
#include <Inventor/nodes/SoBaseColor.h>
|
||||
#include <Base/Vector3D.h>
|
||||
|
||||
class SoTransform;
|
||||
class SoCalculator;
|
||||
class SoCoordinate3;
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
class SoRotatorGeometryKit: public SoBaseKit
|
||||
{
|
||||
SO_KIT_HEADER(SoLinearGeometryKit);
|
||||
|
||||
public:
|
||||
static void initClass();
|
||||
|
||||
SoSFVec3f pivotPosition;
|
||||
|
||||
protected:
|
||||
SoRotatorGeometryKit();
|
||||
~SoRotatorGeometryKit() override = default;
|
||||
|
||||
private:
|
||||
using inherited = SoBaseKit;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Rotator geometry
|
||||
*
|
||||
* A class to contain the geometry for SoRotationDragger
|
||||
*/
|
||||
class SoRotatorGeometry: public SoRotatorGeometryKit
|
||||
{
|
||||
SO_KIT_HEADER(SoArrowGeometry);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(lightModel);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(drawStyle);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(arcCoords);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(arc);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(rotorPivot);
|
||||
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(_rotorPivotTranslation);
|
||||
|
||||
public:
|
||||
static void initClass();
|
||||
SoRotatorGeometry();
|
||||
|
||||
SoSFFloat arcAngle; //!< in radians
|
||||
SoSFFloat arcRadius;
|
||||
SoSFFloat sphereRadius;
|
||||
SoSFFloat arcThickness;
|
||||
|
||||
protected:
|
||||
~SoRotatorGeometry() override = default;
|
||||
|
||||
void notify(SoNotList* notList) override;
|
||||
|
||||
private:
|
||||
constexpr static int segments = 10; //!< segments of the arc per arcAngle
|
||||
|
||||
using inherited = SoRotatorGeometryKit;
|
||||
};
|
||||
|
||||
/*! @brief Rotation Dragger.
|
||||
*
|
||||
* used for rotating around an axis. Set the rotation
|
||||
@@ -46,16 +104,20 @@ namespace Gui
|
||||
class SoRotationDragger : public SoDragger
|
||||
{
|
||||
SO_KIT_HEADER(SoRotationDragger);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(rotatorSwitch);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(activeSwitch);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(secondaryColor);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(scale);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(rotator);
|
||||
SO_KIT_CATALOG_ENTRY_HEADER(rotatorActive);
|
||||
|
||||
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; //!< colour of the dragger while being dragged.
|
||||
SoSFVec3f geometryScale; //!< the scale of the dragger geometry
|
||||
|
||||
protected:
|
||||
~SoRotationDragger() override;
|
||||
@@ -73,15 +135,42 @@ protected:
|
||||
|
||||
SoFieldSensor fieldSensor;
|
||||
SbPlaneProjector projector;
|
||||
float arcRadius;
|
||||
|
||||
private:
|
||||
void buildFirstInstance();
|
||||
int roundIncrement(const float &radiansIn);
|
||||
SoGroup* buildGeometry();
|
||||
SoBaseColor* buildActiveColor();
|
||||
|
||||
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;
|
||||
SoSFBool visible;
|
||||
|
||||
void setPointerDirection(const Base::Vector3d& dir);
|
||||
|
||||
SoRotationDragger* getDragger();
|
||||
|
||||
private:
|
||||
SoBaseColor* buildColor();
|
||||
SoTransform* buildTransform();
|
||||
|
||||
using inherited = SoInteractionKit;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* GUI_ROTATION_DRAGGER_H */
|
||||
|
||||
@@ -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
|
||||
@@ -656,49 +626,49 @@ void SoTransformDragger::setAxisColors(unsigned long x, unsigned long y, unsigne
|
||||
void SoTransformDragger::showTranslationX()
|
||||
{
|
||||
auto tDragger = SO_GET_ANY_PART(this, "xTranslatorDragger", SoLinearDraggerContainer);
|
||||
tDragger->setVisibility(true);
|
||||
tDragger->visible = true;
|
||||
}
|
||||
void SoTransformDragger::showTranslationY()
|
||||
{
|
||||
auto tDragger = SO_GET_ANY_PART(this, "yTranslatorDragger", SoLinearDraggerContainer);
|
||||
tDragger->setVisibility(true);
|
||||
tDragger->visible = true;
|
||||
}
|
||||
void SoTransformDragger::showTranslationZ()
|
||||
{
|
||||
auto tDragger = SO_GET_ANY_PART(this, "zTranslatorDragger", SoLinearDraggerContainer);
|
||||
tDragger->setVisibility(true);
|
||||
tDragger->visible = true;
|
||||
}
|
||||
|
||||
void SoTransformDragger::hideTranslationX()
|
||||
{
|
||||
auto tDragger = SO_GET_ANY_PART(this, "xTranslatorDragger", SoLinearDraggerContainer);
|
||||
tDragger->setVisibility(false);
|
||||
tDragger->visible = false;
|
||||
}
|
||||
void SoTransformDragger::hideTranslationY()
|
||||
{
|
||||
auto tDragger = SO_GET_ANY_PART(this, "yTranslatorDragger", SoLinearDraggerContainer);
|
||||
tDragger->setVisibility(false);
|
||||
tDragger->visible = false;
|
||||
}
|
||||
void SoTransformDragger::hideTranslationZ()
|
||||
{
|
||||
auto tDragger = SO_GET_ANY_PART(this, "zTranslatorDragger", SoLinearDraggerContainer);
|
||||
tDragger->setVisibility(false);
|
||||
tDragger->visible = false;
|
||||
}
|
||||
|
||||
bool SoTransformDragger::isShownTranslationX()
|
||||
{
|
||||
auto tDragger = SO_GET_ANY_PART(this, "xTranslatorDragger", SoLinearDraggerContainer);
|
||||
return tDragger->isVisible();
|
||||
return tDragger->visible.getValue();
|
||||
}
|
||||
bool SoTransformDragger::isShownTranslationY()
|
||||
{
|
||||
auto tDragger = SO_GET_ANY_PART(this, "yTranslatorDragger", SoLinearDraggerContainer);
|
||||
return tDragger->isVisible();
|
||||
return tDragger->visible.getValue();
|
||||
}
|
||||
bool SoTransformDragger::isShownTranslationZ()
|
||||
{
|
||||
auto tDragger = SO_GET_ANY_PART(this, "zTranslatorDragger", SoLinearDraggerContainer);
|
||||
return tDragger->isVisible();
|
||||
return tDragger->visible.getValue();
|
||||
}
|
||||
|
||||
// Planar Translator
|
||||
@@ -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->visible = 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->visible = 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->visible = 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->visible = 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->visible = 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->visible = 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->visible.getValue();
|
||||
}
|
||||
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->visible.getValue();
|
||||
}
|
||||
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->visible.getValue();
|
||||
}
|
||||
|
||||
void SoTransformDragger::setupTranslationDraggers()
|
||||
@@ -850,3 +804,19 @@ void SoTransformDragger::setupTranslationDragger(const std::string& name, SoSFSt
|
||||
|
||||
draggerContainer->setPointerDirection(Base::convertTo<Base::Vector3d>(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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
54
src/Gui/Inventor/SoToggleSwitch.cpp
Normal file
54
src/Gui/Inventor/SoToggleSwitch.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2025 Sayantan Deb <sayantandebin[at]gmail.com> *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
* *
|
||||
* FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 2.1 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* FreeCAD is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with FreeCAD. If not, see *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "SoToggleSwitch.h"
|
||||
|
||||
SO_NODE_SOURCE(SoToggleSwitch)
|
||||
|
||||
void SoToggleSwitch::initClass()
|
||||
{
|
||||
SO_NODE_INIT_CLASS(SoToggleSwitch, SoSwitch, "Switch");
|
||||
}
|
||||
|
||||
SoToggleSwitch::SoToggleSwitch()
|
||||
{
|
||||
SO_NODE_CONSTRUCTOR(SoToggleSwitch);
|
||||
SO_NODE_ADD_FIELD(on, (1));
|
||||
|
||||
whichChild = SO_SWITCH_ALL;
|
||||
}
|
||||
|
||||
void SoToggleSwitch::toggle()
|
||||
{
|
||||
on = !on.getValue();
|
||||
}
|
||||
|
||||
void SoToggleSwitch::notify(SoNotList* notList)
|
||||
{
|
||||
assert(notList);
|
||||
if (notList->getLastField() == &on) {
|
||||
whichChild = on.getValue()? SO_SWITCH_ALL : SO_SWITCH_NONE;
|
||||
}
|
||||
|
||||
inherited::notify(notList);
|
||||
}
|
||||
56
src/Gui/Inventor/SoToggleSwitch.h
Normal file
56
src/Gui/Inventor/SoToggleSwitch.h
Normal file
@@ -0,0 +1,56 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2025 Sayantan Deb <sayantandebin[at]gmail.com> *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
* *
|
||||
* FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 2.1 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* FreeCAD is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with FreeCAD. If not, see *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef SO_TOGGLE_SWITCH
|
||||
#define SO_TOGGLE_SWITCH
|
||||
|
||||
#include <Inventor/fields/SoSFBool.h>
|
||||
#include <Inventor/nodes/SoSwitch.h>
|
||||
|
||||
|
||||
/**
|
||||
* A switch that can be used to show or hide all child nodes
|
||||
*/
|
||||
class SoToggleSwitch: public SoSwitch
|
||||
{
|
||||
SO_NODE_HEADER(SoToggleSwitch);
|
||||
|
||||
public:
|
||||
static void initClass();
|
||||
SoToggleSwitch();
|
||||
|
||||
// the switch is on be default
|
||||
SoSFBool on;
|
||||
// toggles the switch state
|
||||
void toggle();
|
||||
|
||||
protected:
|
||||
~SoToggleSwitch() override = default;
|
||||
|
||||
void notify(SoNotList* notList) override;
|
||||
|
||||
private:
|
||||
using inherited = SoSwitch;
|
||||
};
|
||||
|
||||
#endif /* SO_TOGGLE_SWITCH */
|
||||
@@ -51,6 +51,8 @@
|
||||
#include "Camera.h"
|
||||
#include "Flag.h"
|
||||
#include "Inventor/Draggers/SoTransformDragger.h"
|
||||
#include "Inventor/Draggers/SoLinearDragger.h"
|
||||
#include "Inventor/Draggers/SoRotationDragger.h"
|
||||
#include "Navigation/GestureNavigationStyle.h"
|
||||
#include "Navigation/NavigationStyle.h"
|
||||
#include "Navigation/SiemensNXNavigationStyle.h"
|
||||
@@ -77,6 +79,7 @@
|
||||
#include "Inventor/SoFCBoundingBox.h"
|
||||
#include "Inventor/SoMouseWheelEvent.h"
|
||||
#include "Inventor/SoFCTransform.h"
|
||||
#include "Inventor/SoToggleSwitch.h"
|
||||
#include "propertyeditor/PropertyItem.h"
|
||||
#include "ArcEngine.h"
|
||||
|
||||
@@ -144,6 +147,11 @@ void Gui::SoFCDB::init()
|
||||
SoAutoZoomTranslation ::initClass();
|
||||
MarkerBitmaps ::initClass();
|
||||
SoTransformDragger ::initClass();
|
||||
SoLinearGeometryKit ::initClass();
|
||||
SoArrowGeometry ::initClass();
|
||||
SoRotatorGeometryKit ::initClass();
|
||||
SoRotatorGeometry ::initClass();
|
||||
SoToggleSwitch ::initClass();
|
||||
SmSwitchboard ::initClass();
|
||||
SoFCSeparator ::initClass();
|
||||
SoFCSelectionRoot ::initClass();
|
||||
|
||||
@@ -446,9 +446,16 @@ private:
|
||||
#define FC_SET_SWITCH(__name__, __state__) \
|
||||
do { \
|
||||
SoSwitch* sw = SO_GET_ANY_PART(this, __name__, SoSwitch); \
|
||||
assert(sw); \
|
||||
sw->whichChild = __state__; \
|
||||
} while (0)
|
||||
|
||||
#define FC_SET_TOGGLE_SWITCH(__name__, __state__) \
|
||||
do { \
|
||||
SoToggleSwitch* sw = SO_GET_ANY_PART(this, __name__, SoToggleSwitch); \
|
||||
assert(sw); \
|
||||
sw->on = __state__; \
|
||||
} while (0)
|
||||
|
||||
struct RotationComponents {
|
||||
float angle;
|
||||
|
||||
Reference in New Issue
Block a user