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_SetColorOp.h"
50 #include "HYDROData_Document.h"
51 #include "HYDROData_Obstacle.h"
53 #include <GeometryGUI.h>
54 #include <GeometryGUI_Operations.h>
57 #include <SalomeApp_Study.h>
59 #include <LightApp_Application.h>
61 #include <CAM_Application.h>
63 #include <QtxListAction.h>
65 #include <SUIT_Desktop.h>
66 #include <SUIT_ResourceMgr.h>
67 #include <SUIT_Session.h>
70 #include <QApplication>
72 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
73 const int theKey, const bool isToggle, const QString& theSlot )
75 QString aSlot = theSlot;
77 aSlot = SLOT( onOperation() );
78 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
79 std::string anImg = theImg.toStdString();
80 QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
81 std::string aMenu = ( "MEN_" + theSuffix ).toStdString();
82 std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
83 std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
84 std::string aSlotStr = aSlot.toStdString();
85 return LightApp_Module::createAction( theId, tr( aDesktop.c_str() ), aPixmap,
86 tr( aMenu.c_str() ), tr( aToolbar.c_str() ),
87 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
90 void HYDROGUI_Module::createActions()
92 createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
93 createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
95 createAction( CopyId, "COPY", "", Qt::CTRL + Qt::Key_C );
96 createAction( PasteId, "PASTE", "", Qt::CTRL + Qt::Key_V );
98 createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
99 createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE" );
100 createAction( ObserveImageId, "OBSERVE_IMAGE" );
101 createAction( ExportImageId, "EXPORT_IMAGE" );
102 createAction( UpdateImageId, "UPDATE_IMAGE" );
103 createAction( RemoveImageRefsId, "REMOVE_IMAGE_REFERENCE" );
105 createAction( CreatePolylineId, "CREATE_POLYLINE" );
106 createAction( EditPolylineId, "EDIT_POLYLINE" );
108 createAction( CreateProfileId, "CREATE_PROFILE" );
109 createAction( EditProfileId, "EDIT_PROFILE" );
111 createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::Key_B );
113 createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE" );
114 createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE" );
116 createAction( ImportObstacleFromFileId, "IMPORT_OBSTACLE_FROM_FILE" );
117 createAction( ImportGeomObjectId, "IMPORT_GEOM_OBJECT" );
118 createAction( CreateBoxId, "CREATE_BOX" );
119 createAction( CreateCylinderId, "CREATE_CYLINDER" );
121 createAction( CreateCalculationId, "CREATE_CALCULATION" );
122 createAction( EditCalculationId, "EDIT_CALCULATION" );
123 createAction( ExportCalculationId, "EXPORT_CALCULATION" );
125 createAction( FuseImagesId, "FUSE_IMAGES" );
126 createAction( EditFusedImageId, "EDIT_FUSED_IMAGE" );
128 createAction( CutImagesId, "CUT_IMAGES" );
129 createAction( EditCutImageId, "EDIT_CUT_IMAGE" );
131 createAction( SplitImageId, "SPLIT_IMAGE" );
132 createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE" );
134 createAction( DeleteId, "DELETE", "", Qt::Key_Delete, false,
135 SLOT( onDelete() ) );
137 createAction( SetColorId, "COLOR" );
139 createAction( ShowId, "SHOW" );
140 createAction( ShowOnlyId, "SHOW_ONLY" );
141 createAction( ShowAllId, "SHOW_ALL" );
142 createAction( HideId, "HIDE" );
143 createAction( HideAllId, "HIDE_ALL" );
146 void HYDROGUI_Module::createMenus()
148 int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
149 int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
150 createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
151 createMenu( separator(), aFileMenu, -1, aCustomPos );
153 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
154 createMenu( UndoId, anEditMenu );
155 createMenu( RedoId, anEditMenu );
156 createMenu( separator(), anEditMenu );
157 createMenu( CopyId, anEditMenu );
158 createMenu( PasteId, anEditMenu );
160 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
161 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
162 createMenu( ImportImageId, aHydroId, -1, -1 );
163 createMenu( ImportBathymetryId, aHydroId, -1, -1 );
164 createMenu( CreatePolylineId, aHydroId, -1, -1 );
165 createMenu( CreateProfileId, aHydroId, -1, -1 );
166 createMenu( CreateImmersibleZoneId, aHydroId, -1, -1 );
168 int aNewObstacleId = createMenu( tr( "MEN_OBSTACLE" ), aHydroId, -1 );
169 createMenu( ImportObstacleFromFileId, aNewObstacleId, -1, -1 );
170 createMenu( CreateBoxId, aNewObstacleId, -1, -1 );
171 createMenu( CreateCylinderId, aNewObstacleId, -1, -1 );
173 createMenu( CreateCalculationId, aHydroId, -1, -1 );
174 createMenu( separator(), aHydroId );
175 createMenu( FuseImagesId, aHydroId, -1, -1 );
176 createMenu( CutImagesId, aHydroId, -1, -1 );
177 createMenu( SplitImageId, aHydroId, -1, -1 );
178 createMenu( separator(), aHydroId );
181 void HYDROGUI_Module::createPopups()
185 void HYDROGUI_Module::createToolbars()
187 int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
188 createTool( UndoId, aToolBar );
189 createTool( RedoId, aToolBar );
192 void HYDROGUI_Module::createUndoRedoActions()
194 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
196 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
197 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
198 Qt::CTRL + Qt::Key_Z, application()->desktop() );
200 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
201 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
202 Qt::CTRL + Qt::Key_Y, application()->desktop() );
204 registerAction( UndoId, anEditUndo );
205 registerAction( RedoId, anEditRedo );
207 anEditUndo->setComment( tr( "STB_UNDO" ) );
208 anEditRedo->setComment( tr( "STB_REDO" ) );
210 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
211 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
214 void HYDROGUI_Module::updateUndoRedoControls()
216 HYDROGUI_DataModel* aModel = getDataModel();
218 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
219 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
221 bool aCanUndo = aModel->canUndo();
222 bool aCanRedo = aModel->canRedo();
225 aUndoAction->addNames( aModel->undoNames() );
226 aUndoAction->setEnabled( aCanUndo );
229 aRedoAction->addNames( aModel->redoNames() );
230 aRedoAction->setEnabled( aCanRedo );
233 void HYDROGUI_Module::onOperation()
235 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
236 int anId = actionId( anAction );
238 startOperation( anId );
241 void HYDROGUI_Module::onDelete()
243 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
244 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
245 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
246 aPolylineOp->deleteSelected();
248 startOperation( DeleteId );
251 bool HYDROGUI_Module::onUndo( int theNumActions )
253 QApplication::setOverrideCursor( Qt::WaitCursor );
255 HYDROGUI_DataModel* aModel = getDataModel();
258 while( theNumActions > 0 )
260 if( !aModel->undo() )
269 QApplication::restoreOverrideCursor();
273 bool HYDROGUI_Module::onRedo( int theNumActions )
275 QApplication::setOverrideCursor( Qt::WaitCursor );
277 HYDROGUI_DataModel* aModel = getDataModel();
280 while( theNumActions > 0 )
282 if( !aModel->redo() )
291 QApplication::restoreOverrideCursor();
295 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
297 LightApp_Operation* anOp = 0;
298 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
301 case SaveVisualStateId:
302 case LoadVisualStateId:
303 anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
307 anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
310 case EditImportedImageId:
311 anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
314 anOp = new HYDROGUI_ObserveImageOp( aModule );
317 anOp = new HYDROGUI_ExportImageOp( aModule );
320 anOp = new HYDROGUI_UpdateImageOp( aModule );
322 case RemoveImageRefsId:
323 anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
325 case CreatePolylineId:
327 anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
329 case CreateProfileId:
331 anOp = new HYDROGUI_ProfileOp( aModule, theId == EditProfileId );
333 case ImportBathymetryId:
334 anOp = new HYDROGUI_ImportBathymetryOp( aModule );
336 case CreateImmersibleZoneId:
337 case EditImmersibleZoneId:
338 anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
340 case CreateCalculationId:
341 case EditCalculationId:
342 anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
344 case ExportCalculationId:
345 anOp = new HYDROGUI_ExportCalculationOp( aModule );
348 case EditFusedImageId:
349 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
353 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
356 case EditSplittedImageId:
357 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId );
359 case ImportObstacleFromFileId:
360 anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule );
362 case ImportCreatedPrimitiveId:
363 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportCreated );
365 case ImportGeomObjectId:
366 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelected );
369 application()->activateOperation( "Geometry", GEOMOp::OpBox );
371 case CreateCylinderId:
372 application()->activateOperation( "Geometry", GEOMOp::OpCylinder );
375 anOp = new HYDROGUI_DeleteOp( aModule );
378 anOp = new HYDROGUI_SetColorOp( aModule );
385 anOp = new HYDROGUI_ShowHideOp( aModule, theId );
390 anOp = LightApp_Module::createOperation( theId );
395 bool HYDROGUI_Module::reusableOperation( const int id )
397 if ( id == ImportGeomObjectId ) {
401 return LightApp_Module::reusableOperation( id );
405 * Called when the operation perfomed by another module is finished.
406 * \param theModuleName the name of the module which perfomed the operation
407 * \param theOperationName the operation name
408 * \param theEntryList the list of the created objects entries
410 void HYDROGUI_Module::onExternalOperationFinished( const QString& theModuleName,
411 const QString& theOperationName,
412 const QStringList& theEntryList )
414 // Process "Geometry" module operations with non-empty list of created objects only
415 if ( theModuleName != "Geometry" || theEntryList.isEmpty() ) {
419 // Start import GEOM object operation
420 myGeomObjectsToImport = theEntryList;
421 startOperation( ImportCreatedPrimitiveId );
422 myGeomObjectsToImport.clear();
426 * Returns the list of entries of GEOM objects to be imported.
428 QStringList HYDROGUI_Module::GetGeomObjectsToImport()
430 return myGeomObjectsToImport;