1 // Copyright (C) 2007-2008 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
24 #include "DriverUNV_W_SMDS_Mesh.h"
26 #include "SMDS_Mesh.hxx"
27 #include "SMDS_QuadraticEdge.hxx"
28 #include "SMDS_QuadraticFaceOfNodes.hxx"
29 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
30 #include "SMESHDS_GroupBase.hxx"
32 #include "utilities.h"
34 #include "UNV2411_Structure.hxx"
35 #include "UNV2412_Structure.hxx"
36 #include "UNV2417_Structure.hxx"
37 #include "UNV_Utilities.hxx"
43 typedef std::vector<size_t> TConnect;
45 int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter,
49 for(; theNodesIter->more();){
50 const SMDS_MeshElement* anElem = theNodesIter->next();
51 theConnect.push_back(anElem->GetID());
53 return theConnect.size();
58 Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
61 Status aResult = DRS_OK;
62 std::ofstream out_stream(myFile.c_str());
65 using namespace UNV2411;
66 TDataSet aDataSet2411;
67 // Storing SMDS nodes to the UNV file
68 //-----------------------------------
69 MESSAGE("Perform - myMesh->NbNodes() = "<<myMesh->NbNodes());
70 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
71 for(; aNodesIter->more();){
72 const SMDS_MeshNode* aNode = aNodesIter->next();
74 aRec.coord[0] = aNode->X();
75 aRec.coord[1] = aNode->Y();
76 aRec.coord[2] = aNode->Z();
77 const TNodeLab& aLabel = aNode->GetID();
78 aDataSet2411.insert(TDataSet::value_type(aLabel,aRec));
80 MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
81 UNV2411::Write(out_stream,aDataSet2411);
84 using namespace UNV2412;
85 TDataSet aDataSet2412;
89 MESSAGE("Perform - myMesh->NbEdges() = "<<myMesh->NbEdges());
90 if(myMesh->NbEdges()){
91 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
92 for(; anIter->more();){
93 const SMDS_MeshEdge* anElem = anIter->next();
94 TElementLab aLabel = anElem->GetID();
95 int aNbNodes = anElem->NbNodes();
97 aRec.node_labels.reserve(aNbNodes);
98 SMDS_ElemIteratorPtr aNodesIter;
99 if( anElem->IsQuadratic() ) {
100 aNodesIter = static_cast<const SMDS_QuadraticEdge* >
101 ( anElem )->interlacedNodesElemIterator();
102 aRec.fe_descriptor_id = 22;
104 aNodesIter = anElem->nodesIterator();
105 aRec.fe_descriptor_id = 11;
107 for(; aNodesIter->more();){
108 const SMDS_MeshElement* aNode = aNodesIter->next();
109 aRec.node_labels.push_back(aNode->GetID());
111 aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
113 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
116 MESSAGE("Perform - myMesh->NbFaces() = "<<myMesh->NbFaces());
117 if(myMesh->NbFaces()){
118 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
119 for(; anIter->more();){
120 const SMDS_MeshFace* anElem = anIter->next();
121 TElementLab aLabel = anElem->GetID();
122 int aNbNodes = anElem->NbNodes();
124 aRec.node_labels.reserve(aNbNodes);
125 SMDS_ElemIteratorPtr aNodesIter;
126 if( anElem->IsQuadratic() )
127 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes* >
128 ( anElem )->interlacedNodesElemIterator();
130 aNodesIter = anElem->nodesIterator();
131 for(; aNodesIter->more();){
132 const SMDS_MeshElement* aNode = aNodesIter->next();
133 aRec.node_labels.push_back(aNode->GetID());
137 aRec.fe_descriptor_id = 41;
140 aRec.fe_descriptor_id = 44;
143 aRec.fe_descriptor_id = 42;
146 aRec.fe_descriptor_id = 45;
151 aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
153 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
156 MESSAGE("Perform - myMesh->NbVolumes() = "<<myMesh->NbVolumes());
157 if(myMesh->NbVolumes()){
158 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
159 for(; anIter->more();){
160 const SMDS_MeshVolume* anElem = anIter->next();
161 TElementLab aLabel = anElem->GetID();
163 int aNbNodes = anElem->NbNodes();
164 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
165 if ( anElem->IsPoly() ) {
166 if ( const SMDS_PolyhedralVolumeOfNodes* ph =
167 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem))
169 aNbNodes = ph->NbUniqueNodes();
170 aNodesIter = ph->uniqueNodesIterator();
173 aConnect.resize(aNbNodes);
174 GetConnect(aNodesIter,aConnect);
180 static int anIds[] = {0,2,1,3};
186 static int anIds[] = {0,2,1,3,5,4};
192 static int anIds[] = {0,3,2,1,4,7,6,5};
198 static int anIds[] = {0,4,2,9,5,3, 1,6,8, 7};
204 static int anIds[] = {0,6,4,2,7,5,3,1,8,11,10,9,12};
210 static int anIds[] = {0,4,2,9,13,11,5,3,1,14,12,10,6,8,7};
216 static int anIds[] = {0,6, 4,2, 12,18,16,14,7, 5, 3, 1, 19,17,15,13,8, 11,10,9};
226 aRec.fe_descriptor_id = anId;
227 aRec.node_labels.resize(aNbNodes);
228 for(int aNodeId = 0; aNodeId < aNbNodes; aNodeId++){
229 aRec.node_labels[aConn[aNodeId]] = aConnect[aNodeId];
231 aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
234 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
236 UNV2412::Write(out_stream,aDataSet2412);
239 using namespace UNV2417;
240 if (myGroups.size() > 0) {
241 TDataSet aDataSet2417;
242 TGroupList::const_iterator aIter = myGroups.begin();
243 for (; aIter != myGroups.end(); aIter++) {
244 SMESHDS_GroupBase* aGroupDS = *aIter;
246 aRec.GroupName = aGroupDS->GetStoreName();
249 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
250 if (aGroupDS->GetType() == SMDSAbs_Node) {
251 aRec.NodeList.resize(aGroupDS->Extent());
253 while (aIter->more()) {
254 const SMDS_MeshElement* aElem = aIter->next();
255 aRec.NodeList[i] = aElem->GetID();
259 aRec.ElementList.resize(aGroupDS->Extent());
261 while (aIter->more()) {
262 const SMDS_MeshElement* aElem = aIter->next();
263 aRec.ElementList[i] = aElem->GetID();
267 // 0019936: EDF 794 SMESH : Export UNV : Node color and group id
268 //aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
269 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID()+1, aRec));
271 UNV2417::Write(out_stream,aDataSet2417);
276 using namespace UNV2417;
277 TDataSet aDataSet2417;
278 for ( TGroupsMap::iterator it = myGroupsMap.begin(); it != myGroupsMap.end(); it++ ) {
279 SMESH_Group* aGroup = it->second;
280 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
283 aRec.GroupName = aGroup->GetName();
285 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
286 if (aGroupDS->GetType() == SMDSAbs_Node) {
287 aRec.NodeList.resize(aGroupDS->Extent());
289 while (aIter->more()) {
290 const SMDS_MeshElement* aElem = aIter->next();
291 aRec.NodeList[i] = aElem->GetID();
295 aRec.ElementList.resize(aGroupDS->Extent());
297 while (aIter->more()) {
298 const SMDS_MeshElement* aElem = aIter->next();
299 aRec.ElementList[i] = aElem->GetID();
303 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
306 UNV2417::Write(out_stream,aDataSet2417);
311 if (!check_file(myFile))
312 EXCEPTION(runtime_error,"ERROR: Output file not good.");
314 catch(const std::exception& exc){
315 INFOS("Follow exception was cought:\n\t"<<exc.what());
319 INFOS("Unknown exception was cought !!!");