]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
fix : Rework LOFT for EDGES nrn/Feature/LOFT
authorNicolas RECHATIN <nicolas.rechatin@cea.fr>
Wed, 14 Sep 2022 07:51:07 +0000 (09:51 +0200)
committerNicolas RECHATIN <nicolas.rechatin@cea.fr>
Wed, 14 Sep 2022 07:51:07 +0000 (09:51 +0200)
src/FeaturesPlugin/FeaturesPlugin_Loft.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Loft.cpp

index 48722db46bae2b1f40686116989c6ca31e1d71e1..223e41e6f8761d4caba34f09dad7ccd0ad216ac2 100644 (file)
@@ -61,125 +61,29 @@ void FeaturesPlugin_Loft::execute()
       aSecondShape = aSecondelection->value();
       if (!aSecondShape && aSecondelection->context())
         aSecondShape = aSecondelection->context()->shape();
-
     }
-    // Loft for two edges
-    if(aFirstShape->isEdge()) {
-
-      std::shared_ptr<GeomAlgoAPI_Filling> aFilling(
-                          new GeomAlgoAPI_Filling(2.0, 5.0, 0, 0.0001, 0.0001 ));
-
-      // collect base shapes
-      GeomEdgePtr aFirstEdge = toEdge(aFirstShape);
-      if (!aFirstEdge) {
-        myLastEdgeStartPoint = GeomPointPtr();
-        myLastEdgeEndPoint = GeomPointPtr();
-        return;
-      }
-      aFilling->add(aFirstEdge);
-
-      GeomEdgePtr aSecondEdge = toEdge(aSecondShape);
-      if (!aSecondEdge) {
-        myLastEdgeStartPoint = GeomPointPtr();
-        myLastEdgeEndPoint = GeomPointPtr();
-        return;
-      }
-      aFilling->add(aSecondEdge);
-      myLastEdgeStartPoint = GeomPointPtr();
-      myLastEdgeEndPoint = GeomPointPtr();
-
-      // build result
-      aFilling->build();
-      std::string anError;
-      if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aFilling, getKind(), anError)) {
-        setError(anError);
-        removeResults(0);
-        return;
-      }
-
-      /// store result
-      GeomShapePtr aCreatedFace = aFilling->shape();
-      ResultBodyPtr aResultBody = document()->createBody(data());
-      aResultBody->store(aCreatedFace);
-      // store edges
-      for(GeomAPI_ShapeExplorer anExp(aCreatedFace, GeomAPI_Shape::EDGE);
-                                anExp.more(); anExp.next()) {
-        GeomShapePtr anEdge = anExp.current();
-        aResultBody->generated(anEdge, "Loft_Edge");
-      }
-      setResult(aResultBody, 0);
 
-    } else {
+    std::string anError;
+    std::shared_ptr<GeomAlgoAPI_Loft> aLoftAlgo(new GeomAlgoAPI_Loft(aFirstShape, aSecondShape));
 
-      std::shared_ptr<GeomAlgoAPI_Loft> aLoftAlgo(new GeomAlgoAPI_Loft(aFirstShape, aSecondShape));
-
-      std::string anError;
-
-      if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aLoftAlgo, getKind(), anError)) {
-        setError(anError);
-        return;
-      }
-      ListOfShape  theBoundaryShapes;
-      theBoundaryShapes.push_back(aFirstShape);
-      theBoundaryShapes.push_back(aSecondShape);
-
-      // Create result body.
-      ResultBodyPtr aResultBody = document()->createBody(data());
-
-      aResultBody->store(aLoftAlgo->shape());
-      // store Faces
-      for(GeomAPI_ShapeExplorer anExp(aLoftAlgo->shape(), GeomAPI_Shape::FACE);
-                                anExp.more(); anExp.next()) {
-        GeomShapePtr anEdge = anExp.current();
-        aResultBody->generated(anEdge, "Loft_Face");
-      }
-      setResult(aResultBody, 0);
+    if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aLoftAlgo, getKind(), anError)) {
+      setError(anError);
+      return;
     }
