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