Version: 6.3.1

src/DriverUNV/DriverUNV_W_SMDS_Mesh.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  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 "UNV2411_Structure.hxx"
00036 #include "UNV2412_Structure.hxx"
00037 #include "UNV2417_Structure.hxx"
00038 #include "UNV_Utilities.hxx"
00039 
00040 #include <Basics_Utils.hxx>
00041 
00042 using namespace std;
00043 using namespace UNV;
00044 
00045 namespace{
00046   typedef std::vector<size_t> TConnect;
00047 
00048   int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter, 
00049                  TConnect& theConnect)
00050   {
00051     theConnect.clear();
00052     for(; theNodesIter->more();){
00053       const SMDS_MeshElement* anElem = theNodesIter->next();
00054       theConnect.push_back(anElem->GetID());
00055     }
00056     return theConnect.size();
00057   }
00058   
00059 }
00060 
00061 Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
00062 {
00063   Kernel_Utils::Localizer loc;
00064   Status aResult = DRS_OK;
00065   std::ofstream out_stream(myFile.c_str());
00066   try{
00067     {
00068       using namespace UNV2411;
00069       TDataSet aDataSet2411;
00070       // Storing SMDS nodes to the UNV file
00071       //-----------------------------------
00072       MESSAGE("Perform - myMesh->NbNodes() = "<<myMesh->NbNodes());
00073       SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
00074       for(; aNodesIter->more();){
00075         const SMDS_MeshNode* aNode = aNodesIter->next();
00076         TRecord aRec;
00077         aRec.coord[0] = aNode->X();
00078         aRec.coord[1] = aNode->Y();
00079         aRec.coord[2] = aNode->Z();
00080         const TNodeLab& aLabel = aNode->GetID();
00081         aDataSet2411.insert(TDataSet::value_type(aLabel,aRec));
00082       }
00083       MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
00084       UNV2411::Write(out_stream,aDataSet2411);
00085     }
00086     {
00087       using namespace UNV2412;
00088       TDataSet aDataSet2412;
00089       TConnect aConnect;
00090 
00091       // Storing SMDS Edges
00092       MESSAGE("Perform - myMesh->NbEdges() = "<<myMesh->NbEdges());
00093       if(myMesh->NbEdges()){
00094         SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
00095         for(; anIter->more();){
00096           const SMDS_MeshEdge* anElem = anIter->next();
00097           TElementLab aLabel = anElem->GetID();
00098           int aNbNodes = anElem->NbNodes();
00099           TRecord aRec;
00100           aRec.node_labels.reserve(aNbNodes);
00101           SMDS_ElemIteratorPtr aNodesIter;
00102           aNodesIter = anElem->nodesIteratorToUNV();
00103           if( anElem->IsQuadratic() ) {
00104             aRec.fe_descriptor_id = 22;
00105           } else {
00106             aRec.fe_descriptor_id = 11;
00107           }
00108           for(; aNodesIter->more();){
00109             const SMDS_MeshElement* aNode = aNodesIter->next();
00110             aRec.node_labels.push_back(aNode->GetID());
00111           }
00112           aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
00113         }
00114         MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
00115       }
00116 
00117       MESSAGE("Perform - myMesh->NbFaces() = "<<myMesh->NbFaces());
00118       if(myMesh->NbFaces()){
00119         SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
00120         for(; anIter->more();){
00121           const SMDS_MeshFace* anElem = anIter->next();
00122           TElementLab aLabel = anElem->GetID();
00123           int aNbNodes = anElem->NbNodes();
00124           TRecord aRec;
00125           aRec.node_labels.reserve(aNbNodes);
00126           SMDS_ElemIteratorPtr aNodesIter;
00127           aNodesIter = anElem->nodesIteratorToUNV();
00128           for(; aNodesIter->more();){
00129             const SMDS_MeshElement* aNode = aNodesIter->next();
00130             aRec.node_labels.push_back(aNode->GetID());
00131           }
00132           switch(aNbNodes){
00133           case 3:
00134             aRec.fe_descriptor_id = 41;
00135             break;
00136           case 4:
00137             aRec.fe_descriptor_id = 44;
00138             break;
00139           case 6:
00140             aRec.fe_descriptor_id = 42;
00141             break;
00142           case 8:
00143             aRec.fe_descriptor_id = 45;
00144             break;
00145           default:
00146             continue;
00147           }
00148           aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
00149         }
00150         MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
00151       }
00152 
00153       MESSAGE("Perform - myMesh->NbVolumes() = "<<myMesh->NbVolumes());
00154       if(myMesh->NbVolumes()){
00155         SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
00156         for(; anIter->more();){
00157           const SMDS_MeshVolume* anElem = anIter->next();
00158           TElementLab aLabel = anElem->GetID();
00159 
00160           int aNbNodes = anElem->NbNodes();
00161           //MESSAGE("aNbNodes="<<aNbNodes);
00162           SMDS_ElemIteratorPtr aNodesIter;
00163           aNodesIter = anElem->nodesIteratorToUNV();
00164           if ( anElem->IsPoly() ) {
00165             MESSAGE("anElem->IsPoly");
00166             if ( const SMDS_VtkVolume* ph =
00167                  dynamic_cast<const SMDS_VtkVolume*> (anElem))
00168             {
00169               aNbNodes = ph->NbUniqueNodes();
00170               aNodesIter = ph->uniqueNodesIterator();
00171             }
00172           }
00173 
00174           int anId = -1;
00175           switch(aNbNodes){
00176           case 4: {
00177             anId = 111;
00178             break;
00179           }
00180           case 6: {
00181             anId = 112;
00182             break;
00183           }
00184           case 8: {
00185             anId = 115;
00186             break;
00187           }
00188           case 10: {
00189             anId = 118;
00190             break;
00191           }
00192           case 13: {
00193             anId = 114;
00194             break;
00195           }
00196           case 15: {
00197             anId = 113;
00198             break;
00199           }
00200           case 20: {
00201             anId = 116;
00202             break;
00203           }
00204           default:
00205             continue;
00206           }
00207           if(anId>0){
00208             TRecord aRec;
00209             aRec.fe_descriptor_id = anId;
00210             aRec.node_labels.reserve(aNbNodes);
00211             for(; aNodesIter->more();){
00212               const SMDS_MeshElement* aNode = aNodesIter->next();
00213               aRec.node_labels.push_back(aNode->GetID());
00214             }
00215             aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
00216           }
00217         }
00218         MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
00219       }
00220       UNV2412::Write(out_stream,aDataSet2412);
00221     }
00222     {
00223       using namespace UNV2417;
00224       if (myGroups.size() > 0) {
00225         TDataSet aDataSet2417;
00226         TGroupList::const_iterator aIter = myGroups.begin();
00227         for (; aIter != myGroups.end(); aIter++) {
00228           SMESHDS_GroupBase* aGroupDS = *aIter;
00229           TRecord aRec;
00230           aRec.GroupName = aGroupDS->GetStoreName();
00231 
00232           int i;
00233           SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
00234           if (aGroupDS->GetType() == SMDSAbs_Node) {
00235             aRec.NodeList.resize(aGroupDS->Extent());
00236             i = 0;
00237             while (aIter->more()) {
00238               const SMDS_MeshElement* aElem = aIter->next();
00239               aRec.NodeList[i] = aElem->GetID(); 
00240               i++;
00241             }
00242           } else {
00243             aRec.ElementList.resize(aGroupDS->Extent());
00244             i = 0;
00245             while (aIter->more()) {
00246               const SMDS_MeshElement* aElem = aIter->next();
00247               aRec.ElementList[i] = aElem->GetID(); 
00248               i++;
00249             }
00250           }
00251           // 0019936: EDF 794 SMESH : Export UNV : Node color and group id
00252           //aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
00253           aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID()+1, aRec));
00254         }
00255         UNV2417::Write(out_stream,aDataSet2417);
00256         myGroups.clear();
00257       }
00258     }
00259     /*    {
00260       using namespace UNV2417;
00261       TDataSet aDataSet2417;
00262       for ( TGroupsMap::iterator it = myGroupsMap.begin(); it != myGroupsMap.end(); it++ ) {
00263         SMESH_Group*       aGroup   = it->second;
00264         SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
00265         if ( aGroupDS ) {
00266           TRecord aRec;
00267           aRec.GroupName = aGroup->GetName();
00268           int i;
00269           SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
00270           if (aGroupDS->GetType() == SMDSAbs_Node) {
00271             aRec.NodeList.resize(aGroupDS->Extent());
00272             i = 0;
00273             while (aIter->more()) {
00274               const SMDS_MeshElement* aElem = aIter->next();
00275               aRec.NodeList[i] = aElem->GetID(); 
00276               i++;
00277             }
00278           } else {
00279             aRec.ElementList.resize(aGroupDS->Extent());
00280             i = 0;
00281             while (aIter->more()) {
00282               const SMDS_MeshElement* aElem = aIter->next();
00283               aRec.ElementList[i] = aElem->GetID(); 
00284               i++;
00285             }
00286           }
00287           aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
00288         }
00289       }
00290       UNV2417::Write(out_stream,aDataSet2417);
00291       }*/
00292 
00293     out_stream.flush();
00294     out_stream.close();
00295     if (!check_file(myFile))
00296       EXCEPTION(runtime_error,"ERROR: Output file not good.");
00297   }
00298   catch(const std::exception& exc){
00299     INFOS("Follow exception was cought:\n\t"<<exc.what());
00300     throw;
00301   }
00302   catch(...){
00303     INFOS("Unknown exception was cought !!!");
00304     throw;
00305   }
00306   return aResult;
00307 }
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS