Salome HOME
updated copyright message
[modules/shaper.git] / src / FiltersPlugin / Test / TestFilters_Select.py
1 # Copyright (C) 2014-2023  CEA, EDF
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 import math
25
26 model.begin()
27 partSet = model.moduleDocument()
28 Part_1 = model.addPart(partSet)
29 Part_1_doc = Part_1.document()
30
31 ### Create Box
32 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
33 model.do()
34
35 ### Create Filters
36 filter_1 = model.addFilter(name = "OnPlane",
37                            args = [model.selection("FACE", "Box_1_1/Left")])
38
39 filter_2 = model.addFilter(name = "OnPlane",
40                            args = [model.selection("FACE", "Box_1_1/Top")])
41
42 filters = model.filters(Part_1_doc, [filter_1, filter_2])
43
44 ### Select all (one) suitable edges
45 selected_edges = filters.select("Edges")
46
47 group_1 = model.addGroup(Part_1_doc, "Edges", selected_edges)
48 assert(group_1.feature().results().size() == 1)
49
50 # Check the selected edge
51 aResult = group_1.results()[0].resultSubShapePair()[0]
52 aShape = aResult.shape()
53 aShapeExplorer = GeomAPI_ShapeExplorer(aShape, GeomAPI_Shape.EDGE)
54 assert(aShapeExplorer.more())
55 anEdge = aShapeExplorer.current()
56 assert(anEdge.edge().isLine() and math.fabs(anEdge.edge().line().direction().x() - 1.0) < 1.e-7)
57 aLoc = anEdge.edge().line().location()
58 assert(math.fabs(aLoc.x()) < 1.e-7)
59 assert(math.fabs(aLoc.y()) < 1.e-7)
60 assert(math.fabs(aLoc.z() - 10.0) < 1.e-7)
61 aShapeExplorer.next()
62 assert(not aShapeExplorer.more())
63
64 model.end()