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 MESSAGE("Perform - myMesh->NbNodes() = "<<myMesh->NbNodes());
63 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
65 while ( aNodesIter->more() )
67 const SMDS_MeshNode* aNode = aNodesIter->next();
68 aRec.label = aNode->GetID();
69 aRec.coord[0] = aNode->X();
70 aRec.coord[1] = aNode->Y();
71 aRec.coord[2] = aNode->Z();
72 aDataSet2411.push_back( aRec );
74 MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
75 UNV2411::Write(out_stream,aDataSet2411);
78 using namespace UNV2412;
79 TDataSet aDataSet2412;
82 MESSAGE("Perform - myMesh->NbEdges() = "<<myMesh->NbEdges());
83 if(myMesh->NbEdges()){
84 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
85 while( anIter->more() )
87 const SMDS_MeshEdge* anElem = anIter->next();
88 int aNbNodes = anElem->NbNodes();
90 aRec.label = anElem->GetID();
91 aRec.node_labels.reserve(aNbNodes);
92 if( anElem->IsQuadratic() ) {
93 aRec.fe_descriptor_id = 22;
95 aRec.fe_descriptor_id = 11;
97 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
98 while( aNodesIter->more())
100 const SMDS_MeshNode* aNode = aNodesIter->next();
101 aRec.node_labels.push_back( aNode->GetID() );
103 aDataSet2412.push_back(aRec);
105 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
108 MESSAGE("Perform - myMesh->NbFaces() = "<<myMesh->NbFaces());
109 if ( myMesh->NbFaces() )
111 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
112 while ( anIter->more())
114 const SMDS_MeshFace* anElem = anIter->next();
115 if ( anElem->IsPoly() ) continue;
116 int aNbNodes = anElem->NbNodes();
118 aRec.label = anElem->GetID();
119 aRec.node_labels.reserve(aNbNodes);
120 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
121 while( aNodesIter->more() ) {
122 const SMDS_MeshNode* aNode = aNodesIter->next();
123 aRec.node_labels.push_back( aNode->GetID() );
125 switch ( aNbNodes ) {
126 case 3: aRec.fe_descriptor_id = 41; break;
127 case 4: aRec.fe_descriptor_id = 44; break;
128 case 6: aRec.fe_descriptor_id = 42; break;
129 case 7: aRec.fe_descriptor_id = 42; break;
130 case 8: aRec.fe_descriptor_id = 45; break;
131 case 9: aRec.fe_descriptor_id = 45; aRec.node_labels.resize( 8 ); break;
135 aDataSet2412.push_back(aRec);
137 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
140 MESSAGE("Perform - myMesh->NbVolumes() = "<<myMesh->NbVolumes());
141 if ( myMesh->NbVolumes() )
143 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
144 while ( anIter->more())
146 const SMDS_MeshVolume* anElem = anIter->next();
147 if ( anElem->IsPoly() )
149 int aNbNodes = anElem->NbNodes();
152 case 4: anId = 111; break;
153 case 6: anId = 112; break;
154 case 8: anId = 115; break;
155 case 10: anId = 118; break;
156 case 13: anId = 114; break;
157 case 15: anId = 113; break;
159 case 27: anId = 116; aNbNodes = 20; break;
165 aRec.label = anElem->GetID();
166 aRec.fe_descriptor_id = anId;
167 aRec.node_labels.reserve(aNbNodes);
168 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
169 while ( aNodesIter->more() && (int)aRec.node_labels.size() < aNbNodes )
171 const SMDS_MeshElement* aNode = aNodesIter->next();
172 aRec.node_labels.push_back(aNode->GetID());
174 aDataSet2412.push_back(aRec);
177 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
179 UNV2412::Write(out_stream,aDataSet2412);
182 using namespace UNV2417;
183 if (myGroups.size() > 0) {
184 TDataSet aDataSet2417;
185 TGroupList::const_iterator aIter = myGroups.begin();
186 for (; aIter != myGroups.end(); aIter++) {
187 SMESHDS_GroupBase* aGroupDS = *aIter;
189 aRec.GroupName = aGroupDS->GetStoreName();
192 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
193 if (aGroupDS->GetType() == SMDSAbs_Node) {
194 aRec.NodeList.resize(aGroupDS->Extent());
196 while (aIter->more()) {
197 const SMDS_MeshElement* aElem = aIter->next();
198 aRec.NodeList[i] = aElem->GetID();
202 aRec.ElementList.resize(aGroupDS->Extent());
204 while (aIter->more()) {
205 const SMDS_MeshElement* aElem = aIter->next();
206 aRec.ElementList[i] = aElem->GetID();
210 // 0019936: EDF 794 SMESH : Export UNV : Node color and group id
211 //aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
212 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID()+1, aRec));
214 UNV2417::Write(out_stream,aDataSet2417);
219 using namespace UNV2417;
220 TDataSet aDataSet2417;
221 for ( TGroupsMap::iterator it = myGroupsMap.begin(); it != myGroupsMap.end(); it++ ) {
222 SMESH_Group* aGroup = it->second;
223 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
226 aRec.GroupName = aGroup->GetName();
228 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
229 if (aGroupDS->GetType() == SMDSAbs_Node) {
230 aRec.NodeList.resize(aGroupDS->Extent());
232 while (aIter->more()) {
233 const SMDS_MeshElement* aElem = aIter->next();
234 aRec.NodeList[i] = aElem->GetID();
238 aRec.ElementList.resize(aGroupDS->Extent());
240 while (aIter->more()) {
241 const SMDS_MeshElement* aElem = aIter->next();
242 aRec.ElementList[i] = aElem->GetID();
246 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
249 UNV2417::Write(out_stream,aDataSet2417);
254 if (!check_file(myFile))
255 EXCEPTION(runtime_error,"ERROR: Output file not good.");
257 catch(const std::exception& exc){
258 INFOS("Follow exception was cought:\n\t"<<exc.what());
262 INFOS("Unknown exception was cought !!!");