1 // Copyright (C) 2007-2011 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 "UNV2411_Structure.hxx"
36 #include "UNV2412_Structure.hxx"
37 #include "UNV2417_Structure.hxx"
38 #include "UNV_Utilities.hxx"
40 #include <Basics_Utils.hxx>
46 typedef std::vector<size_t> TConnect;
48 int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter,
52 for(; theNodesIter->more();){
53 const SMDS_MeshElement* anElem = theNodesIter->next();
54 theConnect.push_back(anElem->GetID());
56 return theConnect.size();
61 Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
63 Kernel_Utils::Localizer loc;
64 Status aResult = DRS_OK;
65 std::ofstream out_stream(myFile.c_str());
68 using namespace UNV2411;
69 TDataSet aDataSet2411;
70 // Storing SMDS nodes to the UNV file
71 //-----------------------------------
72 MESSAGE("Perform - myMesh->NbNodes() = "<<myMesh->NbNodes());
73 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
74 for(; aNodesIter->more();){
75 const SMDS_MeshNode* aNode = aNodesIter->next();
77 aRec.coord[0] = aNode->X();
78 aRec.coord[1] = aNode->Y();
79 aRec.coord[2] = aNode->Z();
80 const TNodeLab& aLabel = aNode->GetID();
81 aDataSet2411.insert(TDataSet::value_type(aLabel,aRec));
83 MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
84 UNV2411::Write(out_stream,aDataSet2411);
87 using namespace UNV2412;
88 TDataSet aDataSet2412;
92 MESSAGE("Perform - myMesh->NbEdges() = "<<myMesh->NbEdges());
93 if(myMesh->NbEdges()){
94 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
95 for(; anIter->more();){
96 const SMDS_MeshEdge* anElem = anIter->next();
97 TElementLab aLabel = anElem->GetID();
98 int aNbNodes = anElem->NbNodes();
100 aRec.node_labels.reserve(aNbNodes);
101 SMDS_ElemIteratorPtr aNodesIter;
102 aNodesIter = anElem->nodesIteratorToUNV();
103 if( anElem->IsQuadratic() ) {
104 aRec.fe_descriptor_id = 22;
106 aRec.fe_descriptor_id = 11;
108 for(; aNodesIter->more();){
109 const SMDS_MeshElement* aNode = aNodesIter->next();
110 aRec.node_labels.push_back(aNode->GetID());
112 aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
114 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
117 MESSAGE("Perform - myMesh->NbFaces() = "<<myMesh->NbFaces());
118 if(myMesh->NbFaces()){
119 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
120 for(; anIter->more();){
121 const SMDS_MeshFace* anElem = anIter->next();
122 TElementLab aLabel = anElem->GetID();
123 int aNbNodes = anElem->NbNodes();
125 aRec.node_labels.reserve(aNbNodes);
126 SMDS_ElemIteratorPtr aNodesIter;
127 aNodesIter = anElem->nodesIteratorToUNV();
128 for(; aNodesIter->more();){
129 const SMDS_MeshElement* aNode = aNodesIter->next();
130 aRec.node_labels.push_back(aNode->GetID());
134 aRec.fe_descriptor_id = 41;
137 aRec.fe_descriptor_id = 44;
140 aRec.fe_descriptor_id = 42;
143 aRec.fe_descriptor_id = 45;
148 aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
150 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
153 MESSAGE("Perform - myMesh->NbVolumes() = "<<myMesh->NbVolumes());
154 if(myMesh->NbVolumes()){
155 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
156 for(; anIter->more();){
157 const SMDS_MeshVolume* anElem = anIter->next();
158 TElementLab aLabel = anElem->GetID();
160 int aNbNodes = anElem->NbNodes();
161 //MESSAGE("aNbNodes="<<aNbNodes);
162 SMDS_ElemIteratorPtr aNodesIter;
163 aNodesIter = anElem->nodesIteratorToUNV();
164 if ( anElem->IsPoly() ) {
165 MESSAGE("anElem->IsPoly");
166 if ( const SMDS_VtkVolume* ph =
167 dynamic_cast<const SMDS_VtkVolume*> (anElem))
169 aNbNodes = ph->NbUniqueNodes();
170 aNodesIter = ph->uniqueNodesIterator();
209 aRec.fe_descriptor_id = anId;
210 aRec.node_labels.reserve(aNbNodes);
211 for(; aNodesIter->more();){
212 const SMDS_MeshElement* aNode = aNodesIter->next();
213 aRec.node_labels.push_back(aNode->GetID());
215 aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
218 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
220 UNV2412::Write(out_stream,aDataSet2412);
223 using namespace UNV2417;
224 if (myGroups.size() > 0) {
225 TDataSet aDataSet2417;
226 TGroupList::const_iterator aIter = myGroups.begin();
227 for (; aIter != myGroups.end(); aIter++) {
228 SMESHDS_GroupBase* aGroupDS = *aIter;
230 aRec.GroupName = aGroupDS->GetStoreName();
233 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
234 if (aGroupDS->GetType() == SMDSAbs_Node) {
235 aRec.NodeList.resize(aGroupDS->Extent());
237 while (aIter->more()) {
238 const SMDS_MeshElement* aElem = aIter->next();
239 aRec.NodeList[i] = aElem->GetID();
243 aRec.ElementList.resize(aGroupDS->Extent());
245 while (aIter->more()) {
246 const SMDS_MeshElement* aElem = aIter->next();
247 aRec.ElementList[i] = aElem->GetID();
251 // 0019936: EDF 794 SMESH : Export UNV : Node color and group id
252 //aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
253 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID()+1, aRec));
255 UNV2417::Write(out_stream,aDataSet2417);
260 using namespace UNV2417;
261 TDataSet aDataSet2417;
262 for ( TGroupsMap::iterator it = myGroupsMap.begin(); it != myGroupsMap.end(); it++ ) {
263 SMESH_Group* aGroup = it->second;
264 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
267 aRec.GroupName = aGroup->GetName();
269 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
270 if (aGroupDS->GetType() == SMDSAbs_Node) {
271 aRec.NodeList.resize(aGroupDS->Extent());
273 while (aIter->more()) {
274 const SMDS_MeshElement* aElem = aIter->next();
275 aRec.NodeList[i] = aElem->GetID();
279 aRec.ElementList.resize(aGroupDS->Extent());
281 while (aIter->more()) {
282 const SMDS_MeshElement* aElem = aIter->next();
283 aRec.ElementList[i] = aElem->GetID();
287 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
290 UNV2417::Write(out_stream,aDataSet2417);
295 if (!check_file(myFile))
296 EXCEPTION(runtime_error,"ERROR: Output file not good.");
298 catch(const std::exception& exc){
299 INFOS("Follow exception was cought:\n\t"<<exc.what());
303 INFOS("Unknown exception was cought !!!");