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 std::ofstream out_stream(myFile.c_str());
51 UNV164::Write( out_stream ); // unit system
52 UNV2420::Write( out_stream, myMeshName ); // Coordinate system
55 using namespace UNV2411;
56 TDataSet aDataSet2411;
57 // Storing SMDS nodes to the UNV file
58 //-----------------------------------
59 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
61 while ( aNodesIter->more() )
63 const SMDS_MeshNode* aNode = aNodesIter->next();
64 aRec.label = aNode->GetID();
65 aRec.coord[0] = aNode->X();
66 aRec.coord[1] = aNode->Y();
67 aRec.coord[2] = aNode->Z();
68 aDataSet2411.push_back( aRec );
70 UNV2411::Write(out_stream,aDataSet2411);
73 using namespace UNV2412;
74 TDataSet aDataSet2412;
77 if(myMesh->NbEdges()){
78 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
79 while( anIter->more() )
81 const SMDS_MeshEdge* anElem = anIter->next();
82 int aNbNodes = anElem->NbNodes();
84 aRec.label = anElem->GetID();
85 aRec.node_labels.reserve(aNbNodes);
86 if( anElem->IsQuadratic() ) {
87 aRec.fe_descriptor_id = 22;
89 aRec.fe_descriptor_id = 11;
91 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
92 while( aNodesIter->more())
94 const SMDS_MeshNode* aNode = aNodesIter->next();
95 aRec.node_labels.push_back( aNode->GetID() );
97 aDataSet2412.push_back(aRec);
101 if ( myMesh->NbFaces() )
103 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
104 while ( anIter->more())
106 const SMDS_MeshFace* anElem = anIter->next();
107 if ( anElem->IsPoly() ) continue;
108 int aNbNodes = anElem->NbNodes();
110 aRec.label = anElem->GetID();
111 aRec.node_labels.reserve(aNbNodes);
112 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
113 while( aNodesIter->more() ) {
114 const SMDS_MeshNode* aNode = aNodesIter->next();
115 aRec.node_labels.push_back( aNode->GetID() );
117 switch ( aNbNodes ) {
118 case 3: aRec.fe_descriptor_id = 41; break;
119 case 4: aRec.fe_descriptor_id = 44; break;
120 case 6: aRec.fe_descriptor_id = 42; break;
121 case 7: aRec.fe_descriptor_id = 42; break;
122 case 8: aRec.fe_descriptor_id = 45; break;
123 case 9: aRec.fe_descriptor_id = 45; aRec.node_labels.resize( 8 ); break;
127 aDataSet2412.push_back(aRec);
131 if ( myMesh->NbVolumes() )
133 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
134 while ( anIter->more())
136 const SMDS_MeshVolume* anElem = anIter->next();
137 if ( anElem->IsPoly() )
139 int aNbNodes = anElem->NbNodes();
142 case 4: anId = 111; break;
143 case 6: anId = 112; break;
144 case 8: anId = 115; break;
145 case 10: anId = 118; break;
146 case 13: anId = 114; break;
147 case 15: anId = 113; break;
149 case 27: anId = 116; aNbNodes = 20; break;
155 aRec.label = anElem->GetID();
156 aRec.fe_descriptor_id = anId;
157 aRec.node_labels.reserve(aNbNodes);
158 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
159 while ( aNodesIter->more() && (int)aRec.node_labels.size() < aNbNodes )
161 const SMDS_MeshElement* aNode = aNodesIter->next();
162 aRec.node_labels.push_back(aNode->GetID());
164 aDataSet2412.push_back(aRec);
168 UNV2412::Write(out_stream,aDataSet2412);
171 using namespace UNV2417;
172 if (myGroups.size() > 0) {
173 TDataSet aDataSet2417;
174 TGroupList::const_iterator aIter = myGroups.begin();
175 for (; aIter != myGroups.end(); aIter++) {
176 SMESHDS_GroupBase* aGroupDS = *aIter;
178 aRec.GroupName = aGroupDS->GetStoreName();
181 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
182 if (aGroupDS->GetType() == SMDSAbs_Node) {
183 aRec.NodeList.resize(aGroupDS->Extent());
185 while (aIter->more()) {
186 const SMDS_MeshElement* aElem = aIter->next();
187 aRec.NodeList[i] = aElem->GetID();
191 aRec.ElementList.resize(aGroupDS->Extent());
193 while (aIter->more()) {
194 const SMDS_MeshElement* aElem = aIter->next();
195 aRec.ElementList[i] = aElem->GetID();
199 // 0019936: EDF 794 SMESH : Export UNV : Node color and group id
200 //aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
201 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID()+1, aRec));
203 UNV2417::Write(out_stream,aDataSet2417);
208 using namespace UNV2417;
209 TDataSet aDataSet2417;
210 for ( TGroupsMap::iterator it = myGroupsMap.begin(); it != myGroupsMap.end(); it++ ) {
211 SMESH_Group* aGroup = it->second;
212 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
215 aRec.GroupName = aGroup->GetName();
217 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
218 if (aGroupDS->GetType() == SMDSAbs_Node) {
219 aRec.NodeList.resize(aGroupDS->Extent());
221 while (aIter->more()) {
222 const SMDS_MeshElement* aElem = aIter->next();
223 aRec.NodeList[i] = aElem->GetID();
227 aRec.ElementList.resize(aGroupDS->Extent());
229 while (aIter->more()) {
230 const SMDS_MeshElement* aElem = aIter->next();
231 aRec.ElementList[i] = aElem->GetID();
235 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
238 UNV2417::Write(out_stream,aDataSet2417);
243 if (!check_file(myFile))
244 EXCEPTION(runtime_error,"ERROR: Output file not good.");
246 catch(const std::exception& exc){
247 INFOS("Follow exception was cought:\n\t"<<exc.what());
251 INFOS("Unknown exception was cought !!!");