1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "MEDMEM_Coordinate.hxx"
24 #include "MEDMEM_Exception.hxx"
25 #include "MEDMEM_STRING.hxx"
27 #include "MEDMEM_Utilities.hxx"
32 using namespace MEDMEM;
33 using namespace MED_EN;
35 /*! Default Constructor : should not be used */
36 //----------------------------------------------------------//
37 COORDINATE::COORDINATE():_coordinateSystem(""),
38 _coordinate(MEDARRAY<double>()),
42 //----------------------------------------------------------//
44 const char* LOC = "Default Constructor COORDINATE";
48 /*! This constructor allocate a MEDARRAY of SpaceDimension * NumberOfNodes.\n
49 It will create empty array for optional data (nodeNumber..) */
50 //------------------------------------------------------------------------------//
51 COORDINATE::COORDINATE(int SpaceDimension, int NumberOfNodes, medModeSwitch Mode):
52 _coordinateSystem(""),
53 _coordinate(SpaceDimension,NumberOfNodes,Mode),
54 _coordinateName(SpaceDimension),
55 _coordinateUnit(SpaceDimension),
58 //------------------------------------------------------------------------------//
60 const char* LOC = "Constructor COORDINATE";
64 /*! This constructor is specialy designed for use in class GRID.\n
65 * The purpose is to create a COORDINATE without allocating memory for nodes (in the MEDARRAY).
66 * The allocation (call to setCoordinates) is performed afterward by GRID, if necessary.
67 * We set _coordinateName & _coordinateUnit in the constructor, because calls to setCoordinateName
68 * and setCoordinateUnit are not possible before allocation of MEDARRAY.
70 //------------------------------------------------------------------------------//
71 COORDINATE::COORDINATE(int SpaceDimension,const string * CoordinateName, const string * CoordinateUnit):
72 _coordinateSystem(""), _coordinate(MEDARRAY<double>()), _coordinateName(SpaceDimension),
73 _coordinateUnit(SpaceDimension), _nodeNumber()
75 for (int i=0; i<SpaceDimension; ++i)
77 _coordinateName[i]=CoordinateName[i];
78 _coordinateUnit[i]=CoordinateUnit[i];
83 /*! This constructor will COPY all data (it is a deep copy) included in m.\n
84 But only the default storage mode of coordinates array
85 will be copied (not both storage representation modes even if they both
86 exist in original object) : for example only full_interlace mode */
87 //------------------------------------------------------------------------------//
88 COORDINATE::COORDINATE(const COORDINATE & m):
89 _coordinateSystem(m._coordinateSystem)
90 //------------------------------------------------------------------------------//
92 const char* LOC = "Copy Constructor COORDINATE";
95 _coordinate = m._coordinate;
96 //int spaceDimension = _coordinate.getLeadingValue();
97 int numberOfNodes = _coordinate.getLengthValue();
99 SCRUTE_MED(_coordinate.getLeadingValue());
100 //setCoordinatesNames((const string*)m._coordinateName) ;
101 //setCoordinatesUnits((const string*)m._coordinateUnit) ;
102 setCoordinatesNames( m.getCoordinatesNames() );
103 setCoordinatesUnits( m.getCoordinatesUnits() );
105 if ( (const int * const) m._nodeNumber != NULL)
106 _nodeNumber.set(numberOfNodes,(const int*)m._nodeNumber);
107 // PG : it's default no ?
110 // _nodeNumber.set(0);
115 /* does nothing : all attributs are object (not pointers) */
116 //----------------------//
117 COORDINATE::~COORDINATE()
118 //----------------------//
120 MESSAGE_MED("~COORDINATE()");
123 /*! sets the attribute _coordinate with Coordinate */
124 //----------------------------------------------------------//
125 void COORDINATE::setCoordinates(MEDARRAY<double> *Coordinate,bool shallowCopy)
126 //----------------------------------------------------------//
129 const medModeSwitch mode = Coordinate->getMode();
130 // const int spaceDimension = (int) Coordinate->getLeadingValue();
131 // const int numberOfNodes = (int) Coordinate->getLengthValue();
132 if ( Coordinate->get(mode) != NULL)
136 _coordinate.shallowCopy(*Coordinate);
140 MEDARRAY<double> pourAttribut(*Coordinate,false);
141 _coordinate = pourAttribut;
142 //_coordinate.set(mode,Coordinate->get(mode));
147 throw MED_EXCEPTION ( LOCALIZED(STRING("setCoordinates(MEDARRAY<double> *Coordinate)") << "No Coordinate"));
152 Sets the value in attribute _coordinate with Coordinate.
153 _coordinate must be allocated (with
154 COORDINATE::COORDINATE(int,int,medModeSwitch).
156 //----------------------------------------------------------//
157 void COORDINATE::setCoordinates(const medModeSwitch Mode,
158 const double *Coordinate)
159 //----------------------------------------------------------//
161 // if (_coordinate == NULL)
162 // throw MEDEXCEPTION("COORDINATE::setCoordinates(double*) : coordinate array not allocated !");
164 _coordinate.set(Mode,Coordinate);
167 /*! sets the attribute _coordinateName with CoordinateName */
168 //----------------------------------------------------------//
169 void COORDINATE::setCoordinatesNames(const string * CoordinateName)
170 //----------------------------------------------------------//
172 int SpaceDimension = getSpaceDimension() ;
173 //_coordinateName.set(SpaceDimension) ;
174 _coordinateName.resize(SpaceDimension);
175 for (int i=0; i<SpaceDimension; i++)
176 _coordinateName[i]=CoordinateName[i];
180 sets the (i+1)^th component of the attribute _coordinateName with
183 //----------------------------------------------------------//
184 void COORDINATE::setCoordinateName(const string CoordinateName, const int i)
185 //----------------------------------------------------------//
187 _coordinateName[i]=CoordinateName;
190 /*! sets the attribute _coordinateUnit with CoordinateUnit */
191 //----------------------------------------------------------//
192 void COORDINATE::setCoordinatesUnits(const string * CoordinateUnit)
193 //----------------------------------------------------------//
195 int SpaceDimension = getSpaceDimension() ;
196 //_coordinateUnit.set(SpaceDimension) ;
197 _coordinateUnit.resize(SpaceDimension) ;
198 for (int i=0; i<SpaceDimension; i++)
199 _coordinateUnit[i]=CoordinateUnit[i];
203 sets the (i+1)^th component of the attribute _coordinateUnit with
206 //----------------------------------------------------------//
207 void COORDINATE::setCoordinateUnit(const string CoordinateUnit, const int i)
208 //----------------------------------------------------------//
210 _coordinateUnit[i]=CoordinateUnit;
213 /*! sets the attribute _coordinateSystem with CoordinateSystem */
214 //----------------------------------------------------------//
215 void COORDINATE::setCoordinatesSystem(const string CoordinateSystem)
216 //----------------------------------------------------------//
218 _coordinateSystem=CoordinateSystem;
221 /*! sets the attribute _nodeNumber with NodeNumber */
222 //------------------------------------------------//
223 void COORDINATE::setNodesNumbers(const int * NodeNumber)
224 //------------------------------------------------//
226 int NumberOfNodes = getNumberOfNodes() ;
227 _nodeNumber.set(NumberOfNodes,NodeNumber) ;
230 int COORDINATE::getSpaceDimension() const
232 return _coordinate.getLeadingValue() ;
235 int COORDINATE::getNumberOfNodes() const
237 return _coordinate.getLengthValue() ;
241 /*! returns a pointer to the optional array storing
242 eventual nodes numbers */
243 //-------------------------------------------------//
244 const int * COORDINATE::getNodesNumbers() const
245 //-------------------------------------------------//
247 return (const int *)_nodeNumber;
250 /*! returns a Pointer to Coordinates Array in specified mode representation */
251 //--------------------------------------------------------------------------//
252 const double * COORDINATE::getCoordinates (medModeSwitch Mode)
253 //--------------------------------------------------------------------------//
255 return _coordinate.get(Mode) ;
258 /* returns the coordinate of node Number on axis Axis */
259 //----------------------------------------------------//
260 double COORDINATE::getCoordinate(int Number,int Axis)
261 //----------------------------------------------------//
263 return _coordinate.getIJ(Number,Axis) ;
266 /* returns all nodes coordinates from axis Axis */
267 //----------------------------------------------------//
268 const double * COORDINATE::getCoordinateAxis(int Axis)
269 //----------------------------------------------------//
270 { //< return all nodes coordinates from axis Axis
271 return _coordinate.getColumn(Axis) ;
274 /*! returns an array with names of coordinates. \n
279 //--------------------------------------//
280 const string * COORDINATE::getCoordinatesNames() const
282 return &(_coordinateName[0]) ;
285 /* returns the name of axis Axis */
286 //-------------------------------------------//
287 string COORDINATE::getCoordinateName(int Axis) const
288 //-------------------------------------------//
290 return _coordinateName[Axis-1];
293 /*! returns an array with units of coordinates (cm, m, mm, ...)
294 It could be empty. We suppose we are IS (meter). */
295 //-----------------------------------------------------//
296 const string * COORDINATE::getCoordinatesUnits() const
297 //-----------------------------------------------------//
299 return &(_coordinateUnit[0]) ;
302 /*! returns the unit of axis Axis */
303 //------------------------------------------//
304 string COORDINATE::getCoordinateUnit(int Axis) const
305 //------------------------------------------//
307 return _coordinateUnit[Axis-1] ;
309 /*! returns "CARTESIAN", "CYLINDRICAL" or "SPHERICAL"*/
310 //---------------------------------------------------//
311 string COORDINATE::getCoordinatesSystem() const
312 //---------------------------------------------------//
314 return _coordinateSystem ;