#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);
+
+ anErrorMsg.append( "\n" + tr( "INPUT_VALID_DATA" ) );
+ SUIT_MessageBox::critical( module()->getApp()->desktop(),
+ tr( "INSUFFICIENT_INPUT_DATA" ),
+ 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;
+}