]> SALOME platform Git repositories - modules/smesh.git/blob - src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx
Salome HOME
Bug IPAL21435 - TC5.1.3: incorrect mapping of the object from imported UNV file in...
[modules/smesh.git] / src / DriverUNV / DriverUNV_R_SMDS_Mesh.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "DriverUNV_R_SMDS_Mesh.h"
23 #include "SMDS_Mesh.hxx"
24 #include "SMDS_MeshGroup.hxx"
25
26 #include "utilities.h"
27
28 #include "UNV2411_Structure.hxx"
29 #include "UNV2412_Structure.hxx"
30 #include "UNV2417_Structure.hxx"
31 #include "UNV_Utilities.hxx"
32
33 using namespace std;
34
35
36 #ifdef _DEBUG_
37 static int MYDEBUG = 0;
38 #else
39 static int MYDEBUG = 0;
40 #endif
41
42
43 DriverUNV_R_SMDS_Mesh::~DriverUNV_R_SMDS_Mesh()
44 {
45   if (myGroup != 0) 
46     delete myGroup;
47 }
48
49
50 Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
51 {
52   UNV::Localizer loc;
53   Status aResult = DRS_OK;
54   std::ifstream in_stream(myFile.c_str());
55   try{
56     {
57       using namespace UNV2411;
58       TDataSet aDataSet2411;
59       UNV2411::Read(in_stream,aDataSet2411);
60       if(MYDEBUG) MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
61       TDataSet::const_iterator anIter = aDataSet2411.begin();
62       for(; anIter != aDataSet2411.end(); anIter++){
63         const TNodeLab& aLabel = anIter->first;
64         const TRecord& aRec = anIter->second;
65         myMesh->AddNodeWithID(aRec.coord[0],aRec.coord[1],aRec.coord[2],aLabel);
66       }
67     }
68     {
69       using namespace UNV2412;
70       in_stream.seekg(0);
71       TDataSet aDataSet2412;
72       UNV2412::Read(in_stream,aDataSet2412);
73       TDataSet::const_iterator anIter = aDataSet2412.begin();
74       if(MYDEBUG) MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
75       for(; anIter != aDataSet2412.end(); anIter++){
76         SMDS_MeshElement* anElement = NULL;
77         const TElementLab& aLabel = anIter->first;
78         const TRecord& aRec = anIter->second;
79         if(IsBeam(aRec.fe_descriptor_id)) {
80           switch ( aRec.node_labels.size() ) {
81           case 2: // edge with two nodes
82             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
83                                               aRec.node_labels[1],
84                                               aLabel);
85             break;
86           case 3: // quadratic edge (with 3 nodes)
87             anElement = myMesh->AddEdgeWithID(aRec.node_labels[0],
88                                               aRec.node_labels[2],
89                                               aRec.node_labels[1],
90                                               aLabel);
91           }
92         }
93         else if(IsFace(aRec.fe_descriptor_id)) {
94           switch(aRec.fe_descriptor_id){
95           case 71: // TRI3
96           case 72:
97           case 74:
98             
99           case 41: // Plane Stress Linear Triangle - TRI3
100           case 91: // Thin Shell Linear Triangle - TRI3
101             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
102                                               aRec.node_labels[1],
103                                               aRec.node_labels[2],
104                                               aLabel);
105             break;
106             
107           case 42: // Plane Stress Quadratic Triangle - TRI6
108           case 92: // Thin Shell Quadratic Triangle - TRI6
109             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
110                                               aRec.node_labels[2],
111                                               aRec.node_labels[4],
112                                               aRec.node_labels[1],
113                                               aRec.node_labels[3],
114                                               aRec.node_labels[5],
115                                               aLabel);
116             break;
117             
118           case 44: // Plane Stress Linear Quadrilateral - QUAD4
119           case 94: // Thin Shell   Linear Quadrilateral -  QUAD4
120             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
121                                               aRec.node_labels[1],
122                                               aRec.node_labels[2],
123                                               aRec.node_labels[3],
124                                               aLabel);
125             break;
126             
127           case 45: // Plane Stress Quadratic Quadrilateral - QUAD8
128           case 95: // Thin Shell   Quadratic Quadrilateral - QUAD8
129             anElement = myMesh->AddFaceWithID(aRec.node_labels[0],
130                                               aRec.node_labels[2],
131                                               aRec.node_labels[4],
132                                               aRec.node_labels[6],
133                                               aRec.node_labels[1],
134                                               aRec.node_labels[3],
135                                               aRec.node_labels[5],
136                                               aRec.node_labels[7],
137                                               aLabel);
138             break;
139           }
140         }
141         else if(IsVolume(aRec.fe_descriptor_id)){
142           switch(aRec.fe_descriptor_id){
143             
144           case 111: // Solid Linear Tetrahedron - TET4
145             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
146                                                 aRec.node_labels[2],
147                                                 aRec.node_labels[1],
148                                                 aRec.node_labels[3],
149                                                 aLabel);
150             break;
151
152           case 118: // Solid Quadratic Tetrahedron - TET10
153             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
154                                                 aRec.node_labels[4],
155                                                 aRec.node_labels[2],
156
157                                                 aRec.node_labels[9],
158
159                                                 aRec.node_labels[5],
160                                                 aRec.node_labels[3],
161                                                 aRec.node_labels[1],
162
163                                                 aRec.node_labels[6],
164                                                 aRec.node_labels[8],
165                                                 aRec.node_labels[7],
166                                                 aLabel);
167             break;
168             
169           case 112: // Solid Linear Prism - PRISM6
170             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
171                                                 aRec.node_labels[2],
172                                                 aRec.node_labels[1],
173                                                 aRec.node_labels[3],
174                                                 aRec.node_labels[5],
175                                                 aRec.node_labels[4],
176                                                 aLabel);
177             break;
178             
179           case 113: // Solid Quadratic Prism - PRISM15
180             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
181                                                 aRec.node_labels[4],
182                                                 aRec.node_labels[2],
183
184                                                 aRec.node_labels[9],
185                                                 aRec.node_labels[13],
186                                                 aRec.node_labels[11],
187
188                                                 aRec.node_labels[5],
189                                                 aRec.node_labels[3],
190                                                 aRec.node_labels[1],
191
192                                                 aRec.node_labels[14],
193                                                 aRec.node_labels[12],
194                                                 aRec.node_labels[10],
195
196                                                 aRec.node_labels[6],
197                                                 aRec.node_labels[8],
198                                                 aRec.node_labels[7],
199                                                 aLabel);
200             break;
201             
202           case 115: // Solid Linear Brick - HEX8
203             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
204                                                 aRec.node_labels[3],
205                                                 aRec.node_labels[2],
206                                                 aRec.node_labels[1],
207                                                 aRec.node_labels[4],
208                                                 aRec.node_labels[7],
209                                                 aRec.node_labels[6],
210                                                 aRec.node_labels[5],
211                                                 aLabel);
212             break;
213
214           case 116: // Solid Quadratic Brick - HEX20
215             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
216                                                 aRec.node_labels[6],
217                                                 aRec.node_labels[4],
218                                                 aRec.node_labels[2],
219
220                                                 aRec.node_labels[12],
221                                                 aRec.node_labels[18],
222                                                 aRec.node_labels[16],
223                                                 aRec.node_labels[14],
224
225                                                 aRec.node_labels[7],
226                                                 aRec.node_labels[5],
227                                                 aRec.node_labels[3],
228                                                 aRec.node_labels[1],
229
230                                                 aRec.node_labels[19],
231                                                 aRec.node_labels[17],
232                                                 aRec.node_labels[15],
233                                                 aRec.node_labels[13],
234
235                                                 aRec.node_labels[8],
236                                                 aRec.node_labels[11],
237                                                 aRec.node_labels[10],
238                                                 aRec.node_labels[9],
239                                                 aLabel);
240             break;
241
242           case 114: // pyramid of 13 nodes (quadratic) - PIRA13
243             anElement = myMesh->AddVolumeWithID(aRec.node_labels[0],
244                                                 aRec.node_labels[6],
245                                                 aRec.node_labels[4],
246                                                 aRec.node_labels[2],
247                                                 aRec.node_labels[7],
248                                                 aRec.node_labels[5],
249                                                 aRec.node_labels[3],
250                                                 aRec.node_labels[1],
251
252                                                 aRec.node_labels[8],
253                                                 aRec.node_labels[11],
254                                                 aRec.node_labels[10],
255                                                 aRec.node_labels[9],
256                                                 aRec.node_labels[12],
257                                                 aLabel);
258             break;
259
260           }
261         }
262         //      if(!anElement)
263         //        MESSAGE("DriverUNV_R_SMDS_Mesh::Perform - can not add element with ID = "<<aLabel<<" and type = "<<aRec.fe_descriptor_id);
264       }
265     }
266     {
267       using namespace UNV2417;      
268       in_stream.seekg(0);
269       TDataSet aDataSet2417;
270       UNV2417::Read(in_stream,aDataSet2417);
271       if(MYDEBUG) MESSAGE("Perform - aDataSet2417.size() = "<<aDataSet2417.size());
272       if  (aDataSet2417.size() > 0) {
273         myGroup = new SMDS_MeshGroup(myMesh);
274         TDataSet::const_iterator anIter = aDataSet2417.begin();
275         for(; anIter != aDataSet2417.end(); anIter++){
276           const TGroupId& aLabel = anIter->first;
277           const TRecord& aRec = anIter->second;
278
279           int aNodesNb = aRec.NodeList.size();
280           int aElementsNb = aRec.ElementList.size();
281
282           bool useSuffix = ((aNodesNb > 0) && (aElementsNb > 0));
283           int i;
284           if (aNodesNb > 0) {
285             SMDS_MeshGroup* aNodesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Node);
286             std::string aGrName = (useSuffix) ? aRec.GroupName + "_Nodes" : aRec.GroupName;
287             int i = aGrName.find( "\r" );
288             if (i > 0)
289               aGrName.erase (i, 2);
290             myGroupNames.insert(TGroupNamesMap::value_type(aNodesGroup, aGrName));
291             myGroupId.insert(TGroupIdMap::value_type(aNodesGroup, aLabel));
292
293             for (i = 0; i < aNodesNb; i++) {
294               const SMDS_MeshNode* aNode = myMesh->FindNode(aRec.NodeList[i]);
295               if (aNode)
296                 aNodesGroup->Add(aNode);
297             }
298           }
299           if (aElementsNb > 0){
300             SMDS_MeshGroup* aEdgesGroup = 0;
301             SMDS_MeshGroup* aFacesGroup = 0;
302             SMDS_MeshGroup* aVolumeGroup = 0;
303             bool createdGroup = false;
304
305             for (i = 0; i < aElementsNb; i++) {
306               const SMDS_MeshElement* aElement = myMesh->FindElement(aRec.ElementList[i]);
307               if (aElement) {
308                 switch (aElement->GetType()) {
309                 case SMDSAbs_Edge:
310                   if (!aEdgesGroup) {
311                     aEdgesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Edge);
312                     if (!useSuffix && createdGroup) useSuffix = true;
313                     std::string aEdgesGrName = (useSuffix) ? aRec.GroupName + "_Edges" : aRec.GroupName;
314                     int i = aEdgesGrName.find( "\r" );
315                     if (i > 0)
316                       aEdgesGrName.erase (i, 2);
317                     myGroupNames.insert(TGroupNamesMap::value_type(aEdgesGroup, aEdgesGrName));
318                     myGroupId.insert(TGroupIdMap::value_type(aEdgesGroup, aLabel));
319                     createdGroup = true;
320                   }
321                   aEdgesGroup->Add(aElement);
322                   break;
323                 case SMDSAbs_Face:
324                   if (!aFacesGroup) {
325                     aFacesGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Face);
326                     if (!useSuffix && createdGroup) useSuffix = true;
327                     std::string aFacesGrName = (useSuffix) ? aRec.GroupName + "_Faces" : aRec.GroupName;
328                     int i = aFacesGrName.find( "\r" );
329                     if (i > 0)
330                       aFacesGrName.erase (i, 2);
331                     myGroupNames.insert(TGroupNamesMap::value_type(aFacesGroup, aFacesGrName));
332                     myGroupId.insert(TGroupIdMap::value_type(aFacesGroup, aLabel));
333                     createdGroup = true;
334                   }
335                   aFacesGroup->Add(aElement);
336                   break;
337                 case SMDSAbs_Volume:
338                   if (!aVolumeGroup) {
339                     aVolumeGroup = (SMDS_MeshGroup*) myGroup->AddSubGroup(SMDSAbs_Volume);
340                     if (!useSuffix && createdGroup) useSuffix = true;
341                     std::string aVolumeGrName = (useSuffix) ? aRec.GroupName + "_Volumes" : aRec.GroupName;
342                     int i = aVolumeGrName.find( "\r" );
343                     if (i > 0)
344                       aVolumeGrName.erase (i, 2);
345                     myGroupNames.insert(TGroupNamesMap::value_type(aVolumeGroup, aVolumeGrName));
346                     myGroupId.insert(TGroupIdMap::value_type(aVolumeGroup, aLabel));
347                     createdGroup = true;
348                   }
349                   aVolumeGroup->Add(aElement);
350                   break;
351                 }
352               } 
353             }
354           }
355         }
356       }
357     } 
358   }
359   catch(const std::exception& exc){
360     INFOS("Follow exception was cought:\n\t"<<exc.what());
361   }
362   catch(...){
363     INFOS("Unknown exception was cought !!!");
364   }
365   return aResult;
366 }