Salome HOME
Merge branch 'BR_LAND_COVER' of ssh://git.salome-platform.org/modules/hydro into...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Operations.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_Operations.h"
20
21 #include "HYDROGUI_CopyPasteOp.h"
22 #include "HYDROGUI_CalculationOp.h"
23 #include "HYDROGUI_ChannelOp.h"
24 #include "HYDROGUI_DataModel.h"
25 #include "HYDROGUI_CopyPastePositionOp.h"
26 #include "HYDROGUI_DeleteOp.h"
27 #include "HYDROGUI_DigueOp.h"
28 #include "HYDROGUI_ExportImageOp.h"
29 #include "HYDROGUI_ExportFileOp.h"
30 #include "HYDROGUI_ImportImageOp.h"
31 #include "HYDROGUI_ImportPolylineOp.h"
32 #include "HYDROGUI_ImportBathymetryOp.h"
33 #include "HYDROGUI_ImmersibleZoneOp.h"
34 #include "HYDROGUI_Module.h"
35 #include "HYDROGUI_ObserveImageOp.h"
36 #include "HYDROGUI_PolylineOp.h"
37 #include "HYDROGUI_Poly3DOp.h"
38 #include "HYDROGUI_ProfileOp.h"
39 #include "HYDROGUI_RemoveImageRefsOp.h"
40 #include "HYDROGUI_ShowHideOp.h"
41 #include "HYDROGUI_StreamOp.h"
42 #include "HYDROGUI_TwoImagesOp.h"
43 #include "HYDROGUI_UpdateFlags.h"
44 #include "HYDROGUI_UpdateObjectOp.h"
45 #include "HYDROGUI_VisualStateOp.h"
46 #include "HYDROGUI_ImmersibleZoneOp.h"
47 #include "HYDROGUI_ImportGeomObjectOp.h"
48 #include "HYDROGUI_ImportObstacleFromFileOp.h"
49 #include "HYDROGUI_TranslateObstacleOp.h"
50 #include "HYDROGUI_ExportCalculationOp.h"
51 #include "HYDROGUI_ImportProfilesOp.h"
52 #include "HYDROGUI_GeoreferencementOp.h"
53 #include "HYDROGUI_SetColorOp.h"
54 #include "HYDROGUI_BathymetryBoundsOp.h"
55 #include "HYDROGUI_Tool.h"
56 #include "HYDROGUI_ZLevelsOp.h"
57 #include "HYDROGUI_LocalCSOp.h"
58 #include "HYDROGUI_RiverBottomOp.h"
59 #include "HYDROGUI_ProfileInterpolateOp.h"
60 #include "HYDROGUI_SubmersibleOp.h"
61 #include "HYDROGUI_StricklerTableOp.h"
62 #include "HYDROGUI_DuplicateOp.h"
63 #include "HYDROGUI_LandCoverOp.h"
64
65 #include <HYDROData_Document.h>
66 #include <HYDROData_Obstacle.h>
67 #include <HYDROData_SplitToZonesTool.h>
68
69 #include <GeometryGUI.h>
70 #include <GeometryGUI_Operations.h>
71 #include <GEOMBase.h>
72
73 #include <SalomeApp_Study.h>
74
75 #include <LightApp_Application.h>
76
77 #include <CAM_Application.h>
78
79 #include <QtxListAction.h>
80 #include <QtxActionToolMgr.h>
81
82 #include <SUIT_Desktop.h>
83 #include <SUIT_ResourceMgr.h>
84 #include <SUIT_Session.h>
85 #include <SUIT_MessageBox.h>
86
87 #include <QAction>
88 #include <QApplication>
89
90 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
91                                         const int theKey, const bool isToggle, const QString& theSlot )
92 {
93   QString aSlot = theSlot;
94   if( aSlot.isEmpty() )
95     aSlot = SLOT( onOperation() );
96   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
97   std::string anImg = theImg.toStdString();
98   QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
99   std::string aMenu    = ( "MEN_" + theSuffix ).toStdString();
100   std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
101   std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
102   std::string aSlotStr = aSlot.toStdString();
103   return LightApp_Module::createAction( theId, tr( aDesktop.c_str() ), aPixmap,
104     tr( aMenu.c_str() ), tr( aToolbar.c_str() ),
105                 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
106 }
107
108 void HYDROGUI_Module::createActions()
109 {
110   createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
111   createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
112
113   createAction( CopyId, "COPY", "", Qt::CTRL + Qt::Key_C );
114   createAction( PasteId, "PASTE", "", Qt::CTRL + Qt::Key_V );
115
116   createAction( UpdateObjectId, "UPDATE_OBJECT" );
117   createAction( ForcedUpdateObjectId, "FORCED_UPDATE_OBJECT" );
118
119   createAction( ImportImageId, "IMPORT_IMAGE", "IMPORT_IMAGE_ICO", Qt::CTRL + Qt::Key_I );
120   createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE", "EDIT_IMPORTED_IMAGE_ICO" );
121   createAction( ObserveImageId, "OBSERVE_IMAGE", "OBSERVE_IMAGE_ICO" );
122   createAction( ExportImageId, "EXPORT_IMAGE", "EXPORT_IMAGE_ICO" );
123   createAction( RemoveImageRefsId, "REMOVE_IMAGE_REFERENCE", "REMOVE_IMAGE_REFERENCE_ICO" );
124   
125   createAction( ImportPolylineId, "IMPORT_POLYLINE", "IMPORT_POLYLINE_ICO" );
126
127   createAction( CreatePolylineId, "CREATE_POLYLINE", "CREATE_POLYLINE_ICO" );
128   createAction( EditPolylineId, "EDIT_POLYLINE", "EDIT_POLYLINE_ICO" ); 
129
130   createAction( CreatePolyline3DId, "CREATE_POLYLINE_3D", "CREATE_POLYLINE_3D_ICO" );
131   createAction( EditPolyline3DId, "EDIT_POLYLINE_3D", "EDIT_POLYLINE_3D_ICO" ); 
132
133   createAction( CreateProfileId, "CREATE_PROFILE", "CREATE_PROFILE_ICO" );
134   createAction( ImportProfilesId, "IMPORT_PROFILES", "IMPORT_PROFILES_ICO" );
135   createAction( EditProfileId, "EDIT_PROFILE", "EDIT_PROFILE_ICO" ); 
136   createAction( AllGeoreferencementId, "GEOREFERENCEMENT", "GEOREFERENCEMENT_ICO" ); 
137   createAction( SelectedGeoreferencementId, "GEOREFERENCEMENT", "GEOREFERENCEMENT_ICO" ); 
138   
139   createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "IMPORT_BATHYMETRY_ICO", Qt::CTRL + Qt::Key_B );
140   createAction( EditImportedBathymetryId, "EDIT_IMPORTED_BATHYMETRY", "EDIT_IMPORTED_BATHYMETRY_ICO" );
141   createAction( BathymetryBoundsId, "BATHYMETRY_BOUNDS", "BATHYMETRY_BOUNDS_ICO" );
142
143   createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE", "CREATE_IMMERSIBLE_ZONE_ICO" );
144   createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE", "EDIT_IMMERSIBLE_ZONE_ICO" );
145
146   createAction( CreateStreamId, "CREATE_STREAM", "CREATE_STREAM_ICO" );
147   createAction( EditStreamId, "EDIT_STREAM", "EDIT_STREAM_ICO" );
148
149   createAction( CreateChannelId, "CREATE_CHANNEL", "CREATE_CHANNEL_ICO" );
150   createAction( EditChannelId, "EDIT_CHANNEL", "EDIT_CHANNEL_ICO" );
151
152   createAction( CreateDigueId, "CREATE_DIGUE", "CREATE_DIGUE_ICO" );
153   createAction( EditDigueId, "EDIT_DIGUE", "EDIT_DIGUE_ICO" );
154
155   createAction( ImportStricklerTableFromFileId, "IMPORT_STRICKLER_TABLE", "IMPORT_STRICKLER_TABLE_ICO" );
156   createAction( ExportStricklerTableFromFileId, "EXPORT_STRICKLER_TABLE", "EXPORT_STRICKLER_TABLE_ICO" );
157   createAction( EditStricklerTableId, "EDIT_STRICKLER_TABLE", "EDIT_STRICKLER_TABLE_ICO" );
158   createAction( DuplicateStricklerTableId, "DUPLICATE_STRICKLER_TABLE", "DUPLICATE_STRICKLER_TABLE_ICO" );
159
160   createAction( CreateLandCoverId, "CREATE_LAND_COVER", "CREATE_LAND_COVER_ICO" );
161   createAction( EditLandCoverId, "EDIT_LAND_COVER", "EDIT_LAND_COVER_ICO" );
162
163   createAction( ImportObstacleFromFileId, "IMPORT_OBSTACLE_FROM_FILE", "IMPORT_OBSTACLE_FROM_FILE_ICO" );
164   createAction( ImportGeomObjectAsObstacleId, "IMPORT_GEOM_OBJECT_AS_OBSTACLE", "IMPORT_GEOM_OBJECT_ICO" );
165   createAction( ImportGeomObjectAsPolylineId, "IMPORT_GEOM_OBJECT_AS_POLYLINE", "IMPORT_GEOM_OBJECT_ICO" );
166   createAction( CreateBoxId, "CREATE_BOX", "CREATE_BOX_ICO" );
167   createAction( CreateCylinderId, "CREATE_CYLINDER", "CREATE_CYLINDER_ICO" );
168   createAction( TranslateObstacleId, "TRANSLATE_OBSTACLE" );
169
170   createAction( CreateCalculationId, "CREATE_CALCULATION", "CREATE_CALCULATION_ICO" );
171   createAction( EditCalculationId, "EDIT_CALCULATION", "EDIT_CALCULATION_ICO" );
172   createAction( ExportCalculationId, "EXPORT_CALCULATION", "EXPORT_CALCULATION_ICO" );
173
174   createAction( FuseImagesId, "FUSE_IMAGES", "FUSE_IMAGES_ICO" );
175   createAction( EditFusedImageId, "EDIT_FUSED_IMAGE", "EDIT_FUSED_IMAGE_ICO" );
176
177   createAction( CutImagesId, "CUT_IMAGES", "CUT_IMAGES_ICO" );
178   createAction( EditCutImageId, "EDIT_CUT_IMAGE", "EDIT_CUT_IMAGE_ICO" );
179
180   createAction( SplitImageId, "SPLIT_IMAGE", "SPLIT_IMAGE_ICO" );
181   createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE", "EDIT_SPLITTED_IMAGE_ICO" );
182
183   createAction( CopyViewerPositionId, "COPY_VIEWER_POSITION", "" );
184
185   createAction( DeleteId, "DELETE", "", Qt::Key_Delete, false,
186                 SLOT( onDelete() ) );
187
188   createAction( SetColorId, "COLOR" );
189   createAction( SetZLevelId, "ZLEVEL" );
190   createAction( EditLocalCSId, "EDIT_LOCAL_CS" );
191
192   createAction( ShowId, "SHOW" );
193   createAction( ShowOnlyId, "SHOW_ONLY" );
194   createAction( ShowAllId, "SHOW_ALL" );
195   createAction( HideId, "HIDE" );
196   createAction( HideAllId, "HIDE_ALL" );
197
198   createAction( RiverBottomId, "CREATE_STREAM_BOTTOM", "CREATE_STREAM_BOTTOM_ICO" );
199   createAction( RiverBottomContextId, "CREATE_STREAM_BOTTOM", "CREATE_STREAM_BOTTOM_ICO" );
200   createAction( ProfileInterpolateId, "PROFILE_INTERPOLATE", "PROFILE_INTERPOLATE_ICO" );
201
202   createAction( SubmersibleId, "SUBMERSIBLE", "SUBMERSIBLE_ICO" );
203   createAction( ExportPolylineId, "EXPORT_POLYLINE", "EXPORT_POLYLINE_ICO" );
204
205 }
206
207 void HYDROGUI_Module::createMenus()
208 {
209   int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
210   int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
211   createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
212   createMenu( separator(), aFileMenu, -1, aCustomPos );
213
214   int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
215   createMenu( UndoId, anEditMenu );
216   createMenu( RedoId, anEditMenu );
217   createMenu( separator(), anEditMenu );
218   createMenu( CopyId, anEditMenu );
219   createMenu( PasteId, anEditMenu );
220
221   int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
222   int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
223   createMenu( ImportImageId, aHydroId, -1, -1 );
224   createMenu( ImportPolylineId, aHydroId, -1, -1 );
225   createMenu( ImportBathymetryId, aHydroId, -1, -1 );
226   createMenu( ImportStricklerTableFromFileId, aHydroId, -1, -1 );
227   createMenu( CreatePolylineId, aHydroId, -1, -1 );
228   createMenu( CreatePolyline3DId, aHydroId, -1, -1 );
229   createMenu( CreateImmersibleZoneId, aHydroId, -1, -1 );
230   createMenu( CreateChannelId, aHydroId, -1, -1 );
231   createMenu( CreateDigueId, aHydroId, -1, -1 );  
232   createMenu( CreateLandCoverId, aHydroId, -1, -1 );  
233
234   int aNewProfileId = createMenu( tr( "MEN_DESK_PROFILE" ), aHydroId, -1 );
235   createMenu( CreateProfileId, aNewProfileId, -1, -1 );
236   createMenu( ImportProfilesId, aNewProfileId, -1, -1 );
237   createMenu( AllGeoreferencementId, aNewProfileId, -1, -1 );
238
239   int aStreamMenuId = createMenu( tr( "MEN_DESK_STREAM" ), aHydroId, -1 );
240   createMenu( CreateStreamId, aStreamMenuId, -1, -1 );
241   createMenu( RiverBottomId, aStreamMenuId, -1, -1 );
242   createMenu( ProfileInterpolateId, aStreamMenuId, -1, -1 );
243
244   int anObstacleMenuId = createMenu( tr( "MEN_DESK_OBSTACLE" ), aHydroId, -1 );
245   createMenu( ImportObstacleFromFileId, anObstacleMenuId, -1, -1 );
246   createMenu( CreateBoxId, anObstacleMenuId, -1, -1 );
247   createMenu( CreateCylinderId, anObstacleMenuId, -1, -1 );
248
249   createMenu( CreateCalculationId, aHydroId, -1, -1 );
250   createMenu( separator(), aHydroId );
251   createMenu( EditLocalCSId, aHydroId, -1, -1 );
252   createMenu( separator(), aHydroId );
253   createMenu( FuseImagesId, aHydroId, -1, -1 );
254   createMenu( CutImagesId, aHydroId, -1, -1 );
255   createMenu( SplitImageId, aHydroId, -1, -1 );
256   createMenu( separator(), aHydroId );
257 }
258
259 void HYDROGUI_Module::createPopups()
260 {
261 }
262
263 void HYDROGUI_Module::createToolbars()
264 {
265   int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
266   createTool( UndoId, aToolBar );
267   createTool( RedoId, aToolBar );
268
269   createTool( separator(), aToolBar );
270   createTool( ImportImageId, aToolBar );
271   createTool( ImportPolylineId, aToolBar );
272   createTool( ImportBathymetryId, aToolBar );
273   createTool( CreatePolylineId, aToolBar );
274   createTool( CreatePolyline3DId, aToolBar );
275
276   createTool( separator(), aToolBar );
277   createTool( CreateProfileId, aToolBar );
278   createTool( ImportProfilesId, aToolBar );
279   createTool( AllGeoreferencementId, aToolBar );
280
281   createTool( separator(), aToolBar );
282   createTool( CreateChannelId, aToolBar );
283   createTool( CreateDigueId, aToolBar );
284
285   createTool( separator(), aToolBar );
286   createTool( CreateImmersibleZoneId, aToolBar );
287   createTool( CreateStreamId, aToolBar );
288
289   createTool( separator(), aToolBar );
290   createTool( ImportObstacleFromFileId, aToolBar );
291   createTool( CreateBoxId, aToolBar );
292   createTool( CreateCylinderId, aToolBar );
293
294   createTool( separator(), aToolBar );
295   createTool( ImportStricklerTableFromFileId, aToolBar );
296
297   createTool( separator(), aToolBar );
298   createTool( CreateLandCoverId, aToolBar );
299
300   createTool( separator(), aToolBar );
301   createTool( CreateCalculationId, aToolBar );
302
303   createTool( separator(), aToolBar );
304   createTool( FuseImagesId, aToolBar );
305   createTool( CutImagesId, aToolBar );
306   createTool( SplitImageId, aToolBar );
307 }
308
309 void HYDROGUI_Module::createUndoRedoActions()
310 {
311   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
312
313   QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
314     aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
315     Qt::CTRL + Qt::Key_Z, application()->desktop() );
316     
317   QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
318     aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
319     Qt::CTRL + Qt::Key_Y, application()->desktop() );
320   
321   registerAction( UndoId, anEditUndo );
322   registerAction( RedoId, anEditRedo );
323
324   anEditUndo->setComment( tr( "STB_UNDO" ) );
325   anEditRedo->setComment( tr( "STB_REDO" ) );
326
327   connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
328   connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
329 }
330
331 void HYDROGUI_Module::updateUndoRedoControls()
332 {
333   HYDROGUI_DataModel* aModel = getDataModel();
334
335   QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
336   QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
337
338   bool aCanUndo = aModel->canUndo();
339   bool aCanRedo = aModel->canRedo();
340
341   if( aCanUndo )
342     aUndoAction->addNames( aModel->undoNames() );
343   aUndoAction->setEnabled( aCanUndo );
344
345   if( aCanRedo )
346     aRedoAction->addNames( aModel->redoNames() );
347   aRedoAction->setEnabled( aCanRedo );
348 }
349
350 void HYDROGUI_Module::onOperation()
351 {
352   const QAction* anAction = dynamic_cast<const QAction*>( sender() );
353   int anId = actionId( anAction );
354   if( anId >= 0 )
355     startOperation( anId );
356 }
357
358 void HYDROGUI_Module::onDelete()
359 {
360   SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
361   HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
362   if ( aPolylineOp && aPolylineOp->deleteEnabled() )
363     aPolylineOp->deleteSelected();
364   else
365     startOperation( DeleteId );
366 }
367
368 bool HYDROGUI_Module::onUndo( int theNumActions )
369 {
370   QApplication::setOverrideCursor( Qt::WaitCursor );
371   bool anIsOk = true;
372   HYDROGUI_DataModel* aModel = getDataModel();
373   if( aModel )
374   {
375     while( theNumActions > 0 )
376     {
377       if( !aModel->undo() )
378       {
379         anIsOk = false;
380         break;
381       }
382       theNumActions--;
383     }
384     update( UF_All );
385   }
386   QApplication::restoreOverrideCursor();
387   return anIsOk;
388 }
389
390 bool HYDROGUI_Module::onRedo( int theNumActions )
391 {
392   QApplication::setOverrideCursor( Qt::WaitCursor );
393   bool anIsOk = true;
394   HYDROGUI_DataModel* aModel = getDataModel();
395   if( aModel )
396   {
397     while( theNumActions > 0 )
398     {
399       if( !aModel->redo() )
400       {
401         anIsOk = false;
402         break;
403       }
404       theNumActions--;
405     }
406     update( UF_All );
407   }
408   QApplication::restoreOverrideCursor();
409   return anIsOk;
410 }
411
412 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
413 {
414   LightApp_Operation* anOp = 0;
415   HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
416   switch( theId )
417   {
418   case SaveVisualStateId:
419   case LoadVisualStateId:
420     anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
421     break;
422   case CopyId:
423   case PasteId:
424     anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
425     break;
426   case ImportImageId:
427   case EditImportedImageId:
428     anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
429     break;
430   case ImportPolylineId:
431     anOp = new HYDROGUI_ImportPolylineOp( aModule/*, theId == EditImportedPolylineId*/ );
432     break;
433   case ObserveImageId:
434     anOp = new HYDROGUI_ObserveImageOp( aModule );
435     break;
436   case ExportImageId:
437     anOp = new HYDROGUI_ExportImageOp( aModule );
438     break;
439   case UpdateObjectId:
440   case ForcedUpdateObjectId:
441     anOp = new HYDROGUI_UpdateObjectOp( aModule, theId == ForcedUpdateObjectId );
442     break;
443   case ExportPolylineId:
444     anOp = new HYDROGUI_ExportFileOp( aModule );
445     break;
446   case RemoveImageRefsId:
447     anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
448     break;
449   case CreatePolyline3DId:
450   case EditPolyline3DId:
451     anOp = new HYDROGUI_Poly3DOp( aModule, theId == EditPolyline3DId );
452     break;
453   case CreatePolylineId:
454   case EditPolylineId:
455     anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
456     break;
457   case CreateProfileId:
458   case EditProfileId:
459     anOp = new HYDROGUI_ProfileOp( aModule, theId == EditProfileId );
460     break;
461   case ProfileInterpolateId:
462     anOp = new HYDROGUI_ProfileInterpolateOp( aModule );
463     break;
464   case ImportProfilesId:
465     anOp = new HYDROGUI_ImportProfilesOp( aModule ) ;
466     break;
467   case AllGeoreferencementId:
468     anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::All ) ;
469     break;
470   case SelectedGeoreferencementId:
471     anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::Selected ) ;
472     break;
473   case ImportBathymetryId:
474   case EditImportedBathymetryId:
475     anOp = new HYDROGUI_ImportBathymetryOp( aModule, theId == EditImportedBathymetryId  );
476     break;
477   case BathymetryBoundsId:
478     anOp = new HYDROGUI_BathymetryBoundsOp( aModule );
479     break;
480   case CreateImmersibleZoneId:
481   case EditImmersibleZoneId:
482     anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
483     break;
484   case CreateStreamId:
485   case EditStreamId:
486     anOp = new HYDROGUI_StreamOp( aModule, theId == EditStreamId );
487     break;
488   case CreateChannelId:
489   case EditChannelId:
490     anOp = new HYDROGUI_ChannelOp( aModule, theId == EditChannelId );
491     break;
492   case CreateDigueId:
493   case EditDigueId:
494     anOp = new HYDROGUI_DigueOp( aModule, theId == EditDigueId );
495     break;
496   case ImportStricklerTableFromFileId:
497   case ExportStricklerTableFromFileId:
498   case EditStricklerTableId:
499     anOp = new HYDROGUI_StricklerTableOp( aModule, theId );
500     break;
501   case CreateLandCoverId:
502   case EditLandCoverId:
503     anOp = new HYDROGUI_LandCoverOp( aModule, theId == EditLandCoverId );
504     break;
505   case DuplicateStricklerTableId:
506     anOp = new HYDROGUI_DuplicateOp( aModule );
507     break;
508   case CreateCalculationId:
509   case EditCalculationId:
510     anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
511     break;
512   case ExportCalculationId:
513     anOp = new HYDROGUI_ExportCalculationOp( aModule );
514     break;
515   case FuseImagesId:
516   case EditFusedImageId:
517     anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
518     break;
519   case CutImagesId:
520   case EditCutImageId:
521     anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
522     break;
523   case SplitImageId:
524   case EditSplittedImageId:
525     anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId );
526     break;
527   case ImportObstacleFromFileId:
528     anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule );
529     break;
530   case ImportGeomObjectAsObstacleId:
531     anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelectedAsObstacle );
532     break;
533   case ImportGeomObjectAsPolylineId:
534     anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelectedAsPolyline );
535     break;
536   case CreateBoxId:
537     anOp = new HYDROGUI_ImportGeomObjectOp( aModule, 
538       HYDROGUI_ImportGeomObjectOp::ImportCreatedAsObstacle, GEOMOp::OpBox );
539     break;
540   case CreateCylinderId:
541     anOp = new HYDROGUI_ImportGeomObjectOp( aModule, 
542       HYDROGUI_ImportGeomObjectOp::ImportCreatedAsObstacle, GEOMOp::OpCylinder );
543     break;
544   case TranslateObstacleId:
545     anOp = new HYDROGUI_TranslateObstacleOp( aModule );
546     break;
547   case CopyViewerPositionId:
548     anOp = new HYDROGUI_CopyPastePositionOp( aModule, false );
549     break;
550   case DeleteId:
551     anOp = new HYDROGUI_DeleteOp( aModule );
552     break;
553   case SetColorId:
554     anOp = new HYDROGUI_SetColorOp( aModule );
555     break;
556   case SetZLevelId:
557     anOp = new HYDROGUI_ZLevelsOp( aModule );
558     break;
559   case EditLocalCSId:
560     anOp = new HYDROGUI_LocalCSOp( aModule );
561     break;
562   case RiverBottomId:
563   case RiverBottomContextId:
564     anOp = new HYDROGUI_RiverBottomOp( aModule );
565     break;
566   case ShowId:
567   case ShowOnlyId:
568   case ShowAllId:
569   case HideId:
570   case HideAllId:
571     anOp = new HYDROGUI_ShowHideOp( aModule, theId );
572     break;
573   case SubmersibleId:
574     anOp = new HYDROGUI_SubmersibleOp( aModule );
575     break;
576   }
577
578   if( !anOp )
579     anOp = LightApp_Module::createOperation( theId );
580
581   return anOp;
582 }
583
584 bool HYDROGUI_Module::reusableOperation( const int id )
585 {
586   if ( id == ImportGeomObjectAsObstacleId ||
587        id == ImportGeomObjectAsPolylineId ) {
588     return false;
589   }
590
591   return LightApp_Module::reusableOperation( id );
592 }
593
594 /**
595  * Returns true if the object with the given entry can be renamed.
596  * @param theEntry the object entry
597  */
598 bool HYDROGUI_Module::renameAllowed( const QString& theEntry ) const
599 {
600   // Allow to rename all HYDRO objects
601   Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
602   return !anEntity.IsNull();
603 }
604 /**
605  * Returns true if the object with the given entry is renamed.
606  * @param theEntry the object entry
607  * @param theName the new name
608  */
609 bool HYDROGUI_Module::renameObject( const QString& theEntry, const QString& theName )
610 {
611   Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
612   bool aRes = false;
613   if ( !anEntity.IsNull() )
614   {
615     HYDROGUI_DataModel* aModel = getDataModel();
616     if( aModel )
617     {
618       if( anEntity->GetName() != theName )
619       {
620         // check that there are no other objects with the same name in the document
621         Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( this, theName );
622         if ( anObject.IsNull() )
623         {
624           SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
625           if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
626           {
627             anEntity->SetName( theName );
628             aRes = true;
629           }
630           else
631           {
632             aRes = aModel->rename( anEntity, theName );
633           }
634         }
635         else
636         {
637           // Inform the user that the name is already used
638           QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
639           QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
640           SUIT_MessageBox::critical( getApp()->desktop(), aTitle, aMessage );
641         }
642       }
643     }
644   }
645   return aRes;
646 }