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_CalculationOp.h"
31 #include "HYDROGUI_Module.h"
32 #include "HYDROGUI_ObserveImageOp.h"
33 #include "HYDROGUI_PolylineOp.h"
34 #include "HYDROGUI_ShowHideOp.h"
35 #include "HYDROGUI_TwoImagesOp.h"
36 #include "HYDROGUI_UpdateFlags.h"
37 #include "HYDROGUI_UpdateImageOp.h"
38 #include "HYDROGUI_VisualStateOp.h"
40 #include <CAM_Application.h>
42 #include <QtxListAction.h>
44 #include <SUIT_Desktop.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Session.h>
49 #include <QApplication>
51 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
52 const int theKey, const bool isToggle, const QString& theSlot )
54 QString aSlot = theSlot;
56 aSlot = SLOT( onOperation() );
57 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
58 std::string anImg = theImg.toStdString();
59 QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
60 std::string aMenu = ( "MEN_" + theSuffix ).toStdString();
61 std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
62 std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
63 std::string aSlotStr = aSlot.toStdString();
64 return LightApp_Module::createAction( theId, tr( aMenu.c_str() ), aPixmap,
65 tr( aDesktop.c_str() ), tr( aToolbar.c_str() ),
66 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
69 void HYDROGUI_Module::createActions()
71 createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
72 createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
74 createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
75 createAction( EditImportedImageId, "EDIT_IMPORTED_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( CreateCalculationId, "CREATE_CALCULATION" );
86 createAction( EditCalculationId, "EDIT_CALCULATION" );
88 createAction( FuseImagesId, "FUSE_IMAGES" );
89 createAction( EditFusedImageId, "EDIT_FUSED_IMAGE" );
91 createAction( CutImagesId, "CUT_IMAGES" );
92 createAction( EditCutImageId, "EDIT_CUT_IMAGE" );
94 createAction( SplitImageId, "SPLIT_IMAGE" );
95 createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE" );
97 createAction( DeleteId, "DELETE", "", Qt::Key_Delete );
99 createAction( ShowId, "SHOW" );
100 createAction( ShowOnlyId, "SHOW_ONLY" );
101 createAction( ShowAllId, "SHOW_ALL" );
102 createAction( HideId, "HIDE" );
103 createAction( HideAllId, "HIDE_ALL" );
106 void HYDROGUI_Module::createMenus()
108 int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
109 int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
110 createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
111 createMenu( separator(), aFileMenu, -1, aCustomPos );
113 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
114 createMenu( UndoId, anEditMenu );
115 createMenu( RedoId, anEditMenu );
117 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
118 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
119 createMenu( ImportImageId, aHydroId, -1, -1 );
120 createMenu( ImportBathymetryId, aHydroId, -1, -1 );
121 createMenu( CreatePolylineId, aHydroId, -1, -1 );
122 createMenu( CreateCalculationId, aHydroId, -1, -1 );
123 createMenu( FuseImagesId, aHydroId, -1, -1 );
124 createMenu( CutImagesId, aHydroId, -1, -1 );
125 createMenu( SplitImageId, aHydroId, -1, -1 );
128 void HYDROGUI_Module::createPopups()
132 void HYDROGUI_Module::createToolbars()
134 int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
135 createTool( UndoId, aToolBar );
136 createTool( RedoId, aToolBar );
139 void HYDROGUI_Module::createUndoRedoActions()
141 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
143 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
144 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
145 Qt::CTRL + Qt::Key_Z, application()->desktop() );
147 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
148 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
149 Qt::CTRL + Qt::Key_Y, application()->desktop() );
151 registerAction( UndoId, anEditUndo );
152 registerAction( RedoId, anEditRedo );
154 anEditUndo->setComment( tr( "STB_UNDO" ) );
155 anEditRedo->setComment( tr( "STB_REDO" ) );
157 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
158 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
161 void HYDROGUI_Module::updateUndoRedoControls()
163 HYDROGUI_DataModel* aModel = getDataModel();
165 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
166 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
168 bool aCanUndo = aModel->canUndo();
169 bool aCanRedo = aModel->canRedo();
172 aUndoAction->addNames( aModel->undoNames() );
173 aUndoAction->setEnabled( aCanUndo );
176 aRedoAction->addNames( aModel->redoNames() );
177 aRedoAction->setEnabled( aCanRedo );
180 void HYDROGUI_Module::onOperation()
182 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
183 int anId = actionId( anAction );
185 startOperation( anId );
188 bool HYDROGUI_Module::onUndo( int theNumActions )
190 QApplication::setOverrideCursor( Qt::WaitCursor );
192 HYDROGUI_DataModel* aModel = getDataModel();
195 while( theNumActions > 0 )
197 if( !aModel->undo() )
206 QApplication::restoreOverrideCursor();
210 bool HYDROGUI_Module::onRedo( int theNumActions )
212 QApplication::setOverrideCursor( Qt::WaitCursor );
214 HYDROGUI_DataModel* aModel = getDataModel();
217 while( theNumActions > 0 )
219 if( !aModel->redo() )
228 QApplication::restoreOverrideCursor();
232 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
234 LightApp_Operation* anOp = 0;
235 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
238 case SaveVisualStateId:
239 case LoadVisualStateId:
240 anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
243 case EditImportedImageId:
244 anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
247 anOp = new HYDROGUI_ObserveImageOp( aModule );
250 anOp = new HYDROGUI_ExportImageOp( aModule );
253 anOp = new HYDROGUI_UpdateImageOp( aModule );
255 case CreatePolylineId:
257 anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
259 case ImportBathymetryId:
260 anOp = new HYDROGUI_ImportBathymetryOp( aModule );
262 case CreateCalculationId:
263 case EditCalculationId:
264 anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
267 case EditFusedImageId:
268 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
272 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
275 case EditSplittedImageId:
276 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId );
279 anOp = new HYDROGUI_DeleteOp( aModule );
286 anOp = new HYDROGUI_ShowHideOp( aModule, theId );
291 anOp = LightApp_Module::createOperation( theId );