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<DBF_FieldType>& 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);
+ }
+
+}
+
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();
HYDRODATA_EXPORT int ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName,
NCollection_Sequence<Handle_HYDROData_Entity>& 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<DBF_FieldType>& FTVect);
+ void DBF_CloseDBF();
+
private:
void ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle);
int TryOpenShapeFile(QString theFileName);
private:
std::vector<SHPObject*> mySHPObjects;
SHPHandle myHSHP;
+ DBFHandle myHDBF;
+
+ friend class test_HYDROData_ShapeFile;
};
#endif
test_HYDROData_OperationsFactory.h
test_HYDROData_PolylineXY.h
test_HYDROData_Profile.h
+ test_HYDROData_ShapeFile.h
test_HYDROData_StricklerTable.h
test_HYDROGUI_ListModel.h
test_HYDROData_OperationsFactory.cxx
test_HYDROData_PolylineXY.cxx
test_HYDROData_Profile.cxx
+ test_HYDROData_ShapeFile.cxx
test_HYDROData_StricklerTable.cxx
test_HYDROGUI_ListModel.cxx
--- /dev/null
+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
--- /dev/null
+// 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 <test_HYDROData_ShapeFile.h>
+#include <HYDROData_ShapeFile.h>
+#include <QStringList>
+#include <vector>
+
+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<HYDROData_ShapeFile::DBF_FieldType> 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();
+}
+
+
+
--- /dev/null
+// 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 <cppunit/extensions/HelperMacros.h>
+
+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" );
+