Salome HOME
Fix for bug PAL8110 : PAL-SUPRV-004: "Supervisor Warning" message box misses.
[modules/superv.git] / src / Supervision / SuperV.py
index 76e33d74e79cfde4f5fed1343550bf401ae31521..f68f82a6d4e04576d774b262ec46043d9feb70a4 100644 (file)
@@ -15,6 +15,7 @@ try :
     from salome import naming_service
     from salome import CORBA
     from salome import sg
+    from salome import SALOMEDS
     import SALOME_ModuleCatalog
     import SUPERV
     import SUPERV_idl
@@ -37,6 +38,7 @@ except :
 import os
 import re
 from types import *
+import readline
 
 #try :
 #    SuperVision = SuperV_Swig( len(sys.argv) , sys.argv )
@@ -53,6 +55,44 @@ SuperVision = lcc.FindOrLoadComponent("SuperVisionContainer","SUPERV")
 modulecatalog = naming_service.Resolve("/Kernel/ModulCatalog")
 
 
+def createDataflowStudyObject( theStudy , aDataFlow , aBuilder ) :
+    aStudyObject = theStudy.FindObjectIOR( aDataFlow.G.getIOR() )
+    if aStudyObject == None :
+        aComponent = theStudy.FindComponent( "SUPERV" )
+        if aComponent == None :
+            print "createDataflowStudyObject Component SUPERV is None"
+            aComponent = aBuilder.NewComponent( "SUPERV" )
+            anAttr = aBuilder.FindOrCreateAttribute(aComponent, "AttributeName")
+            aName = anAttr._narrow( SALOMEDS.AttributeName )
+            aName.SetValue( modulecatalog.GetComponentInfo( "SUPERV" ).username )
+            anAttr = aBuilder.FindOrCreateAttribute( aComponent , "AttributePixMap" )
+            aPixmap = anAttr._narrow( SALOMEDS.AttributePixMap )
+            aPixmap.SetPixMap( "ICON_OBJBROWSER_Supervision" );
+            aBuilder.DefineComponentInstance( aComponent , SuperVision )
+            print "createDataflowStudyObject Component SUPERV is created"
+        aStudyObject = aBuilder.NewObject( aComponent )
+        anAttr =  aBuilder.FindOrCreateAttribute( aStudyObject , "AttributeName" )
+        aName = anAttr._narrow( SALOMEDS.AttributeName )
+        aName.SetValue( aDataFlow.Name() )
+        anAttr =  aBuilder.FindOrCreateAttribute( aStudyObject , "AttributeIOR" )
+        anIORAttr = anAttr._narrow( SALOMEDS.AttributeIOR )
+        anIORAttr.SetValue( aDataFlow.G.getIOR() )
+    return aStudyObject
+
+def addDataflowToStudy( theStudy , aDataFlow ) :
+    aBuilder = theStudy.NewBuilder()
+    aBuilder.NewCommand()
+    aStudyObject = createDataflowStudyObject( theStudy , aDataFlow , aBuilder )
+    if aStudyObject != None :
+        aBuilder.CommitCommand()
+        sg.updateObjBrowser( 1 )
+        print "addDataflowToStudy aStudyObject ",aDataFlow.Name()," added in study"
+        #theStudy.updateObjBrowser()
+    else :
+        print "addDataflowToStudy ERROR aStudyObject is None"
+        aBuilder.AbortCommand()
+    return aBuilder,aStudyObject
+
 
 def PortInputFloat(obj, x):
     return obj.Input( SuperVision.AnyValue( CORBA.Any(CORBA.TC_double, x)))
@@ -448,6 +488,12 @@ class CNode:
         return self.N.IsStreamGraph()
     def IsGraph( self ):
         return self.N.IsGraph()
+    def IsMacro( self ):
+        return self.N.IsMacro()
+    def IsFlowMacro( self ):
+        return self.N.IsFlowMacro()
+    def IsStreamMacro( self ):
+        return self.N.IsStreamMacro()
     def IsComputing( self ):
         return self.N.IsComputing()
     def IsFactory( self ):
@@ -464,6 +510,8 @@ class CNode:
         return self.N.IsSwitch()
     def IsEndSwitch( self ):
         return self.N.IsEndSwitch()
+    def GraphLevel( self ) :
+        return self.N.GraphLevel()
     def SubGraph( self ):
         return self.N.SubGraph()
     def SubStreamGraph( self ):
@@ -484,8 +532,6 @@ class CNode:
         return self.N.Control()
     def ControlClear( self ):
         return self.N.ControlClear()
-    def AutoState( self ):
-        return self.N.AutoState()
     def ReadyW( self ):
         return self.N.ReadyW()
     def RunningW( self ):
