Salome HOME
59ea7a3a2f67a3f2aa4618ad18717a280d2d99f0
[modules/yacs.git] / src / engine_swig / GraphForSOPDbg.py
1 # Copyright (C) 2019-2022  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 import pilot
21 import SALOMERuntime
22 import loader
23 from collections import OrderedDict
24
25 fname = "graph.xml"
26 dbgFname = "dbg.xml"
27
28 def IntToStr(i,prefix=""):
29     if i<26:
30         return prefix+chr( ord('A')+i )
31     else:
32         factor = (i//26)-1 ; remain = i%26
33         return IntToStr(factor,prefix)+IntToStr(remain)
34
35 def GenerateSimplifiedOne(p0):
36     children = p0.getChildren()
37
38     dico = OrderedDict()
39     revDico = {}
40
41     for i,c in enumerate(children):
42         newName = IntToStr(i)
43         #if newName in ["R","A"]:
44         #    continue
45         dico[c.getName()] = newName
46         revDico[newName] = c.getName()
47         pass
48
49     newProc = r.createProc("TOP")
50     for k,v in dico.items():
51         node = r.createScriptNode("Salome",v)#createProc
52         newProc.edAddChild(node)
53
54     for c in children:
55         if c.getName() not in dico:
56             continue
57         og = c.getOutGate()
58         sn = newProc.getChildByName( dico[ c.getName() ] )
59         outg = len( og.edMapInGate() )
60         if outg > 1:
61             print( "More than one link ( {} ) for {} !".format( outg, dico[c.getName()]  ) )
62         for ol in og.edMapInGate():
63             en = newProc.getChildByName( dico[ ol[0].getNode().getName() ])
64             newProc.edAddCFLink(sn,en)
65     return newProc, dico, revDico
66     
67     
68 SALOMERuntime.RuntimeSALOME.setRuntime()
69 r = SALOMERuntime.getSALOMERuntime()
70 l = loader.YACSLoader()
71 p = l.load(fname)
72
73 p0 = p.getChildren()[0]
74 newProc, dico, revDico = GenerateSimplifiedOne( p0 )
75 newProc.saveSchema( dbgFname )
76
77 indepGraphs = newProc.splitIntoIndependantGraph()
78
79 if len(indepGraphs) != 1:
80     raise RuntimeError("Ooops !")
81
82 sop = pilot.SetOfPoints(indepGraphs[0])
83 sop.simplify()