From: Nicolas RECHATIN Date: Wed, 14 Sep 2022 07:51:07 +0000 (+0200) Subject: fix : Rework LOFT for EDGES X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f58ebe57feaab2448a5e4b7b5c11f1b916364f19;p=modules%2Fshaper.git fix : Rework LOFT for EDGES --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Loft.cpp b/src/FeaturesPlugin/FeaturesPlugin_Loft.cpp index 48722db46..223e41e6f 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Loft.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Loft.cpp @@ -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 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 aLoftAlgo(new GeomAlgoAPI_Loft(aFirstShape, aSecondShape)); - std::shared_ptr 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; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Loft.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Loft.cpp index 3e07f5265..199fd1870 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Loft.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Loft.cpp @@ -19,6 +19,7 @@ #include "GeomAlgoAPI_DFLoader.h" #include "GeomAlgoAPI_Loft.h" +#include "GeomAlgoAPI_WireBuilder.h" #include #include @@ -26,8 +27,7 @@ #include //================================================================================================== -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(); + + // Convert first edge to wire + aSecondEdge.push_back(theSecondShape); + aSecondWire = GeomAlgoAPI_WireBuilder::wire(aSecondEdge); + TopoDS_Shape aSecondShape = aSecondWire->impl(); + + aFirstShapeOut = aFirstShape; + aSecondShapeOut = aSecondShape; } // Initialize and build