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