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>
48 HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule,
49 const bool theIsEdit )
50 : HYDROGUI_Operation( theModule ),
51 myIsEdit( theIsEdit ),
53 myActiveViewManager( 0 ),
54 myPreviewViewManager( 0 ),
55 myRefViewManager( 0 ),
58 myPointType( HYDROGUI_PrsImage::None )
60 setName( theIsEdit ? tr( "EDIT_IMPORTED_IMAGE" ) : tr( "IMPORT_IMAGE" ) );
63 HYDROGUI_ImportImageOp::~HYDROGUI_ImportImageOp()
67 void HYDROGUI_ImportImageOp::startOperation()
69 HYDROGUI_Operation::startOperation();
71 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
73 aPanel->setIsEdit( myIsEdit );
75 QString aRefImageName;
79 myEditedObject = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
80 if( !myEditedObject.IsNull() )
82 QImage anImage = myEditedObject->Image();
83 bool anIsByTwoPoints = myEditedObject->IsByTwoPoints();
85 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
86 myEditedObject->GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC );
88 // Create the edited image preview presentation in the viewer
89 onCreatePreview( anImage );
91 // Set transformation local points A,B,C to the image preview presentation
92 setPresentationTrsfPoints( myPreviewPrs, anIsByTwoPoints, aLocalPointA,
93 aLocalPointB, aLocalPointC );
95 // Build the existing image local and global points mapping
96 // according to the current transformation mode.
97 HYDROData_Image::TransformationMode aTrsfMode = myEditedObject->GetTrsfMode();
98 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
99 HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
100 if ( aTrsfMode == HYDROData_Image::ReferenceImage )
102 // Compute global points using the transformation matrix of the reference image
103 Handle(HYDROData_Image) aRefImage = myEditedObject->GetTrsfReferenceImage();
104 if ( !aRefImage.IsNull() )
106 QTransform aRefTrsf = aRefImage->Trsf(); // The reference image transformation matrix
107 aTrsfPointA = aRefTrsf.map( aLocalPointA ); // Compute the global point A
108 aTrsfPointB = aRefTrsf.map( aLocalPointB ); // Compute the global point B
109 if ( !anIsByTwoPoints )
111 aTrsfPointC = aRefTrsf.map( aLocalPointC ); // Compute the global point C if used
113 // Build the local-global points map
114 // Use the reference image transformation mode for interpreting global points
115 computeTrsfData( aRefImage->GetTrsfMode(), anIsByTwoPoints, aLocalPointA, aLocalPointB, aLocalPointC,
116 aTrsfPointA, aTrsfPointB, aTrsfPointC, aDataMap );
121 // Get global points from the edited image
122 myEditedObject->GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC );
123 // Build the local-global points map
124 computeTrsfData( aTrsfMode, anIsByTwoPoints, aLocalPointA, aLocalPointB, aLocalPointC,
125 aTrsfPointA, aTrsfPointB, aTrsfPointC, aDataMap );
128 // Initialize the dialog mode, local and global coordinates
129 // except coordinates on the reference image
130 aPanel->setTransformationMode( aTrsfMode );
131 aPanel->setTransformationDataMap( aDataMap );
132 aPanel->setByTwoPoints( anIsByTwoPoints );
134 // Set points of the reference image
135 if ( aTrsfMode == HYDROData_Image::ReferenceImage )
137 Handle(HYDROData_Image) aRefImage;
138 myEditedObject->GetReferencePoints( aRefImage,
139 aTrsfPointA, aTrsfPointB, aTrsfPointC );
140 if ( !aRefImage.IsNull() )
142 aRefImageName = aRefImage->GetName();
144 // Create the reference image presentation in the viewer
145 onRefImageActivated( aRefImageName );
147 // Set transformation points A,B,C to the reference image presentation
148 setPresentationTrsfPoints( myRefPreviewPrs, anIsByTwoPoints, aTrsfPointA.toPoint(),
149 aTrsfPointB.toPoint(), aTrsfPointC.toPoint() );
151 // Prepare A, B, C points on the reference image
152 HYDROGUI_ImportImageDlg::TransformationDataMap aRefDataMap;
153 aRefDataMap[ HYDROGUI_PrsImage::PointA ] =
154 HYDROGUI_ImportImageDlg::TransformationData( aTrsfPointA.toPoint() );
155 aRefDataMap[ HYDROGUI_PrsImage::PointB ] =
156 HYDROGUI_ImportImageDlg::TransformationData( aTrsfPointB.toPoint() );
157 if ( !anIsByTwoPoints )
158 aRefDataMap[ HYDROGUI_PrsImage::PointC ] =
159 HYDROGUI_ImportImageDlg::TransformationData( aTrsfPointC.toPoint() );
161 // Initialize the dialog's A, B, C points coordinates of the reference image
162 aPanel->setTransformationDataMap( aRefDataMap, true, true );
168 // Collect information about existing images and initialize the combobox
169 // reference image selector in the dialog.
170 HYDROGUI_ImportImageDlg::PrsPointDataList aPrsPointDataList;
171 HYDROData_Iterator anIterator( doc(), KIND_IMAGE );
172 for( ; anIterator.More(); anIterator.Next() )
174 Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( anIterator.Current() );
175 if( !anImageObj.IsNull() )
177 if( myIsEdit && IsEqual( anImageObj, myEditedObject ) )
180 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
181 anImageObj->GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC );
183 HYDROData_Image::TransformationMode aImgTrsfMode;
184 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
185 anImageObj->GetGlobalPoints( aImgTrsfMode,
186 aTrsfPointA, aTrsfPointB, aTrsfPointC );
188 HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
189 computeTrsfData( aImgTrsfMode, false, aLocalPointA, aLocalPointB, aLocalPointC,
190 aTrsfPointA, aTrsfPointB, aTrsfPointC, aDataMap );
192 HYDROGUI_ImportImageDlg::PrsPointData aPrsPointData( anImageObj->GetName(), aDataMap );
193 aPrsPointDataList.append( aPrsPointData );
197 // Initialize the combobox in the dialog with the list of available reference images
198 aPanel->setPrsPointDataList( aPrsPointDataList );
199 // Select the current reference image in the dialog combobox
200 aPanel->setRefImageName( aRefImageName );
203 void HYDROGUI_ImportImageOp::setPresentationTrsfPoints( HYDROGUI_PrsImage* thePrs,
204 bool theIsByTwoPoints,
205 const QPoint theLocalPointA,
206 const QPoint theLocalPointB,
207 const QPoint theLocalPointC )
209 // Set transformation points A,B,C to the image presentation
212 HYDROGUI_PrsImage::TransformationPointMap aPointMap =
213 thePrs->getTransformationPointMap();
214 if( !aPointMap.isEmpty() )
216 aPointMap[ HYDROGUI_PrsImage::PointA ].Point = theLocalPointA;
217 aPointMap[ HYDROGUI_PrsImage::PointB ].Point = theLocalPointB;
218 if ( !theIsByTwoPoints )
219 aPointMap[ HYDROGUI_PrsImage::PointC ].Point = theLocalPointC;
221 thePrs->setIsByTwoPoints( theIsByTwoPoints );
222 thePrs->setTransformationPointMap( aPointMap );
227 void HYDROGUI_ImportImageOp::computeTrsfData( HYDROData_Image::TransformationMode theTrsfMode,
228 bool theIsByTwoPoints,
229 const QPoint& theLocalPointA,
230 const QPoint& theLocalPointB,
231 const QPoint& theLocalPointC,
232 const QPointF& theGlobalPointA,
233 const QPointF& theGlobalPointB,
234 const QPointF& theGlobalPointC,
235 HYDROGUI_ImportImageDlg::TransformationDataMap& theDataMap ) const
237 // Build the local-global points map
238 HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
239 theDataMap[ HYDROGUI_PrsImage::PointA ] =
240 HYDROGUI_ImportImageDlg::ComputeTrsfData( theTrsfMode, theLocalPointA, theGlobalPointA );
241 theDataMap[ HYDROGUI_PrsImage::PointB ] =
242 HYDROGUI_ImportImageDlg::ComputeTrsfData( theTrsfMode, theLocalPointB, theGlobalPointB );
243 if ( !theIsByTwoPoints )
245 theDataMap[ HYDROGUI_PrsImage::PointC ] =
246 HYDROGUI_ImportImageDlg::ComputeTrsfData( theTrsfMode, theLocalPointC, theGlobalPointC );
250 void HYDROGUI_ImportImageOp::abortOperation()
254 HYDROGUI_Operation::abortOperation();
257 void HYDROGUI_ImportImageOp::commitOperation()
261 HYDROGUI_Operation::commitOperation();
264 HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const
266 HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportImageDlg( module(), getName() );
267 connect( aPanel, SIGNAL( createPreview( QImage ) ), SLOT( onCreatePreview( QImage ) ) );
268 connect( aPanel, SIGNAL( activatePointSelection( int ) ), SLOT( onActivatePointSelection( int ) ) );
269 connect( aPanel, SIGNAL( pointCoordChanged( bool, int, bool, int ) ),
270 SLOT( onPointCoordChanged( bool, int, bool, int ) ) );
271 connect( aPanel, SIGNAL( modeActivated( int ) ), SLOT( onModeActivated( int ) ) );
272 connect( aPanel, SIGNAL( refImageActivated( const QString& ) ),
273 SLOT( onRefImageActivated( const QString& ) ) );
274 connect( aPanel, SIGNAL( setCIsUsed( bool ) ), SLOT( onSetCIsUsed( bool ) ) );
278 void HYDROGUI_ImportImageOp::onSetCIsUsed( bool theCIsUsed )
282 myPreviewPrs->setIsByTwoPoints( !theCIsUsed );
284 if ( myRefPreviewPrs )
286 myRefPreviewPrs->setIsByTwoPoints( !theCIsUsed );
290 bool HYDROGUI_ImportImageOp::checkPoints( const QPointF& thePointA,
291 const QPointF& thePointB,
292 const QPointF& thePointC,
293 const bool theIsByTwoPoints,
294 const QString& theLineErrMsg,
295 const QString& thePoinErrMsg,
296 QString& theErrorMsg,
297 const bool theIsToCheckInvertibles ) const
299 double xa = thePointA.x();
300 double ya = thePointA.y();
301 double xb = thePointB.x();
302 double yb = thePointB.y();
303 double xc = thePointC.x();
304 double yc = thePointC.y();
306 if ( !theIsByTwoPoints )
308 // check that three input points don't belong to a single line
309 if ( ValuesEquals( ( yb - ya ) * ( xc - xa ), ( yc - ya ) * ( xb - xa ) ) )
311 theErrorMsg = theLineErrMsg;
315 if ( theIsToCheckInvertibles )
317 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
319 bool anIsInvertible = false;
320 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
321 if( !anIsInvertible )
323 theErrorMsg = tr( "TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED" );
330 // check that two points are not identical
331 if ( ValuesEquals( xa, xb ) && ValuesEquals( ya, yb ) )
333 theErrorMsg = thePoinErrMsg;
341 bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
342 QString& theErrorMsg )
344 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
346 QString anImageName = aPanel->getImageName();
347 if( anImageName.isEmpty() )
350 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) )
352 // check that there are no other objects with the same name in the document
353 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
354 if( !anObject.IsNull() )
356 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
361 HYDROGUI_ImportImageDlg::TransformationDataMap aMap;
362 if( !aPanel->getTransformationDataMap( aMap ) )
365 bool anIsByTwoPoints = aPanel->isByTwoPoints();
367 QPoint aPointA = aMap[ HYDROGUI_PrsImage::PointA ].ImagePoint;
368 QPoint aPointB = aMap[ HYDROGUI_PrsImage::PointB ].ImagePoint;
369 QPoint aPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) :
370 aMap[ HYDROGUI_PrsImage::PointC ].ImagePoint;
372 // first, we check correctness of image points
373 if ( !checkPoints( aPointA, aPointB, aPointC, anIsByTwoPoints,
374 tr( "POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ),
375 tr( "POINTS_A_B_ARE_IDENTICAL" ),
376 theErrorMsg, true ) )
379 Handle(HYDROData_Image) aRefImageObj;
380 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC( INT_MIN, INT_MIN );
382 HYDROData_Image::TransformationMode aTransformationMode =
383 (HYDROData_Image::TransformationMode)aPanel->getTransformationMode();
384 if ( aTransformationMode == HYDROData_Image::ReferenceImage )
386 QString aRefImageName = aPanel->getRefImageName();
387 if( aRefImageName.isEmpty() )
389 theErrorMsg = tr( "REFERENCE_IMAGE_IS_NOT_SELECTED" );
393 HYDROGUI_ImportImageDlg::TransformationDataMap aRefMap;
394 if( !aPanel->getTransformationDataMap( aRefMap, true ) )
397 aRefImageObj = Handle(HYDROData_Image)::DownCast(
398 HYDROGUI_Tool::FindObjectByName( module(), aRefImageName, KIND_IMAGE ) );
399 if( aRefImageObj.IsNull() )
402 aTrsfPointA = aRefMap[ HYDROGUI_PrsImage::PointA ].ImagePoint;
403 aTrsfPointB = aRefMap[ HYDROGUI_PrsImage::PointB ].ImagePoint;
404 if ( !anIsByTwoPoints )
405 aTrsfPointC = aRefMap[ HYDROGUI_PrsImage::PointC ].ImagePoint;
407 // the same check of correctness for the reference points
408 if ( !checkPoints( aTrsfPointA, aTrsfPointB, aTrsfPointC, anIsByTwoPoints,
409 tr( "REFERENCE_POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ),
410 tr( "REFERENCE_POINTS_A_B_ARE_IDENTICAL" ),
411 theErrorMsg, false ) )
416 if ( aTransformationMode == HYDROData_Image::ManualGeodesic )
418 aTrsfPointA = aMap[ HYDROGUI_PrsImage::PointA ].GeodesicPoint;
419 aTrsfPointB = aMap[ HYDROGUI_PrsImage::PointB ].GeodesicPoint;
420 if ( !anIsByTwoPoints )
421 aTrsfPointC = aMap[ HYDROGUI_PrsImage::PointC ].GeodesicPoint;
425 aTrsfPointA = aMap[ HYDROGUI_PrsImage::PointA ].CartesianPoint;
426 aTrsfPointB = aMap[ HYDROGUI_PrsImage::PointB ].CartesianPoint;
427 if ( !anIsByTwoPoints )
428 aTrsfPointC = aMap[ HYDROGUI_PrsImage::PointC ].CartesianPoint;
432 Handle(HYDROData_Image) anImageObj;
434 anImageObj = myEditedObject;
436 anImageObj = Handle(HYDROData_Image)::DownCast( doc()->CreateObject( KIND_IMAGE ) );
438 if( anImageObj.IsNull() )
441 anImageObj->SetName( anImageName );
442 anImageObj->SetImage( myImage );
443 anImageObj->SetLocalPoints( aPointA, aPointB, aPointC, false );
445 if ( aTransformationMode == HYDROData_Image::ReferenceImage )
447 anImageObj->SetReferencePoints( aRefImageObj,
448 aTrsfPointA, aTrsfPointB, aTrsfPointC );
452 anImageObj->SetGlobalPoints( aTransformationMode,
453 aTrsfPointA, aTrsfPointB, aTrsfPointC );
458 // Set imported file name for image
459 QString aFilePath = aPanel->getFileName();
460 anImageObj->SetFilePath( aFilePath );
463 // must be done after all checks and before calling SetVisible() method below
467 module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), anImageObj, true );
470 anImageObj->Update();
472 theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;
476 void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
478 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
482 if( myPreviewPrs ) // if the image is changed by choosing another file
484 myPreviewPrs->setImage( myImage );
485 myPreviewPrs->compute();
487 if( myPreviewViewManager )
489 if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
491 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
493 aViewPort->onBoundingRectChanged();
501 LightApp_Application* anApp = module()->getApp();
503 myActiveViewManager = anApp->activeViewManager();
505 myPreviewPrs = new HYDROGUI_PrsImage( myIsEdit ? myEditedObject : 0 );
506 myPreviewPrs->setImage( myImage );
507 myPreviewPrs->compute();
509 myPreviewViewManager =
510 dynamic_cast<GraphicsView_ViewManager*>( anApp->createViewManager( GraphicsView_Viewer::Type() ) );
511 if( myPreviewViewManager )
513 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
514 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
516 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_TransformImage );
517 myPreviewViewManager->setTitle( tr( "TRANSFORM_IMAGE" ) );
518 if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
520 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
522 //aViewPort->setMousePositionEnabled( true ); //ouv: temporarily commented
524 aViewPort->addItem( myPreviewPrs );
527 myPreviewPrs->setIsTransformationPointPreview( true );
529 connect( aViewer, SIGNAL( selectionChanged( GV_SelectionChangeStatus ) ),
530 this, SLOT( onPointSelected() ) );
534 // Set the image name in the dialog
535 QString anImageName = aPanel->getImageName().simplified();
536 // If edit mode and the name was not set yet then get from the edited object
537 if( myIsEdit && anImageName.isEmpty() )
539 if( !myEditedObject.IsNull() )
540 anImageName = myEditedObject->GetName();
542 // If the name was not set then initialize it from the selected file name
543 if ( anImageName.isEmpty() )
545 anImageName = aPanel->getFileName();
546 if ( !anImageName.isEmpty() ) {
547 anImageName = QFileInfo( anImageName ).baseName();
549 // If no file name then generate a new image name
550 if ( anImageName.isEmpty() ) {
551 anImageName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMAGE_NAME" ) );
555 aPanel->setImageName( anImageName );
558 aPanel->setImageSize( myImage.size() );
560 aPanel->initializePointSelection();
561 onPointSelected( false );
564 void HYDROGUI_ImportImageOp::onActivatePointSelection( int thePointType )
566 myPointType = thePointType;
568 myPreviewPrs->setTransformationPointType( thePointType );
569 if( myRefPreviewPrs )
570 myRefPreviewPrs->setTransformationPointType( thePointType );
573 void HYDROGUI_ImportImageOp::onPointCoordChanged( bool theIsRef,
578 if( !theIsRef && myPreviewPrs )
579 myPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue );
580 else if( theIsRef && myRefPreviewPrs )
581 myRefPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue );
584 void HYDROGUI_ImportImageOp::onModeActivated( int theMode )
586 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
588 QString aRefImageName;
589 if( theMode == HYDROData_Image::ReferenceImage )
591 aRefImageName = aPanel->getRefImageName();
592 if( aRefImageName.isEmpty() )
593 return; // do nothing in this case to avoid visual moving of preview prs
594 onRefImageActivated( aRefImageName );
598 if( myRefViewManager )
600 closeView( myRefViewManager );
605 void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName )
607 GraphicsView_ViewPort* aViewPort = 0;
609 LightApp_Application* anApp = module()->getApp();
610 ///// Get a view port for the reference image preview
611 if( myRefViewManager )
613 if( GraphicsView_Viewer* aViewer = myRefViewManager->getViewer() )
615 aViewPort = aViewer->getActiveViewPort();
620 anApp = module()->getApp();
621 // Init reference image preview
623 dynamic_cast<GraphicsView_ViewManager*>( anApp->createViewManager( GraphicsView_Viewer::Type() ) );
624 if( myRefViewManager )
626 connect( myRefViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
627 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
629 module()->setViewManagerRole( myRefViewManager, HYDROGUI_Module::VMR_ReferenceImage );
630 myRefViewManager->setTitle( tr( "REFERENCE_IMAGE" ) );
631 if( GraphicsView_Viewer* aViewer = myRefViewManager->getViewer() )
633 aViewPort = aViewer->getActiveViewPort();
634 connect( aViewer, SIGNAL( selectionChanged( GV_SelectionChangeStatus ) ),
635 this, SLOT( onRefPointSelected() ) );
643 // Remove the old presentation of the reference image if any
644 if( myRefPreviewPrs )
646 myRefPreviewPrs->setCaption( QString() );
647 aViewPort->removeItem( myRefPreviewPrs );
649 delete myRefPreviewPrs;
653 // Create a new reference image presentation
655 Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast(
656 HYDROGUI_Tool::FindObjectByName( module(), theName, KIND_IMAGE ) );
657 if( !anImageObj.IsNull() )
659 anImage = anImageObj->Image();
661 myRefPreviewPrs = new HYDROGUI_PrsImage( anImageObj );
662 myRefPreviewPrs->setImage( anImage );
663 myRefPreviewPrs->compute();
665 myRefPreviewPrs->setIsTransformationPointPreview( true );
666 myRefPreviewPrs->setTransformationPointType( myPointType );
668 // Add the new reference image presentation to the appropriate view
669 aViewPort->addItem( myRefPreviewPrs );
674 // Split views horizontally
675 if( anApp->desktop()->inherits( "STD_TabDesktop" ) )
677 qApp->processEvents();
678 QtxWorkstack* aWorkstack = ( (STD_TabDesktop*)anApp->desktop() )->workstack();
679 aViewPort->activateWindow();
681 aViewPort->setFocus(Qt::ActiveWindowFocusReason);
682 aWorkstack->splitHorizontal();
685 // Initialize the dialog
686 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
687 aPanel->setImageSize( anImage.size(), true );
688 aPanel->initializePointSelection();
689 onPointSelected( true );
692 void HYDROGUI_ImportImageOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
697 void HYDROGUI_ImportImageOp::onPointSelected()
699 onPointSelected( myRefPreviewPrs && myRefPreviewPrs->isSelected() );
702 void HYDROGUI_ImportImageOp::onRefPointSelected()
704 onPointSelected( true );
707 void HYDROGUI_ImportImageOp::onPointSelected( bool theIsRefImage )
709 HYDROGUI_PrsImage* aPrs = theIsRefImage ? myRefPreviewPrs : myPreviewPrs;
713 HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
715 const HYDROGUI_PrsImage::TransformationPointMap& aPointMap =
716 aPrs->getTransformationPointMap();
718 HYDROGUI_PrsImage::TransformationPointMapIterator anIter( aPointMap );
719 while( anIter.hasNext() )
721 int aPointType = anIter.next().key();
722 const HYDROGUI_PrsImage::TransformationPoint& aTransformationPoint = anIter.value();
723 const QPoint& aPoint = aTransformationPoint.Point;
725 HYDROGUI_ImportImageDlg::TransformationData aData( aPoint, QPointF(), QPointF() );
726 aDataMap[ aPointType ] = aData;
729 ( (HYDROGUI_ImportImageDlg*)inputPanel() )->setTransformationDataMap( aDataMap, true, theIsRefImage );
732 void HYDROGUI_ImportImageOp::closePreview()
734 closeView( myPreviewViewManager );
735 closeView( myRefViewManager );
737 if( myActiveViewManager )
738 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
741 void HYDROGUI_ImportImageOp::closeView( GraphicsView_ViewManager* &aViewMgr )
745 GraphicsView_ViewPort* aViewPort = 0;
746 if( GraphicsView_Viewer* aViewer = aViewMgr->getViewer() )
748 aViewPort = aViewer->getActiveViewPort();
750 disconnect( aViewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
751 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
753 // Nullify appropriate presentation pointer
754 HYDROGUI_PrsImage* aPrs = 0;
755 switch ( module()->getViewManagerRole( aViewMgr ) )
757 case HYDROGUI_Module::VMR_ReferenceImage:
758 aPrs = myRefPreviewPrs;
761 case HYDROGUI_Module::VMR_TransformImage:
766 // Remove the appropriate presentation from the view
767 if( aPrs && aViewPort )
769 aViewPort->removeItem( aPrs );
774 module()->getApp()->removeViewManager( aViewMgr ); // aViewMgr is deleted here