1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 #include "DriverUNV_W_SMDS_Mesh.h"
27 #include "SMDS_Mesh.hxx"
28 #include "SMESHDS_GroupBase.hxx"
30 #include "utilities.h"
32 #include "UNV164_Structure.hxx"
33 #include "UNV2411_Structure.hxx"
34 #include "UNV2412_Structure.hxx"
35 #include "UNV2417_Structure.hxx"
36 #include "UNV2420_Structure.hxx"
37 #include "UNV_Utilities.hxx"
39 #include <Basics_Utils.hxx>
44 Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
46 Kernel_Utils::Localizer loc;
47 Status aResult = DRS_OK;
49 if ( Driver_Mesh::IsMeshTooLarge< int >( myMesh, /*checkIDs =*/ false))
50 return DRS_TOO_LARGE_MESH;
52 #if defined(WIN32) && defined(UNICODE)
53 std::wstring aFile = Kernel_Utils::utf8_decode_s(myFile);
54 std::ofstream out_stream(aFile.c_str());
56 std::ofstream out_stream(myFile.c_str());
60 UNV164::Write( out_stream ); // unit system
61 UNV2420::Write( out_stream, myMeshName ); // Coordinate system
63 std::vector< size_t > nodeLabelByID;
64 if ( myMesh->HasNumerationHoles() )
65 nodeLabelByID.resize( myMesh->MaxNodeID() + 1 );
68 using namespace UNV2411;
69 TDataSet aDataSet2411;
70 // -----------------------------------
71 // Storing SMDS nodes to the UNV file
72 // -----------------------------------
73 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
75 for ( aRec.label = 1; aNodesIter->more(); ++aRec.label )
77 const SMDS_MeshNode* aNode = aNodesIter->next();
78 // aRec.label = aNode->GetID(); -- IPAL54452
79 if ( !nodeLabelByID.empty() )
80 nodeLabelByID[ aNode->GetID() ] = aRec.label;
81 aRec.coord[0] = aNode->X();
82 aRec.coord[1] = aNode->Y();
83 aRec.coord[2] = aNode->Z();
84 aDataSet2411.push_back( aRec );
86 UNV2411::Write(out_stream,aDataSet2411);
89 std::vector< size_t > elemLabelByID;
90 if ( !myGroups.empty() )
91 elemLabelByID.resize( myMesh->MaxElementID() + 1 );
94 using namespace UNV2412;
95 TDataSet aDataSet2412;
99 // -------------------
100 // Storing SMDS Edges
101 // -------------------
102 if ( myMesh->NbEdges() )
104 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
105 while ( anIter->more() )
107 const SMDS_MeshEdge* anElem = anIter->next();
108 // aRec.label = anElem->GetID(); -- IPAL54452
110 if ( !elemLabelByID.empty() )
111 elemLabelByID[ anElem->GetID() ] = aRec.label;
113 aRec.fe_descriptor_id = anElem->IsQuadratic() ? 22 : 11;
115 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
116 for ( aRec.node_labels.clear(); aNodesIter->more(); )
118 const SMDS_MeshNode* aNode = aNodesIter->next();
119 if ( nodeLabelByID.empty() )
120 aRec.node_labels.push_back( FromSmIdType<int>(aNode->GetID()) );
122 aRec.node_labels.push_back( nodeLabelByID[ aNode->GetID() ]);
125 aDataSet2412.push_back(aRec);
129 // -------------------
130 // Storing SMDS Faces
131 // -------------------
132 if ( myMesh->NbFaces() )
134 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
135 while ( anIter->more() )
137 const SMDS_MeshFace* anElem = anIter->next();
138 if ( anElem->IsPoly() ) continue;
140 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
141 for ( aRec.node_labels.clear(); aNodesIter->more(); ) {
142 const SMDS_MeshNode* aNode = aNodesIter->next();
143 if ( nodeLabelByID.empty() )
144 aRec.node_labels.push_back( FromSmIdType<int>(aNode->GetID()) );
146 aRec.node_labels.push_back( nodeLabelByID[ aNode->GetID() ]);
148 switch ( anElem->NbNodes() ) {
149 case 3: aRec.fe_descriptor_id = 41; break;
150 case 4: aRec.fe_descriptor_id = 44; break;
151 case 6: aRec.fe_descriptor_id = 42; break;
152 case 7: aRec.fe_descriptor_id = 42; break;
153 case 8: aRec.fe_descriptor_id = 45; break;
154 case 9: aRec.fe_descriptor_id = 45; aRec.node_labels.resize( 8 ); break;
158 // aRec.label = anElem->GetID(); -- IPAL54452
160 if ( !elemLabelByID.empty() )
161 elemLabelByID[ anElem->GetID() ] = aRec.label;
163 aDataSet2412.push_back(aRec);
167 // ---------------------
168 // Storing SMDS Volumes
169 // ---------------------
170 if ( myMesh->NbVolumes() )
172 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
173 while ( anIter->more() )
175 const SMDS_MeshVolume* anElem = anIter->next();
176 if ( anElem->IsPoly() )
178 size_t aNbNodes = anElem->NbNodes();
180 case 4: aRec.fe_descriptor_id = 111; break;
181 case 6: aRec.fe_descriptor_id = 112; break;
182 case 8: aRec.fe_descriptor_id = 115; break;
183 case 10: aRec.fe_descriptor_id = 118; break;
184 case 13: aRec.fe_descriptor_id = 114; break;
185 case 15: aRec.fe_descriptor_id = 113; break;
187 case 27: aRec.fe_descriptor_id = 116; aNbNodes = 20; break;
191 // aRec.label = anElem->GetID(); -- IPAL54452
193 if ( !elemLabelByID.empty() )
194 elemLabelByID[ anElem->GetID() ] = aRec.label;
196 aRec.node_labels.clear();
197 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
198 while ( aNodesIter->more() && aRec.node_labels.size() < aNbNodes )
200 const SMDS_MeshElement* aNode = aNodesIter->next();
201 if ( nodeLabelByID.empty() )
202 aRec.node_labels.push_back( FromSmIdType<int>(aNode->GetID()) );
204 aRec.node_labels.push_back( nodeLabelByID[ aNode->GetID() ]);
206 aDataSet2412.push_back(aRec);
209 UNV2412::Write(out_stream,aDataSet2412);
212 // --------------------
213 // Storing SMDS Groups
214 // --------------------
216 using namespace UNV2417;
217 if ( myGroups.size() > 0 ) {
219 TDataSet aDataSet2417;
220 TGroupList::const_iterator aIter = myGroups.begin();
221 for ( ; aIter != myGroups.end(); aIter++ )
223 SMESHDS_GroupBase* aGroupDS = *aIter;
224 aRec.GroupName = aGroupDS->GetStoreName();
225 aRec.NodeList.clear();
226 aRec.ElementList.clear();
228 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
229 if ( aGroupDS->GetType() == SMDSAbs_Node ) {
230 while ( aIter->more() ) {
231 const SMDS_MeshElement* aNode = aIter->next();
232 if ( nodeLabelByID.empty() )
233 aRec.NodeList.push_back( FromSmIdType<int>(aNode->GetID()) );
235 aRec.NodeList.push_back( nodeLabelByID[ aNode->GetID() ]);
240 while ( aIter->more() ) {
241 const SMDS_MeshElement* aElem = aIter->next();
242 if ( elemLabelByID.empty() )
243 aRec.ElementList.push_back( FromSmIdType<int>(aElem->GetID()) );
245 aRec.ElementList.push_back( elemLabelByID[ aElem->GetID() ]);
248 // 0019936: EDF 794 SMESH : Export UNV : Node color and group id
249 //aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
250 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID()+1, aRec));
252 UNV2417::Write(out_stream,aDataSet2417);
259 if (!check_file(myFile))
260 EXCEPTION(runtime_error,"ERROR: Output file not good.");
262 catch(const std::exception& exc){
263 INFOS("Follow exception was caught:\n\t"<<exc.what());
267 INFOS("Unknown exception was caught !!!");