Salome HOME
Preparation of 3.1.0a2: merge with BR_3_0_0_OCC
[samples/calculator.git] / src / CALCULATOR / CALCULATOR_TEST.py
1 import salome
2 import SALOME
3 import SALOME_MED
4
5 ################   GET A MED FIELD FROM FILE pointe.med   ###################
6 #
7 # This test program is based on the field named fieldcelldoublevector in 
8 # med file $MED_ROOT_DIR/share/salome/resources/pointe.med
9 from os import environ
10 filePath=environ["MED_ROOT_DIR"]
11 filePath=filePath+"/share/salome/resources/"
12 medFile=filePath+"pointe.med"
13 fieldname = "fieldcelldoublescalar"
14
15 # Launch the Med Component and use it to load into memory the test field 
16 print "Launch the Med Component: "
17 med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
18
19 # Get a Corba field proxy on the distant field (located in the med_comp server).
20 try:
21     studyname = salome.myStudyName
22     studynameId = salome.myStudyId
23     print "We are working in the study ",studyname," with the ID ",studynameId
24     print "Read field ",fieldname
25     fieldcell  = med_comp.readFieldInFile(medFile,studyname,fieldname,-1,-1)
26     fieldcelldouble = fieldcell._narrow(SALOME_MED.FIELDDOUBLE)
27 except SALOME.SALOME_Exception, ex:
28     print ex.details
29     print ex.details.type
30     print ex.details.text
31     print ex.details.sourceFile
32     print ex.details.lineNumber
33     raise
34
35 print "Description of Field : "
36 print fieldcelldouble
37 print fieldcelldouble.getName()
38 print fieldcelldouble.getDescription()
39 print fieldcelldouble.getNumberOfComponents()
40 #
41 #
42 ##############  Load Calculator Component and test it   ###################
43 #
44 #
45 print "Load Calculator Component "
46 # we need to import CALCULATOR_ORB to get a typed object (to perform narrowing)
47 import CALCULATOR_ORB
48 calculator = salome.lcc.FindOrLoadComponent("FactoryServer", "CALCULATOR")
49 #
50 print "Appel cloneField : fieldcelldouble -> f1,f2,f3,f4"
51 (f1,f2,f3,f4)=calculator.cloneField(fieldcelldouble)  # fieldcelldouble is consumed
52 #
53 calculator.printField(f1)
54 print "Add fields f2+f3"
55 f_add=calculator.add(f2, f3)
56 calculator.printField(f_add)
57
58 #
59 print "Apply linear function"
60 f_lin=calculator.applyLin(f4,2.0,1.0)
61 #
62 print "Appel Norme Max "
63 norme=calculator.normMax(f_lin)
64 print " -> norme = ",norme
65 #
66 print "End of Calculator Test!"