Salome HOME
Merge branch 'BR_LAND_COVER_MAP' of ssh://git.salome-platform.org/modules/hydro into...
[modules/hydro.git] / src / HYDROData / HYDROData_ShapeFile.cxx
index 629de51bf30d10a74d5862d00f1cf350bd0a7421..987b1f3d2c42fa3a9dc99ae76d6e6ff3a699fbd8 100644 (file)
@@ -101,8 +101,8 @@ void HYDROData_ShapeFile::Export(const QString& aFileName,
   if ( !aLCM.IsNull() && !aLCM->IsEmpty())
   {
     hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_POLYGON );
-    HYDROData_LandCoverMap::Iterator It( aLCM );
-    for( ; It.More(); It.Next() )
+    HYDROData_LandCoverMap::Explorer It( aLCM );
+    for( ; It.More(); It.Next())
     {
       TopoDS_Face aFace = It.Face();
       if (WriteObjectPolygon(hSHPHandle, aFace) != 1)
@@ -264,11 +264,18 @@ void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandl
     if (aW.IsNull())
       continue;
     NbWires++;
+    if (aW.Orientation() == TopAbs_INTERNAL)
+      //cant write internal wires/edges
+      continue; 
     // Try to reorder edges
     Handle(ShapeFix_Wire) aSFW = new ShapeFix_Wire( aW, theFace, Precision::Confusion() );
+    aSFW->ModifyTopologyMode() = Standard_False;
+    aSFW->ModifyGeometryMode() = Standard_False;
     aSFW->FixReorder();
     Handle(ShapeExtend_WireData) aSEWD = aSFW->WireData();
     Standard_Integer nbE = aSEWD->NbEdges();
+    if (nbE == 0)
+      continue;
     //
     anPartStart.push_back(x.size());
     NCollection_Sequence<gp_Pnt2d> aPnts;
@@ -289,30 +296,17 @@ void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandl
         aNPnts.Append(aPnts(j + 1));
     }
 
-    if (k == 1)
-    {
-      //an outer wire
-      //clockwise direction
-      for (int j = 1; j <= aNPnts.Size(); j++)
-      { 
-        x.push_back( aNPnts(j).X());
-        y.push_back( aNPnts(j).Y()); 
-      }
-      x.push_back( aNPnts(1).X());
-      y.push_back( aNPnts(1).Y()); 
-    }
-    else
-    {
-      //holes
-      //counter-clockwise direction
-      for (int j = aNPnts.Size(); j > 0; j--)
-      { 
-        x.push_back( aNPnts(j).X());
-        y.push_back( aNPnts(j).Y()); 
-      }
-      x.push_back( aNPnts(aNPnts.Size()).X());
-      y.push_back( aNPnts(aNPnts.Size()).Y()); 
+    //assume that the orientation of extrenal wire & internal wires is correct
+    //so just write all points "as-is"
+    //External wire will be written in clockwise direction
+    //any other wires (holes) - in anticlockwise direction
+    for (int j = 1; j <= aNPnts.Size(); j++)
+    { 
+      x.push_back( aNPnts(j).X());
+      y.push_back( aNPnts(j).Y()); 
     }
+    x.push_back( aNPnts(1).X());
+    y.push_back( aNPnts(1).Y()); 
   }
   
   aSHPObj = SHPCreateObject( SHPT_POLYGON, -1, NbWires, &anPartStart[0], NULL, x.size(), &x[0], &y[0], NULL, NULL );
@@ -341,6 +335,8 @@ bool HYDROData_ShapeFile::Parse(SHPHandle theHandle, ShapeType theType, int& the
 
 void HYDROData_ShapeFile::ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F)
 {
+  if (!anObj)
+    return;
   TopoDS_Wire W;
   TopoDS_Edge E; 
   int nParts = anObj->nParts;