Salome HOME
Merge from V6_main_20120808 08Aug12
[samples/datafiles.git] / Superv / Python / InLine_Nut.py
1 #  Copyright (C) 2007-2011  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                 :KOVALTCHUK Alexey 
25 #####################################################################
26 #
27 def Geometry(y1=50, y2=90):
28     from batchmode_geompy import *
29     import  math 
30     import os
31     #Sketcher_1 creation
32     Sketcher_1 = 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") 
33     addToStudy(Sketcher_1, "Sketcher_1")
34     Face_1 = MakeFace(Sketcher_1, 1)
35     addToStudy(Face_1, "Face_1")
36     #Line creation
37     Line_1 = MakeLineTwoPnt(MakeVertex(0,0,0), MakeVertex(0,0,100))
38     addToStudy(Line_1, "Line_1")
39     #Prism creation
40     Prism_1 = MakePrismVecH(Face_1, Line_1, 100)
41     addToStudy(Prism_1, "Prism_1")
42     #Sketcher_2 creation
43     #"Sketcher:F 50 0:TT 80 0:TT 112 13:TT 112 48:TT 80 63:TT 80 90:TT 50 90:WW"
44     command = "Sketcher:F " + str(y1)+ " 0:TT 80 0:TT 112 13:TT 112 48:TT 80 63:TT 80 " + str(y2)+ ":TT " + str(y1) + " " + str(y2) + ":WW"
45     Sketcher_2 = MakeSketcher(command, [0,0,0, 1,0,0, 0,1,0])
46     addToStudy(Sketcher_2, "Sketcher_2")
47     Face_2 = MakeFace(Sketcher_2, 1)
48     addToStudy(Face_2, "Face_2")
49     #Revolution creation
50     Revolution_1 = MakeRevolution(Face_2, Line_1, 2*math.pi)
51     addToStudy(Revolution_1, "Revolution_1")
52     #Common applying
53     Common_1 = MakeBoolean(Revolution_1, Prism_1, 1)
54     addToStudy(Common_1, "Common_1")
55     #Explode Common_1 on edges
56     CommonExplodedListEdges = SubShapeAll(Common_1, ShapeType["EDGE"])
57     for i in range(0, len(CommonExplodedListEdges)):
58         name = "Edge_"+str(i+1)
59         addToStudyInFather(Common_1, CommonExplodedListEdges[i], name)
60     #Fillet applying
61     ID = GetSubShapeID(Common_1, CommonExplodedListEdges[0])
62     Fillet_1 = MakeFillet(Common_1, 10, ShapeType["EDGE"], [6])
63     addToStudy(Fillet_1, "Fillet_1")
64     #Chamfer applying
65     Chamfer_1 = MakeChamferEdge(Fillet_1, 10, 10, 16, 50 )
66     addToStudy(Chamfer_1, "Chamfer_1")
67     Chamfer_2 = MakeChamferEdge(Chamfer_1, 10, 10, 21, 31 )
68     addToStudy(Chamfer_2, "Chamfer_2")
69     #Import of the shape from "slots.brep"
70     thePath = os.getenv("DATA_DIR")
71     theFileName = thePath + "/Shapes/Brep/slots.brep"
72     theShapeForCut = ImportBREP(theFileName)
73     addToStudy(theShapeForCut, "slot.brep_1")
74     #Cut applying
75     Cut_1 = MakeBoolean(Chamfer_2, theShapeForCut, 2)
76     addToStudy(Cut_1, "Cut_1")
77     return Cut_1
78     
79
80 def Mesh(theNameOfTheShape = "Cut_1", theAverageLength = 5, theMaxElementArea = 20, theMaxElementVolume = 150):
81     #Format of the <theNameOfTheShape> parameter is: "[[first level object/[second level object/[.../]]]Name"
82     from batchmode_smesh import *
83     import StdMeshers
84     smesh.SetCurrentStudy(myStudy)
85     theNameOfTheShape = "/Geometry/"+ str(theNameOfTheShape)
86     SObject = myStudy.FindObjectByPath(theNameOfTheShape)
87     if SObject == None:
88         raise RuntimeError, "It is an incorrect object name..."
89     shape_mesh = IDToObject( SObject.GetID() )
90     mesh = smesh.CreateMesh(shape_mesh)
91     idmesh = ObjectToID(mesh)
92     SetName( idmesh, "Mesh" )
93
94     #HYPOTHESIS CREATION
95     print "-------------------------- Average length"
96     theName = "AverageLength" + str(theAverageLength)
97     hAvLength = smesh.CreateHypothesis( "LocalLength", "libStdMeshersEngine.so" )
98     hAvLength.SetLength( theAverageLength )
99     print hAvLength.GetName()
100     print hAvLength.GetId()
101     SetName(ObjectToID(hAvLength), theName)
102
103     print "-------------------------- MaxElementArea"
104     theName = "MaxElementArea" + str( theMaxElementArea )
105     hArea = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
106     hArea.SetMaxElementArea( theMaxElementArea )
107     print hArea.GetName()
108     print hArea.GetId()
109     print hArea.GetMaxElementArea()
110     SetName(ObjectToID(hArea), theName)
111     
112     print "-------------------------- MaxElementVolume"
113     theName = "MaxElementVolume" + str( theMaxElementVolume )
114     hVolume = smesh.CreateHypothesis( "MaxElementVolume", "libStdMeshersEngine.so" )
115     hVolume.SetMaxElementVolume( theMaxElementVolume )
116     print hVolume.GetName()
117     print hVolume.GetId()
118     print hVolume.GetMaxElementVolume()
119     SetName(ObjectToID(hVolume), theName)
120     
121     mesh.AddHypothesis(shape_mesh, hAvLength)
122     mesh.AddHypothesis(shape_mesh, hArea)
123     mesh.AddHypothesis(shape_mesh, hVolume)
124     
125     print "-------------------------- Regular_1D"
126     
127     algoReg1D = smesh.CreateHypothesis( "Regular_1D", "libStdMeshersEngine.so" )
128     listHyp = algoReg1D.GetCompatibleHypothesis()
129     for hyp in listHyp:
130         print hyp
131         print algoReg1D.GetName()
132         print algoReg1D.GetId()
133     SetName(ObjectToID(algoReg1D), "Wire discretisation")
134         
135     print "-------------------------- MEFISTO_2D"
136     algoMef = smesh.CreateHypothesis( "MEFISTO_2D", "libStdMeshersEngine.so" )
137     listHyp = algoMef.GetCompatibleHypothesis()
138     for hyp in listHyp:
139         print hyp
140         print algoMef.GetName()
141         print algoMef.GetId()
142     SetName(ObjectToID(algoMef), "Triangle (Mefisto)")
143
144     print "-------------------------- NETGEN_3D"        
145     algoNg = smesh.CreateHypothesis( "NETGEN_3D", "libNETGENEngine.so" )
146     for hyp in listHyp:
147         print hyp
148         print algoNg.GetName()
149         print algoNg.GetId()
150     SetName(ObjectToID(algoNg), "Tetrahedron (NETGEN)")
151     mesh.AddHypothesis(shape_mesh, algoReg1D)
152     mesh.AddHypothesis(shape_mesh, algoMef)
153     mesh.AddHypothesis(shape_mesh, algoNg)
154     smesh.Compute(mesh,shape_mesh)
155             
156     print "Information about the mesh:"
157     print "Number of nodes       : ", mesh.NbNodes()
158     print "Number of edges       : ", mesh.NbEdges()
159     print "Number of faces       : ", mesh.NbFaces()
160     print "Number of triangles   : ", mesh.NbTriangles()
161     print "Number of quadrangles : ", mesh.NbQuadrangles()
162     print "Number of volumes     : ", mesh.NbVolumes()
163     print "Number of tetrahedrons: ", mesh.NbTetras()
164             
165