Salome HOME
Feature 32: Image presentation in OCCViewer.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportImageOp.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_ImportImageOp.h"
24
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_ImportImageDlg.h"
27 #include "HYDROGUI_Module.h"
28 #include "HYDROGUI_PrsImage.h"
29 #include "HYDROGUI_Tool.h"
30 #include "HYDROGUI_UpdateFlags.h"
31
32 #include <HYDROData_Iterator.h>
33 #include <HYDROData_Lambert93.h>
34
35 #include <HYDROOperations_Factory.h>
36
37 #include <GraphicsView_ViewManager.h>
38 #include <GraphicsView_ViewPort.h>
39 #include <GraphicsView_Viewer.h>
40
41 #include <LightApp_Application.h>
42 #include <LightApp_UpdateFlags.h>
43
44 HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule,
45                                                 const bool theIsEdit )
46 : HYDROGUI_Operation( theModule ),
47   myIsEdit( theIsEdit ),
48   myEditedObject( 0 ),
49   myActiveViewManager( 0 ),
50   myPreviewViewManager( 0 ),
51   myPreviewPrs( 0 ),
52   myRefPreviewPrs( 0 ),
53   myPointType( HYDROGUI_PrsImage::None )
54 {
55   setName( theIsEdit ? tr( "EDIT_IMPORTED_IMAGE" ) : tr( "IMPORT_IMAGE" ) );
56 }
57
58 HYDROGUI_ImportImageOp::~HYDROGUI_ImportImageOp()
59 {
60 }
61
62 void HYDROGUI_ImportImageOp::startOperation()
63 {
64   HYDROGUI_Operation::startOperation();
65
66   HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
67   aPanel->reset();
68   aPanel->setIsEdit( myIsEdit );
69
70   if( myIsEdit )
71   {
72     myEditedObject = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
73     if( !myEditedObject.IsNull() )
74     {
75       QImage anImage = myEditedObject->Image();
76
77       int aTransformationMode = myEditedObject->TrsfMode();
78       if( aTransformationMode == HYDROGUI_ImportImageDlg::RefImage )
79         aTransformationMode = HYDROGUI_ImportImageDlg::ManualCartesian;
80       aPanel->setTransformationMode( aTransformationMode );
81
82       QPoint aPointA1, aPointB1, aPointC1;
83       QPointF aPointA2, aPointB2, aPointC2;
84       QPointF aPointA3, aPointB3, aPointC3;
85       myEditedObject->TrsfPoints( aPointA1, aPointB1, aPointC1,
86                                   aPointA2, aPointB2, aPointC2,
87                                   aPointA3, aPointB3, aPointC3 );
88
89       onCreatePreview( anImage );
90
91       if( myPreviewPrs )
92       {
93         HYDROGUI_PrsImage::TransformationPointMap aPointMap =
94           myPreviewPrs->getTransformationPointMap();
95         if( !aPointMap.isEmpty() )
96         {
97           aPointMap[ HYDROGUI_PrsImage::PointA ].Point = aPointA1;
98           aPointMap[ HYDROGUI_PrsImage::PointB ].Point = aPointB1;
99           aPointMap[ HYDROGUI_PrsImage::PointC ].Point = aPointC1;
100           myPreviewPrs->setTransformationPointMap( aPointMap );
101         }
102       }
103
104       HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
105       aDataMap[ HYDROGUI_PrsImage::PointA ] =
106         HYDROGUI_ImportImageDlg::TransformationData( aPointA1, aPointA2, aPointA3 );
107       aDataMap[ HYDROGUI_PrsImage::PointB ] =
108         HYDROGUI_ImportImageDlg::TransformationData( aPointB1, aPointB2, aPointB3 );
109       aDataMap[ HYDROGUI_PrsImage::PointC ] =
110         HYDROGUI_ImportImageDlg::TransformationData( aPointC1, aPointC2, aPointC3 );
111       aPanel->setTransformationDataMap( aDataMap );
112     }
113   }
114
115   // collect information about existing images
116   HYDROGUI_ImportImageDlg::PrsPointDataList aPrsPointDataList;
117   HYDROData_Iterator anIterator( doc(), KIND_IMAGE );
118   for( ; anIterator.More(); anIterator.Next() )
119   {
120     Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( anIterator.Current() );
121     if( !anImageObj.IsNull() )
122     {
123       if( myIsEdit && HYDROGUI_Tool::IsEqual( anImageObj, myEditedObject ) )
124         continue;
125
126       QPoint aPointA1, aPointB1, aPointC1;
127       QPointF aPointA2, aPointB2, aPointC2;
128       QPointF aPointA3, aPointB3, aPointC3;
129       anImageObj->TrsfPoints( aPointA1, aPointB1, aPointC1,
130                               aPointA2, aPointB2, aPointC2,
131                               aPointA3, aPointB3, aPointC3 );
132
133       HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
134       aDataMap[ HYDROGUI_PrsImage::PointA ] =
135         HYDROGUI_ImportImageDlg::TransformationData( aPointA1, aPointA2, aPointA3 );
136       aDataMap[ HYDROGUI_PrsImage::PointB ] =
137         HYDROGUI_ImportImageDlg::TransformationData( aPointB1, aPointB2, aPointB3 );
138       aDataMap[ HYDROGUI_PrsImage::PointC ] =
139         HYDROGUI_ImportImageDlg::TransformationData( aPointC1, aPointC2, aPointC3 );
140
141       HYDROGUI_ImportImageDlg::PrsPointData aPrsPointData( anImageObj->GetName(), aDataMap );
142       aPrsPointDataList.append( aPrsPointData );
143     }
144   }
145   aPanel->setPrsPointDataList( aPrsPointDataList );
146 }
147
148 void HYDROGUI_ImportImageOp::abortOperation()
149 {
150   closePreview();
151
152   HYDROGUI_Operation::abortOperation();
153 }
154
155 void HYDROGUI_ImportImageOp::commitOperation()
156 {
157   closePreview();
158
159   HYDROGUI_Operation::commitOperation();
160 }
161
162 HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const
163 {
164   HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportImageDlg( module(), getName() );
165   connect( aPanel, SIGNAL( createPreview( QImage ) ),
166            this, SLOT( onCreatePreview( QImage ) ) );
167   connect( aPanel, SIGNAL( activatePointSelection( int ) ),
168            this, SLOT( onActivatePointSelection( int ) ) );
169   connect( aPanel, SIGNAL( pointCoordChanged( bool, int, bool, int ) ),
170            this, SLOT( onPointCoordChanged( bool, int, bool, int ) ) );
171   connect( aPanel, SIGNAL( modeActivated( int ) ),
172            this, SLOT( onModeActivated( int ) ) );
173   connect( aPanel, SIGNAL( refImageActivated( const QString& ) ),
174            this, SLOT( onRefImageActivated( const QString& ) ) );
175   return aPanel;
176 }
177
178 bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
179                                            QString& theErrorMsg )
180 {
181   HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
182
183   QString anImageName = aPanel->getImageName();
184   if( anImageName.isEmpty() )
185     return false;
186
187   if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) )
188   {
189     // check that there are no other objects with the same name in the document
190     Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
191     if( !anObject.IsNull() )
192     {
193       theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
194       return false;
195     }
196   }
197
198   int aTransformationMode = aPanel->getTransformationMode();
199   bool anIsRefImage = aTransformationMode == HYDROGUI_ImportImageDlg::RefImage;
200
201   HYDROGUI_ImportImageDlg::TransformationDataMap aMap;
202   if( !aPanel->getTransformationDataMap( aMap ) )
203     return false;
204
205   HYDROGUI_ImportImageDlg::TransformationDataMap aRefMap;
206   if( anIsRefImage && !aPanel->getTransformationDataMap( aRefMap, true ) )
207     return false;
208
209   QPoint aPointA = aMap[ HYDROGUI_PrsImage::PointA ].ImagePoint;
210   QPoint aPointB = aMap[ HYDROGUI_PrsImage::PointB ].ImagePoint;
211   QPoint aPointC = aMap[ HYDROGUI_PrsImage::PointC ].ImagePoint;
212
213   QPointF aLPointA = aMap[ HYDROGUI_PrsImage::PointA ].LambertPoint;
214   QPointF aLPointB = aMap[ HYDROGUI_PrsImage::PointB ].LambertPoint;
215   QPointF aLPointC = aMap[ HYDROGUI_PrsImage::PointC ].LambertPoint;
216
217   QPointF aCPointA = aMap[ HYDROGUI_PrsImage::PointA ].CartesianPoint;
218   QPointF aCPointB = aMap[ HYDROGUI_PrsImage::PointB ].CartesianPoint;
219   QPointF aCPointC = aMap[ HYDROGUI_PrsImage::PointC ].CartesianPoint;
220
221   QPoint aRefPointA, aRefPointB, aRefPointC;
222   if( anIsRefImage )
223   {
224     aRefPointA = aRefMap[ HYDROGUI_PrsImage::PointA ].ImagePoint;
225     aRefPointB = aRefMap[ HYDROGUI_PrsImage::PointB ].ImagePoint;
226     aRefPointC = aRefMap[ HYDROGUI_PrsImage::PointC ].ImagePoint;
227   }
228
229   int xa = aPointA.x();
230   int ya = aPointA.y();
231   int xb = aPointB.x();
232   int yb = aPointB.y();
233   int xc = aPointC.x();
234   int yc = aPointC.y();
235
236   double xca = aCPointA.x();
237   double yca = aCPointA.y();
238   double xcb = aCPointB.x();
239   double ycb = aCPointB.y();
240   double xcc = aCPointC.x();
241   double ycc = aCPointC.y();
242
243   int xra = aRefPointA.x();
244   int yra = aRefPointA.y();
245   int xrb = aRefPointB.x();
246   int yrb = aRefPointB.y();
247   int xrc = aRefPointC.x();
248   int yrc = aRefPointC.y();
249
250   // first, check that three input points don't belong to a single line
251   if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
252   {
253     theErrorMsg = tr( "POINTS_A_B_C_BELONG_TO_SINGLE_LINE" );
254     return false;
255   }
256
257   // the same check for the reference points
258   if( anIsRefImage &&
259       ( ( yrb - yra ) * ( xrc - xra ) == ( yrc - yra ) * ( xrb - xra ) ) )
260   {
261     theErrorMsg = tr( "REFERENCE_POINTS_A_B_C_BELONG_TO_SINGLE_LINE" );
262     return false;
263   }
264
265   QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
266   QTransform aTransform2( xca, yca, 1, xcb, ycb, 1, xcc, ycc, 1 );
267   QTransform aTransform3( xra, yra, 1, xrb, yrb, 1, xrc, yrc, 1 );
268
269   bool anIsInvertible = false;
270   QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
271   if( !anIsInvertible )
272   {
273     theErrorMsg = tr( "TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED" );
274     return false;
275   }
276
277   QTransform aTransform;
278   if( anIsRefImage )
279     aTransform = aTransform1Inverted * aTransform3 * myRefTransform;
280   else
281     aTransform = aTransform1Inverted * aTransform2;
282
283   Handle(HYDROData_Image) anImageObj;
284   if( myIsEdit )
285     anImageObj = myEditedObject;
286   else
287     anImageObj = Handle(HYDROData_Image)::DownCast( doc()->CreateObject( KIND_IMAGE ) );
288
289   if( anImageObj.IsNull() )
290     return false;
291
292   anImageObj->SetName( anImageName );
293
294   anImageObj->SetImage( myImage );
295   anImageObj->SetTrsf( aTransform );
296
297   if( anIsRefImage )
298   {
299     aCPointA = QPointF( aTransform.map( aPointA ) );
300     aCPointB = QPointF( aTransform.map( aPointB ) );
301     aCPointC = QPointF( aTransform.map( aPointC ) );
302
303     // compute Lambert93 points
304     xca = aCPointA.x();
305     yca = aCPointA.y();
306     xcb = aCPointB.x();
307     ycb = aCPointB.y();
308     xcc = aCPointC.x();
309     ycc = aCPointC.y();
310
311     double xla = 0, yla = 0, xlb = 0, ylb = 0, xlc = 0, ylc = 0;
312     HYDROData_Lambert93::toGeo( xca, yca, yla, xla );
313     HYDROData_Lambert93::toGeo( xcb, ycb, ylb, xlb );
314     HYDROData_Lambert93::toGeo( xcc, ycc, ylc, xlc );
315
316     aLPointA = QPointF( xla * 3600.0, yla * 3600.0 ); // convert degrees to seconds
317     aLPointB = QPointF( xlb * 3600.0, ylb * 3600.0 ); // convert degrees to seconds
318     aLPointC = QPointF( xlc * 3600.0, ylc * 3600.0 ); // convert degrees to seconds
319   }
320
321   anImageObj->SetTrsfMode( aTransformationMode );
322   anImageObj->SetTrsfPoints( aPointA, aPointB, aPointC,
323                              aLPointA, aLPointB, aLPointC,
324                              aCPointA, aCPointB, aCPointC );
325
326   if( !myIsEdit )
327   {
328     // Set imported file name for image
329     QString aFilePath = aPanel->getFileName();
330     anImageObj->SetFilePath( aFilePath );
331   }
332    
333   // must be done after all checks and before calling SetVisible() method below
334   closePreview();
335
336   if( !myIsEdit )
337     module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), anImageObj, true );
338
339   if( myIsEdit )
340     anImageObj->Update();
341
342   theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;
343   return true;
344 }
345
346 void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
347 {
348   HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
349
350   myImage = theImage;
351
352   if( myPreviewPrs ) // if the image is changed by choosing another file
353   {
354     myPreviewPrs->setImage( myImage );
355     myPreviewPrs->compute();
356
357     if( myPreviewViewManager )
358     {
359       if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
360       {
361         if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
362         {
363           aViewPort->onBoundingRectChanged();
364           aViewPort->fitAll();
365         }
366       }
367     }
368   }
369   else
370   {
371     LightApp_Application* anApp = module()->getApp();
372
373     myActiveViewManager = anApp->activeViewManager();
374
375     myPreviewPrs = new HYDROGUI_PrsImage( myIsEdit ? myEditedObject : 0 );
376     myPreviewPrs->setImage( myImage );
377     myPreviewPrs->compute();
378
379     myPreviewViewManager =
380       dynamic_cast<GraphicsView_ViewManager*>( anApp->createViewManager( GraphicsView_Viewer::Type() ) );
381     if( myPreviewViewManager )
382     {
383       connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
384                this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
385
386       module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_TransformImage );
387       myPreviewViewManager->setTitle( tr( "TRANSFORM_IMAGE" ) );
388       if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
389       {
390         if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
391         {
392           //aViewPort->setMousePositionEnabled( true ); //ouv: temporarily commented
393
394           aViewPort->addItem( myPreviewPrs );
395           aViewPort->fitAll();
396
397           myPreviewPrs->setIsTransformationPointPreview( true );
398         }
399         connect( aViewer, SIGNAL( selectionChanged( GV_SelectionChangeStatus ) ),
400                  this, SLOT( onPointSelected() ) );
401       }
402     }
403
404     QString anImageName;
405     if( myIsEdit )
406     {
407       if( !myEditedObject.IsNull() )
408         anImageName = myEditedObject->GetName();
409     }
410     else
411       anImageName = HYDROGUI_Tool::GenerateObjectName( module(), "Image" );
412     aPanel->setImageName( anImageName );
413   }
414
415   aPanel->setImageSize( myImage.size() );
416
417   aPanel->initializePointSelection();
418   onPointSelected( false );
419 }
420
421 void HYDROGUI_ImportImageOp::onActivatePointSelection( int thePointType )
422 {
423   myPointType = thePointType;
424   if( myPreviewPrs )
425     myPreviewPrs->setTransformationPointType( thePointType );
426   if( myRefPreviewPrs )
427     myRefPreviewPrs->setTransformationPointType( thePointType );
428 }
429
430 void HYDROGUI_ImportImageOp::onPointCoordChanged( bool theIsRef,
431                                                   int thePointType,
432                                                   bool theIsY,
433                                                   int theValue )
434 {
435   if( !theIsRef && myPreviewPrs )
436     myPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue );
437   else if( theIsRef && myRefPreviewPrs )
438     myRefPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue );
439 }
440
441 void HYDROGUI_ImportImageOp::onModeActivated( int theMode )
442 {
443   HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
444
445   QString aRefImageName;
446   if( theMode == HYDROGUI_ImportImageDlg::RefImage )
447   {
448     aRefImageName = aPanel->getRefImageName();
449     if( aRefImageName.isEmpty() )
450       return; // do nothing in this case to avoid visual moving of preview prs
451   }
452   onRefImageActivated( aRefImageName );
453 }
454
455 void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName )
456 {
457   myRefTransform.reset();
458
459   GraphicsView_ViewPort* aViewPort = 0;
460   if( myPreviewViewManager )
461     if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
462       aViewPort = aViewer->getActiveViewPort();
463
464   if( !aViewPort )
465     return;
466
467   if( myPreviewPrs )
468     myPreviewPrs->setCaption( QString() );
469
470   if( myRefPreviewPrs )
471   {
472     myRefPreviewPrs->setCaption( QString() );
473     aViewPort->removeItem( myRefPreviewPrs );
474
475     delete myRefPreviewPrs;
476     myRefPreviewPrs = 0;
477   }
478
479   QImage anImage;
480   Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast(
481     HYDROGUI_Tool::FindObjectByName( module(), theName, KIND_IMAGE ) );
482   if( !anImageObj.IsNull() )
483   {
484     anImage = anImageObj->Image();
485     myRefTransform = anImageObj->Trsf();
486
487     myRefPreviewPrs = new HYDROGUI_PrsImage( anImageObj );
488     myRefPreviewPrs->setImage( anImage );
489     myRefPreviewPrs->compute();
490
491     myRefPreviewPrs->setIsTransformationPointPreview( true );
492     myRefPreviewPrs->setTransformationPointType( myPointType );
493
494     // vertically shift the reference prs relatively to the main prs
495     if( myPreviewPrs )
496     {
497       myPreviewPrs->setCaption( tr( "IMPORTED_IMAGE" ) );
498
499       QImage anImage = myPreviewPrs->getImage();
500       myRefPreviewPrs->moveBy( 0, anImage.height() + 60 );
501       myRefPreviewPrs->setCaption( tr( "REFERENCE_IMAGE" ) );
502     }
503
504     aViewPort->addItem( myRefPreviewPrs );
505   }
506
507   aViewPort->fitAll();
508
509   HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
510
511   aPanel->setImageSize( anImage.size(), true );
512
513   aPanel->initializePointSelection();
514   onPointSelected( true );
515 }
516
517 void HYDROGUI_ImportImageOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
518 {
519   closePreview();
520 }
521
522 void HYDROGUI_ImportImageOp::onPointSelected()
523 {
524   onPointSelected( myRefPreviewPrs && myRefPreviewPrs->isSelected() );
525 }
526
527 void HYDROGUI_ImportImageOp::onPointSelected( bool theIsRefImage )
528 {
529   HYDROGUI_PrsImage* aPrs = theIsRefImage ? myRefPreviewPrs : myPreviewPrs;
530   if( !aPrs )
531     return;
532
533   HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
534
535   const HYDROGUI_PrsImage::TransformationPointMap& aPointMap =
536     aPrs->getTransformationPointMap();
537   HYDROGUI_PrsImage::TransformationPointMapIterator anIter( aPointMap );
538   while( anIter.hasNext() )
539   {
540     int aPointType = anIter.next().key();
541     const HYDROGUI_PrsImage::TransformationPoint& aTransformationPoint = anIter.value();
542     const QPoint& aPoint = aTransformationPoint.Point;
543
544     HYDROGUI_ImportImageDlg::TransformationData aData( aPoint, QPointF(), QPointF() );
545     aDataMap[ aPointType ] = aData;
546   }
547
548   ( (HYDROGUI_ImportImageDlg*)inputPanel() )->setTransformationDataMap( aDataMap, true, theIsRefImage );
549 }
550
551 void HYDROGUI_ImportImageOp::closePreview()
552 {
553   // It's very strange, but without calling this method (it's quite safe) a crash is stably reproduced.
554   // Scenario: create any non-Graphics view, activate import op, click apply.
555   // Result: a few SIGSEGVs coming from processEvents(), then crash.
556   if( myPreviewViewManager )
557     if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
558       if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
559         aViewPort->onBoundingRectChanged();
560
561   if( myPreviewPrs )
562   {
563     delete myPreviewPrs;
564     myPreviewPrs = 0;
565   }
566
567   if( myRefPreviewPrs )
568   {
569     delete myRefPreviewPrs;
570     myRefPreviewPrs = 0;
571   }
572
573   if( myPreviewViewManager )
574   {
575     disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
576                 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
577
578     module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
579     myPreviewViewManager = 0;
580   }
581
582   if( myActiveViewManager )
583     HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
584 }