From: azv Date: Thu, 3 Nov 2016 14:06:49 +0000 (+0300) Subject: Stabilize orientation of face built by BuildPlugin_Feature (issue #1559) X-Git-Tag: V_2.6.0~117 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=daa4b94e31bc333bbbc39ba0125cfce95a0ce729;p=modules%2Fshaper.git Stabilize orientation of face built by BuildPlugin_Feature (issue #1559) --- 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;