diff --git a/Plugin/src/SofaPython3/PythonEnvironment.cpp b/Plugin/src/SofaPython3/PythonEnvironment.cpp index 4dc4c5d9..0cf17cb7 100644 --- a/Plugin/src/SofaPython3/PythonEnvironment.cpp +++ b/Plugin/src/SofaPython3/PythonEnvironment.cpp @@ -467,16 +467,7 @@ std::string PythonEnvironment::getStackAsString() std::string PythonEnvironment::getPythonCallingPointString() { - PyObject* pDict = PyModule_GetDict(PyImport_AddModule("SofaRuntime")); - PyObject* pFunc = PyDict_GetItemString(pDict, "getPythonCallingPointAsString"); - if (PyCallable_Check(pFunc)) - { - PyObject* res = PyObject_CallFunction(pFunc, nullptr); - std::string tmp=PyBytes_AsString(PyObject_Str(res)); - Py_DECREF(res) ; - return tmp; - } - return "Python Stack is empty."; + return py::cast(py::eval("Sofa.getPythonCallingPointAsString()")); } sofa::helper::logging::FileInfo::SPtr PythonEnvironment::getPythonCallingPointAsFileInfo() diff --git a/bindings/Sofa/package/__init__.py b/bindings/Sofa/package/__init__.py index 30bafb2d..305889e9 100644 --- a/bindings/Sofa/package/__init__.py +++ b/bindings/Sofa/package/__init__.py @@ -77,12 +77,10 @@ def formatStackForSofa(o): in filename3.py:103:functioname2() -> the line of code. """ - ss='Python Stack: \n' + ss='At: ' for entry in o: - ss+= ' in ' + str(entry[1]) + ':' + str(entry[2]) + ':'+ entry[3] + '() \n' - ss+= ' -> '+ entry[4][0] + ' \n' - return ss - + ss+= '\n '+ str(entry[1]) + '(' + str(entry[2]) + '): '+ entry[3] + return ss + "\n" def getStackForSofa(): """returns the current stack with a "informal" formatting. """ diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp index 5ea0cd51..8a546b15 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp +++ b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp @@ -21,6 +21,7 @@ /// Neede to have automatic conversion from pybind types to stl container. #include +#include #include #include @@ -45,6 +46,9 @@ using sofa::core::ObjectFactory; #include using sofapython3::PythonFactory; +#include +using sofapython3::PythonEnvironment; + #include #include #include @@ -58,18 +62,16 @@ using sofa::core::objectmodel::BaseObjectDescription; /// Makes an alias for the pybind11 namespace to increase readability. namespace py { using namespace pybind11; } - using sofa::simulation::Node; namespace sofapython3 { - bool checkParamUsage(BaseObjectDescription& desc) { bool hasFailure = false; std::stringstream tmp; tmp <<"Unknown Attribute(s): " << msgendl; - for( auto it : desc.getAttributeMap() ) + for( auto& it : desc.getAttributeMap() ) { if (!it.second.isAccessed()) { @@ -128,8 +130,6 @@ std::string getLinkPath(Node* node){ return ("@"+node->getPathName()).c_str(); } - - py_shared_ptr __init__noname() { auto dag_node = sofa::core::objectmodel::New("unnamed"); return std::move(dag_node); @@ -261,8 +261,10 @@ py::object addKwargs(Node* self, const py::object& callable, const py::kwargs& k /// a warning for old scenes. py::object createObject(Node* self, const std::string& type, const py::kwargs& kwargs) { - msg_deprecated(self) << "The Node.createObject method is deprecated since sofa 19.06." - "To remove this warning message, use 'addObject'."; + msg_deprecated(self) << "The Node.createObject method is deprecated since sofa 19.06." << msgendl + << "To remove this warning message, use 'addObject' instead of 'createObject'." << msgendl + << msgendl + << PythonEnvironment::getPythonCallingPointString() ; return addObjectKwargs(self, type,kwargs); } @@ -296,8 +298,10 @@ Node* addChild(Node* self, Node* child) /// deprecated, use addChild instead. Keeping for compatibility reasons py::object createChild(Node* self, const std::string& name, const py::kwargs& kwargs) { - msg_deprecated(self) << "The Node.createChild method is deprecated since sofa 19.06." - "To remove this warning message, use 'addChild'."; + msg_deprecated(self) << "The Node.createChild method is deprecated since sofa 19.06." << msgendl + << "To remove this warning message, use 'addChild' instead of 'createChild'." << msgendl + << msgendl + << PythonEnvironment::getPythonCallingPointString() ; return addChildKwargs(self, name, kwargs); }