Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MedClient / test / test1 / TestMedCorba4.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 import os
23 BASE = os.environ["MED_ROOT_DIR"]
24 BASE = os.path.join( BASE, 'share', 'salome', 'resources', 'med' )
25
26 fileName = os.path.join( BASE, 'pointe.med' )
27 fileName = os.path.join( BASE, 'carre_en_quad4_seg2.med' )
28
29 # MED Mesh read from a (local) file
30
31 from libMEDMEM_Swig import *
32
33 md = MED()
34
35 mdDriver = MED_MED_RDONLY_DRIVER(fileName, md)
36
37 mdDriver.open()
38 mdDriver.readFileStruct()
39 mdDriver.close()
40
41 mLocal = md.getMesh(md.getMeshName(0))
42 mLocal.read()
43
44 # MED Mesh recieved from a distant component (via CORBA)
45
46 from omniORB import CORBA
47 from LifeCycleCORBA import *
48 from libSALOME_Swig import *
49
50 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
51 lcc = LifeCycleCORBA(orb)
52
53 C = lcc.FindOrLoadComponent("FactoryServerPy", "Compo1Py")
54 C.Initialise(fileName)
55
56 mDistant = C.Calcul1()
57
58
59 print "Name              : ", mDistant.getName()
60
61
62 for i in [MED_CELL,
63           MED_FACE,
64           MED_EDGE,
65           MED_NODE,
66           MED_ALL_ENTITIES ]:
67
68     n1 = mLocal.getNumberOfTypes(i);
69     n2 = mDistant.getNumberOfTypes(i);
70
71     if (n1 != n2):
72         raise RuntimeError, "MESH::getNumberOfTypes()"
73
74     if ((n1 > 0) & (i != MED_NODE)):
75         T1 = mLocal.getTypes(i);
76         T2 = mDistant.getTypes(i);
77         print "types (local)   : ", i, " : ", T1;
78         print "types (distant) : ", i, " : ", T2;
79
80         if (n2 !=  len(T2)):
81             raise RuntimeError, \
82                   "len(MESH::getTypes()) <> MESH::getNumberOfTypes()"
83
84         for j in range(n2):
85             if (T1[j] != eval(T2[j].__str__())):
86                 raise RuntimeError, "MESH::getTypes()"
87
88             e1 = mLocal.getNumberOfElements(i, T1[j]);
89             e2 = mDistant.getNumberOfElements(i, T2[j]);
90
91             print "elements (local)   : ", T1[j], " : ", e1;
92             print "elements (distant) : ", T2[j], " : ", e2;
93
94             if (e1 != e2):
95                 raise RuntimeError, "MESH::getNumberOfElements"
96         
97 print
98 print "All tests passed"