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_Module.h"
30 #include "HYDROGUI_ObserveImageOp.h"
31 #include "HYDROGUI_PolylineOp.h"
32 #include "HYDROGUI_ShowHideOp.h"
33 #include "HYDROGUI_TwoImagesOp.h"
34 #include "HYDROGUI_UpdateFlags.h"
35 #include "HYDROGUI_VisualStateOp.h"
37 #include <CAM_Application.h>
39 #include <QtxListAction.h>
41 #include <SUIT_Desktop.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Session.h>
46 #include <QApplication>
48 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
49 const int theKey, const bool isToggle, const QString& theSlot )
51 QString aSlot = theSlot;
53 aSlot = SLOT( onOperation() );
54 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
55 std::string anImg = theImg.toStdString();
56 QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
57 std::string aMenu = ( "MEN_" + theSuffix ).toStdString();
58 std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
59 std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
60 std::string aSlotStr = aSlot.toStdString();
61 return LightApp_Module::createAction( theId, tr( aMenu.c_str() ), aPixmap,
62 tr( aDesktop.c_str() ), tr( aToolbar.c_str() ),
63 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
66 void HYDROGUI_Module::createActions()
68 createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
69 createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
71 createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
72 createAction( EditImageId, "EDIT_IMAGE" );
73 createAction( ObserveImageId, "OBSERVE_IMAGE" );
74 createAction( ExportImageId, "EXPORT_IMAGE" );
75 createAction( CreatePolylineId, "CREATE_POLYLINE" );
76 createAction( EditPolylineId, "EDIT_POLYLINE" );
78 createAction( FuseId, "FUSE_IMAGES" );
79 createAction( CutId, "CUT_IMAGES" );
81 createAction( DeleteId, "DELETE", "", Qt::Key_Delete );
83 createAction( ShowId, "SHOW" );
84 createAction( ShowOnlyId, "SHOW_ONLY" );
85 createAction( ShowAllId, "SHOW_ALL" );
86 createAction( HideId, "HIDE" );
87 createAction( HideAllId, "HIDE_ALL" );
90 void HYDROGUI_Module::createMenus()
92 int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
93 int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
94 createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
95 createMenu( separator(), aFileMenu, -1, aCustomPos );
97 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
98 createMenu( UndoId, anEditMenu );
99 createMenu( RedoId, anEditMenu );
101 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
102 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
103 createMenu( ImportImageId, aHydroId, -1, -1 );
104 createMenu( CreatePolylineId, aHydroId, -1, -1 );
105 createMenu( FuseId, aHydroId, -1, -1 );
106 createMenu( CutId, aHydroId, -1, -1 );
109 void HYDROGUI_Module::createPopups()
113 void HYDROGUI_Module::createToolbars()
115 int aToolBar = createTool( tr( "HYDRO_TOOLBAR" ) );
116 createTool( UndoId, aToolBar );
117 createTool( RedoId, aToolBar );
120 void HYDROGUI_Module::createUndoRedoActions()
122 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
124 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
125 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
126 Qt::CTRL + Qt::Key_Z, application()->desktop() );
128 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
129 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
130 Qt::CTRL + Qt::Key_Y, application()->desktop() );
132 registerAction( UndoId, anEditUndo );
133 registerAction( RedoId, anEditRedo );
135 anEditUndo->setComment( tr( "STB_UNDO" ) );
136 anEditRedo->setComment( tr( "STB_REDO" ) );
138 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
139 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
142 void HYDROGUI_Module::updateUndoRedoControls()
144 HYDROGUI_DataModel* aModel = getDataModel();
146 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
147 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
149 bool aCanUndo = aModel->canUndo();
150 bool aCanRedo = aModel->canRedo();
153 aUndoAction->addNames( aModel->undoNames() );
154 aUndoAction->setEnabled( aCanUndo );
157 aRedoAction->addNames( aModel->redoNames() );
158 aRedoAction->setEnabled( aCanRedo );
161 void HYDROGUI_Module::onOperation()
163 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
164 int anId = actionId( anAction );
166 startOperation( anId );
169 bool HYDROGUI_Module::onUndo( int theNumActions )
171 QApplication::setOverrideCursor( Qt::WaitCursor );
173 HYDROGUI_DataModel* aModel = getDataModel();
176 while( theNumActions > 0 )
178 if( !aModel->undo() )
187 QApplication::restoreOverrideCursor();
191 bool HYDROGUI_Module::onRedo( int theNumActions )
193 QApplication::setOverrideCursor( Qt::WaitCursor );
195 HYDROGUI_DataModel* aModel = getDataModel();
198 while( theNumActions > 0 )
200 if( !aModel->redo() )
209 QApplication::restoreOverrideCursor();
213 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
215 LightApp_Operation* anOp = 0;
216 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
219 case SaveVisualStateId:
220 case LoadVisualStateId:
221 anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
225 anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImageId );
228 anOp = new HYDROGUI_ObserveImageOp( aModule );
231 anOp = new HYDROGUI_ExportImageOp( aModule );
233 case CreatePolylineId:
235 anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
238 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse );
241 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut );
244 anOp = new HYDROGUI_DeleteOp( aModule );
251 anOp = new HYDROGUI_ShowHideOp( aModule, theId );
256 anOp = LightApp_Module::createOperation( theId );