From 9e702c016bcc6318ea35a69437241ae67f92524d Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 14 Dec 2022 21:21:02 +0100 Subject: [PATCH] App: handle sub-components in PropertyRotation --- src/App/PropertyGeo.cpp | 75 ++++++++++++++++++------- src/Gui/propertyeditor/PropertyItem.cpp | 6 +- 2 files changed, 56 insertions(+), 25 deletions(-) diff --git a/src/App/PropertyGeo.cpp b/src/App/PropertyGeo.cpp index 9776d707962c..b68c22d8dce6 100644 --- a/src/App/PropertyGeo.cpp +++ b/src/App/PropertyGeo.cpp @@ -1004,30 +1004,29 @@ void PropertyRotation::getPaths(std::vector &paths) const void PropertyRotation::setPathValue(const ObjectIdentifier &path, const boost::any &value) { - if (path.getSubPathStr() == ".Angle") { - double avalue; - - if (value.type() == typeid(Base::Quantity)) - avalue = boost::any_cast(value).getValue(); - else if (value.type() == typeid(double)) - avalue = boost::any_cast(value); - else if (value.type() == typeid(int)) - avalue = boost::any_cast(value); - else if (value.type() == typeid(unsigned int)) - avalue = boost::any_cast(value); - else if (value.type() == typeid(short)) - avalue = boost::any_cast(value); - else if (value.type() == typeid(unsigned short)) - avalue = boost::any_cast(value); - else if (value.type() == typeid(long)) - avalue = boost::any_cast(value); - else if (value.type() == typeid(unsigned long)) - avalue = boost::any_cast(value); - else - throw std::bad_cast(); + auto updateAxis = [=](int index, double coord) { + Base::Vector3d axis; + double angle; + _rot.getRawValue(axis, angle); + axis[index] = coord; + setValue(Base::Rotation{axis, angle}); + }; + + std::string subpath = path.getSubPathStr(); + if (subpath == ".Angle") { + double avalue = toDouble(value); Property::setPathValue(path, Base::toRadians(avalue)); } + else if (subpath == ".Axis.x") { + updateAxis(0, toDouble(value)); + } + else if (subpath == ".Axis.y") { + updateAxis(1, toDouble(value)); + } + else if (subpath == ".Axis.z") { + updateAxis(2, toDouble(value)); + } else { Property::setPathValue(path, value); } @@ -1035,12 +1034,27 @@ void PropertyRotation::setPathValue(const ObjectIdentifier &path, const boost::a const boost::any PropertyRotation::getPathValue(const ObjectIdentifier &path) const { + auto getAxis = [](const Base::Rotation& rot) { + Base::Vector3d axis; + double angle; + rot.getRawValue(axis, angle); + return axis; + }; std::string p = path.getSubPathStr(); if (p == ".Angle") { // Convert angle to degrees return Base::Quantity(Base::toDegrees(boost::any_cast(Property::getPathValue(path))), Unit::Angle); } + else if (p == ".Axis.x") { + return getAxis(_rot).x; + } + else if (p == ".Axis.y") { + return getAxis(_rot).y; + } + else if (p == ".Axis.z") { + return getAxis(_rot).z; + } else { return Property::getPathValue(path); } @@ -1048,6 +1062,13 @@ const boost::any PropertyRotation::getPathValue(const ObjectIdentifier &path) co bool PropertyRotation::getPyPathValue(const ObjectIdentifier &path, Py::Object &res) const { + auto getAxis = [](const Base::Rotation& rot) { + Base::Vector3d axis; + double angle; + rot.getRawValue(axis, angle); + return axis; + }; + std::string p = path.getSubPathStr(); if (p == ".Angle") { Base::Vector3d axis; double angle; @@ -1055,6 +1076,18 @@ bool PropertyRotation::getPyPathValue(const ObjectIdentifier &path, Py::Object & res = Py::asObject(new QuantityPy(new Quantity(Base::toDegrees(angle),Unit::Angle))); return true; } + else if (p == ".Axis.x") { + res = Py::Float(getAxis(_rot).x); + return true; + } + else if (p == ".Axis.y") { + res = Py::Float(getAxis(_rot).y); + return true; + } + else if (p == ".Axis.z") { + res = Py::Float(getAxis(_rot).z); + return true; + } return false; } diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 63f1495ee781..b6d5afd02cf5 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -2446,11 +2446,9 @@ QVariant PropertyRotationItem::editorData(QWidget *editor) const void PropertyRotationItem::propertyBound() { if (isBound()) { - m_a->bind(App::ObjectIdentifier(getPath())<bind(App::ObjectIdentifier(getPath())<bind(App::ObjectIdentifier(getPath())<bind(App::ObjectIdentifier(getPath())<