Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MedClient / src / SUPPORTClient.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #include "Utils_CorbaException.hxx"
21 #include "UtilClient.hxx"
22 #include "SUPPORTClient.hxx"
23 #include "MESHClient.hxx"
24 #include "ReceiverFactory.hxx"
25
26 using namespace MEDMEM;
27 using namespace MED_EN;
28
29 //=============================================================================
30 /*!
31  * Constructeur
32  */
33 //=============================================================================
34
35 SUPPORTClient::SUPPORTClient(const SALOME_MED::SUPPORT_ptr S,
36                              MESH * M) : 
37   SUPPORT(), 
38   IOR_Support(SALOME_MED::SUPPORT::_duplicate(S)),_refCounter(1)
39 {
40   BEGIN_OF("SUPPORTClient::SUPPORTClient(SALOME_MED::SUPPORT_ptr m)");
41
42   SCRUTE(S);
43   SCRUTE(M);
44   if(M)
45     _mesh=M;
46   else
47     {
48       SALOME_MED::MESH_var ior_mesh=IOR_Support->getMesh();
49       _mesh=new MESHClient(ior_mesh);
50     }
51   blankCopy();
52
53   END_OF("SUPPORTClient::SUPPORTClient(SALOME_MED::SUPPORT_ptr m)");
54 }
55 //=============================================================================
56 /*!
57  * Remplit les informations générales
58  */
59 //=============================================================================
60 void SUPPORTClient::blankCopy()
61 {
62   BEGIN_OF("SUPPORTClient::blankCopy");
63
64  try
65   {
66         SALOME_MED::SUPPORT::supportInfos_var all = IOR_Support->getSupportGlobal();
67
68         _name = all->name;
69         _description = all->description;
70         setAll(all->isOnAllElements);
71         setEntity(all->entity);
72 // modifs PN 
73         setNumberOfGeometricType(all->numberOfGeometricType);
74         convertCorbaArray2(_geometricType, _numberOfGeometricType, all->types);
75
76         SCRUTE(_name);
77         SCRUTE(_description);
78
79         int *nE = new int[_numberOfGeometricType];
80         int i;
81         for (i=0; i<_numberOfGeometricType; i++)
82         {
83                 nE[i] = all->nbEltTypes[i];
84         }
85         setNumberOfElements(nE);
86
87         delete [] nE;
88
89         SCRUTE(_totalNumberOfElements);
90         _complete_support = false;
91   }
92   catch( const CORBA::Exception &ex )
93   {
94          MESSAGE("Erreur CORBA dans la communication" ) ;
95          THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
96                                        SALOME::INTERNAL_ERROR);
97   }
98
99   END_OF("SUPPORTClient::blankCopy");
100
101 }
102 //=============================================================================
103 /*!
104  *  
105  */
106 //=============================================================================
107 void SUPPORTClient::fillCopy()
108 {
109   BEGIN_OF("SUPPORTClient::fillCopy");
110
111   if (!_complete_support) {
112     if(!_isOnAllElts) {
113     const int * index, * value;
114     long n_index, n_value;
115     
116     SALOME::SenderInt_var senderForValue=IOR_Support->getSenderForNumber(MED_ALL_ELEMENTS);
117     value=(const int *)ReceiverFactory::getValue(senderForValue,n_value);
118     SALOME::SenderInt_var senderForIndex=IOR_Support->getSenderForNumberIndex();
119     index=(const int *)ReceiverFactory::getValue(senderForIndex,n_index);
120     
121     SCRUTE(n_index);
122     SCRUTE(n_value);
123     setNumber(index, value,true);
124     }
125     _complete_support = true;
126   }
127
128   END_OF("SUPPORTClient::fillCopy");
129 }
130 //=============================================================================
131 /*!
132  * Destructeur
133  */
134 //=============================================================================
135 SUPPORTClient::~SUPPORTClient()
136 {
137   BEGIN_OF("SUPPORTClient::~SUPPORTClient");
138   IOR_Support->Destroy();
139   if(_mesh)
140     _mesh->removeReference();
141   END_OF("SUPPORTClient::~SUPPORTClient");
142 }
143
144 //=============================================================================
145 /*!
146  * Destructeur
147  */
148 //=============================================================================
149 MEDSKYLINEARRAY *  SUPPORTClient::getnumber() const throw (MEDEXCEPTION)
150 {
151   BEGIN_OF("SUPPORTClient::getnumber()");
152
153   if (!_complete_support) (const_cast<SUPPORTClient *>(this))->fillCopy();
154   MEDSKYLINEARRAY *m = SUPPORT::getnumber();
155
156   END_OF("SUPPORTClient::getnumber()");
157   return m;
158 }
159
160 //=============================================================================
161 /*!
162  * 
163  */
164 //=============================================================================
165 const int *  SUPPORTClient::getNumber(medGeometryElement GeometricType) 
166     const throw (MEDEXCEPTION)
167 {
168   BEGIN_OF("SUPPORTClient::getnumber(medGeometryElement)");
169
170   if (!_complete_support) (const_cast<SUPPORTClient *>(this))->fillCopy();
171   const int *n = SUPPORT::getNumber(GeometricType);
172
173   END_OF("SUPPORTClient::getnumber(medGeometryElement)");
174   return n;
175 }
176
177 //=============================================================================
178 /*!
179  * 
180  */
181 //=============================================================================
182 const int *  SUPPORTClient::getNumberIndex() const throw (MEDEXCEPTION) 
183 {
184   BEGIN_OF("SUPPORTClient::getnumberIndex()");
185
186   if (!_complete_support) (const_cast<SUPPORTClient *>(this))->fillCopy();
187   const int * n = SUPPORT::getNumberIndex();
188
189   END_OF("SUPPORTClient::getnumberIndex()");
190   return n;
191 }
192
193 //=============================================================================
194 /*!
195  * 
196  */
197 //=============================================================================
198 int SUPPORTClient::getValIndFromGlobalNumber(const int number) const throw (MEDEXCEPTION)
199 {
200   BEGIN_OF("SUPPORTClient::getValIndFromGlobalNumber()");
201   
202   if (!_complete_support) (const_cast<SUPPORTClient *>(this))->fillCopy();
203   const int n = SUPPORT::getValIndFromGlobalNumber(number);
204   
205   END_OF("SUPPORTClient::getValIndFromGlobalNumber()");
206   return n;
207 }
208
209 //=============================================================================
210 /*!
211  * 
212  */
213 //=============================================================================
214 void SUPPORTClient::addReference() const
215 {
216   _refCounter++;
217 }
218
219 //=============================================================================
220 /*!
221  * 
222  */
223 //=============================================================================
224 void SUPPORTClient::removeReference() const
225 {
226   if (--_refCounter <= 0)
227     {
228       delete this;
229     }
230 }