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_ImportImageOp.h"
27 #include "HYDROGUI_Module.h"
28 #include "HYDROGUI_TwoImagesOp.h"
29 #include "HYDROGUI_UpdateFlags.h"
31 #include <CAM_Application.h>
33 #include <QtxListAction.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SUIT_Session.h>
40 #include <QApplication>
42 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
43 const int theKey, const bool isToggle, const QString& theSlot )
45 QString aSlot = theSlot;
47 aSlot = SLOT( onOperation() );
48 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
49 std::string anImg = theImg.toStdString();
50 QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
51 std::string aMenu = ( "MEN_" + theSuffix ).toStdString();
52 std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
53 std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
54 std::string aSlotStr = aSlot.toStdString();
55 return LightApp_Module::createAction( theId, tr( aMenu.c_str() ), aPixmap,
56 tr( aDesktop.c_str() ), tr( aToolbar.c_str() ),
57 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
60 void HYDROGUI_Module::createActions()
62 createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
63 createAction( FuseId, "FUSE_IMAGES" );
64 createAction( CutId, "CUT_IMAGES" );
67 void HYDROGUI_Module::createMenus()
69 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
70 createMenu( UndoId, anEditMenu );
71 createMenu( RedoId, anEditMenu );
73 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
74 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
75 createMenu( ImportImageId, aHydroId, -1, -1 );
76 createMenu( FuseId, aHydroId, -1, -1 );
77 createMenu( CutId, aHydroId, -1, -1 );
80 void HYDROGUI_Module::createPopups()
84 void HYDROGUI_Module::createToolbars()
86 int aToolBar = createTool( tr( "HYDRO_TOOLBAR" ) );
87 createTool( UndoId, aToolBar );
88 createTool( RedoId, aToolBar );
91 void HYDROGUI_Module::createUndoRedoActions()
93 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
95 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
96 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
97 Qt::CTRL + Qt::Key_Z, application()->desktop() );
99 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
100 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
101 Qt::CTRL + Qt::Key_Y, application()->desktop() );
103 registerAction( UndoId, anEditUndo );
104 registerAction( RedoId, anEditRedo );
106 anEditUndo->setComment( tr( "STB_UNDO" ) );
107 anEditRedo->setComment( tr( "STB_REDO" ) );
109 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
110 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
113 void HYDROGUI_Module::updateUndoRedoControls()
115 HYDROGUI_DataModel* aModel = getDataModel();
117 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
118 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
120 bool aCanUndo = aModel->canUndo();
121 bool aCanRedo = aModel->canRedo();
124 aUndoAction->addNames( aModel->undoNames() );
125 aUndoAction->setEnabled( aCanUndo );
128 aRedoAction->addNames( aModel->redoNames() );
129 aRedoAction->setEnabled( aCanRedo );
132 void HYDROGUI_Module::onOperation()
134 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
135 int anId = actionId( anAction );
137 startOperation( anId );
140 bool HYDROGUI_Module::onUndo( int theNumActions )
142 QApplication::setOverrideCursor( Qt::WaitCursor );
144 HYDROGUI_DataModel* aModel = getDataModel();
147 while( theNumActions > 0 )
149 if( !aModel->undo() )
156 update( UF_All | UF_GV_Init | UF_GV_Forced );
158 QApplication::restoreOverrideCursor();
162 bool HYDROGUI_Module::onRedo( int theNumActions )
164 QApplication::setOverrideCursor( Qt::WaitCursor );
166 HYDROGUI_DataModel* aModel = getDataModel();
169 while( theNumActions > 0 )
171 if( !aModel->redo() )
178 update( UF_All | UF_GV_Init | UF_GV_Forced );
180 QApplication::restoreOverrideCursor();
184 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
186 LightApp_Operation* anOp = 0;
187 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
191 anOp = new HYDROGUI_ImportImageOp( aModule );
194 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse );
197 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut );
202 anOp = LightApp_Module::createOperation( theId );