Salome HOME
1093faace5dffd5ae749113f4e7e1b3c4c7eb8bf
[modules/shaper.git] / src / CollectionPlugin / Test / TestGroupMove05.py
1 # Copyright (C) 2014-2023  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 # Test of deep nested results history.
21 # Faces and edges of a box has been collected to groups. After that, the box has been copied.
22 # Check that groups moved to the end contain corresponding results.
23
24 from salome.shaper import model
25
26 model.begin()
27 partSet = model.moduleDocument()
28 Part_1 = model.addPart(partSet)
29 Part_1_doc = Part_1.document()
30 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
31 Group_1 = model.addGroup(Part_1_doc, [model.selection("SOLID", "Box_1_1")])
32 Group_2_objects = [model.selection("FACE", "Box_1_1/Back"), model.selection("FACE", "Box_1_1/Top"), model.selection("FACE", "Box_1_1/Right"), model.selection("FACE", "Box_1_1/Left"), model.selection("FACE", "Box_1_1/Bottom"), model.selection("FACE", "Box_1_1/Front")]
33 Group_2 = model.addGroup(Part_1_doc, Group_2_objects)
34 Group_3_objects = [model.selection("EDGE", "[Box_1_1/Back][Box_1_1/Bottom]"), model.selection("EDGE", "[Box_1_1/Back][Box_1_1/Right]"), model.selection("EDGE", "[Box_1_1/Back][Box_1_1/Left]"), model.selection("EDGE", "[Box_1_1/Back][Box_1_1/Top]"), model.selection("EDGE", "[Box_1_1/Right][Box_1_1/Bottom]"), model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]"), model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Bottom]"), model.selection("EDGE", "[Box_1_1/Right][Box_1_1/Top]"), model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Bottom]"), model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Left]"), model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Right]"), model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Top]")]
35 Group_3 = model.addGroup(Part_1_doc, Group_3_objects)
36 LinearCopy_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 15, 2)
37 model.do()
38 # move groups to the end
39 Part_1_doc.moveFeature(Group_1.feature(), LinearCopy_1.feature())
40 Part_1_doc.moveFeature(Group_2.feature(), Group_1.feature())
41 Part_1_doc.moveFeature(Group_3.feature(), Group_2.feature())
42 model.end()
43
44 from ModelAPI import *
45
46 aFactory = ModelAPI_Session.get().validators()
47 # check group 1: all solids in compound should be selected
48 selectionList = Group_1.feature().selectionList("group_list")
49 assert(selectionList.size() == 2)
50 assert(aFactory.validate(Group_1.feature()))
51 # check group 2: number of faces is multiplied twice than original
52 selectionList = Group_2.feature().selectionList("group_list")
53 assert(selectionList.size() == 12)
54 assert(aFactory.validate(Group_2.feature()))
55 # check group 3: number of edges is multiplied twice than original
56 selectionList = Group_3.feature().selectionList("group_list")
57 assert(selectionList.size() == 24)
58 assert(aFactory.validate(Group_3.feature()))
59
60 model.begin()
61 LinearCopy_2 = model.addMultiTranslation(Part_1_doc, [model.selection("COMPOUND", "LinearCopy_1_1")], model.selection("EDGE", "PartSet/OY"), 15, 2, model.selection("EDGE", "PartSet/OZ"), 15, 2)
62 # move groups to the end
63 Part_1_doc.moveFeature(Group_1.feature(), LinearCopy_2.feature())
64 Part_1_doc.moveFeature(Group_2.feature(), Group_1.feature())
65 Part_1_doc.moveFeature(Group_3.feature(), Group_2.feature())
66 model.end()
67
68 # check group 1: all solids in compound should be selected
69 selectionList = Group_1.feature().selectionList("group_list")
70 assert(selectionList.size() == 8)
71 assert(aFactory.validate(Group_1.feature()))
72 # check group 2: number of faces is multiplied twice than original
73 selectionList = Group_2.feature().selectionList("group_list")
74 assert(selectionList.size() == 48)
75 assert(aFactory.validate(Group_2.feature()))
76 # check group 3: number of edges is multiplied twice than original
77 selectionList = Group_3.feature().selectionList("group_list")
78 assert(selectionList.size() == 96)
79 assert(aFactory.validate(Group_3.feature()))
80
81 model.begin()
82 AngularCopy_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "LinearCopy_2_1_1_1"), model.selection("SOLID", "LinearCopy_2_1_1_2")], model.selection("EDGE", "PartSet/OZ"), 2)
83 # move groups to the end
84 Part_1_doc.moveFeature(Group_1.feature(), AngularCopy_1.feature())
85 Part_1_doc.moveFeature(Group_2.feature(), Group_1.feature())
86 Part_1_doc.moveFeature(Group_3.feature(), Group_2.feature())
87 model.end()
88
89 # check group 1: all solids in compound should be selected
90 selectionList = Group_1.feature().selectionList("group_list")
91 assert(selectionList.size() == 4)
92 assert(aFactory.validate(Group_1.feature()))
93 # check group 2: number of faces is multiplied twice than original
94 selectionList = Group_2.feature().selectionList("group_list")
95 assert(selectionList.size() == 24)
96 assert(aFactory.validate(Group_2.feature()))
97 # check group 3: number of edges is multiplied twice than original
98 selectionList = Group_3.feature().selectionList("group_list")
99 assert(selectionList.size() == 48)
100 assert(aFactory.validate(Group_3.feature()))
101
102 assert(model.checkPythonDump())