From c4ede86f27ed0d43afaf6d532c294ca7a46108c4 Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Tue, 24 Nov 2020 22:57:13 +0100 Subject: [PATCH] sip for export Shapefile --- src/HYDROData/HYDROData_PolylineXY.cxx | 10 +++ src/HYDROData/HYDROData_PolylineXY.h | 8 ++ src/HYDROPy/CMakeLists.txt | 2 + src/HYDROPy/HYDROData_PolylineXY.sip | 25 ++++++ src/HYDROPy/HYDROData_SequenceOfObjects.sip | 92 +++++++++++++++++++++ 5 files changed, 137 insertions(+) diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index f52eed41..a62affa7 100644 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -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& aPolyXYSeq, + QStringList& aNonExpList) +{ + HYDROData_ShapeFile shp = HYDROData_ShapeFile(); + NCollection_Sequence emptySeq; + shp.Export(theDocument, aFileName, aPolyXYSeq, emptySeq, aNonExpList); +} diff --git a/src/HYDROData/HYDROData_PolylineXY.h b/src/HYDROData/HYDROData_PolylineXY.h index 3dc7e188..d55ce43e 100644 --- a/src/HYDROData/HYDROData_PolylineXY.h +++ b/src/HYDROData/HYDROData_PolylineXY.h @@ -21,12 +21,15 @@ #include "HYDROData_IPolyline.h" #include +#include +#include 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& aPolyXYSeq, + QStringList& aNonExpList); + protected: /** diff --git a/src/HYDROPy/CMakeLists.txt b/src/HYDROPy/CMakeLists.txt index 6e26c713..bb0ec13e 100644 --- a/src/HYDROPy/CMakeLists.txt +++ b/src/HYDROPy/CMakeLists.txt @@ -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 diff --git a/src/HYDROPy/HYDROData_PolylineXY.sip b/src/HYDROPy/HYDROData_PolylineXY.sip index 11c10909..d6a576ca 100644 --- a/src/HYDROPy/HYDROData_PolylineXY.sip +++ b/src/HYDROPy/HYDROData_PolylineXY.sip @@ -24,6 +24,8 @@ class HYDROData_PolylineXY : public HYDROData_IPolyline { %TypeHeaderCode +#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" #include %End @@ -137,6 +139,29 @@ public: Py_END_ALLOW_THREADS %End + static bool ExportShapeXY( HYDROData_Document theDocument, + const QString& aFileName, + const NCollection_Sequence >& aPolyXYSeq) + [ void ( opencascade::handle, + const QString&, + const NCollection_Sequence >&, + 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: diff --git a/src/HYDROPy/HYDROData_SequenceOfObjects.sip b/src/HYDROPy/HYDROData_SequenceOfObjects.sip index e1832150..f55be336 100644 --- a/src/HYDROPy/HYDROData_SequenceOfObjects.sip +++ b/src/HYDROPy/HYDROData_SequenceOfObjects.sip @@ -113,3 +113,95 @@ }; typedef NCollection_Sequence> HYDROData_SequenceOfObjects; + +%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 = 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 *aSeq = + 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_PolylineXY *t = + reinterpret_cast(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 -- 2.39.2