Salome HOME
Update viewer on delete an item
[modules/shaper.git] / src / FiltersPlugin / FiltersPlugin_OppositeToEdge.cpp
index b2cc86a6c85e17f649f7cec75aa6425ccfc14dbd..bf5805e1527403e644e1d68aa091501c78c1a200 100644 (file)
@@ -25,6 +25,8 @@
 
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_Wire.h>
+#include <GeomAPI_WireExplorer.h>
 
 #include <map>
 
@@ -51,12 +53,21 @@ static GeomShapePtr oppositeEdgeInQuadFace(const GeomShapePtr theEdge,
   int aNbEdges = 0;
   int anOriginalEdgeIndex = -THE_QUAD;
   GeomShapePtr anOppositeEdge;
-  GeomAPI_ShapeExplorer anExp(theFace, GeomAPI_Shape::EDGE);
+  GeomAPI_ShapeExplorer aWExp(theFace, GeomAPI_Shape::WIRE);
+  GeomWirePtr aWire = aWExp.current()->wire();
+  aWExp.next();
+  if (aWExp.more()) {
+    // face with a hole is not a quadrangle
+    return anOppositeEdge;
+  }
+
+  GeomAPI_WireExplorer anExp(aWire);
   while (anExp.more()) {
     if (anExp.current()->isSame(theEdge))
       anOriginalEdgeIndex = aNbEdges;
     else if (aNbEdges == anOriginalEdgeIndex + THE_QUAD / 2) {
-      anOppositeEdge = anExp.current();
+      if (anOriginalEdgeIndex < THE_QUAD)
+        anOppositeEdge = anExp.current();
       if (aNbEdges >= THE_QUAD)
         break;
     }
@@ -70,7 +81,7 @@ static GeomShapePtr oppositeEdgeInQuadFace(const GeomShapePtr theEdge,
         break;
       }
       if (!anOppositeEdge)
-        anExp.reinit();
+        anExp.init(aWire);
     }
   }
   return anOppositeEdge;
@@ -133,8 +144,11 @@ bool FiltersPlugin_OppositeToEdge::isOk(const GeomShapePtr& theShape, const Resu
 
   if (myCachedShapes.empty()) {
     ResultBodyPtr aBaseResult = ModelAPI_Tools::bodyOwner(aList->context(), true);
-    if (!aBaseResult.get())
-      return false;
+    if (!aBaseResult.get()) {
+      aBaseResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aList->context());
+      if (!aBaseResult.get())
+        return false;
+    }
 
     cacheOppositeEdges(aBaseResult->shape(), anEdge,
         const_cast<FiltersPlugin_OppositeToEdge*>(this)->myCachedShapes);
@@ -143,20 +157,9 @@ bool FiltersPlugin_OppositeToEdge::isOk(const GeomShapePtr& theShape, const Resu
   return myCachedShapes.find(theShape) != myCachedShapes.end();
 }
 
-static std::string XMLRepresentation =
-"<filter id = \"OppositeToEdge\">"
-" <shape_selector id=\"OppositeToEdge__OppositeToEdge\""
-"   label=\"Edge:\""
-"   tooltip=\"Select edge.\""
-"   shape_types=\"edges\">"
-"   <validator id=\"GeomValidators_ShapeType\" parameters=\"line\"/>"
-" </shape_selector>"
-"</filter>";
-
-
 std::string FiltersPlugin_OppositeToEdge::xmlRepresentation() const
 {
-  return XMLRepresentation;
+  return xmlFromFile("filter-OppositeToEdge.xml");
 }
 
 void FiltersPlugin_OppositeToEdge::initAttributes(ModelAPI_FiltersArgs& theArguments)