Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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
20 #CALCULATOR_TEST_WITHOUTIHM.py
21
22 from omniORB import CORBA
23
24 import salome
25 import SALOME
26 import SALOME_MED
27 import SALOMEDS
28
29 import os
30 host = os.getenv( 'HOST' )
31 orb, lcc, naming_service, contmgr = salome.salome_kernel.salome_kernel_init()
32
33 ################   GET A MED FIELD FROM FILE pointe.med   ###################
34 #
35 # This test program is based on the field named fieldcelldoublevector in 
36 # med file $MED_ROOT_DIR/share/salome/resources/pointe.med
37 filePath=os.environ["MED_ROOT_DIR"]
38 filePath=filePath+"/share/salome/resources/med/"
39 medFile=filePath+"pointe.med"
40 fieldname = "fieldcelldoublevector"
41
42 # Launch the Med Component and use it to load into memory the test field 
43 print "Launch the Med Component: "
44 med_comp = lcc.FindOrLoadComponent("FactoryServer", "MED")
45
46 # Get a Corba field proxy on the distant field (located in the med_comp server).
47 try:
48     obj = naming_service.Resolve('myStudyManager')
49     myStudyManager = obj._narrow(SALOMEDS.StudyManager)
50     print "studyManager found"
51     myStudy = myStudyManager.NewStudy('CALCULATOR_TEST')
52     studynameId = myStudy._get_StudyId()
53     studyname = myStudy._get_Name()
54     print "We are working in the study ",studyname," with the ID ",studynameId
55     print "Read field ",fieldname
56     fieldcell  = med_comp.readFieldInFile(medFile,studyname,fieldname,-1,-1)
57     fieldcelldouble = fieldcell._narrow(SALOME_MED.FIELDDOUBLE)
58 except SALOME.SALOME_Exception, ex:
59     print ex.details
60     print ex.details.type
61     print ex.details.text
62     print ex.details.sourceFile
63     print ex.details.lineNumber
64     raise
65
66 print "Description of Field : "
67 print fieldcelldouble
68 print fieldcelldouble.getName()
69 print fieldcelldouble.getDescription()
70 print fieldcelldouble.getNumberOfComponents()
71
72 #
73 #
74 ##############  Load Calculator Component ###################
75 # Calculator Component must be in the Container of MED
76 #
77 print "Load Calculator Component "
78 # we need to import CALCULATOR_ORB to get a typed object (to perform narrowing)
79 import CALCULATOR_ORB
80 calculator = lcc.FindOrLoadComponent("FactoryServer", "CALCULATOR")
81
82 #
83 #
84 ##############  Test Calculator Component ###################
85 #
86 #
87 print "Appel cloneField : fieldcelldoublevector -> f1,f2,f3,f4"
88 (f1,f2,f3,f4)=calculator.cloneField(fieldcelldouble)  # fieldcelldouble is consumed
89 #
90 f1.Register()
91 calculator.printField(f1)
92 print "Add fields f2+f3"
93 f_add=calculator.add(f2, f3)
94 f_add.Register()
95 calculator.printField( f_add ) # f_add is consumed
96
97 #
98 print "Apply linear function"
99 f_lin=calculator.applyLin(f4,2.0,1.0)
100 f_lin.Register()
101 calculator.printField( f_lin ) # f_lin is consumed
102 #
103 print "Appel Norme Max "
104 f_lin.Register()
105 norme=calculator.normMax(f_lin) # f_lin is consumed
106 print " -> norme = ",norme
107 #
108
109 print "End of Calculator Test!"