Salome HOME
Copyright update 2021
[modules/smesh.git] / src / Tools / blocFissure / gmu / findWireIntermediateVertices.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2021  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
21 import logging
22 from .geomsmesh import geompy
23 from .geomsmesh import geomPublish
24 from .geomsmesh import geomPublishInFather
25 from . import initLog
26
27 # -----------------------------------------------------------------------------
28 # --- trouver les vertices intermediaires d'un wire
29
30 def findWireIntermediateVertices(aWire, getNormals=False):
31   """
32   trouver les vertices d'un wire qui ne sont pas aux extremités
33   calcul optionnel des tangentes. Attention à la tolérance qui peut être élevée (> 0.001)
34   """
35   logging.info("start")
36   edges = geompy.ExtractShapes(aWire, geompy.ShapeType["EDGE"], False)
37   vertices = []
38   idsubs = {}
39   shortList = []
40   if getNormals:
41     normals = []
42     idnorm = {}
43     shortNorm = []
44   for edge in edges:
45     vert = geompy.ExtractShapes(edge, geompy.ShapeType["VERTEX"], False)
46     vertices += vert
47     if getNormals:
48       v0 = geompy.MakeVertexOnCurve(edge, 0.0)
49       n0 = geompy.MakeTangentOnCurve(edge, 0.0)
50       v1 = geompy.MakeVertexOnCurve(edge, 1.0)
51       n1 = geompy.MakeTangentOnCurve(edge, 1.0)
52       dist = geompy.MinDistance(v0, vert[0])
53       logging.debug("distance %s", dist)
54       if dist < 1.e-2:
55         normals += [n0, n1]
56       else:
57         normals += [n1, n0]
58   for i, sub in enumerate(vertices):
59     subid = geompy.GetSubShapeID(aWire, sub)
60     if subid in list(idsubs.keys()):
61       idsubs[subid].append(sub)
62     else:
63       idsubs[subid] = [sub]
64       name='vertex%d'%i
65       geomPublishInFather(initLog.debug, aWire, sub, name)
66       if getNormals:
67         idnorm[subid] = normals[i]
68         name='norm%d'%i
69         geomPublishInFather(initLog.debug, aWire, normals[i], name)
70   for k, v in idsubs.items():
71     if len(v) > 1:
72       shortList.append(v[0])
73       if getNormals:
74         shortNorm.append(idnorm[k])
75   if getNormals:
76     return shortList, shortNorm
77   else:
78     return shortList
79