Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / SMESH_SWIG / ex06_hole1boolean.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 #
25 from geompy import *
26
27 import smesh
28
29 # Geometry
30 # ========
31
32 # A not centered holed cube build by boolean geometric operations
33
34 # Values
35 # ------
36
37 ox = 0
38 oy = 0
39 oz = 0
40
41 longueur1 = 30
42 longueur2 = 70
43
44 largeur1  = 30
45 largeur2  = 50
46
47 hauteur   = 50
48
49 rayon = 10
50
51 # Triangular face
52 # ---------------
53
54 def triangle(p1, p2, p3):
55     l = []
56     l.append(MakeEdge(p1, p2))
57     l.append(MakeEdge(p2, p3))
58     l.append(MakeEdge(p3, p1))
59     w = MakeWire(l)
60     return MakeFace(w, 1)
61
62 # Points
63 # ------
64
65 basePoint111 = MakeVertex(ox-longueur1,  oy, oz-largeur1)
66 basePoint211 = MakeVertex(ox+longueur2,  oy, oz-largeur1)
67 basePoint112 = MakeVertex(ox-longueur1,  oy, oz+largeur2)
68 basePoint212 = MakeVertex(ox+longueur2,  oy, oz+largeur2)
69
70 holePoint    = MakeVertex(ox, oy, oz)
71
72 # Faces
73 # -----
74
75 baseFace1 = triangle(basePoint111, basePoint211, holePoint)
76 baseFace2 = triangle(basePoint211, basePoint212, holePoint)
77 baseFace3 = triangle(basePoint212, basePoint112, holePoint)
78 baseFace4 = triangle(basePoint112, basePoint111, holePoint)
79
80 # Solids
81 # ------
82
83 baseVector = MakeVectorDXDYDZ(0, 1, 0)
84
85 baseSolid1 = MakePrismVecH(baseFace1, baseVector, hauteur)
86 baseSolid2 = MakePrismVecH(baseFace2, baseVector, hauteur)
87 baseSolid3 = MakePrismVecH(baseFace3, baseVector, hauteur)
88 baseSolid4 = MakePrismVecH(baseFace4, baseVector, hauteur)
89
90 holeSolid = MakeCylinder(holePoint, baseVector, rayon, hauteur)
91
92 # Boolean operations
93 # ------------------
94
95 baseHexa1 = MakeCut(baseSolid1, holeSolid)
96 baseHexa2 = MakeCut(baseSolid2, holeSolid)
97 baseHexa3 = MakeCut(baseSolid3, holeSolid)
98 baseHexa4 = MakeCut(baseSolid4, holeSolid)
99
100 # Compound, glue and repair
101 # -------------------------
102
103 c_l = []
104 c_l.append(baseHexa1)
105 c_l.append(baseHexa2)
106 c_l.append(baseHexa3)
107 c_l.append(baseHexa4)
108
109 c_cpd = MakeCompound(c_l)
110 c_glu = MakeGlueFaces(c_cpd, 1.e-5)
111 piece = RemoveExtraEdges(c_glu)
112
113 # Add in study
114 # ------------
115
116 piece_id = addToStudy(piece, "ex06_hole1boolean")
117
118 # Meshing
119 # =======
120
121 # Create a hexahedral mesh
122 # ------------------------
123
124 hexa = smesh.Mesh(piece, "ex06_hole1boolean:hexa")
125
126 algo = hexa.Segment()
127
128 algo.NumberOfSegments(11)
129
130 hexa.Quadrangle()
131
132 hexa.Hexahedron()
133
134 # Create local hypothesis
135 # -----------------------
136
137 edge1 = GetEdgeNearPoint(piece, MakeVertex(ox, oy, oz-largeur1))
138 algo1 = hexa.Segment(edge1)
139 algo1.NumberOfSegments(3)
140 algo1.Propagation()
141
142 edge2 = GetEdgeNearPoint(piece, MakeVertex(ox-longueur1, oy, oz))
143 algo2 = hexa.Segment(edge2)
144 algo2.NumberOfSegments(5)
145 algo2.Propagation()
146
147 edge3 = GetEdgeNearPoint(piece, MakeVertex(ox, oy, oz+largeur2))
148 algo3 = hexa.Segment(edge3)
149 algo3.NumberOfSegments(7)
150 algo3.Propagation()
151
152 edge4 = GetEdgeNearPoint(piece, MakeVertex(ox+longueur2, oy, oz))
153 algo4 = hexa.Segment(edge4)
154 algo4.NumberOfSegments(9)
155 algo4.Propagation()
156
157 # Mesh calculus
158 # -------------
159
160 hexa.Compute()