1 // Copyright (C) 2007-2008 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
22 #include "MEDMEM_Coordinate.hxx"
23 #include "MEDMEM_Exception.hxx"
24 #include "MEDMEM_STRING.hxx"
26 #include "MEDMEM_Utilities.hxx"
29 using namespace MEDMEM;
30 using namespace MED_EN;
32 /*! Default Constructor : should not be used */
33 //----------------------------------------------------------//
34 COORDINATE::COORDINATE():_coordinateSystem(""),
35 _coordinate(MEDARRAY<double>()),
39 //----------------------------------------------------------//
41 const char* LOC = "Default Constructor COORDINATE";
45 /*! This constructor allocate a MEDARRAY of SpaceDimension * NumberOfNodes.\n
46 It will create empty array for optional data (nodeNumber..) */
47 //------------------------------------------------------------------------------//
48 COORDINATE::COORDINATE(int SpaceDimension, int NumberOfNodes, medModeSwitch Mode):
49 _coordinateSystem(""),
50 _coordinate(SpaceDimension,NumberOfNodes,Mode),
51 _coordinateName(SpaceDimension),
52 _coordinateUnit(SpaceDimension),
55 //------------------------------------------------------------------------------//
57 const char* LOC = "Constructor COORDINATE";
61 /*! This constructor is specialy designed for use in class GRID.\n
62 * The purpose is to create a COORDINATE without allocating memory for nodes (in the MEDARRAY).
63 * The allocation (call to setCoordinates) is performed afterward by GRID, if necessary.
64 * We set _coordinateName & _coordinateUnit in the constructor, because calls to setCoordinateName
65 * and setCoordinateUnit are not possible before allocation of MEDARRAY.
67 //------------------------------------------------------------------------------//
68 COORDINATE::COORDINATE(int SpaceDimension,const string * CoordinateName, const string * CoordinateUnit):
69 _coordinateSystem(""), _coordinate(MEDARRAY<double>()), _coordinateName(SpaceDimension),
70 _coordinateUnit(SpaceDimension), _nodeNumber()
72 for (int i=0; i<SpaceDimension; ++i)
74 _coordinateName[i]=CoordinateName[i];
75 _coordinateUnit[i]=CoordinateUnit[i];
80 /*! This constructor will COPY all data (it is a deep copy) included in m.\n
81 But only the default storage mode of coordinates array
82 will be copied (not both storage representation modes even if they both
83 exist in original object) : for example only full_interlace mode */
84 //------------------------------------------------------------------------------//
85 COORDINATE::COORDINATE(const COORDINATE & m):
86 _coordinateSystem(m._coordinateSystem)
87 //------------------------------------------------------------------------------//
89 const char* LOC = "Copy Constructor COORDINATE";
92 _coordinate = m._coordinate;
93 //int spaceDimension = _coordinate.getLeadingValue();
94 int numberOfNodes = _coordinate.getLengthValue();
96 SCRUTE_MED(_coordinate.getLeadingValue());
97 //setCoordinatesNames((const string*)m._coordinateName) ;
98 //setCoordinatesUnits((const string*)m._coordinateUnit) ;
99 setCoordinatesNames( m.getCoordinatesNames() );
100 setCoordinatesUnits( m.getCoordinatesUnits() );
102 if ( (const int * const) m._nodeNumber != NULL)
103 _nodeNumber.set(numberOfNodes,(const int*)m._nodeNumber);
104 // PG : it's default no ?
107 // _nodeNumber.set(0);
112 /* does nothing : all attributs are object (not pointers) */
113 //----------------------//
114 COORDINATE::~COORDINATE()
115 //----------------------//
117 MESSAGE_MED("~COORDINATE()");
120 /*! sets the attribute _coordinate with Coordinate */
121 //----------------------------------------------------------//
122 void COORDINATE::setCoordinates(MEDARRAY<double> *Coordinate,bool shallowCopy)
123 //----------------------------------------------------------//
126 const medModeSwitch mode = Coordinate->getMode();
127 // const int spaceDimension = (int) Coordinate->getLeadingValue();
128 // const int numberOfNodes = (int) Coordinate->getLengthValue();
129 if ( Coordinate->get(mode) != NULL)
133 _coordinate.shallowCopy(*Coordinate);
137 MEDARRAY<double> pourAttribut(*Coordinate,false);
138 _coordinate = pourAttribut;
139 //_coordinate.set(mode,Coordinate->get(mode));
144 throw MED_EXCEPTION ( LOCALIZED(STRING("setCoordinates(MEDARRAY<double> *Coordinate)") << "No Coordinate"));
149 Sets the value in attribute _coordinate with Coordinate.
150 _coordinate must be allocated (with
151 COORDINATE::COORDINATE(int,int,medModeSwitch).
153 //----------------------------------------------------------//
154 void COORDINATE::setCoordinates(const medModeSwitch Mode,
155 const double *Coordinate)
156 //----------------------------------------------------------//
158 // if (_coordinate == NULL)
159 // throw MEDEXCEPTION("COORDINATE::setCoordinates(double*) : coordinate array not allocated !");
161 _coordinate.set(Mode,Coordinate);
164 /*! sets the attribute _coordinateName with CoordinateName */
165 //----------------------------------------------------------//
166 void COORDINATE::setCoordinatesNames(const string * CoordinateName)
167 //----------------------------------------------------------//
169 int SpaceDimension = getSpaceDimension() ;
170 //_coordinateName.set(SpaceDimension) ;
171 _coordinateName.resize(SpaceDimension);
172 for (int i=0; i<SpaceDimension; i++)
173 _coordinateName[i]=CoordinateName[i];
177 sets the (i+1)^th component of the attribute _coordinateName with
180 //----------------------------------------------------------//
181 void COORDINATE::setCoordinateName(const string CoordinateName, const int i)
182 //----------------------------------------------------------//
184 _coordinateName[i]=CoordinateName;
187 /*! sets the attribute _coordinateUnit with CoordinateUnit */
188 //----------------------------------------------------------//
189 void COORDINATE::setCoordinatesUnits(const string * CoordinateUnit)
190 //----------------------------------------------------------//
192 int SpaceDimension = getSpaceDimension() ;
193 //_coordinateUnit.set(SpaceDimension) ;
194 _coordinateUnit.resize(SpaceDimension) ;
195 for (int i=0; i<SpaceDimension; i++)
196 _coordinateUnit[i]=CoordinateUnit[i];
200 sets the (i+1)^th component of the attribute _coordinateUnit with
203 //----------------------------------------------------------//
204 void COORDINATE::setCoordinateUnit(const string CoordinateUnit, const int i)
205 //----------------------------------------------------------//
207 _coordinateUnit[i]=CoordinateUnit;
210 /*! sets the attribute _coordinateSystem with CoordinateSystem */
211 //----------------------------------------------------------//
212 void COORDINATE::setCoordinatesSystem(const string CoordinateSystem)
213 //----------------------------------------------------------//
215 _coordinateSystem=CoordinateSystem;
218 /*! sets the attribute _nodeNumber with NodeNumber */
219 //------------------------------------------------//
220 void COORDINATE::setNodesNumbers(const int * NodeNumber)
221 //------------------------------------------------//
223 int NumberOfNodes = getNumberOfNodes() ;
224 _nodeNumber.set(NumberOfNodes,NodeNumber) ;
227 int COORDINATE::getSpaceDimension() const
229 return _coordinate.getLeadingValue() ;
232 int COORDINATE::getNumberOfNodes() const
234 return _coordinate.getLengthValue() ;
238 /*! returns a pointer to the optional array storing
239 eventual nodes numbers */
240 //-------------------------------------------------//
241 const int * COORDINATE::getNodesNumbers() const
242 //-------------------------------------------------//
244 return (const int *)_nodeNumber;
247 /*! returns a Pointer to Coordinates Array in specified mode representation */
248 //--------------------------------------------------------------------------//
249 const double * COORDINATE::getCoordinates (medModeSwitch Mode)
250 //--------------------------------------------------------------------------//
252 return _coordinate.get(Mode) ;
255 /* returns the coordinate of node Number on axis Axis */
256 //----------------------------------------------------//
257 double COORDINATE::getCoordinate(int Number,int Axis)
258 //----------------------------------------------------//
260 return _coordinate.getIJ(Number,Axis) ;
263 /* returns all nodes coordinates from axis Axis */
264 //----------------------------------------------------//
265 const double * COORDINATE::getCoordinateAxis(int Axis)
266 //----------------------------------------------------//
267 { //< return all nodes coordinates from axis Axis
268 return _coordinate.getColumn(Axis) ;
271 /*! returns an array with names of coordinates. \n
276 //--------------------------------------//
277 const string * COORDINATE::getCoordinatesNames() const
279 return &(_coordinateName[0]) ;
282 /* returns the name of axis Axis */
283 //-------------------------------------------//
284 string COORDINATE::getCoordinateName(int Axis) const
285 //-------------------------------------------//
287 return _coordinateName[Axis-1];
290 /*! returns an array with units of coordinates (cm, m, mm, ...)
291 It could be empty. We suppose we are IS (meter). */
292 //-----------------------------------------------------//
293 const string * COORDINATE::getCoordinatesUnits() const
294 //-----------------------------------------------------//
296 return &(_coordinateUnit[0]) ;
299 /*! returns the unit of axis Axis */
300 //------------------------------------------//
301 string COORDINATE::getCoordinateUnit(int Axis) const
302 //------------------------------------------//
304 return _coordinateUnit[Axis-1] ;
306 /*! returns "CARTESIAN", "CYLINDRICAL" or "SPHERICAL"*/
307 //---------------------------------------------------//
308 string COORDINATE::getCoordinatesSystem() const
309 //---------------------------------------------------//
311 return _coordinateSystem ;