1 // Copyright (C) 2007-2012 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 SMDS_ElemIteratorPtr aNodesIter;
110 aNodesIter = anElem->nodesIteratorToUNV();
111 if( anElem->IsQuadratic() ) {
112 aRec.fe_descriptor_id = 22;
114 aRec.fe_descriptor_id = 11;
116 while( aNodesIter->more())
118 const SMDS_MeshElement* aNode = aNodesIter->next();
119 aRec.node_labels.push_back(aNode->GetID());
121 aDataSet2412.push_back(aRec);
123 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
126 MESSAGE("Perform - myMesh->NbFaces() = "<<myMesh->NbFaces());
127 if ( myMesh->NbFaces() )
129 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
130 while ( anIter->more())
132 const SMDS_MeshFace* anElem = anIter->next();
133 if ( anElem->IsPoly() ) continue;
134 int aNbNodes = anElem->NbNodes();
136 aRec.label = anElem->GetID();
137 aRec.node_labels.reserve(aNbNodes);
138 SMDS_ElemIteratorPtr aNodesIter;
139 aNodesIter = anElem->nodesIteratorToUNV();
140 for(; aNodesIter->more();){
141 const SMDS_MeshElement* aNode = aNodesIter->next();
142 aRec.node_labels.push_back(aNode->GetID());
146 aRec.fe_descriptor_id = 41;
149 aRec.fe_descriptor_id = 44;
152 aRec.fe_descriptor_id = 42;
155 aRec.fe_descriptor_id = 45;
158 aRec.fe_descriptor_id = 45;
159 aRec.node_labels.resize( 8 );
164 aDataSet2412.push_back(aRec);
166 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
169 MESSAGE("Perform - myMesh->NbVolumes() = "<<myMesh->NbVolumes());
170 if ( myMesh->NbVolumes() )
172 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
173 while ( anIter->more())
175 const SMDS_MeshVolume* anElem = anIter->next();
176 int aNbNodes = anElem->NbNodes();
177 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIteratorToUNV();
178 if ( anElem->IsPoly() ) {
183 case 4: anId = 111; break;
184 case 6: anId = 112; break;
185 case 8: anId = 115; break;
186 case 10: anId = 118; break;
187 case 13: anId = 114; break;
188 case 15: anId = 113; break;
190 case 27: anId = 116; aNbNodes = 20; break;
196 aRec.label = anElem->GetID();
197 aRec.fe_descriptor_id = anId;
198 aRec.node_labels.reserve(aNbNodes);
199 while ( aNodesIter->more() && aRec.node_labels.size() < aNbNodes )
201 const SMDS_MeshElement* aNode = aNodesIter->next();
202 aRec.node_labels.push_back(aNode->GetID());
204 aDataSet2412.push_back(aRec);
207 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
209 UNV2412::Write(out_stream,aDataSet2412);
212 using namespace UNV2417;
213 if (myGroups.size() > 0) {
214 TDataSet aDataSet2417;
215 TGroupList::const_iterator aIter = myGroups.begin();
216 for (; aIter != myGroups.end(); aIter++) {
217 SMESHDS_GroupBase* aGroupDS = *aIter;
219 aRec.GroupName = aGroupDS->GetStoreName();
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 // 0019936: EDF 794 SMESH : Export UNV : Node color and group id
241 //aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
242 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID()+1, aRec));
244 UNV2417::Write(out_stream,aDataSet2417);
249 using namespace UNV2417;
250 TDataSet aDataSet2417;
251 for ( TGroupsMap::iterator it = myGroupsMap.begin(); it != myGroupsMap.end(); it++ ) {
252 SMESH_Group* aGroup = it->second;
253 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
256 aRec.GroupName = aGroup->GetName();
258 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
259 if (aGroupDS->GetType() == SMDSAbs_Node) {
260 aRec.NodeList.resize(aGroupDS->Extent());
262 while (aIter->more()) {
263 const SMDS_MeshElement* aElem = aIter->next();
264 aRec.NodeList[i] = aElem->GetID();
268 aRec.ElementList.resize(aGroupDS->Extent());
270 while (aIter->more()) {
271 const SMDS_MeshElement* aElem = aIter->next();
272 aRec.ElementList[i] = aElem->GetID();
276 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
279 UNV2417::Write(out_stream,aDataSet2417);
284 if (!check_file(myFile))
285 EXCEPTION(runtime_error,"ERROR: Output file not good.");
287 catch(const std::exception& exc){
288 INFOS("Follow exception was cought:\n\t"<<exc.what());
292 INFOS("Unknown exception was cought !!!");