Salome HOME
Fix for bug Bug IPAL20288 (4x: CRASH after trying to build a sketch).
[modules/geom.git] / src / GEOMImpl / GEOMImpl_LineDriver.cxx
index a7bf8d433b86970c5addbe27a797b562c6801b8c..4f7b9263c7ba1f0464bea707051609fa0d389fbc 100644 (file)
 
 #include <BRep_Tool.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
-
+#include <BRepAlgoAPI_Section.hxx>
 #include <TopAbs.hxx>
 #include <TopExp.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Vertex.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopTools_MapOfShape.hxx>
 
 #include <gp_Pnt.hxx>
 #include <Precision.hxx>
@@ -92,6 +94,40 @@ Standard_Integer GEOMImpl_LineDriver::Execute(TFunction_Logbook& log) const
     }
     aShape = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
 
+  } else if (aType == LINE_TWO_FACES) {
+    Handle(GEOM_Function) aRefFace1 = aPI.GetFace1();
+    Handle(GEOM_Function) aRefFace2 = aPI.GetFace2();
+    TopoDS_Shape aShape1 = aRefFace1->GetValue();
+    TopoDS_Shape aShape2 = aRefFace2->GetValue();
+    if (aShape1.ShapeType() != TopAbs_FACE ||
+        aShape2.ShapeType() != TopAbs_FACE) {
+      Standard_ConstructionError::Raise("Wrong arguments: two faces must be given");
+    }
+    if (aShape1.IsSame(aShape2)) {
+      Standard_ConstructionError::Raise("The end faces must be different");
+    }
+    BRepAlgoAPI_Section E (aShape1, aShape2, Standard_False);
+    E.Approximation(Standard_True);
+    E.Build();
+    if (!E.IsDone()) {
+      Standard_ConstructionError::Raise("Line can not be performed on the given faces");
+    }
+    else
+    {
+       TopExp_Explorer Exp (E, TopAbs_EDGE);
+       if ( Exp.More() ){
+           aShape = Exp.Current();
+           Exp.Next();
+       }
+       else
+         {
+           Standard_ConstructionError::Raise("Faces not have intersection line");
+           aShape = E.Shape();
+         }
+       if ( Exp.More() )
+         aShape = E.Shape();
+    }
+
   } else if (aType == LINE_PNT_DIR) {
     Handle(GEOM_Function) aRefPnt = aPI.GetPoint1();
     Handle(GEOM_Function) aRefDir = aPI.GetPoint2();