Salome HOME
Merge commit 'refs/tags/V9_2_0^{}'
[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/Face-SketchLine_4r-SketchLine_3r-SketchLine_2r-SketchLine_1r_wire")])
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 SketchConstraintVertical_3 = Sketch_2.setVertical(SketchLine_6.result())
59 SketchConstraintHorizontal_4 = Sketch_2.setHorizontal(SketchLine_7.result())
60 SketchConstraintVertical_4 = Sketch_2.setVertical(SketchLine_8.result())
61 SketchProjection_2 = Sketch_2.addProjection(model.selection("EDGE", "Sketch_1/SketchLine_2"), False)
62 SketchLine_9 = SketchProjection_2.createdFeature()
63 SketchConstraintMiddle_1 = Sketch_2.setMiddlePoint(SketchLine_5.startPoint(), SketchLine_9.result())
64 SketchConstraintCoincidence_10 = Sketch_2.setCoincident(SketchAPI_Line(SketchLine_9).startPoint(), SketchLine_5.endPoint())
65 SketchConstraintEqual_2 = Sketch_2.setEqual(SketchLine_5.result(), SketchLine_6.result())
66 SketchLine_10 = Sketch_2.addLine(20, 20, 20, 40)
67 SketchConstraintCoincidence_11 = Sketch_2.setCoincident(SketchLine_7.endPoint(), SketchLine_10.startPoint())
68 SketchLine_11 = Sketch_2.addLine(20, 40, 0, 40)
69 SketchConstraintCoincidence_12 = Sketch_2.setCoincident(SketchLine_10.endPoint(), SketchLine_11.startPoint())
70 SketchLine_12 = Sketch_2.addLine(0, 40, 0, 20)
71 SketchConstraintCoincidence_13 = Sketch_2.setCoincident(SketchLine_11.endPoint(), SketchLine_12.startPoint())
72 SketchConstraintCoincidence_14 = Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchLine_12.endPoint())
73 SketchConstraintVertical_5 = Sketch_2.setVertical(SketchLine_10.result())
74 SketchConstraintHorizontal_5 = Sketch_2.setHorizontal(SketchLine_11.result())
75 SketchConstraintVertical_6 = Sketch_2.setVertical(SketchLine_12.result())
76 SketchConstraintEqual_3 = Sketch_2.setEqual(SketchLine_6.result(), SketchLine_12.result())
77 model.do()
78 Face_2 = model.addFace(Part_1_doc, [model.selection("WIRE", "Sketch_2/Face-SketchLine_8r-SketchLine_7r-SketchLine_6r-SketchLine_5r_wire")])
79 AngularCopy_1 = model.addMultiRotation(Part_1_doc, [model.selection("FACE", "Face_2_1")], model.selection("EDGE", "PartSet/OZ"), 270, 2)
80 Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "AngularCopy_1_1_1"), model.selection("FACE", "AngularCopy_1_1_2")])
81 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)
82 Sketch_3 = model.addSketch(Part_1_doc, model.defaultPlane("YOZ"))
83 SketchLine_13 = Sketch_3.addLine(40, 0, 20, 0)
84 SketchLine_14 = Sketch_3.addLine(20, 0, 20, 40)
85 SketchLine_15 = Sketch_3.addLine(20, 40, 40, 40)
86 SketchLine_16 = Sketch_3.addLine(40, 40, 40, 0)
87 SketchConstraintCoincidence_15 = Sketch_3.setCoincident(SketchLine_16.endPoint(), SketchLine_13.startPoint())
88 SketchConstraintCoincidence_16 = Sketch_3.setCoincident(SketchLine_13.endPoint(), SketchLine_14.startPoint())
89 SketchConstraintCoincidence_17 = Sketch_3.setCoincident(SketchLine_14.endPoint(), SketchLine_15.startPoint())
90 SketchConstraintCoincidence_18 = Sketch_3.setCoincident(SketchLine_15.endPoint(), SketchLine_16.startPoint())
91 SketchConstraintHorizontal_7 = Sketch_3.setHorizontal(SketchLine_15.result())
92 SketchConstraintVertical_8 = Sketch_3.setVertical(SketchLine_16.result())
93 SketchProjection_3 = Sketch_3.addProjection(model.selection("VERTEX", "Sketch_2/SketchLine_5_StartVertex"), False)
94 SketchPoint_2 = SketchProjection_3.createdFeature()
95 SketchConstraintCoincidence_19 = Sketch_3.setCoincident(SketchLine_13.endPoint(), SketchAPI_Point(SketchPoint_2).coordinates())
96 SketchProjection_4 = Sketch_3.addProjection(model.selection("VERTEX", "Sketch_2/SketchLine_10_EndVertex"), False)
97 SketchPoint_3 = SketchProjection_4.createdFeature()
98 SketchConstraintCoincidence_20 = Sketch_3.setCoincident(SketchLine_14.endPoint(), SketchAPI_Point(SketchPoint_3).coordinates())
99 SketchProjection_5 = Sketch_3.addProjection(model.selection("VERTEX", "Sketch_1/SketchLine_2_EndVertex"), False)
100 SketchPoint_4 = SketchProjection_5.createdFeature()
101 SketchConstraintCoincidence_21 = Sketch_3.setCoincident(SketchLine_13.startPoint(), SketchAPI_Point(SketchPoint_4).coordinates())
102 model.do()
103 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)
104 Box_1 = model.addBox(Part_1_doc, 20, 20, 20)
105 model.do()
106
107 def createCompSolidStepByStep(theSelection, theExpectedType):
108     CompSolid = model.addCompSolid(Part_1_doc, [theSelection[0]])
109     aList = []
110     for selection, expected in zip(theSelection, theExpectedType):
111         aList.append(selection)
112         CompSolid.setBase(aList)
113         if expected == GeomAPI_Shape.SHAPE:
114             assert(len(CompSolid.results()) == 0), "FAILED: CompSolid should not be built"
115         else:
116             assert(len(CompSolid.results()) > 0), "FAILED: CompSolid is not built"
117             resultType = CompSolid.results()[0].resultSubShapePair()[0].shape().shapeType()
118             assert(resultType == expected), "FAILED: Result has unexpected type"
119     # remove solid if it is not built
120     if len(CompSolid.results()) == 0:
121         Part_1_doc.removeFeature(CompSolid.feature())
122         return None
123     return CompSolid
124
125 # =============================================================================
126 # Test 1. Build compsolid cointaining 2 solids
127 # =============================================================================
128 boundaries1 = [model.selection("FACE", "Face_1_1"),
129                model.selection("SHELL", "Shell_1_1"),
130                model.selection("FACE", "Sketch_3/Face-SketchLine_16r-SketchLine_15r-SketchLine_14r-SketchLine_13r"),
131                model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_7"),
132                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_14"),
133                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_15"),
134                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_16"),
135                model.selection("FACE", "Extrusion_2_1/To_Face"),
136                model.selection("FACE", "Box_1_1/Front")]
137 expectType1 = [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.SHAPE,
144                GeomAPI_Shape.SOLID,
145                GeomAPI_Shape.COMPSOLID]
146 CompSolid_1 = createCompSolidStepByStep(boundaries1, expectType1)
147
148 model.checkResult(CompSolid_1, model, 1, [2], [2], [13], [54], [108])
149 model.testHaveNamingSubshapes(CompSolid_1, model, Part_1_doc)
150
151 # =============================================================================
152 # Test 2. Build compsolid containing 3 solids
153 # =============================================================================
154 boundaries2 = [model.selection("FACE", "Face_1_1"),
155                model.selection("SHELL", "Shell_1_1"),
156                model.selection("FACE", "Sketch_3/Face-SketchLine_16r-SketchLine_15r-SketchLine_14r-SketchLine_13r"),
157                model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_7"),
158                model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_10"),
159                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_15"),
160                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_16"),
161                model.selection("FACE", "Extrusion_2_1/To_Face"),
162                model.selection("FACE", "Box_1_1/Front"),
163                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_14"),
164                model.selection("SOLID", "Extrusion_1_1")]
165 expectType2 = [GeomAPI_Shape.SHAPE,
166                GeomAPI_Shape.SHAPE,
167                GeomAPI_Shape.SHAPE,
168                GeomAPI_Shape.SHAPE,
169                GeomAPI_Shape.SHAPE,
170                GeomAPI_Shape.SHAPE,
171                GeomAPI_Shape.SHAPE,
172                GeomAPI_Shape.SHAPE,
173                GeomAPI_Shape.SOLID,
174                GeomAPI_Shape.COMPSOLID,
175                GeomAPI_Shape.COMPSOLID]
176 CompSolid_2 = createCompSolidStepByStep(boundaries2, expectType2)
177
178 model.checkResult(CompSolid_2, model, 1, [3], [3], [21], [88], [176])
179 model.testHaveNamingSubshapes(CompSolid_2, model, Part_1_doc)
180
181 model.end()
182
183 assert(model.checkPythonDump())