Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/smesh.git] / src / SMESH_SWIG / SMESH_Nut.py
1 #  Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 #####################################################################
21 #Created                :17/02/2005
22 #Auhtor                 :MASLOV Eugeny, KOVALTCHUK Alexey 
23 #####################################################################
24
25 import geompy
26 import salome
27 import smesh
28 import os
29 import math
30
31 #Sketcher_1 creation
32 print "Sketcher creation..."
33 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") 
34 geompy.addToStudy(Sketcher_1, "Sketcher_1")
35 Face_1 = geompy.MakeFace(Sketcher_1, 1)
36 geompy.addToStudy(Face_1, "Face_1")
37
38 #Line creation
39 print "Line  creation..."
40 Line_1 = geompy.MakeLineTwoPnt(geompy.MakeVertex(0,0,0), geompy.MakeVertex(0,0,100))
41 geompy.addToStudy(Line_1, "Line_1")
42
43 #Prism creation
44 print "Prism creation..."
45 Prism_1 = geompy.MakePrismVecH(Face_1, Line_1, 100)
46 geompy.addToStudy(Prism_1, "Prism_1")
47
48 #Sketcher_2 creation
49 print "Sketcher creation..."
50 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]) 
51 geompy.addToStudy(Sketcher_2, "Sketcher_2")
52 Face_2 = geompy.MakeFace(Sketcher_2, 1)
53 geompy.addToStudy(Face_2, "Face_2")
54
55 #Revolution creation
56 print "Revolution creation..."
57 Revolution_1 = geompy.MakeRevolution(Face_2, Line_1, 2*math.pi)
58 geompy.addToStudy(Revolution_1, "Revolution_1")
59
60 #Common applying
61 print "Common of Revolution and Prism..."
62 Common_1 = geompy.MakeBoolean(Revolution_1, Prism_1, 1)
63 geompy.addToStudy(Common_1, "Common_1")
64
65 #Explode Common_1 on edges
66 CommonExplodedListEdges = geompy.SubShapeAll(Common_1, geompy.ShapeType["EDGE"])
67 for i in range(0, len(CommonExplodedListEdges)):
68     name = "Edge_"+str(i+1)
69     geompy.addToStudyInFather(Common_1, CommonExplodedListEdges[i], name)
70
71 #Fillet applying
72 print "Fillet creation..."
73 Fillet_1 = geompy.MakeFillet(Common_1, 10, geompy.ShapeType["EDGE"], [6])
74 geompy.addToStudy(Fillet_1, "Fillet_1")
75
76 #Chamfer applying
77 print "Chamfer creation..."
78 Chamfer_1 = geompy.MakeChamferEdge(Fillet_1, 10, 10, 16, 50 )
79 geompy.addToStudy(Chamfer_1, "Chamfer_1")
80 Chamfer_2 = geompy.MakeChamferEdge(Chamfer_1, 10, 10, 21, 31 )
81 geompy.addToStudy(Chamfer_2, "Chamfer_2")
82
83 #Import of the shape from "slots.brep"
84 print "Import multi-rotation from the DATA_DIR/Shapes/Brep/slots.brep"
85 thePath = os.getenv("DATA_DIR")
86 theFileName = thePath + "/Shapes/Brep/slots.brep"
87 theShapeForCut = geompy.ImportBREP(theFileName)
88 geompy.addToStudy(theShapeForCut, "slot.brep_1")
89
90 #Cut applying
91 print "Cut..."
92 Cut_1 = geompy.MakeBoolean(Chamfer_2, theShapeForCut, 2)
93 Cut_1_ID = geompy.addToStudy(Cut_1, "Cut_1")
94
95 #Mesh creation
96
97 # -- Init --
98 shape_mesh = salome.IDToObject( Cut_1_ID )
99
100 mesh = smesh.Mesh(shape_mesh, "Nut")
101
102 #HYPOTHESIS CREATION
103 print "-------------------------- Average length"
104 theAverageLength = 5
105 algoReg1D = mesh.Segment()
106 hAvLength = algoReg1D.LocalLength(theAverageLength)
107 print hAvLength.GetName()
108 print hAvLength.GetId()
109 print hAvLength.GetLength()
110 smesh.SetName(hAvLength, "AverageLength_"+str(theAverageLength))
111
112 print "-------------------------- MaxElementArea"
113 theMaxElementArea = 20
114 algoMef = mesh.Triangle(smesh.MEFISTO)
115 hArea = algoMef.MaxElementArea( theMaxElementArea )
116 print hArea.GetName()
117 print hArea.GetId()
118 print hArea.GetMaxElementArea()
119 smesh.SetName(hArea, "MaxElementArea_"+str(theMaxElementArea))
120
121 print "-------------------------- MaxElementVolume"
122 theMaxElementVolume = 150
123 algoNg = mesh.Tetrahedron(smesh.NETGEN)
124 hVolume = algoNg.MaxElementVolume( theMaxElementVolume )
125 print hVolume.GetName()
126 print hVolume.GetId()
127 print hVolume.GetMaxElementVolume()
128 smesh.SetName(hVolume, "MaxElementVolume_"+str(theMaxElementVolume))
129
130
131 print "-------------------------- compute the mesh of the mechanic piece"
132 mesh.Compute()
133
134 print "Information about the Nut:"
135 print "Number of nodes       : ", mesh.NbNodes()
136 print "Number of edges       : ", mesh.NbEdges()
137 print "Number of faces       : ", mesh.NbFaces()
138 print "Number of triangles   : ", mesh.NbTriangles()
139 print "Number of quadrangles : ", mesh.NbQuadrangles()
140 print "Number of volumes     : ", mesh.NbVolumes()
141 print "Number of tetrahedrons: ", mesh.NbTetras()
142
143 salome.sg.updateObjBrowser(1)