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_ImportImageOp.h"
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"
32 #include <HYDROData_Iterator.h>
33 #include <HYDROData_Tool.h>
35 #include <GraphicsView_ViewManager.h>
36 #include <GraphicsView_ViewPort.h>
37 #include <GraphicsView_Viewer.h>
39 #include <LightApp_Application.h>
40 #include <LightApp_UpdateFlags.h>
42 #include <STD_TabDesktop.h>
43 #include <SUIT_Desktop.h>
44 #include <QtxWorkstack.h>
45 #include <QApplication>
47 HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule,
48 const bool theIsEdit )
49 : HYDROGUI_Operation( theModule ),
50 myIsEdit( theIsEdit ),
52 myActiveViewManager( 0 ),
53 myPreviewViewManager( 0 ),
54 myRefViewManager( 0 ),
57 myPointType( HYDROGUI_PrsImage::None )
59 setName( theIsEdit ? tr( "EDIT_IMPORTED_IMAGE" ) : tr( "IMPORT_IMAGE" ) );
62 HYDROGUI_ImportImageOp::~HYDROGUI_ImportImageOp()
66 void HYDROGUI_ImportImageOp::startOperation()
68 HYDROGUI_Operation::startOperation();
70 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
72 aPanel->setIsEdit( myIsEdit );
74 QString aRefImageName;
78 myEditedObject = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
79 if( !myEditedObject.IsNull() )
81 QImage anImage = myEditedObject->Image();
82 bool anIsByTwoPoints = myEditedObject->IsByTwoPoints();
84 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
85 myEditedObject->GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC );
87 // Create the edited image preview presentation in the viewer
88 onCreatePreview( anImage );
90 // Set transformation local points A,B,C to the image preview presentation
91 setPresentationTrsfPoints( myPreviewPrs, anIsByTwoPoints, aLocalPointA,
92 aLocalPointB, aLocalPointC );
94 // Build the existing image local and global points mapping
95 // according to the current transformation mode.
96 HYDROData_Image::TransformationMode aTrsfMode = myEditedObject->GetTrsfMode();
97 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
98 HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
99 if ( aTrsfMode == HYDROData_Image::ReferenceImage )
101 // Compute global points using the transformation matrix of the reference image
102 Handle(HYDROData_Image) aRefImage = myEditedObject->GetTrsfReferenceImage();
103 if ( !aRefImage.IsNull() )
105 QTransform aRefTrsf = aRefImage->Trsf(); // The reference image transformation matrix
106 aTrsfPointA = aRefTrsf.map( aLocalPointA ); // Compute the global point A
107 aTrsfPointB = aRefTrsf.map( aLocalPointB ); // Compute the global point B
108 if ( !anIsByTwoPoints )
110 aTrsfPointC = aRefTrsf.map( aLocalPointC ); // Compute the global point C if used
112 // Build the local-global points map
113 // Use the reference image transformation mode for interpreting global points
114 computeTrsfData( aRefImage->GetTrsfMode(), anIsByTwoPoints, aLocalPointA, aLocalPointB, aLocalPointC,
115 aTrsfPointA, aTrsfPointB, aTrsfPointC, aDataMap );
120 // Get global points from the edited image
121 myEditedObject->GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC );
122 // Build the local-global points map
123 computeTrsfData( aTrsfMode, anIsByTwoPoints, aLocalPointA, aLocalPointB, aLocalPointC,
124 aTrsfPointA, aTrsfPointB, aTrsfPointC, aDataMap );
127 // Initialize the dialog mode, local and global coordinates
128 // except coordinates on the reference image
129 aPanel->setTransformationMode( aTrsfMode );
130 aPanel->setTransformationDataMap( aDataMap );
131 aPanel->setByTwoPoints( anIsByTwoPoints );
133 // Set points of the reference image
134 if ( aTrsfMode == HYDROData_Image::ReferenceImage )
136 Handle(HYDROData_Image) aRefImage;
137 myEditedObject->GetReferencePoints( aRefImage,
138 aTrsfPointA, aTrsfPointB, aTrsfPointC );
139 if ( !aRefImage.IsNull() )
141 aRefImageName = aRefImage->GetName();
143 // Create the reference image presentation in the viewer
144 onRefImageActivated( aRefImageName );
146 // Set transformation points A,B,C to the reference image presentation
147 setPresentationTrsfPoints( myRefPreviewPrs, anIsByTwoPoints, aTrsfPointA.toPoint(),
148 aTrsfPointB.toPoint(), aTrsfPointC.toPoint() );
150 // Prepare A, B, C points on the reference image
151 HYDROGUI_ImportImageDlg::TransformationDataMap aRefDataMap;
152 aRefDataMap[ HYDROGUI_PrsImage::PointA ] =
153 HYDROGUI_ImportImageDlg::TransformationData( aTrsfPointA.toPoint() );
154 aRefDataMap[ HYDROGUI_PrsImage::PointB ] =
155 HYDROGUI_ImportImageDlg::TransformationData( aTrsfPointB.toPoint() );
156 if ( !anIsByTwoPoints )
157 aRefDataMap[ HYDROGUI_PrsImage::PointC ] =
158 HYDROGUI_ImportImageDlg::TransformationData( aTrsfPointC.toPoint() );
160 // Initialize the dialog's A, B, C points coordinates of the reference image
161 aPanel->setTransformationDataMap( aRefDataMap, true, true );
167 // Collect information about existing images and initialize the combobox
168 // reference image selector in the dialog.
169 HYDROGUI_ImportImageDlg::PrsPointDataList aPrsPointDataList;
170 HYDROData_Iterator anIterator( doc(), KIND_IMAGE );
171 for( ; anIterator.More(); anIterator.Next() )
173 Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( anIterator.Current() );
174 if( !anImageObj.IsNull() )
176 if( myIsEdit && IsEqual( anImageObj, myEditedObject ) )
179 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
180 anImageObj->GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC );
182 HYDROData_Image::TransformationMode aImgTrsfMode;
183 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
184 anImageObj->GetGlobalPoints( aImgTrsfMode,
185 aTrsfPointA, aTrsfPointB, aTrsfPointC );
187 HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
188 computeTrsfData( aImgTrsfMode, false, aLocalPointA, aLocalPointB, aLocalPointC,
189 aTrsfPointA, aTrsfPointB, aTrsfPointC, aDataMap );
191 HYDROGUI_ImportImageDlg::PrsPointData aPrsPointData( anImageObj->GetName(), aDataMap );
192 aPrsPointDataList.append( aPrsPointData );
196 // Initialize the combobox in the dialog with the list of available reference images
197 aPanel->setPrsPointDataList( aPrsPointDataList );
198 // Select the current reference image in the dialog combobox
199 aPanel->setRefImageName( aRefImageName );
202 void HYDROGUI_ImportImageOp::setPresentationTrsfPoints( HYDROGUI_PrsImage* thePrs,
203 bool theIsByTwoPoints,
204 const QPoint theLocalPointA,
205 const QPoint theLocalPointB,
206 const QPoint theLocalPointC )
208 // Set transformation points A,B,C to the image presentation
211 HYDROGUI_PrsImage::TransformationPointMap aPointMap =
212 thePrs->getTransformationPointMap();
213 if( !aPointMap.isEmpty() )
215 aPointMap[ HYDROGUI_PrsImage::PointA ].Point = theLocalPointA;
216 aPointMap[ HYDROGUI_PrsImage::PointB ].Point = theLocalPointB;
217 if ( !theIsByTwoPoints )
218 aPointMap[ HYDROGUI_PrsImage::PointC ].Point = theLocalPointC;
220 thePrs->setTransformationPointMap( aPointMap );
225 void HYDROGUI_ImportImageOp::computeTrsfData( HYDROData_Image::TransformationMode theTrsfMode,
226 bool theIsByTwoPoints,
227 const QPoint& theLocalPointA,
228 const QPoint& theLocalPointB,
229 const QPoint& theLocalPointC,
230 const QPointF& theGlobalPointA,
231 const QPointF& theGlobalPointB,
232 const QPointF& theGlobalPointC,
233 HYDROGUI_ImportImageDlg::TransformationDataMap& theDataMap ) const
235 // Build the local-global points map
236 HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
237 theDataMap[ HYDROGUI_PrsImage::PointA ] =
238 HYDROGUI_ImportImageDlg::ComputeTrsfData( theTrsfMode, theLocalPointA, theGlobalPointA );
239 theDataMap[ HYDROGUI_PrsImage::PointB ] =
240 HYDROGUI_ImportImageDlg::ComputeTrsfData( theTrsfMode, theLocalPointB, theGlobalPointB );
241 if ( !theIsByTwoPoints )
243 theDataMap[ HYDROGUI_PrsImage::PointC ] =
244 HYDROGUI_ImportImageDlg::ComputeTrsfData( theTrsfMode, theLocalPointC, theGlobalPointC );
248 void HYDROGUI_ImportImageOp::abortOperation()
252 HYDROGUI_Operation::abortOperation();
255 void HYDROGUI_ImportImageOp::commitOperation()
259 HYDROGUI_Operation::commitOperation();
262 HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const
264 HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportImageDlg( module(), getName() );
265 connect( aPanel, SIGNAL( createPreview( QImage ) ),
266 this, SLOT( onCreatePreview( QImage ) ) );
267 connect( aPanel, SIGNAL( activatePointSelection( int ) ),
268 this, SLOT( onActivatePointSelection( int ) ) );
269 connect( aPanel, SIGNAL( pointCoordChanged( bool, int, bool, int ) ),
270 this, SLOT( onPointCoordChanged( bool, int, bool, int ) ) );
271 connect( aPanel, SIGNAL( modeActivated( int ) ),
272 this, SLOT( onModeActivated( int ) ) );
273 connect( aPanel, SIGNAL( refImageActivated( const QString& ) ),
274 this, SLOT( onRefImageActivated( const QString& ) ) );
278 bool HYDROGUI_ImportImageOp::checkPoints( const QPointF& thePointA,
279 const QPointF& thePointB,
280 const QPointF& thePointC,
281 const bool theIsByTwoPoints,
282 const QString& theLineErrMsg,
283 const QString& thePoinErrMsg,
284 QString& theErrorMsg,
285 const bool theIsToCheckInvertibles ) const
287 double xa = thePointA.x();
288 double ya = thePointA.y();
289 double xb = thePointB.x();
290 double yb = thePointB.y();
291 double xc = thePointC.x();
292 double yc = thePointC.y();
294 if ( !theIsByTwoPoints )
296 // check that three input points don't belong to a single line
297 if ( ValuesEquals( ( yb - ya ) * ( xc - xa ), ( yc - ya ) * ( xb - xa ) ) )
299 theErrorMsg = theLineErrMsg;
305 // check that two points are not identical
306 if ( ValuesEquals( xa, ya ) && ValuesEquals( xb, yb ) )
308 theErrorMsg = thePoinErrMsg;
313 if ( theIsToCheckInvertibles )
315 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
317 bool anIsInvertible = false;
318 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
319 if( !anIsInvertible )
321 theErrorMsg = tr( "TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED" );
329 bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
330 QString& theErrorMsg )
332 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
334 QString anImageName = aPanel->getImageName();
335 if( anImageName.isEmpty() )
338 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) )
340 // check that there are no other objects with the same name in the document
341 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
342 if( !anObject.IsNull() )
344 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
349 HYDROGUI_ImportImageDlg::TransformationDataMap aMap;
350 if( !aPanel->getTransformationDataMap( aMap ) )
353 bool anIsByTwoPoints = aPanel->isByTwoPoints();
355 QPoint aPointA = aMap[ HYDROGUI_PrsImage::PointA ].ImagePoint;
356 QPoint aPointB = aMap[ HYDROGUI_PrsImage::PointB ].ImagePoint;
357 QPoint aPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) :
358 aMap[ HYDROGUI_PrsImage::PointC ].ImagePoint;
360 // first, we check correctness of image points
361 if ( !checkPoints( aPointA, aPointB, aPointC, anIsByTwoPoints,
362 tr( "POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ),
363 tr( "POINTS_A_B_ARE_IDENTICAL" ),
364 theErrorMsg, true ) )
367 Handle(HYDROData_Image) aRefImageObj;
368 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC( INT_MIN, INT_MIN );
370 HYDROData_Image::TransformationMode aTransformationMode =
371 (HYDROData_Image::TransformationMode)aPanel->getTransformationMode();
372 if ( aTransformationMode == HYDROData_Image::ReferenceImage )
374 QString aRefImageName = aPanel->getRefImageName();
375 if( aRefImageName.isEmpty() )
377 theErrorMsg = tr( "REFERENCE_IMAGE_IS_NOT_SELECTED" );
381 HYDROGUI_ImportImageDlg::TransformationDataMap aRefMap;
382 if( !aPanel->getTransformationDataMap( aRefMap, true ) )
385 aRefImageObj = Handle(HYDROData_Image)::DownCast(
386 HYDROGUI_Tool::FindObjectByName( module(), aRefImageName, KIND_IMAGE ) );
387 if( aRefImageObj.IsNull() )
390 aTrsfPointA = aRefMap[ HYDROGUI_PrsImage::PointA ].ImagePoint;
391 aTrsfPointB = aRefMap[ HYDROGUI_PrsImage::PointB ].ImagePoint;
392 if ( !anIsByTwoPoints )
393 aTrsfPointC = aRefMap[ HYDROGUI_PrsImage::PointC ].ImagePoint;
395 // the same check of correctness for the reference points
396 if ( !checkPoints( aTrsfPointA, aTrsfPointB, aTrsfPointC, anIsByTwoPoints,
397 tr( "REFERENCE_POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ),
398 tr( "REFERENCE_POINTS_A_B_ARE_IDENTICAL" ),
399 theErrorMsg, false ) )
404 if ( aTransformationMode == HYDROData_Image::ManualGeodesic )
406 aTrsfPointA = aMap[ HYDROGUI_PrsImage::PointA ].GeodesicPoint;
407 aTrsfPointB = aMap[ HYDROGUI_PrsImage::PointB ].GeodesicPoint;
408 if ( !anIsByTwoPoints )
409 aTrsfPointC = aMap[ HYDROGUI_PrsImage::PointC ].GeodesicPoint;
413 aTrsfPointA = aMap[ HYDROGUI_PrsImage::PointA ].CartesianPoint;
414 aTrsfPointB = aMap[ HYDROGUI_PrsImage::PointB ].CartesianPoint;
415 if ( !anIsByTwoPoints )
416 aTrsfPointC = aMap[ HYDROGUI_PrsImage::PointC ].CartesianPoint;
420 Handle(HYDROData_Image) anImageObj;
422 anImageObj = myEditedObject;
424 anImageObj = Handle(HYDROData_Image)::DownCast( doc()->CreateObject( KIND_IMAGE ) );
426 if( anImageObj.IsNull() )
429 anImageObj->SetName( anImageName );
430 anImageObj->SetImage( myImage );
431 anImageObj->SetLocalPoints( aPointA, aPointB, aPointC, false );
433 if ( aTransformationMode == HYDROData_Image::ReferenceImage )
435 anImageObj->SetReferencePoints( aRefImageObj,
436 aTrsfPointA, aTrsfPointB, aTrsfPointC );
440 anImageObj->SetGlobalPoints( aTransformationMode,
441 aTrsfPointA, aTrsfPointB, aTrsfPointC );
446 // Set imported file name for image
447 QString aFilePath = aPanel->getFileName();
448 anImageObj->SetFilePath( aFilePath );
451 // must be done after all checks and before calling SetVisible() method below
455 module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), anImageObj, true );
458 anImageObj->Update();
460 theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;
464 void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
466 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
470 if( myPreviewPrs ) // if the image is changed by choosing another file
472 myPreviewPrs->setImage( myImage );
473 myPreviewPrs->compute();
475 if( myPreviewViewManager )
477 if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
479 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
481 aViewPort->onBoundingRectChanged();
489 LightApp_Application* anApp = module()->getApp();
491 myActiveViewManager = anApp->activeViewManager();
493 myPreviewPrs = new HYDROGUI_PrsImage( myIsEdit ? myEditedObject : 0 );
494 myPreviewPrs->setImage( myImage );
495 myPreviewPrs->compute();
497 myPreviewViewManager =
498 dynamic_cast<GraphicsView_ViewManager*>( anApp->createViewManager( GraphicsView_Viewer::Type() ) );
499 if( myPreviewViewManager )
501 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
502 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
504 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_TransformImage );
505 myPreviewViewManager->setTitle( tr( "TRANSFORM_IMAGE" ) );
506 if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
508 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
510 //aViewPort->setMousePositionEnabled( true ); //ouv: temporarily commented
512 aViewPort->addItem( myPreviewPrs );
515 myPreviewPrs->setIsTransformationPointPreview( true );
517 connect( aViewer, SIGNAL( selectionChanged( GV_SelectionChangeStatus ) ),
518 this, SLOT( onPointSelected() ) );
525 if( !myEditedObject.IsNull() )
526 anImageName = myEditedObject->GetName();
529 anImageName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMAGE_NAME" ) );
530 aPanel->setImageName( anImageName );
533 aPanel->setImageSize( myImage.size() );
535 aPanel->initializePointSelection();
536 onPointSelected( false );
539 void HYDROGUI_ImportImageOp::onActivatePointSelection( int thePointType )
541 myPointType = thePointType;
543 myPreviewPrs->setTransformationPointType( thePointType );
544 if( myRefPreviewPrs )
545 myRefPreviewPrs->setTransformationPointType( thePointType );
548 void HYDROGUI_ImportImageOp::onPointCoordChanged( bool theIsRef,
553 if( !theIsRef && myPreviewPrs )
554 myPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue );
555 else if( theIsRef && myRefPreviewPrs )
556 myRefPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue );
559 void HYDROGUI_ImportImageOp::onModeActivated( int theMode )
561 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
563 QString aRefImageName;
564 if( theMode == HYDROData_Image::ReferenceImage )
566 aRefImageName = aPanel->getRefImageName();
567 if( aRefImageName.isEmpty() )
568 return; // do nothing in this case to avoid visual moving of preview prs
569 onRefImageActivated( aRefImageName );
573 if( myRefViewManager )
575 closeView( myRefViewManager );
580 void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName )
582 GraphicsView_ViewPort* aViewPort = 0;
584 LightApp_Application* anApp = module()->getApp();
585 ///// Get a view port for the reference image preview
586 if( myRefViewManager )
588 if( GraphicsView_Viewer* aViewer = myRefViewManager->getViewer() )
590 aViewPort = aViewer->getActiveViewPort();
595 anApp = module()->getApp();
596 // Init reference image preview
598 dynamic_cast<GraphicsView_ViewManager*>( anApp->createViewManager( GraphicsView_Viewer::Type() ) );
599 if( myRefViewManager )
601 connect( myRefViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
602 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
604 module()->setViewManagerRole( myRefViewManager, HYDROGUI_Module::VMR_ReferenceImage );
605 myRefViewManager->setTitle( tr( "REFERENCE_IMAGE" ) );
606 if( GraphicsView_Viewer* aViewer = myRefViewManager->getViewer() )
608 aViewPort = aViewer->getActiveViewPort();
609 connect( aViewer, SIGNAL( selectionChanged( GV_SelectionChangeStatus ) ),
610 this, SLOT( onRefPointSelected() ) );
618 // Remove the old presentation of the reference image if any
619 if( myRefPreviewPrs )
621 myRefPreviewPrs->setCaption( QString() );
622 aViewPort->removeItem( myRefPreviewPrs );
624 delete myRefPreviewPrs;
628 // Create a new reference image presentation
630 Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast(
631 HYDROGUI_Tool::FindObjectByName( module(), theName, KIND_IMAGE ) );
632 if( !anImageObj.IsNull() )
634 anImage = anImageObj->Image();
636 myRefPreviewPrs = new HYDROGUI_PrsImage( anImageObj );
637 myRefPreviewPrs->setImage( anImage );
638 myRefPreviewPrs->compute();
640 myRefPreviewPrs->setIsTransformationPointPreview( true );
641 myRefPreviewPrs->setTransformationPointType( myPointType );
643 // Add the new reference image presentation to the appropriate view
644 aViewPort->addItem( myRefPreviewPrs );
649 // Split views horizontally
650 if( anApp->desktop()->inherits( "STD_TabDesktop" ) )
652 qApp->processEvents();
653 QtxWorkstack* aWorkstack = ( (STD_TabDesktop*)anApp->desktop() )->workstack();
654 aViewPort->activateWindow();
656 aViewPort->setFocus(Qt::ActiveWindowFocusReason);
657 aWorkstack->splitHorizontal();
660 // Initialize the dialog
661 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
662 aPanel->setImageSize( anImage.size(), true );
663 aPanel->initializePointSelection();
664 onPointSelected( true );
667 void HYDROGUI_ImportImageOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
672 void HYDROGUI_ImportImageOp::onPointSelected()
674 onPointSelected( myRefPreviewPrs && myRefPreviewPrs->isSelected() );
677 void HYDROGUI_ImportImageOp::onRefPointSelected()
679 onPointSelected( true );
682 void HYDROGUI_ImportImageOp::onPointSelected( bool theIsRefImage )
684 HYDROGUI_PrsImage* aPrs = theIsRefImage ? myRefPreviewPrs : myPreviewPrs;
688 HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
690 const HYDROGUI_PrsImage::TransformationPointMap& aPointMap =
691 aPrs->getTransformationPointMap();
692 HYDROGUI_PrsImage::TransformationPointMapIterator anIter( aPointMap );
693 while( anIter.hasNext() )
695 int aPointType = anIter.next().key();
696 const HYDROGUI_PrsImage::TransformationPoint& aTransformationPoint = anIter.value();
697 const QPoint& aPoint = aTransformationPoint.Point;
699 HYDROGUI_ImportImageDlg::TransformationData aData( aPoint, QPointF(), QPointF() );
700 aDataMap[ aPointType ] = aData;
703 ( (HYDROGUI_ImportImageDlg*)inputPanel() )->setTransformationDataMap( aDataMap, true, theIsRefImage );
706 void HYDROGUI_ImportImageOp::closePreview()
708 closeView( myPreviewViewManager );
709 closeView( myRefViewManager );
711 if( myActiveViewManager )
712 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
715 void HYDROGUI_ImportImageOp::closeView( GraphicsView_ViewManager* &aViewMgr )
719 GraphicsView_ViewPort* aViewPort = 0;
720 if( GraphicsView_Viewer* aViewer = aViewMgr->getViewer() )
722 aViewPort = aViewer->getActiveViewPort();
724 disconnect( aViewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
725 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
727 // Nullify appropriate presentation pointer
728 HYDROGUI_PrsImage* aPrs = 0;
729 switch ( module()->getViewManagerRole( aViewMgr ) )
731 case HYDROGUI_Module::VMR_ReferenceImage:
732 aPrs = myRefPreviewPrs;
735 case HYDROGUI_Module::VMR_TransformImage:
740 // Remove the appropriate presentation from the view
741 if( aPrs && aViewPort )
743 aViewPort->removeItem( aPrs );
748 module()->getApp()->removeViewManager( aViewMgr ); // aViewMgr is deleted here