SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
// Import image from file
- myFileGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ) );
+ myFileNameGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ) );
- QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileGroup );
+ QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
- myFileName = new QLineEdit( myFileGroup );
+ myFileName = new QLineEdit( myFileNameGroup );
myFileName->setReadOnly( true );
- QToolButton* aBrowseBtn = new QToolButton( myFileGroup );
+ QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
- QBoxLayout* aFileLayout = new QHBoxLayout( myFileGroup );
- aFileLayout->setMargin( 5 );
- aFileLayout->setSpacing( 5 );
- aFileLayout->addWidget( aFileNameLabel );
- aFileLayout->addWidget( myFileName );
- aFileLayout->addWidget( aBrowseBtn );
+ QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
+ aFileNameLayout->setMargin( 5 );
+ aFileNameLayout->setSpacing( 5 );
+ aFileNameLayout->addWidget( aFileNameLabel );
+ aFileNameLayout->addWidget( myFileName );
+ aFileNameLayout->addWidget( aBrowseBtn );
+
+ // Image name
+ myImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ) );
+
+ QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), myImageNameGroup );
+ myImageName = new QLineEdit( myImageNameGroup );
+
+ QBoxLayout* anImageNameLayout = new QHBoxLayout( myImageNameGroup );
+ anImageNameLayout->setMargin( 5 );
+ anImageNameLayout->setSpacing( 5 );
+ anImageNameLayout->addWidget( anImageNameLabel );
+ anImageNameLayout->addWidget( myImageName );
// Mapping
myMappingGroup = new QGroupBox( tr( "MAPPING" ) );
aMappingLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
// Common
- addWidget( myFileGroup, 0, 0 );
- addWidget( myMappingGroup, 1, 0 );
+ addWidget( myFileNameGroup, 0, 0 );
+ addWidget( myImageNameGroup, 1, 0 );
+ addWidget( myMappingGroup, 2, 0 );
setRowStretch();
void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
{
- myFileGroup->setVisible( !theIsEdit );
+ myFileNameGroup->setVisible( !theIsEdit );
+ myImageNameGroup->setEnabled( theIsEdit );
myMappingGroup->setEnabled( theIsEdit );
}
void HYDROGUI_ImportImageDlg::reset()
{
myFileName->clear();
+ myImageName->clear();
+ myImageNameGroup->setEnabled( false );
for( int aPointType = HYDROGUI_PrsImage::PointA;
aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
{
myMappingGroup->setEnabled( false );
}
+void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
+{
+ myImageName->setText( theName );
+}
+
+QString HYDROGUI_ImportImageDlg::getImageName() const
+{
+ return myImageName->text();
+}
+
void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
const bool theIsOnlyInput )
{
{
myFileName->setText( aFileName );
emit createPreview( anImage );
+ myImageNameGroup->setEnabled( true );
myMappingGroup->setEnabled( true );
}
}
void setIsEdit( const bool theIsEdit );
void reset();
+ void setImageName( const QString& theName );
+ QString getImageName() const;
+
void setTransformationDataMap( const TransformationDataMap& theMap,
const bool theIsOnlyInput = false );
bool getTransformationDataMap( TransformationDataMap& theMap ) const;
void activatePointSelection( int );
private:
- QGroupBox* myFileGroup;
+ QGroupBox* myFileNameGroup;
QLineEdit* myFileName;
+ QGroupBox* myImageNameGroup;
+ QLineEdit* myImageName;
+
QGroupBox* myMappingGroup;
QMap<int, QPushButton*> myPointBtnMap;
QMap<int, QLineEdit*> myPointXMap;
}
}
+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 = findObjectByName( anImageName, KIND_UNKNOWN );
+ 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();
HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
+ QString anImageName;
+ if( myIsEdit )
+ {
+ if( !myEditedObject.IsNull() )
+ anImageName = myEditedObject->GetName();
+ }
+ else
+ {
+ int anImageId = 1;
+ while( anImageId < 100 )
+ {
+ anImageName = QString( "Image_%1" ).arg( QString::number( anImageId++ ) );
+
+ // check that there are no other objects with the same name in the document
+ Handle(HYDROData_Object) anObject = findObjectByName( anImageName, KIND_UNKNOWN );
+ if( anObject.IsNull() )
+ break;
+ }
+ }
+ aPanel->setImageName( anImageName );
+
aPanel->initializePointSelection();
onPointSelected();
}
protected:
virtual void startOperation();
+ virtual void abortOperation();
+ virtual void commitOperation();
virtual HYDROGUI_InputPanel* createInputPanel() const;
- virtual bool processApply( int& theUpdateFlags );
- virtual void processCancel();
+ virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg );
protected slots:
void onCreatePreview( QImage );
return NULL;
}
-bool HYDROGUI_Operation::processApply( int& theUpdateFlags )
+bool HYDROGUI_Operation::processApply( int& theUpdateFlags,
+ QString& theErrorMsg )
{
return false;
}
void HYDROGUI_Operation::onApply()
{
int anUpdateFlags = 0;
- if( processApply( anUpdateFlags ) )
+ QString anErrorMsg;
+ if( processApply( anUpdateFlags, anErrorMsg ) )
{
module()->update( anUpdateFlags );
commit();
}
else
{
+ QString aMsg = tr( "INPUT_VALID_DATA" );
+ if( !anErrorMsg.isEmpty() )
+ aMsg.prepend( anErrorMsg + "\n" );
SUIT_MessageBox::critical( module()->getApp()->desktop(),
tr( "INSUFFICIENT_INPUT_DATA" ),
- tr( "INPUT_VALID_DATA" ) );
+ aMsg );
}
}
virtual HYDROGUI_InputPanel* createInputPanel() const;
- virtual bool processApply( int& theUpdateFlags );
+ virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg );
virtual void processCancel();
Handle_HYDROData_Document doc() const;
return new HYDROGUI_PolylineDlg( module(), getName() );
}
-bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags )
+bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags,
+ QString& theErrorMsg )
{
HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
protected:
virtual HYDROGUI_InputPanel* createInputPanel() const;
- virtual bool processApply( int& theUpdateFlags );
+ virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg );
virtual void startOperation();
return new HYDROGUI_TwoImagesDlg( module(), getName() );
}
-bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags )
+bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
+ QString& theErrorMsg )
{
HYDROGUI_TwoImagesDlg* aPanel = dynamic_cast<HYDROGUI_TwoImagesDlg*>( inputPanel() );
protected:
virtual HYDROGUI_InputPanel* createInputPanel() const;
- virtual bool processApply( int& theUpdateFlags );
+ virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg );
private:
int myType;
</context>
<context>
<name>HYDROGUI_ImportImageDlg</name>
+ <message>
+ <source>ACTIVATE_POINT_A_SELECTION</source>
+ <translation>Activate point A selection</translation>
+ </message>
+ <message>
+ <source>ACTIVATE_POINT_B_SELECTION</source>
+ <translation>Activate point B selection</translation>
+ </message>
+ <message>
+ <source>ACTIVATE_POINT_C_SELECTION</source>
+ <translation>Activate point C selection</translation>
+ </message>
<message>
<source>BROWSE_IMAGE_FILE</source>
<translation>Browse image file</translation>
<source>IMAGE_FILTER</source>
<translation>Image files (*.bmp *.jpg *.jpeg *.png);;All files (*.* *)</translation>
</message>
+ <message>
+ <source>IMAGE_NAME</source>
+ <translation>Image name</translation>
+ </message>
<message>
<source>IMPORT_IMAGE_FROM_FILE</source>
<translation>Import image from file</translation>
<translation>Mapping</translation>
</message>
<message>
- <source>ACTIVATE_POINT_A_SELECTION</source>
- <translation>Activate point A selection</translation>
- </message>
- <message>
- <source>ACTIVATE_POINT_B_SELECTION</source>
- <translation>Activate point B selection</translation>
- </message>
- <message>
- <source>ACTIVATE_POINT_C_SELECTION</source>
- <translation>Activate point C selection</translation>
+ <source>NAME</source>
+ <translation>Name</translation>
</message>
</context>
<context>
<source>MAPPING</source>
<translation>Mapping</translation>
</message>
+ <message>
+ <source>OBJECT_EXISTS_IN_DOCUMENT</source>
+ <translation>Object with name '%1' already exists in the document.</translation>
+ </message>
+ <message>
+ <source>POINTS_A_B_C_BELONG_TO_SINGLE_LINE</source>
+ <translation>Points A, B, C belong to a single line.</translation>
+ </message>
+ <message>
+ <source>TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED</source>
+ <translation>Transformation matrix cannot be computed.</translation>
+ </message>
</context>
<context>
<name>HYDROGUI_Module</name>