Salome HOME
75ca6f832714174cb3a11b9d1b622a7eed06100a
[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_ImportSinusXOp.h"
33 #include "HYDROGUI_ImportBathymetryOp.h"
34 #include "HYDROGUI_ImmersibleZoneOp.h"
35 #include "HYDROGUI_Module.h"
36 #include "HYDROGUI_ObserveImageOp.h"
37 #include "HYDROGUI_PolylineOp.h"
38 #include "HYDROGUI_Poly3DOp.h"
39 #include "HYDROGUI_ProfileOp.h"
40 #include "HYDROGUI_RemoveImageRefsOp.h"
41 #include "HYDROGUI_ShowHideOp.h"
42 #include "HYDROGUI_StreamOp.h"
43 #include "HYDROGUI_TwoImagesOp.h"
44 #include "HYDROGUI_UpdateFlags.h"
45 #include "HYDROGUI_UpdateObjectOp.h"
46 #include "HYDROGUI_VisualStateOp.h"
47 #include "HYDROGUI_ImmersibleZoneOp.h"
48 #include "HYDROGUI_ImportGeomObjectOp.h"
49 #include "HYDROGUI_ImportObstacleFromFileOp.h"
50 #include "HYDROGUI_TranslateObstacleOp.h"
51 #include "HYDROGUI_ExportCalculationOp.h"
52 #include "HYDROGUI_ImportProfilesOp.h"
53 #include "HYDROGUI_GeoreferencementOp.h"
54 #include "HYDROGUI_SetColorOp.h"
55 #include "HYDROGUI_BathymetryBoundsOp.h"
56 #include "HYDROGUI_Tool2.h"
57 #include "HYDROGUI_ZLevelsOp.h"
58 #include "HYDROGUI_LocalCSOp.h"
59 #include "HYDROGUI_RiverBottomOp.h"
60 #include "HYDROGUI_ProfileInterpolateOp.h"
61 #include "HYDROGUI_RecognizeContoursOp.h"
62 #include "HYDROGUI_SubmersibleOp.h"
63 #include "HYDROGUI_StricklerTableOp.h"
64 #include "HYDROGUI_DuplicateOp.h"
65 #include "HYDROGUI_LandCoverMapOp.h"
66 #include "HYDROGUI_PolylineExtractionOp.h"
67 #include "HYDROGUI_ExportSinusXOp.h"
68 #include "HYDROGUI_MergePolylinesOp.h"
69 #include "HYDROGUI_SplitPolylinesOp.h"
70 #include "HYDROGUI_LandCoverColoringOp.h"
71 #include "HYDROGUI_SetTransparencyOp.h"
72 #include "HYDROGUI_ImportLandCoverMapOp.h"
73 #include "HYDROGUI_BathymetrySelectionOp.h"
74 #include "HYDROGUI_BathymetryOp.h"
75
76 #include <HYDROData_Document.h>
77 #include <HYDROData_Obstacle.h>
78 #include <HYDROData_SplitToZonesTool.h>
79 #include <HYDROData_Iterator.h>
80
81 #include <GeometryGUI.h>
82 #include <GeometryGUI_Operations.h>
83 #include <GEOMBase.h>
84
85 #include <SalomeApp_Study.h>
86
87 #include <LightApp_Application.h>
88
89 #include <CAM_Application.h>
90
91 #include <QtxListAction.h>
92 #include <QtxActionToolMgr.h>
93
94 #include <SUIT_Desktop.h>
95 #include <SUIT_ResourceMgr.h>
96 #include <SUIT_Session.h>
97 #include <SUIT_MessageBox.h>
98
99 #include <QAction>
100 #include <QApplication>
101
102 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
103                                         const int theKey, const bool isToggle, const QString& theSlot )
104 {
105   QString aSlot = theSlot;
106   if( aSlot.isEmpty() )
107     aSlot = SLOT( onOperation() );
108   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
109   std::string anImg = theImg.toStdString();
110   QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
111   std::string aMenu    = ( "MEN_" + theSuffix ).toStdString();
112   std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
113   std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
114   std::string aSlotStr = aSlot.toStdString();
115   return LightApp_Module::createAction( theId, tr( aDesktop.c_str() ), aPixmap,
116     tr( aMenu.c_str() ), tr( aToolbar.c_str() ),
117                 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
118 }
119
120 void HYDROGUI_Module::createActions()
121 {
122   createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
123   createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
124
125   createAction( CopyId, "COPY", "", Qt::CTRL + Qt::Key_C );
126   createAction( PasteId, "PASTE", "", Qt::CTRL + Qt::Key_V );
127
128   createAction( UpdateObjectId, "UPDATE_OBJECT" );
129   createAction( ForcedUpdateObjectId, "FORCED_UPDATE_OBJECT" );
130
131   createAction( ImportImageId, "IMPORT_IMAGE", "IMPORT_IMAGE_ICO", Qt::CTRL + Qt::Key_I );
132   createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE", "EDIT_IMPORTED_IMAGE_ICO" );
133   createAction( ObserveImageId, "OBSERVE_IMAGE", "OBSERVE_IMAGE_ICO" );
134   createAction( ExportImageId, "EXPORT_IMAGE", "EXPORT_IMAGE_ICO" );
135   createAction( RemoveImageRefsId, "REMOVE_IMAGE_REFERENCE", "REMOVE_IMAGE_REFERENCE_ICO" );
136   
137   createAction( ImportPolylineId, "IMPORT_POLYLINE", "IMPORT_POLYLINE_ICO" );
138   createAction( ImportSinusXId, "IMPORT_SINUSX", "IMPORT_SINUSX_ICO" );
139   createAction( ExportSinusXId, "EXPORT_SINUSX", "EXPORT_SINUSX_ICO" );
140   createAction( ImportLandCoverMapId, "IMPORT_LANDCOVER_MAP", "IMPORT_LANDCOVER_MAP_ICO" );
141
142   createAction( CreatePolylineId, "CREATE_POLYLINE", "CREATE_POLYLINE_ICO" );
143   createAction( EditPolylineId, "EDIT_POLYLINE", "EDIT_POLYLINE_ICO" ); 
144
145   createAction( CreatePolyline3DId, "CREATE_POLYLINE_3D", "CREATE_POLYLINE_3D_ICO" );
146   createAction( EditPolyline3DId, "EDIT_POLYLINE_3D", "EDIT_POLYLINE_3D_ICO" ); 
147
148   createAction( CreateProfileId, "CREATE_PROFILE", "CREATE_PROFILE_ICO" );
149   createAction( ImportProfilesId, "IMPORT_PROFILES", "IMPORT_PROFILES_ICO" );
150   createAction( EditProfileId, "EDIT_PROFILE", "EDIT_PROFILE_ICO" ); 
151   createAction( AllGeoreferencementId, "GEOREFERENCEMENT", "GEOREFERENCEMENT_ICO" ); 
152   createAction( SelectedGeoreferencementId, "GEOREFERENCEMENT", "GEOREFERENCEMENT_ICO" ); 
153   
154   createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "IMPORT_BATHYMETRY_ICO", Qt::CTRL + Qt::Key_B );
155   createAction( EditImportedBathymetryId, "EDIT_IMPORTED_BATHYMETRY", "EDIT_IMPORTED_BATHYMETRY_ICO" );
156   createAction( BathymetryBoundsId, "BATHYMETRY_BOUNDS", "BATHYMETRY_BOUNDS_ICO" );
157   createAction( BathymetrySelectionId, "BATHYMETRY_SELECTION", "BATHYMETRY_SELECTION_ICO",
158     0, true, SLOT( onBathymetrySelection() ) );
159
160   createAction( BathymetryTextId, "BATHYMETRY_TEXT", "BATHYMETRY_TEXT_ICO",
161     0, true, SLOT( onBathymetryText() ) );
162
163   createAction( BathymetryRescaleSelectionId, "BATHYMETRY_RESCALE_SELECTION", "BATHYMETRY_RESCALE_SELECTION_ICO" );
164   createAction( BathymetryRescaleVisibleId, "BATHYMETRY_RESCALE_VISIBLE", "BATHYMETRY_RESCALE_VISIBLE_ICO" );
165   createAction( BathymetryRescaleUserId, "BATHYMETRY_RESCALE_USER", "BATHYMETRY_RESCALE_USER_ICO" );
166   createAction( BathymetryRescaleDefaultId, "BATHYMETRY_RESCALE_DEFAULT", "BATHYMETRY_RESCALE_DEFAULT_ICO" );
167
168   createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE", "CREATE_IMMERSIBLE_ZONE_ICO" );
169   createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE", "EDIT_IMMERSIBLE_ZONE_ICO" );
170
171   createAction( CreateStreamId, "CREATE_STREAM", "CREATE_STREAM_ICO" );
172   createAction( EditStreamId, "EDIT_STREAM", "EDIT_STREAM_ICO" );
173
174   createAction( CreateChannelId, "CREATE_CHANNEL", "CREATE_CHANNEL_ICO" );
175   createAction( EditChannelId, "EDIT_CHANNEL", "EDIT_CHANNEL_ICO" );
176
177   createAction( CreateDigueId, "CREATE_DIGUE", "CREATE_DIGUE_ICO" );
178   createAction( EditDigueId, "EDIT_DIGUE", "EDIT_DIGUE_ICO" );
179
180   createAction( ImportStricklerTableFromFileId, "IMPORT_STRICKLER_TABLE", "IMPORT_STRICKLER_TABLE_ICO" );
181   createAction( ExportStricklerTableFromFileId, "EXPORT_STRICKLER_TABLE", "EXPORT_STRICKLER_TABLE_ICO" );
182   createAction( EditStricklerTableId, "EDIT_STRICKLER_TABLE", "EDIT_STRICKLER_TABLE_ICO" );
183   createAction( DuplicateStricklerTableId, "DUPLICATE_STRICKLER_TABLE", "DUPLICATE_STRICKLER_TABLE_ICO" );
184
185   createAction( CreateLandCoverMapId, "CREATE_LAND_COVER_MAP", "CREATE_LAND_COVER_MAP_ICO" );
186   
187   createAction( AddLandCoverId, "ADD_LAND_COVER", "ADD_LAND_COVER_ICO" );
188   createAction( RemoveLandCoverId, "REMOVE_LAND_COVER", "REMOVE_LAND_COVER_ICO" );
189   createAction( SplitLandCoverId, "SPLIT_LAND_COVER", "SPLIT_LAND_COVER_ICO" );
190   createAction( MergeLandCoverId, "MERGE_LAND_COVER", "MERGE_LAND_COVER_ICO" );
191   createAction( ChangeLandCoverTypeId, "CHANGE_LAND_COVER_TYPE", "CHANGE_LAND_COVER_TYPE_ICO" );
192
193   createAction( ImportObstacleFromFileId, "IMPORT_OBSTACLE_FROM_FILE", "IMPORT_OBSTACLE_FROM_FILE_ICO" );
194   createAction( ImportGeomObjectAsObstacleId, "IMPORT_GEOM_OBJECT_AS_OBSTACLE", "IMPORT_GEOM_OBJECT_ICO" );
195   createAction( ImportGeomObjectAsPolylineId, "IMPORT_GEOM_OBJECT_AS_POLYLINE", "IMPORT_GEOM_OBJECT_ICO" );
196   createAction( CreateBoxId, "CREATE_BOX", "CREATE_BOX_ICO" );
197   createAction( CreateCylinderId, "CREATE_CYLINDER", "CREATE_CYLINDER_ICO" );
198   createAction( TranslateObstacleId, "TRANSLATE_OBSTACLE" );
199
200   createAction( CreateCalculationId, "CREATE_CALCULATION", "CREATE_CALCULATION_ICO" );
201   createAction( EditCalculationId, "EDIT_CALCULATION", "EDIT_CALCULATION_ICO" );
202   createAction( ExportCalculationId, "EXPORT_CALCULATION", "EXPORT_CALCULATION_ICO" );
203
204   createAction( FuseImagesId, "FUSE_IMAGES", "FUSE_IMAGES_ICO" );
205   createAction( EditFusedImageId, "EDIT_FUSED_IMAGE", "EDIT_FUSED_IMAGE_ICO" );
206
207   createAction( CutImagesId, "CUT_IMAGES", "CUT_IMAGES_ICO" );
208   createAction( EditCutImageId, "EDIT_CUT_IMAGE", "EDIT_CUT_IMAGE_ICO" );
209
210   createAction( SplitImageId, "SPLIT_IMAGE", "SPLIT_IMAGE_ICO" );
211   createAction( EditSplitImageId, "EDIT_SPLIT_IMAGE", "EDIT_SPLIT_IMAGE_ICO" );
212
213   createAction( RecognizeContoursId, "RECOGNIZE_CONTOURS", "RECOGNIZE_CONTOURS_ICO" );
214
215   createAction( CopyViewerPositionId, "COPY_VIEWER_POSITION", "" );
216
217   createAction( DeleteId, "DELETE", "", Qt::Key_Delete, false,
218                 SLOT( onDelete() ) );
219
220   createAction( SetColorId, "COLOR" );
221   createAction( SetTransparencyId, "TRANSPARENCY" );
222   createAction( SetZLevelId, "ZLEVEL" );
223   createAction( EditLocalCSId, "EDIT_LOCAL_CS" );
224
225   createAction( ShowId, "SHOW" );
226   createAction( ShowOnlyId, "SHOW_ONLY" );
227   createAction( ShowAllId, "SHOW_ALL" );
228   createAction( HideId, "HIDE" );
229   createAction( HideAllId, "HIDE_ALL" );
230
231   createAction( RiverBottomId, "CREATE_STREAM_BOTTOM", "CREATE_STREAM_BOTTOM_ICO" );
232   createAction( RiverBottomContextId, "CREATE_STREAM_BOTTOM", "CREATE_STREAM_BOTTOM_ICO" );
233   createAction( ProfileInterpolateId, "PROFILE_INTERPOLATE", "PROFILE_INTERPOLATE_ICO" );
234
235   createAction( SubmersibleId, "SUBMERSIBLE", "SUBMERSIBLE_ICO" );
236   createAction( ExportToShapeFileID, "EXPORT_TO_SHAPE_FILE", "EXPORT_TO_SHAPE_FILE_ICO" );
237
238   createAction( PolylineExtractionId, "POLYLINE_EXTRACTION" );
239   createAction( SplitPolylinesId, "SPLIT_POLYLINES", "SPLIT_POLYLINES_ICO" );
240   createAction( MergePolylinesId, "MERGE_POLYLINES", "MERGE_POLYLINES_ICO" );
241
242   createAction( LandCoverScalarMapModeOnId, "LC_SCALARMAP_COLORING_ON" );
243   createAction( LandCoverScalarMapModeOffId, "LC_SCALARMAP_COLORING_OFF" );
244 }
245
246 void HYDROGUI_Module::createMenus()
247 {
248   int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
249   int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
250   createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
251   createMenu( separator(), aFileMenu, -1, aCustomPos );
252
253   int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
254   createMenu( UndoId, anEditMenu );
255   createMenu( RedoId, anEditMenu );
256   createMenu( separator(), anEditMenu );
257   createMenu( CopyId, anEditMenu );
258   createMenu( PasteId, anEditMenu );
259
260   int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
261   int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
262   createMenu( ImportSinusXId, aHydroId, -1, -1 );
263   createMenu( ExportSinusXId, aHydroId, -1, -1 );  
264   
265   createMenu( ImportBathymetryId, aHydroId, -1, -1 );
266   createMenu( ImportStricklerTableFromFileId, aHydroId, -1, -1 );
267   createMenu( CreatePolyline3DId, aHydroId, -1, -1 );
268   createMenu( CreateImmersibleZoneId, aHydroId, -1, -1 );
269   createMenu( CreateChannelId, aHydroId, -1, -1 );
270   createMenu( CreateDigueId, aHydroId, -1, -1 );
271
272   int aNewImageId = createMenu( tr( "MEN_DESK_IMAGE" ), aHydroId, -1 );
273   createMenu( ImportImageId, aNewImageId, -1, -1 );
274   createMenu( separator(), aNewImageId );
275   createMenu( FuseImagesId, aNewImageId, -1, -1 );
276   createMenu( CutImagesId, aNewImageId, -1, -1 );
277   createMenu( SplitImageId, aNewImageId, -1, -1 );
278
279   int aNewPolylineId = createMenu( tr( "MEN_DESK_POLYLINE" ), aHydroId, -1 );
280   createMenu( ImportPolylineId, aNewPolylineId, -1, -1 );
281   createMenu( CreatePolylineId, aNewPolylineId, -1, -1 );
282   createMenu( separator(), aNewPolylineId );
283   createMenu( SplitPolylinesId, aNewPolylineId, -1, -1 );
284   createMenu( MergePolylinesId, aNewPolylineId, -1, -1 );
285
286   int aNewProfileId = createMenu( tr( "MEN_DESK_PROFILE" ), aHydroId, -1 );
287   createMenu( CreateProfileId, aNewProfileId, -1, -1 );
288   createMenu( ImportProfilesId, aNewProfileId, -1, -1 );
289   createMenu( separator(), aNewProfileId );
290   createMenu( AllGeoreferencementId, aNewProfileId, -1, -1 );
291
292   int aStreamMenuId = createMenu( tr( "MEN_DESK_STREAM" ), aHydroId, -1 );
293   createMenu( CreateStreamId, aStreamMenuId, -1, -1 );
294   createMenu( separator(), aStreamMenuId );
295   createMenu( RiverBottomId, aStreamMenuId, -1, -1 );
296   createMenu( ProfileInterpolateId, aStreamMenuId, -1, -1 );
297
298   int anObstacleMenuId = createMenu( tr( "MEN_DESK_OBSTACLE" ), aHydroId, -1 );
299   createMenu( ImportObstacleFromFileId, anObstacleMenuId, -1, -1 );
300   createMenu( separator(), anObstacleMenuId );
301   createMenu( CreateBoxId, anObstacleMenuId, -1, -1 );
302   createMenu( CreateCylinderId, anObstacleMenuId, -1, -1 );
303
304   int aLandCoverMapMenuId = createMenu( tr( "MEN_DESK_LAND_COVER_MAP" ), aHydroId, -1 );
305   createMenu( ImportLandCoverMapId, aLandCoverMapMenuId, -1, -1 );
306   createMenu( CreateLandCoverMapId, aLandCoverMapMenuId, -1, -1 );
307   createMenu( separator(), aLandCoverMapMenuId );
308   createMenu( AddLandCoverId, aLandCoverMapMenuId, -1, -1 );
309   createMenu( RemoveLandCoverId, aLandCoverMapMenuId, -1, -1 );
310   createMenu( separator(), aLandCoverMapMenuId );
311   createMenu( SplitLandCoverId, aLandCoverMapMenuId, -1, -1 );
312   createMenu( MergeLandCoverId, aLandCoverMapMenuId, -1, -1 );
313   createMenu( ChangeLandCoverTypeId, aLandCoverMapMenuId, -1, -1 );
314   
315   createMenu( CreateCalculationId, aHydroId, -1, -1 );
316   createMenu( separator(), aHydroId );
317   createMenu( EditLocalCSId, aHydroId, -1, -1 );
318   createMenu( separator(), aHydroId );
319 }
320
321 void HYDROGUI_Module::createPopups()
322 {
323 }
324
325 void HYDROGUI_Module::createToolbars()
326 {
327   int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
328   createTool( UndoId, aToolBar );
329   createTool( RedoId, aToolBar );
330
331   createTool( separator(), aToolBar );
332   createTool( ImportImageId, aToolBar );
333   createTool( ImportPolylineId, aToolBar );
334   createTool( ImportSinusXId, aToolBar );
335   createTool( ExportSinusXId, aToolBar );
336   createTool( ImportLandCoverMapId, aToolBar );
337
338   createTool( ImportBathymetryId, aToolBar );
339   createTool( CreatePolylineId, aToolBar );
340   createTool( CreatePolyline3DId, aToolBar );
341
342   createTool( separator(), aToolBar );
343   createTool( CreateProfileId, aToolBar );
344   createTool( ImportProfilesId, aToolBar );
345   createTool( AllGeoreferencementId, aToolBar );
346
347   createTool( separator(), aToolBar );
348   createTool( CreateChannelId, aToolBar );
349   createTool( CreateDigueId, aToolBar );
350
351   createTool( separator(), aToolBar );
352   createTool( CreateImmersibleZoneId, aToolBar );
353   createTool( CreateStreamId, aToolBar );
354
355   createTool( separator(), aToolBar );
356   createTool( ImportObstacleFromFileId, aToolBar );
357   createTool( CreateBoxId, aToolBar );
358   createTool( CreateCylinderId, aToolBar );
359
360   createTool( separator(), aToolBar );
361   createTool( ImportStricklerTableFromFileId, aToolBar );
362
363   createTool( separator(), aToolBar );
364   createTool( CreateLandCoverMapId, aToolBar );
365   createTool( AddLandCoverId, aToolBar );
366   createTool( RemoveLandCoverId, aToolBar );
367   createTool( SplitLandCoverId, aToolBar );
368   createTool( MergeLandCoverId, aToolBar );
369   createTool( ChangeLandCoverTypeId, aToolBar );
370   enableLCMActions();
371
372   createTool( separator(), aToolBar );
373   createTool( CreateCalculationId, aToolBar );
374
375   createTool( separator(), aToolBar );
376   createTool( FuseImagesId, aToolBar );
377   createTool( CutImagesId, aToolBar );
378   createTool( SplitImageId, aToolBar );
379
380   createTool( separator(), aToolBar );
381   createTool( BathymetrySelectionId, aToolBar );
382   createTool( BathymetryTextId, aToolBar );
383   createTool( BathymetryRescaleSelectionId, aToolBar );
384   createTool( BathymetryRescaleVisibleId, aToolBar );
385   createTool( BathymetryRescaleUserId, aToolBar );
386   createTool( BathymetryRescaleDefaultId, aToolBar );
387 }
388
389 void HYDROGUI_Module::createUndoRedoActions()
390 {
391   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
392
393   QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
394     aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
395     Qt::CTRL + Qt::Key_Z, application()->desktop() );
396     
397   QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
398     aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
399     Qt::CTRL + Qt::Key_Y, application()->desktop() );
400   
401   registerAction( UndoId, anEditUndo );
402   registerAction( RedoId, anEditRedo );
403
404   anEditUndo->setComment( tr( "STB_UNDO" ) );
405   anEditRedo->setComment( tr( "STB_REDO" ) );
406
407   connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
408   connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
409 }
410
411 void HYDROGUI_Module::updateUndoRedoControls()
412 {
413   HYDROGUI_DataModel* aModel = getDataModel();
414
415   QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
416   QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
417
418   bool aCanUndo = aModel->canUndo();
419   bool aCanRedo = aModel->canRedo();
420
421   if( aCanUndo )
422     aUndoAction->addNames( aModel->undoNames() );
423   aUndoAction->setEnabled( aCanUndo );
424
425   if( aCanRedo )
426     aRedoAction->addNames( aModel->redoNames() );
427   aRedoAction->setEnabled( aCanRedo );
428 }
429
430 void HYDROGUI_Module::enableLCMActions()
431 {
432   HYDROData_Iterator anIt( HYDROData_Document::Document( getStudyId() ), KIND_LAND_COVER_MAP );
433   bool anEnableTools = anIt.More();
434
435   QtxListAction* anAction;
436   anAction = (QtxListAction*)action( AddLandCoverId );
437   if ( anAction ) anAction->setEnabled( anEnableTools );
438   anAction = (QtxListAction*)action( RemoveLandCoverId );
439   if ( anAction ) anAction->setEnabled( anEnableTools );
440   anAction = (QtxListAction*)action( SplitLandCoverId );
441   if ( anAction ) anAction->setEnabled( anEnableTools );
442   anAction = (QtxListAction*)action( MergeLandCoverId );
443   if ( anAction ) anAction->setEnabled( anEnableTools );
444   anAction = (QtxListAction*)action( ChangeLandCoverTypeId );
445   if ( anAction ) anAction->setEnabled( anEnableTools );
446 }
447
448 void HYDROGUI_Module::onOperation()
449 {
450   const QAction* anAction = dynamic_cast<const QAction*>( sender() );
451   int anId = actionId( anAction );
452   if( anId >= 0 )
453     startOperation( anId );
454 }
455
456 void HYDROGUI_Module::onDelete()
457 {
458   SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
459   HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
460   if ( aPolylineOp && aPolylineOp->deleteEnabled() )
461     aPolylineOp->deleteSelected();
462   else
463     startOperation( DeleteId );
464 }
465
466 bool HYDROGUI_Module::onUndo( int theNumActions )
467 {
468   QApplication::setOverrideCursor( Qt::WaitCursor );
469   bool anIsOk = true;
470   HYDROGUI_DataModel* aModel = getDataModel();
471   if( aModel )
472   {
473     while( theNumActions > 0 )
474     {
475       if( !aModel->undo() )
476       {
477         anIsOk = false;
478         break;
479       }
480       theNumActions--;
481     }
482     update( UF_All );
483   }
484   QApplication::restoreOverrideCursor();
485   return anIsOk;
486 }
487
488 bool HYDROGUI_Module::onRedo( int theNumActions )
489 {
490   QApplication::setOverrideCursor( Qt::WaitCursor );
491   bool anIsOk = true;
492   HYDROGUI_DataModel* aModel = getDataModel();
493   if( aModel )
494   {
495     while( theNumActions > 0 )
496     {
497       if( !aModel->redo() )
498       {
499         anIsOk = false;
500         break;
501       }
502       theNumActions--;
503     }
504     update( UF_All );
505   }
506   QApplication::restoreOverrideCursor();
507   return anIsOk;
508 }
509
510 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
511 {
512   LightApp_Operation* anOp = 0;
513   HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
514   switch( theId )
515   {
516   case SaveVisualStateId:
517   case LoadVisualStateId:
518     anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
519     break;
520   case CopyId:
521   case PasteId:
522     anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
523     break;
524   case ImportImageId:
525   case EditImportedImageId:
526     anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
527     break;
528   case ImportPolylineId:
529     anOp = new HYDROGUI_ImportPolylineOp( aModule/*, theId == EditImportedPolylineId*/ );
530     break;
531   case ImportSinusXId:
532     anOp = new HYDROGUI_ImportSinusXOp( aModule );
533     break;
534   case ExportSinusXId:
535     anOp = new HYDROGUI_ExportSinusXOp( aModule );
536     break;
537   case ObserveImageId:
538     anOp = new HYDROGUI_ObserveImageOp( aModule );
539     break;
540   case ExportImageId:
541     anOp = new HYDROGUI_ExportImageOp( aModule );
542     break;
543   case UpdateObjectId:
544   case ForcedUpdateObjectId:
545     anOp = new HYDROGUI_UpdateObjectOp( aModule, theId == ForcedUpdateObjectId );
546     break;
547   case ExportToShapeFileID:
548     anOp = new HYDROGUI_ExportFileOp( aModule );
549     break;
550   case ImportLandCoverMapId:
551     anOp = new HYDROGUI_ImportLandCoverMapOp( aModule );
552     break;
553   case RemoveImageRefsId:
554     anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
555     break;
556   case CreatePolyline3DId:
557   case EditPolyline3DId:
558     anOp = new HYDROGUI_Poly3DOp( aModule, theId == EditPolyline3DId );
559     break;
560   case CreatePolylineId:
561   case EditPolylineId:
562     anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
563     break;
564   case CreateProfileId:
565   case EditProfileId:
566     anOp = new HYDROGUI_ProfileOp( aModule, theId == EditProfileId );
567     break;
568   case ProfileInterpolateId:
569     anOp = new HYDROGUI_ProfileInterpolateOp( aModule );
570     break;
571   case ImportProfilesId:
572     anOp = new HYDROGUI_ImportProfilesOp( aModule ) ;
573     break;
574   case AllGeoreferencementId:
575     anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::All ) ;
576     break;
577   case SelectedGeoreferencementId:
578     anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::Selected ) ;
579     break;
580   case ImportBathymetryId:
581   case EditImportedBathymetryId:
582     anOp = new HYDROGUI_ImportBathymetryOp( aModule, theId == EditImportedBathymetryId  );
583     break;
584   case BathymetryBoundsId:
585     anOp = new HYDROGUI_BathymetryBoundsOp( aModule );
586     break;
587   case BathymetrySelectionId:
588     anOp = new HYDROGUI_BathymetrySelectionOp( aModule );
589     break;
590   case BathymetryTextId:
591   case BathymetryRescaleSelectionId:
592   case BathymetryRescaleVisibleId:
593   case BathymetryRescaleUserId:
594   case BathymetryRescaleDefaultId:
595     anOp = new HYDROGUI_BathymetryOp( aModule, theId );
596     break;
597
598   case CreateImmersibleZoneId:
599   case EditImmersibleZoneId:
600     anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
601     break;
602   case CreateStreamId:
603   case EditStreamId:
604     anOp = new HYDROGUI_StreamOp( aModule, theId == EditStreamId );
605     break;
606   case CreateChannelId:
607   case EditChannelId:
608     anOp = new HYDROGUI_ChannelOp( aModule, theId == EditChannelId );
609     break;
610   case CreateDigueId:
611   case EditDigueId:
612     anOp = new HYDROGUI_DigueOp( aModule, theId == EditDigueId );
613     break;
614   case ImportStricklerTableFromFileId:
615   case ExportStricklerTableFromFileId:
616   case EditStricklerTableId:
617     anOp = new HYDROGUI_StricklerTableOp( aModule, theId );
618     break;
619   case CreateLandCoverMapId:
620   case AddLandCoverId:
621   case RemoveLandCoverId:
622   case SplitLandCoverId:
623   case MergeLandCoverId:
624   case ChangeLandCoverTypeId:
625     anOp = new HYDROGUI_LandCoverMapOp( aModule, theId );
626     break;
627   case DuplicateStricklerTableId:
628     anOp = new HYDROGUI_DuplicateOp( aModule );
629     break;
630   case CreateCalculationId:
631   case EditCalculationId:
632     anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
633     break;
634   case ExportCalculationId:
635     anOp = new HYDROGUI_ExportCalculationOp( aModule );
636     break;
637   case FuseImagesId:
638   case EditFusedImageId:
639     anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
640     break;
641   case CutImagesId:
642   case EditCutImageId:
643     anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
644     break;
645   case SplitImageId:
646   case EditSplitImageId:
647     anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplitImageId );
648     break;
649   case ImportObstacleFromFileId:
650     anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule );
651     break;
652   case ImportGeomObjectAsObstacleId:
653     anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelectedAsObstacle );
654     break;
655   case ImportGeomObjectAsPolylineId:
656     anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelectedAsPolyline );
657     break;
658   case CreateBoxId:
659     anOp = new HYDROGUI_ImportGeomObjectOp( aModule, 
660       HYDROGUI_ImportGeomObjectOp::ImportCreatedAsObstacle, GEOMOp::OpBox );
661     break;
662   case CreateCylinderId:
663     anOp = new HYDROGUI_ImportGeomObjectOp( aModule, 
664       HYDROGUI_ImportGeomObjectOp::ImportCreatedAsObstacle, GEOMOp::OpCylinder );
665     break;
666   case TranslateObstacleId:
667     anOp = new HYDROGUI_TranslateObstacleOp( aModule );
668     break;
669   case CopyViewerPositionId:
670     anOp = new HYDROGUI_CopyPastePositionOp( aModule, false );
671     break;
672   case DeleteId:
673     anOp = new HYDROGUI_DeleteOp( aModule );
674     break;
675   case SetColorId:
676     anOp = new HYDROGUI_SetColorOp( aModule );
677     break;
678   case SetTransparencyId:
679     anOp = new HYDROGUI_SetTransparencyOp( aModule );
680     break;
681   case SetZLevelId:
682     anOp = new HYDROGUI_ZLevelsOp( aModule );
683     break;
684   case EditLocalCSId:
685     anOp = new HYDROGUI_LocalCSOp( aModule );
686     break;
687   case RiverBottomId:
688   case RiverBottomContextId:
689     anOp = new HYDROGUI_RiverBottomOp( aModule );
690     break;
691   case RecognizeContoursId:
692     anOp = new HYDROGUI_RecognizeContoursOp( aModule );
693     break;
694   case ShowId:
695   case ShowOnlyId:
696   case ShowAllId:
697   case HideId:
698   case HideAllId:
699     anOp = new HYDROGUI_ShowHideOp( aModule, theId );
700     break;
701   case SubmersibleId:
702     anOp = new HYDROGUI_SubmersibleOp( aModule );
703     break;
704   case PolylineExtractionId:
705     anOp = new HYDROGUI_PolylineExtractionOp( aModule );
706     break;
707   case SplitPolylinesId:
708     anOp = new HYDROGUI_SplitPolylinesOp( aModule );
709     break;
710   case MergePolylinesId:
711     anOp = new HYDROGUI_MergePolylinesOp( aModule );
712     break;
713   case LandCoverScalarMapModeOnId:
714   case LandCoverScalarMapModeOffId:
715     anOp = new HYDROGUI_LandCoverColoringOp( aModule, theId );
716     break;
717   }
718
719   if( !anOp )
720     anOp = LightApp_Module::createOperation( theId );
721
722   return anOp;
723 }
724
725 bool HYDROGUI_Module::reusableOperation( const int id )
726 {
727   if ( id == ImportGeomObjectAsObstacleId ||
728        id == ImportGeomObjectAsPolylineId ) {
729     return false;
730   }
731
732   return LightApp_Module::reusableOperation( id );
733 }
734
735 /**
736  * Returns true if the object with the given entry can be renamed.
737  * @param theEntry the object entry
738  */
739 bool HYDROGUI_Module::renameAllowed( const QString& theEntry ) const
740 {
741   // Allow to rename all HYDRO objects
742   Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
743   return !anEntity.IsNull();
744 }
745 /**
746  * Returns true if the object with the given entry is renamed.
747  * @param theEntry the object entry
748  * @param theName the new name
749  */
750 bool HYDROGUI_Module::renameObject( const QString& theEntry, const QString& theName )
751 {
752   Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
753   bool aRes = false;
754   if ( !anEntity.IsNull() )
755   {
756     HYDROGUI_DataModel* aModel = getDataModel();
757     if( aModel )
758     {
759       if( anEntity->GetName() != theName )
760       {
761         // check that there are no other objects with the same name in the document
762         Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( this, theName );
763         if ( anObject.IsNull() )
764         {
765           SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
766           if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
767           {
768             anEntity->SetName( theName );
769             aRes = true;
770           }
771           else
772           {
773             aRes = aModel->rename( anEntity, theName );
774           }
775         }
776         else
777         {
778           // Inform the user that the name is already used
779           QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
780           QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
781           SUIT_MessageBox::critical( getApp()->desktop(), aTitle, aMessage );
782         }
783       }
784     }
785   }
786   return aRes;
787 }
788
789 void HYDROGUI_Module::onBathymetrySelection()
790 {
791   QAction* a = qobject_cast<QAction*>( sender() );
792   if( !a )
793     return;
794
795   bool isChecked = a->isChecked();
796   if( isChecked )
797     startOperation( BathymetrySelectionId );
798   else
799     operation( BathymetrySelectionId )->abort();
800 }
801
802 void HYDROGUI_Module::onBathymetryText()
803 {
804   //TODO
805 }