]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
sip for export Shapefile
authorPaul RASCLE <paul.rascle@openfields.fr>
Tue, 24 Nov 2020 21:57:13 +0000 (22:57 +0100)
committerYOANN AUDOUIN <B61570@dsp0919998.atlas.edf.fr>
Fri, 11 Dec 2020 14:53:30 +0000 (15:53 +0100)
src/HYDROData/HYDROData_PolylineXY.cxx
src/HYDROData/HYDROData_PolylineXY.h
src/HYDROPy/CMakeLists.txt
src/HYDROPy/HYDROData_PolylineXY.sip
src/HYDROPy/HYDROData_SequenceOfObjects.sip

index f52eed41496b5d8d06efb936506967cd66d03230..a62affa7f4a01be5544e3fb4af83f6e1d13bc138 100644 (file)
@@ -1835,3 +1835,13 @@ bool HYDROData_PolylineXY::ImportShapesFromFile(const QString& aFileName)
   return true;
 }
 
+
+void HYDROData_PolylineXY::ExportShapeXY(Handle(HYDROData_Document) theDocument,
+                                         const QString& aFileName,
+                                         const NCollection_Sequence<Handle(HYDROData_PolylineXY)>& aPolyXYSeq,
+                                         QStringList& aNonExpList)
+{
+    HYDROData_ShapeFile shp = HYDROData_ShapeFile();
+    NCollection_Sequence<Handle(HYDROData_Polyline3D)> emptySeq;
+    shp.Export(theDocument, aFileName, aPolyXYSeq, emptySeq, aNonExpList);
+}
index 3dc7e1886f5f4eb05499f8d33e368d607e1d0a5d..d55ce43efb86cb6549d8178dcc6f90a2b476b495 100644 (file)
 
 #include "HYDROData_IPolyline.h"
 #include <TopTools_HSequenceOfShape.hxx>
+#include <QString>
+#include <QStringList>
 
 class QPainterPath;
 class QTransform;
 class TopoDS_Wire;
 class gp_XYZ;
 class gp_Pnt;
