Salome HOME
Add support for tetra, pyramid and prism
[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
11 DriverUNV_R_SMDS_Mesh::~DriverUNV_R_SMDS_Mesh()
12 {
13         ;
14 }
15
16 void DriverUNV_R_SMDS_Mesh::SetMesh(SMDS_Mesh * aMesh)
17 {
18         myMesh = aMesh;
19 }
20
21 void DriverUNV_R_SMDS_Mesh::SetFile(string aFile)
22 {
23         myFile = aFile;
24 }
25
26 void DriverUNV_R_SMDS_Mesh::SetFileId(FILE * aFileId)
27 {
28         myFileId = aFileId;
29 }
30
31 void DriverUNV_R_SMDS_Mesh::SetMeshId(int aMeshId)
32 {
33         myMeshId = aMeshId;
34 }
35
36 void DriverUNV_R_SMDS_Mesh::Add()
37 {
38         ;
39 }
40
41 void DriverUNV_R_SMDS_Mesh::Read()
42 {
43
44         int cell = 0, node = 0, n1, n2, n3, n4, n_nodes, nodes[6], blockId, i;
45         char *s1, *s2, *s3;
46         string str1, str2, str3;
47         int i1 = 0;
48         bool ok, found_block2411, found_block2412;
49
50   /****************************************************************************
51   *                      OUVERTURE DU FICHIER EN LECTURE                      *
52   ****************************************************************************/
53         char *file2Read = (char *)myFile.c_str();
54         myFileId = fopen(file2Read, "r");
55         if (myFileId < 0)
56         {
57                 fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
58                 exit(EXIT_FAILURE);
59         }
60
61         s1 = (char *)malloc(sizeof(char) * 100);
62         s2 = (char *)malloc(sizeof(char) * 100);
63         s3 = (char *)malloc(sizeof(char) * 100);
64
65         found_block2411 = false;
66         found_block2412 = false;
67
68         do
69         {
70
71                 while (i1 == -1)
72                 {
73                         fscanf(myFileId, "%d\n", &blockId);
74                         switch (blockId)
75                         {
76                         case 2411:
77                         {
78                                 MESSAGE("BlockId " << blockId);
79                                 fscanf(myFileId, "%d", &node);
80                                 //MESSAGE("Node "<<node);
81                                 while (node != -1)
82                                 {
83                                         fscanf(myFileId, "%d %d %d\n", &n1, &n2, &n3);
84                                         fscanf(myFileId, "%s %s %s\n", s1, s2, s3);
85                                         str1 = string(s1);
86                                         str2 = string(s2);
87                                         str3 = string(s3);
88                                         if (str1.find("D") != string::npos)
89                                                 str1.replace(str1.find("D"), 1, "E");
90                                         if (str2.find("D") != string::npos)
91                                                 str2.replace(str2.find("D"), 1, "E");
92                                         if (str3.find("D") != string::npos)
93                                                 str3.replace(str3.find("D"), 1, "E");
94                                         ok = myMesh->AddNodeWithID(atof(str1.c_str()),
95                                                 atof(str2.c_str()), atof(str3.c_str()), node);
96                                         fscanf(myFileId, "%d", &node);
97                                 }
98                                 i1 = 0;
99                                 found_block2411 = true;
100                                 break;
101                         }
102                         case 2412:
103                         {
104                                 MESSAGE("BlockId " << blockId);
105                                 fscanf(myFileId, "%d", &cell);
106                                 //MESSAGE("Cell "<<cell);
107                                 while (cell != -1)
108                                 {
109                                         fscanf(myFileId, "%d %d %d %d %d\n", &n1, &n2, &n3, &n4,
110                                                 &n_nodes);
111
112                                         if ((n1 == 71) || (n1 == 72) || (n1 == 74) || (n1 == 91) ||
113                                                 (n1 == 92))
114                                         {                       //203
115                                                 if (n_nodes == 3)
116                                                 {
117                                                         for (i = 1; i <= n_nodes; i++)
118                                                                 fscanf(myFileId, "%d", &nodes[i - 1]);
119                                                         ok = myMesh->AddFaceWithID(nodes[0], nodes[1],
120                                                                 nodes[2], cell);
121                                                 }
122                                                 else if (n_nodes == 6)
123                                                 {               //206
124                                                         for (i = 1; i <= n_nodes; i++)
125                                                                 fscanf(myFileId, "%d", &nodes[i - 1]);
126                                                         ok = myMesh->AddFaceWithID(nodes[0], nodes[2],
127                                                                 nodes[4], cell);
128                                                 }
129                                         }
130
131                                         else if ((n1 == 11) || (n1 == 21) || (n1 == 24) ||
132                                                 (n1 == 25))
133                                         {                       //103
134                                                 fgets(s2, 100, myFileId);
135                                                 if (n_nodes == 3)
136                                                 {
137                                                         for (i = 1; i <= n_nodes; i++)
138                                                                 fscanf(myFileId, "%d", &nodes[i - 1]);
139                                                         ok = myMesh->AddEdgeWithID(nodes[0], nodes[1],
140                                                                 cell);
141                                                         //MESSAGE("in 103 "<<cell);
142                                                 }
143                                                 else if (n_nodes == 2)
144                                                 {               //102
145                                                         for (i = 1; i <= n_nodes; i++)
146                                                                 fscanf(myFileId, "%d", &nodes[i - 1]);
147                                                         ok = myMesh->AddEdgeWithID(nodes[0], nodes[1],
148                                                                 cell);
149                                                         //MESSAGE("in 102 "<<cell);
150                                                 }
151                                         }
152
153                                         fscanf(myFileId, "\n");
154                                         fscanf(myFileId, "%d", &cell);
155                                 }
156
157                                 i1 = 0;
158                                 found_block2412 = true;
159                                 break;
160                         }
161                         case -1:
162                         {
163                                 break;
164                         }
165                         default:
166                                 MESSAGE("BlockId " << blockId);
167                                 i1 = 0;
168                                 break;
169                         }
170                 }
171
172                 fscanf(myFileId, "%s\n", s1);
173                 i1 = atoi(s1);
174
175         }
176         while ((!feof(myFileId)) && ((!found_block2411) || (!found_block2412)));
177
178   /****************************************************************************
179   *                      FERMETURE DU FICHIER                      *
180   ****************************************************************************/
181         free(s1);
182         free(s2);
183         free(s3);
184         fclose(myFileId);
185
186 }