Skip to content

Commit

Permalink
App: handle sub-components in PropertyRotation
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Dec 14, 2022
1 parent 7948181 commit 9e702c0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 25 deletions.
75 changes: 54 additions & 21 deletions src/App/PropertyGeo.cpp
Expand Up @@ -1004,57 +1004,90 @@ void PropertyRotation::getPaths(std::vector<ObjectIdentifier> &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<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();
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);
}
}

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);
}
}

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;
_rot.getValue(axis,angle);
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;
}
Expand Down
6 changes: 2 additions & 4 deletions src/Gui/propertyeditor/PropertyItem.cpp
Expand Up @@ -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"));
}
}

Expand Down

0 comments on commit 9e702c0

Please sign in to comment.