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