Salome HOME
e5ea9d0d35c7d9fefdbd1a538feaf8ee5d62e084
[modules/smesh.git] / src / DriverDAT / DriverDAT_W_SMDS_Mesh.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <stdio.h>
24
25 #include "DriverDAT_W_SMDS_Mesh.h"
26
27 #include "SMDS_Mesh.hxx"
28
29 #include "utilities.h"
30
31 #include <Basics_Utils.hxx>
32
33 using namespace std;
34
35 Driver_Mesh::Status DriverDAT_W_SMDS_Mesh::Perform()
36 {
37   Kernel_Utils::Localizer loc;
38   Status aResult = DRS_OK;
39
40   int nbNodes, nbCells;
41   //int i;
42   
43   char *file2Read = (char *)myFile.c_str();
44   FILE* aFileId = fopen(file2Read, "w+");
45   if (aFileId < 0) {
46     fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
47     return DRS_FAIL;
48   }
49   SCRUTE(myMesh);
50   /****************************************************************************
51    *                       NOMBRES D'OBJETS                                    *
52    ****************************************************************************/
53   
54   /* Combien de noeuds ? */
55   nbNodes = myMesh->NbNodes();
56   
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;
63   SCRUTE(nb_of_edges);
64   SCRUTE(nb_of_faces);
65   SCRUTE(nb_of_volumes);
66   
67   fprintf(stdout, "%d %d\n", nbNodes, nbCells);
68   fprintf(aFileId, "%d %d\n", nbNodes, nbCells);
69   
70   /****************************************************************************
71    *                       ECRITURE DES NOEUDS                                 *
72    ****************************************************************************/
73   
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());
78   }
79         
80   /****************************************************************************
81    *                       ECRITURE DES ELEMENTS                                *
82    ****************************************************************************/
83   /* Ecriture des connectivites, noms, numeros des mailles */
84   
85   SMDS_EdgeIteratorPtr itEdges=myMesh->edgesIterator();
86   while(itEdges->more()){
87     const SMDS_MeshElement * elem = itEdges->next();
88     switch (elem->NbNodes()) {
89     case 2:
90       fprintf(aFileId, "%d %d ", elem->GetID(), 102);
91       break;
92     case 3:
93       fprintf(aFileId, "%d %d ", elem->GetID(), 103);
94       break;
95     }
96     SMDS_ElemIteratorPtr it=elem->nodesIterator();
97     while(it->more()) 
98       fprintf(aFileId, "%d ", it->next()->GetID());
99     fprintf(aFileId, "\n");
100   }
101   
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());
107     else
108       fprintf(aFileId, "%d %d ", elem->GetID(), 200+elem->NbNodes());
109     SMDS_ElemIteratorPtr it=elem->nodesIterator();
110     while(it->more()) 
111       fprintf(aFileId, "%d ", it->next()->GetID());
112     fprintf(aFileId, "\n");
113   }
114
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());
120     else
121       fprintf(aFileId, "%d %d ", elem->GetID(), 300+elem->NbNodes());
122     SMDS_ElemIteratorPtr it=elem->nodesIterator();
123     while(it->more()) 
124       fprintf(aFileId, "%d ", it->next()->GetID());
125
126     fprintf(aFileId, "\n");
127   }
128   
129   fclose(aFileId);
130
131   return aResult;
132 }