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