Salome HOME
Issue #1740 The visualization of selected point in the graphic scene is not visible
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Face.cpp
index 36ef2b3e8a73f3dfb9bf35c7ff3ebcf7454d69f3..774cfdf39787a3745719e15fd8cca67d90e8f009 100644 (file)
@@ -8,21 +8,14 @@
 
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_ResultBody.h>
-#include <ModelAPI_ResultConstruction.h>
 
-#include <Events_Error.h>
-
-#include <GeomAPI_DataMapOfShapeShape.h>
+#include <GeomAPI_Edge.h>
 #include <GeomAPI_PlanarEdges.h>
 #include <GeomAPI_Pln.h>
 #include <GeomAPI_ShapeExplorer.h>
 
 #include <GeomAlgoAPI_ShapeTools.h>
 #include <GeomAlgoAPI_SketchBuilder.h>
-#include <GeomAlgoAPI_WireBuilder.h>
-
-#include <algorithm>
-#include <sstream>
 
 //=================================================================================================
 BuildPlugin_Face::BuildPlugin_Face()
@@ -51,31 +44,54 @@ void BuildPlugin_Face::execute()
 
   // Collect base shapes.
   ListOfShape anEdges;
+  std::list< std::shared_ptr<GeomAPI_Dir> > 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<GeomAPI_PlanarEdges> aSketch =
+        std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContext);
+    if (aSketch)
+      aListOfNormals.push_back(aSketch->norm());
   }
 
   // Get plane.
   std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_ShapeTools::findPlane(anEdges);
+  std::shared_ptr<GeomAPI_Dir> aNormal = aPln->direction();
+  bool isReverse = !aListOfNormals.empty();
+  std::list< std::shared_ptr<GeomAPI_Dir> >::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<GeomAPI_Pln>(new GeomAPI_Pln(aPln->location(), aNormal));
+  }
 
   // Get faces.
   ListOfShape aFaces;
-  GeomAlgoAPI_SketchBuilder::createFaces(aPln->location(), aPln->xDirection(), aPln->direction(), anEdges, aFaces);
+  GeomAlgoAPI_SketchBuilder::createFaces(aPln->location(), aPln->xDirection(),
+                                         aPln->direction(), anEdges, aFaces);
 
   // Get wires from faces.
   ListOfShape aWires;
   for(ListOfShape::const_iterator anIt = aFaces.cbegin(); anIt != aFaces.cend(); ++anIt) {
-    for(GeomAPI_ShapeExplorer anExp(*anIt, GeomAPI_Shape::WIRE); anExp.more(); anExp.next()) {
-      aWires.push_back(anExp.current());
-    }
+    aWires.push_back(GeomAlgoAPI_ShapeTools::getFaceOuterWire(*anIt));
+    //for(GeomAPI_ShapeExplorer anExp(*anIt, GeomAPI_Shape::WIRE); anExp.more(); anExp.next()) {
+    //  if(anExp.current()->orientation() == GeomAPI_Shape::REVERSED) {
+    //    continue;
+    //  }
+    //  aWires.push_back(anExp.current());
+    //}
   }
 
   // Make faces with holes.
@@ -89,12 +105,16 @@ void BuildPlugin_Face::execute()
     GeomShapePtr aShape = *anIt;
     aResultBody->store(aShape);
 
+    int anEdgeIndex = 1;
+
     for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
       GeomShapePtr anEdgeInResult = anExp.current();
       for(ListOfShape::const_iterator anIt = anEdges.cbegin(); anIt != anEdges.cend(); ++anIt) {
         std::shared_ptr<GeomAPI_Edge> anEdgeInList(new GeomAPI_Edge(*anIt));
         if(anEdgeInList->isEqual(anEdgeInResult)) {
-          aResultBody->modified(anEdgeInList, anEdgeInResult, "Edge");
+          aResultBody->modified(anEdgeInList, anEdgeInResult,
+                                "Edge_" + std::to_string((long long)anEdgeIndex), anEdgeIndex);
+          ++anEdgeIndex;
           break;
         }
       }