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_RemoveImageRefsOp.h"
37 #include "HYDROGUI_ShowHideOp.h"
38 #include "HYDROData_SplitToZonesTool.h"
39 #include "HYDROGUI_TwoImagesOp.h"
40 #include "HYDROGUI_UpdateFlags.h"
41 #include "HYDROGUI_UpdateImageOp.h"
42 #include "HYDROGUI_VisualStateOp.h"
44 #include <CAM_Application.h>
46 #include <QtxListAction.h>
48 #include <SUIT_Desktop.h>
49 #include <SUIT_ResourceMgr.h>
50 #include <SUIT_Session.h>
53 #include <QApplication>
55 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
56 const int theKey, const bool isToggle, const QString& theSlot )
58 QString aSlot = theSlot;
60 aSlot = SLOT( onOperation() );
61 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
62 std::string anImg = theImg.toStdString();
63 QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
64 std::string aMenu = ( "MEN_" + theSuffix ).toStdString();
65 std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
66 std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
67 std::string aSlotStr = aSlot.toStdString();
68 return LightApp_Module::createAction( theId, tr( aMenu.c_str() ), aPixmap,
69 tr( aDesktop.c_str() ), tr( aToolbar.c_str() ),
70 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
73 void HYDROGUI_Module::createActions()
75 createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
76 createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
78 createAction( CopyId, "COPY", "", Qt::CTRL + Qt::Key_C );
79 createAction( PasteId, "PASTE", "", Qt::CTRL + Qt::Key_V );
81 createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
82 createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE" );
83 createAction( ObserveImageId, "OBSERVE_IMAGE" );
84 createAction( ExportImageId, "EXPORT_IMAGE" );
85 createAction( UpdateImageId, "UPDATE_IMAGE" );
86 createAction( RemoveImageRefsId, "REMOVE_IMAGE_REFERENCE" );
88 createAction( CreatePolylineId, "CREATE_POLYLINE" );
89 createAction( EditPolylineId, "EDIT_POLYLINE" );
91 createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::Key_B );
93 createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE" );
94 createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE" );
96 createAction( CreateCalculationId, "CREATE_CALCULATION" );
97 createAction( EditCalculationId, "EDIT_CALCULATION" );
99 createAction( FuseImagesId, "FUSE_IMAGES" );
100 createAction( EditFusedImageId, "EDIT_FUSED_IMAGE" );
102 createAction( CutImagesId, "CUT_IMAGES" );
103 createAction( EditCutImageId, "EDIT_CUT_IMAGE" );
105 createAction( SplitImageId, "SPLIT_IMAGE" );
106 createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE" );
108 createAction( DeleteId, "DELETE", "", Qt::Key_Delete );
110 createAction( ShowId, "SHOW" );
111 createAction( ShowOnlyId, "SHOW_ONLY" );
112 createAction( ShowAllId, "SHOW_ALL" );
113 createAction( HideId, "HIDE" );
114 createAction( HideAllId, "HIDE_ALL" );
117 void HYDROGUI_Module::createMenus()
119 int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
120 int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
121 createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
122 createMenu( separator(), aFileMenu, -1, aCustomPos );
124 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
125 createMenu( UndoId, anEditMenu );
126 createMenu( RedoId, anEditMenu );
127 createMenu( separator(), anEditMenu );
128 createMenu( CopyId, anEditMenu );
129 createMenu( PasteId, anEditMenu );
131 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
132 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
133 createMenu( ImportImageId, aHydroId, -1, -1 );
134 createMenu( ImportBathymetryId, aHydroId, -1, -1 );
135 createMenu( CreatePolylineId, aHydroId, -1, -1 );
136 createMenu( CreateImmersibleZoneId, aHydroId, -1, -1 );
137 createMenu( CreateCalculationId, aHydroId, -1, -1 );
138 createMenu( separator(), aHydroId );
139 createMenu( FuseImagesId, aHydroId, -1, -1 );
140 createMenu( CutImagesId, aHydroId, -1, -1 );
141 createMenu( SplitImageId, aHydroId, -1, -1 );
144 void HYDROGUI_Module::createPopups()
148 void HYDROGUI_Module::createToolbars()
150 int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
151 createTool( UndoId, aToolBar );
152 createTool( RedoId, aToolBar );
155 void HYDROGUI_Module::createUndoRedoActions()
157 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
159 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
160 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
161 Qt::CTRL + Qt::Key_Z, application()->desktop() );
163 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
164 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
165 Qt::CTRL + Qt::Key_Y, application()->desktop() );
167 registerAction( UndoId, anEditUndo );
168 registerAction( RedoId, anEditRedo );
170 anEditUndo->setComment( tr( "STB_UNDO" ) );
171 anEditRedo->setComment( tr( "STB_REDO" ) );
173 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
174 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
177 void HYDROGUI_Module::updateUndoRedoControls()
179 HYDROGUI_DataModel* aModel = getDataModel();
181 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
182 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
184 bool aCanUndo = aModel->canUndo();
185 bool aCanRedo = aModel->canRedo();
188 aUndoAction->addNames( aModel->undoNames() );
189 aUndoAction->setEnabled( aCanUndo );
192 aRedoAction->addNames( aModel->redoNames() );
193 aRedoAction->setEnabled( aCanRedo );
196 void HYDROGUI_Module::onOperation()
198 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
199 int anId = actionId( anAction );
201 startOperation( anId );
204 bool HYDROGUI_Module::onUndo( int theNumActions )
206 QApplication::setOverrideCursor( Qt::WaitCursor );
208 HYDROGUI_DataModel* aModel = getDataModel();
211 while( theNumActions > 0 )
213 if( !aModel->undo() )
222 QApplication::restoreOverrideCursor();
226 bool HYDROGUI_Module::onRedo( int theNumActions )
228 QApplication::setOverrideCursor( Qt::WaitCursor );
230 HYDROGUI_DataModel* aModel = getDataModel();
233 while( theNumActions > 0 )
235 if( !aModel->redo() )
244 QApplication::restoreOverrideCursor();
248 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
250 LightApp_Operation* anOp = 0;
251 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
254 case SaveVisualStateId:
255 case LoadVisualStateId:
256 anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
260 anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
263 case EditImportedImageId:
264 anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
267 anOp = new HYDROGUI_ObserveImageOp( aModule );
270 anOp = new HYDROGUI_ExportImageOp( aModule );
273 anOp = new HYDROGUI_UpdateImageOp( aModule );
275 case RemoveImageRefsId:
276 anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
278 case CreatePolylineId:
280 anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
282 case ImportBathymetryId:
283 anOp = new HYDROGUI_ImportBathymetryOp( aModule );
285 case CreateImmersibleZoneId:
286 case EditImmersibleZoneId:
287 anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
289 case CreateCalculationId:
290 case EditCalculationId:
291 anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
294 case EditFusedImageId:
295 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
299 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
302 case EditSplittedImageId:
303 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId );
306 anOp = new HYDROGUI_DeleteOp( aModule );
313 anOp = new HYDROGUI_ShowHideOp( aModule, theId );
318 anOp = LightApp_Module::createOperation( theId );