Back to index

salome-smesh  6.5.0
DriverDAT_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 <stdio.h>
00024 
00025 #include "DriverDAT_W_SMDS_Mesh.h"
00026 
00027 #include "SMDS_Mesh.hxx"
00028 
00029 #include "utilities.h"
00030 
00031 #include <Basics_Utils.hxx>
00032 
00033 using namespace std;
00034 
00035 Driver_Mesh::Status DriverDAT_W_SMDS_Mesh::Perform()
00036 {
00037   Kernel_Utils::Localizer loc;
00038   Status aResult = DRS_OK;
00039 
00040   int nbNodes, nbCells;
00041   //int i;
00042   
00043   char *file2Read = (char *)myFile.c_str();
00044   FILE* aFileId = fopen(file2Read, "w+");
00045   if (aFileId < 0) {
00046     fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
00047     return DRS_FAIL;
00048   }
00049   SCRUTE(myMesh);
00050   /****************************************************************************
00051    *                       NOMBRES D'OBJETS                                    *
00052    ****************************************************************************/
00053   fprintf(stdout, "\n(****************************)\n");
00054   fprintf(stdout, "(* INFORMATIONS GENERALES : *)\n");
00055   fprintf(stdout, "(****************************)\n");
00056   
00057   /* Combien de noeuds ? */
00058   nbNodes = myMesh->NbNodes();
00059   
00060   /* Combien de mailles, faces ou aretes ? */
00061   int /*nb_of_nodes,*/ nb_of_edges, nb_of_faces, nb_of_volumes;
00062   nb_of_edges = myMesh->NbEdges();
00063   nb_of_faces = myMesh->NbFaces();
00064   nb_of_volumes = myMesh->NbVolumes();
00065   nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
00066   SCRUTE(nb_of_edges);
00067   SCRUTE(nb_of_faces);
00068   SCRUTE(nb_of_volumes);
00069   
00070   fprintf(stdout, "%d %d\n", nbNodes, nbCells);
00071   fprintf(aFileId, "%d %d\n", nbNodes, nbCells);
00072   
00073   /****************************************************************************
00074    *                       ECRITURE DES NOEUDS                                 *
00075    ****************************************************************************/
00076   fprintf(stdout, "\n(************************)\n");
00077   fprintf(stdout, "(* NOEUDS DU MAILLAGE : *)\n");
00078   fprintf(stdout, "(************************)\n");
00079   
00080   SMDS_NodeIteratorPtr itNodes=myMesh->nodesIterator();
00081   while(itNodes->more()){               
00082     const SMDS_MeshNode * node = itNodes->next();
00083     fprintf(aFileId, "%d %e %e %e\n", node->GetID(), node->X(), node->Y(), node->Z());
00084   }
00085         
00086   /****************************************************************************
00087    *                       ECRITURE DES ELEMENTS                                *
00088    ****************************************************************************/
00089   fprintf(stdout, "\n(**************************)\n");
00090   fprintf(stdout, "(* ELEMENTS DU MAILLAGE : *)\n");
00091   fprintf(stdout, "(**************************)");
00092   /* Ecriture des connectivites, noms, numeros des mailles */
00093   
00094   SMDS_EdgeIteratorPtr itEdges=myMesh->edgesIterator();
00095   while(itEdges->more()){
00096     const SMDS_MeshElement * elem = itEdges->next();
00097     switch (elem->NbNodes()) {
00098     case 2:
00099       fprintf(aFileId, "%d %d ", elem->GetID(), 102);
00100       break;
00101     case 3:
00102       fprintf(aFileId, "%d %d ", elem->GetID(), 103);
00103       break;
00104     }
00105     SMDS_ElemIteratorPtr it=elem->nodesIterator();
00106     while(it->more()) 
00107       fprintf(aFileId, "%d ", it->next()->GetID());
00108     fprintf(aFileId, "\n");
00109   }
00110   
00111   SMDS_FaceIteratorPtr itFaces=myMesh->facesIterator();
00112   while(itFaces->more()){
00113     const SMDS_MeshElement * elem = itFaces->next();
00114     switch (elem->NbNodes()) {
00115     case 3:
00116       fprintf(aFileId, "%d %d ", elem->GetID(), 203);
00117       break;
00118     case 4:
00119       fprintf(aFileId, "%d %d ", elem->GetID(), 204);
00120       break;
00121     case 6:
00122       fprintf(aFileId, "%d %d ", elem->GetID(), 206);
00123       break;
00124     }
00125     SMDS_ElemIteratorPtr it=elem->nodesIterator();
00126     while(it->more()) 
00127       fprintf(aFileId, "%d ", it->next()->GetID());
00128     fprintf(aFileId, "\n");
00129   }
00130 
00131   SMDS_VolumeIteratorPtr itVolumes=myMesh->volumesIterator();
00132   while(itVolumes->more()){
00133     const SMDS_MeshElement * elem = itVolumes->next();
00134     switch (elem->NbNodes()) {
00135     case 8:
00136       fprintf(aFileId, "%d %d ", elem->GetID(), 308);
00137       break;
00138     }
00139 
00140     SMDS_ElemIteratorPtr it=elem->nodesIterator();
00141     while(it->more()) 
00142       fprintf(aFileId, "%d ", it->next()->GetID());
00143 
00144     fprintf(aFileId, "\n");
00145   }
00146   
00147   fclose(aFileId);
00148 
00149   return aResult;
00150 }