Salome HOME
Merge from V6_main 01/04/2013
[modules/med.git] / src / MedClient / src / COORDINATEClient.cxx
1 // Copyright (C) 2007-2013  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
23 #include "COORDINATEClient.hxx"
24 #include <string>
25 #include "UtilClient.hxx"
26 #include "Utils_CorbaException.hxx"
27
28 #include "ReceiverFactory.hxx"
29
30 using namespace MEDMEM;
31 using namespace MED_EN;
32
33 //=============================================================================
34 /*!
35  * Constructeur
36  */
37 //=============================================================================
38
39 COORDINATEClient::COORDINATEClient(const SALOME_MED::MESH_ptr m,
40                                    medModeSwitch Mode) :
41   COORDINATE(m->getSpaceDimension(), 1, Mode),
42   _complete(false),
43   IOR_Mesh(SALOME_MED::MESH::_duplicate(m))
44 {
45   blankCopy();
46 }
47 //=============================================================================
48 /*!
49  * Remplit les informations générales
50  */
51 //=============================================================================
52 void COORDINATEClient::blankCopy()
53 {
54   std::string *tA;
55   long nA;
56   SALOME_MED::GMESH::coordinateInfos_var all;
57   try
58   {
59         all = IOR_Mesh->getCoordGlobal();
60   }
61   catch (const exception & ex)
62   {
63         MESSAGE("Unable to acces Global information");
64         THROW_SALOME_CORBA_EXCEPTION(ex.what() ,SALOME::INTERNAL_ERROR);
65   }
66
67   //convertCorbaArray(tA, nA, IOR_Mesh->getCoordinatesNames());
68   convertCorbaArray(tA, nA, &all->coordNames);
69   ASSERT(nA == getSpaceDimension());
70   setCoordinatesNames(tA);
71   delete [] tA;
72
73   //convertCorbaArray(tA, nA, IOR_Mesh->getCoordinatesUnits());
74   convertCorbaArray(tA, nA, &all->coordUnits);
75   ASSERT(nA == getSpaceDimension());
76   setCoordinatesUnits(tA);
77   delete [] tA;
78
79
80   setCoordinatesSystem( all->coordSystem.in());
81
82   _complete = false;
83 }
84 //=============================================================================
85 /*!
86  * Remplit les coordonnées
87  */
88 //=============================================================================
89
90 void COORDINATEClient::fillCopy()
91 {
92   //PN ?? Est-ce qu on peut pas mettre une variable dans COORDINATEClient
93   // qu on remplirait dans blankCopy ??
94   long nN = IOR_Mesh->getNumberOfNodes();
95   double *tC;
96   long nC;
97
98   SALOME::SenderDouble_var senderForCoords=IOR_Mesh->getSenderForCoordinates(MED_FULL_INTERLACE);
99   tC=ReceiverFactory::getValue(senderForCoords,nC);
100
101   ASSERT(nC == (getSpaceDimension() * nN));
102
103   MEDARRAY<double> mC(tC, getSpaceDimension(), nN,MED_FULL_INTERLACE,true);
104   setCoordinates(&mC,true);
105
106   _complete = true;
107 }
108
109 //=============================================================================
110 /*!
111  * Retourne les coordonnées
112  */
113 //=============================================================================
114
115 const double *  COORDINATEClient::getCoordinates(medModeSwitch Mode)
116 {
117   if (!_complete) fillCopy();
118   const double * c = COORDINATE::getCoordinates(Mode);
119
120   return c;
121 }
122 //=============================================================================
123 /*!
124  * Retourne une coordonnée
125  */
126 //=============================================================================
127
128 double COORDINATEClient::getCoordinate(int Number,int Axis)
129 {
130   if (!_complete) fillCopy();
131   double d = COORDINATE::getCoordinate(Number, Axis);
132
133   return d;
134 }
135 //=============================================================================
136 /*!
137  * Retourne un axe
138  */
139 //=============================================================================
140 const double *  COORDINATEClient::getCoordinateAxis(int Axis)
141 {
142   if (!_complete) fillCopy();
143   const double *c = COORDINATE::getCoordinateAxis(Axis);
144
145   return c;
146 }
147 //=============================================================================
148 /*!
149  * Retourne le nombre de noeuds
150  */
151 //=============================================================================
152 const int*      COORDINATEClient::getNodesNumbers() const
153 {
154   if (!_complete) (const_cast < COORDINATEClient * >(this))->fillCopy();
155
156   MESSAGE("NON IMPLEMENTE DANS L'API CORBA");
157
158   return NULL;
159 }