#include "HYDROGUI_Tool.h"
#include "HYDROGUI_UpdateFlags.h"
-#include <HYDROData_Document.h>
-
#include <GraphicsView_ViewManager.h>
#include <GraphicsView_ViewPort.h>
#include <GraphicsView_Viewer.h>
}
}
+void HYDROGUI_ImportImageOp::abortOperation()
+{
+ closePreview();
+
+ HYDROGUI_Operation::abortOperation();
+}
+
+void HYDROGUI_ImportImageOp::commitOperation()
+{
+ closePreview();
+
+ HYDROGUI_Operation::commitOperation();
+}
+
HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const
{
HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportImageDlg( module(), getName() );
return aPanel;
}
-bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags )
+bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
+ QString& theErrorMsg )
{
HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
+ QString anImageName = aPanel->getImageName();
+ if( anImageName.isEmpty() )
+ return false;
+
+ if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) )
+ {
+ // check that there are no other objects with the same name in the document
+ Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
+ if( !anObject.IsNull() )
+ {
+ theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
+ return false;
+ }
+ }
+
+ QImage anImage = myPreviewPrs->getImage();
+
HYDROGUI_ImportImageDlg::TransformationDataMap aMap;
bool anIsOk = aPanel->getTransformationDataMap( aMap );
if( !anIsOk || !myPreviewPrs )
QPointF aPointB2 = aMap[ HYDROGUI_PrsImage::PointB ].second;
QPointF aPointC2 = aMap[ HYDROGUI_PrsImage::PointC ].second;
- double xa1 = aPointA1.x();
- double ya1 = aPointA1.y();
- double xb1 = aPointB1.x();
- double yb1 = aPointB1.y();
- double xc1 = aPointC1.x();
- double yc1 = aPointC1.y();
+ int xa1 = aPointA1.x();
+ int ya1 = aPointA1.y();
+ int xb1 = aPointB1.x();
+ int yb1 = aPointB1.y();
+ int xc1 = aPointC1.x();
+ int yc1 = aPointC1.y();
double xa2 = aPointA2.x();
double ya2 = aPointA2.y();
double xc2 = aPointC2.x();
double yc2 = aPointC2.y();
+ // first, check that three input points don't belong to a single line
+ if( ( yb1 - ya1 ) * ( xc1 - xa1 ) == ( yc1 - ya1 ) * ( xb1 - xa1 ) )
+ {
+ theErrorMsg = tr( "POINTS_A_B_C_BELONG_TO_SINGLE_LINE" );
+ return false;
+ }
+
QTransform aTransform1( xa1, ya1, 1, xb1, yb1, 1, xc1, yc1, 1 );
QTransform aTransform2( xa2, ya2, 1, xb2, yb2, 1, xc2, yc2, 1 );
- QTransform aTransform = aTransform1.inverted() * aTransform2;
-
- QImage anImage = myPreviewPrs->getImage();
-
- closePreview();
+ bool anIsInvertible = false;
+ QTransform aTransform = aTransform1.inverted( &anIsInvertible ) * aTransform2;
+ if( !anIsInvertible )
+ {
+ theErrorMsg = tr( "TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED" );
+ return false;
+ }
Handle(HYDROData_Image) anImageObj;
if( myIsEdit )
if( anImageObj.IsNull() )
return false;
- if( !myIsEdit )
- {
- static int ImageId = 0;
- anImageObj->SetName( QString( "Image_%1" ).arg( QString::number( ++ImageId ) ) );
- }
+ anImageObj->SetName( anImageName );
anImageObj->SetImage( anImage );
anImageObj->SetTrsf( aTransform );
return true;
}
-void HYDROGUI_ImportImageOp::processCancel()
-{
- closePreview();
-}
-
void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
{
LightApp_Application* anApp = module()->getApp();
dynamic_cast<GraphicsView_ViewManager*>( anApp->createViewManager( GraphicsView_Viewer::Type() ) );
if( myPreviewViewManager )
{
+ module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_Mapping );
myPreviewViewManager->setTitle( tr( "MAPPING" ) );
if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
{
HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
+ QString anImageName;
+ if( myIsEdit )
+ {
+ if( !myEditedObject.IsNull() )
+ anImageName = myEditedObject->GetName();
+ }
+ else
+ anImageName = HYDROGUI_Tool::GenerateObjectName( module(), "Image" );
+ aPanel->setImageName( anImageName );
+
aPanel->initializePointSelection();
onPointSelected();
}