1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2013-2024 CEA, EDF
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")
76 # To define a rotation, we have to set at least 3 source vertices not aligned.
77 p_bas_gauche = geompy.MakeVertex(-5, -5, 0)
78 geompy.addToStudy(p_bas_gauche, "p_bas_gauche")
79 p_bas_mil = geompy.MakeVertex(0, -4, 0)
80 geompy.addToStudy(p_bas_mil, "p_bas_mil")
81 p_bas_droite = geompy.MakeVertex(5, -5, 0)
82 geompy.addToStudy(p_bas_droite, "p_bas_droite")
85 p_mil_droite = geompy.MakeVertex(4, 0, 0)
86 geompy.addToStudy(p_mil_droite, "p_mil_droite")
87 p_haut_droite = geompy.MakeVertex(5, 5, 0)
88 geompy.addToStudy(p_haut_droite, "p_haut_droite")
94 from salome.smesh import smeshBuilder
95 smesh = smeshBuilder.New()
97 Mesh = smesh.Mesh(part, "Mesh")
99 algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf)
100 algo2d.SetGeometricMesh( 1 )
101 algo2d.SetAngleMesh( 4 )
102 algo2d.SetPhySize( 8 )
103 #algo2d.SetGradation(1.05)
105 #algo2d.SetOptionValue( 'debug', '1' )
106 #algo2d.SetPreCADOptionValue( 'debug', '1' )
109 #algo2d.SetVerbosity(10)
110 algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2")
111 algo2d.AddPreCadEdgesPeriodicity(bottom, right, [p_bas_droite, p_bas_mil, p_bas_gauche], [p_bas_droite, p_mil_droite, p_haut_droite])
116 gr_left = Mesh.Group(left)
117 gr_right = Mesh.Group(right)
118 gr_bottom = Mesh.Group(bottom)
119 gr_top = Mesh.Group(top)
121 axe = geompy.MakePrismVecH(p_bas_droite, Vz, 1)
122 bottom_rotated = Mesh.RotateObjectMakeMesh( gr_bottom, axe, -math.pi/2, NewMeshName='bottom_rotated' )
124 def checkProjection(gr, mesh_translated, tol=1e-7):
125 name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
126 mesh_source = smesh.CopyMesh(gr, gr.GetName())
127 mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
128 ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
129 coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
130 mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
131 mesh_nodes = mesh_check.GetNodesId()
132 if len(ll_coincident_nodes) != mesh_translated.NbNodes():
133 non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes))
134 mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes)
135 #raise Exception("Projection failed for %s"%name)
136 print("Projection failed for %s"%name)
138 checkProjection(gr_right, bottom_rotated)
140 #salome.myStudy.SaveAs("test.hdf", 0, 0)
142 if salome.sg.hasDesktop():
143 salome.sg.updateObjBrowser()