Salome HOME
merge V7_7_BR
[modules/smesh.git] / src / DriverDAT / DriverDAT_W_SMDS_Mesh.cxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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
42   char *file2Read = (char *)myFile.c_str();
43   FILE* aFileId = fopen(file2Read, "w+");
44   if ( !aFileId ) {
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
53   /* Combien de noeuds ? */
54   nbNodes = myMesh->NbNodes();
55
56   /* Combien de mailles, faces ou aretes ? */
57   int 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
73   SMDS_NodeIteratorPtr itNodes=myMesh->nodesIterator();
74   while(itNodes->more()){               
75     const SMDS_MeshNode * node = itNodes->next();
76     fprintf(aFileId, "%d %.14e %.14e %.14e\n", node->GetID(), node->X(), node->Y(), node->Z());
77   }
78         
79   /****************************************************************************
80    *                       ECRITURE DES ELEMENTS                                *
81    ****************************************************************************/
82   /* Ecriture des connectivites, noms, numeros des mailles */
83   
84   SMDS_EdgeIteratorPtr itEdges=myMesh->edgesIterator();
85   while(itEdges->more()){
86     const SMDS_MeshElement * elem = itEdges->next();
87     switch (elem->NbNodes()) {
88     case 2:
89       fprintf(aFileId, "%d %d ", elem->GetID(), 102);
90       break;
91     case 3:
92       fprintf(aFileId, "%d %d ", elem->GetID(), 103);
93       break;
94     }
95     SMDS_ElemIteratorPtr it=elem->nodesIterator();
96     while(it->more()) 
97       fprintf(aFileId, "%d ", it->next()->GetID());
98     fprintf(aFileId, "\n");
99   }
100   
101   SMDS_FaceIteratorPtr itFaces=myMesh->facesIterator();
102   while(itFaces->more()){
103     const SMDS_MeshElement * elem = itFaces->next();
104     if ( elem->IsPoly() )
105       fprintf(aFileId, "%d %d ", elem->GetID(), 400+elem->NbNodes());
106     else
107       fprintf(aFileId, "%d %d ", elem->GetID(), 200+elem->NbNodes());
108     SMDS_ElemIteratorPtr it=elem->nodesIterator();
109     while(it->more()) 
110       fprintf(aFileId, "%d ", it->next()->GetID());
111     fprintf(aFileId, "\n");
112   }
113
114   SMDS_VolumeIteratorPtr itVolumes=myMesh->volumesIterator();
115   while(itVolumes->more()){
116     const SMDS_MeshElement * elem = itVolumes->next();
117     if ( elem->IsPoly() )
118       fprintf(aFileId, "%d %d ", elem->GetID(), 500+elem->NbNodes());
119     else
120       fprintf(aFileId, "%d %d ", elem->GetID(), 300+elem->NbNodes());
121     SMDS_ElemIteratorPtr it=elem->nodesIterator();
122     while(it->more()) 
123       fprintf(aFileId, "%d ", it->next()->GetID());
124
125     fprintf(aFileId, "\n");
126   }
127   
128   fclose(aFileId);
129
130   return aResult;
131 }