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 );
132 createAction( SetColorId, "COLOR" );
134 createAction( ShowId, "SHOW" );
135 createAction( ShowOnlyId, "SHOW_ONLY" );
136 createAction( ShowAllId, "SHOW_ALL" );
137 createAction( HideId, "HIDE" );
138 createAction( HideAllId, "HIDE_ALL" );
141 void HYDROGUI_Module::createMenus()
143 int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
144 int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
145 createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
146 createMenu( separator(), aFileMenu, -1, aCustomPos );
148 int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
149 createMenu( UndoId, anEditMenu );
150 createMenu( RedoId, anEditMenu );
151 createMenu( separator(), anEditMenu );
152 createMenu( CopyId, anEditMenu );
153 createMenu( PasteId, anEditMenu );
155 int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
156 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
157 createMenu( ImportImageId, aHydroId, -1, -1 );
158 createMenu( ImportBathymetryId, aHydroId, -1, -1 );
159 createMenu( CreatePolylineId, aHydroId, -1, -1 );
160 createMenu( CreateImmersibleZoneId, aHydroId, -1, -1 );
162 int aNewObstacleId = createMenu( tr( "MEN_OBSTACLE" ), aHydroId, -1 );
163 createMenu( ImportObstacleFromFileId, aNewObstacleId, -1, -1 );
164 createMenu( CreateBoxId, aNewObstacleId, -1, -1 );
165 createMenu( CreateCylinderId, aNewObstacleId, -1, -1 );
167 createMenu( CreateCalculationId, aHydroId, -1, -1 );
168 createMenu( separator(), aHydroId );
169 createMenu( FuseImagesId, aHydroId, -1, -1 );
170 createMenu( CutImagesId, aHydroId, -1, -1 );
171 createMenu( SplitImageId, aHydroId, -1, -1 );
172 createMenu( separator(), aHydroId );
175 void HYDROGUI_Module::createPopups()
179 void HYDROGUI_Module::createToolbars()
181 int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
182 createTool( UndoId, aToolBar );
183 createTool( RedoId, aToolBar );
186 void HYDROGUI_Module::createUndoRedoActions()
188 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
190 QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
191 aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
192 Qt::CTRL + Qt::Key_Z, application()->desktop() );
194 QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
195 aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
196 Qt::CTRL + Qt::Key_Y, application()->desktop() );
198 registerAction( UndoId, anEditUndo );
199 registerAction( RedoId, anEditRedo );
201 anEditUndo->setComment( tr( "STB_UNDO" ) );
202 anEditRedo->setComment( tr( "STB_REDO" ) );
204 connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
205 connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
208 void HYDROGUI_Module::updateUndoRedoControls()
210 HYDROGUI_DataModel* aModel = getDataModel();
212 QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
213 QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
215 bool aCanUndo = aModel->canUndo();
216 bool aCanRedo = aModel->canRedo();
219 aUndoAction->addNames( aModel->undoNames() );
220 aUndoAction->setEnabled( aCanUndo );
223 aRedoAction->addNames( aModel->redoNames() );
224 aRedoAction->setEnabled( aCanRedo );
227 void HYDROGUI_Module::onOperation()
229 const QAction* anAction = dynamic_cast<const QAction*>( sender() );
230 int anId = actionId( anAction );
232 startOperation( anId );
235 bool HYDROGUI_Module::onUndo( int theNumActions )
237 QApplication::setOverrideCursor( Qt::WaitCursor );
239 HYDROGUI_DataModel* aModel = getDataModel();
242 while( theNumActions > 0 )
244 if( !aModel->undo() )
253 QApplication::restoreOverrideCursor();
257 bool HYDROGUI_Module::onRedo( int theNumActions )
259 QApplication::setOverrideCursor( Qt::WaitCursor );
261 HYDROGUI_DataModel* aModel = getDataModel();
264 while( theNumActions > 0 )
266 if( !aModel->redo() )
275 QApplication::restoreOverrideCursor();
279 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
281 LightApp_Operation* anOp = 0;
282 HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
285 case SaveVisualStateId:
286 case LoadVisualStateId:
287 anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
291 anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
294 case EditImportedImageId:
295 anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
298 anOp = new HYDROGUI_ObserveImageOp( aModule );
301 anOp = new HYDROGUI_ExportImageOp( aModule );
304 anOp = new HYDROGUI_UpdateImageOp( aModule );
306 case RemoveImageRefsId:
307 anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
309 case CreatePolylineId:
311 anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
313 case ImportBathymetryId:
314 anOp = new HYDROGUI_ImportBathymetryOp( aModule );
316 case CreateImmersibleZoneId:
317 case EditImmersibleZoneId:
318 anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
320 case CreateCalculationId:
321 case EditCalculationId:
322 anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
324 case ExportCalculationId:
325 anOp = new HYDROGUI_ExportCalculationOp( aModule );
328 case EditFusedImageId:
329 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
333 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
336 case EditSplittedImageId:
337 anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId );
339 case ImportObstacleFromFileId:
340 anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule );
342 case ImportCreatedPrimitiveId:
343 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportCreated );
345 case ImportGeomObjectId:
346 anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelected );
349 application()->activateOperation( "Geometry", GEOMOp::OpBox );
351 case CreateCylinderId:
352 application()->activateOperation( "Geometry", GEOMOp::OpCylinder );
355 anOp = new HYDROGUI_DeleteOp( aModule );
358 anOp = new HYDROGUI_SetColorOp( aModule );
365 anOp = new HYDROGUI_ShowHideOp( aModule, theId );
370 anOp = LightApp_Module::createOperation( theId );
375 bool HYDROGUI_Module::reusableOperation( const int id )
377 if ( id == ImportGeomObjectId ) {
381 return LightApp_Module::reusableOperation( id );
385 * Called when the operation perfomed by another module is finished.
386 * \param theModuleName the name of the module which perfomed the operation
387 * \param theOperationName the operation name
388 * \param theEntryList the list of the created objects entries
390 void HYDROGUI_Module::onExternalOperationFinished( const QString& theModuleName,
391 const QString& theOperationName,
392 const QStringList& theEntryList )
394 // Process "Geometry" module operations with non-empty list of created objects only
395 if ( theModuleName != "Geometry" || theEntryList.isEmpty() ) {
399 // Start import GEOM object operation
400 myGeomObjectsToImport = theEntryList;
401 startOperation( ImportCreatedPrimitiveId );
402 myGeomObjectsToImport.clear();
406 * Returns the list of entries of GEOM objects to be imported.
408 QStringList HYDROGUI_Module::GetGeomObjectsToImport()
410 return myGeomObjectsToImport;