14 lines
1.9 KiB
C++
14 lines
1.9 KiB
C++
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
#include <App/Application.h>
|
|
#include <Base/Exception.h>
|
|
#include <Base/Type.h>
|
|
#include <Python.h>
|
|
#include <emscripten/emscripten.h>
|
|
#include <string>
|
|
extern "C" PyObject* PyInit_Surface(); extern "C" PyObject* PyInit_Part(); extern "C" PyObject* PyInit_Materials();
|
|
namespace { std::string error,names; int count=0,released=0; void addModule(const char* n,PyObject*(*f)()){auto* d=PyImport_GetModuleDict();if(PyDict_GetItemString(d,n))return;PyObject* m=f();if(!m)throw Base::RuntimeError(std::string("PyInit_")+n+" failed");PyDict_SetItemString(d,n,m);Py_DECREF(m);} }
|
|
extern "C" {
|
|
EMSCRIPTEN_KEEPALIVE int fc_web_surface_python_probe(){error.clear();names.clear();count=0;released=0;try{App::Application::initWebCore();addModule("Materials",&PyInit_Materials);addModule("Part",&PyInit_Part);addModule("Surface",&PyInit_Surface);PyObject* module=PyImport_ImportModule("Surface");if(!module)throw Base::RuntimeError("Surface Python module unavailable");Py_DECREF(module);const char* types[]={"Surface::Filling","Surface::Sewing","Surface::Cut","Surface::GeomFillSurface","Surface::Extend","Surface::Sections","Surface::FeatureBlendCurve"};for(const char* type:types)if(!Base::Type::fromName(type).isBad()){++count;if(!names.empty())names+=",";names+=type;}released=App::GetApplication().getDocuments().empty()?1:0;if(count!=7||released!=1){error="Surface Python binding/type contract mismatch";return 0;}return 1;}catch(const Base::Exception&e){error=e.what();}catch(const std::exception&e){error=e.what();}catch(...){error="unknown Surface Python API failure";}return 0;}
|
|
EMSCRIPTEN_KEEPALIVE const char* fc_web_surface_python_error(){return error.c_str();} EMSCRIPTEN_KEEPALIVE const char* fc_web_surface_python_names(){return names.c_str();} EMSCRIPTEN_KEEPALIVE int fc_web_surface_python_count(){return count;} EMSCRIPTEN_KEEPALIVE int fc_web_surface_python_resources_released(){return released;}
|
|
}
|