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_ProfileOp.h"
37 #include "HYDROGUI_RemoveImageRefsOp.h"
38 #include "HYDROGUI_ShowHideOp.h"
39 #include "HYDROData_SplitToZonesTool.h"
40 #include "HYDROGUI_TwoImagesOp.h"
41 #include "HYDROGUI_UpdateFlags.h"
42 #include "HYDROGUI_UpdateImageOp.h"
43 #include "HYDROGUI_VisualStateOp.h"
44 #include "HYDROGUI_ImmersibleZoneOp.h"
45 #include "HYDROGUI_ImportGeomObjectOp.h"
46 #include "HYDROGUI_ImportObstacleFromFileOp.h"
47 #include "HYDROGUI_ExportCalculationOp.h"
48 #include "HYDROGUI_ImportProfilesOp.h"
49 #include "HYDROGUI_SetColorOp.h"
51 #include "HYDROData_Document.h"
52 #include "HYDROData_Obstacle.h"
54 #include <GeometryGUI.h>
55 #include <GeometryGUI_Operations.h>
58 #include <SalomeApp_Study.h>
60 #include <LightApp_Application.h>
62 #include <CAM_Application.h>
64 #include <QtxListAction.h>
66 #include <SUIT_Desktop.h>
67 #include <SUIT_ResourceMgr.h>
68 #include <SUIT_Session.h>
71 #include <QApplication>
73 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
74 const int theKey, const bool isToggle, const QString& theSlot )
76 QString aSlot = theSlot;
78 aSlot = SLOT( onOperation() );
79 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
80 std::string anImg = theImg.toStdString();
81 QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
82 std::string aMenu = ( "MEN_" + theSuffix ).toStdString();
83 std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
84 std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
85 std::string aSlotStr = aSlot.toStdString();
86 return LightApp_Module::createAction( theId, tr( aDesktop.c_str() ), aPixmap,
87 tr( aMenu.c_str() ), tr( aToolbar.c_str() ),
88 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
91 void HYDROGUI_Module::createActions()
93 createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
94 createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
96 createAction( CopyId, "COPY", "", Qt::CTRL + Qt::Key_C );
97 createAction( PasteId, "PASTE", "", Qt::CTRL + Qt::Key_V );
99 createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
100 createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE" );
101 createAction( ObserveImageId, "OBSERVE_IMAGE" );
102 createAction( ExportImageId, "EXPORT_IMAGE" );
103 createAction( UpdateImageId, "UPDATE_IMAGE" );
104 createAction( RemoveImageRefsId, "REMOVE_IMAGE_REFERENCE" );
106 createAction( CreatePolylineId, "CREATE_POLYLINE" );
107 createAction( EditPolylineId, "EDIT_POLYLINE" );
109 createAction( CreateProfileId, "CREATE_PROFILE" );
110 createAction( ImportProfilesId, "IMPORT_PROFILES" );
111 createAction( EditProfileId, "EDIT_PROFILE" );
113 createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::Key_B );
115 createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE" );
116 createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE" );
118 createAction( ImportObstacleFromFileId, "IMPORT_OBSTACLE_FROM_FILE" );
119 createAction( ImportGeomObjectId, "IMPORT_GEOM_OBJECT" );
120 createAction( CreateBoxId, "CREATE_BOX" );
121 createAction( CreateCylinderId, "CREATE_CYLINDER" );
123 createAction( CreateCalculationId, "CREATE_CALCULATION" );
124 createAction( EditCalculationId, "EDIT_CALCULATION" );
125 createAction( ExportCalculationId, "EXPORT_CALCULATION" );
127 createAction( FuseImagesId, "FUSE_IMAGES" );
128 createAction( EditFusedImageId, "EDIT_FUSED_IMAGE" );
130 createAction( CutImagesId, "CUT_IMAGES" );
131 createAction( EditCutImageId, "EDIT_CUT_IMAGE" );
133 createAction( SplitImageId, "SPLIT_IMAGE" );
134 createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE" );
136 createAction( DeleteId, "DELETE", "", Qt::Key_Delete, false,
137 SLOT( onDelete() ) );
139 createAction( SetColorId, "COLOR" );
141 createAction( ShowId, "SHOW" );
142 createAction( ShowOnlyId, "SHOW_ONLY" );
143 createAction( ShowAllId, "SHOW_ALL" );
144 createAction( HideId, "HIDE" );
145 createAction( HideAllId, "HIDE_ALL" );
148 void HYDROGUI_Module::createMenus()
150 int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
151 int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
152 createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
153 createMenu( separator(), aFileMenu, -1, aCustomPos );
155 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
156 createMenu( UndoId, anEditMenu );
157 createMenu( RedoId, anEditMenu );
158 createMenu( separator(), anEditMenu );
159 createMenu( CopyId, anEditMenu );
160 createMenu( PasteId, anEditMenu );
162 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
163 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
164 createMenu( ImportImageId, aHydroId, -1, -1 );
165 createMenu( ImportBathymetryId, aHydroId, -1, -1 );
166 createMenu( CreatePolylineId, aHydroId, -1, -1 );
168 int aNewProfileId = createMenu( tr( "MEN_PROFILE" ), aHydroId, -1 );
169 createMenu( CreateProfileId, aNewProfileId, -1, -1 );
170 createMenu( ImportProfilesId, aNewProfileId, -1, -1 );
172 createMenu( CreateImmersibleZoneId, aHydroId, -1, -1 );
174 int aNewObstacleId = createMenu( tr( "MEN_OBSTACLE" ), aHydroId, -1 );
175 createMenu( ImportObstacleFromFileId, aNewObstacleId, -1, -1 );
176 createMenu( CreateBoxId, aNewObstacleId, -1, -1 );
177 createMenu( CreateCylinderId, aNewObstacleId, -1, -1 );
179 createMenu( CreateCalculationId, aHydroId, -1, -1 );
180 createMenu( separator(), aHydroId );
181 createMenu( FuseImagesId, aHydroId, -1, -1 );
182 createMenu( CutImagesId, aHydroId, -1, -1 );
183 createMenu( SplitImageId, aHydroId, -1, -1 );
184 createMenu( separator(), aHydroId );
187 void HYDROGUI_Module::createPopups()
191 void HYDROGUI_Module::createToolbars()
193 int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
194 createTool( UndoId, aToolBar );
195 createTool( RedoId, aToolBar );
198 void HYDROGUI_Module::createUndoRedoActions()
200 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
202 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
203 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
204 Qt::CTRL + Qt::Key_Z, application()->desktop() );
206 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
207 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
208 Qt::CTRL + Qt::Key_Y, application()->desktop() );
210 registerAction( UndoId, anEditUndo );
211 registerAction( RedoId, anEditRedo );
213 anEditUndo->setComment( tr( "STB_UNDO" ) );
214 anEditRedo->setComment( tr( "STB_REDO" ) );
216 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
217 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
220 void HYDROGUI_Module::updateUndoRedoControls()
222 HYDROGUI_DataModel* aModel = getDataModel();
224 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
225 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
227 bool aCanUndo = aModel->canUndo();
228 bool aCanRedo = aModel->canRedo();
231 aUndoAction->addNames( aModel->undoNames() );
232 aUndoAction->setEnabled( aCanUndo );
235 aRedoAction->addNames( aModel->redoNames() );
236 aRedoAction->setEnabled( aCanRedo );
239 void HYDROGUI_Module::onOperation()
241 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
242 int anId = actionId( anAction );
244 startOperation( anId );
247 void HYDROGUI_Module::onDelete()
249 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
250 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
251 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
252 aPolylineOp->deleteSelected();
254 startOperation( DeleteId );
257 bool HYDROGUI_Module::onUndo( int theNumActions )
259 QApplication::setOverrideCursor( Qt::WaitCursor );
261 HYDROGUI_DataModel* aModel = getDataModel();
264 while( theNumActions > 0 )
266 if( !aModel->undo() )
275 QApplication::restoreOverrideCursor();
279 bool HYDROGUI_Module::onRedo( int theNumActions )
281 QApplication::setOverrideCursor( Qt::WaitCursor );
283 HYDROGUI_DataModel* aModel = getDataModel();
286 while( theNumActions > 0 )
288 if( !aModel->redo() )
297 QApplication::restoreOverrideCursor();
301 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
303 LightApp_Operation* anOp = 0;
304 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
307 case SaveVisualStateId:
308 case LoadVisualStateId:
309 anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
313 anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
316 case EditImportedImageId:
317 anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
320 anOp = new HYDROGUI_ObserveImageOp( aModule );
323 anOp = new HYDROGUI_ExportImageOp( aModule );
326 anOp = new HYDROGUI_UpdateImageOp( aModule );
328 case RemoveImageRefsId:
329 anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
331 case CreatePolylineId:
333 anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
335 case CreateProfileId:
337 anOp = new HYDROGUI_ProfileOp( aModule, theId == EditProfileId );
339 case ImportProfilesId:
340 anOp = new HYDROGUI_ImportProfilesOp( aModule ) ;
342 case ImportBathymetryId:
343 anOp = new HYDROGUI_ImportBathymetryOp( aModule );
345 case CreateImmersibleZoneId:
346 case EditImmersibleZoneId:
347 anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
349 case CreateCalculationId:
350 case EditCalculationId:
351 anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
353 case ExportCalculationId:
354 anOp = new HYDROGUI_ExportCalculationOp( aModule );
357 case EditFusedImageId:
358 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
362 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
365 case EditSplittedImageId:
366 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId );
368 case ImportObstacleFromFileId:
369 anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule );
371 case ImportCreatedPrimitiveId:
372 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportCreated );
374 case ImportGeomObjectId:
375 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelected );
378 application()->activateOperation( "Geometry", GEOMOp::OpBox );
380 case CreateCylinderId:
381 application()->activateOperation( "Geometry", GEOMOp::OpCylinder );
384 anOp = new HYDROGUI_DeleteOp( aModule );
387 anOp = new HYDROGUI_SetColorOp( aModule );
394 anOp = new HYDROGUI_ShowHideOp( aModule, theId );
399 anOp = LightApp_Module::createOperation( theId );
404 bool HYDROGUI_Module::reusableOperation( const int id )
406 if ( id == ImportGeomObjectId ) {
410 return LightApp_Module::reusableOperation( id );
414 * Called when the operation perfomed by another module is finished.
415 * \param theModuleName the name of the module which perfomed the operation
416 * \param theOperationName the operation name
417 * \param theEntryList the list of the created objects entries
419 void HYDROGUI_Module::onExternalOperationFinished( const QString& theModuleName,
420 const QString& theOperationName,
421 const QStringList& theEntryList )
423 // Process "Geometry" module operations with non-empty list of created objects only
424 if ( theModuleName != "Geometry" || theEntryList.isEmpty() ) {
428 // Start import GEOM object operation
429 myGeomObjectsToImport = theEntryList;
430 startOperation( ImportCreatedPrimitiveId );
431 myGeomObjectsToImport.clear();
435 * Returns the list of entries of GEOM objects to be imported.
437 QStringList HYDROGUI_Module::GetGeomObjectsToImport()
439 return myGeomObjectsToImport;