Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/smesh.git] / src / DriverDAT / DriverDAT_W_SMDS_Mesh.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19
20 #include <stdio.h>
21
22 #include "DriverDAT_W_SMDS_Mesh.h"
23
24 #include "SMDS_Mesh.hxx"
25
26 #include "utilities.h"
27
28 using namespace std;
29
30 Driver_Mesh::Status DriverDAT_W_SMDS_Mesh::Perform()
31 {
32   Status aResult = DRS_OK;
33
34   int nbNodes, nbCells;
35   int i;
36   
37   char *file2Read = (char *)myFile.c_str();
38   FILE* aFileId = fopen(file2Read, "w+");
39   if (aFileId < 0) {
40     fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
41     return DRS_FAIL;
42   }
43   SCRUTE(myMesh);
44   /****************************************************************************
45    *                       NOMBRES D'OBJETS                                    *
46    ****************************************************************************/
47   fprintf(stdout, "\n(****************************)\n");
48   fprintf(stdout, "(* INFORMATIONS GENERALES : *)\n");
49   fprintf(stdout, "(****************************)\n");
50   
51   /* Combien de noeuds ? */
52   nbNodes = myMesh->NbNodes();
53   
54   /* Combien de mailles, faces ou aretes ? */
55   int nb_of_nodes, nb_of_edges, nb_of_faces, nb_of_volumes;
56   nb_of_edges = myMesh->NbEdges();
57   nb_of_faces = myMesh->NbFaces();
58   nb_of_volumes = myMesh->NbVolumes();
59   nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
60   SCRUTE(nb_of_edges);
61   SCRUTE(nb_of_faces);
62   SCRUTE(nb_of_volumes);
63   
64   fprintf(stdout, "%d %d\n", nbNodes, nbCells);
65   fprintf(aFileId, "%d %d\n", nbNodes, nbCells);
66   
67   /****************************************************************************
68    *                       ECRITURE DES NOEUDS                                 *
69    ****************************************************************************/
70   fprintf(stdout, "\n(************************)\n");
71   fprintf(stdout, "(* NOEUDS DU MAILLAGE : *)\n");
72   fprintf(stdout, "(************************)\n");
73   
74   SMDS_NodeIteratorPtr itNodes=myMesh->nodesIterator();
75   while(itNodes->more()){               
76     const SMDS_MeshNode * node = itNodes->next();
77     fprintf(aFileId, "%d %e %e %e\n", node->GetID(), node->X(), node->Y(), node->Z());
78   }
79         
80   /****************************************************************************
81    *                       ECRITURE DES ELEMENTS                                *
82    ****************************************************************************/
83   fprintf(stdout, "\n(**************************)\n");
84   fprintf(stdout, "(* ELEMENTS DU MAILLAGE : *)\n");
85   fprintf(stdout, "(**************************)");
86   /* Ecriture des connectivites, noms, numeros des mailles */
87   
88   SMDS_EdgeIteratorPtr itEdges=myMesh->edgesIterator();
89   while(itEdges->more()){
90     const SMDS_MeshElement * elem = itEdges->next();
91     switch (elem->NbNodes()) {
92     case 2:
93       fprintf(aFileId, "%d %d ", elem->GetID(), 102);
94       break;
95     case 3:
96       fprintf(aFileId, "%d %d ", elem->GetID(), 103);
97       break;
98     }
99     SMDS_ElemIteratorPtr it=elem->nodesIterator();
100     while(it->more()) 
101       fprintf(aFileId, "%d ", it->next()->GetID());
102     fprintf(aFileId, "\n");
103   }
104   
105   SMDS_FaceIteratorPtr itFaces=myMesh->facesIterator();
106   while(itFaces->more()){
107     const SMDS_MeshElement * elem = itFaces->next();
108     switch (elem->NbNodes()) {
109     case 3:
110       fprintf(aFileId, "%d %d ", elem->GetID(), 203);
111       break;
112     case 4:
113       fprintf(aFileId, "%d %d ", elem->GetID(), 204);
114       break;
115     case 6:
116       fprintf(aFileId, "%d %d ", elem->GetID(), 206);
117       break;
118     }
119     SMDS_ElemIteratorPtr it=elem->nodesIterator();
120     while(it->more()) 
121       fprintf(aFileId, "%d ", it->next()->GetID());
122     fprintf(aFileId, "\n");
123   }
124
125   SMDS_VolumeIteratorPtr itVolumes=myMesh->volumesIterator();
126   while(itVolumes->more()){
127     const SMDS_MeshElement * elem = itVolumes->next();
128     switch (elem->NbNodes()) {
129     case 8:
130       fprintf(aFileId, "%d %d ", elem->GetID(), 308);
131       break;
132     }
133
134     SMDS_ElemIteratorPtr it=elem->nodesIterator();
135     while(it->more()) 
136       fprintf(aFileId, "%d ", it->next()->GetID());
137
138     fprintf(aFileId, "\n");
139   }
140   
141   fclose(aFileId);
142
143   return aResult;
144 }