Back to index

salome-smesh  6.5.0
DriverUNV_W_SMDS_Mesh.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include <algorithm>
00024 
00025 #include "DriverUNV_W_SMDS_Mesh.h"
00026 
00027 #include "SMDS_Mesh.hxx"
00028 #include "SMDS_QuadraticEdge.hxx"
00029 #include "SMDS_QuadraticFaceOfNodes.hxx"
00030 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
00031 #include "SMESHDS_GroupBase.hxx"
00032 
00033 #include "utilities.h"
00034 
00035 #include "UNV164_Structure.hxx"
00036 #include "UNV2411_Structure.hxx"
00037 #include "UNV2412_Structure.hxx"
00038 #include "UNV2417_Structure.hxx"
00039 #include "UNV2420_Structure.hxx"
00040 #include "UNV_Utilities.hxx"
00041 
00042 #include <Basics_Utils.hxx>
00043 
00044 using namespace std;
00045 using namespace UNV;
00046 
00047 namespace{
00048   typedef std::vector<size_t> TConnect;
00049 
00050   int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter, 
00051                  TConnect& theConnect)
00052   {
00053     theConnect.clear();
00054     for(; theNodesIter->more();){
00055       const SMDS_MeshElement* anElem = theNodesIter->next();
00056       theConnect.push_back(anElem->GetID());
00057     }
00058     return theConnect.size();
00059   }
00060   
00061 }
00062 
00063 Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
00064 {
00065   Kernel_Utils::Localizer loc;
00066   Status aResult = DRS_OK;
00067   std::ofstream out_stream(myFile.c_str());
00068   try{
00069 
00070     UNV164::Write( out_stream ); // unit system
00071     UNV2420::Write( out_stream, myMeshName ); // Coordinate system
00072 
00073     {
00074       using namespace UNV2411;
00075       TDataSet aDataSet2411;
00076       // Storing SMDS nodes to the UNV file
00077       //-----------------------------------
00078       MESSAGE("Perform - myMesh->NbNodes() = "<<myMesh->NbNodes());
00079       SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
00080       TRecord aRec;
00081       while ( aNodesIter->more() )
00082       {
00083         const SMDS_MeshNode* aNode = aNodesIter->next();
00084         aRec.label    = aNode->GetID();
00085         aRec.coord[0] = aNode->X();
00086         aRec.coord[1] = aNode->Y();
00087         aRec.coord[2] = aNode->Z();
00088         aDataSet2411.push_back( aRec );
00089       }
00090       MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
00091       UNV2411::Write(out_stream,aDataSet2411);
00092     }
00093     {
00094       using namespace UNV2412;
00095       TDataSet aDataSet2412;
00096       TConnect aConnect;
00097 
00098       // Storing SMDS Edges
00099       MESSAGE("Perform - myMesh->NbEdges() = "<<myMesh->NbEdges());
00100       if(myMesh->NbEdges()){
00101         SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
00102         while( anIter->more() )
00103         {
00104           const SMDS_MeshEdge* anElem = anIter->next();
00105           int aNbNodes = anElem->NbNodes();
00106           TRecord aRec;
00107           aRec.label = anElem->GetID();
00108           aRec.node_labels.reserve(aNbNodes);
00109           SMDS_ElemIteratorPtr aNodesIter;
00110           aNodesIter = anElem->nodesIteratorToUNV();
00111           if( anElem->IsQuadratic() ) {
00112             aRec.fe_descriptor_id = 22;
00113           } else {
00114             aRec.fe_descriptor_id = 11;
00115           }
00116           while( aNodesIter->more())
00117           {
00118             const SMDS_MeshElement* aNode = aNodesIter->next();
00119             aRec.node_labels.push_back(aNode->GetID());
00120           }
00121           aDataSet2412.push_back(aRec);
00122         }
00123         MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
00124       }
00125 
00126       MESSAGE("Perform - myMesh->NbFaces() = "<<myMesh->NbFaces());
00127       if ( myMesh->NbFaces() )
00128       {
00129         SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
00130         while ( anIter->more())
00131         {
00132           const SMDS_MeshFace* anElem = anIter->next();
00133           if ( anElem->IsPoly() ) continue;
00134           int aNbNodes = anElem->NbNodes();
00135           TRecord aRec;
00136           aRec.label = anElem->GetID();
00137           aRec.node_labels.reserve(aNbNodes);
00138           SMDS_ElemIteratorPtr aNodesIter;
00139           aNodesIter = anElem->nodesIteratorToUNV();
00140           for(; aNodesIter->more();){
00141             const SMDS_MeshElement* aNode = aNodesIter->next();
00142             aRec.node_labels.push_back(aNode->GetID());
00143           }
00144           switch(aNbNodes){
00145           case 3:
00146             aRec.fe_descriptor_id = 41;
00147             break;
00148           case 4:
00149             aRec.fe_descriptor_id = 44;
00150             break;
00151           case 6:
00152             aRec.fe_descriptor_id = 42;
00153             break;
00154           case 8:
00155             aRec.fe_descriptor_id = 45;
00156             break;
00157           case 9:
00158             aRec.fe_descriptor_id = 45;
00159             aRec.node_labels.resize( 8 );
00160             break;
00161           default:
00162             continue;
00163           }
00164           aDataSet2412.push_back(aRec);
00165         }
00166         MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
00167       }
00168 
00169       MESSAGE("Perform - myMesh->NbVolumes() = "<<myMesh->NbVolumes());
00170       if ( myMesh->NbVolumes() )
00171       {
00172         SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
00173         while ( anIter->more())
00174         {
00175           const SMDS_MeshVolume* anElem = anIter->next();
00176           int aNbNodes = anElem->NbNodes();
00177           //MESSAGE("aNbNodes="<<aNbNodes);
00178           SMDS_ElemIteratorPtr aNodesIter;
00179           aNodesIter = anElem->nodesIteratorToUNV();
00180           if ( anElem->IsPoly() ) {
00181             continue;
00182             // MESSAGE("anElem->IsPoly");
00183             // if ( const SMDS_VtkVolume* ph =
00184             //      dynamic_cast<const SMDS_VtkVolume*> (anElem))
00185             // {
00186             //   aNbNodes = ph->NbUniqueNodes();
00187             //   aNodesIter = ph->uniqueNodesIterator();
00188             // }
00189           }
00190 
00191           int anId = -1;
00192           switch(aNbNodes) {
00193           case 4: {
00194             anId = 111;
00195             break;
00196           }
00197           case 6: {
00198             anId = 112;
00199             break;
00200           }
00201           case 8: {
00202             anId = 115;
00203             break;
00204           }
00205           case 10: {
00206             anId = 118;
00207             break;
00208           }
00209           case 13: {
00210             anId = 114;
00211             break;
00212           }
00213           case 15: {
00214             anId = 113;
00215             break;
00216           }
00217           case 20:
00218           case 27: {
00219             anId = 116;
00220             aNbNodes = 20;
00221             break;
00222           }
00223           default:
00224             continue;
00225           }
00226           if(anId>0){
00227             TRecord aRec;
00228             aRec.label = anElem->GetID();
00229             aRec.fe_descriptor_id = anId;
00230             aRec.node_labels.reserve(aNbNodes);
00231             while ( aNodesIter->more() && aRec.node_labels.size() < aNbNodes )
00232             {
00233               const SMDS_MeshElement* aNode = aNodesIter->next();
00234               aRec.node_labels.push_back(aNode->GetID());
00235             }
00236             aDataSet2412.push_back(aRec);
00237           }
00238         }
00239         MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
00240       }
00241       UNV2412::Write(out_stream,aDataSet2412);
00242     }
00243     {
00244       using namespace UNV2417;
00245       if (myGroups.size() > 0) {
00246         TDataSet aDataSet2417;
00247         TGroupList::const_iterator aIter = myGroups.begin();
00248         for (; aIter != myGroups.end(); aIter++) {
00249           SMESHDS_GroupBase* aGroupDS = *aIter;
00250           TRecord aRec;
00251           aRec.GroupName = aGroupDS->GetStoreName();
00252 
00253           int i;
00254           SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
00255           if (aGroupDS->GetType() == SMDSAbs_Node) {
00256             aRec.NodeList.resize(aGroupDS->Extent());
00257             i = 0;
00258             while (aIter->more()) {
00259               const SMDS_MeshElement* aElem = aIter->next();
00260               aRec.NodeList[i] = aElem->GetID(); 
00261               i++;
00262             }
00263           } else {
00264             aRec.ElementList.resize(aGroupDS->Extent());
00265             i = 0;
00266             while (aIter->more()) {
00267               const SMDS_MeshElement* aElem = aIter->next();
00268               aRec.ElementList[i] = aElem->GetID(); 
00269               i++;
00270             }
00271           }
00272           // 0019936: EDF 794 SMESH : Export UNV : Node color and group id
00273           //aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
00274           aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID()+1, aRec));
00275         }
00276         UNV2417::Write(out_stream,aDataSet2417);
00277         myGroups.clear();
00278       }
00279     }
00280     /*    {
00281       using namespace UNV2417;
00282       TDataSet aDataSet2417;
00283       for ( TGroupsMap::iterator it = myGroupsMap.begin(); it != myGroupsMap.end(); it++ ) {
00284         SMESH_Group*       aGroup   = it->second;
00285         SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
00286         if ( aGroupDS ) {
00287           TRecord aRec;
00288           aRec.GroupName = aGroup->GetName();
00289           int i;
00290           SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
00291           if (aGroupDS->GetType() == SMDSAbs_Node) {
00292             aRec.NodeList.resize(aGroupDS->Extent());
00293             i = 0;
00294             while (aIter->more()) {
00295               const SMDS_MeshElement* aElem = aIter->next();
00296               aRec.NodeList[i] = aElem->GetID(); 
00297               i++;
00298             }
00299           } else {
00300             aRec.ElementList.resize(aGroupDS->Extent());
00301             i = 0;
00302             while (aIter->more()) {
00303               const SMDS_MeshElement* aElem = aIter->next();
00304               aRec.ElementList[i] = aElem->GetID(); 
00305               i++;
00306             }
00307           }
00308           aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
00309         }
00310       }
00311       UNV2417::Write(out_stream,aDataSet2417);
00312       }*/
00313 
00314     out_stream.flush();
00315     out_stream.close();
00316     if (!check_file(myFile))
00317       EXCEPTION(runtime_error,"ERROR: Output file not good.");
00318   }
00319   catch(const std::exception& exc){
00320     INFOS("Follow exception was cought:\n\t"<<exc.what());
00321     throw;
00322   }
00323   catch(...){
00324     INFOS("Unknown exception was cought !!!");
00325     throw;
00326   }
00327   return aResult;
00328 }