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