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_DataModel.h"
27 #include "HYDROGUI_DeleteOp.h"
28 #include "HYDROGUI_ExportImageOp.h"
29 #include "HYDROGUI_ImportImageOp.h"
30 #include "HYDROGUI_ImportBathymetryOp.h"
31 #include "HYDROGUI_CalculationOp.h"
32 #include "HYDROGUI_Module.h"
33 #include "HYDROGUI_ObserveImageOp.h"
34 #include "HYDROGUI_PolylineOp.h"
35 #include "HYDROGUI_ShowHideOp.h"
36 #include "HYDROGUI_TwoImagesOp.h"
37 #include "HYDROGUI_UpdateFlags.h"
38 #include "HYDROGUI_UpdateImageOp.h"
39 #include "HYDROGUI_VisualStateOp.h"
41 #include <CAM_Application.h>
43 #include <QtxListAction.h>
45 #include <SUIT_Desktop.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_Session.h>
50 #include <QApplication>
52 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
53 const int theKey, const bool isToggle, const QString& theSlot )
55 QString aSlot = theSlot;
57 aSlot = SLOT( onOperation() );
58 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
59 std::string anImg = theImg.toStdString();
60 QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
61 std::string aMenu = ( "MEN_" + theSuffix ).toStdString();
62 std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
63 std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
64 std::string aSlotStr = aSlot.toStdString();
65 return LightApp_Module::createAction( theId, tr( aMenu.c_str() ), aPixmap,
66 tr( aDesktop.c_str() ), tr( aToolbar.c_str() ),
67 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
70 void HYDROGUI_Module::createActions()
72 createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
73 createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
75 createAction( CopyId, "COPY", "", Qt::CTRL + Qt::Key_C );
76 createAction( PasteId, "PASTE", "", Qt::CTRL + Qt::Key_V );
78 createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
79 createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE" );
80 createAction( ObserveImageId, "OBSERVE_IMAGE" );
81 createAction( ExportImageId, "EXPORT_IMAGE" );
82 createAction( UpdateImageId, "UPDATE_IMAGE" );
84 createAction( CreatePolylineId, "CREATE_POLYLINE" );
85 createAction( EditPolylineId, "EDIT_POLYLINE" );
87 createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::SHIFT + Qt::Key_I );
89 createAction( CreateCalculationId, "CREATE_CALCULATION" );
90 createAction( EditCalculationId, "EDIT_CALCULATION" );
92 createAction( FuseImagesId, "FUSE_IMAGES" );
93 createAction( EditFusedImageId, "EDIT_FUSED_IMAGE" );
95 createAction( CutImagesId, "CUT_IMAGES" );
96 createAction( EditCutImageId, "EDIT_CUT_IMAGE" );
98 createAction( SplitImageId, "SPLIT_IMAGE" );
99 createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE" );
101 createAction( DeleteId, "DELETE", "", Qt::Key_Delete );
103 createAction( ShowId, "SHOW" );
104 createAction( ShowOnlyId, "SHOW_ONLY" );
105 createAction( ShowAllId, "SHOW_ALL" );
106 createAction( HideId, "HIDE" );
107 createAction( HideAllId, "HIDE_ALL" );
110 void HYDROGUI_Module::createMenus()
112 int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
113 int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
114 createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
115 createMenu( separator(), aFileMenu, -1, aCustomPos );
117 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
118 createMenu( UndoId, anEditMenu );
119 createMenu( RedoId, anEditMenu );
120 createMenu( separator(), anEditMenu );
121 createMenu( CopyId, anEditMenu );
122 createMenu( PasteId, anEditMenu );
124 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
125 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
126 createMenu( ImportImageId, aHydroId, -1, -1 );
127 createMenu( ImportBathymetryId, aHydroId, -1, -1 );
128 createMenu( CreatePolylineId, aHydroId, -1, -1 );
129 createMenu( CreateCalculationId, aHydroId, -1, -1 );
130 createMenu( FuseImagesId, aHydroId, -1, -1 );
131 createMenu( CutImagesId, aHydroId, -1, -1 );
132 createMenu( SplitImageId, aHydroId, -1, -1 );
135 void HYDROGUI_Module::createPopups()
139 void HYDROGUI_Module::createToolbars()
141 int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
142 createTool( UndoId, aToolBar );
143 createTool( RedoId, aToolBar );
146 void HYDROGUI_Module::createUndoRedoActions()
148 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
150 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
151 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
152 Qt::CTRL + Qt::Key_Z, application()->desktop() );
154 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
155 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
156 Qt::CTRL + Qt::Key_Y, application()->desktop() );
158 registerAction( UndoId, anEditUndo );
159 registerAction( RedoId, anEditRedo );
161 anEditUndo->setComment( tr( "STB_UNDO" ) );
162 anEditRedo->setComment( tr( "STB_REDO" ) );
164 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
165 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
168 void HYDROGUI_Module::updateUndoRedoControls()
170 HYDROGUI_DataModel* aModel = getDataModel();
172 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
173 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
175 bool aCanUndo = aModel->canUndo();
176 bool aCanRedo = aModel->canRedo();
179 aUndoAction->addNames( aModel->undoNames() );
180 aUndoAction->setEnabled( aCanUndo );
183 aRedoAction->addNames( aModel->redoNames() );
184 aRedoAction->setEnabled( aCanRedo );
187 void HYDROGUI_Module::onOperation()
189 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
190 int anId = actionId( anAction );
192 startOperation( anId );
195 bool HYDROGUI_Module::onUndo( int theNumActions )
197 QApplication::setOverrideCursor( Qt::WaitCursor );
199 HYDROGUI_DataModel* aModel = getDataModel();
202 while( theNumActions > 0 )
204 if( !aModel->undo() )
213 QApplication::restoreOverrideCursor();
217 bool HYDROGUI_Module::onRedo( int theNumActions )
219 QApplication::setOverrideCursor( Qt::WaitCursor );
221 HYDROGUI_DataModel* aModel = getDataModel();
224 while( theNumActions > 0 )
226 if( !aModel->redo() )
235 QApplication::restoreOverrideCursor();
239 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
241 LightApp_Operation* anOp = 0;
242 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
245 case SaveVisualStateId:
246 case LoadVisualStateId:
247 anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
251 anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
254 case EditImportedImageId:
255 anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
258 anOp = new HYDROGUI_ObserveImageOp( aModule );
261 anOp = new HYDROGUI_ExportImageOp( aModule );
264 anOp = new HYDROGUI_UpdateImageOp( aModule );
266 case CreatePolylineId:
268 anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
270 case ImportBathymetryId:
271 anOp = new HYDROGUI_ImportBathymetryOp( aModule );
273 case CreateCalculationId:
274 case EditCalculationId:
275 anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
278 case EditFusedImageId:
279 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
283 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
286 case EditSplittedImageId:
287 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId );
290 anOp = new HYDROGUI_DeleteOp( aModule );
297 anOp = new HYDROGUI_ShowHideOp( aModule, theId );
302 anOp = LightApp_Module::createOperation( theId );