Salome HOME
High level objects history implementation for Translation, Rotation and Scale features.
[modules/shaper.git] / src / CollectionPlugin / Test / TestGroupMove12.py
1 ## Copyright (C) 2014-2017  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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 # Test of deep nested results history. Translation operation.
22 # Check the groups of initial boxes moved to the end contain the corresponding
23 # results, but divided.
24
25 from salome.shaper import model
26 from ModelAPI import *
27
28 aFactory = ModelAPI_Session.get().validators()
29
30 def moveGroupsAndVerify(thePart, theLastFeature, theRefNumInGroups):
31     # move groups to the end
32     model.begin()
33     LastFeature = theLastFeature
34     for i in range(thePart.size("Groups")):
35         GroupFeature = thePart.feature(objectToResult(thePart.object("Groups", 0))) # move always the very first group
36         Part_1_doc.moveFeature(GroupFeature, LastFeature)
37         LastFeature = GroupFeature
38     model.end()
39
40     a = 0
41     for i in range(thePart.size("Groups")):
42         GroupFeature = thePart.feature(objectToResult(thePart.object("Groups", i)))
43         assert(aFactory.validate(GroupFeature))
44         assert(GroupFeature.selectionList("group_list").size() == theRefNumInGroups[a])
45         a = a + 1
46
47
48 model.begin()
49 partSet = model.moduleDocument()
50 Part_1 = model.addPart(partSet)
51 Part_1_doc = Part_1.document()
52 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
53 Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Left"), model.selection("FACE", "Box_1_1/Right"))
54 Plane_5 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Front"), model.selection("FACE", "Box_1_1/Back"))
55 Partition_1_objects = [model.selection("SOLID", "Box_1_1"), model.selection("FACE", "Plane_1"), model.selection("FACE", "Plane_2")]
56 Partition_1 = model.addPartition(Part_1_doc, Partition_1_objects)
57 Group_1 = model.addGroup(Part_1_doc, [model.selection("SOLID", "Partition_1_1_3"), model.selection("SOLID", "Partition_1_1_1")])
58 Group_2_objects = [model.selection("FACE", "Partition_1_1_4/Modified_Face&Box_1_1/Front"), model.selection("FACE", "Partition_1_1_4/Modified_Face&Box_1_1/Top"), model.selection("FACE", "Partition_1_1_2/Modified_Face&Box_1_1/Top"), model.selection("FACE", "Partition_1_1_2/Modified_Face&Box_1_1/Right")]
59 Group_2 = model.addGroup(Part_1_doc, Group_2_objects)
60 Group_3_objects = [model.selection("EDGE", "[Partition_1_1_3/Modified_Face&Box_1_1/Top][Partition_1_1_3/Modified_Face&Box_1_1/Front]"), model.selection("EDGE", "[Partition_1_1_3/Modified_Face&Box_1_1/Top][Partition_1_1_3/Modified_Face&Box_1_1/Left]"), model.selection("EDGE", "Partition_1_1_1/Generated_Edge&Plane_2/Plane_2&Box_1_1/Top"), model.selection("EDGE", "[Partition_1_1_1/Modified_Face&Box_1_1/Top][Partition_1_1_1/Modified_Face&Box_1_1/Left]"), model.selection("EDGE", "[Partition_1_1_1/Modified_Face&Box_1_1/Back][Partition_1_1_1/Modified_Face&Box_1_1/Top]"), model.selection("EDGE", "Partition_1_1_2/Generated_Edge&Plane_1/Plane_1&Box_1_1/Top"), model.selection("EDGE", "Partition_1_1_3/Generated_Edge&Plane_1/Plane_1&Box_1_1/Top"), model.selection("EDGE", "[Partition_1_1_4/Modified_Face&Box_1_1/Top][Partition_1_1_4/Modified_Face&Box_1_1/Front]"), model.selection("EDGE", "[Partition_1_1_4/Modified_Face&Box_1_1/Top][Partition_1_1_4/Modified_Face&Box_1_1/Right]"), model.selection("EDGE", "Partition_1_1_2/Generated_Edge&Plane_2/Plane_2&Box_1_1/Top"), model.selection("EDGE", "[Partition_1_1_2/Modified_Face&Box_1_1/Back][Partition_1_1_2/Modified_Face&Box_1_1/Top]"), model.selection("EDGE", "[Partition_1_1_2/Modified_Face&Box_1_1/Top][Partition_1_1_2/Modified_Face&Box_1_1/Right]")]
61 Group_3 = model.addGroup(Part_1_doc, Group_3_objects)
62 Group_4_objects = [model.selection("VERTEX", "[Partition_1_1_3/Modified_Face&Box_1_1/Front][Partition_1_1_3/Modified_Face&Box_1_1/Left][Partition_1_1_3/Modified_Face&Box_1_1/Bottom]"), model.selection("VERTEX", "Partition_1_1_4/Generated_Vertex&Plane_1/Plane_1&weak_name_1"), model.selection("VERTEX", "[Partition_1_1_4/Modified_Face&Box_1_1/Front][Partition_1_1_4/Modified_Face&Box_1_1/Bottom][Partition_1_1_4/Modified_Face&Box_1_1/Right]"), model.selection("VERTEX", "Partition_1_1_1/Generated_Vertex&Plane_2/Plane_2&weak_name_1"), model.selection("VERTEX", "[Partition_1_1_2/Modified_Face&Box_1_1/Bottom][Partition_1_1_2/Modified_Face&Plane_1/Plane_1][Partition_1_1_2/Modified_Face&Plane_2/Plane_2]"), model.selection("VERTEX", "Partition_1_1_2/Generated_Vertex&Plane_2/Plane_2&weak_name_1"), model.selection("VERTEX", "[Partition_1_1_1/Modified_Face&Box_1_1/Back][Partition_1_1_1/Modified_Face&Box_1_1/Bottom][Partition_1_1_1/Modified_Face&Box_1_1/Left]"), model.selection("VERTEX", "Partition_1_1_2/Generated_Vertex&Plane_1/Plane_1&weak_name_1"), model.selection("VERTEX", "[Partition_1_1_2/Modified_Face&Box_1_1/Back][Partition_1_1_2/Modified_Face&Box_1_1/Right][Partition_1_1_2/Modified_Face&Box_1_1/Bottom]")]
63 Group_4 = model.addGroup(Part_1_doc, Group_4_objects)
64 Translation_1 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Partition_1_1")], model.selection("EDGE", "PartSet/OX"), 20)
65 model.do()
66 model.end()
67
68 num_in_groups = [2, 4, 12, 9]
69 moveGroupsAndVerify(Part_1_doc, Translation_1.feature(), num_in_groups)
70
71 model.begin()
72 Translation_2 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Translation_1_1")], 10, 10, 0)
73 model.end()
74 moveGroupsAndVerify(Part_1_doc, Translation_2.feature(), num_in_groups)
75
76 model.begin()
77 Translation_3 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Translation_2_1")], model.selection("VERTEX", "[Translation_2_1_1/MF:Translated_Face&Box_1_1/Back][Translation_2_1_1/MF:Translated_Face&Box_1_1/Bottom][Translation_2_1_1/MF:Translated_Face&Box_1_1/Left]"), model.selection("VERTEX", "PartSet/Origin"))
78 model.end()
79 moveGroupsAndVerify(Part_1_doc, Translation_3.feature(), num_in_groups)
80
81 assert(model.checkPythonDump())