]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Import/Export // API revision. p3
authorisn <isn@opencascade.com>
Mon, 29 Jun 2015 09:11:39 +0000 (12:11 +0300)
committerisn <isn@opencascade.com>
Mon, 29 Jun 2015 09:11:39 +0000 (12:11 +0300)
src/HYDROData/HYDROData_ShapeFile.cxx
src/HYDROData/HYDROData_ShapeFile.h

index 42b452b7bd386c6b8e01c176148a10882e2485f7..c65c2c2b09140818d43d658cf3477d7d4392491d 100644 (file)
@@ -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<Handle_HYDROData_Entity>& 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<Handle_HYDROData_Entity>& 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<Handle_HYDROData_Entity>& 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  
index 1dc0922bd71975cb5b65d214fdac7a277b66f75a..c0c823c23d3c0d29c2a29311399e35e942d2b9ff 100644 (file)
@@ -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<Handle_HYDROData_PolylineXY> 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<Handle_HYDROData_Entity>& 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<Handle_HYDROData_Entity>& theEntities);
   HYDRODATA_EXPORT bool ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, 
                        NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);