Salome HOME
Use discretization to write non-linear borders of LCM to SHP file // p.2 BR_LCM_COMP
authorisn <isn@opencascade.com>
Mon, 16 Nov 2015 18:29:39 +0000 (21:29 +0300)
committerisn <isn@opencascade.com>
Mon, 16 Nov 2015 19:00:22 +0000 (22:00 +0300)
src/HYDROData/HYDROData_ShapeFile.cxx
src/HYDROData/HYDROData_ShapeFile.h

index b2c30411aa0ab03c46fb8765d5089b6fde6fc555..d3ade82aff87c49e9997abeb5836a8b572823dd1 100644 (file)
@@ -198,34 +198,18 @@ int HYDROData_ShapeFile::WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROD
   return 1;
 }
 
-int HYDROData_ShapeFile::WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS_Shape& theInputShape )
+int HYDROData_ShapeFile::WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS_Shape& theInputShape,
+                                            bool bUseDiscr, double theDefl)
 {
   if (theInputShape.IsNull())
     return 0;
-  TopExp_Explorer anEdgeEx(theInputShape, TopAbs_EDGE);
-  for (; anEdgeEx.More(); anEdgeEx.Next()) 
-  {
-    TopoDS_Edge E = TopoDS::Edge(anEdgeEx.Current());
-    double aFP, aLP;
-    Handle_Geom_Curve aCur = BRep_Tool::Curve(E, aFP, aLP);
-    Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCur);
-    if (aLine.IsNull())
-    {
-      Handle(Geom_TrimmedCurve) aTC = Handle(Geom_TrimmedCurve)::DownCast(aCur);
-      if (!aTC.IsNull())
-      {
-        Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aTC->BasisCurve());
-        if (aLine.IsNull())
-          return -1;
-      }
-      else
-        return -1;
-    }
 
-  }
+  if (!bUseDiscr && !CheckLinear(theInputShape))
+    return -1;
+
   if (theInputShape.ShapeType() == TopAbs_FACE)
   {
-    ProcessFace(TopoDS::Face(theInputShape), theShpHandle);
+    ProcessFace(TopoDS::Face(theInputShape), theShpHandle, bUseDiscr, theDefl);
   }
   else if (theInputShape.ShapeType() == TopAbs_COMPOUND)
   {
@@ -235,7 +219,7 @@ int HYDROData_ShapeFile::WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS
       TopoDS_Face aF = TopoDS::Face(Ex.Current());   
       if (aF.IsNull())
         continue;
-      ProcessFace(aF, theShpHandle);
+      ProcessFace(aF, theShpHandle, bUseDiscr, theDefl);
     }
   }
   else
@@ -292,7 +276,7 @@ void HYDROData_ShapeFile::ProcessFace(const TopoDS_Face& theFace, SHPHandle theS
     for (Standard_Integer i = 1; i <= nbE; i++)
     {
       TopoDS_Edge E = aSEWD->Edge(i);
-      if (bUseDiscr)
+      if (!bUseDiscr)
       {
         TopoDS_Vertex aV = TopExp::LastVertex(E, 1);
         if (aV.IsNull())
@@ -986,4 +970,29 @@ bool HYDROData_ShapeFile::DBF_WriteFieldAndValues(const QString& theFileName, co
   DBFClose( hDBF );
   return true;
 
+}
+
+bool HYDROData_ShapeFile::CheckLinear(const TopoDS_Shape& theInpShape)
+{
+  TopExp_Explorer anEdgeEx(theInpShape, TopAbs_EDGE);
+  for (; anEdgeEx.More(); anEdgeEx.Next()) 
+  {
+    TopoDS_Edge E = TopoDS::Edge(anEdgeEx.Current());
+    double aFP, aLP;
+    Handle_Geom_Curve aCur = BRep_Tool::Curve(E, aFP, aLP);
+    Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCur);
+    if (aLine.IsNull())
+    {
+      Handle(Geom_TrimmedCurve) aTC = Handle(Geom_TrimmedCurve)::DownCast(aCur);
+      if (!aTC.IsNull())
+      {
+        Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aTC->BasisCurve());
+        if (aLine.IsNull())
+          return false;
+      }
+      else
+        return false;
+    }
+  }
+  return true;
 }
\ No newline at end of file
index 4046f0b8562466173ccb70b81164bf39b118da45..cf24d3b5248b785f6bc7ff86d2b6564afb4b6b87 100644 (file)
@@ -94,7 +94,7 @@ public:
 
   int WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly );
 
-  int WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS_Shape& theInputShape );
+  int WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS_Shape& theInputShape, bool bUseDiscr = false, double theDefl = 0.1 );
   //Import
   bool Parse(SHPHandle theHandle, ShapeType theType, int& theShapeTypeOfFile);
   //Import Landcover
@@ -133,7 +133,9 @@ public:
 private:
   
   void ProcessFace(const TopoDS_Face& theFace, SHPHandle theShpHandle,
-                   bool bUseDiscr = false, double theDefl = 0.1);
+                   bool bUseDiscr, double theDefl);
+
+  bool CheckLinear(const TopoDS_Shape& theInpShape);
 
   int TryOpenShapeFile(QString theFileName);