Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / SMESH_SWIG / SMESH_mechanic_editor.py
1 #  -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 #  This library is free software; you can redistribute it and/or
8 #  modify it under the terms of the GNU Lesser General Public
9 #  License as published by the Free Software Foundation; either
10 #  version 2.1 of the License.
11 #
12 #  This library is distributed in the hope that it will be useful,
13 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 #  Lesser General Public License for more details.
16 #
17 #  You should have received a copy of the GNU Lesser General Public
18 #  License along with this library; if not, write to the Free Software
19 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23 #  File   : SMESH_withHole.py
24 #  Author : Lucien PIGNOLONI
25 #  Module : SMESH
26 #  $Header$
27 #-------------------------------------------------------------------------
28 #
29 import salome
30 import geompy
31 import smesh
32
33 # ---------------------------- GEOM --------------------------------------
34
35 # ---- define contigous arcs and segment to define a closed wire
36 p1   = geompy.MakeVertex( 100.0,   0.0,  0.0 )
37 p2   = geompy.MakeVertex(  50.0,  50.0,  0.0 )
38 p3   = geompy.MakeVertex( 100.0, 100.0,  0.0 )
39 arc1 = geompy.MakeArc( p1, p2, p3 )
40
41 p4   = geompy.MakeVertex( 170.0, 100.0, 0.0 )
42 seg1 = geompy.MakeVector( p3, p4 )
43
44 p5   = geompy.MakeVertex( 200.0, 70.0, 0.0 )
45 p6   = geompy.MakeVertex( 170.0, 40.0, 0.0 )
46 arc2 = geompy.MakeArc( p4, p5, p6 )
47
48 p7   = geompy.MakeVertex( 120.0, 30.0, 0.0 )
49 arc3 = geompy.MakeArc( p6, p7, p1 )
50
51 # ---- define a closed wire with arcs and segment
52 List1 = []
53 List1.append( arc1 )
54 List1.append( seg1 )
55 List1.append( arc2 )
56 List1.append( arc3 )
57
58 wire1 = geompy.MakeWire( List1 )
59 Id_wire1 = geompy.addToStudy( wire1, "wire1" )
60
61 # ---- define a planar face with wire
62 WantPlanarFace = 1 #True
63 face1 = geompy.MakeFace( wire1, WantPlanarFace )
64 Id_face1 = geompy.addToStudy( face1, "face1" )
65
66 # ---- create a shape by extrusion
67 pO = geompy.MakeVertex( 0.0, 0.0,   0.0 )
68 pz = geompy.MakeVertex( 0.0, 0.0, 100.0 )
69 vz = geompy.MakeVector( pO, pz )
70
71 prism1 = geompy.MakePrismVecH( face1, vz, 100.0 )
72 Id_prism1 = geompy.addToStudy( prism1, "prism1" )
73
74 # ---- create two cylinders
75 pc1 = geompy.MakeVertex(  90.0, 50.0, -40.0 )
76 pc2 = geompy.MakeVertex( 170.0, 70.0, -40.0 )
77
78 radius = 20.0
79 height = 180.0
80 cyl1 = geompy.MakeCylinder( pc1, vz, radius, height )
81 cyl2 = geompy.MakeCylinder( pc2, vz, radius, height )
82
83 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
84 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
85
86 # ---- cut with cyl1
87 shape = geompy.MakeBoolean( prism1, cyl1, 2 )
88
89 # ---- fuse with cyl2 to obtain the final mechanic piece :)
90 mechanic = geompy.MakeBoolean( shape, cyl2, 3 )
91 Id_mechanic = geompy.addToStudy( mechanic, "mechanic" )
92
93 # ---- explode on faces
94 SubFaceL = geompy.SubShapeAllSorted(mechanic, geompy.ShapeType["FACE"])
95
96 # ---- add a face sub shape in study to be meshed different
97 sub_face1 = SubFaceL[0]
98 name      = geompy.SubShapeName( sub_face1, mechanic )
99
100 Id_SubFace1 = geompy.addToStudyInFather( mechanic, sub_face1, name )
101
102 # ---- add a face sub shape in study to be meshed different
103 sub_face2 = SubFaceL[4]
104 name      = geompy.SubShapeName( sub_face2, mechanic )
105
106 Id_SubFace2 = geompy.addToStudyInFather( mechanic, sub_face2, name )
107
108 # ---- add a face sub shape in study to be meshed different
109 sub_face3 = SubFaceL[5]
110 name      = geompy.SubShapeName( sub_face3, mechanic )
111
112 Id_SubFace3 = geompy.addToStudyInFather( mechanic, sub_face3, name )
113
114 # ---- add a face sub shape in study to be meshed different
115 sub_face4 = SubFaceL[10]
116 name      = geompy.SubShapeName( sub_face4, mechanic )
117
118 Id_SubFace4 = geompy.addToStudyInFather( mechanic, sub_face4, name )
119
120 # ---------------------------- SMESH --------------------------------------
121
122 # -- Init --
123 shape_mesh = salome.IDToObject( Id_mechanic )
124
125 mesh = smesh.Mesh(shape_mesh, "Mesh_mechanic")
126
127 print "-------------------------- NumberOfSegments"
128
129 numberOfSegment = 10
130
131 algo = mesh.Segment()
132 hypNbSeg = algo.NumberOfSegments(numberOfSegment)
133 print hypNbSeg.GetName()
134 print hypNbSeg.GetId()
135 print hypNbSeg.GetNumberOfSegments()
136 smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegment))
137
138
139 print "-------------------------- MaxElementArea"
140
141 maxElementArea = 25
142
143 algo = mesh.Triangle()
144 hypArea25 = algo.MaxElementArea(maxElementArea)
145 print hypArea25.GetName()
146 print hypArea25.GetId()
147 print hypArea25.GetMaxElementArea()
148 smesh.SetName(hypArea25, "MaxElementArea_" + str(maxElementArea))
149
150
151 # Create submesh on sub_face1 - sub_face4
152 # ---------------------------------------
153
154 # Set 2D algorithm to submesh on sub_face1
155 algo = mesh.Quadrangle(sub_face1)
156 smesh.SetName(algo.GetSubMesh(), "SubMeshFace1")
157 submesh1 = algo.GetSubMesh()
158
159 # Set 2D algorithm to submesh on sub_face2
160 algo = mesh.Quadrangle(sub_face2)
161 smesh.SetName(algo.GetSubMesh(), "SubMeshFace2")
162 submesh2 = algo.GetSubMesh()
163
164 # Set 2D algorithm to submesh on sub_face3
165 algo = mesh.Quadrangle(sub_face3)
166 smesh.SetName(algo.GetSubMesh(), "SubMeshFace3")
167 submesh3 = algo.GetSubMesh()
168
169 # Set 2D algorithm to submesh on sub_face4
170 algo = mesh.Quadrangle(sub_face4)
171 smesh.SetName(algo.GetSubMesh(), "SubMeshFace4")
172 submesh4 = algo.GetSubMesh()
173
174
175 print "-------------------------- compute the mesh of the mechanic piece"
176
177 mesh.Compute()
178
179 print "Information about the Mesh_mechanic:"
180 print "Number of nodes       : ", mesh.NbNodes()
181 print "Number of edges       : ", mesh.NbEdges()
182 print "Number of faces       : ", mesh.NbFaces()
183 print "Number of triangles   : ", mesh.NbTriangles()
184 print "Number of quadrangles : ", mesh.NbQuadrangles()
185 print "Number of volumes     : ", mesh.NbVolumes()
186 print "Number of tetrahedrons: ", mesh.NbTetras()
187
188
189 #1 cutting of quadrangles of the 'SubMeshFace2' submesh
190 mesh.SplitQuadObject(submesh2, 1)
191
192 #2 cutting of triangles of the group
193 FacesTriToQuad = [2381, 2382, 2383, 2384, 2385, 2386, 2387, 2388, 2389, 2390, 2391, 2392, 2393, 2394, 2395, 2396, 2397, 2398, 2399, 2400, 2401, 2402, 2403, 2404, 2405, 2406, 2407, 2408, 2409, 2410, 2411, 2412, 2413, 2414, 2415, 2416, 2417, 2418, 2419, 2420, 2421, 2422]
194 GroupTriToQuad = mesh.MakeGroupByIds("Group of faces (quad)", smesh.FACE, FacesTriToQuad)
195 mesh.TriToQuadObject(GroupTriToQuad, None , 1.57)
196
197 #3 extrusion of the group
198 point = smesh.PointStruct(0, 0, 5)
199 vector = smesh.DirStruct(point) 
200 mesh.ExtrusionSweepObject(GroupTriToQuad, vector, 5)
201
202 #4 mirror object
203 mesh.Mirror([], smesh.AxisStruct(0, 0, 0, 0, 0, 0), smesh.POINT, 0) 
204
205 #5 mesh translation
206 point = smesh.PointStruct(10, 10, 10)
207 vector = smesh.DirStruct(point) 
208 mesh.Translate([], vector, 0)
209
210 #6 mesh rotation
211 axisXYZ = smesh.AxisStruct(0, 0, 0, 10, 10, 10)
212 angle180 =  180*3.141/180
213 mesh.Rotate([], axisXYZ, angle180, 0)
214
215 #7 group smoothing
216 FacesSmooth = [864, 933, 941, 950, 1005, 1013]
217 GroupSmooth = mesh.MakeGroupByIds("Group of faces (smooth)", smesh.FACE, FacesSmooth)
218 mesh.SmoothObject(GroupSmooth, [], 20, 2, smesh.CENTROIDAL_SMOOTH)
219
220 #8 rotation sweep object
221 FacesRotate = [492, 493, 502, 503]
222 GroupRotate = mesh.MakeGroupByIds("Group of faces (rotate)", smesh.FACE, FacesRotate)
223 angle45 =  45*3.141/180
224 axisXYZ = smesh.AxisStruct(-38.3128, -73.3658, -133.321, -13.3402, -13.3265, 6.66632)
225 mesh.RotationSweepObject(GroupRotate, axisXYZ, angle45, 4, 1e-5)
226
227 #9 reorientation of the submesh1
228 mesh.ReorientObject(submesh1)
229
230 salome.sg.updateObjBrowser(1)