Salome HOME
Implement filter "F9: External Faces"
authorazv <azv@opencascade.com>
Thu, 4 Jul 2019 12:00:03 +0000 (15:00 +0300)
committerazv <azv@opencascade.com>
Thu, 4 Jul 2019 12:00:03 +0000 (15:00 +0300)
29 files changed:
src/FiltersPlugin/CMakeLists.txt
src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp
src/FiltersPlugin/FiltersPlugin_BelongsTo.h
src/FiltersPlugin/FiltersPlugin_ExternalFaces.cpp [new file with mode: 0644]
src/FiltersPlugin/FiltersPlugin_ExternalFaces.h [new file with mode: 0644]
src/FiltersPlugin/FiltersPlugin_HorizontalFace.cpp
src/FiltersPlugin/FiltersPlugin_HorizontalFace.h
src/FiltersPlugin/FiltersPlugin_OnGeometry.cpp
src/FiltersPlugin/FiltersPlugin_OnGeometry.h
src/FiltersPlugin/FiltersPlugin_OnLine.cpp
src/FiltersPlugin/FiltersPlugin_OnLine.h
src/FiltersPlugin/FiltersPlugin_OnPlane.cpp
src/FiltersPlugin/FiltersPlugin_OnPlane.h
src/FiltersPlugin/FiltersPlugin_OnPlaneSide.cpp
src/FiltersPlugin/FiltersPlugin_OnPlaneSide.h
src/FiltersPlugin/FiltersPlugin_OppositeToEdge.cpp
src/FiltersPlugin/FiltersPlugin_OppositeToEdge.h
src/FiltersPlugin/FiltersPlugin_Plugin.cpp
src/FiltersPlugin/FiltersPlugin_RelativeToSolid.cpp
src/FiltersPlugin/FiltersPlugin_RelativeToSolid.h
src/FiltersPlugin/FiltersPlugin_VerticalFace.cpp
src/FiltersPlugin/FiltersPlugin_VerticalFace.h
src/FiltersPlugin/Test/TestFilter_ExternalFaces.py [new file with mode: 0644]
src/Model/Model_FiltersFactory.cpp
src/Model/Model_FiltersFactory.h
src/ModelAPI/ModelAPI_Filter.h
src/ModelAPI/ModelAPI_FiltersFactory.h
src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp
src/PythonAPI/model/tests/tests.py

