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