#include <LightApp_Application.h>
#include <LightApp_UpdateFlags.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_ViewWindow.h>
+
+#include <OCCViewer_ViewManager.h>
+
#include <gp_XY.hxx>
HYDROGUI_GeoreferencementOp::HYDROGUI_GeoreferencementOp( HYDROGUI_Module* theModule, const int theInitialMode )
aPanel->setMode( aSelectionMode );
onModeActivated( aSelectionMode );
}
+
+ LightApp_Application* anApp = module()->getApp();
+ OCCViewer_ViewManager* aViewManager =
+ dynamic_cast<OCCViewer_ViewManager*>( anApp->getViewManager( OCCViewer_Viewer::Type(), false ) );
+ if ( aViewManager ) {
+ connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
+ aPanel, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
+ }
+
+ connect( anApp->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
+ this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
}
void HYDROGUI_GeoreferencementOp::abortOperation()
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 );
-
- // 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 );
}
+void HYDROGUI_GeoreferencementOp::onWindowActivated( SUIT_ViewWindow* theViewWindow )
+{
+ if ( !theViewWindow ) {
+ return;
+ }
+ OCCViewer_ViewManager* aViewManager =
+ dynamic_cast<OCCViewer_ViewManager*>( theViewWindow->getViewManager() );
+ if ( aViewManager ) {
+ HYDROGUI_GeoreferencementDlg* aPanel =
+ ::qobject_cast<HYDROGUI_GeoreferencementDlg*>( inputPanel() );
+ if ( aPanel ) {
+ connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
+ aPanel, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
+ }
+ }
+}
+
+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;
+}