From b41a72bae6aa93ffcdc2e7b156d411e6bfcc8af0 Mon Sep 17 00:00:00 2001 From: skv Date: Thu, 26 Mar 2015 16:08:55 +0300 Subject: [PATCH] 0022869: Add a function GEOMUtils::IsOpenPath that is common for GUI and Pipe Driver --- src/GEOMUtils/GEOMUtils.cxx | 51 +++++++++++++++++++++ src/GEOMUtils/GEOMUtils.hxx | 13 ++++++ src/GenerationGUI/CMakeLists.txt | 2 + src/GenerationGUI/GenerationGUI_PipeDlg.cxx | 48 ++----------------- 4 files changed, 69 insertions(+), 45 deletions(-) diff --git a/src/GEOMUtils/GEOMUtils.cxx b/src/GEOMUtils/GEOMUtils.cxx index 9b7ca2d97..3e0b18977 100644 --- a/src/GEOMUtils/GEOMUtils.cxx +++ b/src/GEOMUtils/GEOMUtils.cxx @@ -1236,3 +1236,54 @@ double GEOMUtils::DefaultDeflection() { return 0.001; } + +//======================================================================= +//function : IsOpenPath +//purpose : +//======================================================================= +bool GEOMUtils::IsOpenPath(const TopoDS_Shape &theShape) +{ + bool isOpen = true; + + if (theShape.IsNull() == Standard_False) { + if (theShape.Closed()) { + // The shape is closed + isOpen = false; + } else { + const TopAbs_ShapeEnum aType = theShape.ShapeType(); + + if (aType == TopAbs_EDGE || aType == TopAbs_WIRE) { + // Check if path ends are coinsident. + TopoDS_Vertex aV[2]; + + if (aType == TopAbs_EDGE) { + // Edge + TopExp::Vertices(TopoDS::Edge(theShape), aV[0], aV[1]); + } else { + // Wire + TopExp::Vertices(TopoDS::Wire(theShape), aV[0], aV[1]); + } + + if (aV[0].IsNull() == Standard_False && + aV[1].IsNull() == Standard_False) { + if (aV[0].IsSame(aV[1])) { + // The shape is closed + isOpen = false; + } else { + const Standard_Real aTol1 = BRep_Tool::Tolerance(aV[0]); + const Standard_Real aTol2 = BRep_Tool::Tolerance(aV[1]); + const gp_Pnt aPnt1 = BRep_Tool::Pnt(aV[0]); + const gp_Pnt aPnt2 = BRep_Tool::Pnt(aV[1]); + + if (aPnt1.Distance(aPnt2) <= aTol1 + aTol2) { + // The shape is closed + isOpen = false; + } + } + } + } + } + } + + return isOpen; +} diff --git a/src/GEOMUtils/GEOMUtils.hxx b/src/GEOMUtils/GEOMUtils.hxx index d8a839940..8ffa25be2 100644 --- a/src/GEOMUtils/GEOMUtils.hxx +++ b/src/GEOMUtils/GEOMUtils.hxx @@ -328,6 +328,19 @@ namespace GEOMUtils * \return default deflection value */ Standard_EXPORT double DefaultDeflection(); + + /** + * \brief Check if the shape is not a closed wire or edge. + * + * This function is used for pipe creation algorithm to test if + * the pipe path is not closed. It returns false if theShape is a wire or + * an edge with coincident end vertices. Otherwise it returns true. + * + * \param theShape the shape to be tested. + * \return true if theShape is not a closed wire or edge. + */ + Standard_EXPORT bool IsOpenPath(const TopoDS_Shape &theShape); + }; #endif diff --git a/src/GenerationGUI/CMakeLists.txt b/src/GenerationGUI/CMakeLists.txt index 181522a3c..5f7afb3a1 100755 --- a/src/GenerationGUI/CMakeLists.txt +++ b/src/GenerationGUI/CMakeLists.txt @@ -37,6 +37,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/GEOMImpl ${PROJECT_SOURCE_DIR}/src/GEOMGUI ${PROJECT_SOURCE_DIR}/src/GEOMBase + ${PROJECT_SOURCE_DIR}/src/GEOMUtils ${PROJECT_SOURCE_DIR}/src/DlgRef ${PROJECT_BINARY_DIR}/src/DlgRef ${CMAKE_CURRENT_SOURCE_DIR} @@ -55,6 +56,7 @@ SET(_link_LIBRARIES GEOMClient GEOMImpl GEOMBase + GEOMUtils GEOM DlgRef ) diff --git a/src/GenerationGUI/GenerationGUI_PipeDlg.cxx b/src/GenerationGUI/GenerationGUI_PipeDlg.cxx index 5474b1e43..474230309 100644 --- a/src/GenerationGUI/GenerationGUI_PipeDlg.cxx +++ b/src/GenerationGUI/GenerationGUI_PipeDlg.cxx @@ -29,19 +29,14 @@ #include #include #include +#include #include #include #include #include -#include #include -#include -#include -#include -#include -#include #include #include @@ -731,45 +726,8 @@ void GenerationGUI_PipeDlg::updateGenGroup() // Check if the path is closed. TopoDS_Shape aShapePath; - if (GEOMBase::GetShape(myPath.get(), aShapePath) && - aShapePath.IsNull() == Standard_False) { - if (aShapePath.Closed()) { - // No groups should be generated if the path is closed. - isEnable = false; - } else { - const TopAbs_ShapeEnum aType = aShapePath.ShapeType(); - - if (aType == TopAbs_EDGE || aType == TopAbs_WIRE) { - // Check if path ends are coinsident. - TopoDS_Vertex aV[2]; - - if (aType == TopAbs_EDGE) { - // Edge - TopExp::Vertices(TopoDS::Edge(aShapePath), aV[0], aV[1]); - } else { - // Wire - TopExp::Vertices(TopoDS::Wire(aShapePath), aV[0], aV[1]); - } - - if (aV[0].IsNull() == Standard_False && - aV[1].IsNull() == Standard_False) { - if (aV[0].IsSame(aV[1])) { - // No groups should be generated if the path is closed. - isEnable = false; - } else { - const Standard_Real aTol1 = BRep_Tool::Tolerance(aV[0]); - const Standard_Real aTol2 = BRep_Tool::Tolerance(aV[1]); - const gp_Pnt aPnt1 = BRep_Tool::Pnt(aV[0]); - const gp_Pnt aPnt2 = BRep_Tool::Pnt(aV[1]); - - if (aPnt1.Distance(aPnt2) <= aTol1 + aTol2) { - // No groups should be generated if the path is closed. - isEnable = false; - } - } - } - } - } + if (GEOMBase::GetShape(myPath.get(), aShapePath)) { + isEnable = GEOMUtils::IsOpenPath(aShapePath); } } -- 2.39.2