Salome HOME
Merge from V6_main (04/10/2012)
[modules/gui.git] / src / SALOME_SWIG / supervisionexample.py.in
1 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
10 #
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # Lesser General Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22
23 #==============================================================================
24 #  File      : supervisionexample.py
25 #  Created   : 23 nov 2001
26 #  Author    : Jean Rahuel
27 #  Project   : SALOME
28 #==============================================================================
29 #
30 from SuperV import *
31
32
33
34 # load this object with Nodes, Links and Datas stored in GraphEssai.xml
35 # (GraphEssai.xml was created with python in SuperVisionTest and GraphEssai.py)
36 myGraph = Graph("@ROOT_BUILDDIR@/share/salome/resources/superv/GraphEssai.xml")
37
38 #myGraph = Graph("/home/data/jr_HEAD/build/share/salome/resources/superv/GraphEssai.xml")
39 # This DataFlow is "valid" : no loop, correct links between Nodes etc...
40
41 print myGraph.IsValid()
42
43 # Get Nodes
44 myGraph.PrintNodes()
45 Add,Sub,Mul,Div = myGraph.Nodes()
46
47 # Load Datas
48 Addx = Add.Input("x",3.)
49 Addy = Add.Input("y",4.5)
50 Subx = Sub.Input("x",1.5)
51
52 # Get Output Port
53 Addz = Add.Port('z')
54 Subz = Sub.Port('z')
55 Mulz = Mul.Port('z')
56 Divz = Div.Port('z')
57
58 # This DataFlow is "executable" : all pending Ports are defined with Datas
59 print myGraph.IsExecutable()
60
61 # Starts only execution of that DataFlow and gets control immediatly
62 print myGraph.Run()
63
64 # That DataFlow is running ==> 0 (false)
65 print myGraph.IsDone()
66
67 # Events of execution :
68 aStatus,aNode,anEvent,aState = myGraph.Event()
69 while aStatus :
70     print aNode.Thread(),aNode.SubGraph(),aNode.Name(),anEvent,aState
71     aStatus,aNode,anEvent,aState = myGraph.Event()
72 print myGraph.IsDone()
73
74 # Wait for Completion (but it is already done after event loop ...)
75 print "Done : ",myGraph.DoneW()
76
77 # Get result
78 print "Result : ",Divz.ToString()
79
80 # Intermediate results :
81 print "Intermediate Result Add\z : ",Addz.ToString()
82 print "Intermediate Result Sub\z : ",Subz.ToString()
83 print "Intermediate Result Mul\z : ",Mulz.ToString()
84
85 print " "
86 print "Type : print myGraph.IsDone()"
87 print "       If execution is finished ==> 1 (true)"
88 print " "
89 print "Type : print Divz.ToString()"
90 print "       You will get the result"
91 print " "
92 print "Type : myGraph.PrintPorts()"
93 print "       to see input and output values of the graph"
94 print " "
95 print "Type : Add.PrintPorts()"
96 print "Type : Sub.PrintPorts()"
97 print "Type : Mul.PrintPorts()"
98 print "Type : Div.PrintPorts()"
99 print "       to see input and output values of nodes"
100
101 # Export will create newsupervisionexample.xml and the corresponding .py file
102 print myGraph.Export("@ROOT_BUILDDIR@/share/salome/resources/superv/newsupervisionexample.xml")
103
104 print " "
105 print "See file @ROOT_BUILDDIR@/share/salome/resources/superv/newsupervisionexample.xml"
106 print "See file @ROOT_BUILDDIR@/share/salome/resources/superv/newsupervisionexample.py"