]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/Test/Test2901.py
Salome HOME
Added a unit-test for #21537 : Dumped file not loadable
[modules/shaper.git] / src / ModelAPI / Test / Test2901.py
1 # Copyright (C) 2014-2020  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 ModelAPI import *
22 from GeomAPI import *
23
24 from salome.shaper import model
25
26 model.begin()
27 partSet = model.moduleDocument()
28 Part_1 = model.addPart(partSet)
29 Part_1_doc = Part_1.document()
30 model.addParameter(Part_1_doc, "l", "200")
31 model.addParameter(Part_1_doc, "b", "100")
32 model.addParameter(Part_1_doc, "h", "25")
33 model.addParameter(Part_1_doc, "r", "25")
34 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
35 SketchLine_1 = Sketch_1.addLine(200, 0, 0, 0)
36 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
37 SketchPoint_1 = SketchProjection_1.createdFeature()
38 SketchLine_2 = Sketch_1.addLine(0, 0, 0, 100)
39 SketchLine_3 = Sketch_1.addLine(0, 100, 200, 100)
40 SketchLine_4 = Sketch_1.addLine(200, 100, 200, 0)
41 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
42 SketchConstraintCoincidence_1.setName("SketchConstraintCoincidence_2")
43 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
44 SketchConstraintCoincidence_2.setName("SketchConstraintCoincidence_3")
45 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
46 SketchConstraintCoincidence_3.setName("SketchConstraintCoincidence_4")
47 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
48 SketchConstraintCoincidence_4.setName("SketchConstraintCoincidence_5")
49 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
50 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
51 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
52 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
53 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), "l")
54 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_2.result(), "b")
55 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_2.startPoint(), SketchAPI_Point(SketchPoint_1).coordinates())
56 SketchConstraintCoincidence_5.setName("SketchConstraintCoincidence_6")
57 SketchCircle_1 = Sketch_1.addCircle(50, 50, 25)
58 SketchCircle_2 = Sketch_1.addCircle(150, 50, 25)
59 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], "r")
60 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchCircle_1.results()[1], SketchCircle_2.results()[1])
61 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchCircle_1.center(), SketchLine_2.result(), "l/4", True)
62 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchCircle_1.center(), SketchLine_1.result(), "b/2", True)
63 SketchLine_5 = Sketch_1.addLine(50, 50, 150, 50)
64 SketchLine_5.setAuxiliary(True)
65 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchLine_5.startPoint())
66 SketchConstraintCoincidence_6.setName("SketchConstraintCoincidence_7")
67 SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchCircle_2.center(), SketchLine_5.endPoint())
68 SketchConstraintCoincidence_7.setName("SketchConstraintCoincidence_8")
69 SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_5.result())
70 SketchConstraintDistance_3 = Sketch_1.setDistance(SketchLine_5.endPoint(), SketchLine_4.result(), "l/4", True)
71 model.do()
72 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), "h", 0)
73 Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/YOZ"), 100, False)
74 Partition_1 = model.addPartition(Part_1_doc, [model.selection("COMPSOLID", "Extrusion_1_1"), model.selection("FACE", "Plane_1")])
75 Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Extrusion_1_1_1/Generated_Face&Sketch_1/SketchLine_2")])
76 Group_1.setName("Inlet")
77 Group_1.result().setName("Inlet")
78 Group_2 = model.addGroup(Part_1_doc, [model.selection("FACE", "Extrusion_1_1_1/Generated_Face&Sketch_1/SketchLine_4")])
79 Group_2.setName("Outlet")
80 Group_2.result().setName("Outlet")
81 Group_3_objects = [model.selection("FACE", "Partition_1_1_1/Modified_Face&Extrusion_1_1_1/To_Face"), model.selection("FACE", "Partition_1_1_1/Modified_Face&Sketch_1/SketchLine_1"), model.selection("FACE", "Partition_1_1_1/Modified_Face&Extrusion_1_1_1/From_Face"), model.selection("FACE", "Partition_1_1_1/Modified_Face&Sketch_1/SketchLine_3"), model.selection("FACE", "Partition_1_1_2/Modified_Face&Sketch_1/SketchLine_3"), model.selection("FACE", "Partition_1_1_2/Modified_Face&Extrusion_1_1_1/From_Face"), model.selection("FACE", "Partition_1_1_2/Modified_Face&Sketch_1/SketchLine_1"), model.selection("FACE", "Partition_1_1_2/Modified_Face&Extrusion_1_1_1/To_Face")]
82 Group_3 = model.addGroup(Part_1_doc, Group_3_objects)
83 Group_3.setName("Wall")
84 Group_3.result().setName("Wall")
85 Group_4 = model.addGroup(Part_1_doc, [model.selection("SOLID", "Partition_1_1_3"), model.selection("SOLID", "Partition_1_1_4")])
86 Group_4.setName("Cylinders")
87 Group_4.result().setName("Cylinders")
88 Group_4.result().setColor(170, 0, 0)
89 Group_5 = model.addGroup(Part_1_doc, [model.selection("SOLID", "Partition_1_1_1"), model.selection("SOLID", "Partition_1_1_2")])
90 Group_5.setName("Fluide")
91 Group_5.result().setName("Fluide")
92 Group_5.result().setColor(0, 0, 255)
93 Group_6 = model.addGroup(Part_1_doc, [model.selection("FACE", "Extrusion_1_1_2/Generated_Face&Sketch_1/SketchCircle_1_2"), model.selection("FACE", "Extrusion_1_1_3/Generated_Face&Sketch_1/SketchCircle_2_2")])
94 Group_6.setName("Faces_cyl")
95 Group_6.result().setName("Faces_cyl")
96 Plane_5 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/XOY"), 10, False)
97 Partition_2 = model.addPartition(Part_1_doc, [model.selection("COMPSOLID", "Partition_1_1"), model.selection("FACE", "Plane_2")])
98 model.do()
99 # move groups after the latest partitiion
100 Part_1_doc.moveFeature(Group_1.feature(), Partition_2.feature())
101 Part_1_doc.moveFeature(Group_2.feature(), Group_1.feature())
102 Part_1_doc.moveFeature(Group_3.feature(), Group_2.feature())
103 Part_1_doc.moveFeature(Group_4.feature(), Group_3.feature())
104 Part_1_doc.moveFeature(Group_5.feature(), Group_4.feature())
105 Part_1_doc.moveFeature(Group_6.feature(), Group_5.feature())
106 model.end()
107
108 # check groups are correct: group name, number of elements, elements type
109 Group_Info = [
110 (Group_1, 2, GeomAPI_Shape.FACE), # Inlet
111 (Group_2, 2, GeomAPI_Shape.FACE), # Outlet
112 (Group_3, 12, GeomAPI_Shape.FACE), # Wall
113 (Group_4, 4, GeomAPI_Shape.SOLID), # Cylinders
114 (Group_5, 4, GeomAPI_Shape.SOLID), # Fluide
115 (Group_6, 4, GeomAPI_Shape.FACE)] # Faces_cyl
116
117 aFactory = ModelAPI_Session.get().validators()
118 for group in Group_Info:
119   selectionList = group[0].feature().selectionList("group_list")
120   assert(selectionList.size() == group[1])
121   assert(aFactory.validate(group[0].feature()))
122   for i in range(group[1]):
123     assert(group[0].groupList().value(i).value().shapeType() == group[2])
124
125 assert(model.checkPythonDump())