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