Salome HOME
4d393252f5b83346ca5b35780b488e42acff2eda
[modules/shaper.git] / src / FiltersPlugin / Test / TestFilters_Supported.py
1 # Copyright (C) 2014-2021  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from salome.shaper import model
21 from ModelAPI import *
22 from GeomAPI import *
23 from ModelHighAPI import *
24
25 # Whole list of supported filters
26 FILTER_BELONGS_TO = "BelongsTo"
27 FILTER_ON_PLANE = "OnPlane"
28 FILTER_ON_LINE = "OnLine"
29 FILTER_ON_GEOMETRY = "OnGeometry"
30 FILTER_ON_PLANE_SIDE = "OnPlaneSide"
31 FILTER_OPPOSITE_TO_EDGE = "OppositeToEdge"
32 FILTER_RELATIVE_TO_SOLID = "RelativeToSolid"
33 FILTER_EXTERNAL_FACES = "ExternalFaces"
34 FILTER_HORIZONTAL_FACES = "HorizontalFaces"
35 FILTER_VERTICAL_FACES = "VerticalFaces"
36 FILTER_CONNECTED_FACES = "TopoConnectedFaces"
37
38 # Reference data (supported filters) for each type of shape
39 Reference = {
40     GeomAPI_Shape.VERTEX : [FILTER_BELONGS_TO, FILTER_ON_PLANE, FILTER_ON_LINE, FILTER_ON_PLANE_SIDE, FILTER_RELATIVE_TO_SOLID],
41     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],
42     GeomAPI_Shape.WIRE   : [FILTER_BELONGS_TO, FILTER_ON_PLANE, FILTER_ON_PLANE_SIDE, FILTER_RELATIVE_TO_SOLID],
43     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],
44     GeomAPI_Shape.SHELL  : [FILTER_BELONGS_TO, FILTER_ON_PLANE, FILTER_ON_PLANE_SIDE, FILTER_RELATIVE_TO_SOLID],
45     GeomAPI_Shape.SOLID  : [FILTER_BELONGS_TO, FILTER_ON_PLANE_SIDE],
46 }
47
48 model.begin()
49 partSet = model.moduleDocument()
50 Part_1 = model.addPart(partSet)
51 Part_1_doc = Part_1.document()
52 # load 'Filters' plugin
53 model.filters(Part_1_doc, [])
54
55 filtersFactory = ModelAPI_Session.get().filters()
56 for type, res in Reference.items():
57   filtersList = filtersFactory.filters(type)
58   for filter in filtersList:
59     filterID = filtersFactory.id(filter)
60     assert(filterID in res), "Filter \"{}\" is not applicable for {}".format(filterID, strByShapeType(type))
61     res.remove(filterID)
62   assert(len(res) == 0), "There are more filters {}, which should be supported for {}".format(res, strByShapeType(type))
63 model.end()