]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Feature #83: Import profiles (T12.3).
authormzn <mzn@opencascade.com>
Tue, 26 Nov 2013 11:55:23 +0000 (11:55 +0000)
committermzn <mzn@opencascade.com>
Tue, 26 Nov 2013 11:55:23 +0000 (11:55 +0000)
src/HYDROData/HYDROData_Profile.cxx
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_ImportProfilesOp.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_ImportProfilesOp.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/HYDROGUI_Operations.h
src/HYDROGUI/HYDROGUI_ProfileOp.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index 9832cadb3a4a47fa95a35795a1d2ec5da90c2af5..2c4088c0f0a5f0e04d6f96838165cdeb45733d6c 100755 (executable)
@@ -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 )
index d3339b91e2b3d94621f4d09ac7da5afdf8f650ff..06a664cc595584fa67e1b87d59feaf44cf9c2f82 100644 (file)
@@ -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 (file)
index 0000000..e41732b
--- /dev/null
@@ -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 <HYDROData_Profile.h>
+
+#include <LightApp_Application.h>
+#include <LightApp_UpdateFlags.h>
+
+#include <SUIT_Desktop.h>
+#include <SUIT_FileDlg.h>
+
+#include <QFileInfo>
+
+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 (file)
index 0000000..4779988
--- /dev/null
@@ -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
index ccaa4c0d0c7999ce5b4d42151cfa4276a857554c..4a3ad4ca8ebfca32b45dbb6c886d571ce29315fc 100644 (file)
@@ -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 ) );
index a7837f20976d8f2391a91fc2925e99e3394dccc9..8eeee9a60f733da982cf832c94be561a1824efda 100644 (file)
@@ -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;
index 18f5854c823035d9f7ae84d68afb4ac14ace050b..f789e86c58034ae35b630ea94e52db4a7d2ba830 100644 (file)
@@ -46,6 +46,7 @@ enum OperationId
   CreatePolylineId,
   EditPolylineId,
   
+  ImportProfilesId,
   CreateProfileId,
   EditProfileId,
   
@@ -74,8 +75,6 @@ enum OperationId
   CreateBoxId,
   CreateCylinderId,
 
-  ImportProfilesId,
-
   DeleteId,
 
   ShowId,
index 62df8afcd28d925e3d10af0bfd3f8834d41c61b2..ac86f4c1394f45a56530b1dc82e415348f6eddda 100644 (file)
@@ -61,7 +61,7 @@ private:
   //OCCViewer_ViewManager*     myViewManager;
 
   bool                       myIsEdit;
-  Handle(HYDROData_Profile) myEditedObject;
+  Handle(HYDROData_Profile)  myEditedObject;
   CurveCreator_Curve*        myCurve;
 };
 
index 0fa1b04d374cc8d48e84e9df587464a0bb9997c1..3ec3da74d5af6481009c3a4f692757ad586af538 100644 (file)
@@ -468,6 +468,10 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <source>DSK_CREATE_PROFILE</source>
       <translation>Create profile</translation>
     </message>
+    <message>
+      <source>DSK_IMPORT_PROFILES</source>
+      <translation>Import profiles from file(s)</translation>
+    </message>
     <message>
       <source>DSK_CREATE_IMMERSIBLE_ZONE</source>
       <translation>Create immersible zone</translation>
@@ -620,6 +624,10 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <source>MEN_CREATE_PROFILE</source>
       <translation>Create profile</translation>
     </message>
+    <message>
+      <source>MEN_IMPORT_PROFILES</source>
+      <translation>Import profiles</translation>
+    </message>
     <message>
       <source>MEN_CREATE_ZONE</source>
       <translation>Create zone</translation>
@@ -752,6 +760,10 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <source>MEN_OBSTACLE</source>
       <translation>Obstacle</translation>
     </message>
+    <message>
+      <source>MEN_PROFILE</source>
+      <translation>Profile</translation>
+    </message>
     <message>
       <source>MEN_IMPORT_OBSTACLE_FROM_FILE</source>
       <translation>Import obstacle</translation>
@@ -784,6 +796,10 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <source>STB_CREATE_PROFILE</source>
       <translation>Create profile</translation>
     </message>
+    <message>
+      <source>STB_IMPORT_PROFILES</source>
+      <translation>Import profiles from file(s)</translation>
+    </message>
     <message>
       <source>STB_CREATE_IMMERSIBLE_ZONE</source>
       <translation>Create immersible zone</translation>
@@ -1255,6 +1271,24 @@ file cannot be correctly imported for an Obstacle definition.</translation>
     </message>
   </context>
 
+  <context>
+    <name>HYDROGUI_ImportProfilesOp</name>
+    <message>
+      <source>IMPORT_PROFILES</source>
+      <translation>Import profiles</translation>
+    </message>
+    <message>
+      <source>PROFILE_FILTER</source>
+      <translation>All files (*.* *)</translation>
+    </message>
+    <message>
+      <source>BAD_IMPORTED_PROFILES_FILES</source>
+      <translation>The following files cannot be correctly imported for a Profile definition:
+%1
+</translation>
+    </message>
+  </context>
+
   <context>
     <name>HYDROGUI_SetColorOp</name>
     <message>