From daa4b94e31bc333bbbc39ba0125cfce95a0ce729 Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 3 Nov 2016 17:06:49 +0300 Subject: [PATCH] Stabilize orientation of face built by BuildPlugin_Feature (issue #1559) --- src/BuildPlugin/BuildPlugin_Face.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/BuildPlugin/BuildPlugin_Face.cpp b/src/BuildPlugin/BuildPlugin_Face.cpp index a9c40af9e..0f2080298 100644 --- a/src/BuildPlugin/BuildPlugin_Face.cpp +++ b/src/BuildPlugin/BuildPlugin_Face.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -43,20 +44,38 @@ void BuildPlugin_Face::execute() // Collect base shapes. ListOfShape anEdges; + std::list< std::shared_ptr > aListOfNormals; for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); GeomShapePtr aShape = aSelection->value(); + GeomShapePtr aContext = aSelection->context()->shape(); if(!aShape.get()) { - aShape = aSelection->context()->shape(); + aShape = aContext; } for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) { GeomShapePtr anEdge = anExp.current(); anEdges.push_back(anEdge); } + + // check whether the context is a sketch, in this case store its normal for further needs + std::shared_ptr aSketch = + std::dynamic_pointer_cast(aContext); + if (aSketch) + aListOfNormals.push_back(aSketch->norm()); } // Get plane. std::shared_ptr aPln = GeomAlgoAPI_ShapeTools::findPlane(anEdges); + std::shared_ptr aNormal = aPln->direction(); + bool isReverse = !aListOfNormals.empty(); + std::list< std::shared_ptr >::const_iterator aNormIt = aListOfNormals.begin(); + for (; aNormIt != aListOfNormals.end() && isReverse; ++aNormIt) + if ((*aNormIt)->dot(aNormal) > 1.e-7) + isReverse = false; + if (isReverse) { + aNormal->reverse(); + aPln = std::shared_ptr(new GeomAPI_Pln(aPln->location(), aNormal)); + } // Get faces. ListOfShape aFaces; -- 2.39.2