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() && myRenumber )
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();
79 aRec.label = aNode->GetID(); //-- IPAL54452
80 if ( !nodeLabelByID.empty() )
81 nodeLabelByID[ aNode->GetID() ] = aRec.label;
82 aRec.coord[0] = aNode->X();
83 aRec.coord[1] = aNode->Y();
84 aRec.coord[2] = aNode->Z();
85 aDataSet2411.push_back( aRec );
87 UNV2411::Write(out_stream,aDataSet2411);
90 std::vector< size_t > elemLabelByID;
91 if ( !myGroups.empty() )
92 elemLabelByID.resize( myMesh->MaxElementID() + 1 );
95 using namespace UNV2412;
96 TDataSet aDataSet2412;
100 // -------------------
101 // Storing SMDS Edges
102 // -------------------
103 if ( myMesh->NbEdges() )
105 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
106 while ( anIter->more() )
108 const SMDS_MeshEdge* anElem = anIter->next();
109 if ( myRenumber ) // -- IPAL54452
112 aRec.label = anElem->GetID();
113 if ( !elemLabelByID.empty() )
114 elemLabelByID[ anElem->GetID() ] = aRec.label;
116 aRec.fe_descriptor_id = anElem->IsQuadratic() ? 22 : 11;
118 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
119 for ( aRec.node_labels.clear(); aNodesIter->more(); )
121 const SMDS_MeshNode* aNode = aNodesIter->next();
122 if ( nodeLabelByID.empty() )
123 aRec.node_labels.push_back( FromSmIdType<int>(aNode->GetID()) );
125 aRec.node_labels.push_back( nodeLabelByID[ aNode->GetID() ]);
128 aDataSet2412.push_back(aRec);
132 // -------------------
133 // Storing SMDS Faces
134 // -------------------
135 if ( myMesh->NbFaces() )
137 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
138 while ( anIter->more() )
140 const SMDS_MeshFace* anElem = anIter->next();
141 if ( anElem->IsPoly() ) continue;
143 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
144 for ( aRec.node_labels.clear(); aNodesIter->more(); )
146 const SMDS_MeshNode* aNode = aNodesIter->next();
147 if ( nodeLabelByID.empty() )
148 aRec.node_labels.push_back( FromSmIdType<int>(aNode->GetID()) );
150 aRec.node_labels.push_back( nodeLabelByID[ aNode->GetID() ]);
152 switch ( anElem->NbNodes() ) {
153 case 3: aRec.fe_descriptor_id = 41; break;
154 case 4: aRec.fe_descriptor_id = 44; break;
155 case 6: aRec.fe_descriptor_id = 42; break;
156 case 7: aRec.fe_descriptor_id = 42; break;
157 case 8: aRec.fe_descriptor_id = 45; break;
158 case 9: aRec.fe_descriptor_id = 45; aRec.node_labels.resize( 8 ); break;
165 aRec.label = anElem->GetID(); // -- IPAL54452
166 if ( !elemLabelByID.empty() )
167 elemLabelByID[ anElem->GetID() ] = aRec.label;
169 aDataSet2412.push_back(aRec);
173 // ---------------------
174 // Storing SMDS Volumes
175 // ---------------------
176 if ( myMesh->NbVolumes() )
178 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
179 while ( anIter->more() )
181 const SMDS_MeshVolume* anElem = anIter->next();
182 if ( anElem->IsPoly() )
184 size_t aNbNodes = anElem->NbNodes();
186 case 4: aRec.fe_descriptor_id = 111; break;
187 case 6: aRec.fe_descriptor_id = 112; break;
188 case 8: aRec.fe_descriptor_id = 115; break;
189 case 10: aRec.fe_descriptor_id = 118; break;
190 case 13: aRec.fe_descriptor_id = 114; break;
191 case 15: aRec.fe_descriptor_id = 113; break;
193 case 27: aRec.fe_descriptor_id = 116; aNbNodes = 20; break;
198 ++aRec.label; // -- IPAL54452
200 aRec.label = anElem->GetID();
201 if ( !elemLabelByID.empty() )
202 elemLabelByID[ anElem->GetID() ] = aRec.label;
204 aRec.node_labels.clear();
205 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
206 while ( aNodesIter->more() && aRec.node_labels.size() < aNbNodes )
208 const SMDS_MeshElement* aNode = aNodesIter->next();
209 if ( nodeLabelByID.empty() )
210 aRec.node_labels.push_back( FromSmIdType<int>(aNode->GetID()) );
212 aRec.node_labels.push_back( nodeLabelByID[ aNode->GetID() ]);
214 aDataSet2412.push_back(aRec);
217 UNV2412::Write(out_stream,aDataSet2412);
220 // --------------------
221 // Storing SMDS Groups
222 // --------------------
224 using namespace UNV2417;
225 if ( myGroups.size() > 0 )
228 TDataSet aDataSet2417;
229 TGroupList::const_iterator aIter = myGroups.begin();
230 for ( ; aIter != myGroups.end(); aIter++ )
232 SMESHDS_GroupBase* aGroupDS = *aIter;
233 aRec.GroupName = aGroupDS->GetStoreName();
234 aRec.NodeList.clear();
235 aRec.ElementList.clear();
237 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
238 if ( aGroupDS->GetType() == SMDSAbs_Node ) {
239 while ( aIter->more() ) {
240 const SMDS_MeshElement* aNode = aIter->next();
241 if ( nodeLabelByID.empty() )
242 aRec.NodeList.push_back( FromSmIdType<int>( aNode->GetID()) );
244 aRec.NodeList.push_back( nodeLabelByID[ aNode->GetID() ]);
249 while ( aIter->more() ) {
250 const SMDS_MeshElement* aElem = aIter->next();
251 if ( elemLabelByID.empty() )
252 aRec.ElementList.push_back( FromSmIdType<int>(aElem->GetID()) );
254 aRec.ElementList.push_back( elemLabelByID[ aElem->GetID() ]);
257 // 0019936: EDF 794 SMESH : Export UNV : Node color and group id
258 //aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
259 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID()+1, aRec));
261 UNV2417::Write(out_stream,aDataSet2417);
268 if (!check_file(myFile))
269 EXCEPTION(runtime_error,"ERROR: Output file not good.");
271 catch(const std::exception& exc){
272 INFOS("Follow exception was caught:\n\t"<<exc.what());
276 INFOS("Unknown exception was caught !!!");