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 );
126 createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE" );
127 createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE" );
129 createAction( CreateStreamId, "CREATE_STREAM" );
130 createAction( EditStreamId, "EDIT_STREAM" );
132 createAction( CreateChannelId, "CREATE_CHANNEL" );
133 createAction( EditChannelId, "EDIT_CHANNEL" );
135 createAction( ImportObstacleFromFileId, "IMPORT_OBSTACLE_FROM_FILE" );
136 createAction( ImportGeomObjectId, "IMPORT_GEOM_OBJECT" );
137 createAction( CreateBoxId, "CREATE_BOX" );
138 createAction( CreateCylinderId, "CREATE_CYLINDER" );
140 createAction( CreateCalculationId, "CREATE_CALCULATION" );
141 createAction( EditCalculationId, "EDIT_CALCULATION" );
142 createAction( ExportCalculationId, "EXPORT_CALCULATION" );
144 createAction( FuseImagesId, "FUSE_IMAGES" );
145 createAction( EditFusedImageId, "EDIT_FUSED_IMAGE" );
147 createAction( CutImagesId, "CUT_IMAGES" );
148 createAction( EditCutImageId, "EDIT_CUT_IMAGE" );
150 createAction( SplitImageId, "SPLIT_IMAGE" );
151 createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE" );
153 createAction( DeleteId, "DELETE", "", Qt::Key_Delete, false,
154 SLOT( onDelete() ) );
156 createAction( SetColorId, "COLOR" );
158 createAction( ShowId, "SHOW" );
159 createAction( ShowOnlyId, "SHOW_ONLY" );
160 createAction( ShowAllId, "SHOW_ALL" );
161 createAction( HideId, "HIDE" );
162 createAction( HideAllId, "HIDE_ALL" );
165 void HYDROGUI_Module::createMenus()
167 int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
168 int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
169 createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
170 createMenu( separator(), aFileMenu, -1, aCustomPos );
172 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
173 createMenu( UndoId, anEditMenu );
174 createMenu( RedoId, anEditMenu );
175 createMenu( separator(), anEditMenu );
176 createMenu( CopyId, anEditMenu );
177 createMenu( PasteId, anEditMenu );
179 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
180 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
181 createMenu( ImportImageId, aHydroId, -1, -1 );
182 createMenu( ImportBathymetryId, aHydroId, -1, -1 );
183 createMenu( CreatePolylineId, aHydroId, -1, -1 );
184 createMenu( CreatePolyline3DId, aHydroId, -1, -1 );
186 int aNewProfileId = createMenu( tr( "MEN_DESK_PROFILE" ), aHydroId, -1 );
187 createMenu( CreateProfileId, aNewProfileId, -1, -1 );
188 createMenu( ImportProfilesId, aNewProfileId, -1, -1 );
189 createMenu( AllGeoreferencementId, aNewProfileId, -1, -1 );
191 int anArtificialMenuId = createMenu( tr( "MEN_DESK_ARTIFICIAL" ), aHydroId, -1 );
192 createMenu( CreateImmersibleZoneId, anArtificialMenuId, -1, -1 );
193 createMenu( CreateStreamId, anArtificialMenuId, -1, -1 );
195 int aNaturalMenuId = createMenu( tr( "MEN_DESK_NATURAL" ), aHydroId, -1 );
196 createMenu( CreateChannelId, aNaturalMenuId, -1, -1 );
198 int anObstacleMenuId = createMenu( tr( "MEN_DESK_OBSTACLE" ), aHydroId, -1 );
199 createMenu( ImportObstacleFromFileId, anObstacleMenuId, -1, -1 );
200 createMenu( CreateBoxId, anObstacleMenuId, -1, -1 );
201 createMenu( CreateCylinderId, anObstacleMenuId, -1, -1 );
203 createMenu( CreateCalculationId, aHydroId, -1, -1 );
204 createMenu( separator(), aHydroId );
205 createMenu( FuseImagesId, aHydroId, -1, -1 );
206 createMenu( CutImagesId, aHydroId, -1, -1 );
207 createMenu( SplitImageId, aHydroId, -1, -1 );
208 createMenu( separator(), aHydroId );
211 void HYDROGUI_Module::createPopups()
215 void HYDROGUI_Module::createToolbars()
217 int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
218 createTool( UndoId, aToolBar );
219 createTool( RedoId, aToolBar );
222 void HYDROGUI_Module::createUndoRedoActions()
224 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
226 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
227 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
228 Qt::CTRL + Qt::Key_Z, application()->desktop() );
230 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
231 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
232 Qt::CTRL + Qt::Key_Y, application()->desktop() );
234 registerAction( UndoId, anEditUndo );
235 registerAction( RedoId, anEditRedo );
237 anEditUndo->setComment( tr( "STB_UNDO" ) );
238 anEditRedo->setComment( tr( "STB_REDO" ) );
240 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
241 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
244 void HYDROGUI_Module::updateUndoRedoControls()
246 HYDROGUI_DataModel* aModel = getDataModel();
248 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
249 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
251 bool aCanUndo = aModel->canUndo();
252 bool aCanRedo = aModel->canRedo();
255 aUndoAction->addNames( aModel->undoNames() );
256 aUndoAction->setEnabled( aCanUndo );
259 aRedoAction->addNames( aModel->redoNames() );
260 aRedoAction->setEnabled( aCanRedo );
263 void HYDROGUI_Module::onOperation()
265 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
266 int anId = actionId( anAction );
268 startOperation( anId );
271 void HYDROGUI_Module::onDelete()
273 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
274 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
275 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
276 aPolylineOp->deleteSelected();
278 startOperation( DeleteId );
281 bool HYDROGUI_Module::onUndo( int theNumActions )
283 QApplication::setOverrideCursor( Qt::WaitCursor );
285 HYDROGUI_DataModel* aModel = getDataModel();
288 while( theNumActions > 0 )
290 if( !aModel->undo() )
299 QApplication::restoreOverrideCursor();
303 bool HYDROGUI_Module::onRedo( int theNumActions )
305 QApplication::setOverrideCursor( Qt::WaitCursor );
307 HYDROGUI_DataModel* aModel = getDataModel();
310 while( theNumActions > 0 )
312 if( !aModel->redo() )
321 QApplication::restoreOverrideCursor();
325 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
327 LightApp_Operation* anOp = 0;
328 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
331 case SaveVisualStateId:
332 case LoadVisualStateId:
333 anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
337 anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
340 case EditImportedImageId:
341 anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
344 anOp = new HYDROGUI_ObserveImageOp( aModule );
347 anOp = new HYDROGUI_ExportImageOp( aModule );
350 anOp = new HYDROGUI_UpdateImageOp( aModule );
352 case RemoveImageRefsId:
353 anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
355 case CreatePolyline3DId:
356 case EditPolyline3DId:
357 anOp = new HYDROGUI_Poly3DOp( aModule, theId == EditPolyline3DId );
359 case CreatePolylineId:
361 anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
363 case CreateProfileId:
365 anOp = new HYDROGUI_ProfileOp( aModule, theId == EditProfileId );
367 case ImportProfilesId:
368 anOp = new HYDROGUI_ImportProfilesOp( aModule ) ;
370 case AllGeoreferencementId:
371 anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::All ) ;
373 case SelectedGeoreferencementId:
374 anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::Selected ) ;
376 case ImportBathymetryId:
377 anOp = new HYDROGUI_ImportBathymetryOp( aModule );
379 case CreateImmersibleZoneId:
380 case EditImmersibleZoneId:
381 anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
385 anOp = new HYDROGUI_StreamOp( aModule, theId == EditStreamId );
387 case CreateChannelId:
389 anOp = new HYDROGUI_ChannelOp( aModule, theId == EditChannelId );
391 case CreateCalculationId:
392 case EditCalculationId:
393 anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
395 case ExportCalculationId:
396 anOp = new HYDROGUI_ExportCalculationOp( aModule );
399 case EditFusedImageId:
400 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
404 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
407 case EditSplittedImageId:
408 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId );
410 case ImportObstacleFromFileId:
411 anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule );
413 case ImportCreatedPrimitiveId:
414 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportCreated );
416 case ImportGeomObjectId:
417 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelected );
420 application()->activateOperation( "Geometry", GEOMOp::OpBox );
422 case CreateCylinderId:
423 application()->activateOperation( "Geometry", GEOMOp::OpCylinder );
426 anOp = new HYDROGUI_DeleteOp( aModule );
429 anOp = new HYDROGUI_SetColorOp( aModule );
436 anOp = new HYDROGUI_ShowHideOp( aModule, theId );
441 anOp = LightApp_Module::createOperation( theId );
446 bool HYDROGUI_Module::reusableOperation( const int id )
448 if ( id == ImportGeomObjectId ) {
452 return LightApp_Module::reusableOperation( id );
456 * Called when the operation perfomed by another module is finished.
457 * \param theModuleName the name of the module which perfomed the operation
458 * \param theOperationName the operation name
459 * \param theEntryList the list of the created objects entries
461 void HYDROGUI_Module::onExternalOperationFinished( const QString& theModuleName,
462 const QString& theOperationName,
463 const QStringList& theEntryList )
465 // Process "Geometry" module operations with non-empty list of created objects only
466 if ( theModuleName != "Geometry" || theEntryList.isEmpty() ) {
470 // Start import GEOM object operation
471 myGeomObjectsToImport = theEntryList;
472 startOperation( ImportCreatedPrimitiveId );
473 myGeomObjectsToImport.clear();
477 * Returns the list of entries of GEOM objects to be imported.
479 QStringList HYDROGUI_Module::GetGeomObjectsToImport()
481 return myGeomObjectsToImport;
485 * Returns true if the object with the given entry can be renamed.
486 * @param theEntry the object entry
488 bool HYDROGUI_Module::renameAllowed( const QString& theEntry ) const
490 // Allow to rename all HYDRO objects
491 Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
492 return !anEntity.IsNull();
495 * Returns true if the object with the given entry is renamed.
496 * @param theEntry the object entry
497 * @param theName the new name
499 bool HYDROGUI_Module::renameObject( const QString& theEntry, const QString& theName )
501 Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
502 bool aRes = !anEntity.IsNull();
505 HYDROGUI_DataModel* aModel = getDataModel();
508 if( anEntity->GetName() != theName )
510 // check that there are no other objects with the same name in the document
511 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( this, theName );
512 aRes = anObject.IsNull();
515 aRes = aModel->rename( anEntity, theName );
519 // Inform the user that the name is already used
520 QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
521 QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
522 SUIT_MessageBox::critical( getApp()->desktop(), aTitle, aMessage );