Salome HOME
This commit was generated by cvs2git to create tag 'V1_4_0b2'.
[modules/kernel.git] / src / SALOME_SWIG / salome_test.py
index 6b056326db2dd2aa6bad3be33a159f829e556ebf..31b7f308f475f09679164ac33cc48f63d99b9dca 100644 (file)
@@ -15,10 +15,22 @@ from salome import sg
 import SALOMEDS
 import os
 
+import SALOME_ModuleCatalog
+
+print "======================================================================"
+print "           Get Catalog "
+print "======================================================================"
+obj = salome.naming_service.Resolve('Kernel/ModulCatalog')
+catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
+
 print "======================================================================"
 print "           Create Study "
 print "======================================================================"
 
+comp = catalog.GetComponent("GEOM")
+if comp is None:
+       raise RuntimeError,"Component GEOM not found in Module Catalog."
+
 import geompy
 
 print "================================="
@@ -47,10 +59,18 @@ print
 print "=============  Test SMESH  ============================="
 print
 
+comp = catalog.GetComponent("SMESH")
+if comp is None:
+       raise RuntimeError,"Component SMESH not found in Module Catalog."
+
+comp = catalog.GetComponent("MED")
+if comp is None:
+       raise RuntimeError,"Component MED not found in Module Catalog."
+
 import SMESH
 import smeshpy
 
-geom = salome.lcc.FindOrLoadComponent("FactoryServer", "Geometry")
+geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
 myBuilder = salome.myStudy.NewBuilder()
 
 smeshgui = salome.ImportComponentGUI("SMESH")
@@ -231,18 +251,22 @@ print
 print "=============  Test  Supervisor  ============================="
 print
 
+comp = catalog.GetComponent("SUPERV")
+if comp is None:
+       raise RuntimeError,"Component SUPERV not found in Module Catalog."
+
 from SuperV import *
 import SALOMEDS
 myStudy = salome.myStudy
 myBuilder = myStudy.NewBuilder()
 
-SuperVision = lcc.FindOrLoadComponent("SuperVisionContainer","Supervision")
+SuperVision = lcc.FindOrLoadComponent("SuperVisionContainer","SUPERV")
 father = myStudy.FindComponent("SUPERV")
 if father is None:
         father = myBuilder.NewComponent("SUPERV")
         A1 = myBuilder.FindOrCreateAttribute(father, "AttributeName");
         FName = A1._narrow(SALOMEDS.AttributeName)
-        FName.SetValue("Supervision")
+        FName.SetValue( salome.sg.getComponentUserName("SUPERV") )
        A2 = myBuilder.FindOrCreateAttribute(father, "AttributePixMap");
        aPixmap = A2._narrow(SALOMEDS.AttributePixMap);
        aPixmap.SetPixMap( "ICON_OBJBROWSER_Supervision" );
@@ -277,10 +301,10 @@ def addStudy(ior):
     anIOR.SetValue(dataflow.getIOR())
 
 import os
-dir= os.getenv("SALOME_ROOT_DIR")
+dir= os.getenv("SUPERV_ROOT_DIR")
 if dir == None:
-       raise RuntimeError, "SALOME_ROOT_DIR is not defined"
-xmlfile = dir +"/data/GraphEssai.xml"
+       raise RuntimeError, "SUPERV_ROOT_DIR is not defined"
+xmlfile = dir +"/examples/GraphGeomEssai.xml"
 print "Load dataflow from the file : "
 print xmlfile
 print
@@ -292,18 +316,6 @@ print "myGraph.IsValid() = ", myGraph.IsValid()
 
 # Get Nodes
 myGraph.PrintNodes()
-Add,Sub,Mul,Div = myGraph.Nodes()
-
-# Load Datas
-Addx = Add.Input("x",3.)
-Addy = Add.Input("y",4.5)
-Subx = Sub.Input("x",1.5)
-
-# Get Output Port
-Addz = Add.Port('z')
-Subz = Sub.Port('z')
-Mulz = Mul.Port('z')
-Divz = Div.Port('z')
 
 # This DataFlow is "executable" : all pending Ports are defined with Datas
 print myGraph.IsExecutable()
@@ -324,14 +336,6 @@ print "myGraph.IsDone() = ",myGraph.IsDone()
 # Wait for Completion (but it is already done after event loop ...)
 print "Done : ",myGraph.DoneW()
 
-# Get result
-print "Result : ",Divz.ToString()
-
-# Intermediate results :
-print "Intermediate Result Add\z : ",Addz.ToString()
-print "Intermediate Result Sub\z : ",Subz.ToString()
-print "Intermediate Result Mul\z : ",Mulz.ToString()
-
 print " "
 #print "Type : print myGraph.IsDone()"
 #print "       If execution is finished ==> 1 (true)"
@@ -339,30 +343,11 @@ res=myGraph.IsDone()
 if res != 1:
        raise RuntimeError, "myGraph.Run() is not done"
 
-print " "
-print "Type : print Divz.ToString()"
-print "       You will get the result"
-Divz.ToString()
-
 print " "
 print "Type : myGraph.PrintPorts()"
 print "       to see input and output values of the graph"
 myGraph.PrintPorts()
 
