]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_Operations.cxx
Salome HOME
refs #1323, icons of imm. zones (only) are changing while switching between sumb...
[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_UnSubmersibleOp.h"
64 #include "HYDROGUI_StricklerTableOp.h"
65 #include "HYDROGUI_DuplicateOp.h"
66 #include "HYDROGUI_LandCoverMapOp.h"
67 #include "HYDROGUI_PolylineExtractionOp.h"
68 #include "HYDROGUI_ExportSinusXOp.h"
69 #include "HYDROGUI_MergePolylinesOp.h"
70 #include "HYDROGUI_SplitPolylinesOp.h"
71 #include "HYDROGUI_LandCoverColoringOp.h"
72 #include "HYDROGUI_SetTransparencyOp.h"
73 #include "HYDROGUI_ImportLandCoverMapOp.h"
74 #include "HYDROGUI_BathymetrySelectionOp.h"
75 #include "HYDROGUI_BathymetryOp.h"
76 #include "HYDROGUI_RegenerateRegionColorsOp.h"
77
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", "UNSUBMERSIBLE_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
250 }
251
252 void HYDROGUI_Module::createMenus()
253 {
254   int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
255   int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
256   createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
257   createMenu( separator(), aFileMenu, -1, aCustomPos );
258
259   int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
260   createMenu( UndoId, anEditMenu );
261   createMenu( RedoId, anEditMenu );
262   createMenu( separator(), anEditMenu );
263   createMenu( CopyId, anEditMenu );
264   createMenu( PasteId, anEditMenu );
265
266   int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
267   int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
268   createMenu( ImportSinusXId, aHydroId, -1, -1 );
269   createMenu( ExportSinusXId, aHydroId, -1, -1 );  
270   
271   createMenu( ImportBathymetryId, aHydroId, -1, -1 );
272   createMenu( ImportStricklerTableFromFileId, aHydroId, -1, -1 );
273   createMenu( CreatePolyline3DId, aHydroId, -1, -1 );
274   createMenu( CreateImmersibleZoneId, aHydroId, -1, -1 );
275   createMenu( CreateChannelId, aHydroId, -1, -1 );
276   createMenu( CreateDigueId, aHydroId, -1, -1 );
277
278   int aNewImageId = createMenu( tr( "MEN_DESK_IMAGE" ), aHydroId, -1 );
279   createMenu( ImportImageId, aNewImageId, -1, -1 );
280   createMenu( separator(), aNewImageId );
281   createMenu( FuseImagesId, aNewImageId, -1, -1 );
282   createMenu( CutImagesId, aNewImageId, -1, -1 );
283   createMenu( SplitImageId, aNewImageId, -1, -1 );
284
285   int aNewPolylineId = createMenu( tr( "MEN_DESK_POLYLINE" ), aHydroId, -1 );
286   createMenu( ImportPolylineId, aNewPolylineId, -1, -1 );
287   createMenu( CreatePolylineId, aNewPolylineId, -1, -1 );
288   createMenu( separator(), aNewPolylineId );
289   createMenu( SplitPolylinesId, aNewPolylineId, -1, -1 );
290   createMenu( MergePolylinesId, aNewPolylineId, -1, -1 );
291
292   int aNewProfileId = createMenu( tr( "MEN_DESK_PROFILE" ), aHydroId, -1 );
293   createMenu( CreateProfileId, aNewProfileId, -1, -1 );
294   createMenu( ImportProfilesId, aNewProfileId, -1, -1 );
295   createMenu( separator(), aNewProfileId );
296   createMenu( AllGeoreferencementId, aNewProfileId, -1, -1 );
297
298   int aStreamMenuId = createMenu( tr( "MEN_DESK_STREAM" ), aHydroId, -1 );
299   createMenu( CreateStreamId, aStreamMenuId, -1, -1 );
300   createMenu( separator(), aStreamMenuId );
301   createMenu( RiverBottomId, aStreamMenuId, -1, -1 );
302   createMenu( ProfileInterpolateId, aStreamMenuId, -1, -1 );
303
304   int anObstacleMenuId = createMenu( tr( "MEN_DESK_OBSTACLE" ), aHydroId, -1 );
305   createMenu( ImportObstacleFromFileId, anObstacleMenuId, -1, -1 );
306   createMenu( separator(), anObstacleMenuId );
307   createMenu( CreateBoxId, anObstacleMenuId, -1, -1 );
308   createMenu( CreateCylinderId, anObstacleMenuId, -1, -1 );
309
310   int aLandCoverMapMenuId = createMenu( tr( "MEN_DESK_LAND_COVER_MAP" ), aHydroId, -1 );
311   createMenu( ImportLandCoverMapId, aLandCoverMapMenuId, -1, -1 );
312   createMenu( CreateLandCoverMapId, aLandCoverMapMenuId, -1, -1 );
313   createMenu( separator(), aLandCoverMapMenuId );
314   createMenu( AddLandCoverId, aLandCoverMapMenuId, -1, -1 );
315   createMenu( RemoveLandCoverId, aLandCoverMapMenuId, -1, -1 );
316   createMenu( separator(), aLandCoverMapMenuId );
317   createMenu( SplitLandCoverId, aLandCoverMapMenuId, -1, -1 );
318   createMenu( MergeLandCoverId, aLandCoverMapMenuId, -1, -1 );
319   createMenu( ChangeLandCoverTypeId, aLandCoverMapMenuId, -1, -1 );
320   
321   createMenu( CreateCalculationId, aHydroId, -1, -1 );
322   createMenu( separator(), aHydroId );
323   createMenu( EditLocalCSId, aHydroId, -1, -1 );
324   createMenu( separator(), aHydroId );
325 }
326
327 void HYDROGUI_Module::createPopups()
328 {
329 }
330
331 void HYDROGUI_Module::createToolbars()
332 {
333   int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
334   createTool( UndoId, aToolBar );
335   createTool( RedoId, aToolBar );
336
337   createTool( separator(), aToolBar );
338   createTool( ImportImageId, aToolBar );
339   createTool( ImportPolylineId, aToolBar );
340   createTool( ImportSinusXId, aToolBar );
341   createTool( ExportSinusXId, aToolBar );
342   createTool( ImportLandCoverMapId, aToolBar );
343
344   createTool( ImportBathymetryId, aToolBar );
345   createTool( CreatePolylineId, aToolBar );
346   createTool( CreatePolyline3DId, aToolBar );
347
348   createTool( separator(), aToolBar );
349   createTool( CreateProfileId, aToolBar );
350   createTool( ImportProfilesId, aToolBar );
351   createTool( AllGeoreferencementId, aToolBar );
352
353   createTool( separator(), aToolBar );
354   createTool( CreateChannelId, aToolBar );
355   createTool( CreateDigueId, aToolBar );
356
357   createTool( separator(), aToolBar );
358   createTool( CreateImmersibleZoneId, aToolBar );
359   createTool( CreateStreamId, aToolBar );
360
361   createTool( separator(), aToolBar );
362   createTool( ImportObstacleFromFileId, aToolBar );
363   createTool( CreateBoxId, aToolBar );
364   createTool( CreateCylinderId, aToolBar );
365
366   createTool( separator(), aToolBar );
367   createTool( ImportStricklerTableFromFileId, aToolBar );
368
369   createTool( separator(), aToolBar );
370   createTool( CreateLandCoverMapId, aToolBar );
371   createTool( AddLandCoverId, aToolBar );
372   createTool( RemoveLandCoverId, aToolBar );
373   createTool( SplitLandCoverId, aToolBar );
374   createTool( MergeLandCoverId, aToolBar );
375   createTool( ChangeLandCoverTypeId, aToolBar );
376   enableLCMActions();
377
378   createTool( separator(), aToolBar );
379   createTool( CreateCalculationId, aToolBar );
380
381   createTool( separator(), aToolBar );
382   createTool( FuseImagesId, aToolBar );
383   createTool( CutImagesId, aToolBar );
384   createTool( SplitImageId, aToolBar );
385
386   createTool( separator(), aToolBar );
387   createTool( BathymetrySelectionId, aToolBar );
388   createTool( BathymetryTextId, aToolBar );
389   createTool( BathymetryRescaleSelectionId, aToolBar );
390   createTool( BathymetryRescaleVisibleId, aToolBar );
391   createTool( BathymetryRescaleUserId, aToolBar );
392   createTool( BathymetryRescaleDefaultId, aToolBar );
393 }
394
395 void HYDROGUI_Module::createUndoRedoActions()
396 {
397   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
398
399   QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
400     aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
401     Qt::CTRL + Qt::Key_Z, application()->desktop() );
402     
403   QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
404     aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
405     Qt::CTRL + Qt::Key_Y, application()->desktop() );
406   
407   registerAction( UndoId, anEditUndo );
408   registerAction( RedoId, anEditRedo );
409
410   anEditUndo->setComment( tr( "STB_UNDO" ) );
411   anEditRedo->setComment( tr( "STB_REDO" ) );
412
413   connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
414   connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
415 }
416
417 void HYDROGUI_Module::updateUndoRedoControls()
418 {
419   HYDROGUI_DataModel* aModel = getDataModel();
420
421   QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
422   QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
423
424   bool aCanUndo = aModel->canUndo();
425   bool aCanRedo = aModel->canRedo();
426
427   if( aCanUndo )
428     aUndoAction->addNames( aModel->undoNames() );
429   aUndoAction->setEnabled( aCanUndo );
430
431   if( aCanRedo )
432     aRedoAction->addNames( aModel->redoNames() );
433   aRedoAction->setEnabled( aCanRedo );
434 }
435
436 void HYDROGUI_Module::enableLCMActions()
437 {
438   HYDROData_Iterator anIt( HYDROData_Document::Document( getStudyId() ), KIND_LAND_COVER_MAP );
439   bool anEnableTools = anIt.More();
440
441   QtxListAction* anAction;
442   anAction = (QtxListAction*)action( AddLandCoverId );
443   if ( anAction ) anAction->setEnabled( anEnableTools );
444   anAction = (QtxListAction*)action( RemoveLandCoverId );
445   if ( anAction ) anAction->setEnabled( anEnableTools );
446   anAction = (QtxListAction*)action( SplitLandCoverId );
447   if ( anAction ) anAction->setEnabled( anEnableTools );
448   anAction = (QtxListAction*)action( MergeLandCoverId );
449   if ( anAction ) anAction->setEnabled( anEnableTools );
450   anAction = (QtxListAction*)action( ChangeLandCoverTypeId );
451   if ( anAction ) anAction->setEnabled( anEnableTools );
452 }
453
454 void HYDROGUI_Module::onOperation()
455 {
456   const QAction* anAction = dynamic_cast<const QAction*>( sender() );
457   int anId = actionId( anAction );
458   if( anId >= 0 )
459     startOperation( anId );
460 }
461
462 void HYDROGUI_Module::onDelete()
463 {
464   SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
465   HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
466   if ( aPolylineOp && aPolylineOp->deleteEnabled() )
467     aPolylineOp->deleteSelected();
468   else
469     startOperation( DeleteId );
470 }
471
472 bool HYDROGUI_Module::onUndo( int theNumActions )
473 {
474   QApplication::setOverrideCursor( Qt::WaitCursor );
475   bool anIsOk = true;
476   HYDROGUI_DataModel* aModel = getDataModel();
477   if( aModel )
478   {
479     while( theNumActions > 0 )
480     {
481       if( !aModel->undo() )
482       {
483         anIsOk = false;
484         break;
485       }
486       theNumActions--;
487     }
488     update( UF_All );
489   }
490   QApplication::restoreOverrideCursor();
491   return anIsOk;
492 }
493
494 bool HYDROGUI_Module::onRedo( int theNumActions )
495 {
496   QApplication::setOverrideCursor( Qt::WaitCursor );
497   bool anIsOk = true;
498   HYDROGUI_DataModel* aModel = getDataModel();
499   if( aModel )
500   {
501     while( theNumActions > 0 )
502     {
503       if( !aModel->redo() )
504       {
505         anIsOk = false;
506         break;
507       }
508       theNumActions--;
509     }
510     update( UF_All );
511   }
512   QApplication::restoreOverrideCursor();
513   return anIsOk;
514 }
515
516 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
517 {
518   LightApp_Operation* anOp = 0;
519   HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
520   switch( theId )
521   {
522   case SaveVisualStateId:
523   case LoadVisualStateId:
524     anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
525     break;
526   case CopyId:
527   case PasteId:
528     anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
529     break;
530   case ImportImageId:
531   case EditImportedImageId:
532     anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
533     break;
534   case ImportPolylineId:
535     anOp = new HYDROGUI_ImportPolylineOp( aModule/*, theId == EditImportedPolylineId*/ );
536     break;
537   case ImportSinusXId:
538     anOp = new HYDROGUI_ImportSinusXOp( aModule );
539     break;
540   case ExportSinusXId:
541     anOp = new HYDROGUI_ExportSinusXOp( aModule );
542     break;
543   case ObserveImageId:
544     anOp = new HYDROGUI_ObserveImageOp( aModule );
545     break;
546   case ExportImageId:
547     anOp = new HYDROGUI_ExportImageOp( aModule );
548     break;
549   case UpdateObjectId:
550   case ForcedUpdateObjectId:
551     anOp = new HYDROGUI_UpdateObjectOp( aModule, theId == ForcedUpdateObjectId );
552     break;
553   case ExportToShapeFileID:
554     anOp = new HYDROGUI_ExportFileOp( aModule );
555     break;
556   case ImportLandCoverMapId:
557     anOp = new HYDROGUI_ImportLandCoverMapOp( aModule );
558     break;
559   case RemoveImageRefsId:
560     anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
561     break;
562   case CreatePolyline3DId:
563   case EditPolyline3DId:
564     anOp = new HYDROGUI_Poly3DOp( aModule, theId == EditPolyline3DId );
565     break;
566   case CreatePolylineId:
567   case EditPolylineId:
568     anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
569     break;
570   case CreateProfileId:
571   case EditProfileId:
572     anOp = new HYDROGUI_ProfileOp( aModule, theId == EditProfileId );
573     break;
574   case ProfileInterpolateId:
575     anOp = new HYDROGUI_ProfileInterpolateOp( aModule );
576     break;
577   case ImportProfilesId:
578     anOp = new HYDROGUI_ImportProfilesOp( aModule ) ;
579     break;
580   case AllGeoreferencementId:
581     anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::All ) ;
582     break;
583   case SelectedGeoreferencementId:
584     anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::Selected ) ;
585     break;
586   case ImportBathymetryId:
587   case EditImportedBathymetryId:
588     anOp = new HYDROGUI_ImportBathymetryOp( aModule, theId == EditImportedBathymetryId  );
589     break;
590   case BathymetryBoundsId:
591     anOp = new HYDROGUI_BathymetryBoundsOp( aModule );
592     break;
593   case BathymetrySelectionId:
594     anOp = new HYDROGUI_BathymetrySelectionOp( aModule );
595     break;
596   case BathymetryTextId:
597   case BathymetryRescaleSelectionId:
598   case BathymetryRescaleVisibleId:
599   case BathymetryRescaleUserId:
600   case BathymetryRescaleDefaultId:
601     anOp = new HYDROGUI_BathymetryOp( aModule, theId );
602     break;
603
604   case CreateImmersibleZoneId:
605   case EditImmersibleZoneId:
606     anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
607     break;
608   case CreateStreamId:
609   case EditStreamId:
610     anOp = new HYDROGUI_StreamOp( aModule, theId == EditStreamId );
611     break;
612   case CreateChannelId:
613   case EditChannelId:
614     anOp = new HYDROGUI_ChannelOp( aModule, theId == EditChannelId );
615     break;
616   case CreateDigueId:
617   case EditDigueId:
618     anOp = new HYDROGUI_DigueOp( aModule, theId == EditDigueId );
619     break;
620   case ImportStricklerTableFromFileId:
621   case ExportStricklerTableFromFileId:
622   case EditStricklerTableId:
623     anOp = new HYDROGUI_StricklerTableOp( aModule, theId );
624     break;
625   case CreateLandCoverMapId:
626   case AddLandCoverId:
627   case RemoveLandCoverId:
628   case SplitLandCoverId:
629   case MergeLandCoverId:
630   case ChangeLandCoverTypeId:
631     anOp = new HYDROGUI_LandCoverMapOp( aModule, theId );
632     break;
633   case DuplicateStricklerTableId:
634     anOp = new HYDROGUI_DuplicateOp( aModule );
635     break;
636   case CreateCalculationId:
637   case EditCalculationId:
638     anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
639     break;
640   case ExportCalculationId:
641     anOp = new HYDROGUI_ExportCalculationOp( aModule );
642     break;
643   case FuseImagesId:
644   case EditFusedImageId:
645     anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
646     break;
647   case CutImagesId:
648   case EditCutImageId:
649     anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
650     break;
651   case SplitImageId:
652   case EditSplitImageId:
653     anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplitImageId );
654     break;
655   case ImportObstacleFromFileId:
656     anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule );
657     break;
658   case ImportGeomObjectAsObstacleId:
659     anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelectedAsObstacle );
660     break;
661   case ImportGeomObjectAsPolylineId:
662     anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelectedAsPolyline );
663     break;
664   case CreateBoxId:
665     anOp = new HYDROGUI_ImportGeomObjectOp( aModule, 
666       HYDROGUI_ImportGeomObjectOp::ImportCreatedAsObstacle, GEOMOp::OpBox );
667     break;
668   case CreateCylinderId:
669     anOp = new HYDROGUI_ImportGeomObjectOp( aModule, 
670       HYDROGUI_ImportGeomObjectOp::ImportCreatedAsObstacle, GEOMOp::OpCylinder );
671     break;
672   case TranslateObstacleId:
673     anOp = new HYDROGUI_TranslateObstacleOp( aModule );
674     break;
675   case CopyViewerPositionId:
676     anOp = new HYDROGUI_CopyPastePositionOp( aModule, false );
677     break;
678   case DeleteId:
679     anOp = new HYDROGUI_DeleteOp( aModule );
680     break;
681   case SetColorId:
682     anOp = new HYDROGUI_SetColorOp( aModule );
683     break;
684   case SetTransparencyId:
685     anOp = new HYDROGUI_SetTransparencyOp( aModule );
686     break;
687   case SetZLevelId:
688     anOp = new HYDROGUI_ZLevelsOp( aModule );
689     break;
690   case EditLocalCSId:
691     anOp = new HYDROGUI_LocalCSOp( aModule );
692     break;
693   case RiverBottomId:
694   case RiverBottomContextId:
695     anOp = new HYDROGUI_RiverBottomOp( aModule );
696     break;
697   case RecognizeContoursId:
698     anOp = new HYDROGUI_RecognizeContoursOp( aModule );
699     break;
700   case ShowId:
701   case ShowOnlyId:
702   case ShowAllId:
703   case HideId:
704   case HideAllId:
705     anOp = new HYDROGUI_ShowHideOp( aModule, theId );
706     break;
707   case SubmersibleId:
708     anOp = new HYDROGUI_SubmersibleOp( aModule );
709     break;
710   case UnSubmersibleId:
711     anOp = new HYDROGUI_UnSubmersibleOp( aModule );
712     break;
713   case PolylineExtractionId:
714     anOp = new HYDROGUI_PolylineExtractionOp( aModule );
715     break;
716   case SplitPolylinesId:
717     anOp = new HYDROGUI_SplitPolylinesOp( aModule );
718     break;
719   case MergePolylinesId:
720     anOp = new HYDROGUI_MergePolylinesOp( aModule );
721     break;
722   case LandCoverScalarMapModeOnId:
723   case LandCoverScalarMapModeOffId:
724     anOp = new HYDROGUI_LandCoverColoringOp( aModule, theId );
725     break;
726   case RegenerateRegionColorsId:
727      anOp = new HYDROGUI_RegenerateRegionColorsOp( aModule );
728   }
729
730   if( !anOp )
731     anOp = LightApp_Module::createOperation( theId );
732
733   return anOp;
734 }
735
736 bool HYDROGUI_Module::reusableOperation( const int id )
737 {
738   if ( id == ImportGeomObjectAsObstacleId ||
739        id == ImportGeomObjectAsPolylineId ) {
740     return false;
741   }
742
743   return LightApp_Module::reusableOperation( id );
744 }
745
746 /**
747  * Returns true if the object with the given entry can be renamed.
748  * @param theEntry the object entry
749  */
750 bool HYDROGUI_Module::renameAllowed( const QString& theEntry ) const
751 {
752   // Allow to rename all HYDRO objects
753   Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
754   return !anEntity.IsNull();
755 }
756 /**
757  * Returns true if the object with the given entry is renamed.
758  * @param theEntry the object entry
759  * @param theName the new name
760  */
761 bool HYDROGUI_Module::renameObject( const QString& theEntry, const QString& theName )
762 {
763   Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
764   bool aRes = false;
765   if ( !anEntity.IsNull() )
766   {
767     HYDROGUI_DataModel* aModel = getDataModel();
768     if( aModel )
769     {
770       if( anEntity->GetName() != theName )
771       {
772         // check that there are no other objects with the same name in the document
773         Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( this, theName );
774         if ( anObject.IsNull() )
775         {
776           SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
777           if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
778           {
779             anEntity->SetName( theName );
780             aRes = true;
781           }
782           else
783           {
784             aRes = aModel->rename( anEntity, theName );
785           }
786         }
787         else
788         {
789           // Inform the user that the name is already used
790           QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
791           QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
792           SUIT_MessageBox::critical( getApp()->desktop(), aTitle, aMessage );
793         }
794       }
795     }
796   }
797   return aRes;
798 }
799
800 void HYDROGUI_Module::onBathymetrySelection()
801 {
802   QAction* a = qobject_cast<QAction*>( sender() );
803   if( !a )
804     return;
805
806   bool isChecked = a->isChecked();
807   if( isChecked )
808     startOperation( BathymetrySelectionId );
809   else
810   {
811     LightApp_Operation* op = operation( BathymetryTextId );
812     if( op )
813       op->abort();
814
815     op = operation( BathymetrySelectionId );
816     if( op )
817       op->abort();
818   }
819 }
820
821 void HYDROGUI_Module::onBathymetryText()
822 {
823   QAction* a = qobject_cast<QAction*>( sender() );
824   if( !a )
825     return;
826
827   bool isChecked = a->isChecked();
828   if( isChecked )
829     startOperation( BathymetryTextId );
830   else
831     operation( BathymetryTextId )->abort();
832 }