]> SALOME platform Git repositories - modules/shaper.git/blob - src/ConnectorAPI/Test/TestShaperStudy2.py
Salome HOME
Merge remote-tracking branch 'remotes/origin/occ/compounds_processing'
[modules/shaper.git] / src / ConnectorAPI / Test / TestShaperStudy2.py
1 # Copyright (C) 2014-2019  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 os
21 import sys
22 import salome
23
24 salome.salome_init()
25
26 #=========================================================================
27 # A function to get the XAO file path
28 #=========================================================================
29 def getPath(path):
30     shapes_dir = os.path.join(os.getenv("DATA_DIR"), "Shapes")
31     return os.path.join(shapes_dir, path)
32
33 ###
34 ### SHAPER component
35 ###
36
37 from salome.shaper import model
38
39 model.begin()
40 partSet = model.moduleDocument()
41 Part_1 = model.addPart(partSet)
42 Part_1_doc = Part_1.document()
43 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
44 SketchLine_1 = Sketch_1.addLine(147.3929660820667, 79.1580464539047, 58.09363834643254, 79.1580464539047)
45 SketchLine_2 = Sketch_1.addLine(58.09363834643254, 79.1580464539047, 58.09363834643254, 8.969712804393431)
46 SketchLine_3 = Sketch_1.addLine(58.09363834643254, 8.969712804393431, 147.3929660820667, 8.969712804393431)
47 SketchLine_4 = Sketch_1.addLine(147.3929660820667, 8.969712804393431, 147.3929660820667, 79.1580464539047)
48 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
49 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
50 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
51 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
52 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
53 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
54 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
55 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
56 model.do()
57 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f")], model.selection(), 150, 0)
58 Extrusion_1.setName("Box")
59 Extrusion_1.result().setName("Box")
60 Group_1 = model.addGroup(Part_1_doc, "Vertices", [model.selection("VERTEX", "[Box/Generated_Face&Sketch_1/SketchLine_1][Box/Generated_Face&Sketch_1/SketchLine_2][Box/To_Face]"), model.selection("VERTEX", "[Box/Generated_Face&Sketch_1/SketchLine_3][Box/Generated_Face&Sketch_1/SketchLine_4][Box/To_Face]")])
61 Group_1.setName("VerticesGroup")
62 Group_1.result().setName("VerticesGroup")
63 Group_2 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Box/Generated_Face&Sketch_1/SketchLine_4"), model.selection("FACE", "Box/Generated_Face&Sketch_1/SketchLine_3")])
64 Group_2.setName("FacesGroup")
65 Group_2.result().setName("FacesGroup")
66 Field_1 = model.addField(Part_1_doc, 1, "DOUBLE", 3, ["Comp 1", "Comp 2", "Comp 3"], [model.selection("EDGE", "[Box/Generated_Face&Sketch_1/SketchLine_2][Box/Generated_Face&Sketch_1/SketchLine_3]")])
67 Field_1.setName("MyField")
68 Field_1.result().setName("MyField")
69 Field_1.addStep(0, 0, [[0, 0, 0], [1, 1.5, 37.2]])
70
71 model.end()
72
73 ###
74 ### SHAPERSTUDY component
75 ###
76
77 if 'model' in globals():
78   model.publishToShaperStudy()
79 import SHAPERSTUDY
80 Box, VerticesGroup, FacesGroup, MyField, = SHAPERSTUDY.shape(model.featureStringId(Extrusion_1))
81 Box_1, VerticesGroup_1, FacesGroup_1, MyField_1, = SHAPERSTUDY.archive(Box, getPath("Xao/TestShaperStudy2.xao"))
82 ###
83 ### SMESH component
84 ###
85
86 import  SMESH, SALOMEDS
87 from salome.smesh import smeshBuilder
88
89 smesh = smeshBuilder.New()
90 #smesh.SetEnablePublish( False ) # Set to False to avoid publish in study if not needed or in some particular situations:
91                                  # multiples meshes built in parallel, complex and numerous mesh edition (performance)
92
93 Mesh_1 = smesh.Mesh(Box)
94 Regular_1D = Mesh_1.Segment()
95 Number_of_Segments_1 = Regular_1D.NumberOfSegments(4)
96 MEFISTO_2D = Mesh_1.Triangle(algo=smeshBuilder.MEFISTO)
97 Length_From_Edges_1 = MEFISTO_2D.LengthFromEdges()
98 MEFISTO_2D_1 = Mesh_1.Triangle(algo=smeshBuilder.MEFISTO,geom=FacesGroup)
99 Max_Element_Area_1 = MEFISTO_2D_1.MaxElementArea(2)
100 Mesh_1.Compute()
101 Mesh_1.GetMesh().ReplaceShape( Box_1 )
102 SHAPERSTUDY.breakLinkForSubElements(salome.ObjectToSObject(Mesh_1.GetMesh()), Box_1)
103 Mesh_1.Clear()
104 Sub_mesh_1 = MEFISTO_2D_1.GetSubMesh()
105
106
107 ## Set names of Mesh objects
108 smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
109 smesh.SetName(MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D')
110 smesh.SetName(Number_of_Segments_1, 'Number of Segments_1')
111 smesh.SetName(Max_Element_Area_1, 'Max. Element Area_1')
112 smesh.SetName(Length_From_Edges_1, 'Length From Edges_1')
113 smesh.SetName(Mesh_1.GetMesh(), 'Mesh_1')
114 smesh.SetName(Sub_mesh_1, 'Sub-mesh_1')
115
116 assert(Mesh_1.Compute())