-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "HYDROGUI_DataModel.h"
#include "HYDROGUI_Module.h"
#include "HYDROGUI_UpdateFlags.h"
+#include "HYDROGUI_Tool.h"
#include <HYDROData_Profile.h>
#include <SUIT_Desktop.h>
#include <SUIT_FileDlg.h>
+#include <SUIT_MessageBox.h>
+#include <QApplication>
#include <QFileInfo>
HYDROGUI_ImportProfilesOp::HYDROGUI_ImportProfilesOp( HYDROGUI_Module* theModule )
myFileDlg->exec();
}
-bool HYDROGUI_ImportProfilesOp::processApply( int& theUpdateFlags,
- QString& theErrorMsg )
+void HYDROGUI_ImportProfilesOp::onApply()
{
- if ( !myFileDlg ) {
- return false;
+ if ( !myFileDlg )
+ {
+ abort();
+ return;
}
- bool aRes = false;
-
// Get the selected files
QStringList aFileNames = myFileDlg->selectedFiles();
+ if ( aFileNames.isEmpty() )
+ {
+ abort();
+ return;
+ }
+
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+ QStringList aBrowseObjectsEntries;
+ //TODO: to implement the addition of imported profiles' entries to the list
+
+ startDocOperation();
// Import each of the selected files, fill the list of bad imported files
QString aBadImportedFiles;
- foreach ( const QString& aFileName, aFileNames ) {
- if ( !HYDROData_Profile::ImportFromFile( doc(), qPrintable( aFileName ) ) ) {
- aBadImportedFiles += aFileName + "\n";
+ int aTotalNbImported = 0;
+
+ foreach ( const QString& aFileName, aFileNames )
+ {
+ NCollection_Sequence<int> aBadProfilesIds;
+ TCollection_AsciiString anAsciiFileName = HYDROGUI_Tool::ToAsciiString( aFileName );
+
+ int aNbImported = HYDROData_Profile::ImportFromFile( doc(), anAsciiFileName, aBadProfilesIds );
+ if ( aNbImported == 0 || !aBadProfilesIds.IsEmpty() )
+ {
+ aBadImportedFiles += QFileInfo( aFileName ).fileName();
+ if ( !aBadProfilesIds.IsEmpty() && aNbImported > 0 )
+ {
+ aBadImportedFiles += ", " + tr( "BAD_PROFILE_IDS" ) + " : ";
+ for ( int i = 1, n = aBadProfilesIds.Length(); i <= n; ++i )
+ aBadImportedFiles += QString::number( aBadProfilesIds.Value( i ) ) + ", ";
+ aBadImportedFiles.remove( aBadImportedFiles.length() - 2, 2 );
+ }
+ aBadImportedFiles += ";\n";
}
+
+ aTotalNbImported += aNbImported;
}
- // Operation is successful if all the selected files imported succesfully
- if ( aBadImportedFiles.isEmpty() ) {
- aRes = true;
- } else {
- theErrorMsg = tr( "BAD_IMPORTED_PROFILES_FILES" ).arg( aBadImportedFiles );
+ if ( aTotalNbImported == 0 )
+ {
+ QApplication::restoreOverrideCursor();
+
+ SUIT_MessageBox::critical( module()->getApp()->desktop(),
+ tr( "BAD_IMPORTED_PROFILES_FILES_TLT" ),
+ tr( "NO_ONE_PROFILE_IMPORTED" ) );
+
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+
+ abortDocOperation();
abort();
}
+ else
+ {
+ if ( !aBadImportedFiles.isEmpty() )
+ {
+ QApplication::restoreOverrideCursor();
+
+ aBadImportedFiles = aBadImportedFiles.simplified();
+ SUIT_MessageBox::warning( module()->getApp()->desktop(),
+ tr( "BAD_IMPORTED_PROFILES_FILES_TLT" ),
+ tr( "BAD_IMPORTED_PROFILES_FILES" ).arg( aBadImportedFiles ) );
+
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+ }
- theUpdateFlags = UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
+ commitDocOperation();
+ commit();
- return aRes;
+ module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
+ browseObjects( aBrowseObjectsEntries );
+ }
+
+ QApplication::restoreOverrideCursor();
}
+