Salome HOME
Merge remote-tracking branch 'remotes/origin/HigherLevelObjectsHistory'
[modules/shaper.git] / src / BuildPlugin / Test / TestCompound_History.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 that the history of compound works correctly after movement of groups after this compound feature
22
23 # -*- coding: utf-8 -*-
24
25 from salome.shaper import model
26 from ModelAPI import *
27 from GeomAPI import *
28
29 model.begin()
30 partSet = model.moduleDocument()
31 Part_1 = model.addPart(partSet)
32 Part_1_doc = Part_1.document()
33 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
34 SketchPoint_1 = Sketch_1.addPoint(-19.03078817733991, 40.92241379310347)
35 SketchLine_1 = Sketch_1.addLine(-0.7463054187192111, 38.55911330049261, -18.03571428571429, 28.48399014778325)
36 SketchCircle_1 = Sketch_1.addCircle(-2.238916256157633, 23.13546798029557, 5.523556488740459)
37 model.do()
38 Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/SketchPoint_1")])
39 Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_1")])
40 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f")], model.selection(), 10, 0)
41 Group_1_objects = [model.selection("VERTEX", "Vertex_1_1"), model.selection("VERTEX", "Edge_1_1/Modified_Vertex&Sketch_1/SketchLine_1_EndVertex"), model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/To_Face]")]
42 Group_1 = model.addGroup(Part_1_doc, Group_1_objects)
43 Group_2 = model.addGroup(Part_1_doc, [model.selection("EDGE", "Edge_1_1"), model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/To_Face]")])
44 Group_3 = model.addGroup(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")])
45 Compound_1_objects = [model.selection("VERTEX", "Vertex_1_1"), model.selection("EDGE", "Edge_1_1"), model.selection("SOLID", "Extrusion_1_1")]
46 Compound_1 = model.addCompound(Part_1_doc, Compound_1_objects)
47 model.do()
48 # move groups after the compound
49 Part_1_doc.moveFeature(Group_1.feature(), Compound_1.feature())
50 Part_1_doc.moveFeature(Group_2.feature(), Group_1.feature())
51 Part_1_doc.moveFeature(Group_3.feature(), Group_2.feature())
52 model.end()
53
54 # check groups are correct
55 aFactory = ModelAPI_Session.get().validators()
56 selectionList = Group_1.feature().selectionList("group_list")
57 assert(selectionList.size() == 3)
58 assert(aFactory.validate(Group_1.feature()))
59 for i in range(3):
60   assert(Group_1.groupList().value(i).value().shapeType() == GeomAPI_Shape.VERTEX)
61
62 selectionList = Group_2.feature().selectionList("group_list")
63 assert(selectionList.size() == 2)
64 assert(aFactory.validate(Group_2.feature()))
65 for i in range(2):
66   assert(Group_2.groupList().value(i).value().shapeType() == GeomAPI_Shape.EDGE)
67
68 selectionList = Group_3.feature().selectionList("group_list")
69 assert(selectionList.size() == 1)
70 assert(aFactory.validate(Group_3.feature()))
71 assert(Group_3.groupList().value(0).value().shapeType() == GeomAPI_Shape.SOLID)
72
73 assert(model.checkPythonDump())