Salome HOME
Feature #197: translation or georeferencing of OBSTACLES Box and Cylinder.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Operations.cxx
index c9fca653e8d192a0afdbc41b1b52cd5b54ef2d62..aedb1dee49b825b7bcf5fd2d5e1954fd11079240 100644 (file)
@@ -26,6 +26,7 @@
 #include "HYDROGUI_CalculationOp.h"
 #include "HYDROGUI_ChannelOp.h"
 #include "HYDROGUI_DataModel.h"
+#include "HYDROGUI_CopyPastePositionOp.h"
 #include "HYDROGUI_DeleteOp.h"
 #include "HYDROGUI_DigueOp.h"
 #include "HYDROGUI_ExportImageOp.h"
 #include "HYDROGUI_ImmersibleZoneOp.h"
 #include "HYDROGUI_ImportGeomObjectOp.h"
 #include "HYDROGUI_ImportObstacleFromFileOp.h"
+#include "HYDROGUI_TranslateObstacleOp.h"
 #include "HYDROGUI_ExportCalculationOp.h"
 #include "HYDROGUI_ImportProfilesOp.h"
 #include "HYDROGUI_GeoreferencementOp.h"
 #include "HYDROGUI_SetColorOp.h"
+#include "HYDROGUI_BathymetryBoundsOp.h"
 #include "HYDROGUI_Tool.h"
 
 #include <HYDROData_Document.h>
@@ -105,6 +108,7 @@ void HYDROGUI_Module::createActions()
   createAction( PasteId, "PASTE", "", Qt::CTRL + Qt::Key_V );
 
   createAction( UpdateObjectId, "UPDATE_OBJECT" );
+  createAction( ForcedUpdateObjectId, "FORCED_UPDATE_OBJECT" );
 
   createAction( ImportImageId, "IMPORT_IMAGE", "IMPORT_IMAGE_ICO", Qt::CTRL + Qt::Key_I );
   createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE", "EDIT_IMPORTED_IMAGE_ICO" );
@@ -126,6 +130,7 @@ void HYDROGUI_Module::createActions()
   
   createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "IMPORT_BATHYMETRY_ICO", Qt::CTRL + Qt::Key_B );
   createAction( EditImportedBathymetryId, "EDIT_IMPORTED_BATHYMETRY", "EDIT_IMPORTED_BATHYMETRY_ICO" );
+  createAction( BathymetryBoundsId, "BATHYMETRY_BOUNDS", "BATHYMETRY_BOUNDS_ICO" );
 
   createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE", "CREATE_IMMERSIBLE_ZONE_ICO" );
   createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE", "EDIT_IMMERSIBLE_ZONE_ICO" );
@@ -140,9 +145,11 @@ void HYDROGUI_Module::createActions()
   createAction( EditDigueId, "EDIT_DIGUE", "EDIT_DIGUE_ICO" );
 
   createAction( ImportObstacleFromFileId, "IMPORT_OBSTACLE_FROM_FILE", "IMPORT_OBSTACLE_FROM_FILE_ICO" );
-  createAction( ImportGeomObjectId, "IMPORT_GEOM_OBJECT", "IMPORT_GEOM_OBJECT_ICO" );
+  createAction( ImportGeomObjectAsObstacleId, "IMPORT_GEOM_OBJECT_AS_OBSTACLE", "IMPORT_GEOM_OBJECT_ICO" );
+  createAction( ImportGeomObjectAsPolylineId, "IMPORT_GEOM_OBJECT_AS_POLYLINE", "IMPORT_GEOM_OBJECT_ICO" );
   createAction( CreateBoxId, "CREATE_BOX", "CREATE_BOX_ICO" );
   createAction( CreateCylinderId, "CREATE_CYLINDER", "CREATE_CYLINDER_ICO" );
+  createAction( TranslateObstacleId, "TRANSLATE_OBSTACLE" );
 
   createAction( CreateCalculationId, "CREATE_CALCULATION", "CREATE_CALCULATION_ICO" );
   createAction( EditCalculationId, "EDIT_CALCULATION", "EDIT_CALCULATION_ICO" );
@@ -157,6 +164,8 @@ void HYDROGUI_Module::createActions()
   createAction( SplitImageId, "SPLIT_IMAGE", "SPLIT_IMAGE_ICO" );
   createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE", "EDIT_SPLITTED_IMAGE_ICO" );
 
+  createAction( CopyViewerPositionId, "COPY_VIEWER_POSITION", "" );
+
   createAction( DeleteId, "DELETE", "", Qt::Key_Delete, false,
                 SLOT( onDelete() ) );
 
@@ -387,7 +396,8 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
     anOp = new HYDROGUI_ExportImageOp( aModule );
     break;
   case UpdateObjectId:
