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 );
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() ) );
533 // Set the image name in the dialog
534 QString anImageName = aPanel->getImageName().simplified();
535 // If edit mode and the name was not set yet then get from the edited object
536 if( myIsEdit && anImageName.isEmpty() )
538 if( !myEditedObject.IsNull() )
539 anImageName = myEditedObject->GetName();
541 // If the name was not set then initialize it from the selected file name
542 if ( anImageName.isEmpty() )
544 anImageName = aPanel->getFileName();
545 if ( !anImageName.isEmpty() ) {
546 anImageName = QFileInfo( anImageName ).baseName();
548 // If no file name then generate a new image name
549 if ( anImageName.isEmpty() ) {
550 anImageName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMAGE_NAME" ) );
554 aPanel->setImageName( anImageName );
557 aPanel->setImageSize( myImage.size() );
559 aPanel->initializePointSelection();
560 onPointSelected( false );
563 void HYDROGUI_ImportImageOp::onActivatePointSelection( int thePointType )
565 myPointType = thePointType;
567 myPreviewPrs->setTransformationPointType( thePointType );
568 if( myRefPreviewPrs )
569 myRefPreviewPrs->setTransformationPointType( thePointType );
572 void HYDROGUI_ImportImageOp::onPointCoordChanged( bool theIsRef,
577 if( !theIsRef && myPreviewPrs )
578 myPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue );
579 else if( theIsRef && myRefPreviewPrs )
580 myRefPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue );
583 void HYDROGUI_ImportImageOp::onModeActivated( int theMode )
585 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
587 QString aRefImageName;
588 if( theMode == HYDROData_Image::ReferenceImage )
590 aRefImageName = aPanel->getRefImageName();
591 if( aRefImageName.isEmpty() )
592 return; // do nothing in this case to avoid visual moving of preview prs
593 onRefImageActivated( aRefImageName );
597 if( myRefViewManager )
599 closeView( myRefViewManager );
604 void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName )
606 GraphicsView_ViewPort* aViewPort = 0;
608 LightApp_Application* anApp = module()->getApp();
609 ///// Get a view port for the reference image preview
610 if( myRefViewManager )
612 if( GraphicsView_Viewer* aViewer = myRefViewManager->getViewer() )
614 aViewPort = aViewer->getActiveViewPort();
619 anApp = module()->getApp();
620 // Init reference image preview
622 dynamic_cast<GraphicsView_ViewManager*>( anApp->createViewManager( GraphicsView_Viewer::Type() ) );
623 if( myRefViewManager )
625 connect( myRefViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
626 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
628 module()->setViewManagerRole( myRefViewManager, HYDROGUI_Module::VMR_ReferenceImage );
629 myRefViewManager->setTitle( tr( "REFERENCE_IMAGE" ) );
630 if( GraphicsView_Viewer* aViewer = myRefViewManager->getViewer() )
632 aViewPort = aViewer->getActiveViewPort();
633 connect( aViewer, SIGNAL( selectionChanged( GV_SelectionChangeStatus ) ),
634 this, SLOT( onRefPointSelected() ) );
642 // Remove the old presentation of the reference image if any
643 if( myRefPreviewPrs )
645 myRefPreviewPrs->setCaption( QString() );
646 aViewPort->removeItem( myRefPreviewPrs );
648 delete myRefPreviewPrs;
652 // Create a new reference image presentation
654 Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast(
655 HYDROGUI_Tool::FindObjectByName( module(), theName, KIND_IMAGE ) );
656 if( !anImageObj.IsNull() )
658 anImage = anImageObj->Image();
660 myRefPreviewPrs = new HYDROGUI_PrsImage( anImageObj );
661 myRefPreviewPrs->setImage( anImage );
662 myRefPreviewPrs->compute();
664 myRefPreviewPrs->setIsTransformationPointPreview( true );
665 myRefPreviewPrs->setTransformationPointType( myPointType );
667 // Add the new reference image presentation to the appropriate view
668 aViewPort->addItem( myRefPreviewPrs );
673 // Split views horizontally
674 if( anApp->desktop()->inherits( "STD_TabDesktop" ) )
676 qApp->processEvents();
677 QtxWorkstack* aWorkstack = ( (STD_TabDesktop*)anApp->desktop() )->workstack();
678 aViewPort->activateWindow();
680 aViewPort->setFocus(Qt::ActiveWindowFocusReason);
681 aWorkstack->splitHorizontal();
684 // Initialize the dialog
685 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
686 aPanel->setImageSize( anImage.size(), true );
687 aPanel->initializePointSelection();
688 onPointSelected( true );
691 void HYDROGUI_ImportImageOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
696 void HYDROGUI_ImportImageOp::onPointSelected()
698 onPointSelected( myRefPreviewPrs && myRefPreviewPrs->isSelected() );
701 void HYDROGUI_ImportImageOp::onRefPointSelected()
703 onPointSelected( true );
706 void HYDROGUI_ImportImageOp::onPointSelected( bool theIsRefImage )
708 HYDROGUI_PrsImage* aPrs = theIsRefImage ? myRefPreviewPrs : myPreviewPrs;
712 HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
714 const HYDROGUI_PrsImage::TransformationPointMap& aPointMap =
715 aPrs->getTransformationPointMap();
717 HYDROGUI_PrsImage::TransformationPointMapIterator anIter( aPointMap );
718 while( anIter.hasNext() )
720 int aPointType = anIter.next().key();
721 const HYDROGUI_PrsImage::TransformationPoint& aTransformationPoint = anIter.value();
722 const QPoint& aPoint = aTransformationPoint.Point;
724 HYDROGUI_ImportImageDlg::TransformationData aData( aPoint, QPointF(), QPointF() );
725 aDataMap[ aPointType ] = aData;
728 ( (HYDROGUI_ImportImageDlg*)inputPanel() )->setTransformationDataMap( aDataMap, true, theIsRefImage );
731 void HYDROGUI_ImportImageOp::closePreview()
733 closeView( myPreviewViewManager );
734 closeView( myRefViewManager );
736 if( myActiveViewManager )
737 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
740 void HYDROGUI_ImportImageOp::closeView( GraphicsView_ViewManager* &aViewMgr )
744 GraphicsView_ViewPort* aViewPort = 0;
745 if( GraphicsView_Viewer* aViewer = aViewMgr->getViewer() )
747 aViewPort = aViewer->getActiveViewPort();
749 disconnect( aViewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
750 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
752 // Nullify appropriate presentation pointer
753 HYDROGUI_PrsImage* aPrs = 0;
754 switch ( module()->getViewManagerRole( aViewMgr ) )
756 case HYDROGUI_Module::VMR_ReferenceImage:
757 aPrs = myRefPreviewPrs;
760 case HYDROGUI_Module::VMR_TransformImage:
765 // Remove the appropriate presentation from the view
766 if( aPrs && aViewPort )
768 aViewPort->removeItem( aPrs );
773 module()->getApp()->removeViewManager( aViewMgr ); // aViewMgr is deleted here