-  }
-}
-
-//=================================================================================================
-GeomEdgePtr FeaturesPlugin_Loft::toEdge(const GeomShapePtr& theShape)
-{
-  GeomEdgePtr anEdge = GeomEdgePtr(new GeomAPI_Edge(GeomAlgoAPI_Copy(theShape).shape()));
-
-  if (!anEdge || anEdge->empty()) {
-    static const std::string aFeatureError =
-        "Error: incorrect type of input feature (edges are supported only).";
-    setError(aFeatureError);
-    return anEdge;
-  }
-
-  // correct edge orientation according to filling method
-  // check the distance to previous edge boundaries, reverse edge if necessary
-  GeomPointPtr aStartPnt = anEdge->firstPoint();
-  GeomPointPtr aEndPnt = anEdge->lastPoint();
-  if (anEdge->orientation() == GeomAPI_Shape::REVERSED) {
-    aStartPnt = anEdge->lastPoint();
-    aEndPnt = anEdge->firstPoint();
-  }
-  bool isReverse = false;
-  if (myLastEdgeStartPoint) {
-    double d1 = myLastEdgeStartPoint->distance(aStartPnt)
-              + myLastEdgeEndPoint->distance(aEndPnt);
-    double d2 = myLastEdgeStartPoint->distance(aEndPnt)
-              + myLastEdgeEndPoint->distance(aStartPnt);
-    if (fabs(d1 - d2) < 1.e-7) {
-      // undefined case => check distance to start point only
-      d1 = myLastEdgeStartPoint->distance(aStartPnt);
-      d2 = myLastEdgeStartPoint->distance(aEndPnt);
+    ListOfShape  theBoundaryShapes;
+    theBoundaryShapes.push_back(aFirstShape);
+    theBoundaryShapes.push_back(aSecondShape);
+
+    // Create result body.
+    ResultBodyPtr aResultBody = document()->createBody(data());
+
+    aResultBody->store(aLoftAlgo->shape());
+    // store Faces
+    for(GeomAPI_ShapeExplorer anExp(aLoftAlgo->shape(), GeomAPI_Shape::FACE);
+                              anExp.more(); anExp.next()) {
+      GeomShapePtr anEdge = anExp.current();
+      aResultBody->generated(anEdge, "Loft_Face");
     }
-    isReverse = d2 < d1;
+    setResult(aResultBody, 0);
   }
-
-  if (isReverse) {
-    anEdge->reverse();
-    myLastEdgeStartPoint = aEndPnt;
-    myLastEdgeEndPoint = aStartPnt;
-  } else {
-    myLastEdgeStartPoint = aStartPnt;
-    myLastEdgeEndPoint = aEndPnt;
-  }
-
-  return anEdge;
 }
index 3e07f5265b30d27a706f7b42edf198a76742fff2..199fd1870eda3890d80db4326807be18205876bf 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "GeomAlgoAPI_DFLoader.h"
 #include "GeomAlgoAPI_Loft.h"
+#include "GeomAlgoAPI_WireBuilder.h"
 
 #include <BRepOffsetAPI_ThruSections.hxx>
 #include <Precision.hxx>
@@ -26,8 +27,7 @@
 #include <TopoDS.hxx>
 
 //==================================================================================================
-GeomAlgoAPI_Loft::GeomAlgoAPI_Loft(const GeomShapePtr theFirstShape,
-                                   const GeomShapePtr theSecondShape)
+GeomAlgoAPI_Loft::GeomAlgoAPI_Loft(const GeomShapePtr theFirstShape, const GeomShapePtr theSecondShape)
 {
   build(theFirstShape, theSecondShape);
 }
@@ -49,7 +49,7 @@ void GeomAlgoAPI_Loft::build(const GeomShapePtr theFirstShape,
     return;
   }
 
-  bool anIsSolid = true;
+  bool anIsSolid = false;
 
   TopoDS_Shape aFirstShapeOut;
   TopoDS_Shape aSecondShapeOut;
@@ -58,12 +58,31 @@ void GeomAlgoAPI_Loft::build(const GeomShapePtr theFirstShape,
     aFirstShapeOut = anExp.Current();
     TopExp_Explorer anExp2(aSecondShape, TopAbs_WIRE);
     aSecondShapeOut = anExp2.Current();
+    anIsSolid = true;
   }
 
   if (aFirstShape.ShapeType() == TopAbs_WIRE) {
     aFirstShapeOut = aFirstShape;
     aSecondShapeOut = aSecondShape;
-    anIsSolid = false;
+  }
+
+  if (aFirstShape.ShapeType() == TopAbs_EDGE)
+  {
+    GeomShapePtr aFirstWire, aSecondWire;
+    ListOfShape aFirstEdge, aSecondEdge;
+
+    // Convert first edge to wire
+    aFirstEdge.push_back(theFirstShape);
+    aFirstWire = GeomAlgoAPI_WireBuilder::wire(aFirstEdge);
+    TopoDS_Shape aFirstShape = aFirstWire->impl<TopoDS_Shape>();
+
+    // Convert first edge to wire
+    aSecondEdge.push_back(theSecondShape);
+    aSecondWire = GeomAlgoAPI_WireBuilder::wire(aSecondEdge);
+    TopoDS_Shape aSecondShape = aSecondWire->impl<TopoDS_Shape>();
+
+    aFirstShapeOut = aFirstShape;
+    aSecondShapeOut = aSecondShape;
   }
 
   // Initialize and build