Salome HOME
Profile object creation.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_GeoreferencementOp.cxx
index e1dfd89d2b903eeee05137d53dd727c109e42380..15595b6050a611b08f682823a8b8b6bf5499cb39 100644 (file)
@@ -36,6 +36,7 @@
 #include <LightApp_UpdateFlags.h>
 
 #include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
 #include <SUIT_ViewWindow.h>
 
 #include <OCCViewer_ViewManager.h>
@@ -108,49 +109,36 @@ HYDROGUI_InputPanel* HYDROGUI_GeoreferencementOp::createInputPanel() const
 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;
   
@@ -184,6 +172,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 +195,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<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;
+}