App: handle sub-components in PropertyPlacement
This commit is contained in:
@@ -558,38 +558,75 @@ void PropertyPlacement::getPaths(std::vector<ObjectIdentifier> &paths) const
|
||||
<< ObjectIdentifier::SimpleComponent(ObjectIdentifier::String("z")));
|
||||
}
|
||||
|
||||
namespace {
|
||||
double toDouble(const boost::any &value)
|
||||
{
|
||||
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();
|
||||
return avalue;
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyPlacement::setPathValue(const ObjectIdentifier &path, const boost::any &value)
|
||||
{
|
||||
if (path.getSubPathStr() == ".Rotation.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;
|
||||
Base::Vector3d base = _cPos.getPosition();
|
||||
Base::Rotation rot = _cPos.getRotation();
|
||||
rot.getRawValue(axis, angle);
|
||||
axis[index] = coord;
|
||||
rot.setValue(axis, angle);
|
||||
Base::Placement plm(base, rot);
|
||||
setValue(plm);
|
||||
};
|
||||
|
||||
std::string subpath = path.getSubPathStr();
|
||||
if (subpath == ".Rotation.Angle") {
|
||||
double avalue = toDouble(value);
|
||||
Property::setPathValue(path, Base::toRadians(avalue));
|
||||
}
|
||||
else
|
||||
else if (subpath == ".Rotation.Axis.x") {
|
||||
updateAxis(0, toDouble(value));
|
||||
}
|
||||
else if (subpath == ".Rotation.Axis.y") {
|
||||
updateAxis(1, toDouble(value));
|
||||
}
|
||||
else if (subpath == ".Rotation.Axis.z") {
|
||||
updateAxis(2, toDouble(value));
|
||||
}
|
||||
else {
|
||||
Property::setPathValue(path, value);
|
||||
}
|
||||
}
|
||||
|
||||
const boost::any PropertyPlacement::getPathValue(const ObjectIdentifier &path) const
|
||||
{
|
||||
auto getAxis = [](const Base::Placement& plm) {
|
||||
Base::Vector3d axis;
|
||||
double angle;
|
||||
const Base::Rotation& rot = plm.getRotation();
|
||||
rot.getRawValue(axis, angle);
|
||||
return axis;
|
||||
};
|
||||
std::string p = path.getSubPathStr();
|
||||
|
||||
if (p == ".Rotation.Angle") {
|
||||
@@ -600,26 +637,63 @@ const boost::any PropertyPlacement::getPathValue(const ObjectIdentifier &path) c
|
||||
// Convert double to quantity
|
||||
return Base::Quantity(boost::any_cast<double>(Property::getPathValue(path)), Unit::Length);
|
||||
}
|
||||
else
|
||||
else if (p == ".Rotation.Axis.x") {
|
||||
return getAxis(_cPos).x;
|
||||
}
|
||||
else if (p == ".Rotation.Axis.y") {
|
||||
return getAxis(_cPos).y;
|
||||
}
|
||||
else if (p == ".Rotation.Axis.z") {
|
||||
return getAxis(_cPos).z;
|
||||
}
|
||||
else {
|
||||
return Property::getPathValue(path);
|
||||
}
|
||||
}
|
||||
|
||||
bool PropertyPlacement::getPyPathValue(const ObjectIdentifier &path, Py::Object &res) const
|
||||
{
|
||||
auto getAxis = [](const Base::Placement& plm) {
|
||||
Base::Vector3d axis;
|
||||
double angle;
|
||||
const Base::Rotation& rot = plm.getRotation();
|
||||
rot.getRawValue(axis, angle);
|
||||
return axis;
|
||||
};
|
||||
|
||||
std::string p = path.getSubPathStr();
|
||||
if (p == ".Rotation.Angle") {
|
||||
Base::Vector3d axis; double angle;
|
||||
_cPos.getRotation().getValue(axis,angle);
|
||||
res = Py::asObject(new QuantityPy(new Quantity(Base::toDegrees(angle),Unit::Angle)));
|
||||
} else if (p == ".Base.x") {
|
||||
return true;
|
||||
}
|
||||
else if (p == ".Base.x") {
|
||||
res = Py::asObject(new QuantityPy(new Quantity(_cPos.getPosition().x,Unit::Length)));
|
||||
} else if (p == ".Base.y") {
|
||||
return true;
|
||||
}
|
||||
else if (p == ".Base.y") {
|
||||
res = Py::asObject(new QuantityPy(new Quantity(_cPos.getPosition().y,Unit::Length)));
|
||||
} else if (p == ".Base.z") {
|
||||
return true;
|
||||
}
|
||||
else if (p == ".Base.z") {
|
||||
res = Py::asObject(new QuantityPy(new Quantity(_cPos.getPosition().z,Unit::Length)));
|
||||
} else
|
||||
return false;
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
else if (p == ".Rotation.Axis.x") {
|
||||
res = Py::Float(getAxis(_cPos).x);
|
||||
return true;
|
||||
}
|
||||
else if (p == ".Rotation.Axis.y") {
|
||||
res = Py::Float(getAxis(_cPos).y);
|
||||
return true;
|
||||
}
|
||||
else if (p == ".Rotation.Axis.z") {
|
||||
res = Py::Float(getAxis(_cPos).z);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
PyObject *PropertyPlacement::getPyObject()
|
||||
|
||||
Reference in New Issue
Block a user