Salome HOME
Copyright update 2021
[modules/shaper.git] / src / ConnectorAPI / Test / Test2882.py
1 # Copyright (C) 2014-2021  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
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(-20, -11.54700538379252, -40, 11.54700538379252)
30 SketchLine_2 = Sketch_1.addLine(-40, 11.54700538379252, -20, 11.54700538379251)
31 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
32 SketchLine_3 = Sketch_1.addLine(-20, 11.54700538379251, -40, -11.54700538379252)
33 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
34 SketchLine_4 = Sketch_1.addLine(-40, -11.54700538379252, -20, -11.54700538379252)
35 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
36 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_4.endPoint())
37 SketchLine_5 = Sketch_1.addLine(-20, 11.54700538379251, -20, -11.54700538379252)
38 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_5.startPoint())
39 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_5.endPoint())
40 SketchLine_6 = Sketch_1.addLine(-15, 8.660254037844391, -15, -8.660254037844384)
41 SketchLine_7 = Sketch_1.addLine(-15, -8.660254037844384, 0, 0)
42 SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
43 SketchLine_8 = Sketch_1.addLine(0, 0, -15, 8.660254037844391)
44 SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
45 SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_6.startPoint(), SketchLine_8.endPoint())
46 SketchCircle_1 = Sketch_1.addCircle(12, 0, 10)
47 SketchLine_9 = Sketch_1.addLine(7, 8.660254037844386, 17, 8.660254037844386)
48 SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchLine_9.startPoint(), SketchCircle_1.results()[1])
49 SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_9.endPoint(), SketchCircle_1.results()[1])
50 SketchLine_10 = Sketch_1.addLine(7, -8.660254037844386, 17, -8.660254037844386)
51 SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchLine_10.startPoint(), SketchCircle_1.results()[1])
52 SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchLine_10.endPoint(), SketchCircle_1.results()[1])
53 SketchConstraintCoincidence_14 = Sketch_1.setCoincident(SketchLine_8.result(), SketchLine_3.startPoint())
54 SketchConstraintCoincidence_15 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_7.result())
55 SketchConstraintCoincidence_16 = Sketch_1.setCoincident(SketchLine_9.result(), SketchLine_6.startPoint())
56 SketchConstraintCoincidence_17 = Sketch_1.setCoincident(SketchLine_10.result(), SketchLine_6.endPoint())
57 SketchConstraintParallel_1 = Sketch_1.setParallel(SketchLine_2.result(), SketchLine_4.result())
58 SketchConstraintParallel_2 = Sketch_1.setParallel(SketchLine_10.result(), SketchLine_9.result())
59 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_2.result(), SketchLine_4.result())
60 SketchConstraintEqual_2 = Sketch_1.setEqual(SketchLine_7.result(), SketchLine_8.result())
61 SketchConstraintEqual_3 = Sketch_1.setEqual(SketchLine_10.result(), SketchLine_9.result())
62 SketchConstraintEqual_4 = Sketch_1.setEqual(SketchLine_3.result(), SketchLine_1.result())
63 SketchConstraintParallel_3 = Sketch_1.setParallel(SketchLine_6.result(), SketchLine_5.result())
64 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 10)
65 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_9.result(), 10)
66 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchCircle_1.center(), SketchLine_7.endPoint(), 12, True)
67 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchLine_7.endPoint(), SketchLine_5.result(), 20, True)
68 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_4.result())
69 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_9.result())
70 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
71 SketchPoint_1 = SketchProjection_1.createdFeature()
72 SketchConstraintCoincidence_18 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchAPI_Point(SketchPoint_1).coordinates())
73 SketchConstraintEqual_5 = Sketch_1.setEqual(SketchLine_6.result(), SketchLine_8.result())
74 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_2.result(), 20)
75 model.do()
76 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "all-in-Sketch_1")], model.selection(), 10, 0)
77 Group_1_objects = [model.selection("FACE", "Extrusion_1_1_2/Generated_Face&Sketch_1/SketchLine_4"), model.selection("FACE", "Extrusion_1_1_3/Generated_Face&Sketch_1/SketchLine_5"), model.selection("FACE", "Extrusion_1_1_1/Generated_Face&Sketch_1/SketchLine_2"), model.selection("FACE", "Extrusion_1_1_1/Generated_Face&Sketch_1/SketchLine_1"), model.selection("FACE", "Extrusion_1_1_2/Generated_Face&Sketch_1/SketchLine_3"), model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_6"), model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7"), model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8")]
78 Group_1 = model.addGroup(Part_1_doc, Group_1_objects)
79 Group_1.setName("planar")
80 Group_1.result().setName("planar")
81 Group_2 = model.addGroup(Part_1_doc, [model.selection("FACE", "Extrusion_1_2/From_Face"), model.selection("FACE", "Extrusion_1_2/To_Face")])
82 Group_2.setName("triangle_top_bottom")
83 Group_2.result().setName("triangle_top_bottom")
84 model.do()
85 model.exportToGEOM(Part_1_doc)
86 model.end()
87
88 # check what is exported to GEOM
89 import salome
90 from salome.geom import geomBuilder
91
92 import os
93 import tempfile
94
95 salome.salome_init(1)
96 aComp = salome.myStudy.FindComponent("GEOM")
97 iterator = salome.myStudy.NewChildIterator(aComp)
98 aComponents = []
99 while iterator.More():
100   aComponents.append(iterator.Value())
101   iterator.Next()
102
103 assert len(aComponents) == 3
104
105 ok, group_0_1 = aComponents[0].FindSubObject(1)
106 assert ok
107 assert group_0_1.GetName() == "planar"
108
109 ok, group_0_2 = aComponents[0].FindSubObject(2)
110 assert not ok
111
112
113 ok, group_1_1 = aComponents[1].FindSubObject(1)
114 assert ok
115 assert group_1_1.GetName() == "planar"
116
117 ok, group_1_2 = aComponents[1].FindSubObject(2)
118 assert ok
119 assert group_1_2.GetName() == "triangle_top_bottom"
120
121 ok, group_1_3 = aComponents[1].FindSubObject(3)
122 assert not ok
123
124
125 ok, group_2_1 = aComponents[2].FindSubObject(1)
126 assert not ok