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_CalculationOp.h"
27 #include "HYDROGUI_DataModel.h"
28 #include "HYDROGUI_DeleteOp.h"
29 #include "HYDROGUI_ExportImageOp.h"
30 #include "HYDROGUI_ImportImageOp.h"
31 #include "HYDROGUI_ImportBathymetryOp.h"
32 #include "HYDROGUI_ImmersibleZoneOp.h"
33 #include "HYDROGUI_Module.h"
34 #include "HYDROGUI_ObserveImageOp.h"
35 #include "HYDROGUI_PolylineOp.h"
36 #include "HYDROGUI_RemoveImageRefsOp.h"
37 #include "HYDROGUI_ShowHideOp.h"
38 #include "HYDROData_SplitToZonesTool.h"
39 #include "HYDROGUI_TwoImagesOp.h"
40 #include "HYDROGUI_UpdateFlags.h"
41 #include "HYDROGUI_UpdateImageOp.h"
42 #include "HYDROGUI_VisualStateOp.h"
43 #include "HYDROGUI_ImmersibleZoneOp.h"
44 #include "HYDROGUI_ImportGeomObjectOp.h"
45 #include "HYDROGUI_ImportObstacleFromFileOp.h"
46 #include "HYDROGUI_ExportCalculationOp.h"
47 #include "HYDROGUI_SetColorOp.h"
49 #include "HYDROData_Document.h"
50 #include "HYDROData_Obstacle.h"
52 #include <GeometryGUI.h>
53 #include <GeometryGUI_Operations.h>
56 #include <SalomeApp_Study.h>
58 #include <LightApp_Application.h>
60 #include <CAM_Application.h>
62 #include <QtxListAction.h>
64 #include <SUIT_Desktop.h>
65 #include <SUIT_ResourceMgr.h>
66 #include <SUIT_Session.h>
69 #include <QApplication>
71 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
72 const int theKey, const bool isToggle, const QString& theSlot )
74 QString aSlot = theSlot;
76 aSlot = SLOT( onOperation() );
77 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
78 std::string anImg = theImg.toStdString();
79 QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
80 std::string aMenu = ( "MEN_" + theSuffix ).toStdString();
81 std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
82 std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
83 std::string aSlotStr = aSlot.toStdString();
84 return LightApp_Module::createAction( theId, tr( aDesktop.c_str() ), aPixmap,
85 tr( aMenu.c_str() ), tr( aToolbar.c_str() ),
86 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
89 void HYDROGUI_Module::createActions()
91 createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
92 createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
94 createAction( CopyId, "COPY", "", Qt::CTRL + Qt::Key_C );
95 createAction( PasteId, "PASTE", "", Qt::CTRL + Qt::Key_V );
97 createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
98 createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE" );
99 createAction( ObserveImageId, "OBSERVE_IMAGE" );
100 createAction( ExportImageId, "EXPORT_IMAGE" );
101 createAction( UpdateImageId, "UPDATE_IMAGE" );
102 createAction( RemoveImageRefsId, "REMOVE_IMAGE_REFERENCE" );
104 createAction( CreatePolylineId, "CREATE_POLYLINE" );
105 createAction( EditPolylineId, "EDIT_POLYLINE" );
107 createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::Key_B );
109 createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE" );
110 createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE" );
112 createAction( ImportObstacleFromFileId, "IMPORT_OBSTACLE_FROM_FILE" );
113 createAction( ImportGeomObjectId, "IMPORT_GEOM_OBJECT" );
114 createAction( CreateBoxId, "CREATE_BOX" );
115 createAction( CreateCylinderId, "CREATE_CYLINDER" );
117 createAction( CreateCalculationId, "CREATE_CALCULATION" );
118 createAction( EditCalculationId, "EDIT_CALCULATION" );
119 createAction( ExportCalculationId, "EXPORT_CALCULATION" );
121 createAction( FuseImagesId, "FUSE_IMAGES" );
122 createAction( EditFusedImageId, "EDIT_FUSED_IMAGE" );
124 createAction( CutImagesId, "CUT_IMAGES" );
125 createAction( EditCutImageId, "EDIT_CUT_IMAGE" );
127 createAction( SplitImageId, "SPLIT_IMAGE" );
128 createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE" );
130 createAction( DeleteId, "DELETE", "", Qt::Key_Delete, false,
131 SLOT( onDelete() ) );
133 createAction( SetColorId, "COLOR" );
135 createAction( ShowId, "SHOW" );
136 createAction( ShowOnlyId, "SHOW_ONLY" );
137 createAction( ShowAllId, "SHOW_ALL" );
138 createAction( HideId, "HIDE" );
139 createAction( HideAllId, "HIDE_ALL" );
142 void HYDROGUI_Module::createMenus()
144 int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
145 int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
146 createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
147 createMenu( separator(), aFileMenu, -1, aCustomPos );
149 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
150 createMenu( UndoId, anEditMenu );
151 createMenu( RedoId, anEditMenu );
152 createMenu( separator(), anEditMenu );
153 createMenu( CopyId, anEditMenu );
154 createMenu( PasteId, anEditMenu );
156 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
157 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
158 createMenu( ImportImageId, aHydroId, -1, -1 );
159 createMenu( ImportBathymetryId, aHydroId, -1, -1 );
160 createMenu( CreatePolylineId, aHydroId, -1, -1 );
161 createMenu( CreateImmersibleZoneId, aHydroId, -1, -1 );
163 int aNewObstacleId = createMenu( tr( "MEN_OBSTACLE" ), aHydroId, -1 );
164 createMenu( ImportObstacleFromFileId, aNewObstacleId, -1, -1 );
165 createMenu( CreateBoxId, aNewObstacleId, -1, -1 );
166 createMenu( CreateCylinderId, aNewObstacleId, -1, -1 );
168 createMenu( CreateCalculationId, aHydroId, -1, -1 );
169 createMenu( separator(), aHydroId );
170 createMenu( FuseImagesId, aHydroId, -1, -1 );
171 createMenu( CutImagesId, aHydroId, -1, -1 );
172 createMenu( SplitImageId, aHydroId, -1, -1 );
173 createMenu( separator(), aHydroId );
176 void HYDROGUI_Module::createPopups()
180 void HYDROGUI_Module::createToolbars()
182 int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
183 createTool( UndoId, aToolBar );
184 createTool( RedoId, aToolBar );
187 void HYDROGUI_Module::createUndoRedoActions()
189 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
191 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
192 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
193 Qt::CTRL + Qt::Key_Z, application()->desktop() );
195 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
196 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
197 Qt::CTRL + Qt::Key_Y, application()->desktop() );
199 registerAction( UndoId, anEditUndo );
200 registerAction( RedoId, anEditRedo );
202 anEditUndo->setComment( tr( "STB_UNDO" ) );
203 anEditRedo->setComment( tr( "STB_REDO" ) );
205 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
206 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
209 void HYDROGUI_Module::updateUndoRedoControls()
211 HYDROGUI_DataModel* aModel = getDataModel();
213 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
214 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
216 bool aCanUndo = aModel->canUndo();
217 bool aCanRedo = aModel->canRedo();
220 aUndoAction->addNames( aModel->undoNames() );
221 aUndoAction->setEnabled( aCanUndo );
224 aRedoAction->addNames( aModel->redoNames() );
225 aRedoAction->setEnabled( aCanRedo );
228 void HYDROGUI_Module::onOperation()
230 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
231 int anId = actionId( anAction );
233 startOperation( anId );
236 void HYDROGUI_Module::onDelete()
238 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
239 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
240 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
241 aPolylineOp->deleteSelected();
243 startOperation( DeleteId );
246 bool HYDROGUI_Module::onUndo( int theNumActions )
248 QApplication::setOverrideCursor( Qt::WaitCursor );
250 HYDROGUI_DataModel* aModel = getDataModel();
253 while( theNumActions > 0 )
255 if( !aModel->undo() )
264 QApplication::restoreOverrideCursor();
268 bool HYDROGUI_Module::onRedo( int theNumActions )
270 QApplication::setOverrideCursor( Qt::WaitCursor );
272 HYDROGUI_DataModel* aModel = getDataModel();
275 while( theNumActions > 0 )
277 if( !aModel->redo() )
286 QApplication::restoreOverrideCursor();
290 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
292 LightApp_Operation* anOp = 0;
293 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
296 case SaveVisualStateId:
297 case LoadVisualStateId:
298 anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
302 anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
305 case EditImportedImageId:
306 anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
309 anOp = new HYDROGUI_ObserveImageOp( aModule );
312 anOp = new HYDROGUI_ExportImageOp( aModule );
315 anOp = new HYDROGUI_UpdateImageOp( aModule );
317 case RemoveImageRefsId:
318 anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
320 case CreatePolylineId:
322 anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
324 case ImportBathymetryId:
325 anOp = new HYDROGUI_ImportBathymetryOp( aModule );
327 case CreateImmersibleZoneId:
328 case EditImmersibleZoneId:
329 anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
331 case CreateCalculationId:
332 case EditCalculationId:
333 anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
335 case ExportCalculationId:
336 anOp = new HYDROGUI_ExportCalculationOp( aModule );
339 case EditFusedImageId:
340 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
344 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
347 case EditSplittedImageId:
348 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId );
350 case ImportObstacleFromFileId:
351 anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule );
353 case ImportCreatedPrimitiveId:
354 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportCreated );
356 case ImportGeomObjectId:
357 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelected );
360 application()->activateOperation( "Geometry", GEOMOp::OpBox );
362 case CreateCylinderId:
363 application()->activateOperation( "Geometry", GEOMOp::OpCylinder );
366 anOp = new HYDROGUI_DeleteOp( aModule );
369 anOp = new HYDROGUI_SetColorOp( aModule );
376 anOp = new HYDROGUI_ShowHideOp( aModule, theId );
381 anOp = LightApp_Module::createOperation( theId );
386 bool HYDROGUI_Module::reusableOperation( const int id )
388 if ( id == ImportGeomObjectId ) {
392 return LightApp_Module::reusableOperation( id );
396 * Called when the operation perfomed by another module is finished.
397 * \param theModuleName the name of the module which perfomed the operation
398 * \param theOperationName the operation name
399 * \param theEntryList the list of the created objects entries
401 void HYDROGUI_Module::onExternalOperationFinished( const QString& theModuleName,
402 const QString& theOperationName,
403 const QStringList& theEntryList )
405 // Process "Geometry" module operations with non-empty list of created objects only
406 if ( theModuleName != "Geometry" || theEntryList.isEmpty() ) {
410 // Start import GEOM object operation
411 myGeomObjectsToImport = theEntryList;
412 startOperation( ImportCreatedPrimitiveId );
413 myGeomObjectsToImport.clear();
417 * Returns the list of entries of GEOM objects to be imported.
419 QStringList HYDROGUI_Module::GetGeomObjectsToImport()
421 return myGeomObjectsToImport;