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
27 #include "DriverDAT_W_SMDS_Mesh.h"
28 #include "SMDS_MeshElement.hxx"
29 #include "SMDS_MeshNode.hxx"
30 #include "utilities.h"
36 * Factory function which will be called by SMESHDriver
38 void * SMESH_createDATMeshWriter()
40 return new DriverDAT_W_SMDS_Mesh();
44 DriverDAT_W_SMDS_Mesh::DriverDAT_W_SMDS_Mesh()
48 DriverDAT_W_SMDS_Mesh::~DriverDAT_W_SMDS_Mesh()
53 void DriverDAT_W_SMDS_Mesh::SetMesh(SMDS_Mesh * aMesh)
58 void DriverDAT_W_SMDS_Mesh::SetFile(string aFile)
63 void DriverDAT_W_SMDS_Mesh::SetFileId(FILE * aFileId)
68 void DriverDAT_W_SMDS_Mesh::SetMeshId(int aMeshId)
73 void DriverDAT_W_SMDS_Mesh::Add()
75 MESSAGE("Adding a mesh to a DAT document. As DAT do not support more than one mesh in a file, the previous mesh is deleted");
79 void DriverDAT_W_SMDS_Mesh::Write()
84 char *file2Read = (char *)myFile.c_str();
85 myFileId = fopen(file2Read, "w+");
88 fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
92 /****************************************************************************
94 ****************************************************************************/
95 fprintf(stdout, "\n(****************************)\n");
96 fprintf(stdout, "(* INFORMATIONS GENERALES : *)\n");
97 fprintf(stdout, "(****************************)\n");
99 /* Combien de noeuds ? */
100 nbNodes = myMesh->NbNodes();
102 /* Combien de mailles, faces ou aretes ? */
103 int nb_of_nodes, nb_of_edges, nb_of_faces, nb_of_volumes;
104 nb_of_edges = myMesh->NbEdges();
105 nb_of_faces = myMesh->NbFaces();
106 nb_of_volumes = myMesh->NbVolumes();
107 nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
109 fprintf(stdout, "%d %d\n", nbNodes, nbCells);
110 fprintf(myFileId, "%d %d\n", nbNodes, nbCells);
112 /****************************************************************************
113 * ECRITURE DES NOEUDS *
114 ****************************************************************************/
115 fprintf(stdout, "\n(************************)\n");
116 fprintf(stdout, "(* NOEUDS DU MAILLAGE : *)\n");
117 fprintf(stdout, "(************************)\n");
119 SMDS_Iterator<const SMDS_MeshNode *> * itNodes=myMesh->nodesIterator();
120 while(itNodes->more())
122 const SMDS_MeshNode * node = itNodes->next();
123 fprintf(myFileId, "%d %e %e %e\n", node->GetID(), node->X(),
124 node->Y(), node->Z());
128 /****************************************************************************
129 * ECRITURE DES ELEMENTS *
130 ****************************************************************************/
131 fprintf(stdout, "\n(**************************)\n");
132 fprintf(stdout, "(* ELEMENTS DU MAILLAGE : *)\n");
133 fprintf(stdout, "(**************************)");
134 /* Ecriture des connectivites, noms, numeros des mailles */
136 SMDS_Iterator<const SMDS_MeshEdge*> * itEdges=myMesh->edgesIterator();
137 while(itEdges->more())
139 const SMDS_MeshEdge * elem = itEdges->next();
141 switch (elem->NbNodes())
145 fprintf(myFileId, "%d %d ", elem->GetID(), 102);
150 fprintf(myFileId, "%d %d ", elem->GetID(), 103);
155 SMDS_Iterator<const SMDS_MeshElement *> * itNodes=elem->nodesIterator();
156 while(itNodes->more())
157 fprintf(myFileId, "%d ", itNodes->next()->GetID());
159 fprintf(myFileId, "\n");
163 SMDS_Iterator<const SMDS_MeshFace *> * itFaces=myMesh->facesIterator();
164 while(itFaces->more())
166 const SMDS_MeshElement * elem = itFaces->next();
168 switch (elem->NbNodes())
172 fprintf(myFileId, "%d %d ", elem->GetID(), 203);
177 fprintf(myFileId, "%d %d ", elem->GetID(), 204);
182 fprintf(myFileId, "%d %d ", elem->GetID(), 206);
187 SMDS_Iterator<const SMDS_MeshElement *> * itNodes=elem->nodesIterator();
188 while(itNodes->more())
189 fprintf(myFileId, "%d ", itNodes->next()->GetID());
192 fprintf(myFileId, "\n");
196 SMDS_Iterator<const SMDS_MeshVolume*> * itVolumes=myMesh->volumesIterator();
197 while(itVolumes->more())
199 const SMDS_MeshElement * elem = itVolumes->next();
201 switch (elem->NbNodes())
205 fprintf(myFileId, "%d %d ", elem->GetID(), 308);
210 SMDS_Iterator<const SMDS_MeshElement *> * itNodes=elem->nodesIterator();
211 while(itNodes->more())
212 fprintf(myFileId, "%d ", itNodes->next()->GetID());
215 fprintf(myFileId, "\n");