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