Salome HOME
6d834b3fd84cc54f9fd9824a667ee0cd684e91bb
[modules/smesh.git] / src / DriverUNV / DriverUNV_W_SMDS_Mesh.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19
20 #include <algorithm>
21
22 #include "DriverUNV_W_SMDS_Mesh.h"
23
24 #include "SMDS_Mesh.hxx"
25
26 #include "utilities.h"
27
28 #include "UNV2411_Structure.hxx"
29 #include "UNV2412_Structure.hxx"
30 #include "UNV_Utilities.hxx"
31
32 using namespace std;
33
34 Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
35 {
36   Status aResult = DRS_OK;
37   std::ofstream out_stream(myFile.c_str());
38   try{
39     {
40       using namespace UNV2411;
41       TDataSet aDataSet2411;
42       // Storing SMDS nodes to the UNV file
43       //-----------------------------------
44       MESSAGE("Perform - myMesh->NbNodes() = "<<myMesh->NbNodes());
45       SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
46       for(; aNodesIter->more();){
47         const SMDS_MeshNode* aNode = aNodesIter->next();
48         TRecord aRec;
49         aRec.coord[0] = aNode->X();
50         aRec.coord[1] = aNode->Y();
51         aRec.coord[2] = aNode->Z();
52         const TNodeLab& aLabel = aNode->GetID();
53         aDataSet2411.insert(TDataSet::value_type(aLabel,aRec));
54       }
55       MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
56       UNV2411::Write(out_stream,aDataSet2411);
57     }
58     {
59       using namespace UNV2412;
60       TDataSet aDataSet2412;
61       // Storing SMDS Edges
62       MESSAGE("Perform - myMesh->NbEdges() = "<<myMesh->NbEdges());
63       if(myMesh->NbEdges()){
64         SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
65         for(; anIter->more();){
66           const SMDS_MeshEdge* anElem = anIter->next();
67           const TElementLab& aLabel = anElem->GetID();
68           int aNbNodes = anElem->NbNodes();
69           TRecord aRec;
70           aRec.node_labels.reserve(aNbNodes);
71           SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
72           for(; aNodesIter->more();){
73             const SMDS_MeshElement* aNode = aNodesIter->next();
74             aRec.node_labels.push_back(aNode->GetID());
75           }
76           aRec.fe_descriptor_id = 11;
77           aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
78         }
79         MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
80       }
81       MESSAGE("Perform - myMesh->NbFaces() = "<<myMesh->NbFaces());
82       if(myMesh->NbFaces()){
83         SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
84         for(; anIter->more();){
85           const SMDS_MeshFace* anElem = anIter->next();
86           const TElementLab& aLabel = anElem->GetID();
87           int aNbNodes = anElem->NbNodes();
88           TRecord aRec;
89           aRec.node_labels.reserve(aNbNodes);
90           SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
91           for(; aNodesIter->more();){
92             const SMDS_MeshElement* aNode = aNodesIter->next();
93             aRec.node_labels.push_back(aNode->GetID());
94           }
95           switch(aNbNodes){
96           case 3:
97             aRec.fe_descriptor_id = 41;
98             break;
99           case 4:
100             aRec.fe_descriptor_id = 44;
101             break;
102           default:
103             continue;
104           }
105           aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
106         }
107         MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
108       }
109       MESSAGE("Perform - myMesh->NbVolumes() = "<<myMesh->NbVolumes());
110       if(myMesh->NbVolumes()){
111         SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
112         for(; anIter->more();){
113           const SMDS_MeshVolume* anElem = anIter->next();
114           const TElementLab& aLabel = anElem->GetID();
115           int aNbNodes = anElem->NbNodes();
116           TRecord aRec;
117           aRec.node_labels.reserve(aNbNodes);
118           SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
119           for(; aNodesIter->more();){
120             const SMDS_MeshElement* aNode = aNodesIter->next();
121             aRec.node_labels.push_back(aNode->GetID());
122           }
123           switch(aNbNodes){
124           case 4:
125             aRec.fe_descriptor_id = 111;
126             break;
127           case 6:
128             aRec.fe_descriptor_id = 112;
129             swap(aRec.node_labels[1],aRec.node_labels[2]);
130             swap(aRec.node_labels[4],aRec.node_labels[5]);
131             break;
132           case 8:
133             aRec.fe_descriptor_id = 115;
134             break;
135           default:
136             continue;
137           }
138           aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
139         }
140         MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
141       }
142       UNV2412::Write(out_stream,aDataSet2412);
143     }
144   }catch(const std::exception& exc){
145     INFOS("Follow exception was cought:\n\t"<<exc.what());
146   }catch(...){
147     INFOS("Unknown exception was cought !!!");
148   }
149   return aResult;
150 }