+class HYDROData_Document;
 
 /**\class HYDROData_PolylineXY
  * \brief Class that stores/retrieves information about the
@@ -307,6 +310,11 @@ public:
 
   HYDRODATA_EXPORT static bool ImportShapesFromFile( const QString& theFileName );
 
+  HYDRODATA_EXPORT static void ExportShapeXY(Handle(HYDROData_Document) theDocument,
+                                             const QString& aFileName,
+                                             const NCollection_Sequence<Handle(HYDROData_PolylineXY)>& aPolyXYSeq,
+                                             QStringList& aNonExpList);
+
 protected:
 
   /**
index 6e26c713dd58b4a7b801810a42e1519ee8119c6a..bb0ec13e7f2866e5af1ab985b017d61cb6d50117 100644 (file)
@@ -9,6 +9,7 @@ INCLUDE_DIRECTORIES(
   ${PYTHON_INCLUDE_DIRS}
   ${CMAKE_CURRENT_SOURCE_DIR}
   ${PROJECT_SOURCE_DIR}/src/HYDROData
+  ${PROJECT_SOURCE_DIR}/src/shapelib
 )
 
 # additional preprocessor / compiler flags
@@ -72,6 +73,7 @@ SET(_add_SOURCES
   sipHYDROPyNCollection_Sequence0100HYDROData_IPolylineSectionType.cc
   sipHYDROPyNCollection_Sequence0100TCollection_AsciiString.cc
   sipHYDROPyNCollection_Sequence0600opencascadehandle0100HYDROData_Entity.cc
+  sipHYDROPyNCollection_Sequence0600opencascadehandle0100HYDROData_PolylineXY.cc
   sipHYDROPyNCollection_Sequence1800.cc
   sipHYDROPyNCollection_Sequence2400.cc
   sipHYDROPyNCollection_Sequence2600.cc
index 11c10909eb083065c1a5fa07a6c33369623daf45..d6a576ca532f6c142d6db2a93f2aa4bf1eb746a8 100644 (file)
@@ -24,6 +24,8 @@ class HYDROData_PolylineXY : public HYDROData_IPolyline
 {
 
 %TypeHeaderCode
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
 #include <HYDROData_PolylineXY.h>
 %End
 
@@ -137,6 +139,29 @@ public:
     Py_END_ALLOW_THREADS
   %End
 
+  static bool ExportShapeXY( HYDROData_Document theDocument,
+                             const QString& aFileName,
+                             const NCollection_Sequence<opencascade::handle<HYDROData_PolylineXY> >& aPolyXYSeq)
+                    [ void ( opencascade::handle<HYDROData_Document>,
+                             const QString&,
+                             const NCollection_Sequence<opencascade::handle<HYDROData_PolylineXY> >&,
+                             QStringList& ) ];
+  %MethodCode
+    Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
+    QString aFileName(*a1);
+    QStringList aNonExpList;
+    DEBTRACE(" --- 0");
+    if ( !aDoc.IsNull() )
+    {
+        DEBTRACE("before HYDROData_PolylineXY::ExportShapeXY");
+        Py_BEGIN_ALLOW_THREADS
+        HYDROData_PolylineXY::ExportShapeXY( aDoc, aFileName, *a2, aNonExpList );
+        Py_END_ALLOW_THREADS
+        DEBTRACE("after");
+    }
+    bool ret = (aNonExpList.size() == 0);
+    sipRes = ret;
+  %End
 
 protected:
 
index e183215039214a9ed12e82d71bf6f2b360bdc989..f55be33667b0630f8e39ef02dec15bae3fc8f549 100644 (file)
 };
 
 typedef NCollection_Sequence<opencascade::handle<HYDROData_Entity>> HYDROData_SequenceOfObjects;
+
+%MappedType NCollection_Sequence<opencascade::handle<HYDROData_PolylineXY>>
+{
+%TypeHeaderCode
+#include <NCollection_Sequence.hxx>
+%End
+
+%ConvertFromTypeCode
+    // Create the list.
+    PyObject *l;
+
+    if ((l = PyList_New(sipCpp->Length())) == NULL)
+        return NULL;
+
+    // Set the list elements.
+    for (int i = 1; i <= sipCpp->Length(); ++i)
+    {
+       HYDROData_PolylineXY* aPntr = (HYDROData_PolylineXY*)createPointer(sipCpp->Value(i));
+
+        PyObject *tobj;
+
+        if ((tobj = sipConvertFromNewType(aPntr, sipFindType( aPntr->DynamicType()->Name() ), sipTransferObj)) == NULL)
+        {
+            Py_DECREF(l);
+            {
+              Handle(HYDROData_PolylineXY) anEnt( aPntr );
+            }
+
+            return NULL;
+        }
+
+        PyList_SET_ITEM(l, i - 1, 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_PolylineXY, SIP_NOT_NONE));
+
+            Py_XDECREF(itm);
+
+            if (!ok)
+                return 0;
+        }
+
+        return 1;
+    }
+
+    NCollection_Sequence<Handle(HYDROData_PolylineXY)> *aSeq =
+      new NCollection_Sequence<Handle(HYDROData_PolylineXY)>;
+    len = PySequence_Size(sipPy);
+
+    for (SIP_SSIZE_T i = 0; i < len; ++i)
+    {
+        PyObject *itm = PySequence_ITEM(sipPy, i);
+        int state;
+        HYDROData_PolylineXY *t =
+          reinterpret_cast<HYDROData_PolylineXY *>(sipConvertToType(itm, sipType_HYDROData_PolylineXY, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
+
+        Py_DECREF(itm);
+
+        if (*sipIsErr)
+        {
+            sipReleaseType(t, sipType_HYDROData_PolylineXY, state);
+
+            delete aSeq;
+            return 0;
+        }
+
+        Handle(HYDROData_PolylineXY) anEnt( t );
+        aSeq->Append( anEnt );
+
+        //sipReleaseType(t, sipType_HYDROData_PolylineXY, state);
+    }
+
+    *sipCppPtr = aSeq;
+
+    return sipGetState(sipTransferObj);
+%End
+};
\ No newline at end of file