smesh/src/DriverMED/DriverMED_R_SMESHDS_Document.cxx

123 lines
3.4 KiB
C++
Raw Normal View History

2003-07-10 09:06:41 +00:00
// SMESH DriverMED : driver to read and write 'med' files
//
// 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 : DriverMED_R_SMESHDS_Document.cxx
// Module : SMESH
2003-05-19 13:18:36 +00:00
using namespace std;
#include "DriverMED_R_SMESHDS_Document.h"
#include "DriverMED_R_SMESHDS_Mesh.h"
#include "utilities.h"
2003-09-04 12:03:27 +00:00
extern "C"
{
void * SMESH_createMEDDocumentReader()
2003-09-04 12:03:27 +00:00
{
return new DriverMED_R_SMESHDS_Document;
}
}
2003-09-04 12:03:27 +00:00
DriverMED_R_SMESHDS_Document::DriverMED_R_SMESHDS_Document()
:Document_Reader(new DriverMED_R_SMESHDS_Mesh())
2003-09-04 12:03:27 +00:00
{
;
}
2003-09-04 12:03:27 +00:00
DriverMED_R_SMESHDS_Document::~DriverMED_R_SMESHDS_Document()
{
;
}
//void DriverMED_R_SMESHDS_Document::SetFile(string aFile) {
// myFile = aFile;
//}
2003-09-04 12:03:27 +00:00
void DriverMED_R_SMESHDS_Document::Read()
{
2003-09-04 12:03:27 +00:00
med_err ret = 0;
med_idt fid;
med_int nmaa;
2003-09-04 12:03:27 +00:00
int myMeshId;
/****************************************************************************
* OUVERTURE DU FICHIER EN LECTURE *
****************************************************************************/
2003-09-04 12:03:27 +00:00
char *file2Read = (char *)myFile.c_str();
fid = MEDouvrir(file2Read, MED_LECT);
if (fid < 0)
{
fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
exit(EXIT_FAILURE);
}
/****************************************************************************
* COMBIEN DE MAILLAGES ? *
****************************************************************************/
2003-09-04 12:03:27 +00:00
nmaa = MEDnMaa(fid);
if (nmaa < 0)
{
fprintf(stderr, ">> ERREUR : lecture du nombre de maillages \n");
exit(EXIT_FAILURE);
}
printf("Nombre de maillages = %d\n", nmaa);
2003-09-04 12:03:27 +00:00
string myClass = string("SMESHDS_Mesh");
string myExtension = string("MED");
2003-09-04 12:03:27 +00:00
for (int meshIt = 1; meshIt <= nmaa; meshIt++)
{
myMeshId = myDocument->NewMesh();
printf("MeshId = %d\n", myMeshId);
2003-09-04 12:03:27 +00:00
SMDS_Mesh * myMesh = myDocument->GetMesh(myMeshId);
SCRUTE(myMesh);
2003-09-04 12:03:27 +00:00
// Handle (SMDS_Mesh) MMM =.........
//ex SMESHDS_Mesh * myMesh2 =SMESHDS_Mesh *::DownCast(MMM);
2003-09-04 12:03:27 +00:00
DriverMED_R_SMESHDS_Mesh *myReader = new DriverMED_R_SMESHDS_Mesh;
2003-09-04 12:03:27 +00:00
myReader->SetMesh(myMesh);
myReader->SetMeshId(myMeshId);
2003-09-04 12:03:27 +00:00
//myReader->SetFile(myFile);
SCRUTE(fid);
myReader->SetFileId(fid);
2003-09-04 12:03:27 +00:00
myReader->Add();
2003-09-04 12:03:27 +00:00
}
/****************************************************************************
* FERMETURE DU FICHIER *
****************************************************************************/
2003-09-04 12:03:27 +00:00
ret = MEDfermer(fid);
2003-09-04 12:03:27 +00:00
if (ret != 0)
fprintf(stderr, ">> ERREUR : erreur a la fermeture du fichier %s\n",
file2Read);
}