#include <QLayout>
#include <QMouseEvent>
+//! 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
{
// 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 );
// 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 ) );
}
}
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;
#include <LightApp_UpdateFlags.h>
#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
#include <SUIT_ViewWindow.h>
#include <OCCViewer_ViewManager.h>
bool HYDROGUI_GeoreferencementOp::processApply( int& theUpdateFlags,
QString& theErrorMsg )
{
- HYDROGUI_GeoreferencementDlg* aPanel =
- ::qobject_cast<HYDROGUI_GeoreferencementDlg*>( 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<HYDROGUI_GeoreferencementDlg*>( 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;
aDataMap.insert( aProfile->GetName(), aGeoData );
}
+ // Set the collected data to the dialog
aPanel->setData( aDataMap );
}
}
}
+bool HYDROGUI_GeoreferencementOp::store( QString& theErrorMsg )
+{
+ // Clear the error string
+ theErrorMsg.clear();
+
+ // Get the panel
+ HYDROGUI_GeoreferencementDlg* aPanel =
+ ::qobject_cast<HYDROGUI_GeoreferencementDlg*>( 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;
+}