Back to index

salome-med  6.5.0
SUPPORTClient.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "Utils_CorbaException.hxx"
00024 #include "UtilClient.hxx"
00025 #include "SUPPORTClient.hxx"
00026 #include "GMESHClient.hxx"
00027 #include "ReceiverFactory.hxx"
00028 
00029 using namespace MEDMEM;
00030 using namespace MED_EN;
00031 
00032 //=============================================================================
00036 //=============================================================================
00037 
00038 SUPPORTClient::SUPPORTClient(const SALOME_MED::SUPPORT_ptr S,
00039                              GMESH * M) : 
00040   SUPPORT(),
00041   IOR_Support(SALOME_MED::SUPPORT::_duplicate(S))//,_refCounter(1)
00042 {
00043   SCRUTE(S);
00044   SCRUTE(M);
00045   if(M)
00046     {
00047       _mesh=M;
00048       _mesh->addReference();
00049     }
00050   else
00051     {
00052       SALOME_MED::GMESH_var ior_mesh=IOR_Support->getMesh();
00053       _mesh=new GMESHClient(ior_mesh);
00054     }
00055   blankCopy();
00056 }
00057 //=============================================================================
00061 //=============================================================================
00062 void SUPPORTClient::blankCopy()
00063 {
00064  try
00065   {
00066         SALOME_MED::SUPPORT::supportInfos_var all = IOR_Support->getSupportGlobal();
00067 
00068         _name = all->name;
00069         _description = all->description;
00070         setAll(all->isOnAllElements);
00071         setEntity(all->entity);
00072 // modifs PN 
00073         setNumberOfGeometricType(all->numberOfGeometricType);
00074         convertCorbaArray2(_geometricType, _numberOfGeometricType, all->types);
00075 
00076         SCRUTE(_name);
00077         SCRUTE(_description);
00078 
00079         int *nE = new int[_numberOfGeometricType];
00080         int i;
00081         for (i=0; i<_numberOfGeometricType; i++)
00082         {
00083                 nE[i] = all->nbEltTypes[i];
00084         }
00085         setNumberOfElements(nE);
00086 
00087         delete [] nE;
00088 
00089         SCRUTE(_totalNumberOfElements);
00090         _complete_support = false;
00091   }
00092   catch( const CORBA::Exception &ex )
00093   {
00094          MESSAGE("Erreur CORBA dans la communication" ) ;
00095          THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
00096                                        SALOME::INTERNAL_ERROR);
00097   }
00098 }
00099 //=============================================================================
00103 //=============================================================================
00104 void SUPPORTClient::fillCopy()
00105 {
00106   if (!_complete_support) {
00107     if(!_isOnAllElts) {
00108     const int * index, * value;
00109     long n_index, n_value;
00110     
00111     SALOME::SenderInt_var senderForValue=IOR_Support->getSenderForNumber(MED_ALL_ELEMENTS);
00112     value=(const int *)ReceiverFactory::getValue(senderForValue,n_value);
00113     SALOME::SenderInt_var senderForIndex=IOR_Support->getSenderForNumberIndex();
00114     index=(const int *)ReceiverFactory::getValue(senderForIndex,n_index);
00115     
00116     SCRUTE(n_index);
00117     SCRUTE(n_value);
00118     setNumber(index, value,true);
00119     }
00120     _complete_support = true;
00121   }
00122 }
00123 //=============================================================================
00127 //=============================================================================
00128 SUPPORTClient::~SUPPORTClient()
00129 {
00130   IOR_Support->UnRegister();
00131   if(_mesh)
00132     _mesh->removeReference();
00133 }
00134 
00135 //=============================================================================
00139 //=============================================================================
00140 MEDSKYLINEARRAY *  SUPPORTClient::getnumber() const throw (MEDEXCEPTION)
00141 {
00142   if (!_complete_support) (const_cast<SUPPORTClient *>(this))->fillCopy();
00143   MEDSKYLINEARRAY *m = SUPPORT::getnumber();
00144 
00145   return m;
00146 }
00147 
00148 //=============================================================================
00152 //=============================================================================
00153 const int *  SUPPORTClient::getNumber(medGeometryElement GeometricType) 
00154     const throw (MEDEXCEPTION)
00155 {
00156   if (!_complete_support) (const_cast<SUPPORTClient *>(this))->fillCopy();
00157   const int *n = SUPPORT::getNumber(GeometricType);
00158 
00159   return n;
00160 }
00161 
00162 //=============================================================================
00166 //=============================================================================
00167 const int *  SUPPORTClient::getNumberIndex() const throw (MEDEXCEPTION) 
00168 {
00169   if (!_complete_support) (const_cast<SUPPORTClient *>(this))->fillCopy();
00170   const int * n = SUPPORT::getNumberIndex();
00171 
00172   return n;
00173 }
00174 
00175 //=============================================================================
00179 //=============================================================================
00180 int SUPPORTClient::getValIndFromGlobalNumber(const int number) const throw (MEDEXCEPTION)
00181 {
00182   if (!_complete_support) (const_cast<SUPPORTClient *>(this))->fillCopy();
00183   const int n = SUPPORT::getValIndFromGlobalNumber(number);
00184   
00185   return n;
00186 }
00187 
00188 //=============================================================================
00192 //=============================================================================
00193 /*void SUPPORTClient::addReference() const
00194 {
00195   _refCounter++;
00196 }*/
00197 
00198 //=============================================================================
00202 //=============================================================================
00203 /*void SUPPORTClient::removeReference() const
00204 {
00205   if (--_refCounter <= 0)
00206     {
00207       delete this;
00208     }
00209 }*/