0022869: Add a function GEOMUtils::IsOpenPath that is common for GUI and Pipe Driver

This commit is contained in:
skv 2015-03-26 16:08:55 +03:00
parent c5bc521a7c
commit b41a72bae6
4 changed files with 69 additions and 45 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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
)

View File

@ -29,19 +29,14 @@
#include <DlgRef.h>
#include <GeometryGUI.h>
#include <GEOMBase.h>
#include <GEOMUtils.hxx>
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
#include <BRep_Tool.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS.hxx>
#include <TopExp.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>
#include <TColStd_MapOfInteger.hxx>
#include <GEOMImpl_Types.hxx>
@ -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);
}
}