Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@ void setFieldsFromPythonValues(Base* self, const py::kwargs& dict)
/// Implement the addObject function.
py::object addObjectKwargs(Node* self, const std::string& type, const py::kwargs& kwargs)
{
using namespace pybind11::literals;

auto numpy = py::module_::import("numpy");
std::string version = py::cast<std::string>(numpy.attr("__version__"));
if ( std::stoi(version.substr(0,1)) >= 2)
{
py::object setPO = numpy.attr("set_printoptions");
setPO("legacy"_a = true);
}


std::string name {};
if (kwargs.contains("name"))
{
Expand Down Expand Up @@ -292,6 +303,15 @@ py::object addObjectKwargs(Node* self, const std::string& type, const py::kwargs
if(d)
d->setPersistent(true);
}


if ( std::stoi(version.substr(0,1)) >= 2)
{
py::object setPO = numpy.attr("set_printoptions");
setPO();
}


return PythonFactory::toPython(object.get());
}

Expand Down Expand Up @@ -361,6 +381,16 @@ py::object createObject(Node* self, const std::string& type, const py::kwargs& k

py::object addChildKwargs(Node* self, const std::string& name, const py::kwargs& kwargs)
{
using namespace pybind11::literals;

auto numpy = py::module_::import("numpy");
std::string version = py::cast<std::string>(numpy.attr("__version__"));
if ( std::stoi(version.substr(0,1)) >= 2)
{
py::object setPO = numpy.attr("set_printoptions");
setPO("legacy"_a = true);
}

if (sofapython3::isProtectedKeyword(name))
throw py::value_error("addChild: Cannot call addChild with name " + name + ": Protected keyword");
BaseObjectDescription desc (name.c_str());
Expand All @@ -379,6 +409,12 @@ py::object addChildKwargs(Node* self, const std::string& name, const py::kwargs&
d->setPersistent(true);
}

if ( std::stoi(version.substr(0,1)) >= 2)
{
py::object setPO = numpy.attr("set_printoptions");
setPO();
}

return py::cast(node);
}

Expand Down
Loading