Salome HOME
Update of CheckDone
[modules/smesh.git] / src / Tools / blocFissure / gmu / prolongeWire.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2024  EDF
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 """Prolongation d'un wire par deux segments tangents"""
21
22 import logging
23
24 from .geomsmesh import geompy
25 from .geomsmesh import geomPublish
26
27 from . import initLog
28
29 from .orderEdgesFromWire import orderEdgesFromWire
30
31 def prolongeWire(aWire, extrem, norms, longueur):
32   """Prolongation d'un wire par deux segments tangents"""
33   logging.info("start")
34
35   if ( geompy.NumberOfEdges(aWire) > 1 ):
36     edges = geompy.ExtractShapes(aWire, geompy.ShapeType["EDGE"])
37     uneSeuleEdge = False
38   else:
39     edges = [aWire]
40     uneSeuleEdge = True
41
42   edgesBout = list()
43   for i_aux, v_1 in enumerate(extrem):
44     exts = [geompy.MakeTranslationVectorDistance(v_1, norms[i_aux], lg_aux) for lg_aux in (-longueur, longueur)]
45     dists = [(geompy.MinDistance(v, aWire), j_aux , v) for j_aux, v in enumerate(exts)]
46     dists.sort()
47     v_2 = dists[-1][-1]
48     edge = geompy.MakeEdge(v_1, v_2)
49     edges.append(edge)
50     edgesBout.append(edge)
51     name = "extrem{}".format(i_aux)
52     geomPublish(initLog.debug, edge, name)
53
54   try:
55     wireProlonge = geompy.MakeWire(edges)
56     geomPublish(initLog.debug, wireProlonge, "wireProlonge")
57   except:
58     logging.warning("probleme MakeWire, approche pas a pas")
59     if uneSeuleEdge:
60       edgelist = [aWire]
61       accessList = [0]
62     else:
63       edgelist, accessList = orderEdgesFromWire(aWire)
64     edge1 = edgelist[accessList[0]]
65     if geompy.MinDistance(edgesBout[0], edge1) < 1.e-4 :
66       i_0 = 0
67       i_1 = 1
68     else:
69       i_0 = 1
70       i_1 = 0
71     wireProlonge = edgesBout[i_0]
72
73     for i_aux in range(len(edgelist)):
74       wireProlonge = geompy.MakeWire([wireProlonge, edgelist[accessList[i_aux]]])
75       geomPublish(initLog.debug, wireProlonge, "wireProlonge_{}".format(i_aux))
76
77     wireProlonge = geompy.MakeWire([wireProlonge,edgesBout[i_1]])
78     geomPublish(initLog.debug, wireProlonge, "wireProlonge")
79     logging.warning("prolongation wire pas a pas OK")
80
81   return wireProlonge