Salome HOME
51a98e6b5cf45433ddc4284a38572759abc07f91
[modules/superv.git] / examples / GraphSwitch.py
1
2 # Generated python file of Graph GraphSwitch
3
4 from SuperV import *
5 # Graph creation 
6 GraphSwitch = Graph( 'GraphSwitch' )
7 GraphSwitch.SetName( 'GraphSwitch' )
8 GraphSwitch.SetAuthor( '' )
9 GraphSwitch.SetComment( '' )
10 GraphSwitch.Coords( 0 , 0 )
11
12 # Creation of Factory Nodes
13
14 # Creation of InLine Nodes
15 PyIsOdd = []
16 PyIsOdd.append( 'from time import *   ' )
17 PyIsOdd.append( 'def IsOdd(a) :       ' )
18 PyIsOdd.append( '    print a,"IsOdd (GraphSwitch)"      ' )
19 PyIsOdd.append( '    sleep( 1 )   ' )
20 PyIsOdd.append( '    return a     ' )
21 IsOdd = GraphSwitch.INode( 'IsOdd' , PyIsOdd )
22 IsOdd.SetName( 'IsOdd' )
23 IsOdd.SetAuthor( '' )
24 IsOdd.SetComment( 'Python function' )
25 IsOdd.Coords( 388 , 50 )
26 IsOdd.InPort( 'a' , 'long' )
27 IsOdd.OutPort( 'a' , 'long' )
28
29 # Creation of Loop Nodes
30 PyInitLoopSwitch = []
31 PyInitLoopSwitch.append( 'def InitLoop(Index,Min,Max) :      ' )
32 PyInitLoopSwitch.append( '      return Index,Min,Max     ' )
33 PyMoreInitLoopSwitch = []
34 PyMoreInitLoopSwitch.append( 'def MoreLoop(Index,Min,Max) :     ' )
35 PyMoreInitLoopSwitch.append( '  if Index <= Max :   ' )
36 PyMoreInitLoopSwitch.append( '          DoLoop = 1     ' )
37 PyMoreInitLoopSwitch.append( '  else :     ' )
38 PyMoreInitLoopSwitch.append( '          DoLoop = 0     ' )
39 PyMoreInitLoopSwitch.append( '  return DoLoop,Index,Min,Max     ' )
40 PyNextInitLoopSwitch = []
41 PyNextInitLoopSwitch.append( 'def NextLoop(Index,Min,Max) :     ' )
42 PyNextInitLoopSwitch.append( '  Index = Index + 1     ' )
43 PyNextInitLoopSwitch.append( '  return Index,Min,Max     ' )
44 InitLoopSwitch,EndOfInitLoopSwitch = GraphSwitch.LNode( 'InitLoop' , PyInitLoopSwitch , 'MoreLoop' , PyMoreInitLoopSwitch , 'NextLoop' , PyNextInitLoopSwitch )
45 EndOfInitLoopSwitch.SetName( 'EndOfInitLoopSwitch' )
46 EndOfInitLoopSwitch.SetAuthor( '' )
47 EndOfInitLoopSwitch.SetComment( '' )
48 EndOfInitLoopSwitch.Coords( 766 , 127 )
49 InitLoopSwitch.SetName( 'InitLoopSwitch' )
50 InitLoopSwitch.SetAuthor( '' )
51 InitLoopSwitch.SetComment( '' )
52 InitLoopSwitch.Coords( 10 , 129 )
53 InitLoopSwitch.InPort( 'Index' , 'long' )
54 InitLoopSwitch.InPort( 'Min' , 'long' )
55 InitLoopSwitch.InPort( 'Max' , 'long' )
56 InitLoopSwitch.OutPort( 'Index' , 'long' )
57 InitLoopSwitch.OutPort( 'Min' , 'long' )
58 InitLoopSwitch.OutPort( 'Max' , 'long' )
59
60 # Creation of Switch Nodes
61 PySwitch = []
62 PySwitch.append( 'from time import * ' )
63 PySwitch.append( 'def Switch(a) :   ' )
64 PySwitch.append( '    if ( a & 1 ) == 0 : ' )
65 PySwitch.append( '        sleep(1)    ' )
66 PySwitch.append( '    return a & 1,1-(a&1),a    ' )
67 Switch,EndOfSwitch = GraphSwitch.SNode( 'Switch' , PySwitch )
68 EndOfSwitch.SetName( 'EndOfSwitch' )
69 EndOfSwitch.SetAuthor( '' )
70 EndOfSwitch.SetComment( '' )
71 EndOfSwitch.Coords( 587 , 126 )
72 PyEndOfSwitch = []
73 EndOfSwitch.SetPyFunction( 'EndSwitch' , PyEndOfSwitch )
74 EndOfSwitch.InPort( 'a' , 'long' )
75 EndOfSwitch.OutPort( 'a' , 'long' )
76 Switch.SetName( 'Switch' )
77 Switch.SetAuthor( '' )
78 Switch.SetComment( '' )
79 Switch.Coords( 186 , 130 )
80 Switch.InPort( 'a' , 'long' )
81 Switch.OutPort( 'Odd' , 'long' )
82 Switch.OutPort( 'Even' , 'int' )
83 Switch.OutPort( 'a' , 'int' )
84
85 # Creation of Links
86 IsOdda = IsOdd.Port( 'a' )
87 EndOfSwitcha = GraphSwitch.Link( IsOdda , EndOfSwitch.Port( 'a' ) )
88 EndOfSwitcha.AddCoord( 1 , 571 , 161 )
89 EndOfSwitcha.AddCoord( 2 , 571 , 131 )
90
91 InitLoopSwitchIndex = InitLoopSwitch.Port( 'Index' )
92 Switcha = GraphSwitch.Link( InitLoopSwitchIndex , Switch.Port( 'a' ) )
93
94 InitLoopSwitchMin = InitLoopSwitch.Port( 'Min' )
95 EndOfInitLoopSwitchMin = GraphSwitch.Link( InitLoopSwitchMin , EndOfInitLoopSwitch.Port( 'Min' ) )
96
97 InitLoopSwitchMax = InitLoopSwitch.Port( 'Max' )
98 EndOfInitLoopSwitchMax = GraphSwitch.Link( InitLoopSwitchMax , EndOfInitLoopSwitch.Port( 'Max' ) )
99
100 SwitchOdd = Switch.Port( 'Odd' )
101 IsOddInGate = GraphSwitch.Link( SwitchOdd , IsOdd.Port( 'InGate' ) )
102
103 Switcha = Switch.Port( 'a' )
104 IsOdda = GraphSwitch.Link( Switcha , IsOdd.Port( 'a' ) )
105 IsOdda.AddCoord( 1 , 372 , 129 )
106 IsOdda.AddCoord( 2 , 371 , 223 )
107
108 SwitchDefault = Switch.Port( 'Default' )
109 EndOfSwitchDefault = GraphSwitch.Link( SwitchDefault , EndOfSwitch.Port( 'Default' ) )
110 EndOfSwitchDefault.AddCoord( 1 , 572 , 194 )
111 EndOfSwitchDefault.AddCoord( 2 , 571 , 257 )
112
113 EndOfSwitcha = EndOfSwitch.Port( 'a' )
114 EndOfInitLoopSwitchIndex = GraphSwitch.Link( EndOfSwitcha , EndOfInitLoopSwitch.Port( 'Index' ) )
115
116 # Creation of Input datas
117 InitLoopSwitchIndex = InitLoopSwitch.Input( 'Index' , 0)
118 InitLoopSwitchMin = InitLoopSwitch.Input( 'Min' , 0)
119 InitLoopSwitchMax = InitLoopSwitch.Input( 'Max' , 100)
120
121 # Creation of Output variables
122 EndOfInitLoopSwitchIndex = EndOfInitLoopSwitch.Port( 'Index' )
123 EndOfInitLoopSwitchMin = EndOfInitLoopSwitch.Port( 'Min' )
124 EndOfInitLoopSwitchMax = EndOfInitLoopSwitch.Port( 'Max' )
125 SwitchEven = Switch.Port( 'Even' )
126
127 GraphSwitch.Run()
128 GraphSwitch.DoneW()
129 GraphSwitch.State()
130 GraphSwitch.PrintPorts()