]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
correction for Python wrapping
authorasl <asl@opencascade.com>
Thu, 8 Sep 2016 08:23:36 +0000 (11:23 +0300)
committerasl <asl@opencascade.com>
Thu, 8 Sep 2016 08:23:36 +0000 (11:23 +0300)
src/HYDROPy/CAS/vector.sip [new file with mode: 0644]
src/HYDROPy/CMakeLists.txt
src/HYDROPy/HYDROData.sip
src/HYDROPy/HYDROData_Bathymetry.sip

diff --git a/src/HYDROPy/CAS/vector.sip b/src/HYDROPy/CAS/vector.sip
new file mode 100644 (file)
index 0000000..8ea02b9
--- /dev/null
@@ -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 <vector>
+%End
+
+// std::vector<TYPE> is implemented as a Python list.
+template<TYPE>
+%MappedType std::vector<TYPE>
+{
+%TypeHeaderCode
+#include <vector>
+%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<TYPE> *aSeq = new std::vector<TYPE>;
+    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<TYPE *>(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<double> is implemented as a Python list of floats.
+%MappedType std::vector<double>
+{
+%TypeHeaderCode
+#include <vector>
+%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<double> *aSeq = new std::vector<double>;
+
+    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<int> is implemented as a Python list of integers.
+%MappedType std::vector<int>
+{
+%TypeHeaderCode
+#include <vector>
+%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<int> *aSeq = new std::vector<int>;
+
+    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<bool> is implemented as a Python list of integers.
+%MappedType std::vector<bool>
+{
+%TypeHeaderCode
+#include <vector>
+%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<bool> *aSeq = new std::vector<bool>;
+
+    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
index 326a4acbfbf3d2784b36fccb8d336c3a3a7d2751..51954d5496b1705e98c7a25e70e78fcbf7493ddf 100644 (file)
@@ -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 ---
index 0039c21afbaa0b56892a05b258d174e6df0c5afb..9038f64095acb454bc00ee73d2708b1d601435f9 100644 (file)
@@ -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
index e23029181dddbc9b9476af8227dab068511e0733..9f316d7c4bb71fca3b90125e619bc4eaf31e17d3 100644 (file)
@@ -35,8 +35,14 @@ class HYDROData_Bathymetry : public HYDROData_IAltitudeObject
     }
 %End
 
-  typedef gp_XYZ                       AltitudePoint;
-  typedef NCollection_Sequence<gp_XYZ> AltitudePoints;
+public:
+  struct AltitudePoint
+  {
+    double X;
+    double Y;
+    double Z;
+  };
+  typedef std::vector<HYDROData_Bathymetry::AltitudePoint> AltitudePoints;
 
 
 %TypeHeaderCode