#include <STD_TabDesktop.h>
#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
#include <QtxWorkstack.h>
#include <QApplication>
+#include <QFileInfo>
HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule,
const bool theIsEdit )
theErrorMsg = theLineErrMsg;
return false;
}
+
+ if ( theIsToCheckInvertibles )
+ {
+ QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
+
+ bool anIsInvertible = false;
+ QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
+ if( !anIsInvertible )
+ {
+ theErrorMsg = tr( "TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED" );
+ return false;
+ }
+ }
}
else
{
// check that two points are not identical
- if ( ValuesEquals( xa, ya ) && ValuesEquals( xb, yb ) )
+ if ( ValuesEquals( xa, xb ) && ValuesEquals( ya, yb ) )
{
theErrorMsg = thePoinErrMsg;
return false;
}
}
- if ( theIsToCheckInvertibles )
- {
- QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
-
- bool anIsInvertible = false;
- QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
- if( !anIsInvertible )
- {
- theErrorMsg = tr( "TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED" );
- return false;
- }
- }
-
return true;
}
if( aRefImageObj.IsNull() )
return false;
+ else if ( !isReferenceCorrect() )
+ aRefImageObj->RemoveAllReferences();
+
aTrsfPointA = aRefMap[ HYDROGUI_PrsImage::PointA ].ImagePoint;
aTrsfPointB = aRefMap[ HYDROGUI_PrsImage::PointB ].ImagePoint;
if ( !anIsByTwoPoints )
if( !myIsEdit )
module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), anImageObj, true );
- if( myIsEdit )
- anImageObj->Update();
+ anImageObj->Update();
theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;
return true;
}
+bool HYDROGUI_ImportImageOp::isReferenceCorrect() const
+{
+ bool isCorrect = true;
+
+ if( myIsEdit && !myEditedObject.IsNull() )
+ {
+ HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
+ Handle(HYDROData_Image) aRefImageObj = Handle(HYDROData_Image)::DownCast(
+ HYDROGUI_Tool::FindObjectByName( module(), aPanel->getRefImageName(), KIND_IMAGE ) );
+ if( !aRefImageObj.IsNull() )
+ {
+ bool isFoundEdited = false;
+ HYDROData_SequenceOfObjects aRefSeq = aRefImageObj->GetAllReferenceObjects();
+ for ( int i = 1, n = aRefSeq.Length(); i <= n && !isFoundEdited; ++i )
+ {
+ Handle(HYDROData_Entity) anObject = aRefSeq.Value( i );
+ isFoundEdited = anObject->GetName() == myEditedObject->GetName();
+ }
+ isCorrect = !isFoundEdited;
+ }
+ }
+ return isCorrect;
+}
+
+void HYDROGUI_ImportImageOp::onApply()
+{
+ HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
+
+ bool aCanApply = isReferenceCorrect();
+ if ( !aCanApply && !myEditedObject.IsNull() )
+ {
+ Handle(HYDROData_Image) aRefImageObj = Handle(HYDROData_Image)::DownCast(
+ HYDROGUI_Tool::FindObjectByName( module(), aPanel->getRefImageName(), KIND_IMAGE ) );
+ if ( !aRefImageObj.IsNull() )
+ aCanApply = SUIT_MessageBox::question( module()->getApp()->desktop(),
+ tr( "CORRECT_INPUT_DATA" ), tr( "CONFIRM_REMOVE_REFERENCE_FROM_IMAGE" ).
+ arg( aRefImageObj->GetName() ).arg( myEditedObject->GetName() ),
+ QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) == QMessageBox::Yes;
+ }
+ if ( aCanApply )
+ HYDROGUI_Operation::onApply();
+ else {
+ aPanel->setRefImageName( "" );
+ onRefImageActivated( aPanel->getRefImageName() );
+ }
+}
+
void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
{
HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
}
}
- QString anImageName;
- if( myIsEdit )
+ // Set the image name in the dialog
+ QString anImageName = aPanel->getImageName().simplified();
+ // If edit mode and the name was not set yet then get from the edited object
+ if( myIsEdit && anImageName.isEmpty() )
{
if( !myEditedObject.IsNull() )
anImageName = myEditedObject->GetName();
}
- else
- anImageName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMAGE_NAME" ) );
+ // If the name was not set then initialize it from the selected file name
+ if ( anImageName.isEmpty() )
+ {
+ anImageName = aPanel->getFileName();
+ if ( !anImageName.isEmpty() ) {
+ anImageName = QFileInfo( anImageName ).baseName();
+ }
+ // If no file name then generate a new image name
+ if ( anImageName.isEmpty() ) {
+ anImageName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMAGE_NAME" ) );
+ }
+ }
+
aPanel->setImageName( anImageName );
}
aPanel->initializePointSelection();
onPointSelected( false );
+ onSetCIsUsed( !aPanel->isByTwoPoints() );
}
void HYDROGUI_ImportImageOp::onActivatePointSelection( int thePointType )