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_DigueOp.h"
31 #include "HYDROGUI_ExportImageOp.h"
32 #include "HYDROGUI_ImportImageOp.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_ExportCalculationOp.h"
51 #include "HYDROGUI_ImportProfilesOp.h"
52 #include "HYDROGUI_GeoreferencementOp.h"
53 #include "HYDROGUI_SetColorOp.h"
54 #include "HYDROGUI_Tool.h"
56 #include <HYDROData_Document.h>
57 #include <HYDROData_Obstacle.h>
58 #include <HYDROData_SplitToZonesTool.h>
60 #include <GeometryGUI.h>
61 #include <GeometryGUI_Operations.h>
64 #include <SalomeApp_Study.h>
66 #include <LightApp_Application.h>
68 #include <CAM_Application.h>
70 #include <QtxListAction.h>
71 #include <QtxActionToolMgr.h>
73 #include <SUIT_Desktop.h>
74 #include <SUIT_ResourceMgr.h>
75 #include <SUIT_Session.h>
76 #include <SUIT_MessageBox.h>
79 #include <QApplication>
81 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
82 const int theKey, const bool isToggle, const QString& theSlot )
84 QString aSlot = theSlot;
86 aSlot = SLOT( onOperation() );
87 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
88 std::string anImg = theImg.toStdString();
89 QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
90 std::string aMenu = ( "MEN_" + theSuffix ).toStdString();
91 std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
92 std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
93 std::string aSlotStr = aSlot.toStdString();
94 return LightApp_Module::createAction( theId, tr( aDesktop.c_str() ), aPixmap,
95 tr( aMenu.c_str() ), tr( aToolbar.c_str() ),
96 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
99 void HYDROGUI_Module::createActions()
101 createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
102 createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
104 createAction( CopyId, "COPY", "", Qt::CTRL + Qt::Key_C );
105 createAction( PasteId, "PASTE", "", Qt::CTRL + Qt::Key_V );
107 createAction( UpdateObjectId, "UPDATE_OBJECT" );
109 createAction( ImportImageId, "IMPORT_IMAGE", "IMPORT_IMAGE_ICO", Qt::CTRL + Qt::Key_I );
110 createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE", "EDIT_IMPORTED_IMAGE_ICO" );
111 createAction( ObserveImageId, "OBSERVE_IMAGE", "OBSERVE_IMAGE_ICO" );
112 createAction( ExportImageId, "EXPORT_IMAGE", "EXPORT_IMAGE_ICO" );
113 createAction( RemoveImageRefsId, "REMOVE_IMAGE_REFERENCE", "REMOVE_IMAGE_REFERENCE_ICO" );
115 createAction( CreatePolylineId, "CREATE_POLYLINE", "CREATE_POLYLINE_ICO" );
116 createAction( EditPolylineId, "EDIT_POLYLINE", "EDIT_POLYLINE_ICO" );
118 createAction( CreatePolyline3DId, "CREATE_POLYLINE_3D", "CREATE_POLYLINE_3D_ICO" );
119 createAction( EditPolyline3DId, "EDIT_POLYLINE_3D", "EDIT_POLYLINE_3D_ICO" );
121 createAction( CreateProfileId, "CREATE_PROFILE", "CREATE_PROFILE_ICO" );
122 createAction( ImportProfilesId, "IMPORT_PROFILES", "IMPORT_PROFILES_ICO" );
123 createAction( EditProfileId, "EDIT_PROFILE", "EDIT_PROFILE_ICO" );
124 createAction( AllGeoreferencementId, "GEOREFERENCEMENT", "GEOREFERENCEMENT_ICO" );
125 createAction( SelectedGeoreferencementId, "GEOREFERENCEMENT", "GEOREFERENCEMENT_ICO" );
127 createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "IMPORT_BATHYMETRY_ICO", Qt::CTRL + Qt::Key_B );
128 createAction( EditImportedBathymetryId, "EDIT_IMPORTED_BATHYMETRY", "EDIT_IMPORTED_BATHYMETRY_ICO" );
130 createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE", "CREATE_IMMERSIBLE_ZONE_ICO" );
131 createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE", "EDIT_IMMERSIBLE_ZONE_ICO" );
133 createAction( CreateStreamId, "CREATE_STREAM", "CREATE_STREAM_ICO" );
134 createAction( EditStreamId, "EDIT_STREAM", "EDIT_STREAM_ICO" );
136 createAction( CreateChannelId, "CREATE_CHANNEL", "CREATE_CHANNEL_ICO" );
137 createAction( EditChannelId, "EDIT_CHANNEL", "EDIT_CHANNEL_ICO" );
139 createAction( CreateDigueId, "CREATE_DIGUE", "CREATE_DIGUE_ICO" );
140 createAction( EditDigueId, "EDIT_DIGUE", "EDIT_DIGUE_ICO" );
142 createAction( ImportObstacleFromFileId, "IMPORT_OBSTACLE_FROM_FILE", "IMPORT_OBSTACLE_FROM_FILE_ICO" );
143 createAction( ImportGeomObjectId, "IMPORT_GEOM_OBJECT", "IMPORT_GEOM_OBJECT_ICO" );
144 createAction( CreateBoxId, "CREATE_BOX", "CREATE_BOX_ICO" );
145 createAction( CreateCylinderId, "CREATE_CYLINDER", "CREATE_CYLINDER_ICO" );
147 createAction( CreateCalculationId, "CREATE_CALCULATION", "CREATE_CALCULATION_ICO" );
148 createAction( EditCalculationId, "EDIT_CALCULATION", "EDIT_CALCULATION_ICO" );
149 createAction( ExportCalculationId, "EXPORT_CALCULATION", "EXPORT_CALCULATION_ICO" );
151 createAction( FuseImagesId, "FUSE_IMAGES", "FUSE_IMAGES_ICO" );
152 createAction( EditFusedImageId, "EDIT_FUSED_IMAGE", "EDIT_FUSED_IMAGE_ICO" );
154 createAction( CutImagesId, "CUT_IMAGES", "CUT_IMAGES_ICO" );
155 createAction( EditCutImageId, "EDIT_CUT_IMAGE", "EDIT_CUT_IMAGE_ICO" );
157 createAction( SplitImageId, "SPLIT_IMAGE", "SPLIT_IMAGE_ICO" );
158 createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE", "EDIT_SPLITTED_IMAGE_ICO" );
160 createAction( DeleteId, "DELETE", "", Qt::Key_Delete, false,
161 SLOT( onDelete() ) );
163 createAction( SetColorId, "COLOR" );
165 createAction( ShowId, "SHOW" );
166 createAction( ShowOnlyId, "SHOW_ONLY" );
167 createAction( ShowAllId, "SHOW_ALL" );
168 createAction( HideId, "HIDE" );
169 createAction( HideAllId, "HIDE_ALL" );
172 void HYDROGUI_Module::createMenus()
174 int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
175 int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
176 createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
177 createMenu( separator(), aFileMenu, -1, aCustomPos );
179 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
180 createMenu( UndoId, anEditMenu );
181 createMenu( RedoId, anEditMenu );
182 createMenu( separator(), anEditMenu );
183 createMenu( CopyId, anEditMenu );
184 createMenu( PasteId, anEditMenu );
186 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
187 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
188 createMenu( ImportImageId, aHydroId, -1, -1 );
189 createMenu( ImportBathymetryId, aHydroId, -1, -1 );
190 createMenu( CreatePolylineId, aHydroId, -1, -1 );
191 createMenu( CreatePolyline3DId, aHydroId, -1, -1 );
193 int aNewProfileId = createMenu( tr( "MEN_DESK_PROFILE" ), aHydroId, -1 );
194 createMenu( CreateProfileId, aNewProfileId, -1, -1 );
195 createMenu( ImportProfilesId, aNewProfileId, -1, -1 );
196 createMenu( AllGeoreferencementId, aNewProfileId, -1, -1 );
198 int anArtificialMenuId = createMenu( tr( "MEN_DESK_ARTIFICIAL" ), aHydroId, -1 );
199 createMenu( CreateChannelId, anArtificialMenuId, -1, -1 );
200 createMenu( CreateDigueId, anArtificialMenuId, -1, -1 );
202 int aNaturalMenuId = createMenu( tr( "MEN_DESK_NATURAL" ), aHydroId, -1 );
203 createMenu( CreateImmersibleZoneId, aNaturalMenuId, -1, -1 );
204 createMenu( CreateStreamId, aNaturalMenuId, -1, -1 );
206 int anObstacleMenuId = createMenu( tr( "MEN_DESK_OBSTACLE" ), aHydroId, -1 );
207 createMenu( ImportObstacleFromFileId, anObstacleMenuId, -1, -1 );
208 createMenu( CreateBoxId, anObstacleMenuId, -1, -1 );
209 createMenu( CreateCylinderId, anObstacleMenuId, -1, -1 );
211 createMenu( CreateCalculationId, aHydroId, -1, -1 );
212 createMenu( separator(), aHydroId );
213 createMenu( FuseImagesId, aHydroId, -1, -1 );
214 createMenu( CutImagesId, aHydroId, -1, -1 );
215 createMenu( SplitImageId, aHydroId, -1, -1 );
216 createMenu( separator(), aHydroId );
219 void HYDROGUI_Module::createPopups()
223 void HYDROGUI_Module::createToolbars()
225 int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
226 createTool( UndoId, aToolBar );
227 createTool( RedoId, aToolBar );
229 createTool( separator(), aToolBar );
230 createTool( ImportImageId, aToolBar );
231 createTool( ImportBathymetryId, aToolBar );
232 createTool( CreatePolylineId, aToolBar );
233 createTool( CreatePolyline3DId, aToolBar );
235 createTool( separator(), aToolBar );
236 createTool( CreateProfileId, aToolBar );
237 createTool( ImportProfilesId, aToolBar );
238 createTool( AllGeoreferencementId, aToolBar );
240 createTool( separator(), aToolBar );
241 createTool( CreateChannelId, aToolBar );
242 createTool( CreateDigueId, aToolBar );
244 createTool( separator(), aToolBar );
245 createTool( CreateImmersibleZoneId, aToolBar );
246 createTool( CreateStreamId, aToolBar );
248 createTool( separator(), aToolBar );
249 createTool( ImportObstacleFromFileId, aToolBar );
250 createTool( CreateBoxId, aToolBar );
251 createTool( CreateCylinderId, aToolBar );
253 createTool( separator(), aToolBar );
254 createTool( CreateCalculationId, aToolBar );
256 createTool( separator(), aToolBar );
257 createTool( FuseImagesId, aToolBar );
258 createTool( CutImagesId, aToolBar );
259 createTool( SplitImageId, aToolBar );
262 void HYDROGUI_Module::createUndoRedoActions()
264 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
266 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
267 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
268 Qt::CTRL + Qt::Key_Z, application()->desktop() );
270 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
271 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
272 Qt::CTRL + Qt::Key_Y, application()->desktop() );
274 registerAction( UndoId, anEditUndo );
275 registerAction( RedoId, anEditRedo );
277 anEditUndo->setComment( tr( "STB_UNDO" ) );
278 anEditRedo->setComment( tr( "STB_REDO" ) );
280 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
281 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
284 void HYDROGUI_Module::updateUndoRedoControls()
286 HYDROGUI_DataModel* aModel = getDataModel();
288 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
289 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
291 bool aCanUndo = aModel->canUndo();
292 bool aCanRedo = aModel->canRedo();
295 aUndoAction->addNames( aModel->undoNames() );
296 aUndoAction->setEnabled( aCanUndo );
299 aRedoAction->addNames( aModel->redoNames() );
300 aRedoAction->setEnabled( aCanRedo );
303 void HYDROGUI_Module::onOperation()
305 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
306 int anId = actionId( anAction );
308 startOperation( anId );
311 void HYDROGUI_Module::onDelete()
313 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
314 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
315 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
316 aPolylineOp->deleteSelected();
318 startOperation( DeleteId );
321 bool HYDROGUI_Module::onUndo( int theNumActions )
323 QApplication::setOverrideCursor( Qt::WaitCursor );
325 HYDROGUI_DataModel* aModel = getDataModel();
328 while( theNumActions > 0 )
330 if( !aModel->undo() )
339 QApplication::restoreOverrideCursor();
343 bool HYDROGUI_Module::onRedo( int theNumActions )
345 QApplication::setOverrideCursor( Qt::WaitCursor );
347 HYDROGUI_DataModel* aModel = getDataModel();
350 while( theNumActions > 0 )
352 if( !aModel->redo() )
361 QApplication::restoreOverrideCursor();
365 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
367 LightApp_Operation* anOp = 0;
368 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
371 case SaveVisualStateId:
372 case LoadVisualStateId:
373 anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
377 anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
380 case EditImportedImageId:
381 anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
384 anOp = new HYDROGUI_ObserveImageOp( aModule );
387 anOp = new HYDROGUI_ExportImageOp( aModule );
390 anOp = new HYDROGUI_UpdateObjectOp( aModule );
392 case RemoveImageRefsId:
393 anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
395 case CreatePolyline3DId:
396 case EditPolyline3DId:
397 anOp = new HYDROGUI_Poly3DOp( aModule, theId == EditPolyline3DId );
399 case CreatePolylineId:
401 anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
403 case CreateProfileId:
405 anOp = new HYDROGUI_ProfileOp( aModule, theId == EditProfileId );
407 case ImportProfilesId:
408 anOp = new HYDROGUI_ImportProfilesOp( aModule ) ;
410 case AllGeoreferencementId:
411 anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::All ) ;
413 case SelectedGeoreferencementId:
414 anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::Selected ) ;
416 case ImportBathymetryId:
417 case EditImportedBathymetryId:
418 anOp = new HYDROGUI_ImportBathymetryOp( aModule, theId == EditImportedBathymetryId );
420 case CreateImmersibleZoneId:
421 case EditImmersibleZoneId:
422 anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
426 anOp = new HYDROGUI_StreamOp( aModule, theId == EditStreamId );
428 case CreateChannelId:
430 anOp = new HYDROGUI_ChannelOp( aModule, theId == EditChannelId );
434 anOp = new HYDROGUI_DigueOp( aModule, theId == EditDigueId );
436 case CreateCalculationId:
437 case EditCalculationId:
438 anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
440 case ExportCalculationId:
441 anOp = new HYDROGUI_ExportCalculationOp( aModule );
444 case EditFusedImageId:
445 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
449 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
452 case EditSplittedImageId:
453 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId );
455 case ImportObstacleFromFileId:
456 anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule );
458 case ImportCreatedPrimitiveId:
459 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportCreated );
461 case ImportGeomObjectId:
462 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelected );
465 application()->activateOperation( "Geometry", GEOMOp::OpBox );
467 case CreateCylinderId:
468 application()->activateOperation( "Geometry", GEOMOp::OpCylinder );
471 anOp = new HYDROGUI_DeleteOp( aModule );
474 anOp = new HYDROGUI_SetColorOp( aModule );
481 anOp = new HYDROGUI_ShowHideOp( aModule, theId );
486 anOp = LightApp_Module::createOperation( theId );
491 bool HYDROGUI_Module::reusableOperation( const int id )
493 if ( id == ImportGeomObjectId ) {
497 return LightApp_Module::reusableOperation( id );
501 * Called when the operation perfomed by another module is finished.
502 * \param theModuleName the name of the module which perfomed the operation
503 * \param theOperationName the operation name
504 * \param theEntryList the list of the created objects entries
506 void HYDROGUI_Module::onExternalOperationFinished( const QString& theModuleName,
507 const QString& theOperationName,
508 const QStringList& theEntryList )
510 // Process "Geometry" module operations with non-empty list of created objects only
511 if ( theModuleName != "Geometry" || theEntryList.isEmpty() ) {
515 // Start import GEOM object operation
516 myGeomObjectsToImport = theEntryList;
517 startOperation( ImportCreatedPrimitiveId );
518 myGeomObjectsToImport.clear();
522 * Returns the list of entries of GEOM objects to be imported.
524 QStringList HYDROGUI_Module::GetGeomObjectsToImport()
526 return myGeomObjectsToImport;
530 * Returns true if the object with the given entry can be renamed.
531 * @param theEntry the object entry
533 bool HYDROGUI_Module::renameAllowed( const QString& theEntry ) const
535 // Allow to rename all HYDRO objects
536 Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
537 return !anEntity.IsNull();
540 * Returns true if the object with the given entry is renamed.
541 * @param theEntry the object entry
542 * @param theName the new name
544 bool HYDROGUI_Module::renameObject( const QString& theEntry, const QString& theName )
546 Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
548 if ( !anEntity.IsNull() )
550 HYDROGUI_DataModel* aModel = getDataModel();
553 if( anEntity->GetName() != theName )
555 // check that there are no other objects with the same name in the document
556 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( this, theName );
557 if ( anObject.IsNull() )
559 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
560 if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
562 anEntity->SetName( theName );
567 aRes = aModel->rename( anEntity, theName );
572 // Inform the user that the name is already used
573 QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
574 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
575 SUIT_MessageBox::critical( getApp()->desktop(), aTitle, aMessage );