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"
28 #include "HYDROGUI_Tool.h"
30 #include <HYDROData_Profile.h>
32 #include <LightApp_Application.h>
33 #include <LightApp_UpdateFlags.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_FileDlg.h>
37 #include <SUIT_MessageBox.h>
39 #include <QApplication>
42 HYDROGUI_ImportProfilesOp::HYDROGUI_ImportProfilesOp( HYDROGUI_Module* theModule )
43 : HYDROGUI_Operation( theModule )
45 setName( tr( "IMPORT_PROFILES" ) );
48 HYDROGUI_ImportProfilesOp::~HYDROGUI_ImportProfilesOp()
52 void HYDROGUI_ImportProfilesOp::startOperation()
54 HYDROGUI_Operation::startOperation();
56 myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
57 myFileDlg->setWindowTitle( getName() );
58 myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles );
59 myFileDlg->setFilter( tr("PROFILE_FILTER") );
61 connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
62 connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
67 void HYDROGUI_ImportProfilesOp::onApply()
75 // Get the selected files
76 QStringList aFileNames = myFileDlg->selectedFiles();
77 if ( aFileNames.isEmpty() )
83 QApplication::setOverrideCursor( Qt::WaitCursor );
87 // Import each of the selected files, fill the list of bad imported files
88 QString aBadImportedFiles;
89 int aTotalNbImported = 0;
91 foreach ( const QString& aFileName, aFileNames )
93 NCollection_Sequence<int> aBadProfilesIds;
94 TCollection_AsciiString anAsciiFileName = HYDROGUI_Tool::ToAsciiString( aFileName );
96 int aNbImported = HYDROData_Profile::ImportFromFile( doc(), anAsciiFileName, aBadProfilesIds );
97 if ( aNbImported == 0 || !aBadProfilesIds.IsEmpty() )
99 aBadImportedFiles += QFileInfo( aFileName ).fileName();
100 if ( !aBadProfilesIds.IsEmpty() && aNbImported > 0 )
102 aBadImportedFiles += ", " + tr( "BAD_PROFILE_IDS" ) + " : ";
103 for ( int i = 1, n = aBadProfilesIds.Length(); i <= n; ++i )
104 aBadImportedFiles += QString::number( aBadProfilesIds.Value( i ) ) + ", ";
105 aBadImportedFiles.remove( aBadImportedFiles.length() - 2, 2 );
107 aBadImportedFiles += ";\n";
110 aTotalNbImported += aNbImported;
113 if ( aTotalNbImported == 0 )
115 QApplication::restoreOverrideCursor();
117 SUIT_MessageBox::critical( module()->getApp()->desktop(),
118 tr( "BAD_IMPORTED_PROFILES_FILES_TLT" ),
119 tr( "NO_ONE_PROFILE_IMPORTED" ) );
121 QApplication::setOverrideCursor( Qt::WaitCursor );
128 if ( !aBadImportedFiles.isEmpty() )
130 QApplication::restoreOverrideCursor();
132 aBadImportedFiles = aBadImportedFiles.simplified();
133 SUIT_MessageBox::warning( module()->getApp()->desktop(),
134 tr( "BAD_IMPORTED_PROFILES_FILES_TLT" ),
135 tr( "BAD_IMPORTED_PROFILES_FILES" ).arg( aBadImportedFiles ) );
137 QApplication::setOverrideCursor( Qt::WaitCursor );
140 commitDocOperation();
143 module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
146 QApplication::restoreOverrideCursor();