From: isn Date: Thu, 15 Oct 2015 09:09:56 +0000 (+0300) Subject: initial ver. X-Git-Tag: v1.5~89^2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6157337f0cd2502aa22545265ebbc797d631c887;p=modules%2Fhydro.git initial ver. --- diff --git a/src/HYDROData/HYDROData_ShapeFile.cxx b/src/HYDROData/HYDROData_ShapeFile.cxx index 16f72c78..8cf702f0 100644 --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@ -634,4 +634,85 @@ int HYDROData_ShapeFile::TryOpenShapeFile(QString theFileName) fclose (pFileSHP); fclose (pFileSHX); return 0; -} \ No newline at end of file +} + + +bool HYDROData_ShapeFile::CheckDBFFileExisting(const QString& theSHPFilePath, QString& thePathToDBFFile) +{ + QString aSHPfile = theSHPFilePath.simplified(); + QString aDBFfile = theSHPFilePath.simplified().replace( ".shp", ".dbf", Qt::CaseInsensitive); + FILE* pFileDBF = NULL; + pFileDBF = fopen (aDBFfile.toAscii().data(), "r"); + + if (pFileDBF == NULL) + { + return false; + } + + fclose (pFileDBF); + thePathToDBFFile = aDBFfile; + return true; +} + + +bool HYDROData_ShapeFile::DBF_OpenDBF(const QString& thePathToDBFFile) +{ + myHDBF = DBFOpen( thePathToDBFFile.toAscii().data(), "r" ); + if(myHDBF != NULL) + return true; + else + return false; +} + +int HYDROData_ShapeFile::DBF_GetNbFields() +{ + if(myHDBF == NULL) + return 0; + return DBFGetFieldCount(myHDBF); +} + +void HYDROData_ShapeFile::DBF_CloseDBF() +{ + if(myHDBF != NULL) + DBFClose( myHDBF ); +} + +QStringList HYDROData_ShapeFile::DBF_GetFieldList() +{ + QStringList FieldList; + int nWidth, nDecimals; + char chField[12]; + + for( int i = 0; i < DBFGetFieldCount(myHDBF); i++ ) + { + DBFFieldType eType; + eType = DBFGetFieldInfo( myHDBF, i, chField, &nWidth, &nDecimals ); + FieldList.append(QString(chField)); + } + + return FieldList; +} + +void HYDROData_ShapeFile::DBF_GetFieldTypeList(std::vector& FTVect) +{ + int nWidth, nDecimals; + char chField[12]; + DBF_FieldType FT; + for( int i = 0; i < DBFGetFieldCount(myHDBF); i++ ) + { + DBFFieldType eType; + eType = DBFGetFieldInfo( myHDBF, i, chField, &nWidth, &nDecimals ); + if( eType == FTString ) + FT = DBF_FieldType_String; + else if( eType == FTInteger ) + FT = DBF_FieldType_Integer; + else if( eType == FTDouble ) + FT = DBF_FieldType_Double; + else if( eType == FTInvalid ) + FT = DBF_FieldType_Invalid; + + FTVect.push_back(FT); + } + +} + diff --git a/src/HYDROData/HYDROData_ShapeFile.h b/src/HYDROData/HYDROData_ShapeFile.h index e23c9d6e..0f1cd3d2 100644 --- a/src/HYDROData/HYDROData_ShapeFile.h +++ b/src/HYDROData/HYDROData_ShapeFile.h @@ -50,6 +50,14 @@ enum ShapeType ShapeType_Polygon }; +enum DBF_FieldType +{ + DBF_FieldType_String, + DBF_FieldType_Integer, + DBF_FieldType_Double, + DBF_FieldType_Invalid +}; + public: HYDRODATA_EXPORT HYDROData_ShapeFile( ); virtual HYDRODATA_EXPORT ~HYDROData_ShapeFile(); @@ -77,12 +85,24 @@ public: HYDRODATA_EXPORT int ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, NCollection_Sequence& theEntities, int& theShapeTypeOfFile); HYDRODATA_EXPORT QString GetShapeTypeName(int theType); + + //DBF I/O Methods + bool CheckDBFFileExisting(const QString& theSHPFilePath, QString& thePathToDBFFile); + bool DBF_OpenDBF(const QString& thePathToDBFFile); + int DBF_GetNbFields(); + QStringList DBF_GetFieldList(); + void DBF_GetFieldTypeList(std::vector& FTVect); + void DBF_CloseDBF(); + private: void ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle); int TryOpenShapeFile(QString theFileName); private: std::vector mySHPObjects; SHPHandle myHSHP; + DBFHandle myHDBF; + + friend class test_HYDROData_ShapeFile; }; #endif diff --git a/src/HYDRO_tests/CMakeLists.txt b/src/HYDRO_tests/CMakeLists.txt index 9437e762..8ed144a6 100644 --- a/src/HYDRO_tests/CMakeLists.txt +++ b/src/HYDRO_tests/CMakeLists.txt @@ -11,6 +11,7 @@ set(PROJECT_HEADERS test_HYDROData_OperationsFactory.h test_HYDROData_PolylineXY.h test_HYDROData_Profile.h + test_HYDROData_ShapeFile.h test_HYDROData_StricklerTable.h test_HYDROGUI_ListModel.h @@ -28,6 +29,7 @@ set(PROJECT_SOURCES test_HYDROData_OperationsFactory.cxx test_HYDROData_PolylineXY.cxx test_HYDROData_Profile.cxx + test_HYDROData_ShapeFile.cxx test_HYDROData_StricklerTable.cxx test_HYDROGUI_ListModel.cxx diff --git a/src/HYDRO_tests/reference_data/cyprus_natural.dbf b/src/HYDRO_tests/reference_data/cyprus_natural.dbf new file mode 100644 index 00000000..ba0bfd76 Binary files /dev/null and b/src/HYDRO_tests/reference_data/cyprus_natural.dbf differ diff --git a/src/HYDRO_tests/reference_data/cyprus_natural.prj b/src/HYDRO_tests/reference_data/cyprus_natural.prj new file mode 100644 index 00000000..379ef7c8 --- /dev/null +++ b/src/HYDRO_tests/reference_data/cyprus_natural.prj @@ -0,0 +1 @@ +GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]] \ No newline at end of file diff --git a/src/HYDRO_tests/reference_data/cyprus_natural.shp b/src/HYDRO_tests/reference_data/cyprus_natural.shp new file mode 100644 index 00000000..05f9ebc0 Binary files /dev/null and b/src/HYDRO_tests/reference_data/cyprus_natural.shp differ diff --git a/src/HYDRO_tests/reference_data/cyprus_natural.shx b/src/HYDRO_tests/reference_data/cyprus_natural.shx new file mode 100644 index 00000000..b8fbc3aa Binary files /dev/null and b/src/HYDRO_tests/reference_data/cyprus_natural.shx differ diff --git a/src/HYDRO_tests/test_HYDROData_ShapeFile.cxx b/src/HYDRO_tests/test_HYDROData_ShapeFile.cxx new file mode 100644 index 00000000..0edbb457 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_ShapeFile.cxx @@ -0,0 +1,71 @@ +// 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 +// + +#include +#include +#include +#include + +const QString REF_PATH = qgetenv( "HYDRO_REFERENCE_DATA" ); + +void test_HYDROData_ShapeFile::test_openDbf() +{ + QString aDBFPath = REF_PATH + "/cyprus_natural.dbf"; + HYDROData_ShapeFile aSHPFile; + bool Stat = aSHPFile.DBF_OpenDBF(aDBFPath); + CPPUNIT_ASSERT_EQUAL( true, Stat ); + aSHPFile.DBF_CloseDBF(); +} + +void test_HYDROData_ShapeFile::test_NbFieldsDbf() +{ + QString aDBFPath = REF_PATH + "/cyprus_natural.dbf"; + HYDROData_ShapeFile aSHPFile; + aSHPFile.DBF_OpenDBF(aDBFPath); + int NbF = aSHPFile.DBF_GetNbFields(); + CPPUNIT_ASSERT_EQUAL( 2, NbF ); + aSHPFile.DBF_CloseDBF(); +} + +void test_HYDROData_ShapeFile::test_FieldListDbf() +{ + QString aDBFPath = REF_PATH + "/cyprus_natural.dbf"; + HYDROData_ShapeFile aSHPFile; + aSHPFile.DBF_OpenDBF(aDBFPath); + + QStringList FL = aSHPFile.DBF_GetFieldList(); + CPPUNIT_ASSERT_EQUAL(true, "NAME" == FL[0]); + CPPUNIT_ASSERT_EQUAL(true, "TYPE" == FL[1]); + aSHPFile.DBF_CloseDBF(); +} + +void test_HYDROData_ShapeFile::test_FieldTypeListDbf() +{ + QString aDBFPath = REF_PATH + "/cyprus_natural.dbf"; + HYDROData_ShapeFile aSHPFile; + aSHPFile.DBF_OpenDBF(aDBFPath); + + std::vector FTVect; + aSHPFile.DBF_GetFieldTypeList(FTVect); + CPPUNIT_ASSERT_EQUAL(HYDROData_ShapeFile::DBF_FieldType_String, FTVect[0]); + CPPUNIT_ASSERT_EQUAL(HYDROData_ShapeFile::DBF_FieldType_String, FTVect[1]); + aSHPFile.DBF_CloseDBF(); +} + + + diff --git a/src/HYDRO_tests/test_HYDROData_ShapeFile.h b/src/HYDRO_tests/test_HYDROData_ShapeFile.h new file mode 100644 index 00000000..6c3739a5 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_ShapeFile.h @@ -0,0 +1,39 @@ +// 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 +// +#include + +class test_HYDROData_ShapeFile : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( test_HYDROData_ShapeFile ); + CPPUNIT_TEST( test_openDbf ); + CPPUNIT_TEST( test_NbFieldsDbf ); + CPPUNIT_TEST( test_FieldListDbf ); + CPPUNIT_TEST( test_FieldTypeListDbf ); + + CPPUNIT_TEST_SUITE_END(); + +public: + void test_openDbf(); + void test_NbFieldsDbf(); + void test_FieldListDbf(); + void test_FieldTypeListDbf(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_ShapeFile ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( test_HYDROData_ShapeFile, "HYDROData_ShapeFile" ); +