1 // Copyright (C) 2007-2016 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 "SMDS_QuadraticEdge.hxx"
29 #include "SMDS_QuadraticFaceOfNodes.hxx"
30 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
31 #include "SMESHDS_GroupBase.hxx"
33 #include "utilities.h"
35 #include "UNV164_Structure.hxx"
36 #include "UNV2411_Structure.hxx"
37 #include "UNV2412_Structure.hxx"
38 #include "UNV2417_Structure.hxx"
39 #include "UNV2420_Structure.hxx"
40 #include "UNV_Utilities.hxx"
42 #include <Basics_Utils.hxx>
47 Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
49 Kernel_Utils::Localizer loc;
50 Status aResult = DRS_OK;
51 std::ofstream out_stream(myFile.c_str());
54 UNV164::Write( out_stream ); // unit system
55 UNV2420::Write( out_stream, myMeshName ); // Coordinate system
58 using namespace UNV2411;
59 TDataSet aDataSet2411;
60 // Storing SMDS nodes to the UNV file
61 //-----------------------------------
62 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
64 while ( aNodesIter->more() )
66 const SMDS_MeshNode* aNode = aNodesIter->next();
67 aRec.label = aNode->GetID();
68 aRec.coord[0] = aNode->X();
69 aRec.coord[1] = aNode->Y();
70 aRec.coord[2] = aNode->Z();
71 aDataSet2411.push_back( aRec );
73 UNV2411::Write(out_stream,aDataSet2411);
76 using namespace UNV2412;
77 TDataSet aDataSet2412;
80 if(myMesh->NbEdges()){
81 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
82 while( anIter->more() )
84 const SMDS_MeshEdge* anElem = anIter->next();
85 int aNbNodes = anElem->NbNodes();
87 aRec.label = anElem->GetID();
88 aRec.node_labels.reserve(aNbNodes);
89 if( anElem->IsQuadratic() ) {
90 aRec.fe_descriptor_id = 22;
92 aRec.fe_descriptor_id = 11;
94 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
95 while( aNodesIter->more())
97 const SMDS_MeshNode* aNode = aNodesIter->next();
98 aRec.node_labels.push_back( aNode->GetID() );
100 aDataSet2412.push_back(aRec);
104 if ( myMesh->NbFaces() )
106 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
107 while ( anIter->more())
109 const SMDS_MeshFace* anElem = anIter->next();
110 if ( anElem->IsPoly() ) continue;
111 int aNbNodes = anElem->NbNodes();
113 aRec.label = anElem->GetID();
114 aRec.node_labels.reserve(aNbNodes);
115 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
116 while( aNodesIter->more() ) {
117 const SMDS_MeshNode* aNode = aNodesIter->next();
118 aRec.node_labels.push_back( aNode->GetID() );
120 switch ( aNbNodes ) {
121 case 3: aRec.fe_descriptor_id = 41; break;
122 case 4: aRec.fe_descriptor_id = 44; break;
123 case 6: aRec.fe_descriptor_id = 42; break;
124 case 7: aRec.fe_descriptor_id = 42; break;
125 case 8: aRec.fe_descriptor_id = 45; break;
126 case 9: aRec.fe_descriptor_id = 45; aRec.node_labels.resize( 8 ); break;
130 aDataSet2412.push_back(aRec);
134 if ( myMesh->NbVolumes() )
136 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
137 while ( anIter->more())
139 const SMDS_MeshVolume* anElem = anIter->next();
140 if ( anElem->IsPoly() )
142 int aNbNodes = anElem->NbNodes();
145 case 4: anId = 111; break;
146 case 6: anId = 112; break;
147 case 8: anId = 115; break;
148 case 10: anId = 118; break;
149 case 13: anId = 114; break;
150 case 15: anId = 113; break;
152 case 27: anId = 116; aNbNodes = 20; break;
158 aRec.label = anElem->GetID();
159 aRec.fe_descriptor_id = anId;
160 aRec.node_labels.reserve(aNbNodes);
161 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
162 while ( aNodesIter->more() && (int)aRec.node_labels.size() < aNbNodes )
164 const SMDS_MeshElement* aNode = aNodesIter->next();
165 aRec.node_labels.push_back(aNode->GetID());
167 aDataSet2412.push_back(aRec);
171 UNV2412::Write(out_stream,aDataSet2412);
174 using namespace UNV2417;
175 if (myGroups.size() > 0) {
176 TDataSet aDataSet2417;
177 TGroupList::const_iterator aIter = myGroups.begin();
178 for (; aIter != myGroups.end(); aIter++) {
179 SMESHDS_GroupBase* aGroupDS = *aIter;
181 aRec.GroupName = aGroupDS->GetStoreName();
184 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
185 if (aGroupDS->GetType() == SMDSAbs_Node) {
186 aRec.NodeList.resize(aGroupDS->Extent());
188 while (aIter->more()) {
189 const SMDS_MeshElement* aElem = aIter->next();
190 aRec.NodeList[i] = aElem->GetID();
194 aRec.ElementList.resize(aGroupDS->Extent());
196 while (aIter->more()) {
197 const SMDS_MeshElement* aElem = aIter->next();
198 aRec.ElementList[i] = aElem->GetID();
202 // 0019936: EDF 794 SMESH : Export UNV : Node color and group id
203 //aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
204 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID()+1, aRec));
206 UNV2417::Write(out_stream,aDataSet2417);
211 using namespace UNV2417;
212 TDataSet aDataSet2417;
213 for ( TGroupsMap::iterator it = myGroupsMap.begin(); it != myGroupsMap.end(); it++ ) {
214 SMESH_Group* aGroup = it->second;
215 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
218 aRec.GroupName = aGroup->GetName();
220 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
221 if (aGroupDS->GetType() == SMDSAbs_Node) {
222 aRec.NodeList.resize(aGroupDS->Extent());
224 while (aIter->more()) {
225 const SMDS_MeshElement* aElem = aIter->next();
226 aRec.NodeList[i] = aElem->GetID();
230 aRec.ElementList.resize(aGroupDS->Extent());
232 while (aIter->more()) {
233 const SMDS_MeshElement* aElem = aIter->next();
234 aRec.ElementList[i] = aElem->GetID();
238 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
241 UNV2417::Write(out_stream,aDataSet2417);
246 if (!check_file(myFile))
247 EXCEPTION(runtime_error,"ERROR: Output file not good.");
249 catch(const std::exception& exc){
250 INFOS("Follow exception was cought:\n\t"<<exc.what());
254 INFOS("Unknown exception was cought !!!");