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"
27 #include "HYDROGUI_UpdateFlags.h"
29 #include <HYDROData_Profile.h>
31 #include <LightApp_Application.h>
32 #include <LightApp_UpdateFlags.h>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_FileDlg.h>
39 HYDROGUI_ImportProfilesOp::HYDROGUI_ImportProfilesOp( HYDROGUI_Module* theModule )
40 : HYDROGUI_Operation( theModule )
42 setName( tr( "IMPORT_PROFILES" ) );
45 HYDROGUI_ImportProfilesOp::~HYDROGUI_ImportProfilesOp()
49 void HYDROGUI_ImportProfilesOp::startOperation()
51 HYDROGUI_Operation::startOperation();
53 myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
54 myFileDlg->setWindowTitle( getName() );
55 myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles );
56 myFileDlg->setFilter( tr("PROFILE_FILTER") );
58 connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
59 connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
64 bool HYDROGUI_ImportProfilesOp::processApply( int& theUpdateFlags,
65 QString& theErrorMsg )
73 // Get the selected files
74 QStringList aFileNames = myFileDlg->selectedFiles();
76 // Import each of the selected files, fill the list of bad imported files
77 QString aBadImportedFiles;
78 foreach ( const QString& aFileName, aFileNames ) {
79 if ( !HYDROData_Profile::ImportFromFile( doc(), qPrintable( aFileName ) ) ) {
80 aBadImportedFiles += aFileName + "\n";
84 // Operation is successful if all the selected files imported succesfully
85 if ( aBadImportedFiles.isEmpty() ) {
88 theErrorMsg = tr( "BAD_IMPORTED_PROFILES_FILES" ).arg( aBadImportedFiles );
92 theUpdateFlags = UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;