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"
33 #include "SMDS_MeshEdgesIterator.hxx"
34 #include "SMDS_MeshFacesIterator.hxx"
35 #include "SMDS_MeshNodesIterator.hxx"
36 #include "SMDS_MeshVolumesIterator.hxx"
38 #include "utilities.h"
40 DriverDAT_W_SMESHDS_Mesh::DriverDAT_W_SMESHDS_Mesh() {
44 DriverDAT_W_SMESHDS_Mesh::~DriverDAT_W_SMESHDS_Mesh() {
48 void DriverDAT_W_SMESHDS_Mesh::SetMesh(Handle(SMDS_Mesh)& aMesh) {
49 //myMesh = Handle(SMESHDS_Mesh)::DownCast(aMesh);
53 void DriverDAT_W_SMESHDS_Mesh::SetFile(string aFile) {
57 void DriverDAT_W_SMESHDS_Mesh::SetFileId(FILE* aFileId) {
61 void DriverDAT_W_SMESHDS_Mesh::SetMeshId(int aMeshId) {
65 void DriverDAT_W_SMESHDS_Mesh::Write() {
67 string myClass = string("SMDS_Mesh");
68 string myExtension = string("DAT");
70 DriverDAT_W_SMDS_Mesh* myWriter = new DriverDAT_W_SMDS_Mesh;
72 myWriter->SetMesh(myMesh);
73 myWriter->SetFile(myFile);
74 myWriter->SetMeshId(myMeshId);
75 //myWriter->SetFileId(myFileId);
81 void DriverDAT_W_SMESHDS_Mesh::Add() {
85 char* file2Read = (char*)myFile.c_str();
86 myFileId = fopen(file2Read,"w+");
89 fprintf(stderr,">> ERREUR : ouverture du fichier %s \n",file2Read);
93 /****************************************************************************
95 ****************************************************************************/
96 fprintf(stdout,"\n(****************************)\n");
97 fprintf(stdout,"(* INFORMATIONS GENERALES : *)\n");
98 fprintf(stdout,"(****************************)\n");
100 /* Combien de noeuds ? */
101 nbNodes = myMesh->NbNodes();
103 /* Combien de mailles, faces ou aretes ? */
104 Standard_Integer nb_of_nodes, nb_of_edges,nb_of_faces, nb_of_volumes;
105 nb_of_edges = myMesh->NbEdges();
106 nb_of_faces = myMesh->NbFaces();
107 nb_of_volumes = myMesh->NbVolumes();
108 nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
110 fprintf(stdout,"%d %d\n",nbNodes,nbCells);
111 fprintf(myFileId,"%d %d\n",nbNodes,nbCells);
113 /****************************************************************************
114 * ECRITURE DES NOEUDS *
115 ****************************************************************************/
116 fprintf(stdout,"\n(************************)\n");
117 fprintf(stdout,"(* NOEUDS DU MAILLAGE : *)\n");
118 fprintf(stdout,"(************************)\n");
120 SMDS_MeshNodesIterator itNodes(myMesh);
121 for (;itNodes.More();itNodes.Next()) {
122 const Handle(SMDS_MeshElement)& elem = itNodes.Value();
123 const Handle(SMDS_MeshNode)& node = myMesh->GetNode(1,elem);
125 fprintf(myFileId,"%d %e %e %e\n",node->GetID(),node->X(),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_MeshEdgesIterator itEdges(myMesh);
137 for (;itEdges.More();itEdges.Next()) {
138 const Handle(SMDS_MeshElement)& elem = itEdges.Value();
140 switch (elem->NbNodes()) {
142 fprintf(myFileId,"%d %d ",elem->GetID(),102);
146 fprintf(myFileId,"%d %d ",elem->GetID(),103);
151 for (i=0;i<elem->NbNodes();i++)
152 fprintf(myFileId,"%d ",elem->GetConnection(i+1));
154 fprintf(myFileId,"\n");
157 SMDS_MeshFacesIterator itFaces(myMesh);
158 for (;itFaces.More();itFaces.Next()) {
159 const Handle(SMDS_MeshElement)& elem = itFaces.Value();
161 switch (elem->NbNodes()) {
163 fprintf(myFileId,"%d %d ",elem->GetID(),203);
167 fprintf(myFileId,"%d %d ",elem->GetID(),204);
171 fprintf(myFileId,"%d %d ",elem->GetID(),206);
176 for (i=0;i<elem->NbNodes();i++)
177 fprintf(myFileId,"%d ",elem->GetConnection(i+1));
179 fprintf(myFileId,"\n");
182 SMDS_MeshVolumesIterator itVolumes(myMesh);
183 for (;itVolumes.More();itVolumes.Next()) {
184 const Handle(SMDS_MeshElement)& elem = itVolumes.Value();
186 switch (elem->NbNodes()) {
188 fprintf(myFileId,"%d %d ",elem->GetID(),308);
193 for (i=0;i<elem->NbNodes();i++)
194 fprintf(myFileId,"%d ",elem->GetConnection(i+1));
196 fprintf(myFileId,"\n");