Salome HOME
3678534cc7cf3aaded43c736672335749b7d3a65
[modules/shaper.git] / src / BuildPlugin / Test / TestCompSolid.py
1 # Copyright (C) 2017-2023  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 from SketchAPI import *
21 from GeomAPI import GeomAPI_Shape
22 from salome.shaper import model
23
24 model.begin()
25 partSet = model.moduleDocument()
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
28 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
29 SketchLine_1 = Sketch_1.addLine(40, 0, 0, 0)
30 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
31 SketchPoint_1 = SketchProjection_1.createdFeature()
32 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchPoint_1.result())
33 SketchLine_2 = Sketch_1.addLine(0, 0, 0, 40)
34 SketchLine_3 = Sketch_1.addLine(0, 40, 40, 40)
35 SketchLine_4 = Sketch_1.addLine(40, 40, 40, 0)
36 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
37 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
38 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
39 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
40 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
41 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
42 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
43 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
44 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_1.result(), SketchLine_2.result())
45 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 40)
46 model.do()
47 Face_1 = model.addFace(Part_1_doc, [model.selection("WIRE", "Sketch_1/Face-SketchLine_4r-SketchLine_3r-SketchLine_2r-SketchLine_1r_wire")])
48 Sketch_2 = model.addSketch(Part_1_doc, model.standardPlane("YOZ"))
49 SketchLine_5 = Sketch_2.addLine(20, 0, 0, 0)
50 SketchLine_6 = Sketch_2.addLine(0, 0, 0, 20)
51 SketchLine_7 = Sketch_2.addLine(0, 20, 20, 20)
52 SketchLine_8 = Sketch_2.addLine(20, 20, 20, 0)
53 SketchConstraintCoincidence_6 = Sketch_2.setCoincident(SketchLine_8.endPoint(), SketchLine_5.startPoint())
54 SketchConstraintCoincidence_7 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
55 SketchConstraintCoincidence_8 = Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
56 SketchConstraintCoincidence_9 = Sketch_2.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
57 SketchConstraintVertical_3 = Sketch_2.setVertical(SketchLine_6.result())
58 SketchConstraintHorizontal_4 = Sketch_2.setHorizontal(SketchLine_7.result())
59 SketchConstraintVertical_4 = Sketch_2.setVertical(SketchLine_8.result())
60 SketchProjection_2 = Sketch_2.addProjection(model.selection("EDGE", "Sketch_1/SketchLine_2"), False)
61 SketchLine_9 = SketchProjection_2.createdFeature()
62 SketchConstraintMiddle_1 = Sketch_2.setMiddlePoint(SketchLine_5.startPoint(), SketchLine_9.result())
63 SketchConstraintCoincidence_10 = Sketch_2.setCoincident(SketchAPI_Line(SketchLine_9).startPoint(), SketchLine_5.endPoint())
64 SketchConstraintEqual_2 = Sketch_2.setEqual(SketchLine_5.result(), SketchLine_6.result())
65 SketchLine_10 = Sketch_2.addLine(20, 20, 20, 40)
66 SketchConstraintCoincidence_11 = Sketch_2.setCoincident(SketchLine_7.endPoint(), SketchLine_10.startPoint())
67 SketchLine_11 = Sketch_2.addLine(20, 40, 0, 40)
68 SketchConstraintCoincidence_12 = Sketch_2.setCoincident(SketchLine_10.endPoint(), SketchLine_11.startPoint())
69 SketchLine_12 = Sketch_2.addLine(0, 40, 0, 20)
70 SketchConstraintCoincidence_13 = Sketch_2.setCoincident(SketchLine_11.endPoint(), SketchLine_12.startPoint())
71 SketchConstraintCoincidence_14 = Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchLine_12.endPoint())
72 SketchConstraintVertical_5 = Sketch_2.setVertical(SketchLine_10.result())
73 SketchConstraintHorizontal_5 = Sketch_2.setHorizontal(SketchLine_11.result())
74 SketchConstraintVertical_6 = Sketch_2.setVertical(SketchLine_12.result())
75 SketchConstraintEqual_3 = Sketch_2.setEqual(SketchLine_6.result(), SketchLine_12.result())
76 model.do()
77 Face_2 = model.addFace(Part_1_doc, [model.selection("WIRE", "Sketch_2/Face-SketchLine_8r-SketchLine_7r-SketchLine_6r-SketchLine_5r_wire")])
78 AngularCopy_1 = model.addMultiRotation(Part_1_doc, [model.selection("FACE", "Face_2_1")], model.selection("EDGE", "PartSet/OZ"), 270, 2)
79 Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "AngularCopy_1_1_1"), model.selection("FACE", "AngularCopy_1_1_2")])
80 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_7f-SketchLine_10f-SketchLine_11f-SketchLine_12f")], model.selection(), 40, 0)
81 Sketch_3 = model.addSketch(Part_1_doc, model.defaultPlane("YOZ"))
82 SketchLine_13 = Sketch_3.addLine(40, 0, 20, 0)
83 SketchLine_14 = Sketch_3.addLine(20, 0, 20, 40)
84 SketchLine_15 = Sketch_3.addLine(20, 40, 40, 40)
85 SketchLine_16 = Sketch_3.addLine(40, 40, 40, 0)
86 SketchConstraintCoincidence_15 = Sketch_3.setCoincident(SketchLine_16.endPoint(), SketchLine_13.startPoint())
87 SketchConstraintCoincidence_16 = Sketch_3.setCoincident(SketchLine_13.endPoint(), SketchLine_14.startPoint())
88 SketchConstraintCoincidence_17 = Sketch_3.setCoincident(SketchLine_14.endPoint(), SketchLine_15.startPoint())
89 SketchConstraintCoincidence_18 = Sketch_3.setCoincident(SketchLine_15.endPoint(), SketchLine_16.startPoint())
90 SketchConstraintHorizontal_7 = Sketch_3.setHorizontal(SketchLine_15.result())
91 SketchConstraintVertical_8 = Sketch_3.setVertical(SketchLine_16.result())
92 SketchProjection_3 = Sketch_3.addProjection(model.selection("VERTEX", "Sketch_2/SketchLine_5_StartVertex"), False)
93 SketchPoint_2 = SketchProjection_3.createdFeature()
94 SketchConstraintCoincidence_19 = Sketch_3.setCoincident(SketchLine_13.endPoint(), SketchAPI_Point(SketchPoint_2).coordinates())
95 SketchProjection_4 = Sketch_3.addProjection(model.selection("VERTEX", "Sketch_2/SketchLine_10_EndVertex"), False)
96 SketchPoint_3 = SketchProjection_4.createdFeature()
97 SketchConstraintCoincidence_20 = Sketch_3.setCoincident(SketchLine_14.endPoint(), SketchAPI_Point(SketchPoint_3).coordinates())
98 SketchProjection_5 = Sketch_3.addProjection(model.selection("VERTEX", "Sketch_1/SketchLine_2_EndVertex"), False)
99 SketchPoint_4 = SketchProjection_5.createdFeature()
100 SketchConstraintCoincidence_21 = Sketch_3.setCoincident(SketchLine_13.startPoint(), SketchAPI_Point(SketchPoint_4).coordinates())
101 model.do()
102 Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_3/Face-SketchLine_16r-SketchLine_15r-SketchLine_14r-SketchLine_13r")], model.selection(), 20, 0)
103 Box_1 = model.addBox(Part_1_doc, 20, 20, 20)
104 model.do()
105
106 def createCompSolidStepByStep(theSelection, theExpectedType):
107     CompSolid = model.addCompSolid(Part_1_doc, [theSelection[0]])
108     aList = []
109     for selection, expected in zip(theSelection, theExpectedType):
110         aList.append(selection)
111         CompSolid.setBase(aList)
112         if expected == GeomAPI_Shape.SHAPE:
113             assert(len(CompSolid.results()) == 0), "FAILED: CompSolid should not be built"
114         else:
115             assert(len(CompSolid.results()) > 0), "FAILED: CompSolid is not built"
116             resultType = CompSolid.results()[0].resultSubShapePair()[0].shape().shapeType()
117             assert(resultType == expected), "FAILED: Result has unexpected type"
118     # remove solid if it is not built
119     if len(CompSolid.results()) == 0:
120         Part_1_doc.removeFeature(CompSolid.feature())
121         return None
122     return CompSolid
123
124 # =============================================================================
125 # Test 1. Build compsolid cointaining 2 solids
126 # =============================================================================
127 boundaries1 = [model.selection("FACE", "Face_1_1"),
128                model.selection("SHELL", "Shell_1_1"),
129                model.selection("FACE", "Sketch_3/Face-SketchLine_16r-SketchLine_15r-SketchLine_14r-SketchLine_13r"),
130                model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_7"),
131                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_14"),
132                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_15"),
133                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_16"),
134                model.selection("FACE", "Extrusion_2_1/To_Face"),
135                model.selection("FACE", "Box_1_1/Front")]
136 expectType1 = [GeomAPI_Shape.SHAPE,
137                GeomAPI_Shape.SHAPE,
138                GeomAPI_Shape.SHAPE,
139                GeomAPI_Shape.SHAPE,
140                GeomAPI_Shape.SHAPE,
141                GeomAPI_Shape.SHAPE,
142                GeomAPI_Shape.SHAPE,
143                GeomAPI_Shape.SOLID,
144                GeomAPI_Shape.COMPSOLID]
145 CompSolid_1 = createCompSolidStepByStep(boundaries1, expectType1)
146
147 model.checkResult(CompSolid_1, model, 1, [2], [2], [13], [54], [108])
148 model.testHaveNamingSubshapes(CompSolid_1, model, Part_1_doc)
149
150 # to reuse all results, undo the solid and 3 groups creation
151 model.undo()
152 model.undo()
153 model.undo()
154 model.undo()
155
156 # =============================================================================
157 # Test 2. Build compsolid containing 3 solids
158 # =============================================================================
159 boundaries2 = [model.selection("FACE", "Face_1_1"),
160                model.selection("SHELL", "Shell_1_1"),
161                model.selection("FACE", "Sketch_3/Face-SketchLine_16r-SketchLine_15r-SketchLine_14r-SketchLine_13r"),
162                model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_7"),
163                model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_10"),
164                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_15"),
165                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_16"),
166                model.selection("FACE", "Extrusion_2_1/To_Face"),
167                model.selection("FACE", "Box_1_1/Front"),
168                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_14"),
169                model.selection("SOLID", "Extrusion_1_1")]
170 expectType2 = [GeomAPI_Shape.SHAPE,
171                GeomAPI_Shape.SHAPE,
172                GeomAPI_Shape.SHAPE,
173                GeomAPI_Shape.SHAPE,
174                GeomAPI_Shape.SHAPE,
175                GeomAPI_Shape.SHAPE,
176                GeomAPI_Shape.SHAPE,
177                GeomAPI_Shape.SHAPE,
178                GeomAPI_Shape.SOLID,
179                GeomAPI_Shape.COMPSOLID,
180                GeomAPI_Shape.COMPSOLID]
181 CompSolid_2 = createCompSolidStepByStep(boundaries2, expectType2)
182
183 model.checkResult(CompSolid_2, model, 1, [3], [3], [21], [88], [176])
184 model.testHaveNamingSubshapes(CompSolid_2, model, Part_1_doc)
185
186 model.end()
187
188 assert(model.checkPythonDump())