Salome HOME
Copyright update 2022
[modules/smesh.git] / src / Tools / blocFissure / gmu / findWireVertices.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2022  EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 """Trouver les vertices d'un wire"""
21
22 import logging
23
24 from . import initLog
25
26 from .geomsmesh import geompy
27 from .geomsmesh import geomPublishInFather
28
29 def findWireVertices(aWire, edges, getNormals=False):
30   """Trouver les vertices d'un wire
31
32   Calcul optionnel des tangentes. Attention à la tolérance qui peut être élevée (> 0.001)
33   """
34   logging.info("start")
35   vertices = list()
36   idsubs = dict()
37   idnorm = dict()
38   if getNormals:
39     normals = list()
40
41   for edge in edges:
42     vert = geompy.ExtractShapes(edge, geompy.ShapeType["VERTEX"], False)
43     vertices += vert
44     if getNormals:
45       vertex_0 = geompy.MakeVertexOnCurve(edge, 0.0)
46       tangente_0 = geompy.MakeTangentOnCurve(edge, 0.0)
47       tangente_1 = geompy.MakeTangentOnCurve(edge, 1.0)
48       dist = geompy.MinDistance(vertex_0, vert[0])
49       logging.debug("distance %s", dist)
50       if dist < 1.e-2:
51         normals += [tangente_0, tangente_1]
52       else:
53         normals += [tangente_1, tangente_0]
54
55   for nro, sub in enumerate(vertices):
56     subid = geompy.GetSubShapeID(aWire, sub)
57     if subid in list(idsubs.keys()):
58       idsubs[subid].append(sub)
59     else:
60       idsubs[subid] = [sub]
61       name='vertex{}'.format(nro)
62       geomPublishInFather(initLog.debug, aWire, sub, name)
63       if getNormals:
64         idnorm[subid] = normals[nro]
65         name='norm{}'.format(nro)
66         geomPublishInFather(initLog.debug, aWire, normals[nro], name)
67   logging.debug("idsubs: %s", idsubs)
68
69   return idsubs, idnorm