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_DataModel.h"
28 #include "HYDROGUI_DeleteOp.h"
29 #include "HYDROGUI_ExportImageOp.h"
30 #include "HYDROGUI_ImportImageOp.h"
31 #include "HYDROGUI_ImportBathymetryOp.h"
32 #include "HYDROGUI_ImmersibleZoneOp.h"
33 #include "HYDROGUI_Module.h"
34 #include "HYDROGUI_ObserveImageOp.h"
35 #include "HYDROGUI_PolylineOp.h"
36 #include "HYDROGUI_ProfileOp.h"
37 #include "HYDROGUI_RemoveImageRefsOp.h"
38 #include "HYDROGUI_ShowHideOp.h"
39 #include "HYDROData_SplitToZonesTool.h"
40 #include "HYDROGUI_TwoImagesOp.h"
41 #include "HYDROGUI_UpdateFlags.h"
42 #include "HYDROGUI_UpdateImageOp.h"
43 #include "HYDROGUI_VisualStateOp.h"
44 #include "HYDROGUI_ImmersibleZoneOp.h"
45 #include "HYDROGUI_ImportGeomObjectOp.h"
46 #include "HYDROGUI_ImportObstacleFromFileOp.h"
47 #include "HYDROGUI_ExportCalculationOp.h"
48 #include "HYDROGUI_ImportProfilesOp.h"
49 #include "HYDROGUI_GeoreferencementOp.h"
50 #include "HYDROGUI_SetColorOp.h"
52 #include "HYDROData_Document.h"
53 #include "HYDROData_Obstacle.h"
55 #include <GeometryGUI.h>
56 #include <GeometryGUI_Operations.h>
59 #include <SalomeApp_Study.h>
61 #include <LightApp_Application.h>
63 #include <CAM_Application.h>
65 #include <QtxListAction.h>
67 #include <SUIT_Desktop.h>
68 #include <SUIT_ResourceMgr.h>
69 #include <SUIT_Session.h>
72 #include <QApplication>
74 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
75 const int theKey, const bool isToggle, const QString& theSlot )
77 QString aSlot = theSlot;
79 aSlot = SLOT( onOperation() );
80 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
81 std::string anImg = theImg.toStdString();
82 QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
83 std::string aMenu = ( "MEN_" + theSuffix ).toStdString();
84 std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
85 std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
86 std::string aSlotStr = aSlot.toStdString();
87 return LightApp_Module::createAction( theId, tr( aDesktop.c_str() ), aPixmap,
88 tr( aMenu.c_str() ), tr( aToolbar.c_str() ),
89 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
92 void HYDROGUI_Module::createActions()
94 createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
95 createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
97 createAction( CopyId, "COPY", "", Qt::CTRL + Qt::Key_C );
98 createAction( PasteId, "PASTE", "", Qt::CTRL + Qt::Key_V );
100 createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
101 createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE" );
102 createAction( ObserveImageId, "OBSERVE_IMAGE" );
103 createAction( ExportImageId, "EXPORT_IMAGE" );
104 createAction( UpdateImageId, "UPDATE_IMAGE" );
105 createAction( RemoveImageRefsId, "REMOVE_IMAGE_REFERENCE" );
107 createAction( CreatePolylineId, "CREATE_POLYLINE" );
108 createAction( EditPolylineId, "EDIT_POLYLINE" );
110 createAction( CreateProfileId, "CREATE_PROFILE" );
111 createAction( ImportProfilesId, "IMPORT_PROFILES" );
112 createAction( EditProfileId, "EDIT_PROFILE" );
113 createAction( AllGeoreferencementId, "GEOREFERENCEMENT" );
114 createAction( SelectedGeoreferencementId, "GEOREFERENCEMENT" );
116 createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::Key_B );
118 createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE" );
119 createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE" );
121 createAction( ImportObstacleFromFileId, "IMPORT_OBSTACLE_FROM_FILE" );
122 createAction( ImportGeomObjectId, "IMPORT_GEOM_OBJECT" );
123 createAction( CreateBoxId, "CREATE_BOX" );
124 createAction( CreateCylinderId, "CREATE_CYLINDER" );
126 createAction( CreateCalculationId, "CREATE_CALCULATION" );
127 createAction( EditCalculationId, "EDIT_CALCULATION" );
128 createAction( ExportCalculationId, "EXPORT_CALCULATION" );
130 createAction( FuseImagesId, "FUSE_IMAGES" );
131 createAction( EditFusedImageId, "EDIT_FUSED_IMAGE" );
133 createAction( CutImagesId, "CUT_IMAGES" );
134 createAction( EditCutImageId, "EDIT_CUT_IMAGE" );
136 createAction( SplitImageId, "SPLIT_IMAGE" );
137 createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE" );
139 createAction( DeleteId, "DELETE", "", Qt::Key_Delete, false,
140 SLOT( onDelete() ) );
142 createAction( SetColorId, "COLOR" );
144 createAction( ShowId, "SHOW" );
145 createAction( ShowOnlyId, "SHOW_ONLY" );
146 createAction( ShowAllId, "SHOW_ALL" );
147 createAction( HideId, "HIDE" );
148 createAction( HideAllId, "HIDE_ALL" );
151 void HYDROGUI_Module::createMenus()
153 int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
154 int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
155 createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
156 createMenu( separator(), aFileMenu, -1, aCustomPos );
158 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
159 createMenu( UndoId, anEditMenu );
160 createMenu( RedoId, anEditMenu );
161 createMenu( separator(), anEditMenu );
162 createMenu( CopyId, anEditMenu );
163 createMenu( PasteId, anEditMenu );
165 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
166 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
167 createMenu( ImportImageId, aHydroId, -1, -1 );
168 createMenu( ImportBathymetryId, aHydroId, -1, -1 );
169 createMenu( CreatePolylineId, aHydroId, -1, -1 );
171 int aNewProfileId = createMenu( tr( "MEN_PROFILE" ), aHydroId, -1 );
172 createMenu( CreateProfileId, aNewProfileId, -1, -1 );
173 createMenu( ImportProfilesId, aNewProfileId, -1, -1 );
174 createMenu( AllGeoreferencementId, aNewProfileId, -1, -1 );
176 createMenu( CreateImmersibleZoneId, aHydroId, -1, -1 );
178 int aNewObstacleId = createMenu( tr( "MEN_OBSTACLE" ), aHydroId, -1 );
179 createMenu( ImportObstacleFromFileId, aNewObstacleId, -1, -1 );
180 createMenu( CreateBoxId, aNewObstacleId, -1, -1 );
181 createMenu( CreateCylinderId, aNewObstacleId, -1, -1 );
183 createMenu( CreateCalculationId, aHydroId, -1, -1 );
184 createMenu( separator(), aHydroId );
185 createMenu( FuseImagesId, aHydroId, -1, -1 );
186 createMenu( CutImagesId, aHydroId, -1, -1 );
187 createMenu( SplitImageId, aHydroId, -1, -1 );
188 createMenu( separator(), aHydroId );
191 void HYDROGUI_Module::createPopups()
195 void HYDROGUI_Module::createToolbars()
197 int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
198 createTool( UndoId, aToolBar );
199 createTool( RedoId, aToolBar );
202 void HYDROGUI_Module::createUndoRedoActions()
204 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
206 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
207 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
208 Qt::CTRL + Qt::Key_Z, application()->desktop() );
210 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
211 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
212 Qt::CTRL + Qt::Key_Y, application()->desktop() );
214 registerAction( UndoId, anEditUndo );
215 registerAction( RedoId, anEditRedo );
217 anEditUndo->setComment( tr( "STB_UNDO" ) );
218 anEditRedo->setComment( tr( "STB_REDO" ) );
220 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
221 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
224 void HYDROGUI_Module::updateUndoRedoControls()
226 HYDROGUI_DataModel* aModel = getDataModel();
228 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
229 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
231 bool aCanUndo = aModel->canUndo();
232 bool aCanRedo = aModel->canRedo();
235 aUndoAction->addNames( aModel->undoNames() );
236 aUndoAction->setEnabled( aCanUndo );
239 aRedoAction->addNames( aModel->redoNames() );
240 aRedoAction->setEnabled( aCanRedo );
243 void HYDROGUI_Module::onOperation()
245 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
246 int anId = actionId( anAction );
248 startOperation( anId );
251 void HYDROGUI_Module::onDelete()
253 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
254 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
255 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
256 aPolylineOp->deleteSelected();
258 startOperation( DeleteId );
261 bool HYDROGUI_Module::onUndo( int theNumActions )
263 QApplication::setOverrideCursor( Qt::WaitCursor );
265 HYDROGUI_DataModel* aModel = getDataModel();
268 while( theNumActions > 0 )
270 if( !aModel->undo() )
279 QApplication::restoreOverrideCursor();
283 bool HYDROGUI_Module::onRedo( int theNumActions )
285 QApplication::setOverrideCursor( Qt::WaitCursor );
287 HYDROGUI_DataModel* aModel = getDataModel();
290 while( theNumActions > 0 )
292 if( !aModel->redo() )
301 QApplication::restoreOverrideCursor();
305 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
307 LightApp_Operation* anOp = 0;
308 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
311 case SaveVisualStateId:
312 case LoadVisualStateId:
313 anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
317 anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
320 case EditImportedImageId:
321 anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
324 anOp = new HYDROGUI_ObserveImageOp( aModule );
327 anOp = new HYDROGUI_ExportImageOp( aModule );
330 anOp = new HYDROGUI_UpdateImageOp( aModule );
332 case RemoveImageRefsId:
333 anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
335 case CreatePolylineId:
337 anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
339 case CreateProfileId:
341 anOp = new HYDROGUI_ProfileOp( aModule, theId == EditProfileId );
343 case ImportProfilesId:
344 anOp = new HYDROGUI_ImportProfilesOp( aModule ) ;
346 case AllGeoreferencementId:
347 anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::All ) ;
349 case SelectedGeoreferencementId:
350 anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::Selected ) ;
352 case ImportBathymetryId:
353 anOp = new HYDROGUI_ImportBathymetryOp( aModule );
355 case CreateImmersibleZoneId:
356 case EditImmersibleZoneId:
357 anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
359 case CreateCalculationId:
360 case EditCalculationId:
361 anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
363 case ExportCalculationId:
364 anOp = new HYDROGUI_ExportCalculationOp( aModule );
367 case EditFusedImageId:
368 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
372 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
375 case EditSplittedImageId:
376 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId );
378 case ImportObstacleFromFileId:
379 anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule );
381 case ImportCreatedPrimitiveId:
382 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportCreated );
384 case ImportGeomObjectId:
385 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelected );
388 application()->activateOperation( "Geometry", GEOMOp::OpBox );
390 case CreateCylinderId:
391 application()->activateOperation( "Geometry", GEOMOp::OpCylinder );
394 anOp = new HYDROGUI_DeleteOp( aModule );
397 anOp = new HYDROGUI_SetColorOp( aModule );
404 anOp = new HYDROGUI_ShowHideOp( aModule, theId );
409 anOp = LightApp_Module::createOperation( theId );
414 bool HYDROGUI_Module::reusableOperation( const int id )
416 if ( id == ImportGeomObjectId ) {
420 return LightApp_Module::reusableOperation( id );
424 * Called when the operation perfomed by another module is finished.
425 * \param theModuleName the name of the module which perfomed the operation
426 * \param theOperationName the operation name
427 * \param theEntryList the list of the created objects entries
429 void HYDROGUI_Module::onExternalOperationFinished( const QString& theModuleName,
430 const QString& theOperationName,
431 const QStringList& theEntryList )
433 // Process "Geometry" module operations with non-empty list of created objects only
434 if ( theModuleName != "Geometry" || theEntryList.isEmpty() ) {
438 // Start import GEOM object operation
439 myGeomObjectsToImport = theEntryList;
440 startOperation( ImportCreatedPrimitiveId );
441 myGeomObjectsToImport.clear();
445 * Returns the list of entries of GEOM objects to be imported.
447 QStringList HYDROGUI_Module::GetGeomObjectsToImport()
449 return myGeomObjectsToImport;