1 // Copyright (C) 2007-2013 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.
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
23 #include "HYDROGUI_ImportProfilesOp.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_Module.h"
28 #include <HYDROData_Profile.h>
30 #include <LightApp_Application.h>
31 #include <LightApp_UpdateFlags.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_FileDlg.h>
38 HYDROGUI_ImportProfilesOp::HYDROGUI_ImportProfilesOp( HYDROGUI_Module* theModule )
39 : HYDROGUI_Operation( theModule )
41 setName( tr( "IMPORT_PROFILES" ) );
44 HYDROGUI_ImportProfilesOp::~HYDROGUI_ImportProfilesOp()
48 void HYDROGUI_ImportProfilesOp::startOperation()
50 HYDROGUI_Operation::startOperation();
52 myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
53 myFileDlg->setWindowTitle( getName() );
54 myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles );
55 myFileDlg->setFilter( tr("PROFILE_FILTER") );
57 connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
58 connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
63 bool HYDROGUI_ImportProfilesOp::processApply( int& theUpdateFlags,
64 QString& theErrorMsg )
72 // Get the selected files
73 QStringList aFileNames = myFileDlg->selectedFiles();
75 // Import each of the selected files, fill the list of bad imported files
76 QString aBadImportedFiles;
77 foreach ( const QString& aFileName, aFileNames ) {
78 if ( !HYDROData_Profile::ImportFromFile( doc(), qPrintable( aFileName ) ) ) {
79 aBadImportedFiles += aFileName + "\n";
83 // Operation is successful if all the selected files imported succesfully
84 if ( aBadImportedFiles.isEmpty() ) {
87 theErrorMsg = tr( "BAD_IMPORTED_PROFILES_FILES" ).arg( aBadImportedFiles );
91 theUpdateFlags = UF_Model;