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