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