]> SALOME platform Git repositories - modules/shaper.git/blob - src/BuildPlugin/Test/TestSolid.py
Salome HOME
Merge remote-tracking branch 'origin/Toolbars_Management'
[modules/shaper.git] / src / BuildPlugin / Test / TestSolid.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
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 createSolidStepByStep(theSelection, theExpected):
108     Solid = model.addSolid(Part_1_doc, [theSelection[0]])
109     aList = []
110     for selection, expected in zip(theSelection, theExpected):
111         aList.append(selection)
112         Solid.setBase(aList)
113         if expected:
114             assert(len(Solid.results()) > 0), "FAILED: Solid is not built"
115         else:
116             assert(len(Solid.results()) == 0), "FAILED: Solid should not be built"
117     # remove solid if it is not built
118     if len(Solid.results()) == 0:
119         Part_1_doc.removeFeature(Solid.feature())
120         return None
121     return Solid
122
123 # =============================================================================
124 # Test 1. Build solid from faces applicable for compsolid
125 # =============================================================================
126 boundaries1 = [model.selection("FACE", "Face_1_1"),
127                model.selection("SHELL", "Shell_1_1"),
128                model.selection("FACE", "Sketch_3/Face-SketchLine_16r-SketchLine_15r-SketchLine_14r-SketchLine_13r"),
129                model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_7"),
130                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_14"),
131                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_15"),
132                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_16"),
133                model.selection("FACE", "Extrusion_2_1/To_Face"),
134                model.selection("FACE", "Box_1_1/Front")]
135 expectSolid1 = [False, False, False, False, False, False, False, True, False]
136 Solid_1 = createSolidStepByStep(boundaries1, expectSolid1)
137 assert(Solid_1 is None)
138
139 # =============================================================================
140 # Test 2. Build correct solid
141 # =============================================================================
142 boundaries2 = [model.selection("FACE", "Face_1_1"),
143                model.selection("SHELL", "Shell_1_1"),
144                model.selection("FACE", "Sketch_3/Face-SketchLine_16r-SketchLine_15r-SketchLine_14r-SketchLine_13r"),
145                model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_7"),
146                model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_10"),
147                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_15"),
148                model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_3/SketchLine_16"),
149                model.selection("FACE", "Extrusion_2_1/To_Face"),
150                model.selection("FACE", "Box_1_1/Front")]
151 expectSolid2 = [False, False, False, False, False, False, False, False, True]
152 Solid_2 = createSolidStepByStep(boundaries2, expectSolid2)
153
154 model.checkResult(Solid_2, model, 1, [0], [1], [10], [44], [88])
155 model.testHaveNamingSubshapes(Solid_2, model, Part_1_doc)
156
157 model.end()
158
159 assert(model.checkPythonDump())