1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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 "DriverDAT_W_SMDS_Mesh.h"
27 #include "SMDS_Mesh.hxx"
29 #include "utilities.h"
31 #include <Basics_Utils.hxx>
35 Driver_Mesh::Status DriverDAT_W_SMDS_Mesh::Perform()
37 Kernel_Utils::Localizer loc;
38 Status aResult = DRS_OK;
43 char *file2Read = (char *)myFile.c_str();
44 FILE* aFileId = fopen(file2Read, "w+");
46 fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
50 /****************************************************************************
52 ****************************************************************************/
54 /* Combien de noeuds ? */
55 nbNodes = myMesh->NbNodes();
57 /* Combien de mailles, faces ou aretes ? */
58 int /*nb_of_nodes,*/ nb_of_edges, nb_of_faces, nb_of_volumes;
59 nb_of_edges = myMesh->NbEdges();
60 nb_of_faces = myMesh->NbFaces();
61 nb_of_volumes = myMesh->NbVolumes();
62 nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
65 SCRUTE(nb_of_volumes);
67 fprintf(stdout, "%d %d\n", nbNodes, nbCells);
68 fprintf(aFileId, "%d %d\n", nbNodes, nbCells);
70 /****************************************************************************
71 * ECRITURE DES NOEUDS *
72 ****************************************************************************/
74 SMDS_NodeIteratorPtr itNodes=myMesh->nodesIterator();
75 while(itNodes->more()){
76 const SMDS_MeshNode * node = itNodes->next();
77 fprintf(aFileId, "%d %e %e %e\n", node->GetID(), node->X(), node->Y(), node->Z());
80 /****************************************************************************
81 * ECRITURE DES ELEMENTS *
82 ****************************************************************************/
83 /* Ecriture des connectivites, noms, numeros des mailles */
85 SMDS_EdgeIteratorPtr itEdges=myMesh->edgesIterator();
86 while(itEdges->more()){
87 const SMDS_MeshElement * elem = itEdges->next();
88 switch (elem->NbNodes()) {
90 fprintf(aFileId, "%d %d ", elem->GetID(), 102);
93 fprintf(aFileId, "%d %d ", elem->GetID(), 103);
96 SMDS_ElemIteratorPtr it=elem->nodesIterator();
98 fprintf(aFileId, "%d ", it->next()->GetID());
99 fprintf(aFileId, "\n");
102 SMDS_FaceIteratorPtr itFaces=myMesh->facesIterator();
103 while(itFaces->more()){
104 const SMDS_MeshElement * elem = itFaces->next();
105 if ( elem->IsPoly() )
106 fprintf(aFileId, "%d %d ", elem->GetID(), 400+elem->NbNodes());
108 fprintf(aFileId, "%d %d ", elem->GetID(), 200+elem->NbNodes());
109 SMDS_ElemIteratorPtr it=elem->nodesIterator();
111 fprintf(aFileId, "%d ", it->next()->GetID());
112 fprintf(aFileId, "\n");
115 SMDS_VolumeIteratorPtr itVolumes=myMesh->volumesIterator();
116 while(itVolumes->more()){
117 const SMDS_MeshElement * elem = itVolumes->next();
118 if ( elem->IsPoly() )
119 fprintf(aFileId, "%d %d ", elem->GetID(), 500+elem->NbNodes());
121 fprintf(aFileId, "%d %d ", elem->GetID(), 300+elem->NbNodes());
122 SMDS_ElemIteratorPtr it=elem->nodesIterator();
124 fprintf(aFileId, "%d ", it->next()->GetID());
126 fprintf(aFileId, "\n");