index 99493128761b5e7e8812f955adc00c1d619c711f..75ebaf3ef5dfa1229ce4fb41c6152f153bb12313 100644 (file)
@@ -33,6 +33,7 @@ SET(PROJECT_HEADERS
     FiltersPlugin_OnPlaneSide.h
     FiltersPlugin_OppositeToEdge.h
     FiltersPlugin_RelativeToSolid.h
+    FiltersPlugin_ExternalFaces.h
 )
 
 SET(PROJECT_SOURCES
@@ -47,6 +48,7 @@ SET(PROJECT_SOURCES
     FiltersPlugin_OnPlaneSide.cpp
     FiltersPlugin_OppositeToEdge.cpp
     FiltersPlugin_RelativeToSolid.cpp
+    FiltersPlugin_ExternalFaces.cpp
 )
 
 SET(PROJECT_LIBRARIES
@@ -94,6 +96,7 @@ ADD_UNIT_TESTS(
   TestFilter_RelativeToSolid_NotOn.py
   TestFilter_RelativeToSolid_InAndOn.py
   TestFilter_RelativeToSolid_OutAndOn.py
+  TestFilter_ExternalFaces.py
   TestFilter_HorizontalFaces.py
   TestFilter_VerticalFaces.py
 )
index b03093e0ff05dc3454cbb66bee49878ce17ae7a5..6a1553acedb9a7a4997630b09bc60be439d2de0c 100644 (file)
@@ -26,8 +26,8 @@ bool FiltersPlugin_BelongsTo::isSupported(GeomAPI_Shape::ShapeType theType) cons
   return true;
 }
 
-bool FiltersPlugin_BelongsTo::isOk(const GeomShapePtr& theShape,
-  const ModelAPI_FiltersArgs& theArgs) const
+bool FiltersPlugin_BelongsTo::isOk(const GeomShapePtr& theShape, const ResultPtr&,
+                                   const ModelAPI_FiltersArgs& theArgs) const
 {
   AttributePtr aAttr = theArgs.argument("BelongsTo");
   AttributeSelectionListPtr aList =
index 7e0b6bb6ee12e1f7cf598e53240a28deb0d7d5ca..ebe4e6177089ed900701d6853fd1b600f9e94f78 100644 (file)
@@ -44,8 +44,9 @@ public:
   /// This method should contain the filter logic. It returns true if the given shape
   /// is accepted by the filter.
   /// \param theShape the given shape
-  virtual bool isOk(const GeomShapePtr& theShape,
-    const ModelAPI_FiltersArgs& theArgs) const override;
+  /// \param theArgs arguments of the filter
+  virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
+                    const ModelAPI_FiltersArgs& theArgs) const override;
 
   /// Returns XML string which represents GUI of the filter
   virtual std::string xmlRepresentation() const override;
diff --git a/src/FiltersPlugin/FiltersPlugin_ExternalFaces.cpp b/src/FiltersPlugin/FiltersPlugin_ExternalFaces.cpp
new file mode 100644 (file)
index 0000000..1ad3225
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "FiltersPlugin_ExternalFaces.h"
+
+#include <ModelAPI_Tools.h>
+
+#include <TopExp.hxx>
+#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
+
+bool FiltersPlugin_ExternalFaces::isSupported(GeomAPI_Shape::ShapeType theType) const
+{
+  return theType == GeomAPI_Shape::FACE;
+}
+
+bool FiltersPlugin_ExternalFaces::isOk(const GeomShapePtr& theShape,
+                                       const ResultPtr& theResult,
+                                       const ModelAPI_FiltersArgs& theArgs) const
+{
+  if (!theShape->isFace())
+    return false;
+
+  ResultBodyPtr anOwner = ModelAPI_Tools::bodyOwner(theResult, true);
+  if (!anOwner) {
+    anOwner = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+    if (!anOwner)
+      return false;
+  }
+  GeomShapePtr anOwnerShape = anOwner->shape();
+
+  TopTools_IndexedDataMapOfShapeListOfShape aMapFS;
+  TopExp::MapShapesAndUniqueAncestors(anOwnerShape->impl<TopoDS_Shape>(),
+                                      TopAbs_FACE, TopAbs_SOLID, aMapFS);
+  const TopTools_ListOfShape& aSolids = aMapFS.FindFromKey(theShape->impl<TopoDS_Shape>());
+  return aSolids.Extent() <= 1;
+}
diff --git a/src/FiltersPlugin/FiltersPlugin_ExternalFaces.h b/src/FiltersPlugin/FiltersPlugin_ExternalFaces.h
new file mode 100644 (file)
index 0000000..e34e442
--- /dev/null
@@ -0,0 +1,54 @@
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef FILTERSPLUGIN_EXTERNALFACES_H_
+#define FILTERSPLUGIN_EXTERNALFACES_H_
+
+#include "FiltersPlugin.h"
+
+#include <ModelAPI_Filter.h>
+
+/**\class FiltersPlugin_ExternalFaces
+* \ingroup DataModel
+* \brief Filter for faces not shared between solids in compsolid.
+*/
+class FiltersPlugin_ExternalFaces : public ModelAPI_Filter
+{
+public:
+  FiltersPlugin_ExternalFaces() : ModelAPI_Filter() {}
+
+  virtual const std::string& name() const {
+    static const std::string kName("External faces");
+    return kName;
+  }
+
+  /// Returns true for any type because it supports all selection types
+  virtual bool isSupported(GeomAPI_Shape::ShapeType theType) const override;
+
+  /// This method should contain the filter logic. It returns true if the given shape
+  /// is accepted by the filter.
+  /// \param theShape the given shape
+  /// \param theResult parent result of the shape to be checked
+  /// \param theArgs arguments of the filter
+  virtual bool isOk(const GeomShapePtr& theShape,
+                    const ResultPtr& theResult,
+                    const ModelAPI_FiltersArgs& theArgs) const override;
+};
+
+#endif
\ No newline at end of file
index 6bda6a6cfcc802383b80103191c133f28fdbbeea..ce1ec8b3f090779e97a7bca2786afcb0a34d1ecb 100644 (file)
@@ -27,8 +27,8 @@ bool FiltersPlugin_HorizontalFace::isSupported(GeomAPI_Shape::ShapeType theType)
   return theType == GeomAPI_Shape::FACE;
 }
 
