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_DataModel.h"
26 #include "HYDROGUI_DeleteOp.h"
27 #include "HYDROGUI_ExportImageOp.h"
28 #include "HYDROGUI_ImportImageOp.h"
29 #include "HYDROGUI_ImportBathymetryOp.h"
30 #include "HYDROGUI_Module.h"
31 #include "HYDROGUI_ObserveImageOp.h"
32 #include "HYDROGUI_PolylineOp.h"
33 #include "HYDROGUI_ShowHideOp.h"
34 #include "HYDROGUI_TwoImagesOp.h"
35 #include "HYDROGUI_UpdateFlags.h"
36 #include "HYDROGUI_UpdateImageOp.h"
37 #include "HYDROGUI_VisualStateOp.h"
39 #include <CAM_Application.h>
41 #include <QtxListAction.h>
43 #include <SUIT_Desktop.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Session.h>
48 #include <QApplication>
50 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
51 const int theKey, const bool isToggle, const QString& theSlot )
53 QString aSlot = theSlot;
55 aSlot = SLOT( onOperation() );
56 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
57 std::string anImg = theImg.toStdString();
58 QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
59 std::string aMenu = ( "MEN_" + theSuffix ).toStdString();
60 std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
61 std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
62 std::string aSlotStr = aSlot.toStdString();
63 return LightApp_Module::createAction( theId, tr( aMenu.c_str() ), aPixmap,
64 tr( aDesktop.c_str() ), tr( aToolbar.c_str() ),
65 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
68 void HYDROGUI_Module::createActions()
70 createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
71 createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
73 createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
74 createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE" );
75 createAction( EditCompositeImageId, "EDIT_COMPOSITE_IMAGE" );
76 createAction( ObserveImageId, "OBSERVE_IMAGE" );
77 createAction( ExportImageId, "EXPORT_IMAGE" );
78 createAction( UpdateImageId, "UPDATE_IMAGE" );
80 createAction( CreatePolylineId, "CREATE_POLYLINE" );
81 createAction( EditPolylineId, "EDIT_POLYLINE" );
83 createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::SHIFT + Qt::Key_I );
85 createAction( FuseId, "FUSE_IMAGES" );
86 createAction( CutId, "CUT_IMAGES" );
88 createAction( DeleteId, "DELETE", "", Qt::Key_Delete );
90 createAction( ShowId, "SHOW" );
91 createAction( ShowOnlyId, "SHOW_ONLY" );
92 createAction( ShowAllId, "SHOW_ALL" );
93 createAction( HideId, "HIDE" );
94 createAction( HideAllId, "HIDE_ALL" );
97 void HYDROGUI_Module::createMenus()
99 int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
100 int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
101 createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
102 createMenu( separator(), aFileMenu, -1, aCustomPos );
104 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
105 createMenu( UndoId, anEditMenu );
106 createMenu( RedoId, anEditMenu );
108 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
109 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
110 createMenu( ImportImageId, aHydroId, -1, -1 );
111 createMenu( ImportBathymetryId, aHydroId, -1, -1 );
112 createMenu( CreatePolylineId, aHydroId, -1, -1 );
113 createMenu( FuseId, aHydroId, -1, -1 );
114 createMenu( CutId, aHydroId, -1, -1 );
117 void HYDROGUI_Module::createPopups()
121 void HYDROGUI_Module::createToolbars()
123 int aToolBar = createTool( tr( "HYDRO_TOOLBAR" ) );
124 createTool( UndoId, aToolBar );
125 createTool( RedoId, aToolBar );
128 void HYDROGUI_Module::createUndoRedoActions()
130 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
132 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
133 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
134 Qt::CTRL + Qt::Key_Z, application()->desktop() );
136 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
137 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
138 Qt::CTRL + Qt::Key_Y, application()->desktop() );
140 registerAction( UndoId, anEditUndo );
141 registerAction( RedoId, anEditRedo );
143 anEditUndo->setComment( tr( "STB_UNDO" ) );
144 anEditRedo->setComment( tr( "STB_REDO" ) );
146 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
147 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
150 void HYDROGUI_Module::updateUndoRedoControls()
152 HYDROGUI_DataModel* aModel = getDataModel();
154 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
155 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
157 bool aCanUndo = aModel->canUndo();
158 bool aCanRedo = aModel->canRedo();
161 aUndoAction->addNames( aModel->undoNames() );
162 aUndoAction->setEnabled( aCanUndo );
165 aRedoAction->addNames( aModel->redoNames() );
166 aRedoAction->setEnabled( aCanRedo );
169 void HYDROGUI_Module::onOperation()
171 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
172 int anId = actionId( anAction );
174 startOperation( anId );
177 bool HYDROGUI_Module::onUndo( int theNumActions )
179 QApplication::setOverrideCursor( Qt::WaitCursor );
181 HYDROGUI_DataModel* aModel = getDataModel();
184 while( theNumActions > 0 )
186 if( !aModel->undo() )
195 QApplication::restoreOverrideCursor();
199 bool HYDROGUI_Module::onRedo( int theNumActions )
201 QApplication::setOverrideCursor( Qt::WaitCursor );
203 HYDROGUI_DataModel* aModel = getDataModel();
206 while( theNumActions > 0 )
208 if( !aModel->redo() )
217 QApplication::restoreOverrideCursor();
221 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
223 LightApp_Operation* anOp = 0;
224 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
227 case SaveVisualStateId:
228 case LoadVisualStateId:
229 anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
232 case EditImportedImageId:
233 anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
236 anOp = new HYDROGUI_ObserveImageOp( aModule );
239 anOp = new HYDROGUI_ExportImageOp( aModule );
242 anOp = new HYDROGUI_UpdateImageOp( aModule );
244 case CreatePolylineId:
246 anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
249 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse );
252 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut );
254 case EditCompositeImageId:
255 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Edit );
257 case ImportBathymetryId:
258 anOp = new HYDROGUI_ImportBathymetryOp( aModule );
261 anOp = new HYDROGUI_DeleteOp( aModule );
268 anOp = new HYDROGUI_ShowHideOp( aModule, theId );
273 anOp = LightApp_Module::createOperation( theId );