Salome HOME
Merge from BR_V5_DEV 17Feb09
[samples/calculator.git] / src / CALCULATOR / CALCULATOR_TEST.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 #CALCULATOR_TEST_WITHOUTIHM.py
23 #
24 from omniORB import CORBA
25
26 import salome
27 import SALOME
28 import SALOME_MED
29 import SALOMEDS
30
31 import os
32 host = os.getenv( 'HOST' )
33 orb, lcc, naming_service, contmgr = salome.salome_kernel.salome_kernel_init()
34
35 ################   GET A MED FIELD FROM FILE pointe.med   ###################
36 #
37 # This test program is based on the field named fieldcelldoublevector in 
38 # med file $MED_ROOT_DIR/share/salome/resources/pointe.med
39 filePath=os.environ["MED_ROOT_DIR"]
40 filePath=filePath+"/share/salome/resources/med/"
41 medFile=filePath+"pointe.med"
42 fieldname = "fieldcelldoublevector"
43
44 # Launch the Med Component and use it to load into memory the test field 
45 print "Launch the Med Component: "
46 med_comp = lcc.FindOrLoadComponent("FactoryServer", "MED")
47
48 # Get a Corba field proxy on the distant field (located in the med_comp server).
49 try:
50     obj = naming_service.Resolve('myStudyManager')
51     myStudyManager = obj._narrow(SALOMEDS.StudyManager)
52     print "studyManager found"
53     myStudy = myStudyManager.NewStudy('CALCULATOR_TEST')
54     studynameId = myStudy._get_StudyId()
55     studyname = myStudy._get_Name()
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 #
76 ##############  Load Calculator Component ###################
77 # Calculator Component must be in the Container of MED
78 #
79 print "Load Calculator Component "
80 # we need to import CALCULATOR_ORB to get a typed object (to perform narrowing)
81 import CALCULATOR_ORB
82 calculator = lcc.FindOrLoadComponent("FactoryServer", "CALCULATOR")
83
84 #
85 #
86 ##############  Test Calculator Component ###################
87 #
88 #
89 print "Appel cloneField : fieldcelldoublevector -> f1,f2,f3,f4"
90 (f1,f2,f3,f4)=calculator.cloneField(fieldcelldouble)  # fieldcelldouble is consumed
91 #
92 f1.Register()
93 calculator.printField(f1)
94 print "Add fields f2+f3"
95 f_add=calculator.add(f2, f3)
96 f_add.Register()
97 calculator.printField( f_add ) # f_add is consumed
98
99 #
100 print "Apply linear function"
101 f_lin=calculator.applyLin(f4,2.0,1.0)
102 f_lin.Register()
103 calculator.printField( f_lin ) # f_lin is consumed
104 #
105 print "Appel Norme Max "
106 f_lin.Register()
107 norme=calculator.normMax(f_lin) # f_lin is consumed
108 print " -> norme = ",norme
109 #
110
111 print "End of Calculator Test!"