1 // Copyright (C) 2007-2019 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;
41 #if defined(WIN32) && defined(UNICODE)
42 std::wstring file2Read = Kernel_Utils::utf8_decode_s(myFile);
43 FILE* aFileId = _wfopen(file2Read.c_str(), L"w+");
46 char *file2Read = (char *)myFile.c_str();
47 FILE* aFileId = fopen(file2Read, "w+");
51 fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
55 /****************************************************************************
57 ****************************************************************************/
59 /* Combien de noeuds ? */
60 nbNodes = myMesh->NbNodes();
62 /* Combien de mailles, faces ou aretes ? */
63 int nb_of_edges, nb_of_faces, nb_of_volumes;
64 nb_of_edges = myMesh->NbEdges();
65 nb_of_faces = myMesh->NbFaces();
66 nb_of_volumes = myMesh->NbVolumes();
67 nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
70 SCRUTE(nb_of_volumes);
72 //fprintf(stdout, "%d %d\n", nbNodes, nbCells);
73 fprintf(aFileId, "%d %d\n", nbNodes, nbCells);
75 /****************************************************************************
76 * ECRITURE DES NOEUDS *
77 ****************************************************************************/
79 SMDS_NodeIteratorPtr itNodes=myMesh->nodesIterator();
80 while(itNodes->more())
82 const SMDS_MeshNode * node = itNodes->next();
83 fprintf(aFileId, "%d %.14e %.14e %.14e\n", node->GetID(), node->X(), node->Y(), node->Z());
86 /****************************************************************************
87 * ECRITURE DES ELEMENTS *
88 ****************************************************************************/
89 /* Ecriture des connectivites, noms, numeros des mailles */
91 SMDS_EdgeIteratorPtr itEdges=myMesh->edgesIterator();
92 while(itEdges->more())
94 const SMDS_MeshElement * elem = itEdges->next();
95 switch (elem->NbNodes())
98 fprintf(aFileId, "%d %d ", elem->GetID(), 102);
101 fprintf(aFileId, "%d %d ", elem->GetID(), 103);
104 SMDS_ElemIteratorPtr it=elem->nodesIterator();
106 fprintf(aFileId, "%d ", it->next()->GetID());
107 fprintf(aFileId, "\n");
110 SMDS_FaceIteratorPtr itFaces=myMesh->facesIterator();
111 while(itFaces->more())
113 const SMDS_MeshElement * elem = itFaces->next();
114 if ( elem->IsPoly() )
115 fprintf(aFileId, "%d %d ", elem->GetID(), 400+elem->NbNodes());
117 fprintf(aFileId, "%d %d ", elem->GetID(), 200+elem->NbNodes());
118 SMDS_ElemIteratorPtr it=elem->nodesIterator();
120 fprintf(aFileId, "%d ", it->next()->GetID());
121 fprintf(aFileId, "\n");
124 SMDS_VolumeIteratorPtr itVolumes=myMesh->volumesIterator();
125 const SMDS_MeshVolume* v;
126 while(itVolumes->more())
128 const SMDS_MeshElement * elem = itVolumes->next();
129 if ( elem->IsPoly() )
131 fprintf(aFileId, "%d %d ", elem->GetID(), 500+elem->NbNodes());
133 if (( v = myMesh->DownCast< SMDS_MeshVolume >( elem )))
135 std::vector<int> quant = v->GetQuantities();
136 if ( !quant.empty() )
138 fprintf(aFileId, "%d %d ", (int)quant.size(), quant[0]);
139 for ( size_t i = 1; i < quant.size(); ++i )
140 fprintf(aFileId, "%d ", quant[i]);
146 fprintf(aFileId, "%d %d ", elem->GetID(), 300+elem->NbNodes());
148 SMDS_ElemIteratorPtr it=elem->nodesIterator();
150 fprintf(aFileId, "%d ", it->next()->GetID());
152 fprintf(aFileId, "\n");