Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / SMESH_SWIG / SMESH_Nut.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 #####################################################################
24 #Created                :17/02/2005
25 #Auhtor                 :MASLOV Eugeny, KOVALTCHUK Alexey 
26 #####################################################################
27 #
28 import geompy
29 import salome
30 import smesh
31 import os
32 import math
33
34 #Sketcher_1 creation
35 print "Sketcher creation..."
36 Sketcher_1 = geompy.MakeSketcher("Sketcher:F 100 -57.7:TT 100 57.7:TT 0 115.47:TT -100 57.7:TT -100 -57.7:TT 0 -115.47:WW") 
37 geompy.addToStudy(Sketcher_1, "Sketcher_1")
38 Face_1 = geompy.MakeFace(Sketcher_1, 1)
39 geompy.addToStudy(Face_1, "Face_1")
40
41 #Line creation
42 print "Line  creation..."
43 Line_1 = geompy.MakeLineTwoPnt(geompy.MakeVertex(0,0,0), geompy.MakeVertex(0,0,100))
44 geompy.addToStudy(Line_1, "Line_1")
45
46 #Prism creation
47 print "Prism creation..."
48 Prism_1 = geompy.MakePrismVecH(Face_1, Line_1, 100)
49 geompy.addToStudy(Prism_1, "Prism_1")
50
51 #Sketcher_2 creation
52 print "Sketcher creation..."
53 Sketcher_2 = geompy.MakeSketcher("Sketcher:F 50 0:TT 80 0:TT 112 13:TT 112 48:TT 80 63:TT 80 90:TT 50 90:WW", [0,0,0, 1,0,0, 0,1,0]) 
54 geompy.addToStudy(Sketcher_2, "Sketcher_2")
55 Face_2 = geompy.MakeFace(Sketcher_2, 1)
56 geompy.addToStudy(Face_2, "Face_2")
57
58 #Revolution creation
59 print "Revolution creation..."
60 Revolution_1 = geompy.MakeRevolution(Face_2, Line_1, 2*math.pi)
61 geompy.addToStudy(Revolution_1, "Revolution_1")
62
63 #Common applying
64 print "Common of Revolution and Prism..."
65 Common_1 = geompy.MakeBoolean(Revolution_1, Prism_1, 1)
66 geompy.addToStudy(Common_1, "Common_1")
67
68 #Explode Common_1 on edges
69 CommonExplodedListEdges = geompy.SubShapeAll(Common_1, geompy.ShapeType["EDGE"])
70 for i in range(0, len(CommonExplodedListEdges)):
71     name = "Edge_"+str(i+1)
72     geompy.addToStudyInFather(Common_1, CommonExplodedListEdges[i], name)
73
74 #Fillet applying
75 print "Fillet creation..."
76 Fillet_1 = geompy.MakeFillet(Common_1, 10, geompy.ShapeType["EDGE"], [5])
77 geompy.addToStudy(Fillet_1, "Fillet_1")
78
79 #Chamfer applying
80 print "Chamfer creation..."
81 Chamfer_1 = geompy.MakeChamferEdge(Fillet_1, 10, 10, 16, 50 )
82 geompy.addToStudy(Chamfer_1, "Chamfer_1")
83 Chamfer_2 = geompy.MakeChamferEdge(Chamfer_1, 10, 10, 21, 31 )
84 geompy.addToStudy(Chamfer_2, "Chamfer_2")
85
86 #Import of the shape from "slots.brep"
87 print "Import multi-rotation from the DATA_DIR/Shapes/Brep/slots.brep"
88 thePath = os.getenv("DATA_DIR")
89 theFileName = thePath + "/Shapes/Brep/slots.brep"
90 theShapeForCut = geompy.ImportBREP(theFileName)
91 geompy.addToStudy(theShapeForCut, "slot.brep_1")
92
93 #Cut applying
94 print "Cut..."
95 Cut_1 = geompy.MakeBoolean(Chamfer_2, theShapeForCut, 2)
96 Cut_1_ID = geompy.addToStudy(Cut_1, "Cut_1")
97
98 #Mesh creation
99
100 # -- Init --
101 shape_mesh = salome.IDToObject( Cut_1_ID )
102
103 mesh = smesh.Mesh(shape_mesh, "Nut")
104
105 #HYPOTHESIS CREATION
106 print "-------------------------- Average length"
107 theAverageLength = 5
108 algoReg1D = mesh.Segment()
109 hAvLength = algoReg1D.LocalLength(theAverageLength)
110 print hAvLength.GetName()
111 print hAvLength.GetId()
112 print hAvLength.GetLength()
113 smesh.SetName(hAvLength, "AverageLength_"+str(theAverageLength))
114
115 print "-------------------------- MaxElementArea"
116 theMaxElementArea = 20
117 algoMef = mesh.Triangle(smesh.MEFISTO)
118 hArea = algoMef.MaxElementArea( theMaxElementArea )
119 print hArea.GetName()
120 print hArea.GetId()
121 print hArea.GetMaxElementArea()
122 smesh.SetName(hArea, "MaxElementArea_"+str(theMaxElementArea))
123
124 print "-------------------------- MaxElementVolume"
125 theMaxElementVolume = 150
126 algoNg = mesh.Tetrahedron(smesh.NETGEN)
127 hVolume = algoNg.MaxElementVolume( theMaxElementVolume )
128 print hVolume.GetName()
129 print hVolume.GetId()
130 print hVolume.GetMaxElementVolume()
131 smesh.SetName(hVolume, "MaxElementVolume_"+str(theMaxElementVolume))
132
133
134 print "-------------------------- compute the mesh of the mechanic piece"
135 mesh.Compute()
136
137 print "Information about the Nut:"
138 print "Number of nodes       : ", mesh.NbNodes()
139 print "Number of edges       : ", mesh.NbEdges()
140 print "Number of faces       : ", mesh.NbFaces()
141 print "Number of triangles   : ", mesh.NbTriangles()
142 print "Number of quadrangles : ", mesh.NbQuadrangles()
143 print "Number of volumes     : ", mesh.NbVolumes()
144 print "Number of tetrahedrons: ", mesh.NbTetras()
145
146 salome.sg.updateObjBrowser(1)