1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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.
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_ExportMeshOp.cxx
25 // Author : Alexander SOLOVYOV
29 #include "SMESHGUI_ExportMeshOp.h"
30 #include <SMESHGUI_MeshUtils.h>
31 #include <SMESHGUI_Utils.h>
33 #include <SalomeApp_SelectionMgr.h>
34 #include <SUIT_FileDlg.h>
35 #include <SUIT_MessageBox.h>
36 #include <SUIT_Desktop.h>
37 #include <SUIT_OverrideCursor.h>
39 #include <SALOME_ListIO.hxx>
41 //=================================================================================
44 //=================================================================================
45 SMESHGUI_ExportMeshOp::SMESHGUI_ExportMeshOp( const Type t )
46 : SMESHGUI_Operation(),
51 //=================================================================================
54 //=================================================================================
55 SMESHGUI_ExportMeshOp::~SMESHGUI_ExportMeshOp()
59 //=================================================================================
62 //=================================================================================
63 void SMESHGUI_ExportMeshOp::startOperation()
65 SMESHGUI_Operation::startOperation();
67 SalomeApp_SelectionMgr *aSel = selectionMgr();
68 SALOME_ListIO selected;
70 aSel->selectedObjects( selected );
72 if( selected.Extent()==0 )
78 Handle(SALOME_InteractiveObject) anIObject = selected.First();
79 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
80 if( !aMesh->_is_nil() )
82 QString aFilter, aTitle = QObject::tr("Export mesh");
83 QMap<QString, SMESH::MED_VERSION> aFilterMap;
87 aFilterMap.insert( QObject::tr("MED 2.1 (*.med)"), SMESH::MED_V2_1 );
88 aFilterMap.insert( QObject::tr("MED 2.2 (*.med)"), SMESH::MED_V2_2 );
92 aFilter = QObject::tr("DAT files (*.dat)");
96 if( aMesh->NbPyramids() )
98 int aRet = SUIT_MessageBox::warn2( desktop(), tr("SMESH_WRN_WARNING"),
99 tr("SMESH_EXPORT_UNV").arg(anIObject->getName()), tr("SMESH_BUT_YES"),
100 tr("SMESH_BUT_NO"), 0,1,0 );
107 aFilter = QObject::tr("IDEAS files (*.unv)");
115 SMESH::MED_VERSION aFormat;
118 aFilename = SUIT_FileDlg::getFileName( desktop(), "", aFilter, aTitle, false );
122 for( QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin(); it != aFilterMap.end(); ++it )
123 filters.push_back( it.key() );
125 SUIT_FileDlg* fd = new SUIT_FileDlg( desktop(), false, true, true );
126 fd->setCaption( aTitle );
127 fd->setFilters( filters );
132 aFilename = fd->selectedFile();
133 aFormat = aFilterMap[fd->selectedFilter()];
135 if( !aFilename.isEmpty() && (aMesh->NbPolygons()>0 or aMesh->NbPolyhedrons()>0 ) && aFormat==SMESH::MED_V2_1)
137 int aRet = SUIT_MessageBox::warn2( desktop(), tr("SMESH_WRN_WARNING"),
138 tr("SMESH_EXPORT_MED_V2_1").arg(anIObject->getName()), tr("SMESH_BUT_YES"),
139 tr("SMESH_BUT_NO"), 0,1,0 );
147 if( !aFilename.isEmpty() )
149 // Check whether the file already exists and delete it if yes
150 QFile aFile( aFilename );
153 SUIT_OverrideCursor wc;
157 aMesh->ExportToMED( aFilename.latin1(), false, aFormat ); // currently, automatic groups are never created
161 aMesh->ExportDAT( aFilename.latin1() );
165 aMesh->ExportUNV( aFilename.latin1() );