-bool FiltersPlugin_HorizontalFace::isOk(
-  const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const
+bool FiltersPlugin_HorizontalFace::isOk(const GeomShapePtr& theShape, const ResultPtr&,
+                                        const ModelAPI_FiltersArgs& theArgs) const
 {
   if (!theShape->isFace() || !theShape->isPlanar())
     return false;
index aa3a3168f874cc3f615726676a1fb53cc62dd389..8417e0f27f21ff6925908b592e660353884fec8e 100644 (file)
@@ -44,8 +44,9 @@ public:
   /// This method should contain the filter logic. It returns true if the given shape
   /// is accepted by the filter.
   /// \param theShape the given shape
-  virtual bool isOk(
-    const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const override;
+  /// \param theArgs arguments of the filter
+  virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
+                    const ModelAPI_FiltersArgs& theArgs) const override;
 };
 
 #endif
\ No newline at end of file
index e62dba49c31cf3f72e5fa7e4515ed94a4d324b0a..44d9ff4017a9dd984409b1a8931a63d7e1dc1e92 100644 (file)
@@ -26,8 +26,8 @@ bool FiltersPlugin_OnGeometry::isSupported(GeomAPI_Shape::ShapeType theType) con
   return theType == GeomAPI_Shape::EDGE || theType == GeomAPI_Shape::FACE;
 }
 
-bool FiltersPlugin_OnGeometry::isOk(const GeomShapePtr& theShape,
-  const ModelAPI_FiltersArgs& theArgs) const
+bool FiltersPlugin_OnGeometry::isOk(const GeomShapePtr& theShape, const ResultPtr&,
+                                    const ModelAPI_FiltersArgs& theArgs) const
 {
   AttributePtr aAttr = theArgs.argument("OnGeometry");
   AttributeSelectionListPtr aList =
index 98d197aa45f89000f801a8092b79d0c35ac591e0..c90e5dd87076b8aca8162a3587a30832e08df84b 100644 (file)
@@ -44,7 +44,8 @@ public:
   /// This method should contain the filter logic. It returns true if the given shape
   /// is accepted by the filter.
   /// \param theShape the given shape
-  virtual bool isOk(const GeomShapePtr& theShape,
+  /// \param theArgs arguments of the filter
+  virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
                     const ModelAPI_FiltersArgs& theArgs) const override;
 
   /// Returns XML string which represents GUI of the filter
index 092321eaf80e23b9c2bea2a4ca927df85412420d..d2e4384320237f5a635ad7d221fe6b2bfb27b53d 100644 (file)
@@ -46,7 +46,7 @@ bool FiltersPlugin_OnLine::isSupported(GeomAPI_Shape::ShapeType theType) const
   return theType == GeomAPI_Shape::EDGE || theType == GeomAPI_Shape::VERTEX;
 }
 
