]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
0022869: Add a function GEOMUtils::IsOpenPath that is common for GUI and Pipe Driver
authorskv <skv@opencascade.com>
Thu, 26 Mar 2015 13:08:55 +0000 (16:08 +0300)
committerskv <skv@opencascade.com>
Thu, 26 Mar 2015 13:08:55 +0000 (16:08 +0300)
src/GEOMUtils/GEOMUtils.cxx
src/GEOMUtils/GEOMUtils.hxx
src/GenerationGUI/CMakeLists.txt
src/GenerationGUI/GenerationGUI_PipeDlg.cxx

index 9b7ca2d970de5f23e4ee4db05819d217ab8de3ed..3e0b18977de279e5b07a1e1e15efad56bcf371f2 100644 (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;
+}
index d8a8399407cfa7946ea475c79f2374ed51d21923..8ffa25be2e10bb75ad3e2e2b9ed592c14d4b542d 100644 (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
index 181522a3c9d79007c8a15782ace2cfeeca4d2081..5f7afb3a1b54cb600e3bb14c571baa0a4dfb0205 100755 (executable)
@@ -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
   )
index 5474b1e434d306dd6ae80b74bdacfeb932bf1d48..4742303090abcd7e3dcf52baf20e710543abc1b7 100644 (file)
 #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);
     }
   }