1 // SMESH DriverDAT : driver to read and write 'dat' files
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DriverDAT_W_SMDS_Mesh.cxx
28 #include "DriverDAT_W_SMDS_Mesh.h"
30 #include "SMDS_MeshElement.hxx"
31 #include "SMDS_MeshNode.hxx"
33 #include "utilities.h"
35 DriverDAT_W_SMDS_Mesh::DriverDAT_W_SMDS_Mesh()
40 DriverDAT_W_SMDS_Mesh::~DriverDAT_W_SMDS_Mesh()
45 void DriverDAT_W_SMDS_Mesh::SetMesh(SMDS_Mesh * aMesh)
50 void DriverDAT_W_SMDS_Mesh::SetFile(string aFile)
55 void DriverDAT_W_SMDS_Mesh::SetFileId(FILE * aFileId)
60 void DriverDAT_W_SMDS_Mesh::SetMeshId(int aMeshId)
65 void DriverDAT_W_SMDS_Mesh::Add()
70 void DriverDAT_W_SMDS_Mesh::Write()
76 char *file2Read = (char *)myFile.c_str();
77 myFileId = fopen(file2Read, "w+");
80 fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
84 /****************************************************************************
86 ****************************************************************************/
87 fprintf(stdout, "\n(****************************)\n");
88 fprintf(stdout, "(* INFORMATIONS GENERALES : *)\n");
89 fprintf(stdout, "(****************************)\n");
91 /* Combien de noeuds ? */
92 nbNodes = myMesh->NbNodes();
94 /* Combien de mailles, faces ou aretes ? */
95 int nb_of_nodes, nb_of_edges, nb_of_faces, nb_of_volumes;
96 nb_of_edges = myMesh->NbEdges();
97 nb_of_faces = myMesh->NbFaces();
98 nb_of_volumes = myMesh->NbVolumes();
99 nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
102 SCRUTE(nb_of_volumes);
104 fprintf(stdout, "%d %d\n", nbNodes, nbCells);
105 fprintf(myFileId, "%d %d\n", nbNodes, nbCells);
107 /****************************************************************************
108 * ECRITURE DES NOEUDS *
109 ****************************************************************************/
110 fprintf(stdout, "\n(************************)\n");
111 fprintf(stdout, "(* NOEUDS DU MAILLAGE : *)\n");
112 fprintf(stdout, "(************************)\n");
114 SMDS_NodeIteratorPtr itNodes=myMesh->nodesIterator();
115 while(itNodes->more())
117 const SMDS_MeshNode * node = itNodes->next();
118 fprintf(myFileId, "%d %e %e %e\n", node->GetID(), node->X(),
119 node->Y(), node->Z());
122 /****************************************************************************
123 * ECRITURE DES ELEMENTS *
124 ****************************************************************************/
125 fprintf(stdout, "\n(**************************)\n");
126 fprintf(stdout, "(* ELEMENTS DU MAILLAGE : *)\n");
127 fprintf(stdout, "(**************************)");
128 /* Ecriture des connectivites, noms, numeros des mailles */
130 SMDS_EdgeIteratorPtr itEdges=myMesh->edgesIterator();
131 while(itEdges->more())
133 const SMDS_MeshElement * elem = itEdges->next();
135 switch (elem->NbNodes())
139 fprintf(myFileId, "%d %d ", elem->GetID(), 102);
144 fprintf(myFileId, "%d %d ", elem->GetID(), 103);
149 SMDS_ElemIteratorPtr it=elem->nodesIterator();
150 while(it->more()) fprintf(myFileId, "%d ", it->next()->GetID());
152 fprintf(myFileId, "\n");
155 SMDS_FaceIteratorPtr itFaces=myMesh->facesIterator();
156 while(itFaces->more())
158 const SMDS_MeshElement * elem = itFaces->next();
160 switch (elem->NbNodes())
164 fprintf(myFileId, "%d %d ", elem->GetID(), 203);
169 fprintf(myFileId, "%d %d ", elem->GetID(), 204);
174 fprintf(myFileId, "%d %d ", elem->GetID(), 206);
179 SMDS_ElemIteratorPtr it=elem->nodesIterator();
180 while(it->more()) fprintf(myFileId, "%d ", it->next()->GetID());
182 fprintf(myFileId, "\n");
185 SMDS_VolumeIteratorPtr itVolumes=myMesh->volumesIterator();
186 while(itVolumes->more())
188 const SMDS_MeshElement * elem = itVolumes->next();
190 switch (elem->NbNodes())
194 fprintf(myFileId, "%d %d ", elem->GetID(), 308);
199 SMDS_ElemIteratorPtr it=elem->nodesIterator();
200 while(it->more()) fprintf(myFileId, "%d ", it->next()->GetID());
202 fprintf(myFileId, "\n");