Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[samples/calculator.git] / src / CALCULATOR / CALCULATOR_TEST.py
1 #  Copyright (C) 2005  CEA/DEN, EDF R&D
2 #
3 #  This library is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU Lesser General Public
5 #  License as published by the Free Software Foundation; either
6 #  version 2.1 of the License.
7 #
8 #  This library is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 #  Lesser General Public License for more details.
12 #
13 #  You should have received a copy of the GNU Lesser General Public
14 #  License along with this library; if not, write to the Free Software
15 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 from omniORB import CORBA
20
21 import salome
22 import SALOME
23 import SALOME_MED
24
25 #CCRT :
26 import os
27 import Engines
28 import LifeCycleCORBA
29
30 host = os.getenv( 'HOST' )
31
32 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
33
34 lcc = LifeCycleCORBA.LifeCycleCORBA(orb)
35 #endCCRT
36
37 ################   GET A MED FIELD FROM FILE pointe.med   ###################
38 #
39 # This test program is based on the field named fieldcelldoublevector in 
40 # med file $MED_ROOT_DIR/share/salome/resources/pointe.med
41 from os import environ
42 filePath=environ["MED_ROOT_DIR"]
43 filePath=filePath+"/share/salome/resources/"
44 medFile=filePath+"pointe.med"
45 fieldname = "fieldcelldoublescalar"
46
47 # Launch the Med Component and use it to load into memory the test field 
48 print "Launch the Med Component: "
49 #CCRTmed_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
50 med_comp = lcc.FindOrLoadComponent("FactoryServer", "MED")
51
52 # Get a Corba field proxy on the distant field (located in the med_comp server).
53 try:
54     studyname = salome.myStudyName
55     studynameId = salome.myStudyId
56     print "We are working in the study ",studyname," with the ID ",studynameId
57     print "Read field ",fieldname
58     fieldcell  = med_comp.readFieldInFile(medFile,studyname,fieldname,-1,-1)
59     fieldcelldouble = fieldcell._narrow(SALOME_MED.FIELDDOUBLE)
60 except SALOME.SALOME_Exception, ex:
61     print ex.details
62     print ex.details.type
63     print ex.details.text
64     print ex.details.sourceFile
65     print ex.details.lineNumber
66     raise
67
68 print "Description of Field : "
69 print fieldcelldouble
70 print fieldcelldouble.getName()
71 print fieldcelldouble.getDescription()
72 print fieldcelldouble.getNumberOfComponents()
73 #
74 #
75 ##############  Load Calculator Component and test it   ###################
76 #
77 #
78 print "Load Calculator Component "
79 # we need to import CALCULATOR_ORB to get a typed object (to perform narrowing)
80 import CALCULATOR_ORB
81 calculator = salome.lcc.FindOrLoadComponent("FactoryServer", "CALCULATOR")
82 #
83 print "Appel cloneField : fieldcelldouble -> f1,f2,f3,f4"
84 (f1,f2,f3,f4)=calculator.cloneField(fieldcelldouble)  # fieldcelldouble is consumed
85 #
86 calculator.printField(f1)
87 print "Add fields f2+f3"
88 f_add=calculator.add(f2, f3)
89 calculator.printField(f_add)
90
91 #
92 print "Apply linear function"
93 f_lin=calculator.applyLin(f4,2.0,1.0)
94 #
95 print "Appel Norme Max "
96 norme=calculator.normMax(f_lin)
97 print " -> norme = ",norme
98 #
99 print "End of Calculator Test!"