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_SMESHDS_Mesh.cxx
28 #include "DriverDAT_W_SMESHDS_Mesh.h"
29 #include "DriverDAT_W_SMDS_Mesh.h"
31 #include "SMDS_MeshElement.hxx"
32 #include "SMDS_MeshNode.hxx"
38 #include "utilities.h"
40 DriverDAT_W_SMESHDS_Mesh::DriverDAT_W_SMESHDS_Mesh()
45 DriverDAT_W_SMESHDS_Mesh::~DriverDAT_W_SMESHDS_Mesh()
50 void DriverDAT_W_SMESHDS_Mesh::SetMesh(SMDS_Mesh * aMesh)
52 //myMesh = SMESHDS_Mesh *::DownCast(aMesh);
56 void DriverDAT_W_SMESHDS_Mesh::SetFile(string aFile)
61 void DriverDAT_W_SMESHDS_Mesh::SetFileId(FILE * aFileId)
66 void DriverDAT_W_SMESHDS_Mesh::SetMeshId(int aMeshId)
71 void DriverDAT_W_SMESHDS_Mesh::Write()
74 string myClass = string("SMDS_Mesh");
75 string myExtension = string("DAT");
77 DriverDAT_W_SMDS_Mesh *myWriter = new DriverDAT_W_SMDS_Mesh;
79 myWriter->SetMesh(myMesh);
80 myWriter->SetFile(myFile);
81 myWriter->SetMeshId(myMeshId);
82 //myWriter->SetFileId(myFileId);
88 void DriverDAT_W_SMESHDS_Mesh::Add()
93 char *file2Read = (char *)myFile.c_str();
94 myFileId = fopen(file2Read, "w+");
97 fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
101 /****************************************************************************
103 ****************************************************************************/
104 fprintf(stdout, "\n(****************************)\n");
105 fprintf(stdout, "(* INFORMATIONS GENERALES : *)\n");
106 fprintf(stdout, "(****************************)\n");
108 /* Combien de noeuds ? */
109 nbNodes = myMesh->NbNodes();
111 /* Combien de mailles, faces ou aretes ? */
112 int nb_of_nodes, nb_of_edges, nb_of_faces, nb_of_volumes;
113 nb_of_edges = myMesh->NbEdges();
114 nb_of_faces = myMesh->NbFaces();
115 nb_of_volumes = myMesh->NbVolumes();
116 nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
118 fprintf(stdout, "%d %d\n", nbNodes, nbCells);
119 fprintf(myFileId, "%d %d\n", nbNodes, nbCells);
121 /****************************************************************************
122 * ECRITURE DES NOEUDS *
123 ****************************************************************************/
124 fprintf(stdout, "\n(************************)\n");
125 fprintf(stdout, "(* NOEUDS DU MAILLAGE : *)\n");
126 fprintf(stdout, "(************************)\n");
128 SMDS_NodeIteratorPtr itNodes=myMesh->nodesIterator();
129 while(itNodes->more())
131 const SMDS_MeshNode * node = itNodes->next();
132 fprintf(myFileId, "%d %e %e %e\n", node->GetID(), node->X(),
133 node->Y(), node->Z());
136 /****************************************************************************
137 * ECRITURE DES ELEMENTS *
138 ****************************************************************************/
139 fprintf(stdout, "\n(**************************)\n");
140 fprintf(stdout, "(* ELEMENTS DU MAILLAGE : *)\n");
141 fprintf(stdout, "(**************************)");
142 /* Ecriture des connectivites, noms, numeros des mailles */
144 SMDS_EdgeIteratorPtr itEdges=myMesh->edgesIterator();
145 while(itEdges->more())
147 const SMDS_MeshEdge * elem = itEdges->next();
149 switch (elem->NbNodes())
153 fprintf(myFileId, "%d %d ", elem->GetID(), 102);
158 fprintf(myFileId, "%d %d ", elem->GetID(), 103);
163 SMDS_ElemIteratorPtr itNodes=elem->nodesIterator();
164 while(itNodes->more())
165 fprintf(myFileId, "%d ", itNodes->next()->GetID());
167 fprintf(myFileId, "\n");
170 SMDS_FaceIteratorPtr itFaces=myMesh->facesIterator();
171 while(itFaces->more())
173 const SMDS_MeshElement * elem = itFaces->next();
175 switch (elem->NbNodes())
179 fprintf(myFileId, "%d %d ", elem->GetID(), 203);
184 fprintf(myFileId, "%d %d ", elem->GetID(), 204);
189 fprintf(myFileId, "%d %d ", elem->GetID(), 206);
194 SMDS_ElemIteratorPtr itNodes=elem->nodesIterator();
195 while(itNodes->more())
196 fprintf(myFileId, "%d ", itNodes->next()->GetID());
198 fprintf(myFileId, "\n");
201 SMDS_VolumeIteratorPtr itVolumes=myMesh->volumesIterator();
202 while(itVolumes->more())
204 const SMDS_MeshElement * elem = itVolumes->next();
206 switch (elem->NbNodes())
210 fprintf(myFileId, "%d %d ", elem->GetID(), 308);
215 SMDS_ElemIteratorPtr itNodes=elem->nodesIterator();
216 while(itNodes->more())
217 fprintf(myFileId, "%d ", itNodes->next()->GetID());
219 fprintf(myFileId, "\n");