Salome HOME
Initialisation module SMESH_SRC de la base SMESH
[modules/smesh.git] / src / DriverMED / DriverMED_R_SMESHDS_Document.cxx
1 #include "DriverMED_R_SMESHDS_Document.h"
2 #include "DriverMED_R_SMESHDS_Mesh.h"
3 #include "utilities.h"
4
5 extern "C" {
6   Document_Reader* maker() {
7     return new DriverMED_R_SMESHDS_Document;
8   }
9 }
10
11 DriverMED_R_SMESHDS_Document::DriverMED_R_SMESHDS_Document() {
12 ;
13 }
14
15 DriverMED_R_SMESHDS_Document::~DriverMED_R_SMESHDS_Document() {
16 ;
17 }
18
19 //void DriverMED_R_SMESHDS_Document::SetFile(string aFile) {
20 //  myFile = aFile;
21 //}
22
23 void DriverMED_R_SMESHDS_Document::Read() {
24
25   med_err ret = 0;
26   med_idt fid;
27   med_int nmaa;
28
29   Standard_Integer myMeshId;
30
31   //string myFile = string("/home/home_users/cai/projects/salome_prev04/SALOME_ROOT/data/fra1.med");
32
33 /****************************************************************************
34   *                      OUVERTURE DU FICHIER EN LECTURE                      *
35   ****************************************************************************/
36   char* file2Read = (char*)myFile.c_str();
37   fid = MEDouvrir(file2Read,MED_LECT);
38   if (fid < 0)
39     {
40       fprintf(stderr,">> ERREUR : ouverture du fichier %s \n",file2Read);
41       exit(EXIT_FAILURE);
42     }
43
44   /****************************************************************************
45   *                      COMBIEN DE MAILLAGES ?                               *
46   ****************************************************************************/
47   nmaa = MEDnMaa(fid);
48   if (nmaa < 0)
49     {
50       fprintf(stderr,">> ERREUR : lecture du nombre de maillages \n");
51       exit(EXIT_FAILURE);
52     }
53   printf("Nombre de maillages = %d\n",nmaa);
54
55   string myClass = string("SMESHDS_Mesh");
56   string myExtension = string("MED");
57
58
59   for (int meshIt=1;meshIt<=nmaa;meshIt++) {
60     myMeshId = myDocument->NewMesh();
61     printf("MeshId = %d\n",myMeshId);
62
63     Handle(SMDS_Mesh) myMesh = myDocument->GetMesh(myMeshId);
64   SCRUTE(myMesh);
65
66     // Handle (SMDS_Mesh) MMM =.........
67     //ex Handle(SMESHDS_Mesh) myMesh2 =Handle(SMESHDS_Mesh)::DownCast(MMM);
68
69     DriverMED_R_SMESHDS_Mesh* myReader = new DriverMED_R_SMESHDS_Mesh;
70
71     myReader->SetMesh(myMesh);
72     myReader->SetMeshId(myMeshId);
73
74     //myReader->SetFile(myFile);
75   SCRUTE(fid);
76     myReader->SetFileId(fid);
77
78     myReader->Add();
79
80   }
81
82   /****************************************************************************
83   *                      FERMETURE DU FICHIER                                 *
84   ****************************************************************************/
85   ret = MEDfermer(fid);
86   
87   if (ret != 0)
88     fprintf(stderr,">> ERREUR : erreur a la fermeture du fichier %s\n",file2Read);
89
90
91 }