Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MedClient / src / SUPPORTClient.cxx
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 #include "Utils_CorbaException.hxx"
23 #include "UtilClient.hxx"
24 #include "SUPPORTClient.hxx"
25 #include "MESHClient.hxx"
26 #include "ReceiverFactory.hxx"
27
28 using namespace MEDMEM;
29 using namespace MED_EN;
30
31 //=============================================================================
32 /*!
33  * Constructeur
34  */
35 //=============================================================================
36
37 SUPPORTClient::SUPPORTClient(const SALOME_MED::SUPPORT_ptr S,
38                              MESH * M) : 
39   SUPPORT(), 
40   IOR_Support(SALOME_MED::SUPPORT::_duplicate(S)),_refCounter(1)
41 {
42   const char* LOC = "SUPPORTClient::SUPPORTClient(SALOME_MED::SUPPORT_ptr m)";
43   BEGIN_OF(LOC);
44
45   SCRUTE(S);
46   SCRUTE(M);
47   if(M)
48     _mesh=M;
49   else
50     {
51       SALOME_MED::MESH_var ior_mesh=IOR_Support->getMesh();
52       _mesh=new MESHClient(ior_mesh);
53     }
54   blankCopy();
55
56   END_OF(LOC);
57 }
58 //=============================================================================
59 /*!
60  * Remplit les informations générales
61  */
62 //=============================================================================
63 void SUPPORTClient::blankCopy()
64 {
65   const char* LOC = "SUPPORTClient::blankCopy";
66   BEGIN_OF(LOC);
67
68  try
69   {
70         SALOME_MED::SUPPORT::supportInfos_var all = IOR_Support->getSupportGlobal();
71
72         _name = all->name;
73         _description = all->description;
74         setAll(all->isOnAllElements);
75         setEntity(all->entity);
76 // modifs PN 
77         setNumberOfGeometricType(all->numberOfGeometricType);
78         convertCorbaArray2(_geometricType, _numberOfGeometricType, all->types);
79
80         SCRUTE(_name);
81         SCRUTE(_description);
82
83         int *nE = new int[_numberOfGeometricType];
84         int i;
85         for (i=0; i<_numberOfGeometricType; i++)
86         {
87                 nE[i] = all->nbEltTypes[i];
88         }
89         setNumberOfElements(nE);
90
91         delete [] nE;
92
93         SCRUTE(_totalNumberOfElements);
94         _complete_support = false;
95   }
96   catch( const CORBA::Exception &ex )
97   {
98          MESSAGE("Erreur CORBA dans la communication" ) ;
99          THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
100                                        SALOME::INTERNAL_ERROR);
101   }
102
103   END_OF(LOC);
104
105 }
106 //=============================================================================
107 /*!
108  *  
109  */
110 //=============================================================================
111 void SUPPORTClient::fillCopy()
112 {
113   const char* LOC = "SUPPORTClient::fillCopy";
114   BEGIN_OF(LOC);
115
116   if (!_complete_support) {
117     if(!_isOnAllElts) {
118     const int * index, * value;
119     long n_index, n_value;
120     
121     SALOME::SenderInt_var senderForValue=IOR_Support->getSenderForNumber(MED_ALL_ELEMENTS);
122     value=(const int *)ReceiverFactory::getValue(senderForValue,n_value);
123     SALOME::SenderInt_var senderForIndex=IOR_Support->getSenderForNumberIndex();
124     index=(const int *)ReceiverFactory::getValue(senderForIndex,n_index);
125     
126     SCRUTE(n_index);
127     SCRUTE(n_value);
128     setNumber(index, value,true);
129     }
130     _complete_support = true;
131   }
132
133   END_OF(LOC);
134 }
135 //=============================================================================
136 /*!
137  * Destructeur
138  */
139 //=============================================================================
140 SUPPORTClient::~SUPPORTClient()
141 {
142   const char* LOC = "SUPPORTClient::~SUPPORTClient";
143   BEGIN_OF(LOC);
144   IOR_Support->Destroy();
145   if(_mesh)
146     _mesh->removeReference();
147   END_OF(LOC);
148 }
149
150 //=============================================================================
151 /*!
152  * Destructeur
153  */
154 //=============================================================================
155 MEDSKYLINEARRAY *  SUPPORTClient::getnumber() const throw (MEDEXCEPTION)
156 {
157   const char* LOC = "SUPPORTClient::getnumber()";
158   BEGIN_OF(LOC);
159
160   if (!_complete_support) (const_cast<SUPPORTClient *>(this))->fillCopy();
161   MEDSKYLINEARRAY *m = SUPPORT::getnumber();
162
163   END_OF(LOC);
164   return m;
165 }
166
167 //=============================================================================
168 /*!
169  * 
170  */
171 //=============================================================================
172 const int *  SUPPORTClient::getNumber(medGeometryElement GeometricType) 
173     const throw (MEDEXCEPTION)
174 {
175   const char* LOC = "SUPPORTClient::getnumber(medGeometryElement)";
176   BEGIN_OF(LOC);
177
178   if (!_complete_support) (const_cast<SUPPORTClient *>(this))->fillCopy();
179   const int *n = SUPPORT::getNumber(GeometricType);
180
181   END_OF(LOC);
182   return n;
183 }
184
185 //=============================================================================
186 /*!
187  * 
188  */
189 //=============================================================================
190 const int *  SUPPORTClient::getNumberIndex() const throw (MEDEXCEPTION) 
191 {
192   const char* LOC = "SUPPORTClient::getnumberIndex()";
193   BEGIN_OF(LOC);
194
195   if (!_complete_support) (const_cast<SUPPORTClient *>(this))->fillCopy();
196   const int * n = SUPPORT::getNumberIndex();
197
198   END_OF(LOC);
199   return n;
200 }
201
202 //=============================================================================
203 /*!
204  * 
205  */
206 //=============================================================================
207 int SUPPORTClient::getValIndFromGlobalNumber(const int number) const throw (MEDEXCEPTION)
208 {
209   const char* LOC = "SUPPORTClient::getValIndFromGlobalNumber()";
210   BEGIN_OF(LOC);
211   
212   if (!_complete_support) (const_cast<SUPPORTClient *>(this))->fillCopy();
213   const int n = SUPPORT::getValIndFromGlobalNumber(number);
214   
215   END_OF(LOC);
216   return n;
217 }
218
219 //=============================================================================
220 /*!
221  * 
222  */
223 //=============================================================================
224 void SUPPORTClient::addReference() const
225 {
226   _refCounter++;
227 }
228
229 //=============================================================================
230 /*!
231  * 
232  */
233 //=============================================================================
234 void SUPPORTClient::removeReference() const
235 {
236   if (--_refCounter <= 0)
237     {
238       delete this;
239     }
240 }