]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Coordinate.cxx
Salome HOME
update from the MedMemory V1.0.1
[modules/med.git] / src / MEDMEM / MEDMEM_Coordinate.cxx
1 using namespace std;
2 #include "MEDMEM_Coordinate.hxx"
3 #include "MEDMEM_Exception.hxx"
4 #include "MEDMEM_STRING.hxx"
5
6 #include "utilities.h"
7
8 /*! Default Constructor : should not be used */
9 //----------------------------------------------------------//
10 COORDINATE::COORDINATE():_coordinateSystem(""),
11                          _coordinate(MEDARRAY<double>()),
12                          _coordinateName(),
13                          _coordinateUnit(),
14                          _nodeNumber()
15 //----------------------------------------------------------//
16 {
17     BEGIN_OF("Default Constructor COORDINATE");
18 }
19
20 /*! This constructor allocate a MEDARRAY of SpaceDimension * NumberOfNodes./n
21     It will create empty array for optional data (nodeNumber..) */
22 //------------------------------------------------------------------------------//
23 COORDINATE::COORDINATE(int SpaceDimension, int NumberOfNodes, medModeSwitch Mode):
24   _coordinateSystem(""),
25   _coordinate(SpaceDimension,NumberOfNodes,Mode),
26   _coordinateName(SpaceDimension),
27   _coordinateUnit(SpaceDimension),
28   _nodeNumber()
29
30 //------------------------------------------------------------------------------//
31 {
32     BEGIN_OF("Constructor COORDINATE");
33 }
34
35 /*! This constructor will COPY all data (it is a deep copy) included in m./n  
36     But only the default storage mode of coordinates array
37     will be copied (not both storage representation modes even if they both
38     exist in original object) :  for example only full_interlace mode  */
39 //------------------------------------------------------------------------------//
40 COORDINATE::COORDINATE(const COORDINATE & m):
41   _coordinateSystem(m._coordinateSystem),
42   _coordinate(m._coordinate,false)
43 //------------------------------------------------------------------------------//
44 {
45   BEGIN_OF("Copy Constructor COORDINATE");
46
47   int spaceDimension = _coordinate.getLeadingValue();
48   int numberOfNodes = _coordinate.getLengthValue();
49
50   SCRUTE(spaceDimension);
51   setCoordinatesNames((const string*)m._coordinateName) ;
52   setCoordinatesUnits((const string*)m._coordinateUnit) ;
53
54   if ( (const int * const) m._nodeNumber != NULL)
55     _nodeNumber.set(numberOfNodes,(const med_int*)m._nodeNumber);
56   // PG : it's default no ?
57 //    else
58 //      {
59 //        _nodeNumber.set(0);
60 //      }
61 }
62
63
64 /* does nothing :   all attributs are object (not pointers) */
65 //----------------------//
66 COORDINATE::~COORDINATE()
67 //----------------------//
68 {
69   MESSAGE("~COORDINATE()");
70 }
71
72 /*! sets the attribute _coordinate with Coordinate           */
73 //----------------------------------------------------------//
74 void COORDINATE::setCoordinates(MEDARRAY<double> *Coordinate) 
75 //----------------------------------------------------------//
76
77
78   const medModeSwitch mode = Coordinate->getMode(); 
79   //  const int  spaceDimension = (int) Coordinate->getLeadingValue();
80   //  const int  numberOfNodes  = (int) Coordinate->getLengthValue();
81   if ( Coordinate->get(mode) != NULL)
82   {
83       MEDARRAY<double> pourAttribut(*Coordinate,false);
84       _coordinate = pourAttribut;
85       //_coordinate.set(mode,Coordinate->get(mode));
86   }
87   else
88   {
89         throw MED_EXCEPTION ( LOCALIZED(STRING("setCoordinates(MEDARRAY<double>
90          *Coordinate)") << "No Coordinate"));
91   }
92 }
93
94 /*!
95   Sets the value in attribute _coordinate with Coordinate.
96   _coordinate must be allocated (with 
97   COORDINATE::COORDINATE(int,int,medModeSwitch).
98 */
99 //----------------------------------------------------------//
100 void COORDINATE::setCoordinates(const medModeSwitch Mode, 
101                                 const double *Coordinate) 
102 //----------------------------------------------------------//
103
104 //    if (_coordinate == NULL)
105 //      throw MEDEXCEPTION("COORDINATE::setCoordinates(double*) : coordinate array not allocated !");
106
107   _coordinate.set(Mode,Coordinate);
108 }
109
110 /*! sets the attribute _coordinateName with CoordinateName   */
111 //----------------------------------------------------------//
112 void COORDINATE::setCoordinatesNames(const string * CoordinateName) 
113 //----------------------------------------------------------//
114 {
115   int SpaceDimension = getSpaceDimension() ;
116   _coordinateName.set(SpaceDimension) ;
117   for (int i=0; i<SpaceDimension; i++)
118     _coordinateName[i]=CoordinateName[i];
119 }
120
121 /*!
122   sets the (i+1)^th component of the attribute _coordinateName with
123   CoordinateName
124 */
125 //----------------------------------------------------------//
126 void COORDINATE::setCoordinateName(const string CoordinateName, const int i)
127 //----------------------------------------------------------//
128 {
129   _coordinateName[i]=CoordinateName;
130 }
131
132 /*! sets the attribute _coordinateUnit with CoordinateUnit   */
133 //----------------------------------------------------------//
134 void COORDINATE::setCoordinatesUnits(const string * CoordinateUnit) 
135 //----------------------------------------------------------//
136
137   int SpaceDimension = getSpaceDimension() ;
138   _coordinateUnit.set(SpaceDimension) ; 
139   for (int i=0; i<SpaceDimension; i++)
140     _coordinateUnit[i]=CoordinateUnit[i];
141 }
142
143 /*!
144   sets the (i+1)^th component of the attribute _coordinateUnit with
145   CoordinateUnit
146 */
147 //----------------------------------------------------------//
148 void COORDINATE::setCoordinateUnit(const string CoordinateUnit, const int i) 
149 //----------------------------------------------------------//
150
151   _coordinateUnit[i]=CoordinateUnit;
152 }
153
154 /*! sets the attribute _coordinateSystem with CoordinateSystem   */
155 //----------------------------------------------------------//
156 void COORDINATE::setCoordinatesSystem(const string CoordinateSystem) 
157 //----------------------------------------------------------//
158
159         _coordinateSystem=CoordinateSystem; 
160 }
161
162 /*! sets the attribute _nodeNumber with NodeNumber */
163 //------------------------------------------------//
164 void COORDINATE::setNodesNumbers(const int * NodeNumber) 
165 //------------------------------------------------//
166 {       
167   int NumberOfNodes = getNumberOfNodes() ;
168   _nodeNumber.set(NumberOfNodes,NodeNumber) ; 
169 }
170
171 int COORDINATE::getSpaceDimension() const
172 {       
173   return _coordinate.getLeadingValue() ; 
174 }
175
176 int COORDINATE::getNumberOfNodes() const
177 {       
178   return _coordinate.getLengthValue() ; 
179 }
180
181
182 /*! returns a pointer to the optional array storing 
183     eventual nodes numbers */
184 //-------------------------------------------------//
185 const int * COORDINATE::getNodesNumbers() const
186 //-------------------------------------------------//
187 {
188         return  (const int *)_nodeNumber;
189 }
190
191 /*! returns a Pointer to Coordinates Array in specified mode representation */
192 //--------------------------------------------------------------------------//
193 const double *  COORDINATE::getCoordinates (medModeSwitch Mode)
194 //--------------------------------------------------------------------------//
195 {
196         return _coordinate.get(Mode) ;
197 }
198
199 /* returns the coordinate of node Number on axis Axis */
200 //----------------------------------------------------//
201 double COORDINATE::getCoordinate(int Number,int Axis) 
202 //----------------------------------------------------//
203 {       
204         return _coordinate.getIJ(Number,Axis) ;
205 }
206
207 /* returns all nodes coordinates from  axis Axis      */
208 //----------------------------------------------------//
209 const double *  COORDINATE::getCoordinateAxis(int Axis)
210 //----------------------------------------------------//
211 {                       //< return all nodes coordinates from axis Axis
212          return _coordinate.getColumn(Axis) ;
213 }
214
215 /*! returns an array with names of coordinates. /n
216       Example : /n
217       - x,y,z /n
218       - r,teta,phi /n
219       - ... */
220 //--------------------------------------//
221 const string * COORDINATE::getCoordinatesNames() const
222 {
223         return _coordinateName ;
224 }
225
226 /* returns the name of axis Axis             */
227 //-------------------------------------------//
228 string COORDINATE::getCoordinateName(int Axis) const
229 //-------------------------------------------//
230 {
231         return _coordinateName[Axis-1];
232 }
233
234 /*!  returns an array with units of coordinates (cm, m, mm, ...)
235      It could be empty. We suppose we are IS (meter).  */
236 //-----------------------------------------------------//
237 const string * COORDINATE::getCoordinatesUnits() const
238 //-----------------------------------------------------//
239 {
240         return _coordinateUnit ;
241 }
242
243 /*! returns the unit of axis Axis           */
244 //------------------------------------------//
245 string COORDINATE::getCoordinateUnit(int Axis) const
246 //------------------------------------------//
247 {
248         return _coordinateUnit[Axis-1] ;
249 }
250 /*! returns "CARTESIAN", "CYLINDRICAL" or "SPHERICAL"*/
251 //---------------------------------------------------//
252 string COORDINATE::getCoordinatesSystem() const
253 //---------------------------------------------------//
254 {
255   return _coordinateSystem ;
256 }