Salome HOME
421c6c95ca1fa3fa7671bbd3d767bbc12dee062b
[modules/smesh.git] / src / DriverDAT / DriverDAT_R_SMESHDS_Document.cxx
1 //  SMESH DriverDAT : driver to read and write 'dat' files
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : DriverDAT_R_SMESHDS_Document.cxx
25 //  Module : SMESH
26
27 using namespace std;
28 #include "DriverDAT_R_SMESHDS_Document.h"
29 #include "DriverDAT_R_SMESHDS_Mesh.h"
30
31 #include "utilities.h"
32
33 int getOne() {
34   printf("in getOne");
35   return (1);
36 }
37
38 extern "C" {
39   //  Document_Reader* maker() {
40   DriverDAT_R_SMESHDS_Document* maker() {
41     fprintf(stdout,"here in maker\n");
42     return new DriverDAT_R_SMESHDS_Document;
43   }
44 }
45
46 DriverDAT_R_SMESHDS_Document::DriverDAT_R_SMESHDS_Document() {
47   myFile = string("");
48 }
49
50 DriverDAT_R_SMESHDS_Document::~DriverDAT_R_SMESHDS_Document() {
51 ;
52 }
53
54 //void DriverDAT_R_SMESHDS_Document::SetFile(string aFile) {
55 //myFile = aFile;
56 //}
57
58 //void DriverDAT_R_SMESHDS_Document::SetDocument(Handle(SMESHDS_Document)& aDoc) {
59 //myDocument = aDoc;
60 //}
61
62 void DriverDAT_R_SMESHDS_Document::Read() {
63
64   int myMeshId;
65   MESSAGE("in read");
66   SCRUTE(myFile);
67   //Handle(SMESHDS_Document) myDocument = new SMESHDS_Document(1);
68
69   /****************************************************************************
70   *                      OUVERTURE DU FICHIER EN LECTURE                      *
71   ****************************************************************************/
72   char* file2Read = (char*)myFile.c_str();
73   FILE* fid = fopen(file2Read,"r");
74   if (fid < 0)
75     {
76       fprintf(stderr,">> ERREUR : ouverture du fichier %s \n",file2Read);
77       exit(EXIT_FAILURE);
78     }
79
80   /****************************************************************************
81   *                      COMBIEN DE MAILLAGES ?                               *
82   ****************************************************************************/
83   int nmaa = 1;
84
85   /****************************************************************************
86   *                      FERMETURE DU FICHIER                                 *
87   ****************************************************************************/
88   fclose(fid);
89   
90   printf("Nombre de maillages = %d\n",nmaa);
91
92   string myClass = string("SMESHDS_Mesh");
93   string myExtension = string("DAT");
94
95   for (int meshIt=1;meshIt<=nmaa;meshIt++) {
96     myMeshId = myDocument->NewMesh();
97
98     Handle(SMDS_Mesh) myMesh = myDocument->GetMesh(myMeshId);
99
100     DriverDAT_R_SMESHDS_Mesh* myReader = new DriverDAT_R_SMESHDS_Mesh;
101
102
103     myReader->SetMesh(myMesh);
104     myReader->SetFile(myFile);
105     //myReader->SetFileId(fid);
106
107     myReader->Read();
108
109   }
110
111
112 }