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_Poly3DOp.h"
37 #include "HYDROGUI_ProfileOp.h"
38 #include "HYDROGUI_RemoveImageRefsOp.h"
39 #include "HYDROGUI_ShowHideOp.h"
40 #include "HYDROGUI_StreamOp.h"
41 #include "HYDROGUI_TwoImagesOp.h"
42 #include "HYDROGUI_UpdateFlags.h"
43 #include "HYDROGUI_UpdateImageOp.h"
44 #include "HYDROGUI_VisualStateOp.h"
45 #include "HYDROGUI_ImmersibleZoneOp.h"
46 #include "HYDROGUI_ImportGeomObjectOp.h"
47 #include "HYDROGUI_ImportObstacleFromFileOp.h"
48 #include "HYDROGUI_ExportCalculationOp.h"
49 #include "HYDROGUI_ImportProfilesOp.h"
50 #include "HYDROGUI_GeoreferencementOp.h"
51 #include "HYDROGUI_SetColorOp.h"
53 #include <HYDROData_Document.h>
54 #include <HYDROData_Obstacle.h>
55 #include <HYDROData_SplitToZonesTool.h>
57 #include <GeometryGUI.h>
58 #include <GeometryGUI_Operations.h>
61 #include <SalomeApp_Study.h>
63 #include <LightApp_Application.h>
65 #include <CAM_Application.h>
67 #include <QtxListAction.h>
69 #include <SUIT_Desktop.h>
70 #include <SUIT_ResourceMgr.h>
71 #include <SUIT_Session.h>
74 #include <QApplication>
76 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
77 const int theKey, const bool isToggle, const QString& theSlot )
79 QString aSlot = theSlot;
81 aSlot = SLOT( onOperation() );
82 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
83 std::string anImg = theImg.toStdString();
84 QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
85 std::string aMenu = ( "MEN_" + theSuffix ).toStdString();
86 std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
87 std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
88 std::string aSlotStr = aSlot.toStdString();
89 return LightApp_Module::createAction( theId, tr( aDesktop.c_str() ), aPixmap,
90 tr( aMenu.c_str() ), tr( aToolbar.c_str() ),
91 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
94 void HYDROGUI_Module::createActions()
96 createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
97 createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
99 createAction( CopyId, "COPY", "", Qt::CTRL + Qt::Key_C );
100 createAction( PasteId, "PASTE", "", Qt::CTRL + Qt::Key_V );
102 createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
103 createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE" );
104 createAction( ObserveImageId, "OBSERVE_IMAGE" );
105 createAction( ExportImageId, "EXPORT_IMAGE" );
106 createAction( UpdateImageId, "UPDATE_IMAGE" );
107 createAction( RemoveImageRefsId, "REMOVE_IMAGE_REFERENCE" );
109 createAction( CreatePolylineId, "CREATE_POLYLINE" );
110 createAction( EditPolylineId, "EDIT_POLYLINE" );
112 createAction( CreatePolyline3DId, "CREATE_POLYLINE_3D" );
113 createAction( EditPolyline3DId, "EDIT_POLYLINE_3D" );
115 createAction( CreateProfileId, "CREATE_PROFILE" );
116 createAction( ImportProfilesId, "IMPORT_PROFILES" );
117 createAction( EditProfileId, "EDIT_PROFILE" );
118 createAction( AllGeoreferencementId, "GEOREFERENCEMENT" );
119 createAction( SelectedGeoreferencementId, "GEOREFERENCEMENT" );
121 createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::Key_B );
123 createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE" );
124 createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE" );
126 createAction( CreateStreamId, "CREATE_STREAM" );
127 createAction( EditStreamId, "EDIT_STREAM" );
129 createAction( ImportObstacleFromFileId, "IMPORT_OBSTACLE_FROM_FILE" );
130 createAction( ImportGeomObjectId, "IMPORT_GEOM_OBJECT" );
131 createAction( CreateBoxId, "CREATE_BOX" );
132 createAction( CreateCylinderId, "CREATE_CYLINDER" );
134 createAction( CreateCalculationId, "CREATE_CALCULATION" );
135 createAction( EditCalculationId, "EDIT_CALCULATION" );
136 createAction( ExportCalculationId, "EXPORT_CALCULATION" );
138 createAction( FuseImagesId, "FUSE_IMAGES" );
139 createAction( EditFusedImageId, "EDIT_FUSED_IMAGE" );
141 createAction( CutImagesId, "CUT_IMAGES" );
142 createAction( EditCutImageId, "EDIT_CUT_IMAGE" );
144 createAction( SplitImageId, "SPLIT_IMAGE" );
145 createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE" );
147 createAction( DeleteId, "DELETE", "", Qt::Key_Delete, false,
148 SLOT( onDelete() ) );
150 createAction( SetColorId, "COLOR" );
152 createAction( ShowId, "SHOW" );
153 createAction( ShowOnlyId, "SHOW_ONLY" );
154 createAction( ShowAllId, "SHOW_ALL" );
155 createAction( HideId, "HIDE" );
156 createAction( HideAllId, "HIDE_ALL" );
159 void HYDROGUI_Module::createMenus()
161 int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
162 int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
163 createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
164 createMenu( separator(), aFileMenu, -1, aCustomPos );
166 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
167 createMenu( UndoId, anEditMenu );
168 createMenu( RedoId, anEditMenu );
169 createMenu( separator(), anEditMenu );
170 createMenu( CopyId, anEditMenu );
171 createMenu( PasteId, anEditMenu );
173 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
174 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
175 createMenu( ImportImageId, aHydroId, -1, -1 );
176 createMenu( ImportBathymetryId, aHydroId, -1, -1 );
177 createMenu( CreatePolylineId, aHydroId, -1, -1 );
178 createMenu( CreatePolyline3DId, aHydroId, -1, -1 );
180 int aNewProfileId = createMenu( tr( "MEN_PROFILE" ), aHydroId, -1 );
181 createMenu( CreateProfileId, aNewProfileId, -1, -1 );
182 createMenu( ImportProfilesId, aNewProfileId, -1, -1 );
183 createMenu( AllGeoreferencementId, aNewProfileId, -1, -1 );
185 createMenu( CreateImmersibleZoneId, aHydroId, -1, -1 );
186 createMenu( CreateStreamId, aHydroId, -1, -1 );
188 int aNewObstacleId = createMenu( tr( "MEN_OBSTACLE" ), aHydroId, -1 );
189 createMenu( ImportObstacleFromFileId, aNewObstacleId, -1, -1 );
190 createMenu( CreateBoxId, aNewObstacleId, -1, -1 );
191 createMenu( CreateCylinderId, aNewObstacleId, -1, -1 );
193 createMenu( CreateCalculationId, aHydroId, -1, -1 );
194 createMenu( separator(), aHydroId );
195 createMenu( FuseImagesId, aHydroId, -1, -1 );
196 createMenu( CutImagesId, aHydroId, -1, -1 );
197 createMenu( SplitImageId, aHydroId, -1, -1 );
198 createMenu( separator(), aHydroId );
201 void HYDROGUI_Module::createPopups()
205 void HYDROGUI_Module::createToolbars()
207 int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
208 createTool( UndoId, aToolBar );
209 createTool( RedoId, aToolBar );
212 void HYDROGUI_Module::createUndoRedoActions()
214 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
216 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
217 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
218 Qt::CTRL + Qt::Key_Z, application()->desktop() );
220 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
221 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
222 Qt::CTRL + Qt::Key_Y, application()->desktop() );
224 registerAction( UndoId, anEditUndo );
225 registerAction( RedoId, anEditRedo );
227 anEditUndo->setComment( tr( "STB_UNDO" ) );
228 anEditRedo->setComment( tr( "STB_REDO" ) );
230 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
231 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
234 void HYDROGUI_Module::updateUndoRedoControls()
236 HYDROGUI_DataModel* aModel = getDataModel();
238 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
239 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
241 bool aCanUndo = aModel->canUndo();
242 bool aCanRedo = aModel->canRedo();
245 aUndoAction->addNames( aModel->undoNames() );
246 aUndoAction->setEnabled( aCanUndo );
249 aRedoAction->addNames( aModel->redoNames() );
250 aRedoAction->setEnabled( aCanRedo );
253 void HYDROGUI_Module::onOperation()
255 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
256 int anId = actionId( anAction );
258 startOperation( anId );
261 void HYDROGUI_Module::onDelete()
263 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
264 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
265 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
266 aPolylineOp->deleteSelected();
268 startOperation( DeleteId );
271 bool HYDROGUI_Module::onUndo( int theNumActions )
273 QApplication::setOverrideCursor( Qt::WaitCursor );
275 HYDROGUI_DataModel* aModel = getDataModel();
278 while( theNumActions > 0 )
280 if( !aModel->undo() )
289 QApplication::restoreOverrideCursor();
293 bool HYDROGUI_Module::onRedo( int theNumActions )
295 QApplication::setOverrideCursor( Qt::WaitCursor );
297 HYDROGUI_DataModel* aModel = getDataModel();
300 while( theNumActions > 0 )
302 if( !aModel->redo() )
311 QApplication::restoreOverrideCursor();
315 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
317 LightApp_Operation* anOp = 0;
318 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
321 case SaveVisualStateId:
322 case LoadVisualStateId:
323 anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
327 anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
330 case EditImportedImageId:
331 anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
334 anOp = new HYDROGUI_ObserveImageOp( aModule );
337 anOp = new HYDROGUI_ExportImageOp( aModule );
340 anOp = new HYDROGUI_UpdateImageOp( aModule );
342 case RemoveImageRefsId:
343 anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
345 case CreatePolyline3DId:
346 case EditPolyline3DId:
347 anOp = new HYDROGUI_Poly3DOp( aModule, theId == EditPolyline3DId );
349 case CreatePolylineId:
351 anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
353 case CreateProfileId:
355 anOp = new HYDROGUI_ProfileOp( aModule, theId == EditProfileId );
357 case ImportProfilesId:
358 anOp = new HYDROGUI_ImportProfilesOp( aModule ) ;
360 case AllGeoreferencementId:
361 anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::All ) ;
363 case SelectedGeoreferencementId:
364 anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::Selected ) ;
366 case ImportBathymetryId:
367 anOp = new HYDROGUI_ImportBathymetryOp( aModule );
369 case CreateImmersibleZoneId:
370 case EditImmersibleZoneId:
371 anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
375 anOp = new HYDROGUI_StreamOp( aModule, theId == EditStreamId );
377 case CreateCalculationId:
378 case EditCalculationId:
379 anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
381 case ExportCalculationId:
382 anOp = new HYDROGUI_ExportCalculationOp( aModule );
385 case EditFusedImageId:
386 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
390 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
393 case EditSplittedImageId:
394 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId );
396 case ImportObstacleFromFileId:
397 anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule );
399 case ImportCreatedPrimitiveId:
400 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportCreated );
402 case ImportGeomObjectId:
403 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelected );
406 application()->activateOperation( "Geometry", GEOMOp::OpBox );
408 case CreateCylinderId:
409 application()->activateOperation( "Geometry", GEOMOp::OpCylinder );
412 anOp = new HYDROGUI_DeleteOp( aModule );
415 anOp = new HYDROGUI_SetColorOp( aModule );
422 anOp = new HYDROGUI_ShowHideOp( aModule, theId );
427 anOp = LightApp_Module::createOperation( theId );
432 bool HYDROGUI_Module::reusableOperation( const int id )
434 if ( id == ImportGeomObjectId ) {
438 return LightApp_Module::reusableOperation( id );
442 * Called when the operation perfomed by another module is finished.
443 * \param theModuleName the name of the module which perfomed the operation
444 * \param theOperationName the operation name
445 * \param theEntryList the list of the created objects entries
447 void HYDROGUI_Module::onExternalOperationFinished( const QString& theModuleName,
448 const QString& theOperationName,
449 const QStringList& theEntryList )
451 // Process "Geometry" module operations with non-empty list of created objects only
452 if ( theModuleName != "Geometry" || theEntryList.isEmpty() ) {
456 // Start import GEOM object operation
457 myGeomObjectsToImport = theEntryList;
458 startOperation( ImportCreatedPrimitiveId );
459 myGeomObjectsToImport.clear();
463 * Returns the list of entries of GEOM objects to be imported.
465 QStringList HYDROGUI_Module::GetGeomObjectsToImport()
467 return myGeomObjectsToImport;