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