Salome HOME
0433f520d77185f25ee47d3340ebd532604254fc
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationOp.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_CalculationOp.h"
24
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_CalculationDlg.h"
27 #include "HYDROGUI_Module.h"
28 #include "HYDROGUI_Tool.h"
29 #include "HYDROGUI_UpdateFlags.h"
30 #include "HYDROGUI_Zone.h"
31 #include "HYDROGUI_Region.h"
32
33 #include <HYDROData_Polyline.h>
34 #include <HYDROData_Iterator.h>
35 #include <HYDROData_ImmersibleZone.h>
36 #include <HYDROData_Object.h>
37
38 #include <OCCViewer_ViewManager.h>
39 #include <OCCViewer_ViewModel.h>
40 #include <OCCViewer_ViewWindow.h>
41
42 #include <LightApp_Application.h>
43 #include <LightApp_UpdateFlags.h>
44 #include <LightApp_SelectionMgr.h>
45 #include <LightApp_DataOwner.h>
46
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_Desktop.h>
49
50 #include <QApplication>
51
52 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
53 : HYDROGUI_Operation( theModule ),
54   myIsEdit( theIsEdit ),
55   myActiveViewManager( NULL ),
56   myPreviewViewManager( NULL )
57 {
58   setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
59 }
60
61 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
62 {
63   closePreview();
64 }
65
66 void HYDROGUI_CalculationOp::startOperation()
67 {
68   HYDROGUI_Operation::startOperation();
69   
70   // Begin transaction
71   startDocOperation();
72
73   HYDROGUI_CalculationDlg* aPanel = 
74     ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
75   if ( !aPanel )
76     return;
77
78   aPanel->reset();
79   QStringList aList;
80   QStringList anEntryList;
81   HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
82   getNamesAndEntries( aSeq, aList, anEntryList );
83   aPanel->setAllGeomObjects( aList, anEntryList );
84
85   // Get all polylines
86   aList.clear();
87   anEntryList.clear();
88   HYDROData_Iterator anIter( doc(), KIND_POLYLINE );
89   Handle(HYDROData_Polyline) aPolylineObj;
90   QString aPolylineName;
91   for ( ; anIter.More(); anIter.Next() )
92   {
93     aPolylineObj = Handle(HYDROData_Polyline)::DownCast( anIter.Current() );
94
95     if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
96     {
97       aPolylineName = aPolylineObj->GetName();
98       if ( !aPolylineName.isEmpty() )
99       {
100         aList.append( aPolylineName );
101         anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
102       }
103     }
104   }
105   aPanel->setPolylineNames( aList, anEntryList );
106
107   QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
108
109   myEditedObject.Nullify();
110   if ( myIsEdit )
111   {
112     myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
113     if ( !myEditedObject.IsNull() )
114     {
115       anObjectName = myEditedObject->GetName();
116       aPolylineObj = myEditedObject->GetBoundaryPolyline();
117       if ( aPolylineObj.IsNull() )
118       {
119         aPanel->setBoundary( QString() );
120       }
121       else
122       {
123         aPolylineName = aPolylineObj->GetName();
124         aPanel->setBoundary( aPolylineName );
125       }
126       aSeq = myEditedObject->GetGeometryObjects();
127       getNamesAndEntries( aSeq, aList, anEntryList );
128       aPanel->includeGeomObjects( aList );
129     }
130   }
131   else
132   {
133     myEditedObject =
134       Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
135     myEditedObject->SetName(anObjectName);
136   }
137
138   aPanel->setObjectName( anObjectName );
139   aPanel->setEditedObject( myEditedObject );
140
141   createPreview();
142 }
143
144 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq, 
145                                                 QStringList& theNames, QStringList& theEntries ) const
146 {
147   Handle(HYDROData_Object) anObject;
148   Handle(HYDROData_Entity) anEntity;
149   theNames.clear();
150   theEntries.clear();
151   HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
152   for ( ; anIter.More(); anIter.Next() )
153   {
154     anEntity = anIter.Value();
155     if ( !anEntity.IsNull() )
156     {
157       anObject = Handle(HYDROData_Object)::DownCast( anEntity );
158       if ( !anObject.IsNull() )
159       {
160         theNames.append( anObject->GetName() );
161         theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anObject ) );
162       }
163     }
164   }
165 }
166
167 void HYDROGUI_CalculationOp::abortOperation()
168 {
169   closePreview();
170   // Abort transaction
171   abortDocOperation();
172   HYDROGUI_Operation::abortOperation();
173 }
174
175 void HYDROGUI_CalculationOp::commitOperation()
176 {
177   closePreview();
178   // Commit transaction
179   commitDocOperation();
180   HYDROGUI_Operation::commitOperation();
181 }
182
183 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
184 {
185   HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
186
187   // Connect signals and slots
188   connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
189   connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
190   connect( aPanel, SIGNAL( splitZones() ), SLOT( onSplitZones() ) );
191   connect( aPanel, SIGNAL( hideZones() ), SLOT( onHideZones() ) );
192   connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
193   connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
194   connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
195     SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
196   connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
197     SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
198   connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
199     SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
200   connect( aPanel, SIGNAL( objectSelected( const QString & ) ), 
201     SLOT( onObjectSelected( const QString & ) ) );
202   connect( aPanel, SIGNAL( boundarySelected( const QString & ) ), 
203     SLOT( onBoundarySelected( const QString & ) ) );
204
205   return aPanel;
206 }
207
208 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
209 {
210   // Set the selected boundary polyline to the calculation case
211   Handle(HYDROData_Polyline) anObject;
212   HYDROGUI_Shape* aShape;
213   Handle(AIS_InteractiveContext) aCtx;
214   if ( myPreviewViewManager ) 
215   {
216     if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
217     {
218       aCtx = aViewer->getAISContext();
219     }
220   }
221   // Remove the old boundary from the operation viewer
222   anObject = myEditedObject->GetBoundaryPolyline();
223   if ( !anObject.IsNull() )
224   {
225     module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anObject );
226   }
227
228   if ( theObjName.trimmed().isEmpty() )
229   {
230     // No polyline is selected
231     myEditedObject->RemoveBoundaryPolyline();
232   }
233   else
234   {
235     Handle(HYDROData_Entity) anEntity = 
236       HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINE );
237     if ( !anEntity.IsNull() )
238     {
239       anObject = Handle(HYDROData_Polyline)::DownCast( anEntity );
240       if ( !anObject.IsNull() )
241       {
242         myEditedObject->SetBoundaryPolyline( anObject );
243         if ( !aCtx.IsNull() )
244         {
245           showObject( anEntity, aCtx );
246         }
247       }
248     }
249   }
250 }
251
252 void HYDROGUI_CalculationOp::onObjectSelected ( const QString & theObjName )
253 {
254   // Select the appropriate geometry object shape in the viewer
255   selectionMgr()->clearSelected();
256
257   // Unhighlight all objects except selected
258   HYDROGUI_Shape* aShape;
259   HYDROGUI_Shape* aSelectedShape = 0;
260   Handle(HYDROData_Entity) anEntity;
261   HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
262   HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
263   bool isSelected;
264   QString aName;
265   for ( ; anIter.More(); anIter.Next() )
266   {
267     anEntity = anIter.Value();
268     if ( !anEntity.IsNull() )
269     {
270       aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
271       if ( aShape )
272       {
273         aName = anEntity->GetName();
274         isSelected = ( aName == theObjName );
275         if ( isSelected )
276         {
277           aSelectedShape = aShape;
278         }
279         if ( aShape->isHighlighted() != isSelected )
280         {
281           if ( !isSelected )
282           {
283             aShape->highlight( isSelected );
284             aShape->update();
285           }
286         }
287       }
288     }
289   }
290   if ( aSelectedShape )
291   {
292     aSelectedShape->highlight( true );
293     aSelectedShape->update();
294   }
295 }
296
297 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
298 {
299   HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
300   HYDROGUI_Zone* aZoneItem;
301   selectionMgr()->clearSelected();
302   if ( aRegionItem )
303   {
304     // Select a region in preview
305     SUIT_DataOwnerPtrList aList( true );
306     DataObjectList aZones = aRegionItem->children();
307     for ( int i = 0; i < aZones.length(); i++ )
308     {
309       aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
310       if ( aZoneItem )
311       {
312         aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
313       }
314     }
315     selectionMgr()->setSelected( aList );
316   }
317   else
318   {
319     // select a single zone
320     aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
321     if ( aZoneItem )
322     {
323       SUIT_DataOwnerPtrList aList( true );
324       aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
325       selectionMgr()->setSelected( aList );
326     }
327   }
328 }
329
330 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const QList<SUIT_DataObject*>& theZonesList )
331 {
332   HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
333   if ( aRegion )
334   {
335     QList<HYDROGUI_Zone*> aZonesList;
336     HYDROGUI_Zone* aZone;
337     // Get a list of dropped zones
338     for ( int i = 0; i < theZonesList.length(); i++ )
339     {
340       aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
341       if ( aZone )
342       {
343         aZonesList.append( aZone );
344       }
345     }
346     if ( aZonesList.length() > 0 )
347     {
348       aRegion->addZones( aZonesList );
349       HYDROGUI_CalculationDlg* aPanel = 
350         ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
351       if ( aPanel )
352       {
353         aPanel->setEditedObject(myEditedObject);
354       }
355       createPreview();
356     }
357   }
358 }
359
360 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
361 {
362   QList<HYDROGUI_Zone*> aZonesList;
363   HYDROGUI_Zone* aZone;
364   // Get a list of dropped zones
365   for ( int i = 0; i < theZonesList.length(); i++ )
366   {
367     aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
368     if ( aZone )
369     {
370       aZonesList.append( aZone );
371     }
372   }
373   if ( aZonesList.length() > 0 )
374   {
375     module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
376     HYDROGUI_CalculationDlg* aPanel = 
377       ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
378     if ( aPanel )
379     {
380       aPanel->setEditedObject(myEditedObject);
381     }
382     createPreview();
383   }
384 }
385
386 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theBathymetryName )
387 {
388   HYDROGUI_CalculationDlg* aPanel = 
389     ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
390   if ( aPanel )
391   {
392     HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
393     if ( aZone )
394     {
395       aZone->setMergeType( theMergeType, theBathymetryName );
396       HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
397       if ( aShape )
398       {
399         aShape->update();
400       }
401     }
402     aPanel->refreshZonesBrowser();
403   }
404 }
405
406 void HYDROGUI_CalculationOp::onAddObjects()
407 {
408   HYDROGUI_CalculationDlg* aPanel = 
409     ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
410   if ( aPanel )
411   {
412     // Add geometry objects selected in the module browser to the calculation case
413     Handle(HYDROData_Object) anObject;
414     Handle(HYDROData_Entity) anEntity;
415     QStringList aList;
416     QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
417     for (int i = 0; i < aSelectedList.length(); i++)
418     {
419       anEntity = HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) );
420       if ( !anEntity.IsNull() )
421       {
422         anObject = Handle(HYDROData_Object)::DownCast( anEntity );
423         if ( !anObject.IsNull() )
424         {
425           if (myEditedObject->AddGeometryObject( anObject ))
426           {
427             aList.append( anObject->GetName() );
428           }
429         }
430       }
431     }
432     if ( !aList.isEmpty() )
433     {
434       aPanel->includeGeomObjects( aList );
435       createPreview();
436     }
437   }
438 }
439
440 void HYDROGUI_CalculationOp::onRemoveObjects()
441 {
442   // Remove selected objects from the calculation case
443   HYDROGUI_CalculationDlg* aPanel = 
444     ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
445   if ( aPanel )
446   {
447     QStringList aList = aPanel->getSelectedGeomObjects();
448     Handle(HYDROData_Object) anObject;
449     Handle(HYDROData_Entity) anEntity;
450     for (int i = 0; i < aList.length(); i++)
451     {
452       anEntity = HYDROGUI_Tool::FindObjectByName( module(), aList.at(i) );
453       if ( !anEntity.IsNull() )
454       {
455         anObject = Handle(HYDROData_Object)::DownCast( anEntity );
456         if ( !anObject.IsNull() )
457         {
458           module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anObject );
459           myEditedObject->RemoveGeometryObject( anObject );
460         }
461       }
462     }
463     if ( !aList.isEmpty() )
464     {
465       aPanel->excludeGeomObjects( aList );
466     }
467   }
468 }
469
470 bool HYDROGUI_CalculationOp::processApply( int&     theUpdateFlags,
471                                            QString& theErrorMsg )
472 {
473   HYDROGUI_CalculationDlg* aPanel = 
474     ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
475   if ( !aPanel )
476     return false;
477
478   theUpdateFlags = UF_Model;
479
480   return true;
481 }
482
483 void HYDROGUI_CalculationOp::onApply()
484 {
485   QApplication::setOverrideCursor( Qt::WaitCursor );
486
487   int anUpdateFlags = 0;
488   QString anErrorMsg;
489
490   bool aResult = false;
491   
492   try
493   {
494     aResult = processApply( anUpdateFlags, anErrorMsg );
495   }
496   catch ( Standard_Failure )
497   {
498     Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
499     anErrorMsg = aFailure->GetMessageString();
500     aResult = false;
501   }
502   catch ( ... )
503   {
504     aResult = false;
505   }
506   
507   QApplication::restoreOverrideCursor();
508
509   if ( aResult )
510   {
511     module()->update( anUpdateFlags );
512     commit();
513   }
514   else
515   {
516     abort();
517     QString aMsg = tr( "INPUT_VALID_DATA" );
518     if( !anErrorMsg.isEmpty() )
519       aMsg.prepend( anErrorMsg + "\n" );
520     SUIT_MessageBox::critical( module()->getApp()->desktop(),
521                                tr( "INSUFFICIENT_INPUT_DATA" ),
522                                aMsg ); 
523   }
524 }
525
526 void HYDROGUI_CalculationOp::onSplitZones()
527 {
528   QApplication::setOverrideCursor( Qt::WaitCursor );
529
530   if ( myEditedObject->IsMustBeUpdated() )
531   {
532     myShowZones = true;
533     myEditedObject->SplitGeometryObjects();
534
535     HYDROGUI_CalculationDlg* aPanel = 
536       ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
537     if ( aPanel )
538     {
539       aPanel->setEditedObject( myEditedObject );
540     }
541
542     createPreview();
543   }
544   else
545   {
546     setZonesVisible( true );
547   }
548
549   QApplication::restoreOverrideCursor();
550 }
551
552 void HYDROGUI_CalculationOp::onHideZones()
553 {
554   setZonesVisible( false );
555 }
556
557 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
558 {
559   myShowZones = theIsVisible;
560   HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
561   HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
562   HYDROData_SequenceOfObjects aZones;
563   Handle(HYDROData_Region) aRegion;
564   if ( myPreviewViewManager ) 
565   {
566     if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
567     {
568       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
569       if ( !aCtx.IsNull() )
570       {
571         for ( ; aRegionsIter.More(); aRegionsIter.Next() )
572         {
573           aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
574           if ( !aRegion.IsNull() )
575           {
576             aZones = aRegion->GetZones();
577             HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
578             for ( ; aZonesIter.More(); aZonesIter.Next() )
579             {
580               if ( theIsVisible )
581               {
582                 showObject( aZonesIter.Value(), aCtx );
583               }
584               else
585               {
586                 module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZonesIter.Value() );
587               }
588             }
589           }
590         }
591       }
592     }
593   }
594 }
595
596 void HYDROGUI_CalculationOp::createPreview()
597 {
598   LightApp_Application* anApp = module()->getApp();
599   HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
600   Handle(HYDROData_Entity) anEntity;
601
602   if ( myShowZones )
603   {
604     // Gather zones for displaying
605     HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
606     HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
607     HYDROData_SequenceOfObjects aZones;
608     Handle(HYDROData_Region) aRegion;
609     for ( ; aRegionsIter.More(); aRegionsIter.Next() )
610     {
611       anEntity = aRegionsIter.Value();
612       if ( !anEntity.IsNull() )
613       {
614         aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
615         if ( !aRegion.IsNull() )
616         {
617           aZones = aRegion->GetZones();
618           aSeq.Append( aZones );
619         }
620       }
621     }
622   }
623
624   // Get a boundary polyline if any
625   aSeq.Append( myEditedObject->GetBoundaryPolyline() );
626
627   module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
628
629   if ( !myActiveViewManager )
630   {
631     if ( aSeq.IsEmpty() )
632       return;
633
634     myActiveViewManager = anApp->activeViewManager();
635   }
636
637   if ( !myPreviewViewManager )
638   {
639     myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>( 
640       anApp->createViewManager( OCCViewer_Viewer::Type() ) );
641     if ( myPreviewViewManager )
642     {
643       connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
644                this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
645
646       module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
647       myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
648     }
649   }
650
651   if ( !myPreviewViewManager )
652     return;
653
654   if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
655   {
656     Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
657     if ( !aCtx.IsNull() )
658     {
659       HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
660       for ( ; anIter.More(); anIter.Next() )
661       {
662         showObject( anIter.Value(), aCtx );
663       }
664
665       //Process the draw events for viewer
666       QApplication::processEvents();
667       if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
668         vw->onTopView();
669     }
670   }
671 }
672
673 void HYDROGUI_CalculationOp::showObject( Handle(HYDROData_Entity) theEntity, Handle(AIS_InteractiveContext) theCtx )
674 {
675   if ( !theEntity.IsNull() )
676   {
677     HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, theEntity );
678     if ( !aShape )
679     {
680       aShape = new HYDROGUI_Shape( theCtx, theEntity );
681       module()->setObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, theEntity, aShape );
682     }
683     aShape->update();
684   }
685 }
686
687 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
688 {
689   closePreview();
690 }
691
692 void HYDROGUI_CalculationOp::closePreview()
693 {
694   if( myPreviewViewManager )
695   {
696     disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
697                 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
698
699     module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
700     myPreviewViewManager = NULL;
701   }
702
703   if( myActiveViewManager )
704   {
705     HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
706     myActiveViewManager = NULL;
707   }
708 }
709
710