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