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