Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MedClient / test / test1 / TestMedCorba5.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
30 def compare(x, y):
31     if (len(x) != len(y)):
32         return 0
33     for i in xrange(len(x)):
34         if x[i] != y[i]:
35             return 0
36     return 1
37
38 # MED Mesh read from a (local) file
39
40 from libMEDMEM_Swig import *
41
42 md = MED()
43
44 mdDriver = MED_MED_RDONLY_DRIVER(fileName, md)
45
46 mdDriver.open()
47 mdDriver.readFileStruct()
48 mdDriver.close()
49
50 mLocal = md.getMesh(md.getMeshName(0))
51 mLocal.read()
52
53 # MED Mesh recieved from a distant component (via CORBA)
54
55 from omniORB import CORBA
56 from LifeCycleCORBA import *
57 from libSALOME_Swig import *
58
59 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
60 lcc = LifeCycleCORBA(orb)
61
62 C = lcc.FindOrLoadComponent("FactoryServerPy", "Compo1Py")
63 C.Initialise(fileName)
64
65 mDistant = C.Calcul1()
66
67
68 print "Name              : ", mDistant.getName()
69
70
71 for i in [MED_CELL,
72           MED_FACE,
73           MED_EDGE,
74           MED_NODE,
75           MED_ALL_ENTITIES ]:
76
77     n1 = mLocal.getNumberOfTypes(i);
78     n2 = mDistant.getNumberOfTypes(i);
79
80     if (n1 != n2):
81         raise RuntimeError, "MESH::getNumberOfTypes()"
82
83     if ((n1 > 0) & (i != MED_NODE)):
84         T1 = mLocal.getTypes(i);
85         T2 = mDistant.getTypes(i);
86  
87         if (n2 !=  len(T2)):
88             raise RuntimeError, \
89                   "len(MESH::getTypes()) <> MESH::getNumberOfTypes()"
90
91         for j in range(n2):
92             if (T1[j] != T2[j]):
93                 raise RuntimeError, "MESH::getTypes()"
94
95             c1 = mLocal.getConnectivity(MED_FULL_INTERLACE, MED_NODAL, \
96                                         i, T1[j]);
97             c2 = mDistant.getConnectivity(MED_FULL_INTERLACE, MED_NODAL, \
98                                         i, T2[j]);
99
100             print "connectivity (local)   : ", T1[j], " : ", c1;
101             print "connectivity (distant) : ", T2[j], " : ", c2;
102
103             if (compare(c1, c2) == 0):
104                 raise RuntimeError, "MESH::getConnectivity()"
105         
106 print
107 print "All tests passed"