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"
39 #include <Basics_Utils.hxx>
45 typedef std::vector<size_t> TConnect;
47 int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter,
51 for(; theNodesIter->more();){
52 const SMDS_MeshElement* anElem = theNodesIter->next();
53 theConnect.push_back(anElem->GetID());
55 return theConnect.size();
60 Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
62 Kernel_Utils::Localizer loc;
63 Status aResult = DRS_OK;
64 std::ofstream out_stream(myFile.c_str());
67 using namespace UNV2411;
68 TDataSet aDataSet2411;
69 // Storing SMDS nodes to the UNV file
70 //-----------------------------------
71 MESSAGE("Perform - myMesh->NbNodes() = "<<myMesh->NbNodes());
72 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
73 for(; aNodesIter->more();){
74 const SMDS_MeshNode* aNode = aNodesIter->next();
76 aRec.coord[0] = aNode->X();
77 aRec.coord[1] = aNode->Y();
78 aRec.coord[2] = aNode->Z();
79 const TNodeLab& aLabel = aNode->GetID();
80 aDataSet2411.insert(TDataSet::value_type(aLabel,aRec));
82 MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
83 UNV2411::Write(out_stream,aDataSet2411);
86 using namespace UNV2412;
87 TDataSet aDataSet2412;
91 MESSAGE("Perform - myMesh->NbEdges() = "<<myMesh->NbEdges());
92 if(myMesh->NbEdges()){
93 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
94 for(; anIter->more();){
95 const SMDS_MeshEdge* anElem = anIter->next();
96 TElementLab aLabel = anElem->GetID();
97 int aNbNodes = anElem->NbNodes();
99 aRec.node_labels.reserve(aNbNodes);
100 SMDS_ElemIteratorPtr aNodesIter;
101 if( anElem->IsQuadratic() ) {
102 aNodesIter = static_cast<const SMDS_QuadraticEdge* >
103 ( anElem )->interlacedNodesElemIterator();
104 aRec.fe_descriptor_id = 22;
106 aNodesIter = anElem->nodesIterator();
107 aRec.fe_descriptor_id = 11;
109 for(; aNodesIter->more();){
110 const SMDS_MeshElement* aNode = aNodesIter->next();
111 aRec.node_labels.push_back(aNode->GetID());
113 aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
115 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
118 MESSAGE("Perform - myMesh->NbFaces() = "<<myMesh->NbFaces());
119 if(myMesh->NbFaces()){
120 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
121 for(; anIter->more();){
122 const SMDS_MeshFace* anElem = anIter->next();
123 TElementLab aLabel = anElem->GetID();
124 int aNbNodes = anElem->NbNodes();
126 aRec.node_labels.reserve(aNbNodes);
127 SMDS_ElemIteratorPtr aNodesIter;
128 if( anElem->IsQuadratic() )
129 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes* >
130 ( anElem )->interlacedNodesElemIterator();
132 aNodesIter = anElem->nodesIterator();
133 for(; aNodesIter->more();){
134 const SMDS_MeshElement* aNode = aNodesIter->next();
135 aRec.node_labels.push_back(aNode->GetID());
139 aRec.fe_descriptor_id = 41;
142 aRec.fe_descriptor_id = 44;
145 aRec.fe_descriptor_id = 42;
148 aRec.fe_descriptor_id = 45;
153 aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
155 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
158 MESSAGE("Perform - myMesh->NbVolumes() = "<<myMesh->NbVolumes());
159 if(myMesh->NbVolumes()){
160 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
161 for(; anIter->more();){
162 const SMDS_MeshVolume* anElem = anIter->next();
163 TElementLab aLabel = anElem->GetID();
165 int aNbNodes = anElem->NbNodes();
166 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
167 if ( anElem->IsPoly() ) {
168 if ( const SMDS_PolyhedralVolumeOfNodes* ph =
169 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem))
171 aNbNodes = ph->NbUniqueNodes();
172 aNodesIter = ph->uniqueNodesIterator();
175 aConnect.resize(aNbNodes);
176 GetConnect(aNodesIter,aConnect);
182 static int anIds[] = {0,2,1,3};
188 static int anIds[] = {0,2,1,3,5,4};
194 static int anIds[] = {0,3,2,1,4,7,6,5};
200 static int anIds[] = {0,4,2,9,5,3, 1,6,8, 7};
206 static int anIds[] = {0,6,4,2,7,5,3,1,8,11,10,9,12};
212 static int anIds[] = {0,4,2,9,13,11,5,3,1,14,12,10,6,8,7};
218 static int anIds[] = {0,6, 4,2, 12,18,16,14,7, 5, 3, 1, 19,17,15,13,8, 11,10,9};
228 aRec.fe_descriptor_id = anId;
229 aRec.node_labels.resize(aNbNodes);
230 for(int aNodeId = 0; aNodeId < aNbNodes; aNodeId++){
231 aRec.node_labels[aConn[aNodeId]] = aConnect[aNodeId];
233 aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
236 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
238 UNV2412::Write(out_stream,aDataSet2412);
241 using namespace UNV2417;
242 if (myGroups.size() > 0) {
243 TDataSet aDataSet2417;
244 TGroupList::const_iterator aIter = myGroups.begin();
245 for (; aIter != myGroups.end(); aIter++) {
246 SMESHDS_GroupBase* aGroupDS = *aIter;
248 aRec.GroupName = aGroupDS->GetStoreName();
251 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
252 if (aGroupDS->GetType() == SMDSAbs_Node) {
253 aRec.NodeList.resize(aGroupDS->Extent());
255 while (aIter->more()) {
256 const SMDS_MeshElement* aElem = aIter->next();
257 aRec.NodeList[i] = aElem->GetID();
261 aRec.ElementList.resize(aGroupDS->Extent());
263 while (aIter->more()) {
264 const SMDS_MeshElement* aElem = aIter->next();
265 aRec.ElementList[i] = aElem->GetID();
269 // 0019936: EDF 794 SMESH : Export UNV : Node color and group id
270 //aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
271 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID()+1, aRec));
273 UNV2417::Write(out_stream,aDataSet2417);
278 using namespace UNV2417;
279 TDataSet aDataSet2417;
280 for ( TGroupsMap::iterator it = myGroupsMap.begin(); it != myGroupsMap.end(); it++ ) {
281 SMESH_Group* aGroup = it->second;
282 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
285 aRec.GroupName = aGroup->GetName();
287 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
288 if (aGroupDS->GetType() == SMDSAbs_Node) {
289 aRec.NodeList.resize(aGroupDS->Extent());
291 while (aIter->more()) {
292 const SMDS_MeshElement* aElem = aIter->next();
293 aRec.NodeList[i] = aElem->GetID();
297 aRec.ElementList.resize(aGroupDS->Extent());
299 while (aIter->more()) {
300 const SMDS_MeshElement* aElem = aIter->next();
301 aRec.ElementList[i] = aElem->GetID();
305 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
308 UNV2417::Write(out_stream,aDataSet2417);
313 if (!check_file(myFile))
314 EXCEPTION(runtime_error,"ERROR: Output file not good.");
316 catch(const std::exception& exc){
317 INFOS("Follow exception was cought:\n\t"<<exc.what());
321 INFOS("Unknown exception was cought !!!");