1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 # ==================================
29 from salome.geom import geomBuilder
30 geompy = geomBuilder.New()
32 import SMESH, SALOMEDS
33 from salome.smesh import smeshBuilder
34 smesh = smeshBuilder.New()
39 # With hexahedral, build a box partially holed by a not centered cylinder with a thickness
57 def triangle(p1, p2, p3):
59 l.append(geompy.MakeEdge(p1, p2))
60 l.append(geompy.MakeEdge(p2, p3))
61 l.append(geompy.MakeEdge(p3, p1))
62 w = geompy.MakeWire(l)
63 return geompy.MakeFace(w, 1)
68 # Vertex of the holed part
69 # ------------------------
71 hole_point_11 = geompy.MakeVertex(0 , 0 , 0)
72 hole_point_21 = geompy.MakeVertex(box_dx, 0 , 0)
73 hole_point_12 = geompy.MakeVertex(0 , box_dy, 0)
74 hole_point_22 = geompy.MakeVertex(box_dx, box_dy, 0)
76 hole_center = geompy.MakeVertex(cyl_x, cyl_y, 0)
78 # Faces of the holed part
79 # -----------------------
81 hole_face_1 = triangle(hole_point_11, hole_point_21, hole_center)
82 hole_face_2 = triangle(hole_point_21, hole_point_22, hole_center)
83 hole_face_3 = triangle(hole_point_12, hole_point_22, hole_center)
84 hole_face_4 = triangle(hole_point_11, hole_point_12, hole_center)
86 # Solids of the holed part
87 # ------------------------
89 cyl_dir = geompy.MakeVectorDXDYDZ(0, 0, 1)
91 hole_solid_1 = geompy.MakePrismVecH(hole_face_1, cyl_dir, cyl_dz)
92 hole_solid_2 = geompy.MakePrismVecH(hole_face_2, cyl_dir, cyl_dz)
93 hole_solid_3 = geompy.MakePrismVecH(hole_face_3, cyl_dir, cyl_dz)
94 hole_solid_4 = geompy.MakePrismVecH(hole_face_4, cyl_dir, cyl_dz)
96 hole_internal = geompy.MakeCylinder(hole_center, cyl_dir, cyl_radius , cyl_dz)
97 hole_external = geompy.MakeCylinder(hole_center, cyl_dir, cyl_radius+cyl_thick, cyl_dz)
98 hole_median = geompy.MakeCut(hole_external, hole_internal)
105 blocks.append( geompy.MakeCut(hole_solid_1, hole_external))
106 blocks.append(geompy.MakeCommon(hole_solid_1, hole_median ))
108 blocks.append( geompy.MakeCut(hole_solid_2, hole_external))
109 blocks.append(geompy.MakeCommon(hole_solid_2, hole_median ))
111 blocks.append( geompy.MakeCut(hole_solid_3, hole_external))
112 blocks.append(geompy.MakeCommon(hole_solid_3, hole_median ))
114 blocks.append( geompy.MakeCut(hole_solid_4, hole_external))
115 blocks.append(geompy.MakeCommon(hole_solid_4, hole_median ))
120 # Vertex of the full part
121 # -----------------------
123 full_point_11 = geompy.MakeVertex(0 , 0 , cyl_dz)
124 full_point_21 = geompy.MakeVertex(box_dx, 0 , cyl_dz)
125 full_point_12 = geompy.MakeVertex(0 , box_dy, cyl_dz)
126 full_point_22 = geompy.MakeVertex(box_dx, box_dy, cyl_dz)
128 full_center = geompy.MakeVertex(cyl_x, cyl_y, cyl_dz)
130 # Faces of the full part
131 # ----------------------
133 full_face_1 = triangle(full_point_11, full_point_21, full_center)
134 full_face_2 = triangle(full_point_21, full_point_22, full_center)
135 full_face_3 = triangle(full_point_12, full_point_22, full_center)
136 full_face_4 = triangle(full_point_11, full_point_12, full_center)
138 # Solids of the full part
139 # ------------------------
141 full_dz = box_dz - cyl_dz
143 full_solid_1 = geompy.MakePrismVecH(full_face_1, cyl_dir, full_dz)
144 full_solid_2 = geompy.MakePrismVecH(full_face_2, cyl_dir, full_dz)
145 full_solid_3 = geompy.MakePrismVecH(full_face_3, cyl_dir, full_dz)
146 full_solid_4 = geompy.MakePrismVecH(full_face_4, cyl_dir, full_dz)
148 full_internal = geompy.MakeCylinder(full_center, cyl_dir, cyl_radius , full_dz)
149 full_external = geompy.MakeCylinder(full_center, cyl_dir, cyl_radius+cyl_thick, full_dz)
150 full_median = geompy.MakeCut(full_external, full_internal)
157 full.append( geompy.MakeCut(full_solid_1, full_external))
158 full.append(geompy.MakeCommon(full_solid_1, full_median))
160 full.append( geompy.MakeCut(full_solid_2, full_external))
161 full.append(geompy.MakeCommon(full_solid_2, full_median ))
163 full.append( geompy.MakeCut(full_solid_3, full_external))
164 full.append(geompy.MakeCommon(full_solid_3, full_median))
166 full.append( geompy.MakeCut(full_solid_4, full_external))
167 full.append(geompy.MakeCommon(full_solid_4, full_median))
175 y = x * cyl_y / cyl_x
176 box_point_11 = geompy.MakeVertex(x, y, cyl_dz)
179 y = (box_dx - x) * cyl_y / (box_dx - cyl_x)
180 box_point_12 = geompy.MakeVertex(x, y, cyl_dz)
183 y = box_dy - x * (box_dy - cyl_y) / cyl_x
184 box_point_21 = geompy.MakeVertex(x, y, cyl_dz)
187 y = box_dy - (box_dx - x) * (box_dy - cyl_y) / (box_dx - cyl_x)
188 box_point_22 = geompy.MakeVertex(x, y, cyl_dz)
190 box_face = geompy.MakeQuad4Vertices(box_point_11, box_point_12, box_point_21, box_point_22)
192 box = geompy.MakePrismVecH(box_face, cyl_dir, full_dz)
196 full.append(geompy.MakeCut(geompy.MakeCommon(full_solid_1, full_internal), box))
197 full.append(geompy.MakeCut(geompy.MakeCommon(full_solid_2, full_internal), box))
198 full.append(geompy.MakeCut(geompy.MakeCommon(full_solid_3, full_internal), box))
199 full.append(geompy.MakeCut(geompy.MakeCommon(full_solid_4, full_internal), box))
201 # Cut the cylinder thickness
202 # -------------------------
204 full_plan = geompy.MakePlane(geompy.MakeVertex(0, 0, cyl_dz+cyl_thick), cyl_dir, 5000)
206 full_parts = geompy.MakePartition(full, [full_plan], [], [], geompy.ShapeType["SOLID"])
211 blocks.append(full_parts)
213 piece_cpd = geompy.MakeCompound(blocks)
215 piece_ok = geompy.RemoveExtraEdges(piece_cpd, doUnionFaces=True)
217 piece = geompy.MakeGlueFaces(piece_ok, 1.e-3)
219 piece_id = geompy.addToStudy(piece, "ex13_hole1partial")
227 hexa = smesh.Mesh(piece, "ex13_hole1partial:hexa")
229 algo = hexa.Segment()
230 algo.NumberOfSegments(2)
239 def local(x, y, z, d):
240 edge = geompy.GetEdgeNearPoint(piece, geompy.MakeVertex(x, y, z))
241 algo = hexa.Segment(edge)
242 algo.NumberOfSegments(d)
251 local(100, 100, 0, 25)
253 d = cyl_radius-3*cyl_thick
254 local(cyl_x+d, cyl_y+d, box_dz, 10)
261 # Update object browser
262 # ---------------------
264 salome.sg.updateObjBrowser()