1 // Copyright (C) 2007-2013 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.
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>
48 typedef std::vector<size_t> TConnect;
50 int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter,
54 for(; theNodesIter->more();){
55 const SMDS_MeshElement* anElem = theNodesIter->next();
56 theConnect.push_back(anElem->GetID());
58 return theConnect.size();
63 Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
65 Kernel_Utils::Localizer loc;
66 Status aResult = DRS_OK;
67 std::ofstream out_stream(myFile.c_str());
70 UNV164::Write( out_stream ); // unit system
71 UNV2420::Write( out_stream, myMeshName ); // Coordinate system
74 using namespace UNV2411;
75 TDataSet aDataSet2411;
76 // Storing SMDS nodes to the UNV file
77 //-----------------------------------
78 MESSAGE("Perform - myMesh->NbNodes() = "<<myMesh->NbNodes());
79 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
81 while ( aNodesIter->more() )
83 const SMDS_MeshNode* aNode = aNodesIter->next();
84 aRec.label = aNode->GetID();
85 aRec.coord[0] = aNode->X();
86 aRec.coord[1] = aNode->Y();
87 aRec.coord[2] = aNode->Z();
88 aDataSet2411.push_back( aRec );
90 MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
91 UNV2411::Write(out_stream,aDataSet2411);
94 using namespace UNV2412;
95 TDataSet aDataSet2412;
99 MESSAGE("Perform - myMesh->NbEdges() = "<<myMesh->NbEdges());
100 if(myMesh->NbEdges()){
101 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
102 while( anIter->more() )
104 const SMDS_MeshEdge* anElem = anIter->next();
105 int aNbNodes = anElem->NbNodes();
107 aRec.label = anElem->GetID();
108 aRec.node_labels.reserve(aNbNodes);
109 if( anElem->IsQuadratic() ) {
110 aRec.fe_descriptor_id = 22;
112 aRec.fe_descriptor_id = 11;
114 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
115 while( aNodesIter->more())
117 const SMDS_MeshNode* aNode = aNodesIter->next();
118 aRec.node_labels.push_back( aNode->GetID() );
120 aDataSet2412.push_back(aRec);
122 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
125 MESSAGE("Perform - myMesh->NbFaces() = "<<myMesh->NbFaces());
126 if ( myMesh->NbFaces() )
128 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
129 while ( anIter->more())
131 const SMDS_MeshFace* anElem = anIter->next();
132 if ( anElem->IsPoly() ) continue;
133 int aNbNodes = anElem->NbNodes();
135 aRec.label = anElem->GetID();
136 aRec.node_labels.reserve(aNbNodes);
137 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
138 while( aNodesIter->more() ) {
139 const SMDS_MeshNode* aNode = aNodesIter->next();
140 aRec.node_labels.push_back( aNode->GetID() );
142 switch ( aNbNodes ) {
143 case 3: aRec.fe_descriptor_id = 41; break;
144 case 4: aRec.fe_descriptor_id = 44; break;
145 case 6: aRec.fe_descriptor_id = 42; break;
146 case 7: aRec.fe_descriptor_id = 42; break;
147 case 8: aRec.fe_descriptor_id = 45; break;
148 case 9: aRec.fe_descriptor_id = 45; aRec.node_labels.resize( 8 ); break;
152 aDataSet2412.push_back(aRec);
154 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
157 MESSAGE("Perform - myMesh->NbVolumes() = "<<myMesh->NbVolumes());
158 if ( myMesh->NbVolumes() )
160 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
161 while ( anIter->more())
163 const SMDS_MeshVolume* anElem = anIter->next();
164 if ( anElem->IsPoly() )
166 int aNbNodes = anElem->NbNodes();
169 case 4: anId = 111; break;
170 case 6: anId = 112; break;
171 case 8: anId = 115; break;
172 case 10: anId = 118; break;
173 case 13: anId = 114; break;
174 case 15: anId = 113; break;
176 case 27: anId = 116; aNbNodes = 20; break;
182 aRec.label = anElem->GetID();
183 aRec.fe_descriptor_id = anId;
184 aRec.node_labels.reserve(aNbNodes);
185 SMDS_NodeIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
186 while ( aNodesIter->more() && aRec.node_labels.size() < aNbNodes )
188 const SMDS_MeshElement* aNode = aNodesIter->next();
189 aRec.node_labels.push_back(aNode->GetID());
191 aDataSet2412.push_back(aRec);
194 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
196 UNV2412::Write(out_stream,aDataSet2412);
199 using namespace UNV2417;
200 if (myGroups.size() > 0) {
201 TDataSet aDataSet2417;
202 TGroupList::const_iterator aIter = myGroups.begin();
203 for (; aIter != myGroups.end(); aIter++) {
204 SMESHDS_GroupBase* aGroupDS = *aIter;
206 aRec.GroupName = aGroupDS->GetStoreName();
209 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
210 if (aGroupDS->GetType() == SMDSAbs_Node) {
211 aRec.NodeList.resize(aGroupDS->Extent());
213 while (aIter->more()) {
214 const SMDS_MeshElement* aElem = aIter->next();
215 aRec.NodeList[i] = aElem->GetID();
219 aRec.ElementList.resize(aGroupDS->Extent());
221 while (aIter->more()) {
222 const SMDS_MeshElement* aElem = aIter->next();
223 aRec.ElementList[i] = aElem->GetID();
227 // 0019936: EDF 794 SMESH : Export UNV : Node color and group id
228 //aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
229 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID()+1, aRec));
231 UNV2417::Write(out_stream,aDataSet2417);
236 using namespace UNV2417;
237 TDataSet aDataSet2417;
238 for ( TGroupsMap::iterator it = myGroupsMap.begin(); it != myGroupsMap.end(); it++ ) {
239 SMESH_Group* aGroup = it->second;
240 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
243 aRec.GroupName = aGroup->GetName();
245 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
246 if (aGroupDS->GetType() == SMDSAbs_Node) {
247 aRec.NodeList.resize(aGroupDS->Extent());
249 while (aIter->more()) {
250 const SMDS_MeshElement* aElem = aIter->next();
251 aRec.NodeList[i] = aElem->GetID();
255 aRec.ElementList.resize(aGroupDS->Extent());
257 while (aIter->more()) {
258 const SMDS_MeshElement* aElem = aIter->next();
259 aRec.ElementList[i] = aElem->GetID();
263 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
266 UNV2417::Write(out_stream,aDataSet2417);
271 if (!check_file(myFile))
272 EXCEPTION(runtime_error,"ERROR: Output file not good.");
274 catch(const std::exception& exc){
275 INFOS("Follow exception was cought:\n\t"<<exc.what());
279 INFOS("Unknown exception was cought !!!");