From 9514b6cb2419618e5c66b73335a05b195067a266 Mon Sep 17 00:00:00 2001 From: GAUGRY Thierry Date: Tue, 12 Mar 2019 15:16:01 +0100 Subject: [PATCH 1/2] Add Sofa.hasViewer function --- .../plugins/SofaPython/Binding_SofaModule.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/applications/plugins/SofaPython/Binding_SofaModule.cpp b/applications/plugins/SofaPython/Binding_SofaModule.cpp index dff0bf00b60..43bb552173b 100644 --- a/applications/plugins/SofaPython/Binding_SofaModule.cpp +++ b/applications/plugins/SofaPython/Binding_SofaModule.cpp @@ -236,6 +236,21 @@ static PyObject * Sofa_setViewerBackgroundColor(PyObject * /*self*/, PyObject * return Py_BuildValue("i",0); } +/// Check if a viewer is available +static PyObject * Sofa_hasViewer(PyObject* self, PyObject* args) +{ + SOFA_UNUSED(self); + SOFA_UNUSED(args); + BaseGUI *gui = GUIManager::getGUI(); + if (!gui) + { + SP_MESSAGE_ERROR( "hasViewer: no GUI!" ) + return Py_BuildValue("i",-1); + } + return Py_BuildValue("i",!!gui->getViewer()); +} + + /// set the viewer camera static PyObject * Sofa_setViewerCamera(PyObject * /*self*/, PyObject * args) { @@ -904,6 +919,7 @@ SP_MODULE_METHOD(Sofa,sendGUIMessage) SP_MODULE_METHOD(Sofa,saveScreenshot) SP_MODULE_METHOD(Sofa,setViewerResolution) SP_MODULE_METHOD(Sofa,setViewerBackgroundColor) +SP_MODULE_METHOD(Sofa,hasViewer) SP_MODULE_METHOD(Sofa,setViewerCamera) SP_MODULE_METHOD(Sofa,getViewerCamera) SP_MODULE_METHOD(Sofa,generateRigid) From dbc7331bd015544235378593912e815e62a80c92 Mon Sep 17 00:00:00 2001 From: GAUGRY Thierry Date: Wed, 13 Mar 2019 10:05:24 +0100 Subject: [PATCH 2/2] Cleaner condition for hasViewer --- applications/plugins/SofaPython/Binding_SofaModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/plugins/SofaPython/Binding_SofaModule.cpp b/applications/plugins/SofaPython/Binding_SofaModule.cpp index 43bb552173b..60a7b95af70 100644 --- a/applications/plugins/SofaPython/Binding_SofaModule.cpp +++ b/applications/plugins/SofaPython/Binding_SofaModule.cpp @@ -247,7 +247,7 @@ static PyObject * Sofa_hasViewer(PyObject* self, PyObject* args) SP_MESSAGE_ERROR( "hasViewer: no GUI!" ) return Py_BuildValue("i",-1); } - return Py_BuildValue("i",!!gui->getViewer()); + return Py_BuildValue("i", gui->getViewer() != nullptr); }