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 <SUIT_MessageBox.h>
45 #include <QtxWorkstack.h>
46 #include <QApplication>
49 HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule,
50 const bool theIsEdit )
51 : HYDROGUI_Operation( theModule ),
52 myIsEdit( theIsEdit ),
54 myActiveViewManager( 0 ),
55 myPreviewViewManager( 0 ),
56 myRefViewManager( 0 ),
59 myPointType( HYDROGUI_PrsImage::None )
61 setName( theIsEdit ? tr( "EDIT_IMPORTED_IMAGE" ) : tr( "IMPORT_IMAGE" ) );
64 HYDROGUI_ImportImageOp::~HYDROGUI_ImportImageOp()
68 void HYDROGUI_ImportImageOp::startOperation()
70 HYDROGUI_Operation::startOperation();
72 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
74 aPanel->setIsEdit( myIsEdit );
76 QString aRefImageName;
80 myEditedObject = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
81 if( !myEditedObject.IsNull() )
83 QImage anImage = myEditedObject->Image();
84 bool anIsByTwoPoints = myEditedObject->IsByTwoPoints();
86 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
87 myEditedObject->GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC );
89 // Create the edited image preview presentation in the viewer
90 onCreatePreview( anImage );
92 // Set transformation local points A,B,C to the image preview presentation
93 setPresentationTrsfPoints( myPreviewPrs, anIsByTwoPoints, aLocalPointA,
94 aLocalPointB, aLocalPointC );
96 // Build the existing image local and global points mapping
97 // according to the current transformation mode.
98 HYDROData_Image::TransformationMode aTrsfMode = myEditedObject->GetTrsfMode();
99 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
100 HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
101 if ( aTrsfMode == HYDROData_Image::ReferenceImage )
103 // Compute global points using the transformation matrix of the reference image
104 Handle(HYDROData_Image) aRefImage = myEditedObject->GetTrsfReferenceImage();
105 if ( !aRefImage.IsNull() )
107 QTransform aRefTrsf = aRefImage->Trsf(); // The reference image transformation matrix
108 aTrsfPointA = aRefTrsf.map( aLocalPointA ); // Compute the global point A
109 aTrsfPointB = aRefTrsf.map( aLocalPointB ); // Compute the global point B
110 if ( !anIsByTwoPoints )
112 aTrsfPointC = aRefTrsf.map( aLocalPointC ); // Compute the global point C if used
114 // Build the local-global points map
115 // Use the reference image transformation mode for interpreting global points
116 computeTrsfData( aRefImage->GetTrsfMode(), anIsByTwoPoints, aLocalPointA, aLocalPointB, aLocalPointC,
117 aTrsfPointA, aTrsfPointB, aTrsfPointC, aDataMap );
122 // Get global points from the edited image
123 myEditedObject->GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC );
124 // Build the local-global points map
125 computeTrsfData( aTrsfMode, anIsByTwoPoints, aLocalPointA, aLocalPointB, aLocalPointC,
126 aTrsfPointA, aTrsfPointB, aTrsfPointC, aDataMap );
129 // Initialize the dialog mode, local and global coordinates
130 // except coordinates on the reference image
131 aPanel->setTransformationMode( aTrsfMode );
132 aPanel->setTransformationDataMap( aDataMap );
133 aPanel->setByTwoPoints( anIsByTwoPoints );
135 // Set points of the reference image
136 if ( aTrsfMode == HYDROData_Image::ReferenceImage )
138 Handle(HYDROData_Image) aRefImage;
139 myEditedObject->GetReferencePoints( aRefImage,
140 aTrsfPointA, aTrsfPointB, aTrsfPointC );
141 if ( !aRefImage.IsNull() )
143 aRefImageName = aRefImage->GetName();
145 // Create the reference image presentation in the viewer
146 onRefImageActivated( aRefImageName );
148 // Set transformation points A,B,C to the reference image presentation
149 setPresentationTrsfPoints( myRefPreviewPrs, anIsByTwoPoints, aTrsfPointA.toPoint(),
150 aTrsfPointB.toPoint(), aTrsfPointC.toPoint() );
152 // Prepare A, B, C points on the reference image
153 HYDROGUI_ImportImageDlg::TransformationDataMap aRefDataMap;
154 aRefDataMap[ HYDROGUI_PrsImage::PointA ] =
155 HYDROGUI_ImportImageDlg::TransformationData( aTrsfPointA.toPoint() );
156 aRefDataMap[ HYDROGUI_PrsImage::PointB ] =
157 HYDROGUI_ImportImageDlg::TransformationData( aTrsfPointB.toPoint() );
158 if ( !anIsByTwoPoints )
159 aRefDataMap[ HYDROGUI_PrsImage::PointC ] =
160 HYDROGUI_ImportImageDlg::TransformationData( aTrsfPointC.toPoint() );
162 // Initialize the dialog's A, B, C points coordinates of the reference image
163 aPanel->setTransformationDataMap( aRefDataMap, true, true );
169 // Collect information about existing images and initialize the combobox
170 // reference image selector in the dialog.
171 HYDROGUI_ImportImageDlg::PrsPointDataList aPrsPointDataList;
172 HYDROData_Iterator anIterator( doc(), KIND_IMAGE );
173 for( ; anIterator.More(); anIterator.Next() )
175 Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( anIterator.Current() );
176 if( !anImageObj.IsNull() )
178 if( myIsEdit && IsEqual( anImageObj, myEditedObject ) )
181 QPoint aLocalPointA, aLocalPointB, aLocalPointC;
182 anImageObj->GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC );
184 HYDROData_Image::TransformationMode aImgTrsfMode;
185 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
186 anImageObj->GetGlobalPoints( aImgTrsfMode,
187 aTrsfPointA, aTrsfPointB, aTrsfPointC );
189 HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
190 computeTrsfData( aImgTrsfMode, false, aLocalPointA, aLocalPointB, aLocalPointC,
191 aTrsfPointA, aTrsfPointB, aTrsfPointC, aDataMap );
193 HYDROGUI_ImportImageDlg::PrsPointData aPrsPointData( anImageObj->GetName(), aDataMap );
194 aPrsPointDataList.append( aPrsPointData );
198 // Initialize the combobox in the dialog with the list of available reference images
199 aPanel->setPrsPointDataList( aPrsPointDataList );
200 // Select the current reference image in the dialog combobox
201 aPanel->setRefImageName( aRefImageName );
204 void HYDROGUI_ImportImageOp::setPresentationTrsfPoints( HYDROGUI_PrsImage* thePrs,
205 bool theIsByTwoPoints,
206 const QPoint theLocalPointA,
207 const QPoint theLocalPointB,
208 const QPoint theLocalPointC )
210 // Set transformation points A,B,C to the image presentation
213 HYDROGUI_PrsImage::TransformationPointMap aPointMap =
214 thePrs->getTransformationPointMap();
215 if( !aPointMap.isEmpty() )
217 aPointMap[ HYDROGUI_PrsImage::PointA ].Point = theLocalPointA;
218 aPointMap[ HYDROGUI_PrsImage::PointB ].Point = theLocalPointB;
219 if ( !theIsByTwoPoints )
220 aPointMap[ HYDROGUI_PrsImage::PointC ].Point = theLocalPointC;
222 thePrs->setIsByTwoPoints( theIsByTwoPoints );
223 thePrs->setTransformationPointMap( aPointMap );
228 void HYDROGUI_ImportImageOp::computeTrsfData( HYDROData_Image::TransformationMode theTrsfMode,
229 bool theIsByTwoPoints,
230 const QPoint& theLocalPointA,
231 const QPoint& theLocalPointB,
232 const QPoint& theLocalPointC,
233 const QPointF& theGlobalPointA,
234 const QPointF& theGlobalPointB,
235 const QPointF& theGlobalPointC,
236 HYDROGUI_ImportImageDlg::TransformationDataMap& theDataMap ) const
238 // Build the local-global points map
239 HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
240 theDataMap[ HYDROGUI_PrsImage::PointA ] =
241 HYDROGUI_ImportImageDlg::ComputeTrsfData( theTrsfMode, theLocalPointA, theGlobalPointA );
242 theDataMap[ HYDROGUI_PrsImage::PointB ] =
243 HYDROGUI_ImportImageDlg::ComputeTrsfData( theTrsfMode, theLocalPointB, theGlobalPointB );
244 if ( !theIsByTwoPoints )
246 theDataMap[ HYDROGUI_PrsImage::PointC ] =
247 HYDROGUI_ImportImageDlg::ComputeTrsfData( theTrsfMode, theLocalPointC, theGlobalPointC );
251 void HYDROGUI_ImportImageOp::abortOperation()
255 HYDROGUI_Operation::abortOperation();
258 void HYDROGUI_ImportImageOp::commitOperation()
262 HYDROGUI_Operation::commitOperation();
265 HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const
267 HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportImageDlg( module(), getName() );
268 connect( aPanel, SIGNAL( createPreview( QImage ) ), SLOT( onCreatePreview( QImage ) ) );
269 connect( aPanel, SIGNAL( activatePointSelection( int ) ), SLOT( onActivatePointSelection( int ) ) );
270 connect( aPanel, SIGNAL( pointCoordChanged( bool, int, bool, int ) ),
271 SLOT( onPointCoordChanged( bool, int, bool, int ) ) );
272 connect( aPanel, SIGNAL( modeActivated( int ) ), SLOT( onModeActivated( int ) ) );
273 connect( aPanel, SIGNAL( refImageActivated( const QString& ) ),
274 SLOT( onRefImageActivated( const QString& ) ) );
275 connect( aPanel, SIGNAL( setCIsUsed( bool ) ), SLOT( onSetCIsUsed( bool ) ) );
279 void HYDROGUI_ImportImageOp::onSetCIsUsed( bool theCIsUsed )
283 myPreviewPrs->setIsByTwoPoints( !theCIsUsed );
285 if ( myRefPreviewPrs )
287 myRefPreviewPrs->setIsByTwoPoints( !theCIsUsed );
291 bool HYDROGUI_ImportImageOp::checkPoints( const QPointF& thePointA,
292 const QPointF& thePointB,
293 const QPointF& thePointC,
294 const bool theIsByTwoPoints,
295 const QString& theLineErrMsg,
296 const QString& thePoinErrMsg,
297 QString& theErrorMsg,
298 const bool theIsToCheckInvertibles ) const
300 double xa = thePointA.x();
301 double ya = thePointA.y();
302 double xb = thePointB.x();
303 double yb = thePointB.y();
304 double xc = thePointC.x();
305 double yc = thePointC.y();
307 if ( !theIsByTwoPoints )
309 // check that three input points don't belong to a single line
310 if ( ValuesEquals( ( yb - ya ) * ( xc - xa ), ( yc - ya ) * ( xb - xa ) ) )
312 theErrorMsg = theLineErrMsg;
316 if ( theIsToCheckInvertibles )
318 QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
320 bool anIsInvertible = false;
321 QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
322 if( !anIsInvertible )
324 theErrorMsg = tr( "TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED" );
331 // check that two points are not identical
332 if ( ValuesEquals( xa, xb ) && ValuesEquals( ya, yb ) )
334 theErrorMsg = thePoinErrMsg;
342 bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
343 QString& theErrorMsg )
345 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
347 QString anImageName = aPanel->getImageName();
348 if( anImageName.isEmpty() )
351 if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) )
353 // check that there are no other objects with the same name in the document
354 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
355 if( !anObject.IsNull() )
357 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
362 HYDROGUI_ImportImageDlg::TransformationDataMap aMap;
363 if( !aPanel->getTransformationDataMap( aMap ) )
366 bool anIsByTwoPoints = aPanel->isByTwoPoints();
368 QPoint aPointA = aMap[ HYDROGUI_PrsImage::PointA ].ImagePoint;
369 QPoint aPointB = aMap[ HYDROGUI_PrsImage::PointB ].ImagePoint;
370 QPoint aPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) :
371 aMap[ HYDROGUI_PrsImage::PointC ].ImagePoint;
373 // first, we check correctness of image points
374 if ( !checkPoints( aPointA, aPointB, aPointC, anIsByTwoPoints,
375 tr( "POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ),
376 tr( "POINTS_A_B_ARE_IDENTICAL" ),
377 theErrorMsg, true ) )
380 Handle(HYDROData_Image) aRefImageObj;
381 QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC( INT_MIN, INT_MIN );
383 HYDROData_Image::TransformationMode aTransformationMode =
384 (HYDROData_Image::TransformationMode)aPanel->getTransformationMode();
385 if ( aTransformationMode == HYDROData_Image::ReferenceImage )
387 QString aRefImageName = aPanel->getRefImageName();
388 if( aRefImageName.isEmpty() )
390 theErrorMsg = tr( "REFERENCE_IMAGE_IS_NOT_SELECTED" );
394 HYDROGUI_ImportImageDlg::TransformationDataMap aRefMap;
395 if( !aPanel->getTransformationDataMap( aRefMap, true ) )
398 aRefImageObj = Handle(HYDROData_Image)::DownCast(
399 HYDROGUI_Tool::FindObjectByName( module(), aRefImageName, KIND_IMAGE ) );
400 if( aRefImageObj.IsNull() )
403 else if ( !isReferenceCorrect() )
404 aRefImageObj->RemoveAllReferences();
406 aTrsfPointA = aRefMap[ HYDROGUI_PrsImage::PointA ].ImagePoint;
407 aTrsfPointB = aRefMap[ HYDROGUI_PrsImage::PointB ].ImagePoint;
408 if ( !anIsByTwoPoints )
409 aTrsfPointC = aRefMap[ HYDROGUI_PrsImage::PointC ].ImagePoint;
411 // the same check of correctness for the reference points
412 if ( !checkPoints( aTrsfPointA, aTrsfPointB, aTrsfPointC, anIsByTwoPoints,
413 tr( "REFERENCE_POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ),
414 tr( "REFERENCE_POINTS_A_B_ARE_IDENTICAL" ),
415 theErrorMsg, false ) )
420 if ( aTransformationMode == HYDROData_Image::ManualGeodesic )
422 aTrsfPointA = aMap[ HYDROGUI_PrsImage::PointA ].GeodesicPoint;
423 aTrsfPointB = aMap[ HYDROGUI_PrsImage::PointB ].GeodesicPoint;
424 if ( !anIsByTwoPoints )
425 aTrsfPointC = aMap[ HYDROGUI_PrsImage::PointC ].GeodesicPoint;
429 aTrsfPointA = aMap[ HYDROGUI_PrsImage::PointA ].CartesianPoint;
430 aTrsfPointB = aMap[ HYDROGUI_PrsImage::PointB ].CartesianPoint;
431 if ( !anIsByTwoPoints )
432 aTrsfPointC = aMap[ HYDROGUI_PrsImage::PointC ].CartesianPoint;
436 Handle(HYDROData_Image) anImageObj;
438 anImageObj = myEditedObject;
440 anImageObj = Handle(HYDROData_Image)::DownCast( doc()->CreateObject( KIND_IMAGE ) );
442 if( anImageObj.IsNull() )
445 anImageObj->SetName( anImageName );
446 anImageObj->SetImage( myImage );
447 anImageObj->SetLocalPoints( aPointA, aPointB, aPointC, false );
449 if ( aTransformationMode == HYDROData_Image::ReferenceImage )
451 anImageObj->SetReferencePoints( aRefImageObj,
452 aTrsfPointA, aTrsfPointB, aTrsfPointC );
456 anImageObj->SetGlobalPoints( aTransformationMode,
457 aTrsfPointA, aTrsfPointB, aTrsfPointC );
462 // Set imported file name for image
463 QString aFilePath = aPanel->getFileName();
464 anImageObj->SetFilePath( aFilePath );
467 // must be done after all checks and before calling SetVisible() method below
471 module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), anImageObj, true );
473 anImageObj->Update();
475 theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;
479 bool HYDROGUI_ImportImageOp::isReferenceCorrect() const
481 bool isCorrect = true;
483 if( myIsEdit && !myEditedObject.IsNull() )
485 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
486 Handle(HYDROData_Image) aRefImageObj = Handle(HYDROData_Image)::DownCast(
487 HYDROGUI_Tool::FindObjectByName( module(), aPanel->getRefImageName(), KIND_IMAGE ) );
488 if( !aRefImageObj.IsNull() )
490 bool isFoundEdited = false;
491 HYDROData_SequenceOfObjects aRefSeq = aRefImageObj->GetAllReferenceObjects();
492 for ( int i = 1, n = aRefSeq.Length(); i <= n && !isFoundEdited; ++i )
494 Handle(HYDROData_Entity) anObject = aRefSeq.Value( i );
495 isFoundEdited = anObject->GetName() == myEditedObject->GetName();
497 isCorrect = !isFoundEdited;
503 void HYDROGUI_ImportImageOp::onApply()
505 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
507 bool aCanApply = isReferenceCorrect();
508 if ( !aCanApply && !myEditedObject.IsNull() )
510 Handle(HYDROData_Image) aRefImageObj = Handle(HYDROData_Image)::DownCast(
511 HYDROGUI_Tool::FindObjectByName( module(), aPanel->getRefImageName(), KIND_IMAGE ) );
512 if ( !aRefImageObj.IsNull() )
513 aCanApply = SUIT_MessageBox::question( module()->getApp()->desktop(),
514 tr( "CORRECT_INPUT_DATA" ), tr( "CONFIRM_REMOVE_REFERENCE_FROM_IMAGE" ).
515 arg( aRefImageObj->GetName() ).arg( myEditedObject->GetName() ),
516 QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) == QMessageBox::Yes;
519 HYDROGUI_Operation::onApply();
521 aPanel->setRefImageName( "" );
522 onRefImageActivated( aPanel->getRefImageName() );
526 void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
528 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
532 if( myPreviewPrs ) // if the image is changed by choosing another file
534 myPreviewPrs->setImage( myImage );
535 myPreviewPrs->compute();
537 if( myPreviewViewManager )
539 if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
541 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
543 aViewPort->onBoundingRectChanged();
551 LightApp_Application* anApp = module()->getApp();
553 myActiveViewManager = anApp->activeViewManager();
555 myPreviewPrs = new HYDROGUI_PrsImage( myIsEdit ? myEditedObject : 0 );
556 myPreviewPrs->setImage( myImage );
557 myPreviewPrs->compute();
559 myPreviewViewManager =
560 dynamic_cast<GraphicsView_ViewManager*>( anApp->createViewManager( GraphicsView_Viewer::Type() ) );
561 if( myPreviewViewManager )
563 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
564 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
566 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_TransformImage );
567 myPreviewViewManager->setTitle( tr( "TRANSFORM_IMAGE" ) );
568 if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
570 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
572 //aViewPort->setMousePositionEnabled( true ); //ouv: temporarily commented
574 aViewPort->addItem( myPreviewPrs );
577 myPreviewPrs->setIsTransformationPointPreview( true );
579 connect( aViewer, SIGNAL( selectionChanged( GV_SelectionChangeStatus ) ),
580 this, SLOT( onPointSelected() ) );
584 // Set the image name in the dialog
585 QString anImageName = aPanel->getImageName().simplified();
586 // If edit mode and the name was not set yet then get from the edited object
587 if( myIsEdit && anImageName.isEmpty() )
589 if( !myEditedObject.IsNull() )
590 anImageName = myEditedObject->GetName();
592 // If the name was not set then initialize it from the selected file name
593 if ( anImageName.isEmpty() )
595 anImageName = aPanel->getFileName();
596 if ( !anImageName.isEmpty() ) {
597 anImageName = QFileInfo( anImageName ).baseName();
599 // If no file name then generate a new image name
600 if ( anImageName.isEmpty() ) {
601 anImageName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMAGE_NAME" ) );
605 aPanel->setImageName( anImageName );
608 aPanel->setImageSize( myImage.size() );
610 aPanel->initializePointSelection();
611 onPointSelected( false );
612 onSetCIsUsed( !aPanel->isByTwoPoints() );
615 void HYDROGUI_ImportImageOp::onActivatePointSelection( int thePointType )
617 myPointType = thePointType;
619 myPreviewPrs->setTransformationPointType( thePointType );
620 if( myRefPreviewPrs )
621 myRefPreviewPrs->setTransformationPointType( thePointType );
624 void HYDROGUI_ImportImageOp::onPointCoordChanged( bool theIsRef,
629 if( !theIsRef && myPreviewPrs )
630 myPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue );
631 else if( theIsRef && myRefPreviewPrs )
632 myRefPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue );
635 void HYDROGUI_ImportImageOp::onModeActivated( int theMode )
637 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
639 QString aRefImageName;
640 if( theMode == HYDROData_Image::ReferenceImage )
642 aRefImageName = aPanel->getRefImageName();
643 if( aRefImageName.isEmpty() )
644 return; // do nothing in this case to avoid visual moving of preview prs
645 onRefImageActivated( aRefImageName );
649 if( myRefViewManager )
651 closeView( myRefViewManager );
656 void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName )
658 GraphicsView_ViewPort* aViewPort = 0;
660 LightApp_Application* anApp = module()->getApp();
661 ///// Get a view port for the reference image preview
662 if( myRefViewManager )
664 if( GraphicsView_Viewer* aViewer = myRefViewManager->getViewer() )
666 aViewPort = aViewer->getActiveViewPort();
671 anApp = module()->getApp();
672 // Init reference image preview
674 dynamic_cast<GraphicsView_ViewManager*>( anApp->createViewManager( GraphicsView_Viewer::Type() ) );
675 if( myRefViewManager )
677 connect( myRefViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
678 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
680 module()->setViewManagerRole( myRefViewManager, HYDROGUI_Module::VMR_ReferenceImage );
681 myRefViewManager->setTitle( tr( "REFERENCE_IMAGE" ) );
682 if( GraphicsView_Viewer* aViewer = myRefViewManager->getViewer() )
684 aViewPort = aViewer->getActiveViewPort();
685 connect( aViewer, SIGNAL( selectionChanged( GV_SelectionChangeStatus ) ),
686 this, SLOT( onRefPointSelected() ) );
694 // Remove the old presentation of the reference image if any
695 if( myRefPreviewPrs )
697 myRefPreviewPrs->setCaption( QString() );
698 aViewPort->removeItem( myRefPreviewPrs );
700 delete myRefPreviewPrs;
704 // Create a new reference image presentation
706 Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast(
707 HYDROGUI_Tool::FindObjectByName( module(), theName, KIND_IMAGE ) );
708 if( !anImageObj.IsNull() )
710 anImage = anImageObj->Image();
712 myRefPreviewPrs = new HYDROGUI_PrsImage( anImageObj );
713 myRefPreviewPrs->setImage( anImage );
714 myRefPreviewPrs->compute();
716 myRefPreviewPrs->setIsTransformationPointPreview( true );
717 myRefPreviewPrs->setTransformationPointType( myPointType );
719 // Add the new reference image presentation to the appropriate view
720 aViewPort->addItem( myRefPreviewPrs );
725 // Split views horizontally
726 if( anApp->desktop()->inherits( "STD_TabDesktop" ) )
728 qApp->processEvents();
729 QtxWorkstack* aWorkstack = ( (STD_TabDesktop*)anApp->desktop() )->workstack();
730 aViewPort->activateWindow();
732 aViewPort->setFocus(Qt::ActiveWindowFocusReason);
733 aWorkstack->splitHorizontal();
736 // Initialize the dialog
737 HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
738 aPanel->setImageSize( anImage.size(), true );
739 aPanel->initializePointSelection();
740 onPointSelected( true );
743 void HYDROGUI_ImportImageOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
748 void HYDROGUI_ImportImageOp::onPointSelected()
750 onPointSelected( myRefPreviewPrs && myRefPreviewPrs->isSelected() );
753 void HYDROGUI_ImportImageOp::onRefPointSelected()
755 onPointSelected( true );
758 void HYDROGUI_ImportImageOp::onPointSelected( bool theIsRefImage )
760 HYDROGUI_PrsImage* aPrs = theIsRefImage ? myRefPreviewPrs : myPreviewPrs;
764 HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
766 const HYDROGUI_PrsImage::TransformationPointMap& aPointMap =
767 aPrs->getTransformationPointMap();
769 HYDROGUI_PrsImage::TransformationPointMapIterator anIter( aPointMap );
770 while( anIter.hasNext() )
772 int aPointType = anIter.next().key();
773 const HYDROGUI_PrsImage::TransformationPoint& aTransformationPoint = anIter.value();
774 const QPoint& aPoint = aTransformationPoint.Point;
776 HYDROGUI_ImportImageDlg::TransformationData aData( aPoint, QPointF(), QPointF() );
777 aDataMap[ aPointType ] = aData;
780 ( (HYDROGUI_ImportImageDlg*)inputPanel() )->setTransformationDataMap( aDataMap, true, theIsRefImage );
783 void HYDROGUI_ImportImageOp::closePreview()
785 closeView( myPreviewViewManager );
786 closeView( myRefViewManager );
788 if( myActiveViewManager )
789 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
792 void HYDROGUI_ImportImageOp::closeView( GraphicsView_ViewManager* &aViewMgr )
796 GraphicsView_ViewPort* aViewPort = 0;
797 if( GraphicsView_Viewer* aViewer = aViewMgr->getViewer() )
799 aViewPort = aViewer->getActiveViewPort();
801 disconnect( aViewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
802 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
804 // Nullify appropriate presentation pointer
805 HYDROGUI_PrsImage* aPrs = 0;
806 switch ( module()->getViewManagerRole( aViewMgr ) )
808 case HYDROGUI_Module::VMR_ReferenceImage:
809 aPrs = myRefPreviewPrs;
812 case HYDROGUI_Module::VMR_TransformImage:
817 // Remove the appropriate presentation from the view
818 if( aPrs && aViewPort )
820 aViewPort->removeItem( aPrs );
825 module()->getApp()->removeViewManager( aViewMgr ); // aViewMgr is deleted here