Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WaveHeightLocationsView.cs =================================================================== diff -u -r161308cb864a66713f62357c6bcdb6ede03b619f -r3f790bcdb1b5d03f6cc3071e1a4187dbf89f58f7 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WaveHeightLocationsView.cs (.../WaveHeightLocationsView.cs) (revision 161308cb864a66713f62357c6bcdb6ede03b619f) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/WaveHeightLocationsView.cs (.../WaveHeightLocationsView.cs) (revision 3f790bcdb1b5d03f6cc3071e1a4187dbf89f58f7) @@ -1,4 +1,4 @@ -// Copyright (C) Stichting Deltares 2016. All rights reserved. +// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of Ringtoets. // @@ -21,195 +21,105 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Windows.Forms; using Core.Common.Base; -using Core.Common.Controls.Views; -using Core.Common.Gui.Selection; -using Core.Common.Utils.Extensions; -using Core.Common.Utils.Reflection; using Ringtoets.Common.Data.AssessmentSection; -using Ringtoets.HydraRing.Data; -using Ringtoets.Integration.Forms.Commands; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Forms.Views; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Forms.Properties; +using Ringtoets.Integration.Service.MessageProviders; namespace Ringtoets.Integration.Forms.Views { /// /// View for the with . /// - public partial class WaveHeightLocationsView : UserControl, ISelectionProvider + public partial class WaveHeightLocationsView : HydraulicBoundaryLocationsView { private readonly Observer assessmentSectionObserver; private readonly Observer hydraulicBoundaryDatabaseObserver; - private IAssessmentSection assessmentSection; - private bool updatingDataSource; /// /// Creates a new instance of . /// - public WaveHeightLocationsView() + /// The assessment section which the locations belong to. + /// Thrown when + /// is null. + public WaveHeightLocationsView(IAssessmentSection assessmentSection) + : base(assessmentSection) { InitializeComponent(); - InitializeDataGridView(); - assessmentSectionObserver = new Observer(UpdateDataGridViewDataSource); - hydraulicBoundaryDatabaseObserver = new Observer(() => dataGridViewControl.RefreshDataGridView()); + assessmentSectionObserver = new Observer(UpdateHydraulicBoundaryDatabase); + hydraulicBoundaryDatabaseObserver = new Observer(HandleHydraulicBoundaryDatabaseUpdate); + + assessmentSectionObserver.Observable = AssessmentSection; + hydraulicBoundaryDatabaseObserver.Observable = AssessmentSection.HydraulicBoundaryDatabase; } - /// - /// Gets or sets the . - /// - public IApplicationSelection ApplicationSelection { get; set; } + protected override object CreateSelectedItemFromCurrentRow() + { + DataGridViewRow currentRow = dataGridViewControl.CurrentRow; - /// - /// Gets or sets the . - /// - public IHydraulicBoundaryLocationCalculationCommandHandler CalculationCommandHandler { get; set; } + return currentRow != null + ? new WaveHeightLocationContext(((HydraulicBoundaryLocationRow) currentRow.DataBoundItem).CalculatableObject, + AssessmentSection.HydraulicBoundaryDatabase) + : null; + } - public object Data + protected override void HandleCalculateSelectedLocations(IEnumerable locations) { - get + if (AssessmentSection?.HydraulicBoundaryDatabase == null) { - return assessmentSection; + return; } - set - { - assessmentSection = value as IAssessmentSection; - UpdateDataGridViewDataSource(); - assessmentSectionObserver.Observable = assessmentSection; + bool successfulCalculation = CalculationGuiService.CalculateWaveHeights(AssessmentSection.HydraulicBoundaryDatabase.FilePath, + AssessmentSection.HydraulicBoundaryDatabase.EffectivePreprocessorDirectory(), + locations, + AssessmentSection.FailureMechanismContribution.Norm, + new WaveHeightCalculationMessageProvider()); + + if (successfulCalculation) + { + AssessmentSection.HydraulicBoundaryDatabase.NotifyObservers(); } } - public object Selection + protected override void InitializeDataGridView() { - get - { - return CreateSelectedItemFromCurrentRow(); - } + base.InitializeDataGridView(); + dataGridViewControl.AddTextBoxColumn(nameof(HydraulicBoundaryLocationRow.Result), + Resources.HydraulicBoundaryDatabase_Location_WaveHeight_DisplayName); } protected override void Dispose(bool disposing) { assessmentSectionObserver.Dispose(); hydraulicBoundaryDatabaseObserver.Dispose(); - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); } - private void SetHydraulicBoundaryDatabaseObserver() + protected override HydraulicBoundaryLocationCalculation GetCalculation(HydraulicBoundaryLocation location) { - hydraulicBoundaryDatabaseObserver.Observable = assessmentSection != null ? assessmentSection.HydraulicBoundaryDatabase : null; + return location.WaveHeightCalculation; } - private void InitializeDataGridView() + private void UpdateHydraulicBoundaryDatabase() { - dataGridViewControl.AddCellClickHandler(DataGridViewOnCellClick); + HydraulicBoundaryDatabase hydraulicBoundaryDatabase = AssessmentSection.HydraulicBoundaryDatabase; - dataGridViewControl.AddCheckBoxColumn(TypeUtils.GetMemberName(row => row.ToCalculate), - Resources.HydraulicBoundaryLocationsView_Calculate); - dataGridViewControl.AddTextBoxColumn(TypeUtils.GetMemberName(row => row.Name), - Resources.HydraulicBoundaryDatabase_Locations_Name_DisplayName); - dataGridViewControl.AddTextBoxColumn(TypeUtils.GetMemberName(row => row.Id), - Resources.HydraulicBoundaryDatabase_Locations_Id_DisplayName); - dataGridViewControl.AddTextBoxColumn(TypeUtils.GetMemberName(row => row.Location), - Resources.HydraulicBoundaryDatabase_Locations_Coordinates_DisplayName); - dataGridViewControl.AddTextBoxColumn(TypeUtils.GetMemberName(row => row.WaveHeight), - Resources.HydraulicBoundaryDatabase_Locations_WaveHeight_DisplayName); - } - - private void UpdateDataGridViewDataSource() - { - SetHydraulicBoundaryDatabaseObserver(); - - updatingDataSource = true; - dataGridViewControl.SetDataSource(assessmentSection != null && assessmentSection.HydraulicBoundaryDatabase != null - ? assessmentSection.HydraulicBoundaryDatabase.Locations.Select( - hl => new WaveHeightLocationContextRow( - new WaveHeightLocationContext(assessmentSection.HydraulicBoundaryDatabase, hl))).ToArray() - : null); - updatingDataSource = false; - } - - private IEnumerable GetWaveHeightLocationContextRows() - { - return dataGridViewControl.Rows.Cast().Select(row => (WaveHeightLocationContextRow) row.DataBoundItem); - } - - private IEnumerable GetSelectedHydraulicBoundaryLocationContext() - { - return GetWaveHeightLocationContextRows().Where(r => r.ToCalculate).Select(r => r.HydraulicBoundaryLocationContext.HydraulicBoundaryLocation); - } - - #region Event handling - - private void DataGridViewOnCellClick(object sender, DataGridViewCellEventArgs e) - { - if (updatingDataSource) + if (!ReferenceEquals(Data, hydraulicBoundaryDatabase?.Locations)) { - return; + hydraulicBoundaryDatabaseObserver.Observable = hydraulicBoundaryDatabase; + Data = hydraulicBoundaryDatabase?.Locations; } - - UpdateApplicationSelection(); - } - - private void UpdateApplicationSelection() - { - if (ApplicationSelection == null) + else { - return; + HandleHydraulicBoundaryDatabaseUpdate(); } - - HydraulicBoundaryLocationContext selection = CreateSelectedItemFromCurrentRow(); - if ((ApplicationSelection.Selection == null && selection != null) || - (ApplicationSelection.Selection != null && !ReferenceEquals(selection, ApplicationSelection.Selection))) - { - ApplicationSelection.Selection = selection; - } } - - private HydraulicBoundaryLocationContext CreateSelectedItemFromCurrentRow() - { - var currentRow = dataGridViewControl.CurrentRow; - - var waterLevelRow = currentRow != null - ? (WaveHeightLocationContextRow) currentRow.DataBoundItem - : null; - - return waterLevelRow != null - ? waterLevelRow.HydraulicBoundaryLocationContext - : null; - } - - private void SelectAllButton_Click(object sender, EventArgs e) - { - GetWaveHeightLocationContextRows().ForEachElementDo(row => row.ToCalculate = true); - dataGridViewControl.RefreshDataGridView(); - } - - private void DeselectAllButton_Click(object sender, EventArgs e) - { - GetWaveHeightLocationContextRows().ForEachElementDo(row => row.ToCalculate = false); - dataGridViewControl.RefreshDataGridView(); - } - - private void CalculateForSelectedButton_Click(object sender, EventArgs e) - { - if (CalculationCommandHandler == null) - { - return; - } - var locations = GetSelectedHydraulicBoundaryLocationContext(); - CalculationCommandHandler.CalculateWaveHeights(locations); - } - - #endregion } } \ No newline at end of file