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