From 1793911b9fdf321af86f9d7058cd760afcb3bb26 Mon Sep 17 00:00:00 2001 From: asl Date: Thu, 8 Sep 2016 11:23:36 +0300 Subject: [PATCH] correction for Python wrapping --- src/HYDROPy/CAS/vector.sip | 296 +++++++++++++++++++++++++++ src/HYDROPy/CMakeLists.txt | 5 + src/HYDROPy/HYDROData.sip | 1 + src/HYDROPy/HYDROData_Bathymetry.sip | 10 +- 4 files changed, 310 insertions(+), 2 deletions(-) create mode 100644 src/HYDROPy/CAS/vector.sip diff --git a/src/HYDROPy/CAS/vector.sip b/src/HYDROPy/CAS/vector.sip new file mode 100644 index 00000000..8ea02b9c --- /dev/null +++ b/src/HYDROPy/CAS/vector.sip @@ -0,0 +1,296 @@ +// Copyright (C) 2014-2015 EDF-R&D +// 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 + +// std::vector is implemented as a Python list. +template +%MappedType std::vector +{ +%TypeHeaderCode +#include +%End + +%ConvertFromTypeCode + // Create the list. + PyObject *l; + + if ( ( l = PyList_New( sipCpp->size() ) ) == NULL ) + return NULL; + + // Set the list elements. + for ( int i = 1, n = sipCpp->size(); i <= n; ++i ) + { + TYPE* t = new TYPE( (*sipCpp)[i] ); + + PyObject* pobj; + if ( ( pobj = sipConvertFromNewType( t, sipType_TYPE, sipTransferObj ) ) == NULL ) + { + Py_DECREF( l ); + delete t; + + return NULL; + } + + PyList_SET_ITEM( l, i - 1, pobj ); + } + + 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_TYPE, SIP_NOT_NONE)); + + Py_XDECREF(itm); + + if (!ok) + return 0; + } + + return 1; + } + + std::vector *aSeq = new std::vector; + len = PySequence_Size(sipPy); + aSeq->reserve( len ); + + for (SIP_SSIZE_T i = 0; i < len; ++i) + { + PyObject *itm = PySequence_ITEM(sipPy, i); + int state; + TYPE *t = reinterpret_cast(sipConvertToType(itm, sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); + + Py_DECREF(itm); + + if (*sipIsErr) + { + sipReleaseType(t, sipType_TYPE, state); + + delete aSeq; + return 0; + } + + aSeq->push_back(*t); + + sipReleaseType(t, sipType_TYPE, state); + } + + *sipCppPtr = aSeq; + + return sipGetState(sipTransferObj); +%End +}; + +// std::vector is implemented as a Python list of floats. +%MappedType std::vector +{ +%TypeHeaderCode +#include +%End + +%ConvertFromTypeCode + // Create the list. + PyObject *l; + + if ( ( l = PyList_New( sipCpp->size() ) ) == NULL ) + return NULL; + + // Set the list elements. + for ( int i = 1, n = sipCpp->size(); i <= n; ++i ) + { + PyObject *pobj; + if ( ( pobj = PyFloat_FromDouble( (*sipCpp)[i] ) ) == NULL ) + { + Py_DECREF(l); + + return NULL; + } + + PyList_SET_ITEM( l, i - 1, pobj ); + } + + return l; +%End + +%ConvertToTypeCode + // Check the type if that is all that is required. + if ( sipIsErr == NULL ) + return ( PySequence_Check( sipPy) && PySequence_Size( sipPy ) >= 0 ); + + std::vector *aSeq = new std::vector; + + SIP_SSIZE_T len = PySequence_Size(sipPy); + aSeq->reserve( len ); + for ( SIP_SSIZE_T i = 0; i < len; ++i ) + { + PyObject *itm = PySequence_ITEM( sipPy, i ); + if ( !itm ) + { + delete aSeq; + *sipIsErr = 1; + + return 0; + } + + aSeq->push_back( PyFloat_AsDouble( itm ) ); + + Py_DECREF( itm ); + } + + *sipCppPtr = aSeq; + + return sipGetState( sipTransferObj ); +%End +}; + +// std::vector is implemented as a Python list of integers. +%MappedType std::vector +{ +%TypeHeaderCode +#include +%End + +%ConvertFromTypeCode + // Create the list. + PyObject *l; + + if ( ( l = PyList_New( sipCpp->size() ) ) == NULL ) + return NULL; + + // Set the list elements. + for ( int i = 1, n = sipCpp->size(); i <= n; ++i ) + { + PyObject *pobj; + if ( ( pobj = SIPLong_FromLong( (*sipCpp)[i] ) ) == NULL ) + { + Py_DECREF(l); + + return NULL; + } + + PyList_SET_ITEM( l, i - 1, pobj ); + } + + return l; +%End + +%ConvertToTypeCode + // Check the type if that is all that is required. + if ( sipIsErr == NULL ) + return ( PySequence_Check( sipPy) && PySequence_Size( sipPy ) >= 0 ); + + std::vector *aSeq = new std::vector; + + SIP_SSIZE_T len = PySequence_Size(sipPy); + aSeq->reserve( len ); + for ( SIP_SSIZE_T i = 0; i < len; ++i ) + { + PyObject *itm = PySequence_ITEM( sipPy, i ); + if ( !itm ) + { + delete aSeq; + *sipIsErr = 1; + + return 0; + } + + aSeq->push_back( SIPLong_AsLong( itm ) ); + + Py_DECREF( itm ); + } + + *sipCppPtr = aSeq; + + return sipGetState( sipTransferObj ); +%End +}; + +// std::vector is implemented as a Python list of integers. +%MappedType std::vector +{ +%TypeHeaderCode +#include +%End + +%ConvertFromTypeCode + // Create the list. + PyObject *l; + + if ( ( l = PyList_New( sipCpp->size() ) ) == NULL ) + return NULL; + + // Set the list elements. + for ( int i = 1, n = sipCpp->size(); i <= n; ++i ) + { + PyObject *pobj; + if ( ( pobj = SIPLong_FromLong( (*sipCpp)[i] ) ) == NULL ) + { + Py_DECREF(l); + + return NULL; + } + + PyList_SET_ITEM( l, i - 1, pobj ); + } + + return l; +%End + +%ConvertToTypeCode + // Check the type if that is all that is required. + if ( sipIsErr == NULL ) + return ( PySequence_Check( sipPy) && PySequence_Size( sipPy ) >= 0 ); + + std::vector *aSeq = new std::vector; + + SIP_SSIZE_T len = PySequence_Size(sipPy); + aSeq->reserve( len ); + for ( SIP_SSIZE_T i = 0; i < len; ++i ) + { + PyObject *itm = PySequence_ITEM( sipPy, i ); + if ( !itm ) + { + delete aSeq; + *sipIsErr = 1; + + return 0; + } + + aSeq->push_back( SIPLong_AsLong( itm ) != 0 ); + + Py_DECREF( itm ); + } + + *sipCppPtr = aSeq; + + return sipGetState( sipTransferObj ); +%End +}; \ No newline at end of file diff --git a/src/HYDROPy/CMakeLists.txt b/src/HYDROPy/CMakeLists.txt index 326a4acb..51954d54 100644 --- a/src/HYDROPy/CMakeLists.txt +++ b/src/HYDROPy/CMakeLists.txt @@ -81,6 +81,11 @@ SET(_add_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyNCollection_Sequence2400.cc ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyNCollection_Sequence2600.cc ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyTCollection_AsciiString.cc + ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPystdvector0100HYDROData_BathymetryAltitudePoint.cc + ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPystdvector1800.cc + ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPystdvector2400.cc + ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPystdvector2600.cc + ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_BathymetryAltitudePoint.cc ) # --- sources --- diff --git a/src/HYDROPy/HYDROData.sip b/src/HYDROPy/HYDROData.sip index 0039c21a..9038f640 100644 --- a/src/HYDROPy/HYDROData.sip +++ b/src/HYDROPy/HYDROData.sip @@ -46,6 +46,7 @@ %Include CAS/gp_XY.sip %Include CAS/gp_XYZ.sip %Include CAS/NCollection_Sequence.sip +%Include CAS/vector.sip %Include CAS/TCollection_AsciiString.sip %Include HYDROData_AltitudeObject.sip diff --git a/src/HYDROPy/HYDROData_Bathymetry.sip b/src/HYDROPy/HYDROData_Bathymetry.sip index e2302918..9f316d7c 100644 --- a/src/HYDROPy/HYDROData_Bathymetry.sip +++ b/src/HYDROPy/HYDROData_Bathymetry.sip @@ -35,8 +35,14 @@ class HYDROData_Bathymetry : public HYDROData_IAltitudeObject } %End - typedef gp_XYZ AltitudePoint; - typedef NCollection_Sequence AltitudePoints; +public: + struct AltitudePoint + { + double X; + double Y; + double Z; + }; + typedef std::vector AltitudePoints; %TypeHeaderCode -- 2.39.2