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