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