1 // Copyright (C) 2007-2019 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;
48 #if defined(WIN32) && defined(UNICODE)
49 std::wstring aFile = Kernel_Utils::utf8_decode_s(myFile);
50 std::ofstream out_stream(aFile.c_str());
52 std::ofstream out_stream(myFile.c_str());
56 UNV164::Write( out_stream ); // unit system
57 UNV2420::Write( out_stream, myMeshName ); // Coordinate system
60 using namespace UNV2411;
61 TDataSet aDataSet2411;
62 // Storing SMDS nodes to the UNV file
63 //-----------------------------------
64 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
66 while ( aNodesIter->more() )
68 const SMDS_MeshNode* aNode = aNodesIter->next();
69 aRec.label = aNode->GetID();
70 aRec.coord[0] = aNode->X();
71 aRec.coord[1] = aNode->Y();
72 aRec.coord[2] = aNode->Z();
73 aDataSet2411.push_back( aRec );
75 UNV2411::Write(out_stream,aDataSet2411);
78 using namespace UNV2412;
79 TDataSet aDataSet2412;
82 if(myMesh->NbEdges()){
83 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
84 while( anIter->more() )
86 const SMDS_MeshEdge* anElem = anIter->next();
87 int aNbNodes = anElem->NbNodes();
89 aRec.label = anElem->GetID();
90 aRec.node_labels.reserve(aNbNodes);
91 if( anElem->IsQuadratic() ) {
92 aRec.fe_descriptor_id = 22;
94 aRec.fe_descriptor_id = 11;
96 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
97 while( aNodesIter->more())
99 const SMDS_MeshNode* aNode = aNodesIter->next();
100 aRec.node_labels.push_back( aNode->GetID() );
102 aDataSet2412.push_back(aRec);
106 if ( myMesh->NbFaces() )
108 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
109 while ( anIter->more())
111 const SMDS_MeshFace* anElem = anIter->next();
112 if ( anElem->IsPoly() ) continue;
113 int aNbNodes = anElem->NbNodes();
115 aRec.label = anElem->GetID();
116 aRec.node_labels.reserve(aNbNodes);
117 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
118 while( aNodesIter->more() ) {
119 const SMDS_MeshNode* aNode = aNodesIter->next();
120 aRec.node_labels.push_back( aNode->GetID() );
122 switch ( aNbNodes ) {
123 case 3: aRec.fe_descriptor_id = 41; break;
124 case 4: aRec.fe_descriptor_id = 44; break;
125 case 6: aRec.fe_descriptor_id = 42; break;
126 case 7: aRec.fe_descriptor_id = 42; break;
127 case 8: aRec.fe_descriptor_id = 45; break;
128 case 9: aRec.fe_descriptor_id = 45; aRec.node_labels.resize( 8 ); break;
132 aDataSet2412.push_back(aRec);
136 if ( myMesh->NbVolumes() )
138 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
139 while ( anIter->more())
141 const SMDS_MeshVolume* anElem = anIter->next();
142 if ( anElem->IsPoly() )
144 int aNbNodes = anElem->NbNodes();
147 case 4: anId = 111; break;
148 case 6: anId = 112; break;
149 case 8: anId = 115; break;
150 case 10: anId = 118; break;
151 case 13: anId = 114; break;
152 case 15: anId = 113; break;
154 case 27: anId = 116; aNbNodes = 20; break;
160 aRec.label = anElem->GetID();
161 aRec.fe_descriptor_id = anId;
162 aRec.node_labels.reserve(aNbNodes);
163 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
164 while ( aNodesIter->more() && (int)aRec.node_labels.size() < aNbNodes )
166 const SMDS_MeshElement* aNode = aNodesIter->next();
167 aRec.node_labels.push_back(aNode->GetID());
169 aDataSet2412.push_back(aRec);
173 UNV2412::Write(out_stream,aDataSet2412);
176 using namespace UNV2417;
177 if (myGroups.size() > 0) {
178 TDataSet aDataSet2417;
179 TGroupList::const_iterator aIter = myGroups.begin();
180 for (; aIter != myGroups.end(); aIter++) {
181 SMESHDS_GroupBase* aGroupDS = *aIter;
183 aRec.GroupName = aGroupDS->GetStoreName();
186 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
187 if (aGroupDS->GetType() == SMDSAbs_Node) {
188 aRec.NodeList.resize(aGroupDS->Extent());
190 while (aIter->more()) {
191 const SMDS_MeshElement* aElem = aIter->next();
192 aRec.NodeList[i] = aElem->GetID();
196 aRec.ElementList.resize(aGroupDS->Extent());
198 while (aIter->more()) {
199 const SMDS_MeshElement* aElem = aIter->next();
200 aRec.ElementList[i] = aElem->GetID();
204 // 0019936: EDF 794 SMESH : Export UNV : Node color and group id
205 //aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
206 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID()+1, aRec));
208 UNV2417::Write(out_stream,aDataSet2417);
213 using namespace UNV2417;
214 TDataSet aDataSet2417;
215 for ( TGroupsMap::iterator it = myGroupsMap.begin(); it != myGroupsMap.end(); it++ ) {
216 SMESH_Group* aGroup = it->second;
217 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
220 aRec.GroupName = aGroup->GetName();
222 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
223 if (aGroupDS->GetType() == SMDSAbs_Node) {
224 aRec.NodeList.resize(aGroupDS->Extent());
226 while (aIter->more()) {
227 const SMDS_MeshElement* aElem = aIter->next();
228 aRec.NodeList[i] = aElem->GetID();
232 aRec.ElementList.resize(aGroupDS->Extent());
234 while (aIter->more()) {
235 const SMDS_MeshElement* aElem = aIter->next();
236 aRec.ElementList[i] = aElem->GetID();
240 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
243 UNV2417::Write(out_stream,aDataSet2417);
248 if (!check_file(myFile))
249 EXCEPTION(runtime_error,"ERROR: Output file not good.");
251 catch(const std::exception& exc){
252 INFOS("Follow exception was cought:\n\t"<<exc.what());
256 INFOS("Unknown exception was cought !!!");