1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_Operations.h"
25 #include "HYDROGUI_CopyPasteOp.h"
26 #include "HYDROGUI_CalculationOp.h"
27 #include "HYDROGUI_ChannelOp.h"
28 #include "HYDROGUI_DataModel.h"
29 #include "HYDROGUI_DeleteOp.h"
30 #include "HYDROGUI_ExportImageOp.h"
31 #include "HYDROGUI_ImportImageOp.h"
32 #include "HYDROGUI_ImportBathymetryOp.h"
33 #include "HYDROGUI_ImmersibleZoneOp.h"
34 #include "HYDROGUI_Module.h"
35 #include "HYDROGUI_ObserveImageOp.h"
36 #include "HYDROGUI_PolylineOp.h"
37 #include "HYDROGUI_Poly3DOp.h"
38 #include "HYDROGUI_ProfileOp.h"
39 #include "HYDROGUI_RemoveImageRefsOp.h"
40 #include "HYDROGUI_ShowHideOp.h"
41 #include "HYDROGUI_StreamOp.h"
42 #include "HYDROGUI_TwoImagesOp.h"
43 #include "HYDROGUI_UpdateFlags.h"
44 #include "HYDROGUI_UpdateImageOp.h"
45 #include "HYDROGUI_VisualStateOp.h"
46 #include "HYDROGUI_ImmersibleZoneOp.h"
47 #include "HYDROGUI_ImportGeomObjectOp.h"
48 #include "HYDROGUI_ImportObstacleFromFileOp.h"
49 #include "HYDROGUI_ExportCalculationOp.h"
50 #include "HYDROGUI_ImportProfilesOp.h"
51 #include "HYDROGUI_GeoreferencementOp.h"
52 #include "HYDROGUI_SetColorOp.h"
54 #include <HYDROData_Document.h>
55 #include <HYDROData_Obstacle.h>
56 #include <HYDROData_SplitToZonesTool.h>
58 #include <GeometryGUI.h>
59 #include <GeometryGUI_Operations.h>
62 #include <SalomeApp_Study.h>
64 #include <LightApp_Application.h>
66 #include <CAM_Application.h>
68 #include <QtxListAction.h>
70 #include <SUIT_Desktop.h>
71 #include <SUIT_ResourceMgr.h>
72 #include <SUIT_Session.h>
75 #include <QApplication>
77 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
78 const int theKey, const bool isToggle, const QString& theSlot )
80 QString aSlot = theSlot;
82 aSlot = SLOT( onOperation() );
83 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
84 std::string anImg = theImg.toStdString();
85 QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
86 std::string aMenu = ( "MEN_" + theSuffix ).toStdString();
87 std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
88 std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
89 std::string aSlotStr = aSlot.toStdString();
90 return LightApp_Module::createAction( theId, tr( aDesktop.c_str() ), aPixmap,
91 tr( aMenu.c_str() ), tr( aToolbar.c_str() ),
92 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
95 void HYDROGUI_Module::createActions()
97 createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
98 createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
100 createAction( CopyId, "COPY", "", Qt::CTRL + Qt::Key_C );
101 createAction( PasteId, "PASTE", "", Qt::CTRL + Qt::Key_V );
103 createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
104 createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE" );
105 createAction( ObserveImageId, "OBSERVE_IMAGE" );
106 createAction( ExportImageId, "EXPORT_IMAGE" );
107 createAction( UpdateImageId, "UPDATE_IMAGE" );
108 createAction( RemoveImageRefsId, "REMOVE_IMAGE_REFERENCE" );
110 createAction( CreatePolylineId, "CREATE_POLYLINE" );
111 createAction( EditPolylineId, "EDIT_POLYLINE" );
113 createAction( CreatePolyline3DId, "CREATE_POLYLINE_3D" );
114 createAction( EditPolyline3DId, "EDIT_POLYLINE_3D" );
116 createAction( CreateProfileId, "CREATE_PROFILE" );
117 createAction( ImportProfilesId, "IMPORT_PROFILES" );
118 createAction( EditProfileId, "EDIT_PROFILE" );
119 createAction( AllGeoreferencementId, "GEOREFERENCEMENT" );
120 createAction( SelectedGeoreferencementId, "GEOREFERENCEMENT" );
122 createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::Key_B );
124 createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE" );
125 createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE" );
127 createAction( CreateStreamId, "CREATE_STREAM" );
128 createAction( EditStreamId, "EDIT_STREAM" );
130 createAction( CreateChannelId, "CREATE_CHANNEL" );
131 createAction( EditChannelId, "EDIT_CHANNEL" );
133 createAction( ImportObstacleFromFileId, "IMPORT_OBSTACLE_FROM_FILE" );
134 createAction( ImportGeomObjectId, "IMPORT_GEOM_OBJECT" );
135 createAction( CreateBoxId, "CREATE_BOX" );
136 createAction( CreateCylinderId, "CREATE_CYLINDER" );
138 createAction( CreateCalculationId, "CREATE_CALCULATION" );
139 createAction( EditCalculationId, "EDIT_CALCULATION" );
140 createAction( ExportCalculationId, "EXPORT_CALCULATION" );
142 createAction( FuseImagesId, "FUSE_IMAGES" );
143 createAction( EditFusedImageId, "EDIT_FUSED_IMAGE" );
145 createAction( CutImagesId, "CUT_IMAGES" );
146 createAction( EditCutImageId, "EDIT_CUT_IMAGE" );
148 createAction( SplitImageId, "SPLIT_IMAGE" );
149 createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE" );
151 createAction( DeleteId, "DELETE", "", Qt::Key_Delete, false,
152 SLOT( onDelete() ) );
154 createAction( SetColorId, "COLOR" );
156 createAction( ShowId, "SHOW" );
157 createAction( ShowOnlyId, "SHOW_ONLY" );
158 createAction( ShowAllId, "SHOW_ALL" );
159 createAction( HideId, "HIDE" );
160 createAction( HideAllId, "HIDE_ALL" );
163 void HYDROGUI_Module::createMenus()
165 int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
166 int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
167 createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
168 createMenu( separator(), aFileMenu, -1, aCustomPos );
170 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
171 createMenu( UndoId, anEditMenu );
172 createMenu( RedoId, anEditMenu );
173 createMenu( separator(), anEditMenu );
174 createMenu( CopyId, anEditMenu );
175 createMenu( PasteId, anEditMenu );
177 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
178 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
179 createMenu( ImportImageId, aHydroId, -1, -1 );
180 createMenu( ImportBathymetryId, aHydroId, -1, -1 );
181 createMenu( CreatePolylineId, aHydroId, -1, -1 );
182 createMenu( CreatePolyline3DId, aHydroId, -1, -1 );
184 int aNewProfileId = createMenu( tr( "MEN_DESK_PROFILE" ), aHydroId, -1 );
185 createMenu( CreateProfileId, aNewProfileId, -1, -1 );
186 createMenu( ImportProfilesId, aNewProfileId, -1, -1 );
187 createMenu( AllGeoreferencementId, aNewProfileId, -1, -1 );
189 int anArtificialMenuId = createMenu( tr( "MEN_DESK_ARTIFICIAL" ), aHydroId, -1 );
190 createMenu( CreateImmersibleZoneId, anArtificialMenuId, -1, -1 );
191 createMenu( CreateStreamId, anArtificialMenuId, -1, -1 );
193 int aNaturalMenuId = createMenu( tr( "MEN_DESK_NATURAL" ), aHydroId, -1 );
194 createMenu( CreateChannelId, aNaturalMenuId, -1, -1 );
196 int anObstacleMenuId = createMenu( tr( "MEN_DESK_OBSTACLE" ), aHydroId, -1 );
197 createMenu( ImportObstacleFromFileId, anObstacleMenuId, -1, -1 );
198 createMenu( CreateBoxId, anObstacleMenuId, -1, -1 );
199 createMenu( CreateCylinderId, anObstacleMenuId, -1, -1 );
201 createMenu( CreateCalculationId, aHydroId, -1, -1 );
202 createMenu( separator(), aHydroId );
203 createMenu( FuseImagesId, aHydroId, -1, -1 );
204 createMenu( CutImagesId, aHydroId, -1, -1 );
205 createMenu( SplitImageId, aHydroId, -1, -1 );
206 createMenu( separator(), aHydroId );
209 void HYDROGUI_Module::createPopups()
213 void HYDROGUI_Module::createToolbars()
215 int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
216 createTool( UndoId, aToolBar );
217 createTool( RedoId, aToolBar );
220 void HYDROGUI_Module::createUndoRedoActions()
222 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
224 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
225 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
226 Qt::CTRL + Qt::Key_Z, application()->desktop() );
228 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
229 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
230 Qt::CTRL + Qt::Key_Y, application()->desktop() );
232 registerAction( UndoId, anEditUndo );
233 registerAction( RedoId, anEditRedo );
235 anEditUndo->setComment( tr( "STB_UNDO" ) );
236 anEditRedo->setComment( tr( "STB_REDO" ) );
238 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
239 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
242 void HYDROGUI_Module::updateUndoRedoControls()
244 HYDROGUI_DataModel* aModel = getDataModel();
246 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
247 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
249 bool aCanUndo = aModel->canUndo();
250 bool aCanRedo = aModel->canRedo();
253 aUndoAction->addNames( aModel->undoNames() );
254 aUndoAction->setEnabled( aCanUndo );
257 aRedoAction->addNames( aModel->redoNames() );
258 aRedoAction->setEnabled( aCanRedo );
261 void HYDROGUI_Module::onOperation()
263 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
264 int anId = actionId( anAction );
266 startOperation( anId );
269 void HYDROGUI_Module::onDelete()
271 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
272 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
273 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
274 aPolylineOp->deleteSelected();
276 startOperation( DeleteId );
279 bool HYDROGUI_Module::onUndo( int theNumActions )
281 QApplication::setOverrideCursor( Qt::WaitCursor );
283 HYDROGUI_DataModel* aModel = getDataModel();
286 while( theNumActions > 0 )
288 if( !aModel->undo() )
297 QApplication::restoreOverrideCursor();
301 bool HYDROGUI_Module::onRedo( int theNumActions )
303 QApplication::setOverrideCursor( Qt::WaitCursor );
305 HYDROGUI_DataModel* aModel = getDataModel();
308 while( theNumActions > 0 )
310 if( !aModel->redo() )
319 QApplication::restoreOverrideCursor();
323 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
325 LightApp_Operation* anOp = 0;
326 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
329 case SaveVisualStateId:
330 case LoadVisualStateId:
331 anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
335 anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
338 case EditImportedImageId:
339 anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
342 anOp = new HYDROGUI_ObserveImageOp( aModule );
345 anOp = new HYDROGUI_ExportImageOp( aModule );
348 anOp = new HYDROGUI_UpdateImageOp( aModule );
350 case RemoveImageRefsId:
351 anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
353 case CreatePolyline3DId:
354 case EditPolyline3DId:
355 anOp = new HYDROGUI_Poly3DOp( aModule, theId == EditPolyline3DId );
357 case CreatePolylineId:
359 anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
361 case CreateProfileId:
363 anOp = new HYDROGUI_ProfileOp( aModule, theId == EditProfileId );
365 case ImportProfilesId:
366 anOp = new HYDROGUI_ImportProfilesOp( aModule ) ;
368 case AllGeoreferencementId:
369 anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::All ) ;
371 case SelectedGeoreferencementId:
372 anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::Selected ) ;
374 case ImportBathymetryId:
375 anOp = new HYDROGUI_ImportBathymetryOp( aModule );
377 case CreateImmersibleZoneId:
378 case EditImmersibleZoneId:
379 anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
383 anOp = new HYDROGUI_StreamOp( aModule, theId == EditStreamId );
385 case CreateChannelId:
387 anOp = new HYDROGUI_ChannelOp( aModule, theId == EditChannelId );
389 case CreateCalculationId:
390 case EditCalculationId:
391 anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
393 case ExportCalculationId:
394 anOp = new HYDROGUI_ExportCalculationOp( aModule );
397 case EditFusedImageId:
398 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
402 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
405 case EditSplittedImageId:
406 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId );
408 case ImportObstacleFromFileId:
409 anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule );
411 case ImportCreatedPrimitiveId:
412 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportCreated );
414 case ImportGeomObjectId:
415 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelected );
418 application()->activateOperation( "Geometry", GEOMOp::OpBox );
420 case CreateCylinderId:
421 application()->activateOperation( "Geometry", GEOMOp::OpCylinder );
424 anOp = new HYDROGUI_DeleteOp( aModule );
427 anOp = new HYDROGUI_SetColorOp( aModule );
434 anOp = new HYDROGUI_ShowHideOp( aModule, theId );
439 anOp = LightApp_Module::createOperation( theId );
444 bool HYDROGUI_Module::reusableOperation( const int id )
446 if ( id == ImportGeomObjectId ) {
450 return LightApp_Module::reusableOperation( id );
454 * Called when the operation perfomed by another module is finished.
455 * \param theModuleName the name of the module which perfomed the operation
456 * \param theOperationName the operation name
457 * \param theEntryList the list of the created objects entries
459 void HYDROGUI_Module::onExternalOperationFinished( const QString& theModuleName,
460 const QString& theOperationName,
461 const QStringList& theEntryList )
463 // Process "Geometry" module operations with non-empty list of created objects only
464 if ( theModuleName != "Geometry" || theEntryList.isEmpty() ) {
468 // Start import GEOM object operation
469 myGeomObjectsToImport = theEntryList;
470 startOperation( ImportCreatedPrimitiveId );
471 myGeomObjectsToImport.clear();
475 * Returns the list of entries of GEOM objects to be imported.
477 QStringList HYDROGUI_Module::GetGeomObjectsToImport()
479 return myGeomObjectsToImport;