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_Iterator<const SMDS_MeshNode *> * 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());
137 /****************************************************************************
138 * ECRITURE DES ELEMENTS *
139 ****************************************************************************/
140 fprintf(stdout, "\n(**************************)\n");
141 fprintf(stdout, "(* ELEMENTS DU MAILLAGE : *)\n");
142 fprintf(stdout, "(**************************)");
143 /* Ecriture des connectivites, noms, numeros des mailles */
145 SMDS_Iterator<const SMDS_MeshEdge*> * itEdges=myMesh->edgesIterator();
146 while(itEdges->more())
148 const SMDS_MeshEdge * elem = itEdges->next();
150 switch (elem->NbNodes())
154 fprintf(myFileId, "%d %d ", elem->GetID(), 102);
159 fprintf(myFileId, "%d %d ", elem->GetID(), 103);
164 SMDS_Iterator<const SMDS_MeshElement *> * itNodes=elem->nodesIterator();
165 while(itNodes->more())
166 fprintf(myFileId, "%d ", itNodes->next()->GetID());
168 fprintf(myFileId, "\n");
172 SMDS_Iterator<const SMDS_MeshFace *> * itFaces=myMesh->facesIterator();
173 while(itFaces->more())
175 const SMDS_MeshElement * elem = itFaces->next();
177 switch (elem->NbNodes())
181 fprintf(myFileId, "%d %d ", elem->GetID(), 203);
186 fprintf(myFileId, "%d %d ", elem->GetID(), 204);
191 fprintf(myFileId, "%d %d ", elem->GetID(), 206);
196 SMDS_Iterator<const SMDS_MeshElement *> * itNodes=elem->nodesIterator();
197 while(itNodes->more())
198 fprintf(myFileId, "%d ", itNodes->next()->GetID());
201 fprintf(myFileId, "\n");
205 SMDS_Iterator<const SMDS_MeshVolume*> * itVolumes=myMesh->volumesIterator();
206 while(itVolumes->more())
208 const SMDS_MeshElement * elem = itVolumes->next();
210 switch (elem->NbNodes())
214 fprintf(myFileId, "%d %d ", elem->GetID(), 308);
219 SMDS_Iterator<const SMDS_MeshElement *> * itNodes=elem->nodesIterator();
220 while(itNodes->more())
221 fprintf(myFileId, "%d ", itNodes->next()->GetID());
224 fprintf(myFileId, "\n");