#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 );
+
+ 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;
+ commitDocOperation();
+ commit();
- return aRes;
+ module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
+ }
+
+ QApplication::restoreOverrideCursor();
}
+