-bool FiltersPlugin_OnLine::isOk(const GeomShapePtr& theShape,
+bool FiltersPlugin_OnLine::isOk(const GeomShapePtr& theShape, const ResultPtr&,
                                 const ModelAPI_FiltersArgs& theArgs) const
 {
   AttributePtr aAttr = theArgs.argument("OnLine");
index 8678159d69dc48a38d7652b642ae22dbda95cd45..b609bd940ae0697d0660021b8ad1393ab1705941 100644 (file)
@@ -44,7 +44,8 @@ public:
   /// This method should contain the filter logic. It returns true if the given shape
   /// is accepted by the filter.
   /// \param theShape the given shape
-  virtual bool isOk(const GeomShapePtr& theShape,
+  /// \param theArgs arguments of the filter
+  virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
                     const ModelAPI_FiltersArgs& theArgs) const override;
 
   /// Returns XML string which represents GUI of the filter
index c86a33474cade21da6c83288d94bb40677f3266e..f7b4a07a660cd0e0120291eb7562fe7125b77326 100644 (file)
@@ -52,8 +52,8 @@ GeomPlanePtr getPlane(AttributeSelectionPtr theAttr)
   return aFace->getPlane();
 }
 
-bool FiltersPlugin_OnPlane::isOk(const GeomShapePtr& theShape,
-  const ModelAPI_FiltersArgs& theArgs) const
+bool FiltersPlugin_OnPlane::isOk(const GeomShapePtr& theShape, const ResultPtr&,
+                                 const ModelAPI_FiltersArgs& theArgs) const
 {
   AttributePtr aAttr = theArgs.argument("OnPlane");
   AttributeSelectionListPtr aList =
index e496d9f42a95bbedd3b51d4c2ec7610e6355f115..62fccd1fc7bb4f56b8dee528054ef5eb20b3a9bf 100644 (file)
@@ -44,8 +44,9 @@ public:
   /// This method should contain the filter logic. It returns true if the given shape
   /// is accepted by the filter.
   /// \param theShape the given shape
-  virtual bool isOk(const GeomShapePtr& theShape,
-    const ModelAPI_FiltersArgs& theArgs) const override;
+  /// \param theArgs arguments of the filter
+  virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
+                    const ModelAPI_FiltersArgs& theArgs) const override;
 
   /// Returns XML string which represents GUI of the filter
   virtual std::string xmlRepresentation() const override;
index b19a98ec5898d876ba6d233332d1d20ca7b395c7..1d77e6b742e1d879536414db15d6ee7f951e93fc 100644 (file)
@@ -32,7 +32,7 @@ bool FiltersPlugin_OnPlaneSide::isSupported(GeomAPI_Shape::ShapeType theType) co
   return true;
 }
 
