App: handle sub-components in PropertyRotation

This commit is contained in:
wmayer
2022-12-14 21:21:02 +01:00
parent 7948181a4d
commit 9e702c016b
2 changed files with 55 additions and 24 deletions

View File

@@ -1004,30 +1004,29 @@ void PropertyRotation::getPaths(std::vector<ObjectIdentifier> &paths) const
void PropertyRotation::setPathValue(const ObjectIdentifier &path, const boost::any &value)
{
if (path.getSubPathStr() == ".Angle") {
double avalue;
auto updateAxis = [=](int index, double coord) {
Base::Vector3d axis;
double angle;
_rot.getRawValue(axis, angle);
if (value.type() == typeid(Base::Quantity))
avalue = boost::any_cast<Base::Quantity>(value).getValue();
else if (value.type() == typeid(double))
avalue = boost::any_cast<double>(value);
else if (value.type() == typeid(int))
avalue = boost::any_cast<int>(value);
else if (value.type() == typeid(unsigned int))
avalue = boost::any_cast<unsigned int >(value);
else if (value.type() == typeid(short))
avalue = boost::any_cast<short>(value);
else if (value.type() == typeid(unsigned short))
avalue = boost::any_cast<unsigned short>(value);
else if (value.type() == typeid(long))
avalue = boost::any_cast<long>(value);
else if (value.type() == typeid(unsigned long))
avalue = boost::any_cast<unsigned long>(value);
else
throw std::bad_cast();
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<double>(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;
}

View File

@@ -2446,11 +2446,9 @@ QVariant PropertyRotationItem::editorData(QWidget *editor) const
void PropertyRotationItem::propertyBound()
{
if (isBound()) {
m_a->bind(App::ObjectIdentifier(getPath())<<App::ObjectIdentifier::String("Rotation")
<<App::ObjectIdentifier::String("Angle"));
m_a->bind(App::ObjectIdentifier(getPath())<<App::ObjectIdentifier::String("Angle"));
m_d->bind(App::ObjectIdentifier(getPath())<<App::ObjectIdentifier::String("Rotation")
<<App::ObjectIdentifier::String("Axis"));
m_d->bind(App::ObjectIdentifier(getPath())<<App::ObjectIdentifier::String("Axis"));
}
}