1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2013-2022 CEA/DEN, EDF R&D
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, or (at your option) any later version.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
31 from salome.geom import geomBuilder
32 geompy = geomBuilder.New()
34 O = geompy.MakeVertex(0, 0, 0)
35 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
36 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
37 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
38 Face_1 = geompy.MakeFaceHW(10, 10, 1)
39 geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
40 Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 )
41 vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True)
42 Curve_1 = geompy.MakeInterpol(vertices, True, True)
44 part = geompy.MakePartition([Face_1], [Curve_1], Limit=geompy.ShapeType["FACE"])
45 geompy.addToStudy(part, "part")
47 Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
48 Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
49 Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
51 p1 = geompy.MakeVertex(-5, -5, 0)
52 p2 = geompy.MakeVertex(5, 5, 0)
53 left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON)
54 left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
55 geompy.UnionList(left, left_edges)
56 geompy.addToStudyInFather(part, left, "left")
58 right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON)
59 right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
60 geompy.UnionList(right, right_edges)
61 geompy.addToStudyInFather(part, right, "right")
63 bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON)
64 bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
65 geompy.UnionList(bottom, bottom_edges)
66 geompy.addToStudyInFather(part, bottom, "bottom")
68 top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON)
69 top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
70 geompy.UnionList(top, top_edges)
71 geompy.addToStudyInFather(part, top, "top")
73 source_face = geompy.GetFaceNearPoint(part, p1)
74 geompy.addToStudyInFather(part, source_face, "source_face")
81 from salome.smesh import smeshBuilder
82 smesh = smeshBuilder.New()
84 Mesh = smesh.Mesh(part, "Mesh")
86 algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf)
87 algo2d.SetGeometricMesh( 1 )
88 algo2d.SetAngleMesh( 4 )
89 algo2d.SetPhySize( 8 )
90 #algo2d.SetGradation(1.05)
93 #algo2d.SetVerbosity(10)
94 algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2")
95 algo2d.AddPreCadEdgesPeriodicity(left, right)
96 algo2d.AddPreCadEdgesPeriodicity(bottom, top)
101 gr_left = Mesh.Group(left)
102 gr_right = Mesh.Group(right)
103 gr_bottom = Mesh.Group(bottom)
104 gr_top = Mesh.Group(top)
108 left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 10, 0, 0 )), 0, 'left_translated' )
109 bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 10, 0 )), 0, 'bottom_translated' )
111 def checkProjection(gr, mesh_translated, tol=1e-7):
112 name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
113 mesh_source = smesh.CopyMesh(gr, gr.GetName())
114 mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
115 ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
116 coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
117 mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
118 mesh_nodes = mesh_check.GetNodesId()
119 if len(ll_coincident_nodes) != mesh_translated.NbNodes():
120 non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes))
121 mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes)
122 raise Exception("Projection failed for %s"%name)
124 checkProjection(gr_right, left_translated)
125 checkProjection(gr_top, bottom_translated)
127 if salome.sg.hasDesktop():
128 salome.sg.updateObjBrowser()