Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/smesh.git] / src / DriverUNV / DriverUNV_R_SMDS_Mesh.cxx
1 using namespace std;
2 #include "DriverUNV_R_SMDS_Mesh.h"
3
4 #include "utilities.h"
5
6 DriverUNV_R_SMDS_Mesh::DriverUNV_R_SMDS_Mesh() {
7 ;
8 }
9
10 DriverUNV_R_SMDS_Mesh::~DriverUNV_R_SMDS_Mesh() {
11 ;
12 }
13
14 void DriverUNV_R_SMDS_Mesh::SetMesh(Handle(SMDS_Mesh)& aMesh) {
15   myMesh = aMesh;
16 }
17
18 void DriverUNV_R_SMDS_Mesh::SetFile(string aFile) {
19   myFile = aFile;
20 }
21
22 void DriverUNV_R_SMDS_Mesh::SetFileId(FILE* aFileId) {
23   myFileId = aFileId;
24 }
25
26 void DriverUNV_R_SMDS_Mesh::SetMeshId(int aMeshId) {
27   myMeshId = aMeshId;
28 }
29
30 void DriverUNV_R_SMDS_Mesh::Add() {
31   ;
32 }
33
34 void DriverUNV_R_SMDS_Mesh::Read() {
35
36   int cell=0,node=0,n1,n2,n3,n4,n_nodes,nodes[6],blockId,i;
37   char *s1,*s2,*s3;
38   string str1,str2,str3;
39   int i1=0;
40   bool ok, found_block2411, found_block2412;
41
42   /****************************************************************************
43   *                      OUVERTURE DU FICHIER EN LECTURE                      *
44   ****************************************************************************/
45   char* file2Read = (char*)myFile.c_str();
46   myFileId = fopen(file2Read,"r");
47   if (myFileId < 0)
48     {
49       fprintf(stderr,">> ERREUR : ouverture du fichier %s \n",file2Read);
50       exit(EXIT_FAILURE);
51     }
52
53   s1 = (char*) malloc(sizeof(char)*100);
54   s2 = (char*) malloc(sizeof(char)*100);
55   s3 = (char*) malloc(sizeof(char)*100);
56
57   found_block2411 = false;
58   found_block2412 = false;
59
60   do {
61
62     while (i1==-1) {
63       fscanf(myFileId,"%d\n",&blockId);
64       switch (blockId) {
65       case 2411 : {
66       MESSAGE("BlockId "<<blockId);
67         fscanf(myFileId,"%d",&node);
68         //MESSAGE("Node "<<node);
69         while (node!=-1) {
70           fscanf(myFileId,"%d %d %d\n",&n1,&n2,&n3);
71           fscanf(myFileId,"%s %s %s\n",s1,s2,s3);
72           str1=string(s1);
73           str2=string(s2);
74           str3=string(s3);
75           if (str1.find("D")!=string::npos) str1.replace(str1.find("D"),1,"E");
76           if (str2.find("D")!=string::npos) str2.replace(str2.find("D"),1,"E");
77           if (str3.find("D")!=string::npos) str3.replace(str3.find("D"),1,"E");
78           ok = myMesh->AddNodeWithID(atof(str1.c_str()),atof(str2.c_str()),atof(str3.c_str()),node);
79           fscanf(myFileId,"%d",&node);
80         }
81         i1=0;
82         found_block2411 = true;
83         break;
84       } 
85       case 2412 : {
86       MESSAGE("BlockId "<<blockId);
87         fscanf(myFileId,"%d",&cell);
88         //MESSAGE("Cell "<<cell);
89         while (cell!=-1) {
90           fscanf(myFileId,"%d %d %d %d %d\n",&n1,&n2,&n3,&n4,&n_nodes);
91
92           if ((n1==71)||(n1==72)||(n1==74)||(n1==91)||(n1==92)) {//203
93             if (n_nodes==3) {
94               for (i=1;i<=n_nodes;i++)
95                 fscanf(myFileId,"%d",&nodes[i-1]);
96               ok = myMesh->AddFaceWithID(nodes[0],nodes[1],nodes[2],cell);
97             }
98             else if (n_nodes==6) {//206
99               for (i=1;i<=n_nodes;i++)
100                 fscanf(myFileId,"%d",&nodes[i-1]);
101               ok = myMesh->AddFaceWithID(nodes[0],nodes[2],nodes[4],cell);
102             }
103           }
104
105           else if ((n1==11)||(n1==21)||(n1==24)||(n1==25)) {//103
106             fgets(s2,100,myFileId);
107             if (n_nodes==3) {
108               for (i=1;i<=n_nodes;i++)
109                 fscanf(myFileId,"%d",&nodes[i-1]);
110               ok = myMesh->AddEdgeWithID(nodes[0],nodes[1],cell);
111               //MESSAGE("in 103 "<<cell);
112             }
113             else if (n_nodes==2) {//102
114               for (i=1;i<=n_nodes;i++)
115                 fscanf(myFileId,"%d",&nodes[i-1]);
116               ok = myMesh->AddEdgeWithID(nodes[0],nodes[1],cell);
117               //MESSAGE("in 102 "<<cell);
118             }
119           }
120
121           fscanf(myFileId,"\n");
122           fscanf(myFileId,"%d",&cell);
123         }
124
125         i1=0;
126         found_block2412 = true;
127         break;
128       }
129       case -1 : {
130         break;
131       }
132       default:
133         MESSAGE("BlockId "<<blockId);
134         i1=0;
135         break;
136       }
137     }
138   
139     fscanf(myFileId,"%s\n",s1);
140     i1 = atoi(s1);
141
142   }
143   while ((!feof(myFileId))&&((!found_block2411)||(!found_block2412)));
144
145   /****************************************************************************
146   *                      FERMETURE DU FICHIER                      *
147   ****************************************************************************/
148   free(s1);
149   free(s2);
150   free(s3);
151   fclose(myFileId);
152
153 }