1 // SMESH DriverUNV : driver to read and write 'unv' 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 : DriverUNV_W_SMDS_Mesh.cxx
28 #include "DriverUNV_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 #define sNODE_UNV_ID " 2411"
40 #define sELT_UNV_ID " 2412"
41 #define sUNV_SEPARATOR " -1"
42 #define sNODE_UNV_DESCR "%10d 1 1 11\n"
43 #define sELT_SURF_DESC "%10d %2d 1 1 11 %1d\n"
44 #define sELT_VOLU_DESC "%10d %2d 1 1 9 %1d\n"
45 #define sELT_BEAM_DESC1 "%10d %2d 1 1 7 %1d\n"
46 #define sELT_BEAM_DESC2 " 0 1 1\n"
48 DriverUNV_W_SMDS_Mesh::DriverUNV_W_SMDS_Mesh() {
52 DriverUNV_W_SMDS_Mesh::~DriverUNV_W_SMDS_Mesh() {
56 void DriverUNV_W_SMDS_Mesh::SetMesh(Handle(SMDS_Mesh)& aMesh) {
60 void DriverUNV_W_SMDS_Mesh::SetFile(string aFile) {
64 void DriverUNV_W_SMDS_Mesh::SetFileId(FILE* aFileId) {
68 void DriverUNV_W_SMDS_Mesh::SetMeshId(int aMeshId) {
72 void DriverUNV_W_SMDS_Mesh::Add() {
76 void DriverUNV_W_SMDS_Mesh::Write() {
81 char* file2Read = (char*)myFile.c_str();
82 myFileId = fopen(file2Read,"w+");
85 fprintf(stderr,">> ERREUR : ouverture du fichier %s \n",file2Read);
89 /****************************************************************************
91 ****************************************************************************/
92 fprintf(stdout,"\n(****************************)\n");
93 fprintf(stdout,"(* INFORMATIONS GENERALES : *)\n");
94 fprintf(stdout,"(****************************)\n");
96 /* Combien de noeuds ? */
97 nbNodes = myMesh->NbNodes();
99 /* Combien de mailles, faces ou aretes ? */
100 Standard_Integer nb_of_nodes, nb_of_edges,nb_of_faces, nb_of_volumes;
101 nb_of_edges = myMesh->NbEdges();
102 nb_of_faces = myMesh->NbFaces();
103 nb_of_volumes = myMesh->NbVolumes();
104 nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
107 SCRUTE(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_MeshNodesIterator itNodes(myMesh);
121 fprintf(myFileId,"%s\n", sUNV_SEPARATOR);
122 fprintf(myFileId,"%s\n", sNODE_UNV_ID );
124 for (;itNodes.More();itNodes.Next()) {
125 const Handle(SMDS_MeshElement)& elem = itNodes.Value();
126 const Handle(SMDS_MeshNode )& node = myMesh->GetNode(1, elem);
128 fprintf(myFileId, sNODE_UNV_DESCR, node->GetID());
129 fprintf(myFileId, "%25.16E%25.16E%25.16E\n", node->X(), node->Y(), node->Z());
131 fprintf(myFileId,"%s\n", sUNV_SEPARATOR);
133 /****************************************************************************
134 * ECRITURE DES ELEMENTS *
135 ****************************************************************************/
136 fprintf(stdout,"\n(**************************)\n");
137 fprintf(stdout,"(* ELEMENTS DU MAILLAGE : *)\n");
138 fprintf(stdout,"(**************************)");
139 /* Ecriture des connectivites, noms, numeros des mailles */
141 fprintf(myFileId,"%s\n", sUNV_SEPARATOR);
142 fprintf(myFileId,"%s\n", sELT_UNV_ID );
144 SMDS_MeshEdgesIterator itEdges(myMesh);
145 for (;itEdges.More();itEdges.Next()) {
146 const Handle(SMDS_MeshElement)& elem = itEdges.Value();
148 switch (elem->NbNodes()) {
150 fprintf(myFileId, sELT_BEAM_DESC1, elem->GetID(), 21, elem->NbNodes());
151 fprintf(myFileId, sELT_BEAM_DESC2);
152 fprintf(myFileId, "%10d%10d\n", elem->GetConnection(1), elem->GetConnection(2));
156 fprintf(myFileId, sELT_BEAM_DESC1, elem->GetID(), 24, elem->NbNodes());
157 fprintf(myFileId, sELT_BEAM_DESC2);
158 fprintf(myFileId, "%10d%10d%10d\n",elem->GetConnection(1), elem->GetConnection(2), elem->GetConnection(3));
164 SMDS_MeshFacesIterator itFaces(myMesh);
165 for (;itFaces.More();itFaces.Next()) {
166 const Handle(SMDS_MeshElement)& elem = itFaces.Value();
168 switch (elem->NbNodes()) {
171 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 74, elem->NbNodes());
174 // linear quadrilateral
175 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 71, elem->NbNodes());
178 // parabolic triangle
179 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 72, elem->NbNodes());
182 // parabolic quadrilateral
183 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 75, elem->NbNodes());
186 fprintf(myFileId, "element not registered\n");
189 for (i=0;i<elem->NbNodes();i++)
190 fprintf(myFileId,"%10d",elem->GetConnection(i+1));
192 fprintf(myFileId,"\n");
195 SMDS_MeshVolumesIterator itVolumes(myMesh);
196 for (;itVolumes.More();itVolumes.Next()) {
197 const Handle(SMDS_MeshElement)& elem = itVolumes.Value();
199 switch (elem->NbNodes()) {
201 // linear tetrahedron
202 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 111, elem->NbNodes());
205 // linear tetrahedron
206 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 112, elem->NbNodes());
210 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 115, elem->NbNodes());
214 for (i=0;i<elem->NbNodes();i++)
215 fprintf(myFileId,"%10d",elem->GetConnection(i+1));
217 fprintf(myFileId,"\n");
219 fprintf(myFileId,"%s\n", sUNV_SEPARATOR);