-    anOp = new HYDROGUI_UpdateObjectOp( aModule );
+  case ForcedUpdateObjectId:
+    anOp = new HYDROGUI_UpdateObjectOp( aModule, theId == ForcedUpdateObjectId );
     break;
   case RemoveImageRefsId:
     anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
@@ -417,6 +427,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
   case EditImportedBathymetryId:
     anOp = new HYDROGUI_ImportBathymetryOp( aModule, theId == EditImportedBathymetryId  );
     break;
+  case BathymetryBoundsId:
+    anOp = new HYDROGUI_BathymetryBoundsOp( aModule );
+    break;
   case CreateImmersibleZoneId:
   case EditImmersibleZoneId:
     anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
@@ -455,17 +468,25 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
   case ImportObstacleFromFileId:
     anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule );
     break;
-  case ImportCreatedPrimitiveId:
-    anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportCreated );
+  case ImportGeomObjectAsObstacleId:
+    anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelectedAsObstacle );
     break;
-  case ImportGeomObjectId:
-    anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelected );
+  case ImportGeomObjectAsPolylineId:
+    anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelectedAsPolyline );
     break;
   case CreateBoxId:
-    application()->activateOperation( "Geometry", GEOMOp::OpBox );
+    anOp = new HYDROGUI_ImportGeomObjectOp( aModule, 
+      HYDROGUI_ImportGeomObjectOp::ImportCreatedAsObstacle, GEOMOp::OpBox );
     break;
   case CreateCylinderId:
-    application()->activateOperation( "Geometry", GEOMOp::OpCylinder );
+    anOp = new HYDROGUI_ImportGeomObjectOp( aModule, 
+      HYDROGUI_ImportGeomObjectOp::ImportCreatedAsObstacle, GEOMOp::OpCylinder );
+    break;
+  case TranslateObstacleId:
+    anOp = new HYDROGUI_TranslateObstacleOp( aModule );
+    break;
+  case CopyViewerPositionId:
+    anOp = new HYDROGUI_CopyPastePositionOp( aModule, false );
     break;
   case DeleteId:
     anOp = new HYDROGUI_DeleteOp( aModule );
@@ -490,42 +511,14 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
 
 bool HYDROGUI_Module::reusableOperation( const int id )
 {
-  if ( id == ImportGeomObjectId ) {
+  if ( id == ImportGeomObjectAsObstacleId ||
+       id == ImportGeomObjectAsPolylineId ) {
     return false;
   }
 
   return LightApp_Module::reusableOperation( id );
 }
 
-/**
- * Called when the operation perfomed by another module is finished.
- * \param theModuleName the name of the module which perfomed the operation
- * \param theOperationName the operation name
- * \param theEntryList the list of the created objects entries
- */
-void HYDROGUI_Module::onExternalOperationFinished( const QString& theModuleName,
-                                                   const QString& theOperationName,
-                                                   const QStringList& theEntryList )
-{
-  // Process "Geometry" module operations with non-empty list of created objects only
-  if ( theModuleName != "Geometry" || theEntryList.isEmpty() ) {
-    return;
-  }
-  
-  // Start import GEOM object operation
-  myGeomObjectsToImport = theEntryList;
-  startOperation( ImportCreatedPrimitiveId );
-  myGeomObjectsToImport.clear();
-}
-
-/**
- * Returns the list of entries of GEOM objects to be imported.
- */
-QStringList HYDROGUI_Module::GetGeomObjectsToImport()
-{
-  return myGeomObjectsToImport;
-}
-
 /**
  * Returns true if the object with the given entry can be renamed.
  * @param theEntry the object entry
@@ -544,8 +537,8 @@ bool HYDROGUI_Module::renameAllowed( const QString& theEntry ) const
 bool HYDROGUI_Module::renameObject( const QString& theEntry, const QString& theName )
 {
   Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
-  bool aRes = !anEntity.IsNull();
-  if ( aRes )
+  bool aRes = false;
+  if ( !anEntity.IsNull() )
   {
     HYDROGUI_DataModel* aModel = getDataModel();
     if( aModel )
@@ -554,10 +547,18 @@ bool HYDROGUI_Module::renameObject( const QString& theEntry, const QString& theN
       {
         // check that there are no other objects with the same name in the document
         Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( this, theName );
-        aRes = anObject.IsNull();
-        if ( aRes )
+        if ( anObject.IsNull() )
         {
-          aRes = aModel->rename( anEntity, theName );
+          SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
+          if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
+          {
+            anEntity->SetName( theName );
+            aRes = true;
+          }
+          else
+          {
+            aRes = aModel->rename( anEntity, theName );
+          }
         }
         else
         {