Salome HOME
Merge remote-tracking branch 'remotes/origin/HigherLevelObjectsHistory'
[modules/shaper.git] / src / FeaturesPlugin / Test / TestBooleanCommon_SolidsHistory.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 Common operation works correctly after movement of groups after this Common feature
22
23 # -*- coding: utf-8 -*-
24
25 from salome.shaper import model
26 from ModelAPI import *
27 from GeomAPI import *
28 from SketchAPI import *
29
30 model.begin()
31 partSet = model.moduleDocument()
32 Part_1 = model.addPart(partSet)
33 Part_1_doc = Part_1.document()
34 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
35 SketchCircle_1 = Sketch_1.addCircle(5, 5, 7.071067811865464)
36 SketchCircle_2 = Sketch_1.addCircle(0, 10, 7.071067811865464)
37 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchCircle_2.results()[1])
38 SketchCircle_3 = Sketch_1.addCircle(-5, 5, 7.071067811865464)
39 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchCircle_2.center(), SketchCircle_3.results()[1])
40 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchCircle_3.center(), SketchCircle_2.results()[1])
41 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchCircle_1.results()[1], SketchCircle_2.center())
42 SketchCircle_4 = Sketch_1.addCircle(0, 0, 7.071067811865464)
43 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchCircle_4.center(), SketchCircle_3.results()[1])
44 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchCircle_4.results()[1], SketchCircle_3.center())
45 SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchCircle_4.results()[1], SketchCircle_1.center())
46 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchCircle_1.center(), SketchCircle_3.center(), 10, True)
47 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchCircle_2.center(), SketchCircle_4.center(), 10, True)
48 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
49 SketchPoint_1 = SketchProjection_1.createdFeature()
50 SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchCircle_4.center(), SketchAPI_Point(SketchPoint_1).coordinates())
51 SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False)
52 SketchLine_1 = SketchProjection_2.createdFeature()
53 SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchCircle_2.center(), SketchLine_1.result())
54 model.do()
55 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
56 SketchLine_2 = Sketch_2.addLine(-5, 5, 0, 0)
57 SketchProjection_3 = Sketch_2.addProjection(model.selection("VERTEX", "Sketch_1/SketchCircle_3_2__cc"), False)
58 SketchPoint_2 = SketchProjection_3.createdFeature()
59 SketchConstraintCoincidence_10 = Sketch_2.setCoincident(SketchLine_2.startPoint(), SketchPoint_2.result())
60 SketchProjection_4 = Sketch_2.addProjection(model.selection("VERTEX", "Sketch_1/SketchCircle_4_2__cc"), False)
61 SketchPoint_3 = SketchProjection_4.createdFeature()
62 SketchConstraintCoincidence_11 = Sketch_2.setCoincident(SketchLine_2.endPoint(), SketchPoint_3.result())
63 SketchLine_3 = Sketch_2.addLine(0, 0, 5, 5)
64 SketchConstraintCoincidence_12 = Sketch_2.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
65 SketchProjection_5 = Sketch_2.addProjection(model.selection("VERTEX", "Sketch_1/SketchCircle_1_2__cc"), False)
66 SketchPoint_4 = SketchProjection_5.createdFeature()
67 SketchConstraintCoincidence_13 = Sketch_2.setCoincident(SketchLine_3.endPoint(), SketchPoint_4.result())
68 SketchLine_4 = Sketch_2.addLine(-5, 5, 5, 5)
69 SketchConstraintCoincidence_14 = Sketch_2.setCoincident(SketchLine_2.startPoint(), SketchLine_4.startPoint())
70 SketchConstraintCoincidence_15 = Sketch_2.setCoincident(SketchLine_3.endPoint(), SketchLine_4.endPoint())
71 SketchArc_1 = Sketch_2.addArc(-1.474514954580286e-16, 5, -5, 5, 5, 5, True)
72 SketchConstraintCoincidence_16 = Sketch_2.setCoincident(SketchLine_4.result(), SketchArc_1.center())
73 SketchConstraintCoincidence_17 = Sketch_2.setCoincident(SketchLine_2.startPoint(), SketchArc_1.startPoint())
74 SketchConstraintCoincidence_18 = Sketch_2.setCoincident(SketchLine_4.endPoint(), SketchArc_1.endPoint())
75 model.do()
76 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "all-in-Sketch_1")], model.selection(), 10, 0)
77 Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "all-in-Sketch_2")], model.selection(), 5, 5)
78 Group_1_objects = [model.selection("SOLID", "Extrusion_1_1_13"), model.selection("SOLID", "Extrusion_1_1_10"), model.selection("SOLID", "Extrusion_1_1_7"), model.selection("SOLID", "Extrusion_1_1_9"), model.selection("SOLID", "Extrusion_1_1_1"), model.selection("SOLID", "Extrusion_1_1_5"), model.selection("SOLID", "Extrusion_1_1_4"), model.selection("SOLID", "Extrusion_1_1_12"), model.selection("SOLID", "Extrusion_1_1_11"), model.selection("SOLID", "Extrusion_1_1_8"), model.selection("SOLID", "Extrusion_1_1_3"), model.selection("SOLID", "Extrusion_1_1_6"), model.selection("SOLID", "Extrusion_1_1_2")]
79 Group_1 = model.addGroup(Part_1_doc, Group_1_objects)
80 Group_2 = model.addGroup(Part_1_doc, [model.selection("SOLID", "Extrusion_2_1_2"), model.selection("SOLID", "Extrusion_2_1_1")])
81 Group_3_objects = [model.selection("FACE", "Extrusion_1_1_7/From_Face"), model.selection("FACE", "Extrusion_1_1_1/From_Face"), model.selection("FACE", "Extrusion_1_1_9/From_Face"), model.selection("FACE", "Extrusion_1_1_12/From_Face"), model.selection("FACE", "Extrusion_1_1_4/From_Face"), model.selection("FACE", "Extrusion_1_1_5/From_Face"), model.selection("FACE", "Extrusion_1_1_8/From_Face"), model.selection("FACE", "Extrusion_1_1_11/From_Face"), model.selection("FACE", "Extrusion_1_1_6/From_Face"), model.selection("FACE", "Extrusion_1_1_2/From_Face"), model.selection("FACE", "Extrusion_1_1_3/From_Face"), model.selection("FACE", "Extrusion_1_1_10/From_Face")]
82 Group_3 = model.addGroup(Part_1_doc, Group_3_objects)
83 Group_4_objects = [model.selection("FACE", "Extrusion_2_1_2/Generated_Face&Sketch_2/SketchLine_4"), model.selection("FACE", "Extrusion_2_1_2/Generated_Face&Sketch_2/SketchArc_1_2"), model.selection("FACE", "Extrusion_2_1_2/From_Face"), model.selection("FACE", "Extrusion_2_1_2/To_Face"), model.selection("FACE", "Extrusion_2_1_1/Generated_Face&Sketch_2/SketchLine_2"), model.selection("FACE", "Extrusion_2_1_1/To_Face"), model.selection("FACE", "Extrusion_2_1_1/From_Face"), model.selection("FACE", "Extrusion_2_1_1/Generated_Face&Sketch_2/SketchLine_4"), model.selection("FACE", "Extrusion_2_1_1/Generated_Face&Sketch_2/SketchLine_3")]
84 Group_4 = model.addGroup(Part_1_doc, Group_4_objects)
85 Common_1 = model.addCommon(Part_1_doc, [model.selection("COMPSOLID", "Extrusion_1_1"), model.selection("COMPSOLID", "Extrusion_2_1")])
86 Common_1.result().subResult(0).setColor(254, 254, 127)
87 Common_1.result().subResult(1).setColor(204, 102, 204)
88 Common_1.result().subResult(2).setColor(51, 102, 102)
89 Common_1.result().subResult(3).setColor(0, 153, 0)
90 Common_1.result().subResult(4).setColor(254, 0, 0)
91 Common_1.result().subResult(5).setColor(204, 0, 204)
92 Common_1.result().subResult(6).setColor(102, 0, 0)
93 Common_1.result().subResult(7).setColor(0, 0, 153)
94 Common_1.result().subResult(8).setColor(0, 0, 204)
95 Common_1.result().subResult(9).setColor(0, 0, 204)
96 Common_1.result().subResult(10).setColor(0, 153, 0)
97 Common_1.result().subResult(11).setColor(127, 127, 254)
98 model.do()
99 # move groups after the Common
100 Part_1_doc.moveFeature(Group_1.feature(), Common_1.feature())
101 Part_1_doc.moveFeature(Group_2.feature(), Group_1.feature())
102 Part_1_doc.moveFeature(Group_3.feature(), Group_2.feature())
103 Part_1_doc.moveFeature(Group_4.feature(), Group_3.feature())
104 model.end()
105
106 # check groups are correct
107 aFactory = ModelAPI_Session.get().validators()
108 selectionList = Group_1.feature().selectionList("group_list")
109 assert(selectionList.size() == 12)
110 assert(aFactory.validate(Group_1.feature()))
111 for i in range(12):
112   assert(Group_1.groupList().value(i).value().shapeType() == GeomAPI_Shape.SOLID)
113
114 selectionList = Group_2.feature().selectionList("group_list")
115 assert(selectionList.size() == 12)
116 assert(aFactory.validate(Group_2.feature()))
117 for i in range(12):
118   assert(Group_2.groupList().value(i).value().shapeType() == GeomAPI_Shape.SOLID)
119
120 selectionList = Group_3.feature().selectionList("group_list")
121 assert(selectionList.size() == 12)
122 assert(aFactory.validate(Group_3.feature()))
123 for i in range(12):
124   assert(Group_3.groupList().value(i).value().shapeType() == GeomAPI_Shape.FACE)
125
126 selectionList = Group_4.feature().selectionList("group_list")
127 assert(selectionList.size() == 22)
128 assert(aFactory.validate(Group_4.feature()))
129 for i in range(22):
130   assert(Group_4.groupList().value(i).value().shapeType() == GeomAPI_Shape.FACE)
131
132 assert(model.checkPythonDump(model.ModelHighAPI.CHECK_NAMING))