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"
32 #include "SMDS_MeshEdgesIterator.hxx"
33 #include "SMDS_MeshFacesIterator.hxx"
34 #include "SMDS_MeshNodesIterator.hxx"
35 #include "SMDS_MeshVolumesIterator.hxx"
37 #include "utilities.h"
39 DriverDAT_W_SMDS_Mesh::DriverDAT_W_SMDS_Mesh() {
43 DriverDAT_W_SMDS_Mesh::~DriverDAT_W_SMDS_Mesh() {
47 void DriverDAT_W_SMDS_Mesh::SetMesh(Handle(SMDS_Mesh)& aMesh) {
51 void DriverDAT_W_SMDS_Mesh::SetFile(string aFile) {
55 void DriverDAT_W_SMDS_Mesh::SetFileId(FILE* aFileId) {
59 void DriverDAT_W_SMDS_Mesh::SetMeshId(int aMeshId) {
63 void DriverDAT_W_SMDS_Mesh::Add() {
67 void DriverDAT_W_SMDS_Mesh::Write() {
72 char* file2Read = (char*)myFile.c_str();
73 myFileId = fopen(file2Read,"w+");
76 fprintf(stderr,">> ERREUR : ouverture du fichier %s \n",file2Read);
80 /****************************************************************************
82 ****************************************************************************/
83 fprintf(stdout,"\n(****************************)\n");
84 fprintf(stdout,"(* INFORMATIONS GENERALES : *)\n");
85 fprintf(stdout,"(****************************)\n");
87 /* Combien de noeuds ? */
88 nbNodes = myMesh->NbNodes();
90 /* Combien de mailles, faces ou aretes ? */
91 Standard_Integer nb_of_nodes, nb_of_edges,nb_of_faces, nb_of_volumes;
92 nb_of_edges = myMesh->NbEdges();
93 nb_of_faces = myMesh->NbFaces();
94 nb_of_volumes = myMesh->NbVolumes();
95 nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
98 SCRUTE(nb_of_volumes);
100 fprintf(stdout,"%d %d\n",nbNodes,nbCells);
101 fprintf(myFileId,"%d %d\n",nbNodes,nbCells);
103 /****************************************************************************
104 * ECRITURE DES NOEUDS *
105 ****************************************************************************/
106 fprintf(stdout,"\n(************************)\n");
107 fprintf(stdout,"(* NOEUDS DU MAILLAGE : *)\n");
108 fprintf(stdout,"(************************)\n");
110 SMDS_MeshNodesIterator itNodes(myMesh);
111 for (;itNodes.More();itNodes.Next()) {
112 const Handle(SMDS_MeshElement)& elem = itNodes.Value();
113 const Handle(SMDS_MeshNode)& node = myMesh->GetNode(1,elem);
115 fprintf(myFileId,"%d %e %e %e\n",node->GetID(),node->X(),node->Y(),node->Z());
118 /****************************************************************************
119 * ECRITURE DES ELEMENTS *
120 ****************************************************************************/
121 fprintf(stdout,"\n(**************************)\n");
122 fprintf(stdout,"(* ELEMENTS DU MAILLAGE : *)\n");
123 fprintf(stdout,"(**************************)");
124 /* Ecriture des connectivites, noms, numeros des mailles */
126 SMDS_MeshEdgesIterator itEdges(myMesh);
127 for (;itEdges.More();itEdges.Next()) {
128 const Handle(SMDS_MeshElement)& elem = itEdges.Value();
130 switch (elem->NbNodes()) {
132 fprintf(myFileId,"%d %d ",elem->GetID(),102);
136 fprintf(myFileId,"%d %d ",elem->GetID(),103);
141 for (i=0;i<elem->NbNodes();i++)
142 fprintf(myFileId,"%d ",elem->GetConnection(i+1));
144 fprintf(myFileId,"\n");
147 SMDS_MeshFacesIterator itFaces(myMesh);
148 for (;itFaces.More();itFaces.Next()) {
149 const Handle(SMDS_MeshElement)& elem = itFaces.Value();
151 switch (elem->NbNodes()) {
153 fprintf(myFileId,"%d %d ",elem->GetID(),203);
157 fprintf(myFileId,"%d %d ",elem->GetID(),204);
161 fprintf(myFileId,"%d %d ",elem->GetID(),206);
166 for (i=0;i<elem->NbNodes();i++)
167 fprintf(myFileId,"%d ",elem->GetConnection(i+1));
169 fprintf(myFileId,"\n");
172 SMDS_MeshVolumesIterator itVolumes(myMesh);
173 for (;itVolumes.More();itVolumes.Next()) {
174 const Handle(SMDS_MeshElement)& elem = itVolumes.Value();
176 switch (elem->NbNodes()) {
178 fprintf(myFileId,"%d %d ",elem->GetID(),308);
183 for (i=0;i<elem->NbNodes();i++)
184 fprintf(myFileId,"%d ",elem->GetConnection(i+1));
186 fprintf(myFileId,"\n");