Salome HOME
387df2768b082c9d2da1015f3649b7703a4d0931
[modules/med.git] / src / MedClient / test / test1 / TestMedCorba4.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 import os
25 BASE = os.environ["MED_ROOT_DIR"]
26 BASE = os.path.join( BASE, 'share', 'salome', 'resources', 'med' )
27
28 fileName = os.path.join( BASE, 'pointe.med' )
29 fileName = os.path.join( BASE, 'carre_en_quad4_seg2.med' )
30
31 # MED Mesh read from a (local) file
32
33 from libMEDMEM_Swig import *
34
35 md = MED()
36
37 mdDriver = MED_MED_RDONLY_DRIVER(fileName, md)
38
39 mdDriver.open()
40 mdDriver.readFileStruct()
41 mdDriver.close()
42
43 mLocal = md.getMesh(md.getMeshName(0))
44 mLocal.read()
45
46 # MED Mesh recieved from a distant component (via CORBA)
47
48 from omniORB import CORBA
49 from LifeCycleCORBA import *
50 from libSALOME_Swig import *
51
52 orb = CORBA.ORB_init([''], CORBA.ORB_ID)
53 lcc = LifeCycleCORBA(orb)
54
55 C = lcc.FindOrLoadComponent("FactoryServerPy", "Compo1Py")
56 C.Initialise(fileName)
57
58 mDistant = C.Calcul1()
59
60
61 print "Name              : ", mDistant.getName()
62
63
64 for i in [MED_CELL,
65           MED_FACE,
66           MED_EDGE,
67           MED_NODE,
68           MED_ALL_ENTITIES ]:
69
70     n1 = mLocal.getNumberOfTypes(i);
71     n2 = mDistant.getNumberOfTypes(i);
72
73     if (n1 != n2):
74         raise RuntimeError, "MESH::getNumberOfTypes()"
75
76     if ((n1 > 0) & (i != MED_NODE)):
77         T1 = mLocal.getTypes(i);
78         T2 = mDistant.getTypes(i);
79         print "types (local)   : ", i, " : ", T1;
80         print "types (distant) : ", i, " : ", T2;
81
82         if (n2 !=  len(T2)):
83             raise RuntimeError, \
84                   "len(MESH::getTypes()) <> MESH::getNumberOfTypes()"
85
86         for j in range(n2):
87             if (T1[j] != eval(T2[j].__str__())):
88                 raise RuntimeError, "MESH::getTypes()"
89
90             e1 = mLocal.getNumberOfElements(i, T1[j]);
91             e2 = mDistant.getNumberOfElements(i, T2[j]);
92
93             print "elements (local)   : ", T1[j], " : ", e1;
94             print "elements (distant) : ", T2[j], " : ", e2;
95
96             if (e1 != e2):
97                 raise RuntimeError, "MESH::getNumberOfElements"
98         
99 print
100 print "All tests passed"