-bool FiltersPlugin_OnPlaneSide::isOk(const GeomShapePtr& theShape,
+bool FiltersPlugin_OnPlaneSide::isOk(const GeomShapePtr& theShape, const ResultPtr&,
                                      const ModelAPI_FiltersArgs& theArgs) const
 {
   static const double THE_TOLERANCE = 1.e-7;
index ef3f4a88a033212330203b7a657ed49cb1e0bd4d..9939e45888c5b51fbdc2770abca5ea8b5bc3e3bc 100644 (file)
@@ -44,7 +44,8 @@ public:
   /// This method should contain the filter logic. It returns true if the given shape
   /// is accepted by the filter.
   /// \param theShape the given shape
-  virtual bool isOk(const GeomShapePtr& theShape,
+  /// \param theArgs arguments of the filter
+  virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
                     const ModelAPI_FiltersArgs& theArgs) const override;
 
   /// Returns XML string which represents GUI of the filter
index 35d1a42c6c94226ea208503e1a55a4ac986358d5..b2cc86a6c85e17f649f7cec75aa6425ccfc14dbd 100644 (file)
@@ -117,7 +117,7 @@ bool FiltersPlugin_OppositeToEdge::isSupported(GeomAPI_Shape::ShapeType theType)
   return theType == GeomAPI_Shape::EDGE;
 }
 
-bool FiltersPlugin_OppositeToEdge::isOk(const GeomShapePtr& theShape,
+bool FiltersPlugin_OppositeToEdge::isOk(const GeomShapePtr& theShape, const ResultPtr&,
                                         const ModelAPI_FiltersArgs& theArgs) const
 {
   AttributePtr aAttr = theArgs.argument("OppositeToEdge");
index 9db4458f907600afa87256d3da292aba59fa85b9..5d745d3ab605e094d8dbfdd060fe8a0c4804fc5d 100644 (file)
@@ -49,7 +49,8 @@ public:
   /// This method should contain the filter logic. It returns true if the given shape
   /// is accepted by the filter.
   /// \param theShape the given shape
-  virtual bool isOk(const GeomShapePtr& theShape,
+  /// \param theArgs arguments of the filter
+  virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
                     const ModelAPI_FiltersArgs& theArgs) const override;
 
   /// Returns XML string which represents GUI of the filter
index a0181d6bf13d874e783f49eca1358d545986d290..2538b8f26939c4e195e21be9bb81184ec84b9358 100644 (file)
@@ -28,6 +28,7 @@
 #include "FiltersPlugin_OnPlaneSide.h"
 #include "FiltersPlugin_OppositeToEdge.h"
 #include "FiltersPlugin_RelativeToSolid.h"
+#include "FiltersPlugin_ExternalFaces.h"
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_FiltersFactory.h>
@@ -49,6 +50,7 @@ FiltersPlugin_Plugin::FiltersPlugin_Plugin()
   aFactory->registerFilter("OnPlaneSide", new FiltersPlugin_OnPlaneSide);
   aFactory->registerFilter("OppositeToEdge", new FiltersPlugin_OppositeToEdge);
   aFactory->registerFilter("RelativeToSolid", new FiltersPlugin_RelativeToSolid);
+  aFactory->registerFilter("ExternalFaces", new FiltersPlugin_ExternalFaces);
 
   ModelAPI_Session::get()->registerPlugin(this);
 }
index 512f66563ec37c1960a8e3886ba8d60c6d2e9a12..df1559485e3b9ebf9b3995d2ba23995967bf8719 100644 (file)
@@ -32,7 +32,7 @@ bool FiltersPlugin_RelativeToSolid::isSupported(GeomAPI_Shape::ShapeType theType
   return true;
 }
 
-bool FiltersPlugin_RelativeToSolid::isOk(const GeomShapePtr& theShape,
+bool FiltersPlugin_RelativeToSolid::isOk(const GeomShapePtr& theShape, const ResultPtr&,
                                          const ModelAPI_FiltersArgs& theArgs) const
 {
   AttributePtr anAttr = theArgs.argument("Solid");
index 61d0b59007f480873b6dfd95940cc028c0238634..821b9a7ec243b649f19c9459f05889c368efc0c4 100644 (file)
@@ -44,7 +44,8 @@ public:
   /// This method should contain the filter logic. It returns true if the given shape
   /// is accepted by the filter.
   /// \param theShape the given shape
-  virtual bool isOk(const GeomShapePtr& theShape,
+  /// \param theArgs arguments of the filter
+  virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
                     const ModelAPI_FiltersArgs& theArgs) const override;
 
   /// Returns XML string which represents GUI of the filter
index 56ab8ff2ba9214594e6aa5b6269b65f73896ad4d..9d1883126d501924c7a2b3dcaa086018bc924c39 100644 (file)
@@ -32,8 +32,8 @@ bool FiltersPlugin_VerticalFace::isSupported(GeomAPI_Shape::ShapeType theType) c
   return theType == GeomAPI_Shape::FACE;
 }
 
-bool FiltersPlugin_VerticalFace::isOk(
-  const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const
+bool FiltersPlugin_VerticalFace::isOk(const GeomShapePtr& theShape, const ResultPtr&,
+                                      const ModelAPI_FiltersArgs& theArgs) const
 {
   if (!theShape->isFace() || !theShape->isPlanar())
     return false;
index e920f4ced60c64ff43bd9c4b470135382c780454..df733d3c0cd8961f4a379838157648fa054b550e 100644 (file)
@@ -44,8 +44,9 @@ public:
   /// This method should contain the filter logic. It returns true if the given shape
   /// is accepted by the filter.
   /// \param theShape the given shape
-  virtual bool isOk(
-    const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const override;
+  /// \param theArgs arguments of the filter
+  virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
+                    const ModelAPI_FiltersArgs& theArgs) const override;
 };
 
 #endif
\ No newline at end of file
diff --git a/src/FiltersPlugin/Test/TestFilter_ExternalFaces.py b/src/FiltersPlugin/Test/TestFilter_ExternalFaces.py
new file mode 100644 (file)
index 0000000..58f2145
--- /dev/null
@@ -0,0 +1,76 @@
+# Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+from salome.shaper import model
+from GeomAPI import *
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Left"), model.selection("FACE", "Box_1_1/Right"))
+Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_1_1"), model.selection("FACE", "Plane_1")], 20190506)
+Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
+Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1")], model.selection("EDGE", "PartSet/OX"), 20)
+Filters = model.filters(Part_1_doc, [model.addFilter(name = "ExternalFaces")])
+model.end()
+
+Reference = {}
+# Faces of the box
+ResultBox_1 = Partition_1.result().resultSubShapePair()[0]
+exp = GeomAPI_ShapeExplorer(ResultBox_1.shape(), GeomAPI_Shape.FACE)
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = False; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = False; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+# Faces of the cylinder
+ResultCylinder_1 = Translation_1.result().resultSubShapePair()[0]
+exp = GeomAPI_ShapeExplorer(ResultCylinder_1.shape(), GeomAPI_Shape.FACE)
+while exp.more():
+  Reference[model.selection(ResultCylinder_1, exp.current())] = True
+  exp.next()
+model.checkFilter(Part_1_doc, model, Filters, Reference)
+
+Reference = {
+    model.selection("FACE", "Partition_1_1_2/Modified_Face&Box_1_1/Back"): True,
+    model.selection("FACE", "Partition_1_1_2/Modified_Face&Plane_1/Plane_1"): True,
+    model.selection("FACE", "Partition_1_1_2/Modified_Face&Box_1_1/Bottom"): True,
+    model.selection("FACE", "Box_1_1/Right"): True,
+    model.selection("FACE", "Partition_1_1_2/Modified_Face&Box_1_1/Top"): True,
+    model.selection("FACE", "Partition_1_1_2/Modified_Face&Box_1_1/Front"): True,
+    model.selection("FACE", "Partition_1_1_1/Modified_Face&Box_1_1/Back"): True,
+    model.selection("FACE", "Box_1_1/Left"): True,
+    model.selection("FACE", "Partition_1_1_1/Modified_Face&Box_1_1/Bottom"): True,
+    model.selection("FACE", "Partition_1_1_1/Modified_Face&Plane_1/Plane_1"): True,
+    model.selection("FACE", "Partition_1_1_1/Modified_Face&Box_1_1/Top"): True,
+    model.selection("FACE", "Partition_1_1_1/Modified_Face&Box_1_1/Front"): True,
+    model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_1"): True,
+    model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_2"): True,
+    model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_3"): True,
+}
+model.checkFilter(Part_1_doc, model, Filters, Reference)
index f0a7c92422aae575c971ba5b7dbc4c8554bbf970..f84febdfcb599a7d476ef74903c06387a630056a 100644 (file)
@@ -40,7 +40,9 @@ struct FilterArgs {
   std::string myFilterID;
 };
 
-bool Model_FiltersFactory::isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape)
+bool Model_FiltersFactory::isValid(FeaturePtr theFiltersFeature,
+                                   ResultPtr theResult,
+                                   GeomShapePtr theShape)
 {
   // check that the shape type corresponds to the attribute list type
   AttributePtr aBase =
@@ -84,7 +86,7 @@ bool Model_FiltersFactory::isValid(FeaturePtr theFiltersFeature, GeomShapePtr th
   std::list<FilterArgs>::iterator aFilter = aFilters.begin();
   for(; aFilter != aFilters.end(); aFilter++) {
     anArgs.setFilter(aFilter->myFilterID);
-    bool aResult = aFilter->myFilter->isOk(theShape, anArgs);
+    bool aResult = aFilter->myFilter->isOk(theShape, theResult, anArgs);
     if (aFilter->myReverse)
       aResult = !aResult;
     if (!aResult) // one filter is failed => exit immediately
index 3672516f83fc75720fd155f1cc6193123e385eec..b52078651e86631d93a7a8b33d0397e4f65fab6e 100644 (file)
@@ -41,9 +41,11 @@ public:
 
   /// Returns true if all filters of the Filters feature are ok for the Shape (taking into account
   /// the Reversed states).
-  /// \param theFiltersFeature feature that contains all information about the filters
+  /// \param theResult parent result of the shape to check
   /// \param theShape the checked shape
-  virtual bool isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape);
+  virtual bool isValid(FeaturePtr theFiltersFeature,
+                       ResultPtr theResult,
+                       GeomShapePtr theShape);
 
   /// Returns the filters that support the given shape type
   virtual std::list<FilterPtr> filters(GeomAPI_Shape::ShapeType theType);
index 0e5d5b9dfa232f831cbef219ee8f4b769688884b..0469801fe5fbb3fd9b8d85a7ad2d2a4b88ebd6fb 100644 (file)
@@ -21,6 +21,7 @@
 #define ModelAPI_Filter_H_
 
 #include "ModelAPI_FiltersArgs.h"
+#include "ModelAPI_ResultBody.h"
 
 #include <GeomAPI_Shape.h>
 
@@ -41,7 +42,11 @@ public:
   /// This method should contain the filter logic. It returns true if the given shape
   /// is accepted by the filter.
   /// \param theShape the given shape
-  virtual bool isOk(const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const = 0;
+  /// \param theResult parent result of the shape to be checked
+  /// \param theArgs arguments of the filter
+  virtual bool isOk(const GeomShapePtr& theShape,
+                    const ResultPtr& theResult,
+                    const ModelAPI_FiltersArgs& theArgs) const = 0;
 
   /// Returns XML string which represents GUI of the filter
   /// By default it returns nothing (no GUI)
index bc24d0d3eee8f9841958c00fb695b431654be199..6e5e7a3e799c17436ff3a25fedce64906fcf4e28 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "ModelAPI_Feature.h"
 #include "ModelAPI_Filter.h"
+#include "ModelAPI_ResultBody.h"
 
 #include <GeomAPI_Shape.h>
 
@@ -41,8 +42,11 @@ public:
   /// Returns true if all filters of the Filters feature are ok for the Shape (taking into account
   /// the Reversed states).
   /// \param theFiltersFeature feature that contains all information about the filters
+  /// \param theResult parent result of the shape to check
   /// \param theShape the checked shape
-  virtual bool isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape) = 0;
+  virtual bool isValid(FeaturePtr theFiltersFeature,
+                       ResultPtr theResult,
+                       GeomShapePtr theShape) = 0;
 
   /// Returns the filters that support the given shape type
   virtual std::list<FilterPtr> filters(GeomAPI_Shape::ShapeType theType) = 0;
index 0abdd259c940e39d80340c12c3fa60fe00b72cdd..2b7763ce2ef6a8aed7a8eb2a3c7ec10282772f8b 100644 (file)
@@ -456,7 +456,7 @@ void ModuleBase_WidgetSelectionFilter::onSelect()
       if (!alreadyThere.Add(aTShape))
         continue;
       static SessionPtr aSession = ModelAPI_Session::get();
-      bool isValid = aSession->filters()->isValid(myFeature, aShape);
+      bool isValid = aSession->filters()->isValid(myFeature, aBody, aShape);
       if (isValid) {
         aBuilder.Add(aComp, aTShape);
         ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj, aShape));
index 687d2e1bb0c256440fbf26ab2d73c0791ad61cf4..f80fd84f4b138bd23cb8294939980c48936b9bc1 100644 (file)
@@ -343,19 +343,21 @@ def checkFilter(thePartDoc, theModel, theFilter, theShapesList):
     shapeName = ""
     shapeType = "UNKNOWN"
     if sel.variantType() == ModelHighAPI_Selection.VT_ResultSubShapePair:
+      parent = sel.resultSubShapePair()[0]
       shape = sel.resultSubShapePair()[1]
       if shape.isNull():
         shape = sel.resultSubShapePair()[0].shape()
-        shapeName = sel.name()
-        shapeType = shape.shapeTypeStr()
+      shapeName = sel.name()
+      shapeType = shape.shapeTypeStr()
     else:
       needUndo = True
       theModel.begin()
       subShapeFeature = createSubShape(thePartDoc, theModel, sel)
       theModel.end()
+      parent = subShapeFeature.results()[0].resultSubShapePair()[0]
       shape = subShapeFeature.results()[0].resultSubShapePair()[0].shape()
       shapeType = sel.typeSubShapeNamePair()[0]
       shapeName = sel.typeSubShapeNamePair()[1]
-    assert aFiltersFactory.isValid(theFilter.feature(), shape) == res, "Filter result for {} \"{}\" incorrect. Expected {}.".format(shapeType, shapeName, res)
+    assert aFiltersFactory.isValid(theFilter.feature(), parent, shape) == res, "Filter result for {} \"{}\" incorrect. Expected {}.".format(shapeType, shapeName, res)
     if needUndo:
       theModel.undo()