@@ -494,14 +540,14 @@ class CNode:
         return self.N.DoneW()
     def SuspendedW( self ):
         return self.N.SuspendedW()
-    def ReRun( self ):
-        return self.N.ReRun()
-    def ReStart( self ):
-        return self.N.ReStart()
-    def ReRunAt( self , aNodeName ):
-        return self.N.ReRunAt( aNodeName )
-    def ReStartAt( self , aNodeName ):
-        return self.N.ReStartAt( aNodeName )
+    #def ReRun( self ):
+    #    return self.N.ReRun()
+    #def ReStart( self ):
+    #    return self.N.ReStart()
+    #def ReRunAt( self , aNodeName ):
+    #    return self.N.ReRunAt( aNodeName )
+    #def ReStartAt( self , aNodeName ):
+    #    return self.N.ReStartAt( aNodeName )
     def Ping( self ):
         return self.N.ping()
     def Kill( self ):
@@ -708,7 +754,7 @@ class ESNode(GNode):
 #        self.Parametername = aServicesParameter.Parametername
 
 ##########################################################
-class Graph(INode):
+class Graph(GNode):
 ##########################################################
     def __init__( self , aName ):
         try:
@@ -717,7 +763,7 @@ class Graph(INode):
             try:
                 graph = aName.G.Copy()
             except:
-                graph = None
+                graph = aName
         if graph != None :
             if graph.IsStreamGraph() :
                 aGraph = graph.ToStreamGraph()
@@ -803,6 +849,36 @@ class Graph(INode):
         if self.G.Verbose :
             print ErrMsg
         return aNode
+    def MNode( self , aGraphXml ):
+        aMNode = self.G.MNode( aGraphXml )
+        if aMNode != None :
+            myMNode = MNode( aMNode , self.G.Verbose )
+            return myMNode
+        ErrMsg = "Failed to create a MNode"
+        if self.G.Verbose :
+            print ErrMsg
+        return aMNode
+    def GraphMNode( self , aGraph ):
+        aGraphMNode = self.G.GraphMNode( aGraph.G )
+        if aGraphMNode != None :
+            myMNode = MNode( aGraphMNode , self.G.Verbose )
+            return myMNode
+        ErrMsg = "Failed to create a MNode"
+        if self.G.Verbose :
+            print ErrMsg
+        return aGraphMNode
+    def FlowObjRef( self ) :
+        aGraph = self.G.FlowObjRef()
+        if aGraph != None :
+            myGraph = Graph( aGraph )
+            return myGraph
+        return aGraph
+    def StreamObjRef( self ) :
+        aGraph = self.G.StreamObjRef()
+        if aGraph != None :
+            myGraph = StreamGraph( aGraph )
+            return myGraph
+        return aGraph
     def PrintService( self , aComponent , anInterface , aService ):
         NodeComponent = modulecatalog.GetComponent( aComponent )
         aService = NodeComponent.GetService( anInterface , aService )
@@ -957,6 +1033,12 @@ class Graph(INode):
             pynodes.append( GNode( nodes.ESNodes[i] , self.G.Verbose ) )
             i = i + 1
             j = j + 1
+        n = len( nodes.Graphs )
+        i = 0
+        while i < n :
+            pynodes.append( MNode( nodes.Graphs[i] , self.G.Verbose ) )
+            i = i + 1
+            j = j + 1
         return pynodes
     def ListNodes( self , *args ):
         nodes = self.Nodes()
@@ -989,7 +1071,7 @@ class Graph(INode):
         nodes = self.Nodes()
         i = 0
         while i < len( nodes ) :
-            print nodes[i].Name(),nodes[i].Thread(),nodes[i].State(),nodes[i].Control(),nodes[i].AutoState()
+            print nodes[i].Name(),nodes[i].Thread(),nodes[i].State(),nodes[i].Control(),nodes[i]
             i = i + 1
     def GLinks( self ):
         links = self.G.GLinks()
@@ -1051,8 +1133,8 @@ class Graph(INode):
         while i < len( links ) :
             links[ i ].Print()
             i = i + 1
-    def Graphs( self ):
-        graphs = self.G.Graphs()
+    def SubGraphsNodes( self , ):
+        graphs = self.G.SubGraphsNodes()
         outgraphs = graphs
         i = 0
         while i < len( graphs ) :
@@ -1097,6 +1179,15 @@ class GraphE(Graph):
             return StreamGraphE( aGraph )
         return None
 
+##########################################################
+class MNode(Graph):
+##########################################################
+    def __init__( self , aMNode , Verbose ):
+        self.G = aMNode
+        self.G.Verbose = Verbose
+        self.N = aMNode
+        self.N.Verbose = Verbose
+
 ##########################################################
 class StreamGraph(Graph):
 ##########################################################