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_SMESHDS_Mesh.cxx
28 #include "DriverUNV_W_SMESHDS_Mesh.h"
29 #include "DriverUNV_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 #define sNODE_UNV_ID " 2411"
41 #define sELT_UNV_ID " 2412"
42 #define sUNV_SEPARATOR " -1"
43 #define sNODE_UNV_DESCR "%10d 1 1 11\n"
44 #define sELT_SURF_DESC "%10d %2d 1 1 11 %1d\n"
45 #define sELT_VOLU_DESC "%10d %2d 1 1 9 %1d\n"
46 #define sELT_BEAM_DESC1 "%10d %2d 1 1 7 %1d\n"
47 #define sELT_BEAM_DESC2 " 0 1 1\n"
49 DriverUNV_W_SMESHDS_Mesh::DriverUNV_W_SMESHDS_Mesh() {
53 DriverUNV_W_SMESHDS_Mesh::~DriverUNV_W_SMESHDS_Mesh() {
57 void DriverUNV_W_SMESHDS_Mesh::SetMesh(Handle(SMDS_Mesh)& aMesh) {
58 //myMesh = Handle(SMESHDS_Mesh)::DownCast(aMesh);
62 void DriverUNV_W_SMESHDS_Mesh::SetFile(string aFile) {
66 void DriverUNV_W_SMESHDS_Mesh::SetFileId(FILE* aFileId) {
70 void DriverUNV_W_SMESHDS_Mesh::SetMeshId(int aMeshId) {
74 void DriverUNV_W_SMESHDS_Mesh::Write() {
76 string myClass = string("SMDS_Mesh");
77 string myExtension = string("UNV");
79 DriverUNV_W_SMDS_Mesh* myWriter = new DriverUNV_W_SMDS_Mesh;
81 myWriter->SetMesh(myMesh);
82 myWriter->SetFile(myFile);
83 myWriter->SetMeshId(myMeshId);
84 //myWriter->SetFileId(myFileId);
90 void DriverUNV_W_SMESHDS_Mesh::Add() {
94 char* file2Read = (char*)myFile.c_str();
95 myFileId = fopen(file2Read,"w+");
98 fprintf(stderr,">> ERREUR : ouverture du fichier %s \n",file2Read);
102 /****************************************************************************
104 ****************************************************************************/
105 fprintf(stdout,"\n(****************************)\n");
106 fprintf(stdout,"(* INFORMATIONS GENERALES : *)\n");
107 fprintf(stdout,"(****************************)\n");
109 /* Combien de noeuds ? */
110 nbNodes = myMesh->NbNodes();
112 /* Combien de mailles, faces ou aretes ? */
113 Standard_Integer nb_of_nodes, nb_of_edges,nb_of_faces, nb_of_volumes;
114 nb_of_edges = myMesh->NbEdges();
115 nb_of_faces = myMesh->NbFaces();
116 nb_of_volumes = myMesh->NbVolumes();
117 nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
119 fprintf(stdout,"%d %d\n",nbNodes,nbCells);
120 //fprintf(myFileId,"%d %d\n",nbNodes,nbCells);
122 /****************************************************************************
123 * ECRITURE DES NOEUDS *
124 ****************************************************************************/
125 fprintf(stdout,"\n(************************)\n");
126 fprintf(stdout,"(* NOEUDS DU MAILLAGE : *)\n");
127 fprintf(stdout,"(************************)\n");
129 SMDS_MeshNodesIterator itNodes(myMesh);
131 fprintf(myFileId,"%s\n", sUNV_SEPARATOR);
132 fprintf(myFileId,"%s\n", sNODE_UNV_ID );
134 for (;itNodes.More();itNodes.Next()) {
135 const Handle(SMDS_MeshElement)& elem = itNodes.Value();
136 const Handle(SMDS_MeshNode )& node = myMesh->GetNode(1, elem);
138 fprintf(myFileId, sNODE_UNV_DESCR, node->GetID());
139 fprintf(myFileId, "%25.16E%25.16E%25.16E\n", node->X(), node->Y(), node->Z());
141 fprintf(myFileId,"%s\n", sUNV_SEPARATOR);
143 /****************************************************************************
144 * ECRITURE DES ELEMENTS *
145 ****************************************************************************/
146 fprintf(stdout,"\n(**************************)\n");
147 fprintf(stdout,"(* ELEMENTS DU MAILLAGE : *)\n");
148 fprintf(stdout,"(**************************)");
149 /* Ecriture des connectivites, noms, numeros des mailles */
151 fprintf(myFileId,"%s\n", sUNV_SEPARATOR);
152 fprintf(myFileId,"%s\n", sELT_UNV_ID );
154 SMDS_MeshEdgesIterator itEdges(myMesh);
155 for (;itEdges.More();itEdges.Next()) {
156 const Handle(SMDS_MeshElement)& elem = itEdges.Value();
158 switch (elem->NbNodes()) {
160 fprintf(myFileId, sELT_BEAM_DESC1, elem->GetID(), 21, elem->NbNodes());
161 fprintf(myFileId, sELT_BEAM_DESC2);
162 fprintf(myFileId, "%10d%10d\n", elem->GetConnection(1), elem->GetConnection(2));
166 fprintf(myFileId, sELT_BEAM_DESC1, elem->GetID(), 24, elem->NbNodes());
167 fprintf(myFileId, sELT_BEAM_DESC2);
168 fprintf(myFileId, "%10d%10d%10d\n",elem->GetConnection(1), elem->GetConnection(2), elem->GetConnection(3));
174 SMDS_MeshFacesIterator itFaces(myMesh);
175 for (;itFaces.More();itFaces.Next()) {
176 const Handle(SMDS_MeshElement)& elem = itFaces.Value();
178 switch (elem->NbNodes()) {
181 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 74, elem->NbNodes());
184 // linear quadrilateral
185 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 71, elem->NbNodes());
188 // parabolic triangle
189 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 72, elem->NbNodes());
192 // parabolic quadrilateral
193 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 75, elem->NbNodes());
196 fprintf(myFileId, "element not registered\n");
199 for (i=0;i<elem->NbNodes();i++)
200 fprintf(myFileId,"%10d",elem->GetConnection(i+1));
202 fprintf(myFileId,"\n");
205 SMDS_MeshVolumesIterator itVolumes(myMesh);
206 for (;itVolumes.More();itVolumes.Next()) {
207 const Handle(SMDS_MeshElement)& elem = itVolumes.Value();
209 switch (elem->NbNodes()) {
211 // linear tetrahedron
212 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 111, elem->NbNodes());
215 // linear tetrahedron
216 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 112, elem->NbNodes());
220 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 115, elem->NbNodes());
224 for (i=0;i<elem->NbNodes();i++)
225 fprintf(myFileId,"%10d",elem->GetConnection(i+1));
227 fprintf(myFileId,"\n");
229 fprintf(myFileId,"%s\n", sUNV_SEPARATOR);