-print " "
-print "Type : Add.PrintPorts()"
-Add.PrintPorts()
-
-print "Type : Sub.PrintPorts()"
-Sub.PrintPorts()
-
-print "Type : Mul.PrintPorts()"
-Mul.PrintPorts()
-
-print "Type : Div.PrintPorts()"
-print "       to see input and output values of nodes"
-Div.PrintPorts()
-
 # Export will create newsupervisionexample.xml and the corresponding .py file
 tmpdir=os.getenv("TmpDir")
 if tmpdir is None:
@@ -385,30 +370,88 @@ for node in nodes:
        names.append(node.Name())
 print names
 
-print "Load FactorialComponent component, create dataflow using its services and run execution"
-myPy = Graph('myPy')
-
-eval = myPy.Node('FactorialComponent','FactorialComponent','eval')
-eval.SetContainer('FactoryServerPy')
-
-myPy.IsValid()
-
-myPy.PrintPorts()
-
-myPy.Run( 3 )
-
-myPy.DoneW()
-
-myPy.State()
-
-myPy.PrintPorts()
-
+# Graph creation 
+GraphInLines = Graph( 'GraphInLines' )
+GraphInLines.SetName( 'GraphInLines' )
+GraphInLines.SetAuthor( '' )
+GraphInLines.SetComment( '' )
+GraphInLines.Coords( 0 , 0 )
+
+# Creation of InLine Nodes
+PyAdd = []
+PyAdd.append( 'def Add(a,b) :  ' )
+PyAdd.append( '    return a+b  ' )
+PyAdd.append( '' )
+Add = GraphInLines.INode( 'Add' , PyAdd )
+Add.InPort( 'a' , 'long' )
+Add.InPort( 'b' , 'long' )
+Add.OutPort( 'f' , 'long' )
+Add.SetName( 'Add' )
+Add.SetAuthor( '' )
+Add.SetComment( 'Python function' )
+Add.Coords( 351 , 77 )
+PySub = []
+PySub.append( 'def Sub(a,b) : ' )
+PySub.append( '    return a-b ' )
+PySub.append( '' )
+Sub = GraphInLines.INode( 'Sub' , PySub )
+Sub.InPort( 'a' , 'long' )
+Sub.InPort( 'b' , 'long' )
+Sub.OutPort( 'f' , 'long' )
+Sub.SetName( 'Sub' )
+Sub.SetAuthor( '' )
+Sub.SetComment( 'Python function' )
+Sub.Coords( 86 , 333 )
+PyMul = []
+PyMul.append( 'def Mul(a,b) : ' )
+PyMul.append( '    return a*b ' )
+Mul = GraphInLines.INode( 'Mul' , PyMul )
+Mul.InPort( 'a' , 'long' )
+Mul.InPort( 'b' , 'long' )
+Mul.OutPort( 'Result' , 'long' )
+Mul.SetName( 'Mul' )
+Mul.SetAuthor( '' )
+Mul.SetComment( 'Python function' )
+Mul.Coords( 616 , 247 )
+
+# Creation of intermediate Output variables and of Control Links
+Addf = Add.Port( 'f' )
+Mula = GraphInLines.Link( Addf , Mul.Port( 'a' ) )
+Mula.AddCoord( 1 , 570 , 356 )
+Mula.AddCoord( 2 , 570 , 186 )
+Subf = Sub.Port( 'f' )
+Mulb = GraphInLines.Link( Subf , Mul.Port( 'b' ) )
+Mulb.AddCoord( 1 , 282 , 376 )
+Mulb.AddCoord( 2 , 282 , 442 )
+Addb = GraphInLines.Link( Subf , Add.Port( 'b' ) )
+Addb.AddCoord( 1 , 283 , 209 )
+Addb.AddCoord( 2 , 283 , 374 )
+Addb.AddCoord( 3 , 283 , 442 )
+
+# Creation of Input datas
+Adda = Add.Input( 'a' , 1)
+Suba = Sub.Input( 'a' , 3)
+Subb = Sub.Input( 'b' , 4)
+
+# Creation of Output variables
+MulResult = Mul.Port( 'Result' )
+
+GraphInLines.Run()
+
+GraphInLines.DoneW()
+
+GraphInLines.PrintPorts()
 
 sg.updateObjBrowser(1);
 
 print
 print "=============  Test  VISU  and MED ============================="
 print
+
+comp = catalog.GetComponent("VISU")
+if comp is None:
+       raise RuntimeError,"Component VISU not found in Module Catalog."
+
 import sys
 import SALOMEDS
 import SALOME
@@ -418,16 +461,23 @@ import VISU
 import visu_gui
 
 medFile = "pointe.med"
-medFile = os.getenv('SALOME_ROOT_DIR') + '/data/' + medFile
+medFile = os.getenv('KERNEL_ROOT_DIR') + '/examples/' + medFile
 print "Load ", medFile
 
 studyCurrent = salome.myStudyName
 
-med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "Med")
-myVisu = salome.lcc.FindOrLoadComponent("FactoryServer", "Visu")
+med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
+myVisu = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
 
 try:
     if os.access(medFile, os.R_OK) :
+       if not os.access(medFile, os.W_OK) :
+              import random
+              medFileNew = "/tmp/" + str(random.randint(0,1000000)) + "_" + medfile
+              print " -- Copy " + medFile + " to " + medFileNew
+              os.system("cp "+ medFile + " " + medFileNew)
+              medFile = medFileNew
+
        if os.access(medFile, os.W_OK) :
            med_comp.readStructFileWithFieldType(medFile,studyCurrent)
            med_obj = visu_gui.visu.getMedObjectFromStudy()