From 5ee3d3bd35543e74c5fe6ac4c6bb2ea97684841d Mon Sep 17 00:00:00 2001 From: nri Date: Thu, 10 Jul 2003 14:57:13 +0000 Subject: [PATCH] NRI : Merge from V1_2. --- src/MED/MED_test1.py | 33 ++- src/MED/MED_test2.py | 33 ++- src/MED/Makefile.in | 34 ++- src/MED/Med_Gen_i.cxx | 160 +++++++++++-- src/MED/Med_Gen_i.hxx | 48 +++- src/MEDMEM/MEDMEM_GenDriver.hxx | 79 ++++++- src/MEDMEM/MEDMEM_MedFieldDriver.hxx | 298 ++++++++++++++++++++++--- src/MEDMEM/MEDMEM_PointerOf.hxx | 193 +++++++++++++--- src/MEDMEM/MEDMEM_define.hxx | 28 +++ src/MEDMEM/test_affect_medarray.cxx | 35 ++- src/MEDMEM/test_copie_connectivity.cxx | 63 ++++-- src/MEDMEM/test_copie_coordinate.cxx | 35 ++- src/MEDMEM/test_copie_family.cxx | 86 ++++--- src/MEDMEM/test_copie_fieldT.cxx | 56 +++-- src/MEDMEM/test_copie_field_.cxx | 33 ++- src/MEDMEM/test_copie_group.cxx | 47 +++- src/MEDMEM/test_copie_medarray.cxx | 38 +++- src/MEDMEM/test_copie_support.cxx | 57 ++++- 18 files changed, 1154 insertions(+), 202 deletions(-) diff --git a/src/MED/MED_test1.py b/src/MED/MED_test1.py index 815fae438..d5ac9907d 100755 --- a/src/MED/MED_test1.py +++ b/src/MED/MED_test1.py @@ -1,11 +1,30 @@ -#============================================================================== -# File : MED_test1.py -# Created : -# Author : -# Project : SALOME -# Copyright : EDF 2002 +# MED MED : implemetation of MED idl descriptions +# +# 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 : MED_test1.py +# Author : +# Module : MED # $Header$ -#============================================================================== import salome diff --git a/src/MED/MED_test2.py b/src/MED/MED_test2.py index 47ce56eb8..901ee2926 100755 --- a/src/MED/MED_test2.py +++ b/src/MED/MED_test2.py @@ -1,11 +1,30 @@ -#============================================================================== -# File : MED_test2.py -# Created : -# Author : -# Project : SALOME -# Copyright : EDF 2002 +# MED MED : implemetation of MED idl descriptions +# +# 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 : MED_test2.py +# Author : +# Module : MED # $Header$ -#============================================================================== import salome import SALOME diff --git a/src/MED/Makefile.in b/src/MED/Makefile.in index c91a0aa93..c5a639de5 100644 --- a/src/MED/Makefile.in +++ b/src/MED/Makefile.in @@ -1,13 +1,31 @@ -#============================================================================== -# File : Makefile.in -# Created : ven déc 7 13:33:08 CET 2001 -# Author : Paul RASCLE, EDF -# Project : SALOME -# Copyright : EDF 2001 +# MED MED : implemetation of MED idl descriptions +# +# 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 : Makefile.in +# Author : Paul RASCLE, EDF +# Module : MED # $Header$ -#============================================================================== -# source path top_srcdir=@top_srcdir@ top_builddir=../.. srcdir=@srcdir@ diff --git a/src/MED/Med_Gen_i.cxx b/src/MED/Med_Gen_i.cxx index ae87fc1f2..347a8304c 100755 --- a/src/MED/Med_Gen_i.cxx +++ b/src/MED/Med_Gen_i.cxx @@ -1,14 +1,33 @@ +// MED MED : implemetation of MED idl descriptions +// +// 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 : Med_Gen_i.cxx +// Author : Paul RASCLE, EDF +// Module : MED +// $Header$ + using namespace std; -//============================================================================= -// File : Med_Gen_i.cxx -// Created : mer fév 20 15:47:57 CET 2002 -// Author : Paul RASCLE, EDF -// Project : SALOME -// Copyright : EDF 2001 -// $Header$ -//============================================================================= using namespace std; - #include "Med_Gen_i.hxx" #include "Mesh_i.hxx" @@ -39,6 +58,7 @@ using namespace std; #include #include +#include #include "SALOMEDS_Tool.hxx" // Initialisation des variables statiques @@ -554,6 +574,90 @@ SALOMEDS::TMPFile* Med_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, END_OF(LOC); } +SALOMEDS::TMPFile* Med_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile) { + const char* LOC = "Med_Gen_i::SaveASCII"; + BEGIN_OF(LOC); + + SALOMEDS::TMPFile_var aStreamFile; + // Get a temporary directory to store a file + TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir(); + // Create a list to store names of created files + SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; + TColStd_SequenceOfAsciiString aFileNames; + + CORBA::String_var aSaveStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())); + + SALOMEDS::SObject_var aMedMeshFather = theComponent->GetStudy()->FindObject("MEDMESH"); + if (!CORBA::is_nil(aMedMeshFather)) { + SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedMeshFather); + for(; anIter->More(); anIter->Next()) { + SALOMEDS::SObject_var aSO = anIter->Value(); + SALOMEDS::GenericAttribute_var anAttr; + if (aSO->FindAttribute(anAttr,"AttributeIOR")) { + CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()); + SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR); + if (! CORBA::is_nil(myMesh)) { + TCollection_AsciiString aName(strdup(aSaveStudyName)); + aName += "_MEDMESH_"; + aName += myMesh->getName(); + aName += ".med"; + MESSAGE("Save mesh with name "<addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myMesh->getName()); + myMesh->write(driverId,""); + HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir+aName).ToCString()), true); + aFileNames.Append(aName); + } + } + } + } + + SALOMEDS::SObject_var aMedFieldFather = theComponent->GetStudy()->FindObject("MEDFIELD"); + if (!CORBA::is_nil(aMedFieldFather)) { + SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedFieldFather); + for(; anIter->More(); anIter->Next()) { + SALOMEDS::SObject_var aSO = anIter->Value(); + SALOMEDS::GenericAttribute_var anAttr; + if (aSO->FindAttribute(anAttr,"AttributeIOR")) { + CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()); + SALOME_MED::FIELD_var myField = SALOME_MED::FIELD::_narrow(myIOR); + if (! CORBA::is_nil(myField)) { + ostringstream a,b; + a<< myField->getOrderNumber(); + b<< myField->getIterationNumber(); + + TCollection_AsciiString aName(strdup(aSaveStudyName)); + aName += "_MEDFIELD_"; + aName += myField->getName(); + aName += "_ORDRE_"; + aName += strdup(a.str().c_str()); + aName += "_ITER_"; + aName += strdup(b.str().c_str()); + aName += ".med"; + MESSAGE("Save mesh with name "<addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myField->getName()); + myField->write(driverId,""); + HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir+aName).ToCString()), true); + aFileNames.Append(aName); + } + } + } + } + + int i; + aSeq->length(aFileNames.Length()); + for(i = aFileNames.Length(); i > 0; i--) aSeq[i-1] = CORBA::string_dup(aFileNames.Value(i).ToCString()); + // Conver a file to the byte stream + aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile); + // Remove the created file and tmp directory + if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); + // Return the created byte stream + return aStreamFile._retn(); + + END_OF(LOC); +} + //============================================================================= /*! * CORBA: Load Mesh objects (called when an existing study is opened) @@ -578,6 +682,13 @@ CORBA::Boolean Med_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, END_OF(LOC); } +CORBA::Boolean Med_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent, + const SALOMEDS::TMPFile& theStream, + const char* theURL, + bool isMultiFile) { + return Load(theComponent, theStream, theURL, isMultiFile); +} + //============================================================================= /*! * CORBA: @@ -622,8 +733,8 @@ char* Med_Gen_i::ComponentDataType() char* Med_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, const char* IORString, - CORBA::Boolean isMultiFile) -{ + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII) { const char * LOC = "Med_Gen_i::IORToLocalPersistentID" ; BEGIN_OF(LOC) ; SCRUTE(IORString); @@ -702,12 +813,12 @@ char* Med_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, char* Med_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, const char* aLocalPersistentID, - CORBA::Boolean isMultiFile) + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII) throw(SALOME::SALOME_Exception) { const char * LOC = "Med_Gen_i::LocalPersistentIDToIOR" ; BEGIN_OF(LOC) ; - TCollection_AsciiString aTmpDir(CORBA::string_dup(_saveFileName.c_str())); string aSaveStudyName(strdup(SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL()))); @@ -716,14 +827,22 @@ char* Med_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, if (strlen(aLocalPersistentID) <= aStudyNameLen) return strdup(""); if (strcmp(aLocalPersistentID, "Objet Med + /OBJ_MED/") == 0) return strdup(""); // MED - if (strncmp(&(aLocalPersistentID[aStudyNameLen]), "_MEDMESH_",13) == 0) {// MESH + if (strncmp(&(aLocalPersistentID[aStudyNameLen]), "_MEDMESH_",9) == 0) {// MESH MESH * myMesh= new MESH() ; - int aMeshNameLen = strlen(aLocalPersistentID) - 16 - aStudyNameLen; + int aMeshNameLen = strlen(aLocalPersistentID) - 12 - aStudyNameLen; char* aMeshName = new char[aMeshNameLen]; - strncpy(aMeshName, &(aLocalPersistentID[aStudyNameLen + 13]), aMeshNameLen-1); + strncpy(aMeshName, &(aLocalPersistentID[aStudyNameLen + 9]), aMeshNameLen-1); aMeshName[aMeshNameLen-1] = 0; myMesh->setName(aMeshName); - MED_MESH_RDONLY_DRIVER myMeshDriver((aTmpDir + strdup(aLocalPersistentID)).ToCString(),myMesh); + + char* aFileName; + if (isASCII) { + char* aResultPath = HDFascii::ConvertFromASCIIToHDF((aTmpDir + strdup(aLocalPersistentID)).ToCString()); + aFileName = new char[strlen(aResultPath) + 19]; + sprintf(aFileName, "%shdf_from_ascii.hdf", aResultPath); + delete(aResultPath); + } else aFileName = strdup((aTmpDir + strdup(aLocalPersistentID)).ToCString()); + MED_MESH_RDONLY_DRIVER myMeshDriver(aFileName,myMesh); try { myMeshDriver.setMeshName(aMeshName); @@ -754,6 +873,13 @@ char* Med_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, aSeq->length(1); aSeq[0]=CORBA::string_dup(aLocalPersistentID); if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); + if (isASCII) { + SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames; + aFilesToRemove->length(1); + aFilesToRemove[0] = strdup(&(aFileName[strlen(SALOMEDS_Tool::GetDirFromPath(aFileName))])); + SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aFileName), aFilesToRemove, true); + } + delete(aFileName); return(CORBA::string_dup(_orb->object_to_string(mesh))); } else if (strncmp(&(aLocalPersistentID[aStudyNameLen]), "_MEDFIELD_",14) == 0) { // FIELD return(strdup("")); // not implemented yet diff --git a/src/MED/Med_Gen_i.hxx b/src/MED/Med_Gen_i.hxx index c61b16b9b..cbc9db16e 100644 --- a/src/MED/Med_Gen_i.hxx +++ b/src/MED/Med_Gen_i.hxx @@ -1,11 +1,30 @@ -//============================================================================= -// File : Med_Gen_i.hxx -// Created : mer fév 20 15:47:52 CET 2002 -// Author : Paul RASCLE, EDF -// Project : SALOME -// Copyright : EDF 2001 -// $Header$ -//============================================================================= +// MED MED : implemetation of MED idl descriptions +// +// 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 : Med_Gen_i.hxx +// Author : Paul RASCLE, EDF +// Module : MED +// $Header$ #ifndef _MED_GEN_I_HXX_ #define _MED_GEN_I_HXX_ @@ -68,21 +87,30 @@ public: SALOMEDS::TMPFile* Save(SALOMEDS::SComponent_ptr theComponent, const char* theURL, bool isMultiFile); + SALOMEDS::TMPFile* SaveASCII(SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile); CORBA::Boolean Load(SALOMEDS::SComponent_ptr theComponent, const SALOMEDS::TMPFile& theStream, const char* theURL, bool isMultiFile); + CORBA::Boolean LoadASCII(SALOMEDS::SComponent_ptr theComponent, + const SALOMEDS::TMPFile& theStream, + const char* theURL, + bool isMultiFile); void Close(SALOMEDS::SComponent_ptr theComponent); char* ComponentDataType(); char* IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, const char* IORString, - CORBA::Boolean isMultiFile); + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII); char* LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, const char* aLocalPersistentID, - CORBA::Boolean isMultiFile) + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII) throw(SALOME::SALOME_Exception); bool CanPublishInStudy(CORBA::Object_ptr theIOR); diff --git a/src/MEDMEM/MEDMEM_GenDriver.hxx b/src/MEDMEM/MEDMEM_GenDriver.hxx index b24d4882d..9e9813cf7 100644 --- a/src/MEDMEM/MEDMEM_GenDriver.hxx +++ b/src/MEDMEM/MEDMEM_GenDriver.hxx @@ -1,3 +1,29 @@ +// 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_GenDriver.hxx +// Module : MED + #ifndef GENDRIVER_HXX #define GENDRIVER_HXX @@ -8,11 +34,18 @@ /* Generic Read/Write Driver Class for Meshes & Fields */ -typedef enum { MED_DRIVER = 0, VTK_DRIVER = 1, NO_DRIVER = 255 } driverTypes; +/* Modify the following line to add a new driver type (step 1) */ +typedef enum { MED_DRIVER = 0, GIBI_DRIVER = 1, VTK_DRIVER = 254, NO_DRIVER = 255 } driverTypes; using namespace MED_EN; using namespace std; +/*! + + Virtual class GENDRIVER use by all driver. + +*/ + class GENDRIVER { protected : @@ -20,29 +53,61 @@ protected : int _id; // MED_INVALID : if the driver hasn't been created by a MedMedDriver // the MedMedDriver index of the driver vector in the MED object where it has been created /*File related part*/ - string _fileName; - med_mode_acces _accessMode; - int _status; + string _fileName; // The name of the file currently in use. + med_mode_acces _accessMode; // The file access mode set by the adequate construtor. + int _status; // The file status {MED_INVALID, MED_OPENED, MED_CLOSED } driverTypes _driverType; // A FAIRE LE POSITIONNER DS TOUTES LES SS CLASSES !! public: + /*! + Constructor. + */ GENDRIVER(); - + /*! + Constructor. + */ GENDRIVER(const string & fileName,med_mode_acces accessMode); + /*! + Copy constructor. + */ GENDRIVER(const GENDRIVER & genDriver); - ~GENDRIVER(); + /*! + Destructor. + */ + virtual ~GENDRIVER(); + + /*! + Operator = : duplicate the given genDriver. + */ GENDRIVER & operator=(const GENDRIVER & genDriver); + /*! + Operator << : put GENDRIVER object information to the given stream + */ friend ostream & operator<<(ostream &os,const GENDRIVER &genDriver); bool operator ==(const GENDRIVER &genDriver) const; - + /*! + Open file. + */ virtual void open ( void ) = 0; + /*! + Close file. + */ virtual void close( void ) = 0; + /*! + Write object in opened file. + */ virtual void write( void ) const = 0; + /*! + Read object in opened file. + */ virtual void read ( void ) = 0; + // needed to duplicate arrays + virtual GENDRIVER * copy ( void ) const = 0 ; + // MED related part virtual void writeFrom ( void ); virtual void readFileStruct ( void ); diff --git a/src/MEDMEM/MEDMEM_MedFieldDriver.hxx b/src/MEDMEM/MEDMEM_MedFieldDriver.hxx index 19880683f..805536bf2 100644 --- a/src/MEDMEM/MEDMEM_MedFieldDriver.hxx +++ b/src/MEDMEM/MEDMEM_MedFieldDriver.hxx @@ -1,3 +1,29 @@ +// 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_MedFieldDriver.hxx +// Module : MED + #ifndef MED_FIELD_DRIVER_HXX #define MED_FIELD_DRIVER_HXX @@ -14,12 +40,22 @@ #include "MEDMEM_Array.hxx" #include "MEDMEM_Support.hxx" //#include "MEDMEM_Field.hxx" +#include "MEDMEM_Mesh.hxx" //using namespace MED_FR ; template class FIELD; // A QD LA CLASSE MED_ALL_ELEMENTS_DRIVER.... :) pour mutualiser le open ..... avec led _medIdt... + +/*! + + Driver Med for FIELD. + + Generic part : implement open and close methods. + +*/ + template class MED_FIELD_DRIVER : public GENDRIVER { protected: @@ -38,28 +74,66 @@ public : // static const char * const all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE]; + /*! + Constructor. + */ MED_FIELD_DRIVER():GENDRIVER(), _ptrField((FIELD *)MED_NULL),_medIdt(MED_INVALID), _fieldName(""),_fieldNum(MED_INVALID) {} + /*! + Constructor. + */ MED_FIELD_DRIVER(const string & fileName, FIELD * ptrField, med_mode_acces accessMode) : GENDRIVER(fileName,accessMode), _ptrField((FIELD *) ptrField),_medIdt(MED_INVALID), - _fieldName(""),_fieldNum(MED_INVALID) + _fieldName(fileName),_fieldNum(MED_INVALID) { } - - void open() { + + /*! + Copy constructor. + */ + MED_FIELD_DRIVER(const MED_FIELD_DRIVER & fieldDriver): + GENDRIVER(fieldDriver), + _ptrField(fieldDriver._ptrField), + _medIdt(MED_INVALID), + _fieldName(fieldDriver._fieldName), + _fieldNum(fieldDriver._fieldNum) + { + } + + /*! + Destructor. + */ + virtual ~MED_FIELD_DRIVER() { + } + + void open() throw (MEDEXCEPTION) + { const char * LOC = "MED_FIELD_DRIVER::open() "; BEGIN_OF(LOC); // we must set fieldname before open, because we must find field number in file (if it exist !!!) + if ( _fileName == "" ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + << "_fileName is |\"\"|, please set a correct fileName before calling open()" + ) + ); MESSAGE(LOC<<"_fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode); _medIdt = MED_FR::MEDouvrir( (const_cast (_fileName.c_str())),(MED_FR::med_mode_acces) _accessMode); MESSAGE(LOC<<"_medIdt : "<< _medIdt ); - if (_medIdt > 0) _status=MED_OPENED; else { + if (_medIdt > 0) + _status=MED_OPENED; + else { _status = MED_INVALID; + _medIdt = MED_INVALID; + throw MED_EXCEPTION (LOCALIZED( STRING(LOC) + << "Can't open |" << _fileName + << "|, _medIdt : " << _medIdt + ) + ); } END_OF(LOC); @@ -81,40 +155,97 @@ public : virtual void write( void ) const = 0 ; virtual void read ( void ) = 0 ; + + /*! + Set the name of the FIELD asked in file. + + It could be different than the name of the FIELD object. + */ void setFieldName(const string & fieldName) ; + /*! + Get the name of the FIELD asked in file. + */ string getFieldName() const ; + +private: + virtual GENDRIVER * copy ( void ) const = 0 ; + }; +/*! + + Driver Med for FIELD : Read only. + + Implement read method. + +*/ + template class MED_FIELD_RDONLY_DRIVER : public virtual MED_FIELD_DRIVER { public : + /*! + Constructor. + */ MED_FIELD_RDONLY_DRIVER():MED_FIELD_DRIVER() {}; + /*! + Constructor. + */ MED_FIELD_RDONLY_DRIVER(const string & fileName, FIELD * ptrField): MED_FIELD_DRIVER(fileName,ptrField,MED_RDONLY) { BEGIN_OF("MED_FIELD_RDONLY_DRIVER::MED_FIELD_RDONLY_DRIVER(const string & fileName, const FIELD * ptrField)"); END_OF("MED_FIELD_RDONLY_DRIVER::MED_FIELD_RDONLY_DRIVER(const string & fileName, const FIELD * ptrField)"); } - ~MED_FIELD_RDONLY_DRIVER() { - BEGIN_OF("MED_FIELD_RDONLY_DRIVER::~MED_FIELD_RDONLY_DRIVER()"); - END_OF("MED_FIELD_RDONLY_DRIVER::~MED_FIELD_RDONLY_DRIVER()"); - } + /*! + Copy constructor. + */ + MED_FIELD_RDONLY_DRIVER(const MED_FIELD_RDONLY_DRIVER & fieldDriver): + MED_FIELD_DRIVER(fieldDriver) {}; + + /*! + Destructor. + */ + virtual ~MED_FIELD_RDONLY_DRIVER() {}; // CREER UNE METHODE POUR LIRE LA LISTE DES MAILLAGES ..... - void write( void ) const ; - void read ( void ) ; + /*! + Return a MEDEXCEPTION : it is the read-only driver. + */ + void write( void ) const throw (MEDEXCEPTION) ; + /*! + Read FIELD in the specified file. + */ + void read ( void ) throw (MEDEXCEPTION) ; + +private: + GENDRIVER * copy( void ) const ; + }; +/*! + + Driver Med for FIELD : Write only. + + Implement write method. + +*/ + template class MED_FIELD_WRONLY_DRIVER : public virtual MED_FIELD_DRIVER { public : + /*! + Constructor. + */ MED_FIELD_WRONLY_DRIVER():MED_FIELD_DRIVER() {} + /*! + Constructor. + */ MED_FIELD_WRONLY_DRIVER(const string & fileName, FIELD * ptrField): MED_FIELD_DRIVER(fileName,ptrField,MED_WRONLY) { @@ -122,30 +253,83 @@ public : END_OF("MED_FIELD_WRONLY_DRIVER::MED_FIELD_WRONLY_DRIVER(const string & fileName, const FIELD * ptrField)"); }; - ~MED_FIELD_WRONLY_DRIVER() { } + /*! + Copy constructor. + */ + MED_FIELD_WRONLY_DRIVER(const MED_FIELD_WRONLY_DRIVER & fieldDriver): + MED_FIELD_DRIVER(fieldDriver) {}; + + /*! + Destructor. + */ + virtual ~MED_FIELD_WRONLY_DRIVER() {}; + + /*! + Write FIELD in the specified file. + */ + void write( void ) const throw (MEDEXCEPTION) ; + /*! + Return a MEDEXCEPTION : it is the write-only driver. + */ + void read ( void ) throw (MEDEXCEPTION) ; + +private: + GENDRIVER * copy( void ) const ; - void write( void ) const ; - void read ( void ) ; }; +/*! + + Driver Med for FIELD : Read write. + - Use read method from MED_FIELD_RDONLY_DRIVER + - Use write method from MED_FIELD_WDONLY_DRIVER + +*/ + template class MED_FIELD_RDWR_DRIVER : public MED_FIELD_RDONLY_DRIVER, public MED_FIELD_WRONLY_DRIVER { public : + /*! + Constructor. + */ MED_FIELD_RDWR_DRIVER():MED_FIELD_DRIVER() {} + /*! + Constructor. + */ MED_FIELD_RDWR_DRIVER(const string & fileName, FIELD * ptrField): MED_FIELD_DRIVER(fileName,ptrField,MED_RDWR) { BEGIN_OF("MED_FIELD_RDWR_DRIVER::MED_FIELD_RDWR_DRIVER(const string & fileName, const FIELD * ptrField)"); + //_accessMode = MED_RDWR ; END_OF("MED_FIELD_RDWR_DRIVER::MED_FIELD_RDWR_DRIVER(const string & fileName, const FIELD * ptrField)"); }; - ~MED_FIELD_RDWR_DRIVER() { } + /*! + Copy constructor. + */ + MED_FIELD_RDWR_DRIVER(const MED_FIELD_RDWR_DRIVER & fieldDriver): + MED_FIELD_DRIVER(fieldDriver) {}; + + /*! + Destructor. + */ + ~MED_FIELD_RDWR_DRIVER() {}; + + /*! + Write FIELD in the specified file. + */ + void write(void) const throw (MEDEXCEPTION) ; + /*! + Read FIELD in the specified file. + */ + void read (void) throw (MEDEXCEPTION) ; + +private: + GENDRIVER * copy( void ) const ; - void write(void) const ; - void read (void) ; }; @@ -210,7 +394,15 @@ template string MED_FIELD_DRIVER::getFieldName() const /*--------------------- RDONLY PART -------------------------------*/ +template GENDRIVER * MED_FIELD_RDONLY_DRIVER::copy(void) const +{ + MED_FIELD_RDONLY_DRIVER * myDriver = + new MED_FIELD_RDONLY_DRIVER(*this); + return myDriver ; +} + template void MED_FIELD_RDONLY_DRIVER::read(void) + throw (MEDEXCEPTION) { const char * LOC = " MED_FIELD_RDONLY_DRIVER::read() " ; BEGIN_OF(LOC); @@ -264,6 +456,9 @@ template void MED_FIELD_RDONLY_DRIVER::read(void) _fieldNum = i ; break ; } + // not found : release memory and search next field ! + delete[] componentName ; + delete[] unitName ; } } @@ -298,7 +493,7 @@ template void MED_FIELD_RDONLY_DRIVER::read(void) // read values for each geometric type in _support int NumberOfTypes = _ptrField->_support->getNumberOfTypes() ; - medGeometryElement *Types = _ptrField->_support->getTypes() ; + const medGeometryElement *Types = _ptrField->_support->getTypes() ; T ** myValues = new (T*)[NumberOfTypes] ; int * NumberOfValues = new int[NumberOfTypes] ; int TotalNumberOfValues = 0 ; @@ -338,6 +533,21 @@ template void MED_FIELD_RDONLY_DRIVER::read(void) _ptrField->getOrderNumber() ) < 0) { // we must do some delete !!! + for(int j=0; j<=i;j++) + delete[] myValues[j]; + delete[] myValues; + delete[] NumberOfValues ; + delete[] ProfilName; + delete[] _ptrField->_componentsTypes ; + delete[] _ptrField->_componentsNames ; + delete[] _ptrField->_componentsUnits ; + delete[] _ptrField->_componentsDescriptions ; + delete[] _ptrField->_MEDComponentsUnits ; + _ptrField->_componentsTypes = NULL ; + _ptrField->_componentsNames = NULL ; + _ptrField->_componentsUnits = NULL ; + _ptrField->_componentsDescriptions = NULL ; + _ptrField->_MEDComponentsUnits = NULL ; _fieldNum = MED_INVALID ; // we have not found right field, so reset the field number throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<": ERROR when read value")) ; } @@ -352,21 +562,25 @@ template void MED_FIELD_RDONLY_DRIVER::read(void) _ptrField->_value=new MEDARRAY(numberOfComponents,TotalNumberOfValues,MED_EN::MED_NO_INTERLACE); MEDARRAY * Values = _ptrField->_value ; // create by constructor ??? - // check if dimensions are right - if (Values->getLeadingValue() != numberOfComponents) - throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<": leading dimension are false : "<getLeadingValue()<<" and "<getLengthValue() != TotalNumberOfValues) - throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<": length dimension are false : "<getLengthValue()<<" and "<getLeadingValue() != numberOfComponents) + // throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<": leading dimension are false : "<getLeadingValue()<<" and "<getLengthValue() != TotalNumberOfValues) + // throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<": length dimension are false : "<getLengthValue()<<" and "<getI(MED_NO_INTERLACE,i+1) ; - int Count = 0 ; + //T * ValuesT = Values->getRow(i+1) ; + int Count = 1 ; for (int j=0; j_numberOfValues+=NumberOf; // problem with gauss point : _numberOfValues != TotalNumberOfValues !!!!!!! int offset = NumberOf*i ; for (int k=0 ; ksetIJ(Count,i+1,myValue[k+offset]); + SCRUTE(Count); + SCRUTE(Values->getIJ(Count,i+1)); Count++; } } @@ -376,23 +590,36 @@ template void MED_FIELD_RDONLY_DRIVER::read(void) delete[] myValues[j] ; delete[] myValues ; delete[] NumberOfValues ; + + _ptrField->_isRead = true ; } + END_OF(LOC); } template void MED_FIELD_RDONLY_DRIVER::write( void ) const + throw (MEDEXCEPTION) { throw MEDEXCEPTION("MED_FIELD_RDONLY_DRIVER::write : Can't write with a RDONLY driver !"); } /*--------------------- WRONLY PART -------------------------------*/ +template GENDRIVER * MED_FIELD_WRONLY_DRIVER::copy(void) const +{ + MED_FIELD_WRONLY_DRIVER * myDriver = + new MED_FIELD_WRONLY_DRIVER(*this); + return myDriver ; +} + template void MED_FIELD_WRONLY_DRIVER::read (void) + throw (MEDEXCEPTION) { - throw MEDEXCEPTION("MED_FIELD_WRONLY_DRIVER::write : Can't read with a WRONLY driver !"); + throw MEDEXCEPTION("MED_FIELD_WRONLY_DRIVER::read : Can't read with a WRONLY driver !"); } template void MED_FIELD_WRONLY_DRIVER::write(void) const + throw (MEDEXCEPTION) { const char * LOC = "MED_FIELD_WRONLY_DRIVER::write(void) const " ; BEGIN_OF(LOC); @@ -404,8 +631,8 @@ template void MED_FIELD_WRONLY_DRIVER::write(void) const string component_name(component_count*MED_TAILLE_PNOM,' ') ; string component_unit(component_count*MED_TAILLE_PNOM,' ') ; - string * listcomponent_name=_ptrField->getComponentsNames() ; - string * listcomponent_unit=_ptrField->getMEDComponentsUnits() ; + const string * listcomponent_name=_ptrField->getComponentsNames() ; + const string * listcomponent_unit=_ptrField->getMEDComponentsUnits() ; int length ; for (int i=0; i < component_count ; i++) { length = min(MED_TAILLE_PNOM,(int)listcomponent_name[i].size()); @@ -497,8 +724,8 @@ template void MED_FIELD_WRONLY_DRIVER::write(void) const // on boucle sur tout les types pour ecrire les tableaux de valeur int NumberOfType = mySupport->getNumberOfTypes() ; int Index = 1 ; - medGeometryElement * Types = mySupport->getTypes() ; - int * NumberOfGaussPoint = mySupport->getNumberOfGaussPoint() ; + const medGeometryElement * Types = mySupport->getTypes() ; + const int * NumberOfGaussPoint = mySupport->getNumberOfGaussPoint() ; for (int i=0;igetNumberOfElements(Types[i]) ; @@ -512,7 +739,7 @@ template void MED_FIELD_WRONLY_DRIVER::write(void) const MESSAGE(" "<<_ptrField->getOrderNumber()); MESSAGE("MEDchampEcr :"<getValueI(MED_EN::MED_FULL_INTERLACE,Index) ; + const T * value = _ptrField->getValueI(MED_EN::MED_FULL_INTERLACE,Index) ; err=MED_FR::MEDchampEcr(_medIdt, const_cast ( MeshName.c_str()) , //( string(mesh_name).resize(MED_TAILLE_NOM).c_str()) const_cast ( (_ptrField->getName()).c_str()), @@ -539,7 +766,15 @@ template void MED_FIELD_WRONLY_DRIVER::write(void) const /*--------------------- RDWR PART -------------------------------*/ +template GENDRIVER * MED_FIELD_RDWR_DRIVER::copy(void) const +{ + MED_FIELD_RDWR_DRIVER * myDriver = + new MED_FIELD_RDWR_DRIVER(*this); + return myDriver ; +} + template void MED_FIELD_RDWR_DRIVER::write(void) const + throw (MEDEXCEPTION) { BEGIN_OF("MED_FIELD_RDWR_DRIVER::write(void)"); MED_FIELD_WRONLY_DRIVER::write(); @@ -547,6 +782,7 @@ template void MED_FIELD_RDWR_DRIVER::write(void) const } template void MED_FIELD_RDWR_DRIVER::read (void) + throw (MEDEXCEPTION) { BEGIN_OF("MED_FIELD_RDWR_DRIVER::read(void)"); MED_FIELD_RDONLY_DRIVER::read(); diff --git a/src/MEDMEM/MEDMEM_PointerOf.hxx b/src/MEDMEM/MEDMEM_PointerOf.hxx index dc5744547..cc68738cf 100644 --- a/src/MEDMEM/MEDMEM_PointerOf.hxx +++ b/src/MEDMEM/MEDMEM_PointerOf.hxx @@ -1,57 +1,142 @@ +// 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_PointerOf.hxx +// Module : MED + # if ! defined( __PointerOf_HXX__ ) # define __PointerOf_HXX__ #include #include "utilities.h" +#include "MEDMEM_Exception.hxx" /*! The template class PointerOf embedding a standard pointer (_pointer) is in charge of - managing a the pointed memory. + managing the pointed memory.\n + + the object PointerOf is the memory owner if a size is given at object construction. + In these cases, memory will be desallocated at object destruction. In all other cases, + the desallocator will only nullify pointers. */ template class PointerOf { protected : + /*! pointer to the pointed memory */ T* _pointer ; + /*! boolean setted to true if memory has to be desallocated */ bool _done ; + public : - PointerOf() ; // + PointerOf() ; + ~PointerOf() ; PointerOf( const int &size ) ; PointerOf( const T *pointer ) ; - ~PointerOf() ; - operator T*() ; + PointerOf( const int &size, const T *pointer ) ; + PointerOf( const PointerOf & pointerOf ) ; + PointerOf( const int &size, const PointerOf & pointerOf ) ; + operator T*() ; operator const T*() const ; - - //operator T*() const ; - void set( const int &size ) ; void set( const T *pointer ) ; + void set( const int &size, const T *pointer ) ; PointerOf& operator=( const PointerOf &pointer ) ; } ; -template PointerOf& PointerOf::operator=( const PointerOf &pointer ) +// ------------------------------------------------------------ // +// // +// Implementation // +// // +// ------------------------------------------------------------ // + + +/*! Creates a null T* pointer and sets the boolean (for desallocation) to false. */ +template PointerOf::PointerOf() : _pointer(0), _done(false) { - BEGIN_OF("PointerOf::operator=( const PointerOf &pointer )") ; - if ( &pointer != this ) - { - this->set( pointer._pointer ) ; - } - END_OF("PointerOf::operator=( const PointerOf &pointer )") ; - return *this ; } -template PointerOf::PointerOf() : _pointer(0), _done(false) +/*! Creates a standard T* pointer to the pointed memory. \n + The boolean for desallocation is setted to false. \n + Be aware : \n + - The "old" PointerOf always has propriety of the pointed memory. \n + - If the "old" PointerOf is detroyed, the "new" PointerOf points + a desallocated memory zone. */ +template PointerOf::PointerOf(const PointerOf & pointerOf) : _done(false), + _pointer((T*)(const T* const)pointerOf) { + BEGIN_OF("PointerOf::PointerOf(const PointerOf & pointerOf)"); + MESSAGE("Warning ! No Propriety Transfer"); + END_OF ("PointerOf::PointerOf(const PointerOf & pointerOf)"); } -template PointerOf::PointerOf( const int &size ) : _pointer( new T[ size ]), _done(true) +/*! + Duplicate array of size size pointed in pointerOf. +*/ +template PointerOf::PointerOf( const int &size, const PointerOf & pointerOf) : + _pointer((size,(T*)pointerOf)) +{ +} + +/*! If size <= 0, creates a null "T*" pointer\n + Else allocates memory and sets desallocation boolean to true./n + Memory will be desallocated when erasing this PointerOf*/ +template PointerOf::PointerOf( const int &size ) { + if (size <= 0) + { + _pointer=(T*)NULL; + _done=false; + } + else + { + _pointer = new T[ size ] ; + _done=true; + } } +/*! Creates a standard pointer to the memory zone pointed by T*. /n + T* owner is in charged of memory desallocation. /n + Memory will not be released when erasing this PointerOf*/ template PointerOf::PointerOf( const T* pointer ) : _pointer( (T*)pointer ), _done(false) { } +/*! If size <= 0, return an exception\n + Else duplicate array and sets desallocation boolean to true./n + Memory will be desallocated when erasing this PointerOf*/ +template PointerOf::PointerOf( const int &size, const T* pointer) +{ + if (size <= 0) + throw MEDEXCEPTION("PointerOf( const int,const T*) : array size <= 0"); + + _pointer = new T[ size ] ; + memcpy(_pointer,pointer,size*sizeof(T)); + _done=true; +} + +/*! The destuctor desallocates memory if necessary (that is if the attribute _done equals true).\n + The attribute _pointer is nullified */ template PointerOf::~PointerOf() { if ( _pointer ) @@ -70,49 +155,103 @@ template PointerOf::~PointerOf() } } +/*! Creates a standard pointer (T*) to the pointed memory. \n + The boolean for desallocation is setted to false. \n + Be aware : \n + - The "right" PointerOf always has propriety of the pointed memory. \n + - If the "right" PointerOf is detroyed, the "left" PointerOf points + a desallocated memory zone. + - it works the same way as PointerOf(const PointerOf & pointerOf) */ +template PointerOf& PointerOf::operator=( const PointerOf &pointer ) +{ + BEGIN_OF("PointerOf::operator=( const PointerOf &pointer )") ; + if ( &pointer != this ) + { + this->set( pointer._pointer ) ; + } + END_OF("PointerOf::operator=( const PointerOf &pointer )") ; + return *this ; +} + +/*! Returns _pointer.*/ template PointerOf::operator T*() { return _pointer ; } + +/*! Returns _pointer.*/ template PointerOf::operator const T*() const { return _pointer ; } -// template PointerOf::operator T*() const -// { -// return _pointer ; -// } +/*! If necessary, released memory holded by PointerOf/n. + Else allocates memory and sets desallocation boolean to true./n + Can be used in order to "nullify" an existing PointerOf/n + Memory will be desallocated when erasing this PointerOf*/ template void PointerOf::set( const int &size ) { - ASSERT(size>0) ; if ( _pointer && _done ) { - delete [] _pointer ; + delete [] _pointer ; _pointer=0 ; } - _pointer = new T[ size ] ; + if (size <= 0) + { + _pointer=(T*)NULL; + } + else + { + _pointer = new T[ size ] ; + } _done = true ; return ; } + +/*! If necessary, released memory holded by PointerOf/n. + Then, sets _pointer to the memory zone pointed by T*. /n + T* owner is in charged of memory desallocation. /n + memory will not be released when erasing this PointerOf*/ template void PointerOf::set( const T *pointer ) { - MESSAGE( "PointerOf::set( const T *pointer )" ) ; + MESSAGE( "BEGIN PointerOf::set( const T *pointer )" ) ; SCRUTE(pointer) ; SCRUTE(_done) ; if ( _pointer && _done ) { MESSAGE("PointerOf::set --> deleting _pointer") ; - delete [] _pointer ; + delete [] _pointer ; _pointer=0 ; _done=false ; } _pointer=(T*)pointer ; _done=false ; - MESSAGE( "PointerOf::set( const T *pointer )" ) ; + MESSAGE( "END PointerOf::set( const T *pointer )" ) ; return ; } +/*! If necessary, released memory holded by PointerOf/n. + If size <= 0, return an exception\n. + Else allocates memory and sets desallocation boolean to true./n + Can be used in order to "nullify" an existing PointerOf/n + Memory will be desallocated when erasing this PointerOf*/ +template void PointerOf::set( const int &size, const T *pointer) +{ + if ( _pointer && _done ) + { + delete [] _pointer ; + _pointer = NULL ; + } + if (size <= 0) + throw MEDEXCEPTION("PointerOf( const int,const T*) : array size <= 0"); + + _pointer = new T[ size ] ; + memcpy(_pointer,pointer,size*sizeof(T)); + _done=true; + + return ; +} + # endif /* # if ! defined( __PointerOf_HXX__ ) */ diff --git a/src/MEDMEM/MEDMEM_define.hxx b/src/MEDMEM/MEDMEM_define.hxx index 09de197b8..92d578b0f 100644 --- a/src/MEDMEM/MEDMEM_define.hxx +++ b/src/MEDMEM/MEDMEM_define.hxx @@ -1,3 +1,29 @@ +// 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_define.hxx +// Module : MED + #ifndef DEFINE_HXX #define DEFINE_HXX @@ -29,6 +55,8 @@ namespace MED_EN { #define MED_TAILLE_LNOM 80 #define MED_TAILLE_PNOM 8 +typedef enum {MED_CARTESIAN, MED_POLAR, MED_BODY_FITTED} med_grid_type; + typedef enum {MED_FULL_INTERLACE, MED_NO_INTERLACE} medModeSwitch; diff --git a/src/MEDMEM/test_affect_medarray.cxx b/src/MEDMEM/test_affect_medarray.cxx index b5043f1bb..cc9a79485 100644 --- a/src/MEDMEM/test_affect_medarray.cxx +++ b/src/MEDMEM/test_affect_medarray.cxx @@ -1,3 +1,29 @@ +// 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 : test_affect_medarray.cxx +// Module : MED + using namespace std; /* Programme de test du constructeur de copies de la classe MEDARRAY de MEDMEM jroy - 16/12/2002 */ @@ -25,7 +51,7 @@ void affiche_medarray(MEDARRAY & myMedArray) MESSAGE("Show all 1 :"); numberof = myMedArray.getLeadingValue() ; for (int i=1; i<=myMedArray.getLengthValue() ; i++) { - double * node = myMedArray.getI(MED_FULL_INTERLACE,i) ; + const double * node = myMedArray.getRow(i) ; cout << " - " ; for (int j=0;j & myMedArray) MESSAGE("Show all 2 :"); numberof = myMedArray.getLengthValue() ; for (int i=1; i<=myMedArray.getLeadingValue() ; i++) { - double * node = myMedArray.getI(MED_NO_INTERLACE,i) ; + const double * node = myMedArray.getColumn(i) ; cout << " - " ; for (int j=0;j & myMedArray) MESSAGE("Show all 0 :"); numberof = myMedArray.getLeadingValue() ; int length = myMedArray.getLengthValue() ; - double * NoInterlaceArray = myMedArray.get(MED_NO_INTERLACE) ; + const double * NoInterlaceArray = myMedArray.get(MED_NO_INTERLACE) ; for (int i=0; i * myMedArray2 = new MEDARRAY(); * myMedArray2 = * myMedArray; - delete myMedArray; + // delete myMedArray; // si on recopie les tableaux affiche_medarray(* myMedArray2); + delete myMedArray; // si on ne recopie pas les tableaux delete myMedArray2; return 0; diff --git a/src/MEDMEM/test_copie_connectivity.cxx b/src/MEDMEM/test_copie_connectivity.cxx index 4b94dcb17..b3442471a 100644 --- a/src/MEDMEM/test_copie_connectivity.cxx +++ b/src/MEDMEM/test_copie_connectivity.cxx @@ -1,3 +1,29 @@ +// 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 : test_copie_connectivity.cxx +// Module : MED + using namespace std; /* Programme de test du constructeur de copies de la classe CONNECTIVITY de MEDMEM jroy - 19/12/2002 */ @@ -18,20 +44,20 @@ using namespace std; #include "MEDMEM_Field.hxx" #include "MEDMEM_define.hxx" -void affiche_connectivity(CONNECTIVITY * myConnectivity, MESH * myMesh) +void affiche_connectivity(const CONNECTIVITY * myConnectivity, MESH * myMesh) { int SpaceDimension = myMesh->getSpaceDimension() ; int MeshDimension = myMesh->getMeshDimension() ; int NumberOfNodes = myMesh->getNumberOfNodes() ; - int NumberOfTypes = myMesh->getNumberOfTypes(MED_CELL) ; - medGeometryElement * Types = myMesh->getTypes(MED_CELL) ; + int NumberOfTypes = myMesh->getNumberOfTypes(MED_CELL) ; + const medGeometryElement * Types = myMesh->getTypes(MED_CELL) ; cout << "Show Connectivity (Nodal) :" << endl ; for (int i=0; igetNumberOfElements(MED_CELL,Types[i]); - int * connectivity = myMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,Types[i]); + const int * connectivity = myMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,Types[i]); int NomberOfNodesPerCell = Types[i]%100 ; for (int j=0;jgetReverseConnectivity(MED_NODAL) ; - int * ReverseNodalConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_NODAL) ; + const int * ReverseNodalConnectivity = myMesh->getReverseConnectivity(MED_NODAL) ; + const int * ReverseNodalConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_NODAL) ; for (int i=0; icalculateConnectivity(MED_FULL_INTERLACE,MED_DESCENDING,MED_CELL); try { NumberOfElements = myMesh->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS); @@ -73,8 +99,8 @@ void affiche_connectivity(CONNECTIVITY * myConnectivity, MESH * myMesh) } cout << "Show Reverse Descending Connectivity :" << endl ; - int * ReverseDescendingConnectivity = myMesh->getReverseConnectivity(MED_DESCENDING) ; - int * ReverseDescendingConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_DESCENDING) ; + const int * ReverseDescendingConnectivity = myMesh->getReverseConnectivity(MED_DESCENDING) ; + const int * ReverseDescendingConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_DESCENDING) ; int NumberOfConstituents = 0; string constituent ; @@ -103,8 +129,8 @@ void affiche_connectivity(CONNECTIVITY * myConnectivity, MESH * myMesh) } } cout << "Show "<getConnectivity(MED_FULL_INTERLACE,MED_NODAL,constituentEntity,MED_ALL_ELEMENTS); - int * face_connectivity_index = myMesh->getConnectivityIndex(MED_NODAL,constituentEntity); + const int * face_connectivity = myMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,constituentEntity,MED_ALL_ELEMENTS); + const int * face_connectivity_index = myMesh->getConnectivityIndex(MED_NODAL,constituentEntity); for (int i=0; igetConnectivityptr(); + const CONNECTIVITY * myConnectivity = myMesh->getConnectivityptr(); affiche_connectivity(myConnectivity, myMesh); + CONNECTIVITY * myConnectivity2 = new CONNECTIVITY(* myConnectivity); affiche_connectivity(myConnectivity2, myMesh); - delete myConnectivity;//myConnectivity utile pour afficher myConnectivity2 via myMesh! + + CONNECTIVITY * myConnectivity3 = new CONNECTIVITY(* myConnectivity2); + delete myConnectivity2; + affiche_connectivity(myConnectivity3, myMesh); + delete myConnectivity3; + + delete myMesh ; return 0; } diff --git a/src/MEDMEM/test_copie_coordinate.cxx b/src/MEDMEM/test_copie_coordinate.cxx index 56e2ea1e2..385b8ab0e 100644 --- a/src/MEDMEM/test_copie_coordinate.cxx +++ b/src/MEDMEM/test_copie_coordinate.cxx @@ -1,3 +1,29 @@ +// 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 : test_copie_coordinate.cxx +// Module : MED + using namespace std; /* Programme de test du constructeur de copies de la classe COORDINATE de MEDMEM jroy - 17/12/2002 */ @@ -101,10 +127,17 @@ int main (int argc, char ** argv) { // myCoordinate->setCoordinatesNames((string *)NULL); // myCoordinate->setNodesNumbers((int *) NULL); + delete myMedArray ; + delete[] myCoordinatesNames ; + delete[] myCoordinatesUnits ; + delete[] myNodeNumber ; + affiche_coordinate(* myCoordinate,numberofNodes,spaceDimension); COORDINATE * myCoordinate2 = new COORDINATE(* myCoordinate); - delete myCoordinate; + delete myCoordinate ; + affiche_coordinate(* myCoordinate2,numberofNodes,spaceDimension); + delete myCoordinate2 ; return 0; } diff --git a/src/MEDMEM/test_copie_family.cxx b/src/MEDMEM/test_copie_family.cxx index 047ef2c94..29fbcab8a 100644 --- a/src/MEDMEM/test_copie_family.cxx +++ b/src/MEDMEM/test_copie_family.cxx @@ -1,3 +1,29 @@ +// 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 : test_copie_family.cxx +// Module : MED + using namespace std; #include @@ -16,7 +42,7 @@ using namespace std; #include "MEDMEM_define.hxx" -void affiche_support(SUPPORT * mySupport) +void affiche_support(const SUPPORT * mySupport) { cout << " - Name : "<getName().c_str()<getDescription().c_str()<isOnAllElements())) { int NumberOfTypes = mySupport->getNumberOfTypes() ; cout<<" - NumberOfTypes : "<getTypes() ; + const medGeometryElement * Types = mySupport->getTypes() ; for (int j=0;jgetNumberOfElements(Types[j]) ; - int * Number = mySupport->getNumber(Types[j]) ; + const int * Number = mySupport->getNumber(Types[j]) ; for (int k=0; kgetIdentifier()<getNumberOfGroups(Entity) ; cout << "NumberOfGroups : "<getGroup(Entity,i); + const GROUP* myGroup = myMesh->getGroup(Entity,i); affiche_support(myGroup); int NumberOfFamillies = myGroup->getNumberOfFamilies() ; cout << " - Families ("<getFamily(MED_NODE,1); + const FAMILY * myFamily = myMesh->getFamily(MED_NODE,1); //On renseigne les attributs spécifiques à FAMILY (p/r à SUPPORT) et non renseignés lors de la lecture du maillage - int NumberOfAttribute = 3; - int *AttributeIdentifier = new int[NumberOfAttribute]; - int *AttributeValue = new int[NumberOfAttribute]; - string *AttributeDescription = new string[NumberOfAttribute]; - char *tmp; - for (int i=0;isetNumberOfAttributes(NumberOfAttribute); - myFamily->setAttributesIdentifiers (AttributeIdentifier); - myFamily->setAttributesValues (AttributeValue); - myFamily->setAttributesDescriptions (AttributeDescription); +// int NumberOfAttribute = 3; +// int *AttributeIdentifier = new int[NumberOfAttribute]; +// int *AttributeValue = new int[NumberOfAttribute]; +// string *AttributeDescription = new string[NumberOfAttribute]; +// char *tmp; +// for (int i=0;isetNumberOfAttributes(NumberOfAttribute); +// myFamily->setAttributesIdentifiers (AttributeIdentifier); +// myFamily->setAttributesValues (AttributeValue); +// myFamily->setAttributesDescriptions (AttributeDescription); cout << "Show Family :"< * myField, const SUPPORT * mySupport) int NumberOfComponents = myField->getNumberOfComponents() ; for (int i=1; igetValueI(MED_FULL_INTERLACE,i) ; + const double * value = myField->getValueI(MED_FULL_INTERLACE,i) ; for (int j=0; jsetName(meshname); MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ; myMeshDriver.setMeshName(meshname); - myMeshDriver.open() ; - myMeshDriver.read() ; - myMeshDriver.close() ; + int current = myMesh->addDriver(myMeshDriver); + myMesh->read(current); // read field : if (argc != 4) exit(0) ; // else we have a field ! string fieldname = argv[3]; + FIELD * myField ; // SUPPORT * mySupport = new SUPPORT(myMesh,"On_all_node",MED_NODE); SUPPORT * mySupport = new SUPPORT(myMesh,"On_all_cell",MED_CELL); - FIELD * myField = new FIELD() ; - - myField->setName(fieldname); - myField->setSupport(mySupport); - MED_FIELD_RDONLY_DRIVER myFieldDriver(filename,myField) ; - myFieldDriver.setFieldName(fieldname); - myFieldDriver.open() ; - try { - myFieldDriver.read() ; + myField = new FIELD(mySupport,MED_DRIVER,filename,fieldname) ; + myField->setValueType(MED_REEL64); } catch (...) { delete mySupport ; mySupport = new SUPPORT(myMesh,"On_all_node",MED_NODE); - myField->setSupport(mySupport); try { - myFieldDriver.read() ; + myField = new FIELD(mySupport,MED_DRIVER,filename,fieldname) ; + myField->setValueType(MED_REEL64); } catch (...) { - cout << "Field " << fieldname << " not found !!!" << endl ; + cout << "Field double " << fieldname << " not found !!!" << endl ; exit (-1) ; } } - myFieldDriver.close() ; - affiche_fieldT(myField, mySupport); FIELD * myField2 = new FIELD(* myField); delete myField; affiche_fieldT(myField2, myField2->getSupport()); delete myField2; + delete mySupport ; + delete myMesh ; + return 0; } diff --git a/src/MEDMEM/test_copie_field_.cxx b/src/MEDMEM/test_copie_field_.cxx index ac68a0b25..08f8c9e93 100644 --- a/src/MEDMEM/test_copie_field_.cxx +++ b/src/MEDMEM/test_copie_field_.cxx @@ -1,4 +1,29 @@ -using namespace std; +// 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 : test_copie_field_.cxx +// Module : MED + /* Programme de test du constructeur de copies de la classe FIELD_ de MEDMEM jroy - 12/12/2002 */ @@ -92,6 +117,7 @@ int main (int argc, char ** argv) { // SUPPORT * mySupport = new SUPPORT(myMesh,"On_all_node",MED_NODE); SUPPORT * mySupport = new SUPPORT(myMesh,"On_all_cell",MED_CELL); FIELD * myField = new FIELD() ; + myField->setValueType(MED_REEL64); myField->setName(fieldname); myField->setSupport(mySupport); @@ -120,6 +146,11 @@ int main (int argc, char ** argv) { FIELD_ * pt_field_2 = new FIELD_(* pt_field_); delete myField; affiche_field(pt_field_2, pt_field_2->getSupport()); + + delete pt_field_2 ; + + delete mySupport ; + delete myMesh ; return 0; } diff --git a/src/MEDMEM/test_copie_group.cxx b/src/MEDMEM/test_copie_group.cxx index 3238ea150..7bf53c8e2 100644 --- a/src/MEDMEM/test_copie_group.cxx +++ b/src/MEDMEM/test_copie_group.cxx @@ -1,3 +1,29 @@ +// 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 : test_copie_group.cxx +// Module : MED + using namespace std; #include @@ -16,7 +42,7 @@ using namespace std; #include "MEDMEM_define.hxx" -void affiche_support(SUPPORT * mySupport) +void affiche_support(const SUPPORT * mySupport) { cout << " - Name : "<getName().c_str()<getDescription().c_str()<isOnAllElements())) { int NumberOfTypes = mySupport->getNumberOfTypes() ; cout<<" - NumberOfTypes : "<getTypes() ; + const medGeometryElement * Types = mySupport->getTypes() ; for (int j=0;jgetNumberOfElements(Types[j]) ; - int * Number = mySupport->getNumber(Types[j]) ; + const int * Number = mySupport->getNumber(Types[j]) ; for (int k=0; kgetIdentifier()<getGroupName(j).c_str()<getNumberOfFamilies() ; @@ -66,7 +92,7 @@ int main (int argc, char ** argv) { int read; - if (argc !=3) { + if (argc <3) { // after 3, ignored ! cerr << "Usage : " << argv[0] << " filename meshname" << endl << endl; exit(-1); @@ -83,13 +109,18 @@ int main (int argc, char ** argv) { myMeshDriver.read() ; myMeshDriver.close() ; - GROUP * myGroup = myMesh->getGroup(MED_NODE,1); + const GROUP * myGroup = myMesh->getGroup(MED_NODE,1); cout << "Show Group :"< & myMedArray) MESSAGE("Show all 1 :"); numberof = myMedArray.getLeadingValue() ; for (int i=1; i<=myMedArray.getLengthValue() ; i++) { - double * node = myMedArray.getI(MED_FULL_INTERLACE,i) ; + const double * node = myMedArray.getRow(i) ; cout << " - " ; for (int j=0;j & myMedArray) MESSAGE("Show all 2 :"); numberof = myMedArray.getLengthValue() ; for (int i=1; i<=myMedArray.getLeadingValue() ; i++) { - double * node = myMedArray.getI(MED_NO_INTERLACE,i) ; + const double * node = myMedArray.getColumn(i) ; cout << " - " ; for (int j=0;j & myMedArray) MESSAGE("Show all 0 :"); numberof = myMedArray.getLeadingValue() ; int length = myMedArray.getLengthValue() ; - double * NoInterlaceArray = myMedArray.get(MED_NO_INTERLACE) ; + const double * NoInterlaceArray = myMedArray.get(MED_NO_INTERLACE) ; for (int i=0; i * myMedArray2 = new MEDARRAY(* myMedArray); + MEDARRAY * myMedArray2 = new MEDARRAY(* myMedArray,false); delete myMedArray; affiche_medarray(* myMedArray2); + MEDARRAY * myMedArray3 = new MEDARRAY(10,20); + (* myMedArray3) = (* myMedArray2) ; delete myMedArray2; + affiche_medarray(* myMedArray3); + delete myMedArray3; return 0; } diff --git a/src/MEDMEM/test_copie_support.cxx b/src/MEDMEM/test_copie_support.cxx index 7256e5e67..bc228814a 100644 --- a/src/MEDMEM/test_copie_support.cxx +++ b/src/MEDMEM/test_copie_support.cxx @@ -1,3 +1,29 @@ +// 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 : test_copie_support.cxx +// Module : MED + using namespace std; #include @@ -16,7 +42,7 @@ using namespace std; #include "MEDMEM_define.hxx" -void affiche_support(SUPPORT * mySupport) +void affiche_support(const SUPPORT * mySupport) { cout << " - Name : "<getName().c_str()<getDescription().c_str()<isOnAllElements())) { int NumberOfTypes = mySupport->getNumberOfTypes() ; cout<<" - NumberOfTypes : "<getTypes() ; + const medGeometryElement * Types = mySupport->getTypes() ; for (int j=0;jgetNumberOfElements(Types[j]) ; - int * Number = mySupport->getNumber(Types[j]) ; + const int * Number = mySupport->getNumber(Types[j]) ; for (int k=0; kgetNumberOfFamilies(Entity) ; cout << "NumberOfFamilies : "<getFamily(Entity,i); + const FAMILY* myFamily = myMesh->getFamily(Entity,i); affiche_support(myFamily); cout << " - Identifier : "<getIdentifier()<getNumberOfAttributes() ; @@ -63,7 +89,7 @@ void affiche_groupe(MESH *myMesh,medEntityMesh Entity) int NumberOfGroups = myMesh->getNumberOfGroups(Entity) ; cout << "NumberOfGroups : "<getGroup(Entity,i); + const GROUP* myGroup = myMesh->getGroup(Entity,i); affiche_support(myGroup); int NumberOfFamillies = myGroup->getNumberOfFamilies() ; cout << " - Families ("<getTypes(MED_CELL); - int TotalNumberOfEntity = 0; - int * NumberOfEntity = new int[myMesh->getNumberOfTypes(MED_CELL)]; + int TotalNumberOfElements = 0; + int * NumberOfElements = new int[myMesh->getNumberOfTypes(MED_CELL)]; // NumberOfEntity[0] = 2; // int * NumberValue = new int[TotalNumberOfEntity]; int * NumberValue = new int[myMesh->getGlobalNumberingIndex(MED_CELL)[myMesh->getNumberOfTypes(MED_CELL)]-1]; @@ -122,11 +147,12 @@ int main (int argc, char ** argv) { // NumberValue[1] = 15; int cmp = 0; medGeometryElement * GeometricTypePartial = new medGeometryElement[myMesh->getNumberOfTypes(MED_CELL)]; + const medGeometryElement * GeometricType = myMesh->getTypes(MED_CELL); for (int i=0;igetNumberOfTypes(MED_CELL);i=i+2) { NumberOfGeometricType=NumberOfGeometricType+1; - TotalNumberOfEntity=TotalNumberOfEntity+myMesh->getNumberOfElements(MED_CELL,GeometricType[i]); - NumberOfEntity[i/2]=myMesh->getNumberOfElements(MED_CELL,GeometricType[i]); + TotalNumberOfElements=TotalNumberOfElements+myMesh->getNumberOfElements(MED_CELL,GeometricType[i]); + NumberOfElements[i/2]=myMesh->getNumberOfElements(MED_CELL,GeometricType[i]); for (int j=0;jgetNumberOfElements(MED_CELL,GeometricType[i]);j++) { NumberValue[cmp]=myMesh->getGlobalNumberingIndex(MED_CELL)[i]+j; @@ -135,7 +161,11 @@ int main (int argc, char ** argv) { GeometricTypePartial[i/2]=GeometricType[i]; } - mySupport->setpartial("Support partiel",NumberOfGeometricType,TotalNumberOfEntity,GeometricTypePartial,NumberOfEntity,NumberValue); + mySupport->setpartial("Support partiel",NumberOfGeometricType,TotalNumberOfElements,GeometricTypePartial,NumberOfElements,NumberValue); + + delete[] NumberOfElements ; + delete[] NumberValue ; + delete[] GeometricTypePartial ; cout << "Show Partial Support :"<