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