Salome HOME
Initial version of files for OCC developers
[modules/smesh.git] / src / SMESH_SWIG / meshpy.py
1 # CEA/LGLS 2004, Francis KLOSS (OCC)
2 # ==================================
3
4 # Import
5 # ------
6
7 import geompy
8
9 import salome
10
11 import StdMeshers
12
13 import SMESH
14
15 # Variables
16 # ---------
17
18 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
19 smesh.SetCurrentStudy(salome.myStudy)
20 smeshgui = salome.ImportComponentGUI("SMESH")
21 smeshgui.Init(salome.myStudyId)
22
23 # Hexahedrical meshing
24 #
25 # Examples: cube2pyGibi.py, lines 270-295
26 #           cube2partition.py, lines 72-83
27 # --------------------
28
29 class MeshHexaImpl:
30     piece = 0
31     name  = 0
32     mesh  = 0
33     cpt   = 0
34
35     # Sets algorithm and hypothesis for 1D discretization of the <shape>:
36     #   - algorithm  "Regular_1D"
37     #   - hypothesis "NumberOfSegments" with number of segments <n>
38     # --------------------
39
40     def Mesh1D(self, shape, n, propagate=0):
41         hyp1D=smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
42         smeshgui.SetName(salome.ObjectToID(hyp1D), self.name+"/WireDiscretisation/"+str(self.cpt))
43         self.mesh.AddHypothesis(shape, hyp1D)
44
45         hyp=smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
46         hyp.SetNumberOfSegments(n)
47         smeshgui.SetName(salome.ObjectToID(hyp), self.name+"/Segments_"+str(n)+"/"+str(self.cpt))
48         self.mesh.AddHypothesis(shape, hyp)
49
50         if propagate:
51             hypPro=smesh.CreateHypothesis("Propagation", "libStdMeshersEngine.so")
52             smeshgui.SetName(salome.ObjectToID(hypPro), self.name+"/Propagation/"+str(self.cpt))
53             self.mesh.AddHypothesis(shape, hypPro)
54
55         self.cpt=self.cpt+1
56
57     # Constructor
58     #
59     # Creates mesh on the shape <piece>,
60     # sets GUI name of this mesh to <name>.
61     # Sets the following global algorithms and hypotheses:
62     #   - for 1D discretization:
63     #       - algorithm  "Regular_1D"
64     #       - hypothesis "NumberOfSegments" with number of segments <n>,
65     #   - for 2D discretization:
66     #       - algorithm  "Quadrangle_2D"
67     #   - for 3D discretization:
68     #       - algorithm  "Hexa_3D"
69     # --------------------
70
71     def __init__(self, piece, n, name):
72         self.piece = piece
73         self.name  = name
74
75         self.mesh  = smesh.CreateMesh(piece)
76         smeshgui.SetName(salome.ObjectToID(self.mesh), name)
77
78         self.Mesh1D(piece, n)
79
80         hyp2D=smesh.CreateHypothesis("Quadrangle_2D", "libStdMeshersEngine.so")
81         smeshgui.SetName(salome.ObjectToID(hyp2D), name+"/Quadrangle")
82         self.mesh.AddHypothesis(piece, hyp2D)
83
84         hyp3D=smesh.CreateHypothesis("Hexa_3D", "libStdMeshersEngine.so")
85         smeshgui.SetName(salome.ObjectToID(hyp3D), name+"/ijk")
86         self.mesh.AddHypothesis(piece, hyp3D)
87
88     # Creates sub-mesh of the mesh, created by constructor.
89     # This sub-mesh will be created on edge <edge>.
90     # Set algorithm and hypothesis for 1D discretization of the <edge>:
91     #   - algorithm  "Regular_1D"
92     #   - hypothesis "NumberOfSegments" with number of segments <n>
93     # Note: the <edge> will be automatically published in study under the shape, given in constructor.
94     # --------------------
95
96     def local(self, edge, n):
97         geompy.addToStudyInFather(self.piece, edge, geompy.SubShapeName(edge, self.piece))
98         submesh = self.mesh.GetSubMesh(edge, self.name+"/SubMeshEdge/"+str(self.cpt))
99         self.Mesh1D(edge, n)
100
101     # Creates sub-mesh of the mesh, created by constructor.
102     # This sub-mesh will be created on edge <edge> and propagate the hypothesis on all correspondant edges.
103     # Set algorithm and hypothesis for 1D discretization of the <edge> and all other propagate edges:
104     #   - algorithm  "Regular_1D"
105     #   - hypothesis "NumberOfSegments" with number of segments <n>
106     #   - hypothesis "Propagation" with number of segments <n>
107     # Note: the <edge> will be automatically published in study under the shape, given in constructor.
108     # --------------------
109
110     def Propagate(self, edge, n):
111         geompy.addToStudyInFather(self.piece, edge, geompy.SubShapeName(edge, self.piece))
112         submesh = self.mesh.GetSubMesh(edge, self.name+"/SubMeshEdge/"+str(self.cpt))
113         self.Mesh1D(edge, n, 1)
114
115     # Computes mesh, created by constructor.
116     # --------------------
117
118     def Compute(self):
119         smesh.Compute(self.mesh, self.piece)
120         salome.sg.updateObjBrowser(1)
121
122     # Creates mesh group based on a geometric group
123     # --------------------
124
125     def Group(self, grp, name=""):
126         if name == "":
127             name = grp.GetName()
128         tgeo = geompy.GroupOp.GetType(grp)
129         if tgeo == geompy.ShapeType["VERTEX"]:
130             type = SMESH.NODE
131         elif tgeo == geompy.ShapeType["EDGE"]:
132             type = SMESH.EDGE
133         elif tgeo == geompy.ShapeType["FACE"]:
134             type = SMESH.FACE
135         elif tgeo == geompy.ShapeType["SOLID"]:
136             type = SMESH.VOLUME
137         return self.mesh.CreateGroupFromGEOM(type, name, grp)
138
139     # Export mesh in a MED file
140     # --------------------
141
142     def ExportMED(self, filename, groups=1):
143         self.mesh.ExportMED(filename, groups)
144
145 MeshHexa = MeshHexaImpl