1 // MED MEDMEM : MED files in memory
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : MEDMEM_Coordinate.cxx
28 #include "MEDMEM_Coordinate.hxx"
29 #include "MEDMEM_Exception.hxx"
30 #include "MEDMEM_STRING.hxx"
32 #include "utilities.h"
34 /*! Default Constructor : should not be used */
35 //----------------------------------------------------------//
36 COORDINATE::COORDINATE():_coordinate(MEDARRAY<double>()),
39 _coordinateSystem(""),
41 //----------------------------------------------------------//
43 BEGIN_OF("Default Constructor COORDINATE");
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):
51 _coordinateUnit(SpaceDimension),
52 _coordinateSystem(""),
53 _coordinateName(SpaceDimension),
54 _coordinate(SpaceDimension,NumberOfNodes,Mode)
56 //------------------------------------------------------------------------------//
58 BEGIN_OF("Constructor COORDINATE");
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 //------------------------------------------------------------------------------//
71 BEGIN_OF("Copy Constructor COORDINATE");
73 int spaceDimension = _coordinate.getLeadingValue();
74 int numberOfNodes = _coordinate.getLengthValue();
76 SCRUTE(spaceDimension);
77 setCoordinatesNames((const string*)m._coordinateName) ;
78 setCoordinatesUnits((const string*)m._coordinateUnit) ;
80 if ( (const int * const) m._nodeNumber != NULL)
81 _nodeNumber.set(numberOfNodes,(const med_int*)m._nodeNumber);
82 // PG : it's default no ?
85 // _nodeNumber.set(0);
90 /* does nothing : all attributs are object (not pointers) */
91 //----------------------//
92 COORDINATE::~COORDINATE()
93 //----------------------//
95 MESSAGE("~COORDINATE()");
98 /*! sets the attribute _coordinate with Coordinate */
99 //----------------------------------------------------------//
100 void COORDINATE::setCoordinates(MEDARRAY<double> *Coordinate)
101 //----------------------------------------------------------//
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)
109 MEDARRAY<double> pourAttribut(*Coordinate,false);
110 _coordinate = pourAttribut;
111 //_coordinate.set(mode,Coordinate->get(mode));
115 throw MED_EXCEPTION ( LOCALIZED(STRING("setCoordinates(MEDARRAY<double>
116 *Coordinate)") << "No Coordinate"));
121 Sets the value in attribute _coordinate with Coordinate.
122 _coordinate must be allocated (with
123 COORDINATE::COORDINATE(int,int,medModeSwitch).
125 //----------------------------------------------------------//
126 void COORDINATE::setCoordinates(const medModeSwitch Mode,
127 const double *Coordinate)
128 //----------------------------------------------------------//
130 // if (_coordinate == NULL)
131 // throw MEDEXCEPTION("COORDINATE::setCoordinates(double*) : coordinate array not allocated !");
133 _coordinate.set(Mode,Coordinate);
136 /*! sets the attribute _coordinateName with CoordinateName */
137 //----------------------------------------------------------//
138 void COORDINATE::setCoordinatesNames(const string * CoordinateName)
139 //----------------------------------------------------------//
141 int SpaceDimension = getSpaceDimension() ;
142 _coordinateName.set(SpaceDimension) ;
143 for (int i=0; i<SpaceDimension; i++)
144 _coordinateName[i]=CoordinateName[i];
148 sets the (i+1)^th component of the attribute _coordinateName with
151 //----------------------------------------------------------//
152 void COORDINATE::setCoordinateName(const string CoordinateName, const int i)
153 //----------------------------------------------------------//
155 _coordinateName[i]=CoordinateName;
158 /*! sets the attribute _coordinateUnit with CoordinateUnit */
159 //----------------------------------------------------------//
160 void COORDINATE::setCoordinatesUnits(const string * CoordinateUnit)
161 //----------------------------------------------------------//
163 int SpaceDimension = getSpaceDimension() ;
164 _coordinateUnit.set(SpaceDimension) ;
165 for (int i=0; i<SpaceDimension; i++)
166 _coordinateUnit[i]=CoordinateUnit[i];
170 sets the (i+1)^th component of the attribute _coordinateUnit with
173 //----------------------------------------------------------//
174 void COORDINATE::setCoordinateUnit(const string CoordinateUnit, const int i)
175 //----------------------------------------------------------//
177 _coordinateUnit[i]=CoordinateUnit;
180 /*! sets the attribute _coordinateSystem with CoordinateSystem */
181 //----------------------------------------------------------//
182 void COORDINATE::setCoordinatesSystem(const string CoordinateSystem)
183 //----------------------------------------------------------//
185 _coordinateSystem=CoordinateSystem;
188 /*! sets the attribute _nodeNumber with NodeNumber */
189 //------------------------------------------------//
190 void COORDINATE::setNodesNumbers(const int * NodeNumber)
191 //------------------------------------------------//
193 int NumberOfNodes = getNumberOfNodes() ;
194 _nodeNumber.set(NumberOfNodes,NodeNumber) ;
197 int COORDINATE::getSpaceDimension() const
199 _coordinate.getLeadingValue() ;
202 int COORDINATE::getNumberOfNodes() const
204 _coordinate.getLengthValue() ;
208 /*! returns a pointer to the optional array storing
209 eventual nodes numbers */
210 //-------------------------------------------------//
211 const int * COORDINATE::getNodesNumbers() const
212 //-------------------------------------------------//
214 return (const int *)_nodeNumber;
217 /*! returns a Pointer to Coordinates Array in specified mode representation */
218 //--------------------------------------------------------------------------//
219 const double * COORDINATE::getCoordinates (medModeSwitch Mode)
220 //--------------------------------------------------------------------------//
222 return _coordinate.get(Mode) ;
225 /* returns the coordinate of node Number on axis Axis */
226 //----------------------------------------------------//
227 double COORDINATE::getCoordinate(int Number,int Axis)
228 //----------------------------------------------------//
230 return _coordinate.getIJ(Number,Axis) ;
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) ;
241 /*! returns an array with names of coordinates. /n
246 //--------------------------------------//
247 const string * COORDINATE::getCoordinatesNames() const
249 return _coordinateName ;
252 /* returns the name of axis Axis */
253 //-------------------------------------------//
254 string COORDINATE::getCoordinateName(int Axis) const
255 //-------------------------------------------//
257 return _coordinateName[Axis-1];
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 //-----------------------------------------------------//
266 return _coordinateUnit ;
269 /*! returns the unit of axis Axis */
270 //------------------------------------------//
271 string COORDINATE::getCoordinateUnit(int Axis) const
272 //------------------------------------------//
274 return _coordinateUnit[Axis-1] ;
276 /*! returns "CARTESIAN", "CYLINDRICAL" or "SPHERICAL"*/
277 //---------------------------------------------------//
278 string COORDINATE::getCoordinatesSystem() const
279 //---------------------------------------------------//
281 return _coordinateSystem ;