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->setIsByTwoPoints( theIsByTwoPoints );
221 thePrs->setTransformationPointMap( aPointMap );
226 void HYDROGUI_ImportImageOp::computeTrsfData( HYDROData_Image::TransformationMode theTrsfMode,
227 bool theIsByTwoPoints,
228 const QPoint& theLocalPointA,
229 const QPoint& theLocalPointB,
230 const QPoint& theLocalPointC,
231 const QPointF& theGlobalPointA,
232 const QPointF& theGlobalPointB,
233 const QPointF& theGlobalPointC,
234 HYDROGUI_ImportImageDlg::TransformationDataMap& theDataMap ) const
236 // Build the local-global points map
237 HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
238 theDataMap[ HYDROGUI_PrsImage::PointA ] =
239 HYDROGUI_ImportImageDlg::ComputeTrsfData( theTrsfMode, theLocalPointA, theGlobalPointA );
240 theDataMap[ HYDROGUI_PrsImage::PointB ] =
241 HYDROGUI_ImportImageDlg::ComputeTrsfData( theTrsfMode, theLocalPointB, theGlobalPointB );
242 if ( !theIsByTwoPoints )
244 theDataMap[ HYDROGUI_PrsImage::PointC ] =
245 HYDROGUI_ImportImageDlg::ComputeTrsfData( theTrsfMode, theLocalPointC, theGlobalPointC );
249 void HYDROGUI_ImportImageOp::abortOperation()
253 HYDROGUI_Operation::abortOperation();
256 void HYDROGUI_ImportImageOp::commitOperation()
260 HYDROGUI_Operation::commitOperation();
263 HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const
265 HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportImageDlg( module(), getName() );
266 connect( aPanel, SIGNAL( createPreview( QImage ) ), SLOT( onCreatePreview( QImage ) ) );
267 connect( aPanel, SIGNAL( activatePointSelection( int ) ), SLOT( onActivatePointSelection( int ) ) );
268 connect( aPanel, SIGNAL( pointCoordChanged( bool, int, bool, int ) ),
269 SLOT( onPointCoordChanged( bool, int, bool, int ) ) );
270 connect( aPanel, SIGNAL( modeActivated( int ) ), SLOT( onModeActivated( int ) ) );
271 connect( aPanel, SIGNAL( refImageActivated( const QString& ) ),
272 SLOT( onRefImageActivated( const QString& ) ) );
273 connect( aPanel, SIGNAL( setCIsUsed( bool ) ), SLOT( onSetCIsUsed( bool ) ) );
277 void HYDROGUI_ImportImageOp::onSetCIsUsed( bool theCIsUsed )
281 myPreviewPrs->setIsByTwoPoints( !theCIsUsed );
283 if ( myRefPreviewPrs )
285 myRefPreviewPrs->setIsByTwoPoints( !theCIsUsed );
289 bool HYDROGUI_ImportImageOp::checkPoints( const QPointF& thePointA,
290 const QPointF& thePointB,
291 const QPointF& thePointC,
292 const bool theIsByTwoPoints,
293 const QString& theLineErrMsg,
294 const QString& thePoinErrMsg,
295 QString& theErrorMsg,
296 const bool theIsToCheckInvertibles ) const
298 double xa = thePointA.x();
299 double ya = thePointA.y();
300 double xb = thePointB.x();
301 double yb = thePointB.y();
302 double xc = thePointC.x();
303 double yc = thePointC.y();
305 if ( !theIsByTwoPoints )
307 // check that three input points don't belong to a single line
308 if ( ValuesEquals( ( yb - ya ) * ( xc - xa ), ( yc - ya ) * ( xb - xa ) ) )
310 theErrorMsg = theLineErrMsg;
314 if ( theIsToCheckInvertibles )
316 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
318 bool anIsInvertible = false;
319 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
320 if( !anIsInvertible )
322 theErrorMsg = tr( "TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED" );
329 // check that two points are not identical
330 if ( ValuesEquals( xa, xb ) && ValuesEquals( ya, yb ) )
332 theErrorMsg = thePoinErrMsg;
340 bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
341 QString& theErrorMsg )
343 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
345 QString anImageName = aPanel->getImageName();
346 if( anImageName.isEmpty() )
349 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) )
351 // check that there are no other objects with the same name in the document
352 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
353 if( !anObject.IsNull() )
355 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
360 HYDROGUI_ImportImageDlg::TransformationDataMap aMap;
361 if( !aPanel->getTransformationDataMap( aMap ) )
364 bool anIsByTwoPoints = aPanel->isByTwoPoints();
366 QPoint aPointA = aMap[ HYDROGUI_PrsImage::PointA ].ImagePoint;
367 QPoint aPointB = aMap[ HYDROGUI_PrsImage::PointB ].ImagePoint;
368 QPoint aPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) :
369 aMap[ HYDROGUI_PrsImage::PointC ].ImagePoint;
371 // first, we check correctness of image points
372 if ( !checkPoints( aPointA, aPointB, aPointC, anIsByTwoPoints,
373 tr( "POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ),
374 tr( "POINTS_A_B_ARE_IDENTICAL" ),
375 theErrorMsg, true ) )
378 Handle(HYDROData_Image) aRefImageObj;
379 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC( INT_MIN, INT_MIN );
381 HYDROData_Image::TransformationMode aTransformationMode =
382 (HYDROData_Image::TransformationMode)aPanel->getTransformationMode();
383 if ( aTransformationMode == HYDROData_Image::ReferenceImage )
385 QString aRefImageName = aPanel->getRefImageName();
386 if( aRefImageName.isEmpty() )
388 theErrorMsg = tr( "REFERENCE_IMAGE_IS_NOT_SELECTED" );
392 HYDROGUI_ImportImageDlg::TransformationDataMap aRefMap;
393 if( !aPanel->getTransformationDataMap( aRefMap, true ) )
396 aRefImageObj = Handle(HYDROData_Image)::DownCast(
397 HYDROGUI_Tool::FindObjectByName( module(), aRefImageName, KIND_IMAGE ) );
398 if( aRefImageObj.IsNull() )
401 aTrsfPointA = aRefMap[ HYDROGUI_PrsImage::PointA ].ImagePoint;
402 aTrsfPointB = aRefMap[ HYDROGUI_PrsImage::PointB ].ImagePoint;
403 if ( !anIsByTwoPoints )
404 aTrsfPointC = aRefMap[ HYDROGUI_PrsImage::PointC ].ImagePoint;
406 // the same check of correctness for the reference points
407 if ( !checkPoints( aTrsfPointA, aTrsfPointB, aTrsfPointC, anIsByTwoPoints,
408 tr( "REFERENCE_POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ),
409 tr( "REFERENCE_POINTS_A_B_ARE_IDENTICAL" ),
410 theErrorMsg, false ) )
415 if ( aTransformationMode == HYDROData_Image::ManualGeodesic )
417 aTrsfPointA = aMap[ HYDROGUI_PrsImage::PointA ].GeodesicPoint;
418 aTrsfPointB = aMap[ HYDROGUI_PrsImage::PointB ].GeodesicPoint;
419 if ( !anIsByTwoPoints )
420 aTrsfPointC = aMap[ HYDROGUI_PrsImage::PointC ].GeodesicPoint;
424 aTrsfPointA = aMap[ HYDROGUI_PrsImage::PointA ].CartesianPoint;
425 aTrsfPointB = aMap[ HYDROGUI_PrsImage::PointB ].CartesianPoint;
426 if ( !anIsByTwoPoints )
427 aTrsfPointC = aMap[ HYDROGUI_PrsImage::PointC ].CartesianPoint;
431 Handle(HYDROData_Image) anImageObj;
433 anImageObj = myEditedObject;
435 anImageObj = Handle(HYDROData_Image)::DownCast( doc()->CreateObject( KIND_IMAGE ) );
437 if( anImageObj.IsNull() )
440 anImageObj->SetName( anImageName );
441 anImageObj->SetImage( myImage );
442 anImageObj->SetLocalPoints( aPointA, aPointB, aPointC, false );
444 if ( aTransformationMode == HYDROData_Image::ReferenceImage )
446 anImageObj->SetReferencePoints( aRefImageObj,
447 aTrsfPointA, aTrsfPointB, aTrsfPointC );
451 anImageObj->SetGlobalPoints( aTransformationMode,
452 aTrsfPointA, aTrsfPointB, aTrsfPointC );
457 // Set imported file name for image
458 QString aFilePath = aPanel->getFileName();
459 anImageObj->SetFilePath( aFilePath );
462 // must be done after all checks and before calling SetVisible() method below
466 module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), anImageObj, true );
469 anImageObj->Update();
471 theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;
475 void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
477 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
481 if( myPreviewPrs ) // if the image is changed by choosing another file
483 myPreviewPrs->setImage( myImage );
484 myPreviewPrs->compute();
486 if( myPreviewViewManager )
488 if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
490 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
492 aViewPort->onBoundingRectChanged();
500 LightApp_Application* anApp = module()->getApp();
502 myActiveViewManager = anApp->activeViewManager();
504 myPreviewPrs = new HYDROGUI_PrsImage( myIsEdit ? myEditedObject : 0 );
505 myPreviewPrs->setImage( myImage );
506 myPreviewPrs->compute();
508 myPreviewViewManager =
509 dynamic_cast<GraphicsView_ViewManager*>( anApp->createViewManager( GraphicsView_Viewer::Type() ) );
510 if( myPreviewViewManager )
512 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
513 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
515 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_TransformImage );
516 myPreviewViewManager->setTitle( tr( "TRANSFORM_IMAGE" ) );
517 if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
519 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
521 //aViewPort->setMousePositionEnabled( true ); //ouv: temporarily commented
523 aViewPort->addItem( myPreviewPrs );
526 myPreviewPrs->setIsTransformationPointPreview( true );
528 connect( aViewer, SIGNAL( selectionChanged( GV_SelectionChangeStatus ) ),
529 this, SLOT( onPointSelected() ) );
536 if( !myEditedObject.IsNull() )
537 anImageName = myEditedObject->GetName();
540 anImageName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMAGE_NAME" ) );
541 aPanel->setImageName( anImageName );
544 aPanel->setImageSize( myImage.size() );
546 aPanel->initializePointSelection();
547 onPointSelected( false );
550 void HYDROGUI_ImportImageOp::onActivatePointSelection( int thePointType )
552 myPointType = thePointType;
554 myPreviewPrs->setTransformationPointType( thePointType );
555 if( myRefPreviewPrs )
556 myRefPreviewPrs->setTransformationPointType( thePointType );
559 void HYDROGUI_ImportImageOp::onPointCoordChanged( bool theIsRef,
564 if( !theIsRef && myPreviewPrs )
565 myPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue );
566 else if( theIsRef && myRefPreviewPrs )
567 myRefPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue );
570 void HYDROGUI_ImportImageOp::onModeActivated( int theMode )
572 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
574 QString aRefImageName;
575 if( theMode == HYDROData_Image::ReferenceImage )
577 aRefImageName = aPanel->getRefImageName();
578 if( aRefImageName.isEmpty() )
579 return; // do nothing in this case to avoid visual moving of preview prs
580 onRefImageActivated( aRefImageName );
584 if( myRefViewManager )
586 closeView( myRefViewManager );
591 void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName )
593 GraphicsView_ViewPort* aViewPort = 0;
595 LightApp_Application* anApp = module()->getApp();
596 ///// Get a view port for the reference image preview
597 if( myRefViewManager )
599 if( GraphicsView_Viewer* aViewer = myRefViewManager->getViewer() )
601 aViewPort = aViewer->getActiveViewPort();
606 anApp = module()->getApp();
607 // Init reference image preview
609 dynamic_cast<GraphicsView_ViewManager*>( anApp->createViewManager( GraphicsView_Viewer::Type() ) );
610 if( myRefViewManager )
612 connect( myRefViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
613 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
615 module()->setViewManagerRole( myRefViewManager, HYDROGUI_Module::VMR_ReferenceImage );
616 myRefViewManager->setTitle( tr( "REFERENCE_IMAGE" ) );
617 if( GraphicsView_Viewer* aViewer = myRefViewManager->getViewer() )
619 aViewPort = aViewer->getActiveViewPort();
620 connect( aViewer, SIGNAL( selectionChanged( GV_SelectionChangeStatus ) ),
621 this, SLOT( onRefPointSelected() ) );
629 // Remove the old presentation of the reference image if any
630 if( myRefPreviewPrs )
632 myRefPreviewPrs->setCaption( QString() );
633 aViewPort->removeItem( myRefPreviewPrs );
635 delete myRefPreviewPrs;
639 // Create a new reference image presentation
641 Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast(
642 HYDROGUI_Tool::FindObjectByName( module(), theName, KIND_IMAGE ) );
643 if( !anImageObj.IsNull() )
645 anImage = anImageObj->Image();
647 myRefPreviewPrs = new HYDROGUI_PrsImage( anImageObj );
648 myRefPreviewPrs->setImage( anImage );
649 myRefPreviewPrs->compute();
651 myRefPreviewPrs->setIsTransformationPointPreview( true );
652 myRefPreviewPrs->setTransformationPointType( myPointType );
654 // Add the new reference image presentation to the appropriate view
655 aViewPort->addItem( myRefPreviewPrs );
660 // Split views horizontally
661 if( anApp->desktop()->inherits( "STD_TabDesktop" ) )
663 qApp->processEvents();
664 QtxWorkstack* aWorkstack = ( (STD_TabDesktop*)anApp->desktop() )->workstack();
665 aViewPort->activateWindow();
667 aViewPort->setFocus(Qt::ActiveWindowFocusReason);
668 aWorkstack->splitHorizontal();
671 // Initialize the dialog
672 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
673 aPanel->setImageSize( anImage.size(), true );
674 aPanel->initializePointSelection();
675 onPointSelected( true );
678 void HYDROGUI_ImportImageOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
683 void HYDROGUI_ImportImageOp::onPointSelected()
685 onPointSelected( myRefPreviewPrs && myRefPreviewPrs->isSelected() );
688 void HYDROGUI_ImportImageOp::onRefPointSelected()
690 onPointSelected( true );
693 void HYDROGUI_ImportImageOp::onPointSelected( bool theIsRefImage )
695 HYDROGUI_PrsImage* aPrs = theIsRefImage ? myRefPreviewPrs : myPreviewPrs;
699 HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
701 const HYDROGUI_PrsImage::TransformationPointMap& aPointMap =
702 aPrs->getTransformationPointMap();
704 HYDROGUI_PrsImage::TransformationPointMapIterator anIter( aPointMap );
705 while( anIter.hasNext() )
707 int aPointType = anIter.next().key();
708 const HYDROGUI_PrsImage::TransformationPoint& aTransformationPoint = anIter.value();
709 const QPoint& aPoint = aTransformationPoint.Point;
711 HYDROGUI_ImportImageDlg::TransformationData aData( aPoint, QPointF(), QPointF() );
712 aDataMap[ aPointType ] = aData;
715 ( (HYDROGUI_ImportImageDlg*)inputPanel() )->setTransformationDataMap( aDataMap, true, theIsRefImage );
718 void HYDROGUI_ImportImageOp::closePreview()
720 closeView( myPreviewViewManager );
721 closeView( myRefViewManager );
723 if( myActiveViewManager )
724 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
727 void HYDROGUI_ImportImageOp::closeView( GraphicsView_ViewManager* &aViewMgr )
731 GraphicsView_ViewPort* aViewPort = 0;
732 if( GraphicsView_Viewer* aViewer = aViewMgr->getViewer() )
734 aViewPort = aViewer->getActiveViewPort();
736 disconnect( aViewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
737 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
739 // Nullify appropriate presentation pointer
740 HYDROGUI_PrsImage* aPrs = 0;
741 switch ( module()->getViewManagerRole( aViewMgr ) )
743 case HYDROGUI_Module::VMR_ReferenceImage:
744 aPrs = myRefPreviewPrs;
747 case HYDROGUI_Module::VMR_TransformImage:
752 // Remove the appropriate presentation from the view
753 if( aPrs && aViewPort )
755 aViewPort->removeItem( aPrs );
760 module()->getApp()->removeViewManager( aViewMgr ); // aViewMgr is deleted here