From: asl Date: Thu, 22 Oct 2015 09:29:22 +0000 (+0300) Subject: refs #651: wrapping land cover map by Python X-Git-Tag: v1.5~75^2~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0b8b69a9ad7c8c3340c4a828c7f96cb9455d7df9;p=modules%2Fhydro.git refs #651: wrapping land cover map by Python --- diff --git a/CMake/UsePyQt4EXT.cmake b/CMake/UsePyQt4EXT.cmake index c85230fe..bd1875f6 100644 --- a/CMake/UsePyQt4EXT.cmake +++ b/CMake/UsePyQt4EXT.cmake @@ -177,6 +177,9 @@ MACRO(PYQT4_WRAP_SIP_EXT outfiles) LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_StricklerTable.cc) SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_StricklerTable.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_LandCoverMap.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_LandCoverMap.cc) ADD_CUSTOM_COMMAND( OUTPUT ${_output} diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index d7703a87..5ba643a9 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -208,7 +208,7 @@ HYDROData_LandCoverMap::DBFStatus HYDROData_LandCoverMap::ImportDBF( const QStri const QString& theFieldName, const QStringList& theDBFValues, const QStringList& theStricklerTypes, - QMap theIndices ) + const QList& theIndices ) { if (theDBFValues.size() != theStricklerTypes.size()) return DBFStatus_DIFF_SIZE_ERROR; diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index ed60ce28..1bb887e4 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -21,7 +21,6 @@ #include #include -#include DEFINE_STANDARD_HANDLE( HYDROData_LandCoverMap, HYDROData_Entity ) @@ -78,34 +77,34 @@ public: DBFStatus_NO_DBFVALUES_CORRESPONDENCE_WARNING }; - HYDROData_LandCoverMap(); - ~HYDROData_LandCoverMap(); + HYDRODATA_EXPORT HYDROData_LandCoverMap(); + HYDRODATA_EXPORT virtual ~HYDROData_LandCoverMap(); - virtual const ObjectKind GetKind() const; + HYDRODATA_EXPORT virtual const ObjectKind GetKind() const; - DBFStatus ImportDBF( const QString& theDBFFileName, - const QString& theFieldName, - const QStringList& DBFValues, - const QStringList& StricklerTypes, - QMap theIndices ); + HYDRODATA_EXPORT DBFStatus ImportDBF( const QString& theDBFFileName, + const QString& theFieldName, + const QStringList& DBFValues, + const QStringList& StricklerTypes, + const QList& theIndices ); - void ExportDBF( const QString& theDBFFileName, - const QString& theFieldName, - const QStringList& theDBFValues, - const QStringList& theStricklerTypes) const; + HYDRODATA_EXPORT void ExportDBF( const QString& theDBFFileName, + const QString& theFieldName, + const QStringList& theDBFValues, + const QStringList& theStricklerTypes ) const; - bool ExportTelemac( const QString& theFileName, double theDeflection ) const; + HYDRODATA_EXPORT bool ExportTelemac( const QString& theFileName, double theDeflection ) const; - bool Add( const Handle( HYDROData_Object )&, const QString& theType ); - bool Add( const Handle( HYDROData_PolylineXY )&, const QString& theType ); + HYDRODATA_EXPORT bool Add( const Handle( HYDROData_Object )&, const QString& theType ); + HYDRODATA_EXPORT bool Add( const Handle( HYDROData_PolylineXY )&, const QString& theType ); - bool Remove( const TopoDS_Face& ); - bool Remove( const TopTools_ListOfShape& ); + HYDRODATA_EXPORT bool Remove( const TopoDS_Face& ); + HYDRODATA_EXPORT bool Remove( const TopTools_ListOfShape& ); - bool Split( const Handle( HYDROData_PolylineXY )& ); - bool Merge( const TopTools_ListOfShape&, const QString& theType ); + HYDRODATA_EXPORT bool Split( const Handle( HYDROData_PolylineXY )& ); + HYDRODATA_EXPORT bool Merge( const TopTools_ListOfShape&, const QString& theType ); - TopoDS_Face FindByPoint( const gp_Pnt2d&, QString& theType ) const; + HYDRODATA_EXPORT TopoDS_Face FindByPoint( const gp_Pnt2d&, QString& theType ) const; HYDRODATA_EXPORT TopoDS_Shape GetShape() const; diff --git a/src/HYDROPy/CMakeLists.txt b/src/HYDROPy/CMakeLists.txt index d91a5834..013a4a9e 100644 --- a/src/HYDROPy/CMakeLists.txt +++ b/src/HYDROPy/CMakeLists.txt @@ -92,6 +92,7 @@ SET(_sip_files2 HYDROData_Document.sip HYDROData_Application.sip HYDROData_IProfilesInterpolator.sip + HYDROData_LandCoverMap.sip ) # --- sources --- diff --git a/src/HYDROPy/HYDROData_LandCoverMap.sip b/src/HYDROPy/HYDROData_LandCoverMap.sip new file mode 100644 index 00000000..734565ea --- /dev/null +++ b/src/HYDROPy/HYDROData_LandCoverMap.sip @@ -0,0 +1,109 @@ +// 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, or (at your option) any later version. +// +// 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 + +class HYDROData_LandCoverMap : public HYDROData_Entity +{ +%TypeHeaderCode +#include +%End + +%ConvertToSubClassCode + switch ( sipCpp->GetKind() ) + { + case KIND_LAND_COVER_MAP: + sipClass = sipClass_HYDROData_LandCoverMap; + break; + + default: + // We don't recognise the type. + sipClass = NULL; + } +%End + +public: + enum DBFStatus + { + DBFStatus_OK, + DBFStatus_DIFF_SIZE_ERROR, + DBFStatus_OPEN_FILE_ERROR, + DBFStatus_NO_SUCH_FIELD_ERROR, + DBFStatus_NO_DBFVALUES_CORRESPONDENCE_WARNING + }; + + HYDROData_LandCoverMap(); + ~HYDROData_LandCoverMap(); + + DBFStatus ImportDBF( const QString& theDBFFileName, + const QString& theFieldName, + const QStringList& DBFValues, + const QStringList& StricklerTypes, + const QList& theIndices ); + + void ExportDBF( const QString& theDBFFileName, + const QString& theFieldName, + const QStringList& theDBFValues, + const QStringList& theStricklerTypes ) const; + + bool ExportTelemac( const QString& theFileName, double theDeflection ) const; + + bool Add( HYDROData_Object theObject, const QString& theType ) + [bool ( const Handle_HYDROData_Object&, const QString& )]; + %MethodCode + Handle(HYDROData_Object) aRef = + Handle(HYDROData_Object)::DownCast( createHandle( a0 ) ); + if ( !aRef.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipRes = sipSelfWasArg ? sipCpp->HYDROData_LandCoverMap::Add( aRef, *a1 ): + sipCpp->Add( aRef, *a1 ); + Py_END_ALLOW_THREADS + } + %End + + bool Add( HYDROData_PolylineXY thePolyline, const QString& theType ) + [bool ( const Handle_HYDROData_PolylineXY&, const QString& )]; + %MethodCode + Handle(HYDROData_PolylineXY) aRef = + Handle(HYDROData_PolylineXY)::DownCast( createHandle( a0 ) ); + if ( !aRef.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipRes = sipSelfWasArg ? sipCpp->HYDROData_LandCoverMap::Add( aRef, *a1 ): + sipCpp->Add( aRef, *a1 ); + Py_END_ALLOW_THREADS + } + %End + + bool Split( HYDROData_PolylineXY thePolyline ) + [bool ( const Handle_HYDROData_PolylineXY& )]; + %MethodCode + Handle(HYDROData_PolylineXY) aRef = + Handle(HYDROData_PolylineXY)::DownCast( createHandle( a0 ) ); + if ( !aRef.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipRes = sipSelfWasArg ? sipCpp->HYDROData_LandCoverMap::Split( aRef ): + sipCpp->Split( aRef ); + Py_END_ALLOW_THREADS + } + %End +}; diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx index e474ad9a..8f38a522 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx @@ -441,17 +441,13 @@ void test_HYDROData_LandCoverMap::test_import_dbf() CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) ); CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) ); - QMap Inds; - Inds.insert(1, 1); - Inds.insert(2, 2); - Inds.insert(3, 3); + QList Inds = QList() << 1 << 2 << 3; aMap->ImportDBF(aFileName, "TESTFIELD1", aDBFV, aST, Inds); HYDROData_LandCoverMap::Iterator anIt( aMap ); - CPPUNIT_ASSERT_EQUAL(true, "water" == anIt.StricklerType()); + CPPUNIT_ASSERT_EQUAL( QString( "forest" ), anIt.StricklerType() ); anIt.Next(); - CPPUNIT_ASSERT_EQUAL(true, "forest" == anIt.StricklerType()); - + CPPUNIT_ASSERT_EQUAL( QString( "road" ), anIt.StricklerType() ); } void test_HYDROData_LandCoverMap::test_land_cover_prs_by_types()