diff --git a/CMakeLists.txt b/CMakeLists.txt index 3055beb6d..d678a7a52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,16 +107,22 @@ MARK_AS_ADVANCED(SALOME_BUILD_GUI SALOME_GEOM_USE_OPENCV SALOME_GEOM_USE_VTK) ## # Various -# FIND_PACKAGE(SalomePythonInterp REQUIRED) -# FIND_PACKAGE(SalomePythonLibs REQUIRED) +FIND_PACKAGE(SalomePythonInterp REQUIRED) +FIND_PACKAGE(SalomePythonLibs REQUIRED) + +IF (NOT DEFINED EMSCRIPTEN) + FIND_PACKAGE(SalomeOmniORBPy REQUIRED) + FIND_PACKAGE(SalomeSWIG REQUIRED) +ELSE() + LIST(TRANSFORM OMNIORB_LIBRARIES REPLACE "\.so$" "\.a") + FIND_PACKAGE(SalomePythonWasm REQUIRED) + SET(PYTHON_INCLUDE_DIRS ${PYTHONWASM_INCLUDE_DIR}) + SET(PYTHON_LIBRARIES ${PYTHONWASM_LIB}) +ENDIF() + FIND_PACKAGE(SalomePThread REQUIRED) -# FIND_PACKAGE(SalomeSWIG REQUIRED) FIND_PACKAGE(SalomeBoost REQUIRED) FIND_PACKAGE(SalomeOmniORB REQUIRED) -IF(DEFINED EMSCRIPTEN) - LIST(TRANSFORM OMNIORB_LIBRARIES REPLACE "\.so$" "\.a") -ENDIF() -# FIND_PACKAGE(SalomeOmniORBPy REQUIRED) FIND_PACKAGE(SalomeLibXml2 REQUIRED) FIND_PACKAGE(SalomeHDF5 REQUIRED COMPONENTS C) diff --git a/src/GEOMImpl/CMakeLists.txt b/src/GEOMImpl/CMakeLists.txt index f0ef9737b..ffe0bb80a 100644 --- a/src/GEOMImpl/CMakeLists.txt +++ b/src/GEOMImpl/CMakeLists.txt @@ -20,6 +20,7 @@ # --- options --- # additional include directories + INCLUDE_DIRECTORIES( ${OpenCASCADE_INCLUDE_DIR} ${PTHREAD_INCLUDE_DIR} diff --git a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx index dbc564b11..412982541 100644 --- a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx @@ -28,8 +28,8 @@ #include #endif -// #include -// #include +#include +#include #ifdef HAVE_FINITE #undef HAVE_FINITE @@ -78,108 +78,108 @@ namespace { - // typedef struct { - // PyObject_HEAD - // int softspace; - // std::string *out; - // } PyStdOut; + typedef struct { + PyObject_HEAD + int softspace; + std::string *out; + } PyStdOut; - // static void - // PyStdOut_dealloc(PyStdOut *self) - // { - // PyObject_Del(self); - // } + static void + PyStdOut_dealloc(PyStdOut *self) + { + PyObject_Del(self); + } - // static PyObject* - // PyStdOut_write(PyStdOut* self, PyObject* args) - // { - // char *c; - // if (!PyArg_ParseTuple(args, "s", &c)) - // return NULL; + static PyObject* + PyStdOut_write(PyStdOut* self, PyObject* args) + { + char *c; + if (!PyArg_ParseTuple(args, "s", &c)) + return NULL; - // *(self->out) = *(self->out) + c; + *(self->out) = *(self->out) + c; - // Py_INCREF(Py_None); - // return Py_None; - // } + Py_INCREF(Py_None); + return Py_None; + } - // static PyMethodDef PyStdOut_methods[] = { - // {"write", (PyCFunction)PyStdOut_write, METH_VARARGS, - // PyDoc_STR("write(string) -> None")}, - // {0, 0, 0, 0} /* sentinel */ - // }; + static PyMethodDef PyStdOut_methods[] = { + {"write", (PyCFunction)PyStdOut_write, METH_VARARGS, + PyDoc_STR("write(string) -> None")}, + {0, 0, 0, 0} /* sentinel */ + }; - // static PyMemberDef PyStdOut_memberlist[] = { - // {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0, - // (char*)"flag indicating that a space needs to be printed; used by print"}, - // {0, 0, 0, 0, 0} /* sentinel */ - // }; + static PyMemberDef PyStdOut_memberlist[] = { + {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0, + (char*)"flag indicating that a space needs to be printed; used by print"}, + {0, 0, 0, 0, 0} /* sentinel */ + }; - // static PyTypeObject PyStdOut_Type = { - // /* The ob_type field must be initialized in the module init function - // * to be portable to Windows without using C++. */ - // PyVarObject_HEAD_INIT(NULL, 0) - // /* 0, */ /*ob_size*/ - // "PyOut", /*tp_name*/ - // sizeof(PyStdOut), /*tp_basicsize*/ - // 0, /*tp_itemsize*/ - // /* methods */ - // (destructor)PyStdOut_dealloc, /*tp_dealloc*/ - // 0, /*tp_print*/ - // 0, /*tp_getattr*/ - // 0, /*tp_setattr*/ - // 0, /*tp_compare*/ - // 0, /*tp_repr*/ - // 0, /*tp_as_number*/ - // 0, /*tp_as_sequence*/ - // 0, /*tp_as_mapping*/ - // 0, /*tp_hash*/ - // 0, /*tp_call*/ - // 0, /*tp_str*/ - // PyObject_GenericGetAttr, /*tp_getattro*/ - // /* softspace is writable: we must supply tp_setattro */ - // PyObject_GenericSetAttr, /* tp_setattro */ - // 0, /*tp_as_buffer*/ - // Py_TPFLAGS_DEFAULT, /*tp_flags*/ - // 0, /*tp_doc*/ - // 0, /*tp_traverse*/ - // 0, /*tp_clear*/ - // 0, /*tp_richcompare*/ - // 0, /*tp_weaklistoffset*/ - // 0, /*tp_iter*/ - // 0, /*tp_iternext*/ - // PyStdOut_methods, /*tp_methods*/ - // PyStdOut_memberlist, /*tp_members*/ - // 0, /*tp_getset*/ - // 0, /*tp_base*/ - // 0, /*tp_dict*/ - // 0, /*tp_descr_get*/ - // 0, /*tp_descr_set*/ - // 0, /*tp_dictoffset*/ - // 0, /*tp_init*/ - // 0, /*tp_alloc*/ - // 0, /*tp_new*/ - // 0, /*tp_free*/ - // 0, /*tp_is_gc*/ - // 0, /*tp_bases*/ - // 0, /*tp_mro*/ - // 0, /*tp_cache*/ - // 0, /*tp_subclasses*/ - // 0, /*tp_weaklist*/ - // 0, /*tp_del*/ - // 0, /*tp_version_tag*/ - // 0, /*tp_finalize*/ - // }; + static PyTypeObject PyStdOut_Type = { + /* The ob_type field must be initialized in the module init function + * to be portable to Windows without using C++. */ + PyVarObject_HEAD_INIT(NULL, 0) + /* 0, */ /*ob_size*/ + "PyOut", /*tp_name*/ + sizeof(PyStdOut), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor)PyStdOut_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + PyObject_GenericGetAttr, /*tp_getattro*/ + /* softspace is writable: we must supply tp_setattro */ + PyObject_GenericSetAttr, /* tp_setattro */ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + PyStdOut_methods, /*tp_methods*/ + PyStdOut_memberlist, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + 0, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + 0, /*tp_finalize*/ + }; - // PyObject* newPyStdOut( std::string& out ) - // { - // PyStdOut* self = PyObject_New(PyStdOut, &PyStdOut_Type); - // if (self) { - // self->softspace = 0; - // self->out=&out; - // } - // return (PyObject*)self; - // } + PyObject* newPyStdOut( std::string& out ) + { + PyStdOut* self = PyObject_New(PyStdOut, &PyStdOut_Type); + if (self) { + self->softspace = 0; + self->out=&out; + } + return (PyObject*)self; + } } ////////////////////////END PYTHON/////////////////////////// @@ -978,83 +978,83 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric } /* Initialize the Python interpreter */ - // if (! Py_IsInitialized()) { - // SetErrorCode("Python interpreter is not initialized !!! "); - // return NULL; - // } + if (! Py_IsInitialized()) { + SetErrorCode("Python interpreter is not initialized !!! "); + return NULL; + } - // PyGILState_STATE gstate; - // gstate = PyGILState_Ensure(); + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); - // PyObject* main_mod = PyImport_AddModule("__main__"); - // PyObject* main_dict = PyModule_GetDict(main_mod); + PyObject* main_mod = PyImport_AddModule("__main__"); + PyObject* main_dict = PyModule_GetDict(main_mod); - // PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL); + PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL); - // if (obj == NULL) { - // SetErrorCode("Error during executing of python script !!!"); - // PyErr_Print(); - // PyGILState_Release(gstate); - // return NULL; - // } else { - // Py_DECREF(obj); - // } + if (obj == NULL) { + SetErrorCode("Error during executing of python script !!!"); + PyErr_Print(); + PyGILState_Release(gstate); + return NULL; + } else { + Py_DECREF(obj); + } - // PyObject * func = NULL; - // func = PyObject_GetAttrString(main_mod, "coordCalculator"); + PyObject * func = NULL; + func = PyObject_GetAttrString(main_mod, "coordCalculator"); - // if (func == NULL){ - // SetErrorCode("Can't get function from python module !!!"); - // PyGILState_Release(gstate); - // return NULL; - // } + if (func == NULL){ + SetErrorCode("Can't get function from python module !!!"); + PyGILState_Release(gstate); + return NULL; + } - // PyObject* coords; - // if (theNewMethod) - // coords = PyObject_CallFunction(func,(char*)"(d, d, i)", theParamMin, theParamMax, theParamNbStep ); - // else - // coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep ); + PyObject* coords; + if (theNewMethod) + coords = PyObject_CallFunction(func,(char*)"(d, d, i)", theParamMin, theParamMax, theParamNbStep ); + else + coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep ); - // if (coords == NULL){ - // fflush(stderr); - // std::string err_description=""; - // PyObject* new_stderr = newPyStdOut(err_description); - // PyObject* old_stderr = PySys_GetObject((char*)"stderr"); - // Py_INCREF(old_stderr); - // PySys_SetObject((char*)"stderr", new_stderr); - // PyErr_Print(); - // PySys_SetObject((char*)"stderr", old_stderr); - // Py_DECREF(new_stderr); - // MESSAGE("Can't evaluate coordCalculator()" << " error is " << err_description); - // SetErrorCode("Can't evaluate the expressions, please check them !!!"); - // PyGILState_Release(gstate); - // return NULL; - // } + if (coords == NULL){ + fflush(stderr); + std::string err_description=""; + PyObject* new_stderr = newPyStdOut(err_description); + PyObject* old_stderr = PySys_GetObject((char*)"stderr"); + Py_INCREF(old_stderr); + PySys_SetObject((char*)"stderr", new_stderr); + PyErr_Print(); + PySys_SetObject((char*)"stderr", old_stderr); + Py_DECREF(new_stderr); + MESSAGE("Can't evaluate coordCalculator()" << " error is " << err_description); + SetErrorCode("Can't evaluate the expressions, please check them !!!"); + PyGILState_Release(gstate); + return NULL; + } - // int lsize = PyList_Size( coords ); + int lsize = PyList_Size( coords ); - // if(lsize <= 0) { - // SetErrorCode("Empty list of the points, please check input parameters !!!"); - // return NULL; - // } + if(lsize <= 0) { + SetErrorCode("Empty list of the points, please check input parameters !!!"); + return NULL; + } - // Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, lsize * 3); + Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, lsize * 3); - // int k=1; - // for ( Py_ssize_t i = 0; i < lsize; ++i ) { - // PyObject* coord = PyList_GetItem( coords, i ); - // if (coord != NULL) { - // for ( Py_ssize_t j = 0; j < PyList_Size(coord); ++j) { - // PyObject* item = PyList_GetItem(coord, j); - // aCoordsArray->SetValue(k, PyFloat_AsDouble(item)); - // k++; - // } - // } - // } + int k=1; + for ( Py_ssize_t i = 0; i < lsize; ++i ) { + PyObject* coord = PyList_GetItem( coords, i ); + if (coord != NULL) { + for ( Py_ssize_t j = 0; j < PyList_Size(coord); ++j) { + PyObject* item = PyList_GetItem(coord, j); + aCoordsArray->SetValue(k, PyFloat_AsDouble(item)); + k++; + } + } + } - // Py_DECREF(coords); + Py_DECREF(coords); - // PyGILState_Release(gstate); + PyGILState_Release(gstate); Handle(GEOM_Object) aCurve; Handle(GEOM_Function) aFunction;