Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MedClient / src / FIELDClient.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 template<class T, class INTERLACING_TAG>
21 FIELDClient<T,INTERLACING_TAG>::FIELDClient(typename FIELDI_TRAITS<T,INTERLACING_TAG>::SimpleFieldCorbaPtrType ptrCorba,MEDMEM::SUPPORT * S):_fieldPtr(FIELDI_TRAITS<T,INTERLACING_TAG>::SimpleFieldGlobalType::_duplicate(ptrCorba)),_refCounter(1)
22 {
23   if (!S) 
24     {
25       SCRUTE(_fieldPtr);
26       SCRUTE(_fieldPtr->getSupport());
27       MEDMEM::FIELD<T,INTERLACING_TAG>::_support=new MEDMEM::SUPPORTClient(_fieldPtr->getSupport());
28     }
29   else
30     MEDMEM::FIELD<T,INTERLACING_TAG>::setSupport(S);
31   
32   setName(_fieldPtr->getName());
33
34   MEDMEM::FIELD<T,INTERLACING_TAG>::setDescription(_fieldPtr->getDescription());
35   int nc = _fieldPtr->getNumberOfComponents();
36   MEDMEM::FIELD<T,INTERLACING_TAG>::setNumberOfComponents(nc);
37
38   MEDMEM::FIELD<T,INTERLACING_TAG>::setNumberOfValues( MEDMEM::FIELD<T,INTERLACING_TAG>::_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS));
39
40   string * _s = new string[nc];
41
42   SALOME_MED::string_array_var s;
43   s = _fieldPtr->getComponentsNames();
44   for (int i=0; i<nc; i++)
45     _s[i] = s[i];
46   MEDMEM::FIELD<T,INTERLACING_TAG>::setComponentsNames(_s);
47
48   s = _fieldPtr->getComponentsDescriptions();
49   for (int i=0; i<nc; i++)
50     _s[i] = s[i];
51   MEDMEM::FIELD<T,INTERLACING_TAG>::setComponentsDescriptions(_s);
52
53   s = _fieldPtr->getComponentsUnits();
54   for (int i=0; i<nc; i++)
55     _s[i] = s[i];
56   MEDMEM::FIELD<T,INTERLACING_TAG>::setMEDComponentsUnits(_s);
57
58   delete [] _s;
59   setIterationNumber(_fieldPtr->getIterationNumber());
60   setTime(_fieldPtr->getTime());
61   setOrderNumber(_fieldPtr->getOrderNumber());
62   fillCopy();
63 }
64
65 template<class T, class INTERLACING_TAG>
66 void FIELDClient<T,INTERLACING_TAG>::fillCopy()
67 {
68   long n;
69   typename FIELDI_TRAITS<T,INTERLACING_TAG>::SenderVarType sender=_fieldPtr->getSenderForValue(MEDMEM::FIELD<T,INTERLACING_TAG>::_interlacingType);
70   T *v = (T *)ReceiverFactory::getValue(sender,n);
71   MEDMEM::MEDMEM_Array_ * array;
72   if(_fieldPtr->getGaussPresence())
73     array=0;
74   //array=new typename MEDMEM::MEDMEM_ArrayInterface<T,INTERLACING_TAG,Gauss>::Array
75   //    (v, MEDMEM::FIELD<T,INTERLACING_TAG>::getNumberOfComponents(),MEDMEM::FIELD<T,INTERLACING_TAG>::getNumberOfValues(),true,true);
76   else
77     array=new typename MEDMEM::MEDMEM_ArrayInterface<T,INTERLACING_TAG,NoGauss>::Array
78       (v, MEDMEM::FIELD<T,INTERLACING_TAG>::getNumberOfComponents(),MEDMEM::FIELD<T,INTERLACING_TAG>::getNumberOfValues(),true,true);
79   MEDMEM::FIELD<T,INTERLACING_TAG>::setArray(array);
80 }
81
82 template<class T, class INTERLACING_TAG>
83 FIELDClient<T,INTERLACING_TAG>::~FIELDClient()
84 {
85   _fieldPtr->Destroy();
86   CORBA::release(_fieldPtr);
87   /* CCAR : better put in FIELD_ destructor if support is a SUPPORTClient
88   if(FIELD<T,INTERLACING_TAG>::_support)
89     FIELD<T,INTERLACING_TAG>::_support->removeReference();
90     */
91 }
92