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"
53 #include "HYDROGUI_Tool.h"
55 #include <HYDROData_Document.h>
56 #include <HYDROData_Obstacle.h>
57 #include <HYDROData_SplitToZonesTool.h>
59 #include <GeometryGUI.h>
60 #include <GeometryGUI_Operations.h>
63 #include <SalomeApp_Study.h>
65 #include <LightApp_Application.h>
67 #include <CAM_Application.h>
69 #include <QtxListAction.h>
71 #include <SUIT_Desktop.h>
72 #include <SUIT_ResourceMgr.h>
73 #include <SUIT_Session.h>
74 #include <SUIT_MessageBox.h>
77 #include <QApplication>
79 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
80 const int theKey, const bool isToggle, const QString& theSlot )
82 QString aSlot = theSlot;
84 aSlot = SLOT( onOperation() );
85 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
86 std::string anImg = theImg.toStdString();
87 QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
88 std::string aMenu = ( "MEN_" + theSuffix ).toStdString();
89 std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
90 std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
91 std::string aSlotStr = aSlot.toStdString();
92 return LightApp_Module::createAction( theId, tr( aDesktop.c_str() ), aPixmap,
93 tr( aMenu.c_str() ), tr( aToolbar.c_str() ),
94 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
97 void HYDROGUI_Module::createActions()
99 createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
100 createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
102 createAction( CopyId, "COPY", "", Qt::CTRL + Qt::Key_C );
103 createAction( PasteId, "PASTE", "", Qt::CTRL + Qt::Key_V );
105 createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
106 createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE" );
107 createAction( ObserveImageId, "OBSERVE_IMAGE" );
108 createAction( ExportImageId, "EXPORT_IMAGE" );
109 createAction( UpdateImageId, "UPDATE_IMAGE" );
110 createAction( RemoveImageRefsId, "REMOVE_IMAGE_REFERENCE" );
112 createAction( CreatePolylineId, "CREATE_POLYLINE" );
113 createAction( EditPolylineId, "EDIT_POLYLINE" );
115 createAction( CreatePolyline3DId, "CREATE_POLYLINE_3D" );
116 createAction( EditPolyline3DId, "EDIT_POLYLINE_3D" );
118 createAction( CreateProfileId, "CREATE_PROFILE" );
119 createAction( ImportProfilesId, "IMPORT_PROFILES" );
120 createAction( EditProfileId, "EDIT_PROFILE" );
121 createAction( AllGeoreferencementId, "GEOREFERENCEMENT" );
122 createAction( SelectedGeoreferencementId, "GEOREFERENCEMENT" );
124 createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::Key_B );
125 createAction( EditImportedBathymetryId, "EDIT_IMPORTED_BATHYMETRY" );
127 createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE" );
128 createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE" );
130 createAction( CreateStreamId, "CREATE_STREAM" );
131 createAction( EditStreamId, "EDIT_STREAM" );
133 createAction( CreateChannelId, "CREATE_CHANNEL" );
134 createAction( EditChannelId, "EDIT_CHANNEL" );
136 createAction( ImportObstacleFromFileId, "IMPORT_OBSTACLE_FROM_FILE" );
137 createAction( ImportGeomObjectId, "IMPORT_GEOM_OBJECT" );
138 createAction( CreateBoxId, "CREATE_BOX" );
139 createAction( CreateCylinderId, "CREATE_CYLINDER" );
141 createAction( CreateCalculationId, "CREATE_CALCULATION" );
142 createAction( EditCalculationId, "EDIT_CALCULATION" );
143 createAction( ExportCalculationId, "EXPORT_CALCULATION" );
145 createAction( FuseImagesId, "FUSE_IMAGES" );
146 createAction( EditFusedImageId, "EDIT_FUSED_IMAGE" );
148 createAction( CutImagesId, "CUT_IMAGES" );
149 createAction( EditCutImageId, "EDIT_CUT_IMAGE" );
151 createAction( SplitImageId, "SPLIT_IMAGE" );
152 createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE" );
154 createAction( DeleteId, "DELETE", "", Qt::Key_Delete, false,
155 SLOT( onDelete() ) );
157 createAction( SetColorId, "COLOR" );
159 createAction( ShowId, "SHOW" );
160 createAction( ShowOnlyId, "SHOW_ONLY" );
161 createAction( ShowAllId, "SHOW_ALL" );
162 createAction( HideId, "HIDE" );
163 createAction( HideAllId, "HIDE_ALL" );
166 void HYDROGUI_Module::createMenus()
168 int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
169 int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
170 createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
171 createMenu( separator(), aFileMenu, -1, aCustomPos );
173 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
174 createMenu( UndoId, anEditMenu );
175 createMenu( RedoId, anEditMenu );
176 createMenu( separator(), anEditMenu );
177 createMenu( CopyId, anEditMenu );
178 createMenu( PasteId, anEditMenu );
180 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
181 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
182 createMenu( ImportImageId, aHydroId, -1, -1 );
183 createMenu( ImportBathymetryId, aHydroId, -1, -1 );
184 createMenu( CreatePolylineId, aHydroId, -1, -1 );
185 createMenu( CreatePolyline3DId, aHydroId, -1, -1 );
187 int aNewProfileId = createMenu( tr( "MEN_DESK_PROFILE" ), aHydroId, -1 );
188 createMenu( CreateProfileId, aNewProfileId, -1, -1 );
189 createMenu( ImportProfilesId, aNewProfileId, -1, -1 );
190 createMenu( AllGeoreferencementId, aNewProfileId, -1, -1 );
192 int anArtificialMenuId = createMenu( tr( "MEN_DESK_ARTIFICIAL" ), aHydroId, -1 );
193 createMenu( CreateImmersibleZoneId, anArtificialMenuId, -1, -1 );
194 createMenu( CreateStreamId, anArtificialMenuId, -1, -1 );
196 int aNaturalMenuId = createMenu( tr( "MEN_DESK_NATURAL" ), aHydroId, -1 );
197 createMenu( CreateChannelId, aNaturalMenuId, -1, -1 );
199 int anObstacleMenuId = createMenu( tr( "MEN_DESK_OBSTACLE" ), aHydroId, -1 );
200 createMenu( ImportObstacleFromFileId, anObstacleMenuId, -1, -1 );
201 createMenu( CreateBoxId, anObstacleMenuId, -1, -1 );
202 createMenu( CreateCylinderId, anObstacleMenuId, -1, -1 );
204 createMenu( CreateCalculationId, aHydroId, -1, -1 );
205 createMenu( separator(), aHydroId );
206 createMenu( FuseImagesId, aHydroId, -1, -1 );
207 createMenu( CutImagesId, aHydroId, -1, -1 );
208 createMenu( SplitImageId, aHydroId, -1, -1 );
209 createMenu( separator(), aHydroId );
212 void HYDROGUI_Module::createPopups()
216 void HYDROGUI_Module::createToolbars()
218 int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
219 createTool( UndoId, aToolBar );
220 createTool( RedoId, aToolBar );
223 void HYDROGUI_Module::createUndoRedoActions()
225 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
227 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
228 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
229 Qt::CTRL + Qt::Key_Z, application()->desktop() );
231 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
232 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
233 Qt::CTRL + Qt::Key_Y, application()->desktop() );
235 registerAction( UndoId, anEditUndo );
236 registerAction( RedoId, anEditRedo );
238 anEditUndo->setComment( tr( "STB_UNDO" ) );
239 anEditRedo->setComment( tr( "STB_REDO" ) );
241 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
242 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
245 void HYDROGUI_Module::updateUndoRedoControls()
247 HYDROGUI_DataModel* aModel = getDataModel();
249 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
250 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
252 bool aCanUndo = aModel->canUndo();
253 bool aCanRedo = aModel->canRedo();
256 aUndoAction->addNames( aModel->undoNames() );
257 aUndoAction->setEnabled( aCanUndo );
260 aRedoAction->addNames( aModel->redoNames() );
261 aRedoAction->setEnabled( aCanRedo );
264 void HYDROGUI_Module::onOperation()
266 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
267 int anId = actionId( anAction );
269 startOperation( anId );
272 void HYDROGUI_Module::onDelete()
274 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
275 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
276 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
277 aPolylineOp->deleteSelected();
279 startOperation( DeleteId );
282 bool HYDROGUI_Module::onUndo( int theNumActions )
284 QApplication::setOverrideCursor( Qt::WaitCursor );
286 HYDROGUI_DataModel* aModel = getDataModel();
289 while( theNumActions > 0 )
291 if( !aModel->undo() )
300 QApplication::restoreOverrideCursor();
304 bool HYDROGUI_Module::onRedo( int theNumActions )
306 QApplication::setOverrideCursor( Qt::WaitCursor );
308 HYDROGUI_DataModel* aModel = getDataModel();
311 while( theNumActions > 0 )
313 if( !aModel->redo() )
322 QApplication::restoreOverrideCursor();
326 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
328 LightApp_Operation* anOp = 0;
329 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
332 case SaveVisualStateId:
333 case LoadVisualStateId:
334 anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
338 anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
341 case EditImportedImageId:
342 anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
345 anOp = new HYDROGUI_ObserveImageOp( aModule );
348 anOp = new HYDROGUI_ExportImageOp( aModule );
351 anOp = new HYDROGUI_UpdateImageOp( aModule );
353 case RemoveImageRefsId:
354 anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
356 case CreatePolyline3DId:
357 case EditPolyline3DId:
358 anOp = new HYDROGUI_Poly3DOp( aModule, theId == EditPolyline3DId );
360 case CreatePolylineId:
362 anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
364 case CreateProfileId:
366 anOp = new HYDROGUI_ProfileOp( aModule, theId == EditProfileId );
368 case ImportProfilesId:
369 anOp = new HYDROGUI_ImportProfilesOp( aModule ) ;
371 case AllGeoreferencementId:
372 anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::All ) ;
374 case SelectedGeoreferencementId:
375 anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::Selected ) ;
377 case ImportBathymetryId:
378 case EditImportedBathymetryId:
379 anOp = new HYDROGUI_ImportBathymetryOp( aModule, theId == EditImportedBathymetryId );
381 case CreateImmersibleZoneId:
382 case EditImmersibleZoneId:
383 anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
387 anOp = new HYDROGUI_StreamOp( aModule, theId == EditStreamId );
389 case CreateChannelId:
391 anOp = new HYDROGUI_ChannelOp( aModule, theId == EditChannelId );
393 case CreateCalculationId:
394 case EditCalculationId:
395 anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
397 case ExportCalculationId:
398 anOp = new HYDROGUI_ExportCalculationOp( aModule );
401 case EditFusedImageId:
402 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
406 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
409 case EditSplittedImageId:
410 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId );
412 case ImportObstacleFromFileId:
413 anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule );
415 case ImportCreatedPrimitiveId:
416 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportCreated );
418 case ImportGeomObjectId:
419 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelected );
422 application()->activateOperation( "Geometry", GEOMOp::OpBox );
424 case CreateCylinderId:
425 application()->activateOperation( "Geometry", GEOMOp::OpCylinder );
428 anOp = new HYDROGUI_DeleteOp( aModule );
431 anOp = new HYDROGUI_SetColorOp( aModule );
438 anOp = new HYDROGUI_ShowHideOp( aModule, theId );
443 anOp = LightApp_Module::createOperation( theId );
448 bool HYDROGUI_Module::reusableOperation( const int id )
450 if ( id == ImportGeomObjectId ) {
454 return LightApp_Module::reusableOperation( id );
458 * Called when the operation perfomed by another module is finished.
459 * \param theModuleName the name of the module which perfomed the operation
460 * \param theOperationName the operation name
461 * \param theEntryList the list of the created objects entries
463 void HYDROGUI_Module::onExternalOperationFinished( const QString& theModuleName,
464 const QString& theOperationName,
465 const QStringList& theEntryList )
467 // Process "Geometry" module operations with non-empty list of created objects only
468 if ( theModuleName != "Geometry" || theEntryList.isEmpty() ) {
472 // Start import GEOM object operation
473 myGeomObjectsToImport = theEntryList;
474 startOperation( ImportCreatedPrimitiveId );
475 myGeomObjectsToImport.clear();
479 * Returns the list of entries of GEOM objects to be imported.
481 QStringList HYDROGUI_Module::GetGeomObjectsToImport()
483 return myGeomObjectsToImport;
487 * Returns true if the object with the given entry can be renamed.
488 * @param theEntry the object entry
490 bool HYDROGUI_Module::renameAllowed( const QString& theEntry ) const
492 // Allow to rename all HYDRO objects
493 Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
494 return !anEntity.IsNull();
497 * Returns true if the object with the given entry is renamed.
498 * @param theEntry the object entry
499 * @param theName the new name
501 bool HYDROGUI_Module::renameObject( const QString& theEntry, const QString& theName )
503 Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
504 bool aRes = !anEntity.IsNull();
507 HYDROGUI_DataModel* aModel = getDataModel();
510 if( anEntity->GetName() != theName )
512 // check that there are no other objects with the same name in the document
513 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( this, theName );
514 aRes = anObject.IsNull();
517 aRes = aModel->rename( anEntity, theName );
521 // Inform the user that the name is already used
522 QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
523 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
524 SUIT_MessageBox::critical( getApp()->desktop(), aTitle, aMessage );