1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #ifndef __MED_FIELDTEMPLATE_I_HXX__
24 #define __MED_FIELDTEMPLATE_I_HXX__
26 #include <SALOMEconfig.h>
27 #include CORBA_SERVER_HEADER(MED)
28 #include "MEDMEM_Field_i.hxx"
29 #include "MEDMEM_Field.hxx"
30 #include "SenderFactory.hxx"
31 #include "MultiCommException.hxx"
32 #include "MEDMEM_ArrayConvert.hxx"
33 #include "MEDMEM_TraitsForFields.hxx"
34 #include "utilities.h"
38 template < class T, class INTERLACING_TAG=FullInterlace >
39 class FIELDTEMPLATE_I : public FIELDI_TRAITS<T,INTERLACING_TAG>::InterfaceForServant,
41 public SALOMEMultiComm
46 FIELDTEMPLATE_I(MEDMEM::FIELD<T, INTERLACING_TAG> *f, bool ownCppPtr=false);
47 FIELDTEMPLATE_I(FIELDTEMPLATE_I & f);
48 typename FIELDI_TRAITS<T,INTERLACING_TAG>::SeqType* getValue (SALOME_MED::medModeSwitch mode )
49 throw (SALOME::SALOME_Exception);
50 typename FIELDI_TRAITS<T,INTERLACING_TAG>::SenderPtrType getSenderForValue(SALOME_MED::medModeSwitch mode)
51 throw (SALOME::SALOME_Exception);
54 //=============================================================================
58 //=============================================================================
59 template < class T, class INTERLACING_TAG >
60 FIELDTEMPLATE_I<T,INTERLACING_TAG>::FIELDTEMPLATE_I(): FIELD_i()
63 //=============================================================================
67 //=============================================================================
68 template < class T, class INTERLACING_TAG >
69 FIELDTEMPLATE_I<T,INTERLACING_TAG>::~FIELDTEMPLATE_I()
72 //=============================================================================
74 * Constructor par recopie
76 //=============================================================================
77 template < class T, class INTERLACING_TAG >
78 FIELDTEMPLATE_I<T,INTERLACING_TAG>::FIELDTEMPLATE_I(FIELDTEMPLATE_I<T, INTERLACING_TAG>& fd):
82 //=============================================================================
86 //=============================================================================
87 template < class T, class INTERLACING_TAG >
88 FIELDTEMPLATE_I<T,INTERLACING_TAG>::FIELDTEMPLATE_I(MEDMEM::FIELD<T, INTERLACING_TAG> *f, bool ownCppPtr):FIELD_i(f,ownCppPtr)
92 //=============================================================================
94 * CORBA: Accessor for Field's values
96 //=============================================================================
97 template < class T, class INTERLACING_TAG >
98 typename FIELDI_TRAITS<T,INTERLACING_TAG>::SeqType *FIELDTEMPLATE_I<T,INTERLACING_TAG>::getValue( SALOME_MED::medModeSwitch mode )
99 throw (SALOME::SALOME_Exception)
101 if (_fieldTptr==NULL)
102 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
103 SALOME::INTERNAL_ERROR);
104 typename FIELDI_TRAITS<T,INTERLACING_TAG>::SeqVarType myseq = new typename FIELDI_TRAITS<T,INTERLACING_TAG>::SeqType;
107 medModeSwitch modemed=convertIdlModeToMedMode(mode);
108 // ::FIELD<T> *ptrD=dynamic_cast< ::FIELD<T>* >(_fieldTptr);
109 // the alternative is not safe but the dynamic_cast fails using the python API
110 MEDMEM::FIELD<T, INTERLACING_TAG> *ptrD = static_cast<MEDMEM::FIELD<T, INTERLACING_TAG>* >(_fieldTptr);
111 int nbval=ptrD->getValueLength();
112 if(ptrD->getInterlacingType()==modemed)
114 const T* values =ptrD->getValue();
115 myseq->length(nbval);
116 for (int i=0; i<nbval; i++)
124 if ( ptrD->getGaussPresence() )
126 typename MEDMEM_ArrayInterface<T,INTERLACING_TAG,Gauss>::Array * myArray = ptrD->getArrayGauss();
127 int size=myArray->getArraySize();
129 delete ArrayConvert(*myArray,values);
133 typename MEDMEM_ArrayInterface<T,INTERLACING_TAG,NoGauss>::Array * myArray = ptrD->getArrayNoGauss();
134 int size=myArray->getArraySize();
136 delete ArrayConvert(*myArray,values);
138 for (int i=0; i<nbval; i++)
144 catch (MEDEXCEPTION &ex)
146 MESSAGE("Unable to acces Field ");
147 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
149 return myseq._retn();
151 //=============================================================================
153 * CORBA: Accessor for Field's values
155 //=============================================================================
156 template < class T, class INTERLACING_TAG >
157 typename FIELDI_TRAITS<T,INTERLACING_TAG>::SenderPtrType FIELDTEMPLATE_I<T,INTERLACING_TAG>::getSenderForValue( SALOME_MED::medModeSwitch mode )
158 throw (SALOME::SALOME_Exception)
160 if (_fieldTptr==NULL)
161 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
162 SALOME::INTERNAL_ERROR);
163 typename FIELDI_TRAITS<T,INTERLACING_TAG>::SenderPtrType ret;
166 medModeSwitch modemed=convertIdlModeToMedMode(mode);
167 // ::FIELD<T> *ptrD=dynamic_cast< ::FIELD<T>* >(_fieldTptr);
168 // the alternative is not safe but the dynamic_cast fails using the python API
169 MEDMEM::FIELD<T, INTERLACING_TAG> *ptrD=static_cast< MEDMEM::FIELD<T, INTERLACING_TAG>* >(_fieldTptr);
170 int nbval=ptrD->getValueLength();
171 if(ptrD->getInterlacingType()==modemed)
173 const T* values =ptrD->getValue();
174 ret=SenderFactory::buildSender(*this,values,nbval);
179 if ( ptrD->getGaussPresence() )
181 typename MEDMEM_ArrayInterface<T,INTERLACING_TAG,Gauss>::Array * myArray = ptrD->getArrayGauss();
182 int size=myArray->getArraySize();
184 delete ArrayConvert(*myArray,values);
189 typename MEDMEM_ArrayInterface<T,INTERLACING_TAG,NoGauss>::Array * myArray = ptrD->getArrayNoGauss();
190 int size=myArray->getArraySize();
192 delete ArrayConvert(*myArray,values);
194 ret=SenderFactory::buildSender(*this,values,nbval);
197 catch (MEDEXCEPTION &ex)
199 MESSAGE("Unable to acces Field ");
200 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);