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