From: isn Date: Mon, 16 Nov 2015 18:29:39 +0000 (+0300) Subject: Use discretization to write non-linear borders of LCM to SHP file // p.2 X-Git-Tag: v1.5~37^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9da13b7faab6019c75848f200330e54ee3442965;p=modules%2Fhydro.git Use discretization to write non-linear borders of LCM to SHP file // p.2 --- diff --git a/src/HYDROData/HYDROData_ShapeFile.cxx b/src/HYDROData/HYDROData_ShapeFile.cxx index b2c30411..d3ade82a 100644 --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@ -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 diff --git a/src/HYDROData/HYDROData_ShapeFile.h b/src/HYDROData/HYDROData_ShapeFile.h index 4046f0b8..cf24d3b5 100644 --- a/src/HYDROData/HYDROData_ShapeFile.h +++ b/src/HYDROData/HYDROData_ShapeFile.h @@ -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);