Salome HOME
merging the main trunk with the BrForComp branch to build a pre V3_0_1
[modules/med.git] / src / MEDMEM_I / MEDMEM_FieldDouble_i.cxx
1 //=============================================================================
2 // File      : MEDMEM_Fielddouble_i.hxx
3 // Project   : SALOME
4 // Author    : EDF 
5 // Copyright : EDF 2002
6 // $Header: /export/home/PAL/MED_SRC/src/MEDMEM_I/MEDMEM_Fielddouble_i.hxx
7 //=============================================================================
8
9 #include "MEDMEM_FieldDouble_i.hxx"
10 #include "utilities.h"
11 #include "MEDMEM_convert.hxx"
12 #include "SenderFactory.hxx"
13 #include "MultiCommException.hxx"
14 using namespace MEDMEM;
15
16 //=============================================================================
17 /*!
18  * Default constructor
19  */
20 //=============================================================================
21 FIELDDOUBLE_i::FIELDDOUBLE_i(): FIELD_i()
22 {
23         BEGIN_OF("Default Constructor FIELDDOUBLE_i");
24         END_OF("Default Constructor FIELDDOUBLE_i");
25 }
26 //=============================================================================
27 /*!
28  * Destructor
29  */
30 //=============================================================================
31 FIELDDOUBLE_i::~FIELDDOUBLE_i()
32 {
33         BEGIN_OF("Default Destructor FIELDDOUBLE_i");
34         END_OF("Default Destructor FIELDDOUBLE_i");
35 }
36 //=============================================================================
37 /*!
38  * Constructor par recopie
39  */
40 //=============================================================================
41 FIELDDOUBLE_i::FIELDDOUBLE_i(FIELDDOUBLE_i & fd):
42                                FIELD_i(fd)
43 {
44         BEGIN_OF("Default Constructor FIELDDOUBLE_i");
45         END_OF("Default Constructor FIELDDOUBLE_i");
46 }
47 //=============================================================================
48 /*!
49  * Default constructor
50  */
51 //=============================================================================
52 FIELDDOUBLE_i::FIELDDOUBLE_i(::FIELD<double> * const f, bool ownCppPtr):
53   FIELD_i(f,ownCppPtr)
54 {
55         BEGIN_OF("Constructor FIELDDOUBLE_i");
56         END_OF(" Constructor FIELDDOUBLE_i");
57 }
58
59 //=============================================================================
60 /*!
61  * CORBA: Accessor for Field's values
62 */
63 //=============================================================================
64
65 SALOME_MED::double_array* FIELDDOUBLE_i::getValue( SALOME_MED::medModeSwitch mode ) 
66 throw (SALOME::SALOME_Exception)
67 {
68         if (_fieldTptr==NULL)
69                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
70                                              SALOME::INTERNAL_ERROR);
71         SALOME_MED::double_array_var myseq = new SALOME_MED::double_array;
72         try
73         {
74                 medModeSwitch modemed=convertIdlModeToMedMode(mode);
75 //              ::FIELD<double> *ptrD=dynamic_cast< ::FIELD<double>* >(_fieldTptr);
76 // the alternative is not safe but the dynamic_cast fails using the python API
77                 MEDMEM::FIELD<double> *ptrD = static_cast<MEDMEM::FIELD<double>* >(_fieldTptr);
78                 const double * values =ptrD->getValue(modemed);
79                 int nbval=ptrD->getValueLength(modemed);
80                 myseq->length(nbval);
81                 for (int i=0; i<nbval; i++)
82                 {
83                         myseq[i]=values[i];
84                 };
85         }
86         catch (MEDEXCEPTION &ex)
87         {
88                 MESSAGE("Unable to acces Field ");
89                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
90         }
91         return myseq._retn();
92 }
93 //=============================================================================
94 /*!
95  * CORBA: Accessor for Field's values
96 */
97 //=============================================================================
98
99 SALOME::SenderDouble_ptr FIELDDOUBLE_i::getSenderForValue( SALOME_MED::medModeSwitch mode ) 
100 throw (SALOME::SALOME_Exception)
101 {
102         if (_fieldTptr==NULL)
103                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
104                                              SALOME::INTERNAL_ERROR);
105         SALOME::SenderDouble_ptr ret;
106         try
107         {
108                 medModeSwitch modemed=convertIdlModeToMedMode(mode);
109                 // ::FIELD<double> *ptrD=dynamic_cast< ::FIELD<double>* >(_fieldTptr);
110                 // the alternative is not safe but the dynamic_cast fails using the python API
111                 MEDMEM::FIELD<double> *ptrD=static_cast< MEDMEM::FIELD<double>* >(_fieldTptr);
112                 const double * values =ptrD->getValue(modemed);
113                 int nbval=ptrD->getValueLength(modemed);
114                 ret=SenderFactory::buildSender(*this,values,nbval);
115         }
116         catch (MEDEXCEPTION &ex)
117         {
118                 MESSAGE("Unable to acces Field ");
119                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
120         }
121         return ret;
122 }