Salome HOME
796cd5b661b078f01dbe92edebb077c4a9c4f6d1
[modules/smesh.git] / src / DriverDAT / DriverDAT_W_SMDS_Mesh.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include <stdio.h>
23
24 #include "DriverDAT_W_SMDS_Mesh.h"
25
26 #include "SMDS_Mesh.hxx"
27
28 #include "utilities.h"
29
30 #include <Basics_Utils.hxx>
31
32 using namespace std;
33
34 Driver_Mesh::Status DriverDAT_W_SMDS_Mesh::Perform()
35 {
36   Kernel_Utils::Localizer loc;
37   Status aResult = DRS_OK;
38
39   int nbNodes, nbCells;
40   //int i;
41   
42   char *file2Read = (char *)myFile.c_str();
43   FILE* aFileId = fopen(file2Read, "w+");
44   if (aFileId < 0) {
45     fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
46     return DRS_FAIL;
47   }
48   SCRUTE(myMesh);
49   /****************************************************************************
50    *                       NOMBRES D'OBJETS                                    *
51    ****************************************************************************/
52   fprintf(stdout, "\n(****************************)\n");
53   fprintf(stdout, "(* INFORMATIONS GENERALES : *)\n");
54   fprintf(stdout, "(****************************)\n");
55   
56   /* Combien de noeuds ? */
57   nbNodes = myMesh->NbNodes();
58   
59   /* Combien de mailles, faces ou aretes ? */
60   int /*nb_of_nodes,*/ nb_of_edges, nb_of_faces, nb_of_volumes;
61   nb_of_edges = myMesh->NbEdges();
62   nb_of_faces = myMesh->NbFaces();
63   nb_of_volumes = myMesh->NbVolumes();
64   nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
65   SCRUTE(nb_of_edges);
66   SCRUTE(nb_of_faces);
67   SCRUTE(nb_of_volumes);
68   
69   fprintf(stdout, "%d %d\n", nbNodes, nbCells);
70   fprintf(aFileId, "%d %d\n", nbNodes, nbCells);
71   
72   /****************************************************************************
73    *                       ECRITURE DES NOEUDS                                 *
74    ****************************************************************************/
75   fprintf(stdout, "\n(************************)\n");
76   fprintf(stdout, "(* NOEUDS DU MAILLAGE : *)\n");
77   fprintf(stdout, "(************************)\n");
78   
79   SMDS_NodeIteratorPtr itNodes=myMesh->nodesIterator();
80   while(itNodes->more()){               
81     const SMDS_MeshNode * node = itNodes->next();
82     fprintf(aFileId, "%d %e %e %e\n", node->GetID(), node->X(), node->Y(), node->Z());
83   }
84         
85   /****************************************************************************
86    *                       ECRITURE DES ELEMENTS                                *
87    ****************************************************************************/
88   fprintf(stdout, "\n(**************************)\n");
89   fprintf(stdout, "(* ELEMENTS DU MAILLAGE : *)\n");
90   fprintf(stdout, "(**************************)");
91   /* Ecriture des connectivites, noms, numeros des mailles */
92   
93   SMDS_EdgeIteratorPtr itEdges=myMesh->edgesIterator();
94   while(itEdges->more()){
95     const SMDS_MeshElement * elem = itEdges->next();
96     switch (elem->NbNodes()) {
97     case 2:
98       fprintf(aFileId, "%d %d ", elem->GetID(), 102);
99       break;
100     case 3:
101       fprintf(aFileId, "%d %d ", elem->GetID(), 103);
102       break;
103     }
104     SMDS_ElemIteratorPtr it=elem->nodesIterator();
105     while(it->more()) 
106       fprintf(aFileId, "%d ", it->next()->GetID());
107     fprintf(aFileId, "\n");
108   }
109   
110   SMDS_FaceIteratorPtr itFaces=myMesh->facesIterator();
111   while(itFaces->more()){
112     const SMDS_MeshElement * elem = itFaces->next();
113     switch (elem->NbNodes()) {
114     case 3:
115       fprintf(aFileId, "%d %d ", elem->GetID(), 203);
116       break;
117     case 4:
118       fprintf(aFileId, "%d %d ", elem->GetID(), 204);
119       break;
120     case 6:
121       fprintf(aFileId, "%d %d ", elem->GetID(), 206);
122       break;
123     }
124     SMDS_ElemIteratorPtr it=elem->nodesIterator();
125     while(it->more()) 
126       fprintf(aFileId, "%d ", it->next()->GetID());
127     fprintf(aFileId, "\n");
128   }
129
130   SMDS_VolumeIteratorPtr itVolumes=myMesh->volumesIterator();
131   while(itVolumes->more()){
132     const SMDS_MeshElement * elem = itVolumes->next();
133     switch (elem->NbNodes()) {
134     case 8:
135       fprintf(aFileId, "%d %d ", elem->GetID(), 308);
136       break;
137     }
138
139     SMDS_ElemIteratorPtr it=elem->nodesIterator();
140     while(it->more()) 
141       fprintf(aFileId, "%d ", it->next()->GetID());
142
143     fprintf(aFileId, "\n");
144   }
145   
146   fclose(aFileId);
147
148   return aResult;
149 }