From b7c5fbb0932062ca9d22c9a35bc59d0b50752ff7 Mon Sep 17 00:00:00 2001 From: Ekaterina Sukhareva Date: Fri, 10 Nov 2023 10:36:43 +0000 Subject: [PATCH] Fix regression after - bos #35156 Non planar Faces --- src/BuildPlugin/BuildPlugin_Face.cpp | 35 +++++++++++++++------- src/BuildPlugin/BuildPlugin_Validators.cpp | 14 +++++++++ 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/BuildPlugin/BuildPlugin_Face.cpp b/src/BuildPlugin/BuildPlugin_Face.cpp index 874ff58f3..bdad80062 100644 --- a/src/BuildPlugin/BuildPlugin_Face.cpp +++ b/src/BuildPlugin/BuildPlugin_Face.cpp @@ -60,7 +60,8 @@ void BuildPlugin_Face::execute() } // Collect base shapes. - ListOfShape anEdges; + ListOfShape anAllEdges; + ListOfShape aPlanarEdges; ListOfShape aNonPlanarEdges; ListOfShape anOriginalFaces; ListOfShape aContexts; @@ -101,26 +102,40 @@ void BuildPlugin_Face::execute() for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) { GeomShapePtr anEdge = anExp.current(); - isPlanar? anEdges.push_back(anEdge) : aNonPlanarEdges.push_back(anEdge); + anAllEdges.push_back(anEdge); + isPlanar? aPlanarEdges.push_back(anEdge) : aNonPlanarEdges.push_back(anEdge); } } - if (!anEdges.empty()) + bool isAllPlanar(false); + if(!anAllEdges.empty()) { - //check is planar objects belong to nke - std::shared_ptr aPln = GeomAlgoAPI_ShapeTools::findPlane(anEdges); + //check if all the object actually belong to one plane. + std::shared_ptr aPln = GeomAlgoAPI_ShapeTools::findPlane(anAllEdges); + if(aPln.get() && !aNonPlanarEdges.empty()) + { + aPlanarEdges.insert(aPlanarEdges.end(), aNonPlanarEdges.begin(), aNonPlanarEdges.end()); + aNonPlanarEdges.clear(); + isAllPlanar = true; + } + } + + if (!isAllPlanar && !aPlanarEdges.empty()) + { + //check is planar objects belong to one plane + std::shared_ptr aPln = GeomAlgoAPI_ShapeTools::findPlane(aPlanarEdges); if(!aPln.get()) { - aNonPlanarEdges.insert(aNonPlanarEdges.end(), anEdges.begin(), anEdges.end()); - anEdges.clear(); + aNonPlanarEdges.insert(aNonPlanarEdges.end(), aPlanarEdges.begin(), aPlanarEdges.end()); + aPlanarEdges.clear(); } } // Build faces by edges. ListOfShape aFaces; GeomMakeShapePtr aFaceBuilder; - if (!anEdges.empty()) - buildFacesByEdges(anEdges, aListOfNormals, aFaces, aFaceBuilder); + if (!aPlanarEdges.empty()) + buildFacesByEdges(aPlanarEdges, aListOfNormals, aFaces, aFaceBuilder); int aNbFacesFromEdges = (int)aFaces.size(); // Build non-planar faces by edges. @@ -153,7 +168,7 @@ void BuildPlugin_Face::execute() ListOfShape aBaseShapes; if (anIndex < aNbFacesFromEdges) - aBaseShapes = anEdges; + aBaseShapes = aPlanarEdges; else if(anIndex < aNbNonPlanarFaces) aBaseShapes = aNonPlanarEdges; else diff --git a/src/BuildPlugin/BuildPlugin_Validators.cpp b/src/BuildPlugin/BuildPlugin_Validators.cpp index 81c16c770..8d12b7cad 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.cpp +++ b/src/BuildPlugin/BuildPlugin_Validators.cpp @@ -353,6 +353,20 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr aPln = GeomAlgoAPI_ShapeTools::findPlane(anAllEdges); + if(aPln.get()) { + // Check that selected objects have closed contours. + GeomAlgoAPI_SketchBuilder aBuilder(aPln, anAllEdges); + const ListOfShape& aFaces = aBuilder.faces(); + if(!aFaces.empty()) { + return true; + } + } + } + + //check only planar onjects bool isPlanarBelongToOnePlane(false); if (!aPlanarEdges.empty()) { -- 2.39.2