From 29da58751140d09fa1083f58aec5f25e12dc2477 Mon Sep 17 00:00:00 2001 From: isn Date: Mon, 29 Jun 2015 12:11:39 +0300 Subject: [PATCH] Import/Export // API revision. p3 --- src/HYDROData/HYDROData_ShapeFile.cxx | 38 +++++++++++---------------- src/HYDROData/HYDROData_ShapeFile.h | 17 +++++++----- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/HYDROData/HYDROData_ShapeFile.cxx b/src/HYDROData/HYDROData_ShapeFile.cxx index 42b452b7..c65c2c2b 100644 --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@ -261,19 +261,21 @@ void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandl return; } -void HYDROData_ShapeFile::Parse1(SHPHandle theHandle) +void HYDROData_ShapeFile::Parse(SHPHandle theHandle, ShapeType theType) { int aShapeType; mySHPObjects.clear(); SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL ); - if (aShapeType == 5) + bool ToRead = (theType == ShapeType_Polyline && (aShapeType == 3 || aShapeType == 13 || aShapeType == 23)) || + (theType == ShapeType_Polygon && aShapeType == 5); + if (ToRead) { for (int i = 0; i < theHandle->nRecords; i++) mySHPObjects.push_back(SHPReadObject(theHandle, i)); } } -void HYDROData_ShapeFile::ProcessSHP(SHPObject* anObj, int i, TopoDS_Face& F) +void HYDROData_ShapeFile::ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F) { TopoDS_Wire W; TopoDS_Edge E; @@ -326,16 +328,16 @@ bool HYDROData_ShapeFile::ImportLandCovers(const QString theFileName, QStringLis { Free(); myHSHP = SHPOpen( theFileName.toAscii().data(), "rb" ); - Parse1(myHSHP); - for (int i = 0; i < mySHPObjects.size(); i++) + Parse(myHSHP, HYDROData_ShapeFile::ShapeType_Polygon); + for (size_t i = 0; i < mySHPObjects.size(); i++) thePolygonsList.append("polygon_" + QString::number(i + 1)); TopoDS_Face aF; if (myHSHP->nShapeType == 5) { - for (int i = 0; i < mySHPObjects.size(); i++) + for (size_t i = 0; i < mySHPObjects.size(); i++) { - ProcessSHP(mySHPObjects[i], i, aF); + ReadSHPPolygon(mySHPObjects[i], i, aF); theFaces.Append(aF); } return true; @@ -358,7 +360,7 @@ void HYDROData_ShapeFile::Free() } -void HYDROData_ShapeFile::ProcessSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, +void HYDROData_ShapeFile::ReadSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, int theInd, NCollection_Sequence& theEntities) { @@ -405,7 +407,7 @@ void HYDROData_ShapeFile::ProcessSHPPolyXY(Handle(HYDROData_Document) theDocumen } -void HYDROData_ShapeFile::ProcessSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, +void HYDROData_ShapeFile::ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, int theInd, NCollection_Sequence& theEntities) { Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) ); @@ -474,17 +476,7 @@ void HYDROData_ShapeFile::ProcessSHPPoly3D(Handle(HYDROData_Document) theDocumen } -void HYDROData_ShapeFile::Parse2(SHPHandle theHandle) -{ - int aShapeType; - mySHPObjects.clear(); - SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL ); - if (aShapeType == 3 || aShapeType == 13 || aShapeType == 23) - { - for (int i = 0; i < theHandle->nRecords; i++) - mySHPObjects.push_back(SHPReadObject(theHandle, i)); - } -} + bool HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, NCollection_Sequence& theEntities) { @@ -501,7 +493,7 @@ bool HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument QFileInfo aFileInfo(theFileName); QString aBaseFileName = aFileInfo.baseName(); - Parse2(aHSHP); + Parse(aHSHP, HYDROData_ShapeFile::ShapeType_Polyline); bool aStat = false; if (aHSHP->nShapeType == 3 || aHSHP->nShapeType == 23) { @@ -519,7 +511,7 @@ bool HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument for (size_t i = 0; i < mySHPObjects.size(); i++ ) { - ProcessSHPPolyXY(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities); + ReadSHPPolyXY(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities); } aStat = true; } @@ -539,7 +531,7 @@ bool HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument anInd++; } for (size_t i = 0; i < mySHPObjects.size(); i++ ) - ProcessSHPPoly3D(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities); + ReadSHPPoly3D(theDocument, mySHPObjects[i], aBaseFileName, anAllowedIndexes[i], theEntities); aStat = true; } else diff --git a/src/HYDROData/HYDROData_ShapeFile.h b/src/HYDROData/HYDROData_ShapeFile.h index 1dc0922b..c0c823c2 100644 --- a/src/HYDROData/HYDROData_ShapeFile.h +++ b/src/HYDROData/HYDROData_ShapeFile.h @@ -44,11 +44,16 @@ class Handle_HYDROData_Entity; class HYDROData_ShapeFile { +enum ShapeType +{ + ShapeType_Polyline, + ShapeType_Polygon +}; + public: HYDRODATA_EXPORT HYDROData_ShapeFile( ); virtual HYDRODATA_EXPORT ~HYDROData_ShapeFile(); -public: //Export operation HYDRODATA_EXPORT void Export(const QString& aFileName, NCollection_Sequence aPolyXYSeq, @@ -58,16 +63,16 @@ public: int WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly ); int WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly ); int WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC ); + //Import + void Parse(SHPHandle theHandle, ShapeType theType); //Import Landcover - void Parse1(SHPHandle theHandle); - void ProcessSHP(SHPObject* anObj, int i, TopoDS_Face& F); + void ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F); HYDRODATA_EXPORT bool ImportLandCovers(const QString theFileName, QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces); HYDRODATA_EXPORT void Free(); //Import Polyline - void Parse2( SHPHandle theHandle); - void ProcessSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, + void ReadSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, int theInd, NCollection_Sequence& theEntities); - void ProcessSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, + void ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, int theInd, NCollection_Sequence& theEntities); HYDRODATA_EXPORT bool ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, NCollection_Sequence& theEntities); -- 2.39.2