Salome HOME
refs #651: wrapping land cover map by Python
authorasl <asl@opencascade.com>
Thu, 22 Oct 2015 09:29:22 +0000 (12:29 +0300)
committerasl <asl@opencascade.com>
Thu, 22 Oct 2015 09:29:22 +0000 (12:29 +0300)
CMake/UsePyQt4EXT.cmake
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDROData/HYDROData_LandCoverMap.h
src/HYDROPy/CMakeLists.txt
src/HYDROPy/HYDROData_LandCoverMap.sip [new file with mode: 0644]
src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx

index c85230fe4557c1e72b63f11097b22d67c4d3cb6b..bd1875f6aa869e3977df2fc18838d15a1f02c767 100644 (file)
@@ -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}
index d7703a87e1d0d14f75237ce07d5a4cf82bdbe87f..5ba643a95dc305feff80b17f73d24e00db665a8a 100644 (file)
@@ -208,7 +208,7 @@ HYDROData_LandCoverMap::DBFStatus HYDROData_LandCoverMap::ImportDBF( const QStri
                                                                      const QString& theFieldName, 
                                                                      const QStringList& theDBFValues,
                                                                      const QStringList& theStricklerTypes,
-                                                                     QMap<int, int> theIndices )
+                                                                     const QList<int>& theIndices )
 {
   if (theDBFValues.size() != theStricklerTypes.size())
     return DBFStatus_DIFF_SIZE_ERROR;
index ed60ce28d10ce732cc1a62a3f4df0cc625b94d86..1bb887e4bb1419248c28ab3b935045b96d79c97a 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <HYDROData_Entity.h>
 #include <TDataStd_ExtStringArray.hxx>
-#include <QMap>
 
 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<int, int> theIndices );
+  HYDRODATA_EXPORT DBFStatus ImportDBF( const QString& theDBFFileName, 
+                                        const QString& theFieldName, 
+                                        const QStringList& DBFValues,
+                                        const QStringList& StricklerTypes,
+                                        const QList<int>& 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;
 
index d91a58346f9a9aa5efe9b2e18da95f547db65a91..013a4a9e06a4c0dfc4b87bef82c36ae6a0ffa083 100644 (file)
@@ -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 (file)
index 0000000..734565e
--- /dev/null
@@ -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 <HYDROData_LandCoverMap.h>
+%End
+
+class HYDROData_LandCoverMap : public HYDROData_Entity
+{
+%TypeHeaderCode
+#include <HYDROData_LandCoverMap.h>
+%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<int>& 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
+};
index e474ad9ab0f1136c600c77a8c3f180a1626ccfff..8f38a522f4d88a6c846b8e3102fe6408dde1f022 100644 (file)
@@ -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<int, int> Inds;
-  Inds.insert(1, 1);
-  Inds.insert(2, 2);
-  Inds.insert(3, 3);
+  QList<int> Inds = QList<int>() << 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()