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