Salome HOME
The bathymetry is changed to their base altitude class for geometry objects (Bug...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportProfilesOp.cxx
1 // Copyright (C) 2007-2013  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.
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 "HYDROGUI_ImportProfilesOp.h"
24
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_Module.h"
27
28 #include <HYDROData_Profile.h>
29
30 #include <LightApp_Application.h>
31 #include <LightApp_UpdateFlags.h>
32
33 #include <SUIT_Desktop.h>
34 #include <SUIT_FileDlg.h>
35
36 #include <QFileInfo>
37
38 HYDROGUI_ImportProfilesOp::HYDROGUI_ImportProfilesOp( HYDROGUI_Module* theModule )
39 : HYDROGUI_Operation( theModule )
40 {
41   setName( tr( "IMPORT_PROFILES" ) );
42 }
43
44 HYDROGUI_ImportProfilesOp::~HYDROGUI_ImportProfilesOp()
45 {
46 }
47
48 void HYDROGUI_ImportProfilesOp::startOperation()
49 {
50   HYDROGUI_Operation::startOperation();
51
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") );
56
57   connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
58   connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
59
60   myFileDlg->exec();
61 }
62
63 bool HYDROGUI_ImportProfilesOp::processApply( int& theUpdateFlags,
64                                               QString& theErrorMsg )
65 {
66   if ( !myFileDlg ) {
67     return false;
68   }
69
70   bool aRes = false;
71
72   // Get the selected files
73   QStringList aFileNames = myFileDlg->selectedFiles();
74
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";
80     }
81   }
82
83   // Operation is successful if all the selected files imported succesfully
84   if ( aBadImportedFiles.isEmpty() ) {
85     aRes = true;
86   } else {
87     theErrorMsg = tr( "BAD_IMPORTED_PROFILES_FILES" ).arg( aBadImportedFiles );
88     abort();
89   }
90
91   theUpdateFlags = UF_Model;
92
93   return aRes;
94 }