From dee7322c7412f9734670502e479f62a1bd076705 Mon Sep 17 00:00:00 2001 From: adv Date: Fri, 27 Dec 2013 09:33:32 +0000 Subject: [PATCH] Python wrapping for sequence of HYDRO data objects. --- CMake/UsePyQt4EXT.cmake | 96 ++++++++++------ src/HYDROPy/CMakeLists.txt | 1 + src/HYDROPy/HYDROData.sip | 1 + src/HYDROPy/HYDROData_Entity.sip | 6 + src/HYDROPy/HYDROData_SequenceOfObjects.sip | 119 ++++++++++++++++++++ 5 files changed, 186 insertions(+), 37 deletions(-) create mode 100644 src/HYDROPy/HYDROData_SequenceOfObjects.sip diff --git a/CMake/UsePyQt4EXT.cmake b/CMake/UsePyQt4EXT.cmake index 27bcce91..ce01b53a 100644 --- a/CMake/UsePyQt4EXT.cmake +++ b/CMake/UsePyQt4EXT.cmake @@ -43,44 +43,66 @@ #################################################################### MACRO(PYQT4_WRAP_SIP_EXT outfiles) FOREACH(_input ${ARGN}) - FILE(STRINGS ${_input} _sip_modules REGEX "%Module") - FILE(STRINGS ${_input} _sip_includes REGEX "%Include") - FILE(STRINGS ${_input} _sip_classes REGEX "^class ") + SET(_output) - - FOREACH(_sip_module ${_sip_modules}) - STRING(REGEX MATCH ".*%Module *\\( *name=.*\\).*" _mod_name "${_sip_module}") - IF (_mod_name) - STRING(REGEX REPLACE ".*%Module *\\( *name=(.*).*\\).*" "\\1" _mod_name ${_sip_module}) - ELSE() - STRING(REGEX REPLACE ".*%Module *(.*)" "\\1" _mod_name ${_sip_module}) - ENDIF() - SET(_mod_header "sipAPI${_mod_name}.h") - SET(_mod_source "sip${_mod_name}cmodule${PYQT_CXX_EXT}") - LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/${_mod_source}) - SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/${_mod_source}) - ENDFOREACH() - - FOREACH(_sip_include ${_sip_includes}) - STRING(REGEX REPLACE ".*%Include +(.*)\\.sip *" "\\1" _include_name ${_sip_include}) - SET(_include_source "sip${_mod_name}${_include_name}${PYQT_CXX_EXT}") - LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/${_include_source}) - SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/${_include_source}) - ENDFOREACH() - - FOREACH(_sip_class ${_sip_classes}) - STRING(REGEX MATCH ".*class +.* *:" _class_name "${_sip_class}") - IF (_class_name) - STRING(REGEX REPLACE ".*class +(.*) *:.*" "\\1" _class_name ${_sip_class}) - ELSE() - STRING(REGEX REPLACE ".*class *(.*)" "\\1" _class_name ${_sip_class}) - ENDIF() - STRING(STRIP ${_class_name} _class_name) - SET(_class_source "sip${_mod_name}${_class_name}${PYQT_CXX_EXT}") - LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/${_class_source}) - SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/${_class_source}) - ENDFOREACH() - + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPycmodule.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPycmodule.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_ArtificialObject.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_ArtificialObject.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Bathymetry.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Bathymetry.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_CalculationCase.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_CalculationCase.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Document.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Document.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Entity.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Entity.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_IAltitudeObject.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_IAltitudeObject.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Image.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Image.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_ImmersibleZone.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_ImmersibleZone.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_IPolyline.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_IPolyline.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_NaturalObject.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_NaturalObject.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Object.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Object.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Obstacle.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Obstacle.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_PolylineXY.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_PolylineXY.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_ProfileUZ.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_ProfileUZ.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Region.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Region.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_River.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_River.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Zone.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Zone.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyNCollection_Sequence0100Handle_HYDROData_Entity.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyNCollection_Sequence0100Handle_HYDROData_Entity.cc) + ADD_CUSTOM_COMMAND( OUTPUT ${_output} COMMAND ${SIP_EXECUTABLE} ${PYQT_SIPFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${_input} diff --git a/src/HYDROPy/CMakeLists.txt b/src/HYDROPy/CMakeLists.txt index d1f9d144..b30b6570 100644 --- a/src/HYDROPy/CMakeLists.txt +++ b/src/HYDROPy/CMakeLists.txt @@ -79,6 +79,7 @@ SET(_sip_files # HYDROData_Document.sip SET(_sip_files2 + HYDROData_SequenceOfObjects.sip HYDROData_Entity.sip HYDROData_IPolyline.sip HYDROData_IAltitudeObject.sip diff --git a/src/HYDROPy/HYDROData.sip b/src/HYDROPy/HYDROData.sip index 13a1c7be..530587c8 100644 --- a/src/HYDROPy/HYDROData.sip +++ b/src/HYDROPy/HYDROData.sip @@ -51,6 +51,7 @@ See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com %Import QtGuimod.sip +%Include HYDROData_SequenceOfObjects.sip %Include HYDROData_Entity.sip %Include HYDROData_IPolyline.sip %Include HYDROData_IAltitudeObject.sip diff --git a/src/HYDROPy/HYDROData_Entity.sip b/src/HYDROPy/HYDROData_Entity.sip index f0205a2f..d53bcbd5 100644 --- a/src/HYDROPy/HYDROData_Entity.sip +++ b/src/HYDROPy/HYDROData_Entity.sip @@ -144,6 +144,12 @@ public: void CopyTo( HYDROData_Entity theDestination ) const; */ + /** + * Returns the list of all reference objects of this object. + * Base implementation always return empty list. + */ + virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const; + protected: /** diff --git a/src/HYDROPy/HYDROData_SequenceOfObjects.sip b/src/HYDROPy/HYDROData_SequenceOfObjects.sip new file mode 100644 index 00000000..be9b94cc --- /dev/null +++ b/src/HYDROPy/HYDROData_SequenceOfObjects.sip @@ -0,0 +1,119 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +%ExportedHeaderCode +#include +%End + +%MappedType NCollection_Sequence +{ +%TypeHeaderCode +#include +%End + +%ConvertFromTypeCode + // Create the list. + PyObject *l; + + if ((l = PyList_New(sipCpp->Length())) == NULL) + return NULL; + + // Set the list elements. + for (int i = 0; i < sipCpp->Length(); ++i) + { + HYDROData_Entity* aPntr = createPointer(sipCpp->Value(i)); + + PyObject *tobj; + + if ((tobj = sipConvertFromNewType(aPntr, sipFindType( aPntr->DynamicType()->Name() ), sipTransferObj)) == NULL) + { + Py_DECREF(l); + { + Handle_HYDROData_Entity anEnt( aPntr ); + } + + return NULL; + } + + PyList_SET_ITEM(l, i, tobj); + } + + return l; +%End + +%ConvertToTypeCode + SIP_SSIZE_T len; + + // Check the type if that is all that is required. + if (sipIsErr == NULL) + { + if (!PySequence_Check(sipPy) || (len = PySequence_Size(sipPy)) < 0) + return 0; + + for (SIP_SSIZE_T i = 0; i < len; ++i) + { + PyObject *itm = PySequence_ITEM(sipPy, i); + bool ok = (itm && sipCanConvertToType(itm, sipType_HYDROData_Entity, SIP_NOT_NONE)); + + Py_XDECREF(itm); + + if (!ok) + return 0; + } + + return 1; + } + + NCollection_Sequence *ql = + new NCollection_Sequence; + len = PySequence_Size(sipPy); + + for (SIP_SSIZE_T i = 0; i < len; ++i) + { + PyObject *itm = PySequence_ITEM(sipPy, i); + int state; + HYDROData_Entity *t = + reinterpret_cast(sipConvertToType(itm, sipType_HYDROData_Entity, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); + + Py_DECREF(itm); + + if (*sipIsErr) + { + sipReleaseType(t, sipType_HYDROData_Entity, state); + + delete ql; + return 0; + } + + Handle_HYDROData_Entity anEnt( t ); + ql->Append( anEnt ); + + //sipReleaseType(t, sipType_HYDROData_Entity, state); + } + + *sipCppPtr = ql; + + return sipGetState(sipTransferObj); +%End +}; + +typedef NCollection_Sequence HYDROData_SequenceOfObjects; -- 2.39.2