Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 1 addition & 10 deletions Plugin/src/SofaPython3/PythonEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>(py::eval("Sofa.getPythonCallingPointAsString()"));
}

sofa::helper::logging::FileInfo::SPtr PythonEnvironment::getPythonCallingPointAsFileInfo()
Expand Down
8 changes: 3 additions & 5 deletions bindings/Sofa/package/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. """
Expand Down
22 changes: 13 additions & 9 deletions bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

/// Neede to have automatic conversion from pybind types to stl container.
#include <pybind11/stl.h>
#include <pybind11/eval.h>

#include <sofa/core/objectmodel/BaseData.h>
#include <sofa/simulation/Simulation.h>
Expand All @@ -45,6 +46,9 @@ using sofa::core::ObjectFactory;
#include <SofaPython3/PythonFactory.h>
using sofapython3::PythonFactory;

#include <SofaPython3/PythonEnvironment.h>
using sofapython3::PythonEnvironment;

#include <SofaPython3/Sofa/Core/Binding_Node.h>
#include <SofaPython3/Sofa/Core/Binding_Node_doc.h>
#include <SofaPython3/Sofa/Core/Binding_NodeIterator.h>
Expand All @@ -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())
{
Expand Down Expand Up @@ -128,8 +130,6 @@ std::string getLinkPath(Node* node){
return ("@"+node->getPathName()).c_str();
}



py_shared_ptr<Node> __init__noname() {
auto dag_node = sofa::core::objectmodel::New<sofa::simulation::graph::DAGNode>("unnamed");
return std::move(dag_node);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down