Salome HOME
Freshly added file
[modules/smesh.git] / src / DriverDAT / DriverDAT_W_SMDS_Mesh.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_W_SMDS_Mesh.cxx
25 //  Module : SMESH
26
27 using namespace std;
28 #include "DriverDAT_W_SMDS_Mesh.h"
29
30 #include "SMDS_MeshElement.hxx"
31 #include "SMDS_MeshNode.hxx"
32
33 #include "utilities.h"
34
35 DriverDAT_W_SMDS_Mesh::DriverDAT_W_SMDS_Mesh()
36 {
37         ;
38 }
39
40 DriverDAT_W_SMDS_Mesh::~DriverDAT_W_SMDS_Mesh()
41 {
42         ;
43 }
44
45 void DriverDAT_W_SMDS_Mesh::SetMesh(SMDS_Mesh * aMesh)
46 {
47         myMesh = aMesh;
48 }
49
50 void DriverDAT_W_SMDS_Mesh::SetFile(string aFile)
51 {
52         myFile = aFile;
53 }
54
55 void DriverDAT_W_SMDS_Mesh::SetFileId(FILE * aFileId)
56 {
57         myFileId = aFileId;
58 }
59
60 void DriverDAT_W_SMDS_Mesh::SetMeshId(int aMeshId)
61 {
62         myMeshId = aMeshId;
63 }
64
65 void DriverDAT_W_SMDS_Mesh::Add()
66 {
67         ;
68 }
69
70 void DriverDAT_W_SMDS_Mesh::Write()
71 {
72
73         int nbNodes, nbCells;
74         int i;
75
76         char *file2Read = (char *)myFile.c_str();
77         myFileId = fopen(file2Read, "w+");
78         if (myFileId < 0)
79         {
80                 fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
81                 exit(EXIT_FAILURE);
82         }
83         SCRUTE(myMesh);
84   /****************************************************************************
85   *                       NOMBRES D'OBJETS                                    *
86   ****************************************************************************/
87         fprintf(stdout, "\n(****************************)\n");
88         fprintf(stdout, "(* INFORMATIONS GENERALES : *)\n");
89         fprintf(stdout, "(****************************)\n");
90
91         /* Combien de noeuds ? */
92         nbNodes = myMesh->NbNodes();
93
94         /* Combien de mailles, faces ou aretes ? */
95         int nb_of_nodes, nb_of_edges, nb_of_faces, nb_of_volumes;
96         nb_of_edges = myMesh->NbEdges();
97         nb_of_faces = myMesh->NbFaces();
98         nb_of_volumes = myMesh->NbVolumes();
99         nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
100         SCRUTE(nb_of_edges);
101         SCRUTE(nb_of_faces);
102         SCRUTE(nb_of_volumes);
103
104         fprintf(stdout, "%d %d\n", nbNodes, nbCells);
105         fprintf(myFileId, "%d %d\n", nbNodes, nbCells);
106
107   /****************************************************************************
108   *                       ECRITURE DES NOEUDS                                 *
109   ****************************************************************************/
110         fprintf(stdout, "\n(************************)\n");
111         fprintf(stdout, "(* NOEUDS DU MAILLAGE : *)\n");
112         fprintf(stdout, "(************************)\n");
113
114         SMDS_Iterator<const SMDS_MeshNode *> * itNodes=myMesh->nodesIterator();
115         while(itNodes->more())
116         {               
117                 const SMDS_MeshNode * node = itNodes->next();
118                 fprintf(myFileId, "%d %e %e %e\n", node->GetID(), node->X(),
119                         node->Y(), node->Z());
120         }
121         
122   /****************************************************************************
123   *                       ECRITURE DES ELEMENTS                                *
124   ****************************************************************************/
125         fprintf(stdout, "\n(**************************)\n");
126         fprintf(stdout, "(* ELEMENTS DU MAILLAGE : *)\n");
127         fprintf(stdout, "(**************************)");
128         /* Ecriture des connectivites, noms, numeros des mailles */
129
130         SMDS_Iterator<const SMDS_MeshEdge *> * itEdges=myMesh->edgesIterator();
131         while(itEdges->more())
132         {
133                 const SMDS_MeshElement * elem = itEdges->next();
134
135                 switch (elem->NbNodes())
136                 {
137                 case 2:
138                 {
139                         fprintf(myFileId, "%d %d ", elem->GetID(), 102);
140                         break;
141                 }
142                 case 3:
143                 {
144                         fprintf(myFileId, "%d %d ", elem->GetID(), 103);
145                         break;
146                 }
147                 }
148
149                 SMDS_Iterator<const SMDS_MeshElement *> * it=elem->nodesIterator();
150                 while(it->more()) fprintf(myFileId, "%d ", it->next()->GetID());
151
152                 fprintf(myFileId, "\n");
153         }
154
155         SMDS_Iterator<const SMDS_MeshFace *> * itFaces=myMesh->facesIterator();
156         while(itFaces->more())
157         {
158                 const SMDS_MeshElement * elem = itFaces->next();
159
160                 switch (elem->NbNodes())
161                 {
162                 case 3:
163                 {
164                         fprintf(myFileId, "%d %d ", elem->GetID(), 203);
165                         break;
166                 }
167                 case 4:
168                 {
169                         fprintf(myFileId, "%d %d ", elem->GetID(), 204);
170                         break;
171                 }
172                 case 6:
173                 {
174                         fprintf(myFileId, "%d %d ", elem->GetID(), 206);
175                         break;
176                 }
177                 }
178
179                 SMDS_Iterator<const SMDS_MeshElement *> * it=elem->nodesIterator();
180                 while(it->more()) fprintf(myFileId, "%d ", it->next()->GetID());
181
182                 fprintf(myFileId, "\n");
183         }
184
185         SMDS_Iterator<const SMDS_MeshVolume *> * itVolumes=myMesh->volumesIterator();
186         while(itVolumes->more())
187         {
188                 const SMDS_MeshElement * elem = itVolumes->next();
189                 
190                 switch (elem->NbNodes())
191                 {
192                 case 8:
193                 {
194                         fprintf(myFileId, "%d %d ", elem->GetID(), 308);
195                         break;
196                 }
197                 }
198
199                 SMDS_Iterator<const SMDS_MeshElement *> * it=elem->nodesIterator();
200                 while(it->more()) fprintf(myFileId, "%d ", it->next()->GetID());
201
202                 fprintf(myFileId, "\n");
203         }
204
205         fclose(myFileId);
206 }