From: mzn Date: Fri, 29 Nov 2013 06:55:36 +0000 (+0000) Subject: Feature #84: Profiles georeferencement (12.4). X-Git-Tag: BR_hydro_v_0_4~136 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=347f7cf014bec3113cc79c89b0d19ef5735aab10;p=modules%2Fhydro.git Feature #84: Profiles georeferencement (12.4). Add error message for incomplete data rows. Store data in the data model on mode change. --- diff --git a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx index 534ba659..bd10b2c0 100644 --- a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.cxx @@ -40,6 +40,32 @@ #include #include +//! Profile data structre constructor +HYDROGUI_GeoreferencementDlg::ProfileGeoData::ProfileGeoData( + const QString& theXg, const QString& theYg, + const QString& theXd, const QString& theYd) +{ + this->isEmpty = theXg.isEmpty() && theYg.isEmpty() && + theXd.isEmpty() && theYd.isEmpty(); + this->isIncomplete = !isEmpty; + + if ( isIncomplete ) { + bool isOk = false; + + this->Xg= theXg.toDouble( &isOk ); + if ( isOk ) { + this->Yg = theYg.toDouble( &isOk ); + if ( isOk ) { + this->Xd = theXd.toDouble( &isOk ); + if ( isOk ) { + this->Yd = theYd.toDouble( &isOk ); + this->isIncomplete = !isOk; + } + } + } + } +} + //! Custom item delegate (line edit with double validator) class HYDROGUI_GeoreferencementDlg::Delegate : public QItemDelegate { @@ -181,7 +207,7 @@ void HYDROGUI_GeoreferencementDlg::setData( const ProfilesGeoDataMap& theMap ) // Get georeferencement data for the current profile ProfileGeoData aGeoData = theMap.value( aProfileName ); QString aXg, anYg, aXd, anYd; - if ( aGeoData.isValid ) { + if ( !aGeoData.isEmpty ) { aXg = getString( aGeoData.Xg ); anYg = getString( aGeoData.Yg ); aXd = getString( aGeoData.Xd ); @@ -223,26 +249,16 @@ void HYDROGUI_GeoreferencementDlg::getData( ProfilesGeoDataMap& theMap ) // Fill the map bool isOk = false; + QString aXg, anYg, aXd, anYd; for ( int aRow = 0; aRow < myTable->rowCount(); aRow++ ) { QString aProfileName = myTable->item( aRow, 0 )->text(); - theMap.insert( aProfileName, ProfileGeoData() ); - - double aXg, anYg, aXd, anYd; - - aXg = myTable->item( aRow, 1 )->text().toDouble( &isOk ); - if ( !isOk ) continue; - - anYg = myTable->item( aRow, 2 )->text().toDouble( &isOk ); - if ( !isOk ) continue; - - aXd = myTable->item( aRow, 3 )->text().toDouble( &isOk ); - if ( !isOk ) continue; - - anYd = myTable->item( aRow, 4 )->text().toDouble( &isOk ); - if ( !isOk ) continue; + aXg = myTable->item( aRow, 1 )->text(); + anYg = myTable->item( aRow, 2 )->text(); + aXd = myTable->item( aRow, 3 )->text(); + anYd = myTable->item( aRow, 4 )->text(); - theMap[aProfileName] = ProfileGeoData( aXg, anYg, aXd, anYd ); + theMap.insert( aProfileName, ProfileGeoData( aXg, anYg, aXd, anYd ) ); } } diff --git a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.h b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.h index 25e2130e..428cf1c7 100644 --- a/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.h +++ b/src/HYDROGUI/HYDROGUI_GeoreferencementDlg.h @@ -47,13 +47,18 @@ public: double Xd; double Yd; - bool isValid; + bool isIncomplete, isEmpty; ProfileGeoData() : - isValid( false ) {} + isEmpty( true ), isIncomplete( false ) {} - ProfileGeoData( double theXg, double theYg, double theXd, double theYd ) : - Xg( theXg ), Yg( theYg ), Xd( theXd ), Yd( theYd ), isValid( true ) {} + ProfileGeoData( const QString& theXg, const QString& theYg, + const QString& theXd, const QString& theYd ); + + ProfileGeoData( double theXg, double theYg, + double theXd, double theYd ) + : Xg( theXg ), Yg( theYg ), Xd( theXd ), Yd( theYd ), + isIncomplete(false), isEmpty(false) {} }; typedef QMap< QString, ProfileGeoData > ProfilesGeoDataMap; diff --git a/src/HYDROGUI/HYDROGUI_GeoreferencementOp.cxx b/src/HYDROGUI/HYDROGUI_GeoreferencementOp.cxx index e1dfd89d..80a0373e 100644 --- a/src/HYDROGUI/HYDROGUI_GeoreferencementOp.cxx +++ b/src/HYDROGUI/HYDROGUI_GeoreferencementOp.cxx @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -108,49 +109,38 @@ HYDROGUI_InputPanel* HYDROGUI_GeoreferencementOp::createInputPanel() const bool HYDROGUI_GeoreferencementOp::processApply( int& theUpdateFlags, QString& theErrorMsg ) { - HYDROGUI_GeoreferencementDlg* aPanel = - ::qobject_cast( inputPanel() ); - if ( !aPanel ) { - return false; - } - - // Get georeferencement data from the panel - HYDROGUI_GeoreferencementDlg::ProfilesGeoDataMap aGeoDataMap; - aPanel->getData( aGeoDataMap ); - - if ( aGeoDataMap.empty() ) { - return false; - } - - // Set the data - foreach ( const QString& aProfileName, aGeoDataMap.keys() ) { - Handle(HYDROData_Profile) aProfile = - Handle(HYDROData_Profile)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) ); - if ( !aProfile.IsNull() ) { - HYDROGUI_GeoreferencementDlg::ProfileGeoData aGeoData = - aGeoDataMap.value( aProfileName ); - if ( aGeoData.isValid ) { - aProfile->SetFirstPoint( gp_XY( aGeoData.Xg, aGeoData.Yg ) ); - aProfile->SetLastPoint( gp_XY( aGeoData.Xd, aGeoData.Yd ) ); - } else { - aProfile->Invalidate(); - } - } - } - theUpdateFlags = UF_Model; - return true; + + return store( theErrorMsg ); } void HYDROGUI_GeoreferencementOp::onModeActivated( const int theActualMode ) { + QString anErrorMsg; + + // Get the panel HYDROGUI_GeoreferencementDlg* aPanel = ::qobject_cast( inputPanel() ); if ( !aPanel ) { return; } + // Store the dialog data to the data model + if ( !store( anErrorMsg ) ) { + aPanel->setMode( theActualMode == HYDROGUI_GeoreferencementDlg::AllProfiles ? + HYDROGUI_GeoreferencementDlg::SelectedProfiles : + HYDROGUI_GeoreferencementDlg::AllProfiles ); + + if ( anErrorMsg.isEmpty() ) { + anErrorMsg = tr( "INSUFFICIENT_INPUT_DATA" ); + } + SUIT_MessageBox::critical( module()->getApp()->desktop(), + tr( "ERROR" ), + anErrorMsg ); + return; + } + + // Get georeferencement data from the data model HYDROGUI_GeoreferencementDlg::ProfilesGeoDataMap aDataMap; HYDROData_SequenceOfObjects aSeqOfProfiles; @@ -184,6 +174,7 @@ void HYDROGUI_GeoreferencementOp::onModeActivated( const int theActualMode ) aDataMap.insert( aProfile->GetName(), aGeoData ); } + // Set the collected data to the dialog aPanel->setData( aDataMap ); } @@ -206,3 +197,52 @@ void HYDROGUI_GeoreferencementOp::onWindowActivated( SUIT_ViewWindow* theViewWin } } +bool HYDROGUI_GeoreferencementOp::store( QString& theErrorMsg ) +{ + // Clear the error string + theErrorMsg.clear(); + + // Get the panel + HYDROGUI_GeoreferencementDlg* aPanel = + ::qobject_cast( inputPanel() ); + if ( !aPanel ) { + return false; + } + + // Get georeferencement data from the panel + HYDROGUI_GeoreferencementDlg::ProfilesGeoDataMap aGeoDataMap; + aPanel->getData( aGeoDataMap ); + + if ( aGeoDataMap.empty() ) { + return true; + } + + // Check the data validity + foreach ( const QString& aProfileName, aGeoDataMap.keys() ) { + HYDROGUI_GeoreferencementDlg::ProfileGeoData aGeoData = + aGeoDataMap.value( aProfileName ); + if ( aGeoData.isIncomplete ) { + theErrorMsg = tr( "INCOMPLETE_DATA" ).arg( aProfileName ); + return false; + } + } + + // Store the data in the data model + foreach ( const QString& aProfileName, aGeoDataMap.keys() ) { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) ); + if ( !aProfile.IsNull() ) { + HYDROGUI_GeoreferencementDlg::ProfileGeoData aGeoData = + aGeoDataMap.value( aProfileName ); + if ( !aGeoData.isEmpty ) { + aProfile->SetFirstPoint( gp_XY( aGeoData.Xg, aGeoData.Yg ) ); + aProfile->SetLastPoint( gp_XY( aGeoData.Xd, aGeoData.Yd ) ); + } else { + aProfile->Invalidate(); + } + } + } + + return true; +} diff --git a/src/HYDROGUI/HYDROGUI_GeoreferencementOp.h b/src/HYDROGUI/HYDROGUI_GeoreferencementOp.h index e8c362b4..e76cbd12 100644 --- a/src/HYDROGUI/HYDROGUI_GeoreferencementOp.h +++ b/src/HYDROGUI/HYDROGUI_GeoreferencementOp.h @@ -51,6 +51,9 @@ protected slots: void onModeActivated( const int theActualMode ); void onWindowActivated( SUIT_ViewWindow* theViewWindow ); +private: + bool store( QString& theErrorMsg ); + private: int myInitialMode; }; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index eeec7ed1..27f7350c 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -1351,6 +1351,10 @@ file cannot be correctly imported for an Obstacle definition. PROFILES_GEOREFERENCEMENT Profiles georeferencement + + INCOMPLETE_DATA + Incomplete data is set for '%1'. +