Back to index

salome-med  6.5.0
MEDMEM_Coordinate.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "MEDMEM_Coordinate.hxx"
00024 #include "MEDMEM_Exception.hxx"
00025 #include "MEDMEM_STRING.hxx"
00026 
00027 #include "MEDMEM_Utilities.hxx"
00028 
00029 #include <cstring>
00030 
00031 using namespace std;
00032 using namespace MEDMEM;
00033 using namespace MED_EN;
00034 
00036 //----------------------------------------------------------//
00037 COORDINATE::COORDINATE():_coordinateSystem(""),
00038                          _coordinate(MEDARRAY<double>()),
00039                          _coordinateName(),
00040                          _coordinateUnit(),
00041                          _nodeNumber()
00042 //----------------------------------------------------------//
00043 {
00044   const char* LOC = "Default Constructor COORDINATE";
00045   BEGIN_OF_MED(LOC);
00046 }
00047 
00050 //------------------------------------------------------------------------------//
00051 COORDINATE::COORDINATE(int SpaceDimension, int NumberOfNodes, medModeSwitch Mode):
00052   _coordinateSystem(""),
00053   _coordinate(SpaceDimension,NumberOfNodes,Mode),
00054   _coordinateName(SpaceDimension),
00055   _coordinateUnit(SpaceDimension),
00056   _nodeNumber()
00057 
00058 //------------------------------------------------------------------------------//
00059 {
00060   const char* LOC = "Constructor COORDINATE";
00061   BEGIN_OF_MED(LOC);
00062 }
00063 
00070 //------------------------------------------------------------------------------//
00071 COORDINATE::COORDINATE(int SpaceDimension,const string * CoordinateName, const string * CoordinateUnit): 
00072    _coordinateSystem(""), _coordinate(MEDARRAY<double>()), _coordinateName(SpaceDimension), 
00073    _coordinateUnit(SpaceDimension), _nodeNumber()
00074 {
00075     for (int i=0; i<SpaceDimension; ++i)
00076     {
00077         _coordinateName[i]=CoordinateName[i];
00078         _coordinateUnit[i]=CoordinateUnit[i];
00079     }
00080 }
00081 
00082 
00087 //------------------------------------------------------------------------------//
00088 COORDINATE::COORDINATE(const COORDINATE & m):
00089   _coordinateSystem(m._coordinateSystem)
00090 //------------------------------------------------------------------------------//
00091 {
00092   const char* LOC = "Copy Constructor COORDINATE";
00093   BEGIN_OF_MED(LOC);
00094 
00095   _coordinate = m._coordinate;
00096   //int spaceDimension = _coordinate.getLeadingValue();
00097   int numberOfNodes = _coordinate.getLengthValue();
00098 
00099   SCRUTE_MED(_coordinate.getLeadingValue());
00100   //setCoordinatesNames((const string*)m._coordinateName) ;
00101   //setCoordinatesUnits((const string*)m._coordinateUnit) ;
00102   setCoordinatesNames( m.getCoordinatesNames() );
00103   setCoordinatesUnits( m.getCoordinatesUnits() );
00104 
00105   if ( (const int * const) m._nodeNumber != NULL)
00106     _nodeNumber.set(numberOfNodes,(const int*)m._nodeNumber);
00107   // PG : it's default no ?
00108 //    else
00109 //      {
00110 //        _nodeNumber.set(0);
00111 //      }
00112 }
00113 
00114 
00115 /* does nothing :   all attributs are object (not pointers) */
00116 //----------------------//
00117 COORDINATE::~COORDINATE()
00118 //----------------------//
00119 {
00120   MESSAGE_MED("~COORDINATE()");
00121 }
00122 
00124 //----------------------------------------------------------//
00125 void COORDINATE::setCoordinates(MEDARRAY<double> *Coordinate,bool shallowCopy) 
00126 //----------------------------------------------------------//
00127 { 
00128 
00129   const medModeSwitch mode = Coordinate->getMode(); 
00130   //  const int  spaceDimension = (int) Coordinate->getLeadingValue();
00131   //  const int  numberOfNodes  = (int) Coordinate->getLengthValue();
00132   if ( Coordinate->get(mode) != NULL)
00133   {
00134     if(shallowCopy)
00135       {
00136         _coordinate.shallowCopy(*Coordinate);
00137       }
00138     else
00139       {
00140         MEDARRAY<double> pourAttribut(*Coordinate,false);
00141         _coordinate = pourAttribut;
00142         //_coordinate.set(mode,Coordinate->get(mode));
00143       }
00144   }
00145   else
00146   {
00147         throw MED_EXCEPTION ( LOCALIZED(STRING("setCoordinates(MEDARRAY<double> *Coordinate)") << "No Coordinate"));
00148   }
00149 }
00150 
00156 //----------------------------------------------------------//
00157 void COORDINATE::setCoordinates(const medModeSwitch Mode, 
00158                                 const double *Coordinate) 
00159 //----------------------------------------------------------//
00160 { 
00161 //    if (_coordinate == NULL)
00162 //      throw MEDEXCEPTION("COORDINATE::setCoordinates(double*) : coordinate array not allocated !");
00163 
00164   _coordinate.set(Mode,Coordinate);
00165 }
00166 
00168 //----------------------------------------------------------//
00169 void COORDINATE::setCoordinatesNames(const string * CoordinateName) 
00170 //----------------------------------------------------------//
00171 {
00172   int SpaceDimension = getSpaceDimension() ;
00173   //_coordinateName.set(SpaceDimension) ;
00174   _coordinateName.resize(SpaceDimension);
00175   for (int i=0; i<SpaceDimension; i++)
00176     _coordinateName[i]=CoordinateName[i];
00177 }
00178 
00183 //----------------------------------------------------------//
00184 void COORDINATE::setCoordinateName(const string CoordinateName, const int i)
00185 //----------------------------------------------------------//
00186 {
00187   _coordinateName[i]=CoordinateName;
00188 }
00189 
00191 //----------------------------------------------------------//
00192 void COORDINATE::setCoordinatesUnits(const string * CoordinateUnit) 
00193 //----------------------------------------------------------//
00194 { 
00195   int SpaceDimension = getSpaceDimension() ;
00196   //_coordinateUnit.set(SpaceDimension) ; 
00197   _coordinateUnit.resize(SpaceDimension) ; 
00198   for (int i=0; i<SpaceDimension; i++)
00199     _coordinateUnit[i]=CoordinateUnit[i];
00200 }
00201 
00206 //----------------------------------------------------------//
00207 void COORDINATE::setCoordinateUnit(const string CoordinateUnit, const int i) 
00208 //----------------------------------------------------------//
00209 { 
00210   _coordinateUnit[i]=CoordinateUnit;
00211 }
00212 
00214 //----------------------------------------------------------//
00215 void COORDINATE::setCoordinatesSystem(const string CoordinateSystem) 
00216 //----------------------------------------------------------//
00217 { 
00218         _coordinateSystem=CoordinateSystem; 
00219 }
00220 
00222 //------------------------------------------------//
00223 void COORDINATE::setNodesNumbers(const int * NodeNumber) 
00224 //------------------------------------------------//
00225 {       
00226   int NumberOfNodes = getNumberOfNodes() ;
00227   _nodeNumber.set(NumberOfNodes,NodeNumber) ; 
00228 }
00229 
00230 int COORDINATE::getSpaceDimension() const
00231 {       
00232   return _coordinate.getLeadingValue() ; 
00233 }
00234 
00235 int COORDINATE::getNumberOfNodes() const
00236 {       
00237   return _coordinate.getLengthValue() ; 
00238 }
00239 
00240 
00243 //-------------------------------------------------//
00244 const int * COORDINATE::getNodesNumbers() const
00245 //-------------------------------------------------//
00246 {
00247         return  (const int *)_nodeNumber;
00248 }
00249 
00251 //--------------------------------------------------------------------------//
00252 const double *  COORDINATE::getCoordinates (medModeSwitch Mode)
00253 //--------------------------------------------------------------------------//
00254 {
00255         return _coordinate.get(Mode) ;
00256 }
00257 
00258 /* returns the coordinate of node Number on axis Axis */
00259 //----------------------------------------------------//
00260 double COORDINATE::getCoordinate(int Number,int Axis) 
00261 //----------------------------------------------------//
00262 {       
00263         return _coordinate.getIJ(Number,Axis) ;
00264 }
00265 
00266 /* returns all nodes coordinates from  axis Axis      */
00267 //----------------------------------------------------//
00268 const double *  COORDINATE::getCoordinateAxis(int Axis)
00269 //----------------------------------------------------//
00270 {                       //< return all nodes coordinates from axis Axis
00271          return _coordinate.getColumn(Axis) ;
00272 }
00273 
00279 //--------------------------------------//
00280 const string * COORDINATE::getCoordinatesNames() const
00281 {
00282   return &(_coordinateName[0]) ;
00283 }
00284 
00285 /* returns the name of axis Axis             */
00286 //-------------------------------------------//
00287 string COORDINATE::getCoordinateName(int Axis) const
00288 //-------------------------------------------//
00289 {
00290   return _coordinateName[Axis-1];
00291 }
00292 
00295 //-----------------------------------------------------//
00296 const string * COORDINATE::getCoordinatesUnits() const
00297 //-----------------------------------------------------//
00298 {
00299   return &(_coordinateUnit[0]) ;
00300 }
00301 
00303 //------------------------------------------//
00304 string COORDINATE::getCoordinateUnit(int Axis) const
00305 //------------------------------------------//
00306 {
00307   return _coordinateUnit[Axis-1] ;
00308 }
00310 //---------------------------------------------------//
00311 string COORDINATE::getCoordinatesSystem() const
00312 //---------------------------------------------------//
00313 {
00314   return _coordinateSystem ;
00315 }