From: ouv Date: Mon, 12 Aug 2013 13:33:50 +0000 (+0000) Subject: 1) Image name X-Git-Tag: BR_hydro_v_0_1~117 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b475ac9f5ce7ab52045e70fec0c8e6f8ffb51432;p=modules%2Fhydro.git 1) Image name 2) Error management --- diff --git a/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx index eb7a24b1..9e3e173b 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx @@ -46,22 +46,34 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co 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" ) ); @@ -181,8 +193,9 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co 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(); @@ -195,13 +208,16 @@ HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg() 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++ ) { @@ -222,6 +238,16 @@ void HYDROGUI_ImportImageDlg::reset() 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 ) { @@ -326,6 +352,7 @@ void HYDROGUI_ImportImageDlg::onBrowse() { myFileName->setText( aFileName ); emit createPreview( anImage ); + myImageNameGroup->setEnabled( true ); myMappingGroup->setEnabled( true ); } } diff --git a/src/HYDROGUI/HYDROGUI_ImportImageDlg.h b/src/HYDROGUI/HYDROGUI_ImportImageDlg.h index a1dcbda5..752a5201 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageDlg.h +++ b/src/HYDROGUI/HYDROGUI_ImportImageDlg.h @@ -45,6 +45,9 @@ public: 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; @@ -60,9 +63,12 @@ signals: void activatePointSelection( int ); private: - QGroupBox* myFileGroup; + QGroupBox* myFileNameGroup; QLineEdit* myFileName; + QGroupBox* myImageNameGroup; + QLineEdit* myImageName; + QGroupBox* myMappingGroup; QMap myPointBtnMap; QMap myPointXMap; diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx index 2ab7cec6..d86e4cfc 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx @@ -102,6 +102,20 @@ void HYDROGUI_ImportImageOp::startOperation() } } +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() ); @@ -112,10 +126,28 @@ HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const 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 ) @@ -129,12 +161,12 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags ) 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(); @@ -143,14 +175,23 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags ) 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 ) @@ -161,11 +202,7 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags ) 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 ); @@ -179,11 +216,6 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags ) return true; } -void HYDROGUI_ImportImageOp::processCancel() -{ - closePreview(); -} - void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage ) { LightApp_Application* anApp = module()->getApp(); @@ -217,6 +249,27 @@ void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage ) 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(); } diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.h b/src/HYDROGUI/HYDROGUI_ImportImageOp.h index bdb58867..fa4472e2 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.h +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.h @@ -45,11 +45,12 @@ public: 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 ); diff --git a/src/HYDROGUI/HYDROGUI_Operation.cxx b/src/HYDROGUI/HYDROGUI_Operation.cxx index b19684ab..aacf5dfc 100644 --- a/src/HYDROGUI/HYDROGUI_Operation.cxx +++ b/src/HYDROGUI/HYDROGUI_Operation.cxx @@ -116,7 +116,8 @@ HYDROGUI_InputPanel* HYDROGUI_Operation::createInputPanel() const return NULL; } -bool HYDROGUI_Operation::processApply( int& theUpdateFlags ) +bool HYDROGUI_Operation::processApply( int& theUpdateFlags, + QString& theErrorMsg ) { return false; } @@ -145,16 +146,20 @@ Handle_HYDROData_Object HYDROGUI_Operation::findObjectByName( const QString& the 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 ); } } diff --git a/src/HYDROGUI/HYDROGUI_Operation.h b/src/HYDROGUI/HYDROGUI_Operation.h index 1f3ae1d5..6ab80bd1 100644 --- a/src/HYDROGUI/HYDROGUI_Operation.h +++ b/src/HYDROGUI/HYDROGUI_Operation.h @@ -53,7 +53,7 @@ protected: 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; diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx index 774f3c36..b8a69826 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx @@ -46,7 +46,8 @@ HYDROGUI_InputPanel* HYDROGUI_PolylineOp::createInputPanel() 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(); diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.h b/src/HYDROGUI/HYDROGUI_PolylineOp.h index d3377603..c56ec0a4 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.h +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.h @@ -38,7 +38,7 @@ public: protected: virtual HYDROGUI_InputPanel* createInputPanel() const; - virtual bool processApply( int& theUpdateFlags ); + virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); virtual void startOperation(); diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx index a91d4734..872a0977 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx @@ -57,7 +57,8 @@ HYDROGUI_InputPanel* HYDROGUI_TwoImagesOp::createInputPanel() const 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( inputPanel() ); diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.h b/src/HYDROGUI/HYDROGUI_TwoImagesOp.h index 8940d854..d5b3306d 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.h +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.h @@ -39,7 +39,7 @@ public: protected: virtual HYDROGUI_InputPanel* createInputPanel() const; - virtual bool processApply( int& theUpdateFlags ); + virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); private: int myType; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 30f70b53..e6ff1d24 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -54,6 +54,18 @@ HYDROGUI_ImportImageDlg + + ACTIVATE_POINT_A_SELECTION + Activate point A selection + + + ACTIVATE_POINT_B_SELECTION + Activate point B selection + + + ACTIVATE_POINT_C_SELECTION + Activate point C selection + BROWSE_IMAGE_FILE Browse image file @@ -66,6 +78,10 @@ IMAGE_FILTER Image files (*.bmp *.jpg *.jpeg *.png);;All files (*.* *) + + IMAGE_NAME + Image name + IMPORT_IMAGE_FROM_FILE Import image from file @@ -75,16 +91,8 @@ Mapping - ACTIVATE_POINT_A_SELECTION - Activate point A selection - - - ACTIVATE_POINT_B_SELECTION - Activate point B selection - - - ACTIVATE_POINT_C_SELECTION - Activate point C selection + NAME + Name @@ -101,6 +109,18 @@ MAPPING Mapping + + OBJECT_EXISTS_IN_DOCUMENT + Object with name '%1' already exists in the document. + + + POINTS_A_B_C_BELONG_TO_SINGLE_LINE + Points A, B, C belong to a single line. + + + TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED + Transformation matrix cannot be computed. + HYDROGUI_Module