Salome HOME
Fix for the bug #255: VTK viewer is not updated after modification of objects.
[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 #include "HYDROGUI_UpdateFlags.h"
28
29 #include <HYDROData_Profile.h>
30
31 #include <LightApp_Application.h>
32 #include <LightApp_UpdateFlags.h>
33
34 #include <SUIT_Desktop.h>
35 #include <SUIT_FileDlg.h>
36
37 #include <QFileInfo>
38
39 HYDROGUI_ImportProfilesOp::HYDROGUI_ImportProfilesOp( HYDROGUI_Module* theModule )
40 : HYDROGUI_Operation( theModule )
41 {
42   setName( tr( "IMPORT_PROFILES" ) );
43 }
44
45 HYDROGUI_ImportProfilesOp::~HYDROGUI_ImportProfilesOp()
46 {
47 }
48
49 void HYDROGUI_ImportProfilesOp::startOperation()
50 {
51   HYDROGUI_Operation::startOperation();
52
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") );
57
58   connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
59   connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
60
61   myFileDlg->exec();
62 }
63
64 bool HYDROGUI_ImportProfilesOp::processApply( int& theUpdateFlags,
65                                               QString& theErrorMsg )
66 {
67   if ( !myFileDlg ) {
68     return false;
69   }
70
71   bool aRes = false;
72
73   // Get the selected files
74   QStringList aFileNames = myFileDlg->selectedFiles();
75
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";
81     }
82   }
83
84   // Operation is successful if all the selected files imported succesfully
85   if ( aBadImportedFiles.isEmpty() ) {
86     aRes = true;
87   } else {
88     theErrorMsg = tr( "BAD_IMPORTED_PROFILES_FILES" ).arg( aBadImportedFiles );
89     abort();
90   }
91
92   theUpdateFlags = UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
93
94   return aRes;
95 }