X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_ImportProfilesOp.cxx;h=deaab0c3de442f6a06a0e9e01244806828bb371b;hb=dbee981213585cb317e098b0d2a288761cd3d37b;hp=e41732b2fa0eced39bb63ebd4f2916990ebbf5ba;hpb=63d2e34be4f1702765390c4a52833e338df5ca9f;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_ImportProfilesOp.cxx b/src/HYDROGUI/HYDROGUI_ImportProfilesOp.cxx index e41732b2..deaab0c3 100644 --- a/src/HYDROGUI/HYDROGUI_ImportProfilesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportProfilesOp.cxx @@ -1,12 +1,8 @@ -// Copyright (C) 2007-2013 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 -// +// Copyright (C) 2014-2015 EDF-R&D // 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 @@ -24,6 +20,8 @@ #include "HYDROGUI_DataModel.h" #include "HYDROGUI_Module.h" +#include "HYDROGUI_UpdateFlags.h" +#include "HYDROGUI_Tool.h" #include @@ -32,7 +30,9 @@ #include #include +#include +#include #include HYDROGUI_ImportProfilesOp::HYDROGUI_ImportProfilesOp( HYDROGUI_Module* theModule ) @@ -60,35 +60,88 @@ void HYDROGUI_ImportProfilesOp::startOperation() 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 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 ); + browseObjects( aBrowseObjectsEntries ); + } + + QApplication::restoreOverrideCursor(); } +