Salome HOME
Copyright update 2022
[modules/shaper.git] / src / ConnectorAPI / Test / TestExportToGEOMPartSet.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 import salome
21 from ModelAPI import *
22 from salome.shaper import model
23
24
25 import os
26 import tempfile
27
28 salome.standalone()
29 from salome.geom import geomBuilder
30 salome.salome_init(1)
31 geompy = geomBuilder.New()
32
33 ## Get the last object published in the GEOM section of the object browser
34 def getGEOMShape(index):
35   sb = salome.myStudy.NewBuilder()
36   comp = salome.myStudy.FindComponent("GEOM")
37   obj = None
38   if comp:
39     iterator = salome.myStudy.NewChildIterator( comp )
40     sobj = None
41     i = index + 1
42     while iterator.More() and i:
43       sobj = iterator.Value()
44       iterator.Next()
45       i = i - 1
46     if i == 0 and sobj:
47       obj = sobj.GetObject()
48   else:
49     raise Exception("GEOM component " + str(index) + " not found.")
50   return obj
51
52 # create 4 parts:
53 #  just an extrusiob
54 #  extrusion with faces-group
55 #  polyline with vertices-field
56 #  part of one construction point
57
58 model.begin()
59 partSet = model.moduleDocument()
60 Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
61 SketchLine_1 = Sketch_1.addLine(7, 0, 0, 0)
62 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "Origin"), False)
63 SketchPoint_1 = SketchProjection_1.createdFeature()
64 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchPoint_1.result())
65 SketchLine_2 = Sketch_1.addLine(0, 0, 0, 9)
66 SketchLine_3 = Sketch_1.addLine(0, 9, 7, 9)
67 SketchLine_4 = Sketch_1.addLine(7, 9, 7, 0)
68 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
69 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
70 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
71 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
72 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
73 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
74 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
75 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
76 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_3.result(), 7)
77 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_4.result(), 9)
78 SketchCircle_1 = Sketch_1.addCircle(3, 5, 2)
79 SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchCircle_1.center(), SketchLine_1.startPoint(), 5)
80 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchCircle_1.center(), SketchLine_1.endPoint(), 3)
81 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 2)
82 model.do()
83 Part_1 = model.addPart(partSet)
84 Part_1_doc = Part_1.document()
85 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "PartSet/Sketch_1/Face-SketchLine_4r-SketchLine_3r-SketchLine_2r-SketchLine_1r-SketchCircle_1_2r")], model.selection(), 10, 0)
86 model.do()
87 Part_2 = model.addPart(partSet)
88 Part_2_doc = Part_2.document()
89 Extrusion_2 = model.addExtrusion(Part_2_doc, [model.selection("FACE", "PartSet/Sketch_1/Face-SketchCircle_1_2f")], model.selection(), 10, 0)
90 Group_1 = model.addGroup(Part_2_doc, [model.selection("FACE", "Extrusion_1_1/Generated_Face&PartSet/Sketch_1/SketchCircle_1_2"), model.selection("FACE", "Extrusion_1_1/To_Face")])
91 model.do()
92 Part_3 = model.addPart(partSet)
93 Part_3_doc = Part_3.document()
94 Polyline_1_objects = [model.selection("VERTEX", "PartSet/Sketch_1/SketchLine_3_StartVertex"), model.selection("VERTEX", "PartSet/Sketch_1/SketchLine_4_EndVertex"), model.selection("VERTEX", "PartSet/Sketch_1/SketchLine_3_EndVertex")]
95 Polyline_1 = model.addPolyline3D(Part_3_doc, Polyline_1_objects, True)
96 Field_1_objects = [model.selection("VERTEX", "[Polyline_1_1/Generated_Edge&PartSet/Sketch_1/SketchLine_3_StartVertex]e[Polyline_1_1/Generated_Edge&PartSet/Sketch_1/SketchLine_4_EndVertex]e"), model.selection("VERTEX", "[Polyline_1_1/Generated_Edge&PartSet/Sketch_1/SketchLine_4_EndVertex]e[Polyline_1_1/Generated_Edge&PartSet/Sketch_1/SketchLine_3_EndVertex]e"), model.selection("VERTEX", "[Polyline_1_1/Generated_Edge&PartSet/Sketch_1/SketchLine_3_StartVertex]e[Polyline_1_1/Generated_Edge&PartSet/Sketch_1/SketchLine_3_EndVertex]e")]
97 Field_1 = model.addField(Part_3_doc, 2, "DOUBLE", 1, ["Comp 1"], Field_1_objects)
98 Field_1.addStep(0, 0, [[1.5], [1.1], [2.4], [3]])
99 Field_1.addStep(1, 2, [[1], [7], [5], [1.9]])
100 model.do()
101 Part_4 = model.addPart(partSet)
102 Part_4_doc = Part_4.document()
103 Point_2 = model.addPoint(Part_4_doc, model.selection("EDGE", "PartSet/Sketch_1/SketchCircle_1_2"))
104 model.end()
105
106 # Activate Partset to export to geom all Parts with group and filed where it is needed
107 model.begin()
108 aSession = ModelAPI_Session.get()
109 partSet = aSession.moduleDocument()
110 aSession.setActiveDocument(partSet, True)
111 model.end()
112
113 # export to GEOM
114 model.begin()
115 model.exportToGEOM(Part_1_doc)
116 model.end()
117
118 # check that in GEOM module there are results:
119 # extrusion of the first part
120 # extrusion with group of the second part
121 # extrusion with filed of the third part
122 shape1 = getGEOMShape(0)
123 assert(shape1)
124 assert(shape1.GetName() == "Part_1")
125 assert(geompy.NumberOfSolids(shape1) == 1)
126 assert(not salome.ObjectToSObject(shape1).FindSubObject(1)[1])
127
128 shape2 = getGEOMShape(1)
129 assert(shape2)
130 assert(shape2.GetName() == "Part_2")
131 assert(geompy.NumberOfSolids(shape2) == 1)
132 group = salome.ObjectToSObject(shape2).FindSubObject(1)[1].GetObject()
133 assert(group)
134 assert(group.GetName() == "Group_1")
135 assert(geompy.NumberOfFaces(group) == 2)
136
137 shape3 = getGEOMShape(2)
138 assert(shape3)
139 assert(shape3.GetName() == "Part_3")
140 assert(geompy.NumberOfSolids(shape3) == 0)
141 assert(geompy.NumberOfSubShapes(shape3, geompy.ShapeType["VERTEX"]) == 3)
142 field = salome.ObjectToSObject(shape3).FindSubObject(1)[1].GetObject()
143 assert(field)
144 assert(field.GetName() == "Field_1")
145 assert(field.GetSteps() == [1, 2])
146
147 shape4 = getGEOMShape(3)
148 assert(not shape4)