From: mzn Date: Tue, 26 Nov 2013 11:55:23 +0000 (+0000) Subject: Feature #83: Import profiles (T12.3). X-Git-Tag: issue_132_11_28~26 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=63d2e34be4f1702765390c4a52833e338df5ca9f;p=modules%2Fhydro.git Feature #83: Import profiles (T12.3). --- diff --git a/src/HYDROData/HYDROData_Profile.cxx b/src/HYDROData/HYDROData_Profile.cxx index 9832cadb..2c4088c0 100755 --- a/src/HYDROData/HYDROData_Profile.cxx +++ b/src/HYDROData/HYDROData_Profile.cxx @@ -345,7 +345,7 @@ bool HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc // Close the file aFile.Close(); - for ( int i = 1, n = aCreatedProfiles.Length(); i < n ; ++i ) + for ( int i = 1, n = aCreatedProfiles.Length(); i <= n ; ++i ) { Handle(HYDROData_Profile) aProfile = aCreatedProfiles.Value( i ); if ( aRes ) diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index d3339b91..06a664cc 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -66,6 +66,7 @@ set(PROJECT_HEADERS HYDROGUI_ObstacleDlg.h HYDROGUI_SetColorOp.h HYDROGUI_ColorDlg.h + HYDROGUI_ImportProfilesOp.h ) QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS}) @@ -133,6 +134,7 @@ set(PROJECT_SOURCES HYDROGUI_ObstacleDlg.cxx HYDROGUI_SetColorOp.cxx HYDROGUI_ColorDlg.cxx + HYDROGUI_ImportProfilesOp.cxx ) add_definitions( diff --git a/src/HYDROGUI/HYDROGUI_ImportProfilesOp.cxx b/src/HYDROGUI/HYDROGUI_ImportProfilesOp.cxx new file mode 100644 index 00000000..e41732b2 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImportProfilesOp.cxx @@ -0,0 +1,94 @@ +// 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 +// +// 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. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_ImportProfilesOp.h" + +#include "HYDROGUI_DataModel.h" +#include "HYDROGUI_Module.h" + +#include + +#include +#include + +#include +#include + +#include + +HYDROGUI_ImportProfilesOp::HYDROGUI_ImportProfilesOp( HYDROGUI_Module* theModule ) +: HYDROGUI_Operation( theModule ) +{ + setName( tr( "IMPORT_PROFILES" ) ); +} + +HYDROGUI_ImportProfilesOp::~HYDROGUI_ImportProfilesOp() +{ +} + +void HYDROGUI_ImportProfilesOp::startOperation() +{ + HYDROGUI_Operation::startOperation(); + + myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true ); + myFileDlg->setWindowTitle( getName() ); + myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles ); + myFileDlg->setFilter( tr("PROFILE_FILTER") ); + + connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) ); + connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) ); + + myFileDlg->exec(); +} + +bool HYDROGUI_ImportProfilesOp::processApply( int& theUpdateFlags, + QString& theErrorMsg ) +{ + if ( !myFileDlg ) { + return false; + } + + bool aRes = false; + + // Get the selected files + QStringList aFileNames = myFileDlg->selectedFiles(); + + // 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"; + } + } + + // Operation is successful if all the selected files imported succesfully + if ( aBadImportedFiles.isEmpty() ) { + aRes = true; + } else { + theErrorMsg = tr( "BAD_IMPORTED_PROFILES_FILES" ).arg( aBadImportedFiles ); + abort(); + } + + theUpdateFlags = UF_Model; + + return aRes; +} diff --git a/src/HYDROGUI/HYDROGUI_ImportProfilesOp.h b/src/HYDROGUI/HYDROGUI_ImportProfilesOp.h new file mode 100644 index 00000000..4779988d --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImportProfilesOp.h @@ -0,0 +1,47 @@ +// 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 +// +// 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. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_IMPORTPROFILES_H +#define HYDROGUI_IMPORTPROFILES_H + +#include "HYDROGUI_Operation.h" + +class SUIT_FileDlg; + +class HYDROGUI_ImportProfilesOp : public HYDROGUI_Operation +{ + Q_OBJECT + +public: + HYDROGUI_ImportProfilesOp( HYDROGUI_Module* theModule ); + virtual ~HYDROGUI_ImportProfilesOp(); + +protected: + virtual void startOperation(); + + virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); + +private: + SUIT_FileDlg* myFileDlg; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index ccaa4c0d..4a3ad4ca 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -318,6 +318,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, break; case KIND_PROFILE: theMenu->addAction( action( CreateProfileId ) ); + theMenu->addAction( action( ImportProfilesId ) ); break; case KIND_VISUAL_STATE: theMenu->addAction( action( SaveVisualStateId ) ); diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index a7837f20..8eeee9a6 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -45,6 +45,7 @@ #include "HYDROGUI_ImportGeomObjectOp.h" #include "HYDROGUI_ImportObstacleFromFileOp.h" #include "HYDROGUI_ExportCalculationOp.h" +#include "HYDROGUI_ImportProfilesOp.h" #include "HYDROGUI_SetColorOp.h" #include "HYDROData_Document.h" @@ -106,6 +107,7 @@ void HYDROGUI_Module::createActions() createAction( EditPolylineId, "EDIT_POLYLINE" ); createAction( CreateProfileId, "CREATE_PROFILE" ); + createAction( ImportProfilesId, "IMPORT_PROFILES" ); createAction( EditProfileId, "EDIT_PROFILE" ); createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::Key_B ); @@ -162,7 +164,11 @@ void HYDROGUI_Module::createMenus() createMenu( ImportImageId, aHydroId, -1, -1 ); createMenu( ImportBathymetryId, aHydroId, -1, -1 ); createMenu( CreatePolylineId, aHydroId, -1, -1 ); - createMenu( CreateProfileId, aHydroId, -1, -1 ); + + int aNewProfileId = createMenu( tr( "MEN_PROFILE" ), aHydroId, -1 ); + createMenu( CreateProfileId, aNewProfileId, -1, -1 ); + createMenu( ImportProfilesId, aNewProfileId, -1, -1 ); + createMenu( CreateImmersibleZoneId, aHydroId, -1, -1 ); int aNewObstacleId = createMenu( tr( "MEN_OBSTACLE" ), aHydroId, -1 ); @@ -330,6 +336,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case EditProfileId: anOp = new HYDROGUI_ProfileOp( aModule, theId == EditProfileId ); break; + case ImportProfilesId: + anOp = new HYDROGUI_ImportProfilesOp( aModule ) ; + break; case ImportBathymetryId: anOp = new HYDROGUI_ImportBathymetryOp( aModule ); break; diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index 18f5854c..f789e86c 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -46,6 +46,7 @@ enum OperationId CreatePolylineId, EditPolylineId, + ImportProfilesId, CreateProfileId, EditProfileId, @@ -74,8 +75,6 @@ enum OperationId CreateBoxId, CreateCylinderId, - ImportProfilesId, - DeleteId, ShowId, diff --git a/src/HYDROGUI/HYDROGUI_ProfileOp.h b/src/HYDROGUI/HYDROGUI_ProfileOp.h index 62df8afc..ac86f4c1 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileOp.h +++ b/src/HYDROGUI/HYDROGUI_ProfileOp.h @@ -61,7 +61,7 @@ private: //OCCViewer_ViewManager* myViewManager; bool myIsEdit; - Handle(HYDROData_Profile) myEditedObject; + Handle(HYDROData_Profile) myEditedObject; CurveCreator_Curve* myCurve; }; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 0fa1b04d..3ec3da74 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -468,6 +468,10 @@ file cannot be correctly imported for a Bathymetry definition. DSK_CREATE_PROFILE Create profile + + DSK_IMPORT_PROFILES + Import profiles from file(s) + DSK_CREATE_IMMERSIBLE_ZONE Create immersible zone @@ -620,6 +624,10 @@ file cannot be correctly imported for a Bathymetry definition. MEN_CREATE_PROFILE Create profile + + MEN_IMPORT_PROFILES + Import profiles + MEN_CREATE_ZONE Create zone @@ -752,6 +760,10 @@ file cannot be correctly imported for a Bathymetry definition. MEN_OBSTACLE Obstacle + + MEN_PROFILE + Profile + MEN_IMPORT_OBSTACLE_FROM_FILE Import obstacle @@ -784,6 +796,10 @@ file cannot be correctly imported for a Bathymetry definition. STB_CREATE_PROFILE Create profile + + STB_IMPORT_PROFILES + Import profiles from file(s) + STB_CREATE_IMMERSIBLE_ZONE Create immersible zone @@ -1255,6 +1271,24 @@ file cannot be correctly imported for an Obstacle definition. + + HYDROGUI_ImportProfilesOp + + IMPORT_PROFILES + Import profiles + + + PROFILE_FILTER + All files (*.* *) + + + BAD_IMPORTED_PROFILES_FILES + The following files cannot be correctly imported for a Profile definition: +%1 + + + + HYDROGUI_SetColorOp