Salome HOME
More tests to improve coverage of filters
authorazv <azv@opencascade.com>
Wed, 10 Jul 2019 11:45:11 +0000 (14:45 +0300)
committerazv <azv@opencascade.com>
Wed, 10 Jul 2019 11:45:11 +0000 (14:45 +0300)
src/FiltersPlugin/CMakeLists.txt
src/FiltersPlugin/Test/TestFilters_Supported.py [new file with mode: 0644]
src/FiltersPlugin/Test/TestFilters_Xml.py [new file with mode: 0644]
src/ModelAPI/ModelAPI.i

index bf09153ad3438f9c52012586a2ef134f5319a1ae..ab179ee4855bf30430f054d20f53ce0c4ee003fe 100644 (file)
@@ -98,6 +98,8 @@ ADD_UNIT_TESTS(
   TestFilters.py
   TestFilters_Mixed1.py
   TestFilters_Mixed2.py
+  TestFilters_Supported.py
+  TestFilters_Xml.py
   TestFilter_BelongsTo.py
   TestFilter_BelongsTo_Exclude.py
   TestFilter_OnPlane.py
diff --git a/src/FiltersPlugin/Test/TestFilters_Supported.py b/src/FiltersPlugin/Test/TestFilters_Supported.py
new file mode 100644 (file)
index 0000000..418a687
--- /dev/null
@@ -0,0 +1,63 @@
+# 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 ModelAPI import *
+from GeomAPI import *
+from ModelHighAPI import *
+
+# Whole list of supported filters
+FILTER_BELONGS_TO = "BelongsTo"
+FILTER_ON_PLANE = "OnPlane"
+FILTER_ON_LINE = "OnLine"
+FILTER_ON_GEOMETRY = "OnGeometry"
+FILTER_ON_PLANE_SIDE = "OnPlaneSide"
+FILTER_OPPOSITE_TO_EDGE = "OppositeToEdge"
+FILTER_RELATIVE_TO_SOLID = "RelativeToSolid"
+FILTER_EXTERNAL_FACES = "ExternalFaces"
+FILTER_HORIZONTAL_FACES = "HorizontalFaces"
+FILTER_VERTICAL_FACES = "VerticalFaces"
+FILTER_CONNECTED_FACES = "TopoConnectedFaces"
+
+# Reference data (supported filters) for each type of shape
+Reference = {
+    GeomAPI_Shape.VERTEX : [FILTER_BELONGS_TO, FILTER_ON_PLANE, FILTER_ON_LINE, FILTER_ON_PLANE_SIDE, FILTER_RELATIVE_TO_SOLID],
+    GeomAPI_Shape.EDGE   : [FILTER_BELONGS_TO, FILTER_ON_PLANE, FILTER_ON_LINE, FILTER_ON_GEOMETRY, FILTER_ON_PLANE_SIDE, FILTER_OPPOSITE_TO_EDGE, FILTER_RELATIVE_TO_SOLID],
+    GeomAPI_Shape.WIRE   : [FILTER_BELONGS_TO, FILTER_ON_PLANE, FILTER_ON_PLANE_SIDE, FILTER_RELATIVE_TO_SOLID],
+    GeomAPI_Shape.FACE   : [FILTER_BELONGS_TO, FILTER_ON_PLANE, FILTER_ON_GEOMETRY, FILTER_ON_PLANE_SIDE, FILTER_RELATIVE_TO_SOLID, FILTER_EXTERNAL_FACES, FILTER_HORIZONTAL_FACES, FILTER_VERTICAL_FACES, FILTER_CONNECTED_FACES],
+    GeomAPI_Shape.SHELL  : [FILTER_BELONGS_TO, FILTER_ON_PLANE, FILTER_ON_PLANE_SIDE, FILTER_RELATIVE_TO_SOLID],
+    GeomAPI_Shape.SOLID  : [FILTER_BELONGS_TO, FILTER_ON_PLANE_SIDE, FILTER_RELATIVE_TO_SOLID],
+}
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+# load 'Filters' plugin
+model.filters(Part_1_doc, [])
+
+filtersFactory = ModelAPI_Session.get().filters()
+for type, res in Reference.items():
+  filtersList = filtersFactory.filters(type)
+  for filter in filtersList:
+    filterID = filtersFactory.id(filter)
+    assert(filterID in res), "Filter \"{}\" is not applicable for {}".format(filterID, strByShapeType(type))
+    res.remove(filterID)
+  assert(len(res) == 0), "There are more filters {}, which should be supported for {}".format(res, strByShapeType(type))
+model.end()
diff --git a/src/FiltersPlugin/Test/TestFilters_Xml.py b/src/FiltersPlugin/Test/TestFilters_Xml.py
new file mode 100644 (file)
index 0000000..e53c4b6
--- /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
+#
+
+from salome.shaper import model
+from ModelAPI import *
+from GeomAPI import *
+from ModelHighAPI import *
+
+# Map filter and emptyness of its XML representation
+Reference = {
+    "BelongsTo"          : False,
+    "OnPlane"            : False,
+    "OnLine"             : False,
+    "OnGeometry"         : False,
+    "OnPlaneSide"        : False,
+    "OppositeToEdge"     : False,
+    "RelativeToSolid"    : False,
+    "ExternalFaces"      : True,
+    "HorizontalFaces"    : True,
+    "VerticalFaces"      : True,
+    "TopoConnectedFaces" : False,
+}
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+# load 'Filters' plugin
+model.filters(Part_1_doc, [])
+
+filtersFactory = ModelAPI_Session.get().filters()
+for id, res in Reference.items():
+  filter = filtersFactory.filter(id)
+  xmlString = filter.xmlRepresentation()
+  assert((len(xmlString) == 0) == res)
+model.end()
index 6f6a1f784d7dd4c7467105adc9f43c87b7a56916..dc76645c858400c27b191d35e251c9fc336ff224 100644 (file)
@@ -66,6 +66,7 @@
 %shared_ptr(ModelAPI_Feature)
 %shared_ptr(ModelAPI_CompositeFeature)
 %shared_ptr(ModelAPI_Data)
+%shared_ptr(ModelAPI_Filter)
 %shared_ptr(ModelAPI_FiltersFeature)
 %shared_ptr(ModelAPI_Folder)
 %shared_ptr(ModelAPI_Attribute)
 %template(FeatureList) std::list<std::shared_ptr<ModelAPI_Feature> >;
 %template(ResultList) std::list<std::shared_ptr<ModelAPI_Result> >;
 %template(DocumentList) std::list<std::shared_ptr<ModelAPI_Document> >;
+%template(FilterList) std::list<std::shared_ptr<ModelAPI_Filter> >;
 // std::set -> []
 %template(AttributeSet) std::set<std::shared_ptr<ModelAPI_Attribute> >;
 %template(FeatureSet) std::set<std::shared_ptr<ModelAPI_Feature> >;