Salome HOME
Feature #228: Import of polylines from GEOM.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Operations.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_Operations.h"
24
25 #include "HYDROGUI_CopyPasteOp.h"
26 #include "HYDROGUI_CalculationOp.h"
27 #include "HYDROGUI_ChannelOp.h"
28 #include "HYDROGUI_DataModel.h"
29 #include "HYDROGUI_DeleteOp.h"
30 #include "HYDROGUI_DigueOp.h"
31 #include "HYDROGUI_ExportImageOp.h"
32 #include "HYDROGUI_ImportImageOp.h"
33 #include "HYDROGUI_ImportBathymetryOp.h"
34 #include "HYDROGUI_ImmersibleZoneOp.h"
35 #include "HYDROGUI_Module.h"
36 #include "HYDROGUI_ObserveImageOp.h"
37 #include "HYDROGUI_PolylineOp.h"
38 #include "HYDROGUI_Poly3DOp.h"
39 #include "HYDROGUI_ProfileOp.h"
40 #include "HYDROGUI_RemoveImageRefsOp.h"
41 #include "HYDROGUI_ShowHideOp.h"
42 #include "HYDROGUI_StreamOp.h"
43 #include "HYDROGUI_TwoImagesOp.h"
44 #include "HYDROGUI_UpdateFlags.h"
45 #include "HYDROGUI_UpdateObjectOp.h"
46 #include "HYDROGUI_VisualStateOp.h"
47 #include "HYDROGUI_ImmersibleZoneOp.h"
48 #include "HYDROGUI_ImportGeomObjectOp.h"
49 #include "HYDROGUI_ImportObstacleFromFileOp.h"
50 #include "HYDROGUI_ExportCalculationOp.h"
51 #include "HYDROGUI_ImportProfilesOp.h"
52 #include "HYDROGUI_GeoreferencementOp.h"
53 #include "HYDROGUI_SetColorOp.h"
54 #include "HYDROGUI_Tool.h"
55
56 #include <HYDROData_Document.h>
57 #include <HYDROData_Obstacle.h>
58 #include <HYDROData_SplitToZonesTool.h>
59
60 #include <GeometryGUI.h>
61 #include <GeometryGUI_Operations.h>
62 #include <GEOMBase.h>
63
64 #include <SalomeApp_Study.h>
65
66 #include <LightApp_Application.h>
67
68 #include <CAM_Application.h>
69
70 #include <QtxListAction.h>
71 #include <QtxActionToolMgr.h>
72
73 #include <SUIT_Desktop.h>
74 #include <SUIT_ResourceMgr.h>
75 #include <SUIT_Session.h>
76 #include <SUIT_MessageBox.h>
77
78 #include <QAction>
79 #include <QApplication>
80
81 QAction* HYDROGUI_Module::createAction( const int theId, const QString& theSuffix, const QString& theImg,
82                                         const int theKey, const bool isToggle, const QString& theSlot )
83 {
84   QString aSlot = theSlot;
85   if( aSlot.isEmpty() )
86     aSlot = SLOT( onOperation() );
87   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
88   std::string anImg = theImg.toStdString();
89   QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aResMgr->loadPixmap( "HYDRO", tr( anImg.c_str() ) );
90   std::string aMenu    = ( "MEN_" + theSuffix ).toStdString();
91   std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
92   std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
93   std::string aSlotStr = aSlot.toStdString();
94   return LightApp_Module::createAction( theId, tr( aDesktop.c_str() ), aPixmap,
95     tr( aMenu.c_str() ), tr( aToolbar.c_str() ),
96                 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
97 }
98
99 void HYDROGUI_Module::createActions()
100 {
101   createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" );
102   createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" );
103
104   createAction( CopyId, "COPY", "", Qt::CTRL + Qt::Key_C );
105   createAction( PasteId, "PASTE", "", Qt::CTRL + Qt::Key_V );
106
107   createAction( UpdateObjectId, "UPDATE_OBJECT" );
108
109   createAction( ImportImageId, "IMPORT_IMAGE", "IMPORT_IMAGE_ICO", Qt::CTRL + Qt::Key_I );
110   createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE", "EDIT_IMPORTED_IMAGE_ICO" );
111   createAction( ObserveImageId, "OBSERVE_IMAGE", "OBSERVE_IMAGE_ICO" );
112   createAction( ExportImageId, "EXPORT_IMAGE", "EXPORT_IMAGE_ICO" );
113   createAction( RemoveImageRefsId, "REMOVE_IMAGE_REFERENCE", "REMOVE_IMAGE_REFERENCE_ICO" );
114
115   createAction( CreatePolylineId, "CREATE_POLYLINE", "CREATE_POLYLINE_ICO" );
116   createAction( EditPolylineId, "EDIT_POLYLINE", "EDIT_POLYLINE_ICO" ); 
117
118   createAction( CreatePolyline3DId, "CREATE_POLYLINE_3D", "CREATE_POLYLINE_3D_ICO" );
119   createAction( EditPolyline3DId, "EDIT_POLYLINE_3D", "EDIT_POLYLINE_3D_ICO" ); 
120
121   createAction( CreateProfileId, "CREATE_PROFILE", "CREATE_PROFILE_ICO" );
122   createAction( ImportProfilesId, "IMPORT_PROFILES", "IMPORT_PROFILES_ICO" );
123   createAction( EditProfileId, "EDIT_PROFILE", "EDIT_PROFILE_ICO" ); 
124   createAction( AllGeoreferencementId, "GEOREFERENCEMENT", "GEOREFERENCEMENT_ICO" ); 
125   createAction( SelectedGeoreferencementId, "GEOREFERENCEMENT", "GEOREFERENCEMENT_ICO" ); 
126   
127   createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "IMPORT_BATHYMETRY_ICO", Qt::CTRL + Qt::Key_B );
128   createAction( EditImportedBathymetryId, "EDIT_IMPORTED_BATHYMETRY", "EDIT_IMPORTED_BATHYMETRY_ICO" );
129
130   createAction( CreateImmersibleZoneId, "CREATE_IMMERSIBLE_ZONE", "CREATE_IMMERSIBLE_ZONE_ICO" );
131   createAction( EditImmersibleZoneId, "EDIT_IMMERSIBLE_ZONE", "EDIT_IMMERSIBLE_ZONE_ICO" );
132
133   createAction( CreateStreamId, "CREATE_STREAM", "CREATE_STREAM_ICO" );
134   createAction( EditStreamId, "EDIT_STREAM", "EDIT_STREAM_ICO" );
135
136   createAction( CreateChannelId, "CREATE_CHANNEL", "CREATE_CHANNEL_ICO" );
137   createAction( EditChannelId, "EDIT_CHANNEL", "EDIT_CHANNEL_ICO" );
138
139   createAction( CreateDigueId, "CREATE_DIGUE", "CREATE_DIGUE_ICO" );
140   createAction( EditDigueId, "EDIT_DIGUE", "EDIT_DIGUE_ICO" );
141
142   createAction( ImportObstacleFromFileId, "IMPORT_OBSTACLE_FROM_FILE", "IMPORT_OBSTACLE_FROM_FILE_ICO" );
143   createAction( ImportGeomObjectAsObstacleId, "IMPORT_GEOM_OBJECT_AS_OBSTACLE", "IMPORT_GEOM_OBJECT_ICO" );
144   createAction( ImportGeomObjectAsPolylineId, "IMPORT_GEOM_OBJECT_AS_POLYLINE", "IMPORT_GEOM_OBJECT_ICO" );
145   createAction( CreateBoxId, "CREATE_BOX", "CREATE_BOX_ICO" );
146   createAction( CreateCylinderId, "CREATE_CYLINDER", "CREATE_CYLINDER_ICO" );
147
148   createAction( CreateCalculationId, "CREATE_CALCULATION", "CREATE_CALCULATION_ICO" );
149   createAction( EditCalculationId, "EDIT_CALCULATION", "EDIT_CALCULATION_ICO" );
150   createAction( ExportCalculationId, "EXPORT_CALCULATION", "EXPORT_CALCULATION_ICO" );
151
152   createAction( FuseImagesId, "FUSE_IMAGES", "FUSE_IMAGES_ICO" );
153   createAction( EditFusedImageId, "EDIT_FUSED_IMAGE", "EDIT_FUSED_IMAGE_ICO" );
154
155   createAction( CutImagesId, "CUT_IMAGES", "CUT_IMAGES_ICO" );
156   createAction( EditCutImageId, "EDIT_CUT_IMAGE", "EDIT_CUT_IMAGE_ICO" );
157
158   createAction( SplitImageId, "SPLIT_IMAGE", "SPLIT_IMAGE_ICO" );
159   createAction( EditSplittedImageId, "EDIT_SPLITTED_IMAGE", "EDIT_SPLITTED_IMAGE_ICO" );
160
161   createAction( DeleteId, "DELETE", "", Qt::Key_Delete, false,
162                 SLOT( onDelete() ) );
163
164   createAction( SetColorId, "COLOR" );
165
166   createAction( ShowId, "SHOW" );
167   createAction( ShowOnlyId, "SHOW_ONLY" );
168   createAction( ShowAllId, "SHOW_ALL" );
169   createAction( HideId, "HIDE" );
170   createAction( HideAllId, "HIDE_ALL" );
171 }
172
173 void HYDROGUI_Module::createMenus()
174 {
175   int aFileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
176   int aCustomPos = 5; // to insert custom actions after "Save as" and before "Preferences"
177   createMenu( SaveVisualStateId, aFileMenu, aCustomPos );
178   createMenu( separator(), aFileMenu, -1, aCustomPos );
179
180   int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 );
181   createMenu( UndoId, anEditMenu );
182   createMenu( RedoId, anEditMenu );
183   createMenu( separator(), anEditMenu );
184   createMenu( CopyId, anEditMenu );
185   createMenu( PasteId, anEditMenu );
186
187   int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10
188   int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu );
189   createMenu( ImportImageId, aHydroId, -1, -1 );
190   createMenu( ImportBathymetryId, aHydroId, -1, -1 );
191   createMenu( CreatePolylineId, aHydroId, -1, -1 );
192   createMenu( CreatePolyline3DId, aHydroId, -1, -1 );
193
194   int aNewProfileId = createMenu( tr( "MEN_DESK_PROFILE" ), aHydroId, -1 );
195   createMenu( CreateProfileId, aNewProfileId, -1, -1 );
196   createMenu( ImportProfilesId, aNewProfileId, -1, -1 );
197   createMenu( AllGeoreferencementId, aNewProfileId, -1, -1 );
198
199   int anArtificialMenuId = createMenu( tr( "MEN_DESK_ARTIFICIAL" ), aHydroId, -1 );
200   createMenu( CreateChannelId, anArtificialMenuId, -1, -1 );
201   createMenu( CreateDigueId, anArtificialMenuId, -1, -1 );
202
203   int aNaturalMenuId = createMenu( tr( "MEN_DESK_NATURAL" ), aHydroId, -1 );
204   createMenu( CreateImmersibleZoneId, aNaturalMenuId, -1, -1 );
205   createMenu( CreateStreamId, aNaturalMenuId, -1, -1 );
206
207   int anObstacleMenuId = createMenu( tr( "MEN_DESK_OBSTACLE" ), aHydroId, -1 );
208   createMenu( ImportObstacleFromFileId, anObstacleMenuId, -1, -1 );
209   createMenu( CreateBoxId, anObstacleMenuId, -1, -1 );
210   createMenu( CreateCylinderId, anObstacleMenuId, -1, -1 );
211
212   createMenu( CreateCalculationId, aHydroId, -1, -1 );
213   createMenu( separator(), aHydroId );
214   createMenu( FuseImagesId, aHydroId, -1, -1 );
215   createMenu( CutImagesId, aHydroId, -1, -1 );
216   createMenu( SplitImageId, aHydroId, -1, -1 );
217   createMenu( separator(), aHydroId );
218 }
219
220 void HYDROGUI_Module::createPopups()
221 {
222 }
223
224 void HYDROGUI_Module::createToolbars()
225 {
226   int aToolBar = createTool( tr( "MEN_DESK_HYDRO" ) );
227   createTool( UndoId, aToolBar );
228   createTool( RedoId, aToolBar );
229
230   createTool( separator(), aToolBar );
231   createTool( ImportImageId, aToolBar );
232   createTool( ImportBathymetryId, aToolBar );
233   createTool( CreatePolylineId, aToolBar );
234   createTool( CreatePolyline3DId, aToolBar );
235
236   createTool( separator(), aToolBar );
237   createTool( CreateProfileId, aToolBar );
238   createTool( ImportProfilesId, aToolBar );
239   createTool( AllGeoreferencementId, aToolBar );
240
241   createTool( separator(), aToolBar );
242   createTool( CreateChannelId, aToolBar );
243   createTool( CreateDigueId, aToolBar );
244
245   createTool( separator(), aToolBar );
246   createTool( CreateImmersibleZoneId, aToolBar );
247   createTool( CreateStreamId, aToolBar );
248
249   createTool( separator(), aToolBar );
250   createTool( ImportObstacleFromFileId, aToolBar );
251   createTool( CreateBoxId, aToolBar );
252   createTool( CreateCylinderId, aToolBar );
253
254   createTool( separator(), aToolBar );
255   createTool( CreateCalculationId, aToolBar );
256
257   createTool( separator(), aToolBar );
258   createTool( FuseImagesId, aToolBar );
259   createTool( CutImagesId, aToolBar );
260   createTool( SplitImageId, aToolBar );
261 }
262
263 void HYDROGUI_Module::createUndoRedoActions()
264 {
265   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
266
267   QtxListAction* anEditUndo = new QtxListAction( tr( "MEN_UNDO" ),
268     aResMgr->loadPixmap( "HYDRO", tr( "UNDO_ICO" ) ), tr( "DSK_UNDO" ),
269     Qt::CTRL + Qt::Key_Z, application()->desktop() );
270     
271   QtxListAction* anEditRedo = new QtxListAction( tr( "MEN_REDO" ),
272     aResMgr->loadPixmap( "HYDRO", tr( "REDO_ICO" ) ), tr( "DSK_REDO" ),
273     Qt::CTRL + Qt::Key_Y, application()->desktop() );
274   
275   registerAction( UndoId, anEditUndo );
276   registerAction( RedoId, anEditRedo );
277
278   anEditUndo->setComment( tr( "STB_UNDO" ) );
279   anEditRedo->setComment( tr( "STB_REDO" ) );
280
281   connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
282   connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
283 }
284
285 void HYDROGUI_Module::updateUndoRedoControls()
286 {
287   HYDROGUI_DataModel* aModel = getDataModel();
288
289   QtxListAction* aUndoAction = (QtxListAction*)action( UndoId );
290   QtxListAction* aRedoAction = (QtxListAction*)action( RedoId );
291
292   bool aCanUndo = aModel->canUndo();
293   bool aCanRedo = aModel->canRedo();
294
295   if( aCanUndo )
296     aUndoAction->addNames( aModel->undoNames() );
297   aUndoAction->setEnabled( aCanUndo );
298
299   if( aCanRedo )
300     aRedoAction->addNames( aModel->redoNames() );
301   aRedoAction->setEnabled( aCanRedo );
302 }
303
304 void HYDROGUI_Module::onOperation()
305 {
306   const QAction* anAction = dynamic_cast<const QAction*>( sender() );
307   int anId = actionId( anAction );
308   if( anId >= 0 )
309     startOperation( anId );
310 }
311
312 void HYDROGUI_Module::onDelete()
313 {
314   SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
315   HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
316   if ( aPolylineOp && aPolylineOp->deleteEnabled() )
317     aPolylineOp->deleteSelected();
318   else
319     startOperation( DeleteId );
320 }
321
322 bool HYDROGUI_Module::onUndo( int theNumActions )
323 {
324   QApplication::setOverrideCursor( Qt::WaitCursor );
325   bool anIsOk = true;
326   HYDROGUI_DataModel* aModel = getDataModel();
327   if( aModel )
328   {
329     while( theNumActions > 0 )
330     {
331       if( !aModel->undo() )
332       {
333         anIsOk = false;
334         break;
335       }
336       theNumActions--;
337     }
338     update( UF_All );
339   }
340   QApplication::restoreOverrideCursor();
341   return anIsOk;
342 }
343
344 bool HYDROGUI_Module::onRedo( int theNumActions )
345 {
346   QApplication::setOverrideCursor( Qt::WaitCursor );
347   bool anIsOk = true;
348   HYDROGUI_DataModel* aModel = getDataModel();
349   if( aModel )
350   {
351     while( theNumActions > 0 )
352     {
353       if( !aModel->redo() )
354       {
355         anIsOk = false;
356         break;
357       }
358       theNumActions--;
359     }
360     update( UF_All );
361   }
362   QApplication::restoreOverrideCursor();
363   return anIsOk;
364 }
365
366 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
367 {
368   LightApp_Operation* anOp = 0;
369   HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
370   switch( theId )
371   {
372   case SaveVisualStateId:
373   case LoadVisualStateId:
374     anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId );
375     break;
376   case CopyId:
377   case PasteId:
378     anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId );
379     break;
380   case ImportImageId:
381   case EditImportedImageId:
382     anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId );
383     break;
384   case ObserveImageId:
385     anOp = new HYDROGUI_ObserveImageOp( aModule );
386     break;
387   case ExportImageId:
388     anOp = new HYDROGUI_ExportImageOp( aModule );
389     break;
390   case UpdateObjectId:
391     anOp = new HYDROGUI_UpdateObjectOp( aModule );
392     break;
393   case RemoveImageRefsId:
394     anOp = new HYDROGUI_RemoveImageRefsOp( aModule );
395     break;
396   case CreatePolyline3DId:
397   case EditPolyline3DId:
398     anOp = new HYDROGUI_Poly3DOp( aModule, theId == EditPolyline3DId );
399     break;
400   case CreatePolylineId:
401   case EditPolylineId:
402     anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
403     break;
404   case CreateProfileId:
405   case EditProfileId:
406     anOp = new HYDROGUI_ProfileOp( aModule, theId == EditProfileId );
407     break;
408   case ImportProfilesId:
409     anOp = new HYDROGUI_ImportProfilesOp( aModule ) ;
410     break;
411   case AllGeoreferencementId:
412     anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::All ) ;
413     break;
414   case SelectedGeoreferencementId:
415     anOp = new HYDROGUI_GeoreferencementOp( aModule, HYDROGUI_GeoreferencementOp::Selected ) ;
416     break;
417   case ImportBathymetryId:
418   case EditImportedBathymetryId:
419     anOp = new HYDROGUI_ImportBathymetryOp( aModule, theId == EditImportedBathymetryId  );
420     break;
421   case CreateImmersibleZoneId:
422   case EditImmersibleZoneId:
423     anOp = new HYDROGUI_ImmersibleZoneOp( aModule, theId == EditImmersibleZoneId );
424     break;
425   case CreateStreamId:
426   case EditStreamId:
427     anOp = new HYDROGUI_StreamOp( aModule, theId == EditStreamId );
428     break;
429   case CreateChannelId:
430   case EditChannelId:
431     anOp = new HYDROGUI_ChannelOp( aModule, theId == EditChannelId );
432     break;
433   case CreateDigueId:
434   case EditDigueId:
435     anOp = new HYDROGUI_DigueOp( aModule, theId == EditDigueId );
436     break;
437   case CreateCalculationId:
438   case EditCalculationId:
439     anOp = new HYDROGUI_CalculationOp( aModule, theId == EditCalculationId );
440     break;
441   case ExportCalculationId:
442     anOp = new HYDROGUI_ExportCalculationOp( aModule );
443     break;
444   case FuseImagesId:
445   case EditFusedImageId:
446     anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Fuse, theId == EditFusedImageId );
447     break;
448   case CutImagesId:
449   case EditCutImageId:
450     anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut, theId == EditCutImageId );
451     break;
452   case SplitImageId:
453   case EditSplittedImageId:
454     anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Split, theId == EditSplittedImageId );
455     break;
456   case ImportObstacleFromFileId:
457     anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule );
458     break;
459   case ImportCreatedPrimitiveId:
460     anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportCreatedAsObstacle );
461     break;
462   case ImportGeomObjectAsObstacleId:
463     anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelectedAsObstacle );
464     break;
465   case ImportGeomObjectAsPolylineId:
466     anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelectedAsPolyline );
467     break;
468   case CreateBoxId:
469     application()->activateOperation( "Geometry", GEOMOp::OpBox );
470     break;
471   case CreateCylinderId:
472     application()->activateOperation( "Geometry", GEOMOp::OpCylinder );
473     break;
474   case DeleteId:
475     anOp = new HYDROGUI_DeleteOp( aModule );
476     break;
477   case SetColorId:
478     anOp = new HYDROGUI_SetColorOp( aModule );
479     break;
480   case ShowId:
481   case ShowOnlyId:
482   case ShowAllId:
483   case HideId:
484   case HideAllId:
485     anOp = new HYDROGUI_ShowHideOp( aModule, theId );
486     break;
487   }
488
489   if( !anOp )
490     anOp = LightApp_Module::createOperation( theId );
491
492   return anOp;
493 }
494
495 bool HYDROGUI_Module::reusableOperation( const int id )
496 {
497   if ( id == ImportGeomObjectAsObstacleId ||
498        id == ImportGeomObjectAsPolylineId ) {
499     return false;
500   }
501
502   return LightApp_Module::reusableOperation( id );
503 }
504
505 /**
506  * Called when the operation perfomed by another module is finished.
507  * \param theModuleName the name of the module which perfomed the operation
508  * \param theOperationName the operation name
509  * \param theEntryList the list of the created objects entries
510  */
511 void HYDROGUI_Module::onExternalOperationFinished( const QString& theModuleName,
512                                                    const QString& theOperationName,
513                                                    const QStringList& theEntryList )
514 {
515   // Process "Geometry" module operations with non-empty list of created objects only
516   if ( theModuleName != "Geometry" || theEntryList.isEmpty() ) {
517     return;
518   }
519   
520   // Start import GEOM object operation
521   myGeomObjectsToImport = theEntryList;
522   startOperation( ImportCreatedPrimitiveId );
523   myGeomObjectsToImport.clear();
524 }
525
526 /**
527  * Returns the list of entries of GEOM objects to be imported.
528  */
529 QStringList HYDROGUI_Module::GetGeomObjectsToImport()
530 {
531   return myGeomObjectsToImport;
532 }
533
534 /**
535  * Returns true if the object with the given entry can be renamed.
536  * @param theEntry the object entry
537  */
538 bool HYDROGUI_Module::renameAllowed( const QString& theEntry ) const
539 {
540   // Allow to rename all HYDRO objects
541   Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
542   return !anEntity.IsNull();
543 }
544 /**
545  * Returns true if the object with the given entry is renamed.
546  * @param theEntry the object entry
547  * @param theName the new name
548  */
549 bool HYDROGUI_Module::renameObject( const QString& theEntry, const QString& theName )
550 {
551   Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
552   bool aRes = false;
553   if ( !anEntity.IsNull() )
554   {
555     HYDROGUI_DataModel* aModel = getDataModel();
556     if( aModel )
557     {
558       if( anEntity->GetName() != theName )
559       {
560         // check that there are no other objects with the same name in the document
561         Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( this, theName );
562         if ( anObject.IsNull() )
563         {
564           SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
565           if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
566           {
567             anEntity->SetName( theName );
568             aRes = true;
569           }
570           else
571           {
572             aRes = aModel->rename( anEntity, theName );
573           }
574         }
575         else
576         {
577           // Inform the user that the name is already used
578           QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
579           QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
580           SUIT_MessageBox::critical( getApp()->desktop(), aTitle, aMessage );
581         }
582       }
583     }
584   }
585   return aRes;
586 }