Salome HOME
remove a reference to the $MED_ROOT_DIR in the Makefile.in wich is useless
[modules/med.git] / src / MEDMEM / MEDMEM_Coordinate.cxx
index 686c618bc8e0aff3675b59fa36362fea846a7718..6b0ab18af11357efbe16aea471735caa13dc0991 100644 (file)
@@ -1,64 +1,60 @@
-//  MED MEDMEM : MED files in memory
-//
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
-//
-//
-//
-//  File   : MEDMEM_Coordinate.cxx
-//  Module : MED
-
-using namespace std;
 #include "MEDMEM_Coordinate.hxx"
 #include "MEDMEM_Exception.hxx"
 #include "MEDMEM_STRING.hxx"
 
 #include "utilities.h"
 
+using namespace std;
+using namespace MEDMEM;
+using namespace MED_EN;
+
 /*! Default Constructor : should not be used */
 //----------------------------------------------------------//
-COORDINATE::COORDINATE():_coordinate(MEDARRAY<double>()),
+COORDINATE::COORDINATE():_coordinateSystem(""),
+                        _coordinate(MEDARRAY<double>()),
                         _coordinateName(),
                         _coordinateUnit(),
-                        _coordinateSystem(""),
                         _nodeNumber()
 //----------------------------------------------------------//
 {
     BEGIN_OF("Default Constructor COORDINATE");
 }
 
-/*! This constructor allocate a MEDARRAY of SpaceDimension * NumberOfNodes./n
+/*! This constructor allocate a MEDARRAY of SpaceDimension * NumberOfNodes.\n
     It will create empty array for optional data (nodeNumber..) */
 //------------------------------------------------------------------------------//
 COORDINATE::COORDINATE(int SpaceDimension, int NumberOfNodes, medModeSwitch Mode):
-                        _nodeNumber(),
-                        _coordinateUnit(SpaceDimension),
-                       _coordinateSystem(""),
-                       _coordinateName(SpaceDimension),
-                       _coordinate(SpaceDimension,NumberOfNodes,Mode)
+  _coordinateSystem(""),
+  _coordinate(SpaceDimension,NumberOfNodes,Mode),
+  _coordinateName(SpaceDimension),
+  _coordinateUnit(SpaceDimension),
+  _nodeNumber()
 
 //------------------------------------------------------------------------------//
 {
     BEGIN_OF("Constructor COORDINATE");
 }
 
-/*! This constructor will COPY all data (it is a deep copy) included in m./n  
+/*! This constructor is specialy designed for use in class GRID.\n
+ *  The purpose is to create a COORDINATE without allocating memory for nodes (in the MEDARRAY).
+ *  The allocation (call to setCoordinates) is performed afterward by GRID, if necessary.
+ *  We set _coordinateName & _coordinateUnit in the constructor, because calls to setCoordinateName
+ *  and setCoordinateUnit are not possible before allocation of MEDARRAY.
+ */
+//------------------------------------------------------------------------------//
+COORDINATE::COORDINATE(int SpaceDimension,const string * CoordinateName, const string * CoordinateUnit): 
+   _coordinateSystem(""), _coordinate(MEDARRAY<double>()), _coordinateName(SpaceDimension), 
+   _coordinateUnit(SpaceDimension), _nodeNumber()
+{
+    for (int i=0; i<SpaceDimension; ++i)
+    {
+       _coordinateName[i]=CoordinateName[i];
+       _coordinateUnit[i]=CoordinateUnit[i];
+    }
+}
+
+
+/*! This constructor will COPY all data (it is a deep copy) included in m.\n  
     But only the default storage mode of coordinates array
     will be copied (not both storage representation modes even if they both
     exist in original object) :  for example only full_interlace mode  */
@@ -78,7 +74,7 @@ COORDINATE::COORDINATE(const COORDINATE & m):
   setCoordinatesUnits((const string*)m._coordinateUnit) ;
 
   if ( (const int * const) m._nodeNumber != NULL)
-    _nodeNumber.set(numberOfNodes,(const med_int*)m._nodeNumber);
+    _nodeNumber.set(numberOfNodes,(const int*)m._nodeNumber);
   // PG : it's default no ?
 //    else
 //      {
@@ -97,23 +93,29 @@ COORDINATE::~COORDINATE()
 
 /*! sets the attribute _coordinate with Coordinate           */
 //----------------------------------------------------------//
-void COORDINATE::setCoordinates(MEDARRAY<double> *Coordinate) 
+void COORDINATE::setCoordinates(MEDARRAY<double> *Coordinate,bool shallowCopy
 //----------------------------------------------------------//
 { 
 
   const medModeSwitch mode = Coordinate->getMode(); 
-  const int  spaceDimension = (int) Coordinate->getLeadingValue();
-  const int  numberOfNodes  = (int) Coordinate->getLengthValue();
+  //  const int  spaceDimension = (int) Coordinate->getLeadingValue();
+  //  const int  numberOfNodes  = (int) Coordinate->getLengthValue();
   if ( Coordinate->get(mode) != NULL)
   {
-      MEDARRAY<double> pourAttribut(*Coordinate,false);
-      _coordinate = pourAttribut;
-      //_coordinate.set(mode,Coordinate->get(mode));
+    if(shallowCopy)
+      {
+       _coordinate.shallowCopy(*Coordinate);
+      }
+    else
+      {
+       MEDARRAY<double> pourAttribut(*Coordinate,false);
+       _coordinate = pourAttribut;
+       //_coordinate.set(mode,Coordinate->get(mode));
+      }
   }
   else
   {
-       throw MED_EXCEPTION ( LOCALIZED(STRING("setCoordinates(MEDARRAY<double>
-        *Coordinate)") << "No Coordinate"));
+       throw MED_EXCEPTION ( LOCALIZED(STRING("setCoordinates(MEDARRAY<double> *Coordinate)") << "No Coordinate"));
   }
 }
 
@@ -196,12 +198,12 @@ void COORDINATE::setNodesNumbers(const int * NodeNumber)
 
 int COORDINATE::getSpaceDimension() const
 {      
-  _coordinate.getLeadingValue() ; 
+  return _coordinate.getLeadingValue() ; 
 }
 
 int COORDINATE::getNumberOfNodes() const
 {      
-  _coordinate.getLengthValue() ; 
+  return _coordinate.getLengthValue() ; 
 }
 
 
@@ -238,10 +240,10 @@ const double *  COORDINATE::getCoordinateAxis(int Axis)
         return _coordinate.getColumn(Axis) ;
 }
 
-/*! returns an array with names of coordinates. /n
-      Example : /n
-      - x,y,z /n
-      - r,teta,phi /n
+/*! returns an array with names of coordinates. \n
+      Example : \n
+      - x,y,z \n
+      - r,teta,phi \n
       - ... */
 //--------------------------------------//
 const string * COORDINATE::getCoordinatesNames() const