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_R_SMDS_Mesh.cxx
28 #include "DriverUNV_R_SMDS_Mesh.h"
30 #include "utilities.h"
32 DriverUNV_R_SMDS_Mesh::DriverUNV_R_SMDS_Mesh() {
36 DriverUNV_R_SMDS_Mesh::~DriverUNV_R_SMDS_Mesh() {
40 void DriverUNV_R_SMDS_Mesh::SetMesh(Handle(SMDS_Mesh)& aMesh) {
44 void DriverUNV_R_SMDS_Mesh::SetFile(string aFile) {
48 void DriverUNV_R_SMDS_Mesh::SetFileId(FILE* aFileId) {
52 void DriverUNV_R_SMDS_Mesh::SetMeshId(int aMeshId) {
56 void DriverUNV_R_SMDS_Mesh::Add() {
60 void DriverUNV_R_SMDS_Mesh::Read() {
62 int cell=0,node=0,n1,n2,n3,n4,n_nodes,nodes[6],blockId,i;
64 string str1,str2,str3;
66 bool ok, found_block2411, found_block2412;
68 /****************************************************************************
69 * OUVERTURE DU FICHIER EN LECTURE *
70 ****************************************************************************/
71 char* file2Read = (char*)myFile.c_str();
72 myFileId = fopen(file2Read,"r");
75 fprintf(stderr,">> ERREUR : ouverture du fichier %s \n",file2Read);
79 s1 = (char*) malloc(sizeof(char)*100);
80 s2 = (char*) malloc(sizeof(char)*100);
81 s3 = (char*) malloc(sizeof(char)*100);
83 found_block2411 = false;
84 found_block2412 = false;
89 fscanf(myFileId,"%d\n",&blockId);
92 MESSAGE("BlockId "<<blockId);
93 fscanf(myFileId,"%d",&node);
94 //MESSAGE("Node "<<node);
96 fscanf(myFileId,"%d %d %d\n",&n1,&n2,&n3);
97 fscanf(myFileId,"%s %s %s\n",s1,s2,s3);
101 if (str1.find("D")!=string::npos) str1.replace(str1.find("D"),1,"E");
102 if (str2.find("D")!=string::npos) str2.replace(str2.find("D"),1,"E");
103 if (str3.find("D")!=string::npos) str3.replace(str3.find("D"),1,"E");
104 ok = myMesh->AddNodeWithID(atof(str1.c_str()),atof(str2.c_str()),atof(str3.c_str()),node);
105 fscanf(myFileId,"%d",&node);
108 found_block2411 = true;
112 MESSAGE("BlockId "<<blockId);
113 fscanf(myFileId,"%d",&cell);
114 //MESSAGE("Cell "<<cell);
116 fscanf(myFileId,"%d %d %d %d %d\n",&n1,&n2,&n3,&n4,&n_nodes);
118 if ((n1==71)||(n1==72)||(n1==74)||(n1==91)||(n1==92)) {//203
120 for (i=1;i<=n_nodes;i++)
121 fscanf(myFileId,"%d",&nodes[i-1]);
122 ok = myMesh->AddFaceWithID(nodes[0],nodes[1],nodes[2],cell);
124 else if (n_nodes==6) {//206
125 for (i=1;i<=n_nodes;i++)
126 fscanf(myFileId,"%d",&nodes[i-1]);
127 ok = myMesh->AddFaceWithID(nodes[0],nodes[2],nodes[4],cell);
131 else if ((n1==11)||(n1==21)||(n1==24)||(n1==25)) {//103
132 fgets(s2,100,myFileId);
134 for (i=1;i<=n_nodes;i++)
135 fscanf(myFileId,"%d",&nodes[i-1]);
136 ok = myMesh->AddEdgeWithID(nodes[0],nodes[1],cell);
137 //MESSAGE("in 103 "<<cell);
139 else if (n_nodes==2) {//102
140 for (i=1;i<=n_nodes;i++)
141 fscanf(myFileId,"%d",&nodes[i-1]);
142 ok = myMesh->AddEdgeWithID(nodes[0],nodes[1],cell);
143 //MESSAGE("in 102 "<<cell);
147 fscanf(myFileId,"\n");
148 fscanf(myFileId,"%d",&cell);
152 found_block2412 = true;
159 MESSAGE("BlockId "<<blockId);
165 fscanf(myFileId,"%s\n",s1);
169 while ((!feof(myFileId))&&((!found_block2411)||(!found_block2412)));
171 /****************************************************************************
172 * FERMETURE DU FICHIER *
173 ****************************************************************************/