// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using Core.Common.Base; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.IllustrationPoints; using Ringtoets.Common.Forms.GuiServices; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Common.Forms.Views { /// /// Base view for views which should be derived in /// order to get a consistent look and feel. /// public abstract partial class HydraulicBoundaryLocationsView : LocationsView { private readonly Observer calculationsObserver; private readonly RecursiveObserver, HydraulicBoundaryLocationCalculation> calculationObserver; private readonly ObservableList calculations; /// /// Creates a new instance of . /// /// The calculations to show in the view. /// The assessment section which the calculations belong to. /// Thrown when any input parameter is null. protected HydraulicBoundaryLocationsView(ObservableList calculations, IAssessmentSection assessmentSection) { if (calculations == null) { throw new ArgumentNullException(nameof(calculations)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } AssessmentSection = assessmentSection; calculationsObserver = new Observer(UpdateDataGridViewDataSource); calculationObserver = new RecursiveObserver, HydraulicBoundaryLocationCalculation>(HandleHydraulicBoundaryLocationCalculationUpdate, list => list); this.calculations = calculations; calculationsObserver.Observable = calculations; calculationObserver.Observable = calculations; UpdateDataGridViewDataSource(); } public override object Data { get; set; } /// /// Gets or sets the . /// public IHydraulicBoundaryLocationCalculationGuiService CalculationGuiService { get; set; } protected override void Dispose(bool disposing) { calculationsObserver.Dispose(); calculationObserver.Dispose(); base.Dispose(disposing); } protected override void InitializeDataGridView() { base.InitializeDataGridView(); dataGridViewControl.AddCheckBoxColumn(nameof(HydraulicBoundaryLocationRow.IncludeIllustrationPoints), RingtoetsCommonFormsResources.HydraulicBoundaryLocationCalculationInput_IncludeIllustrationPoints_DisplayName); dataGridViewControl.AddTextBoxColumn(nameof(HydraulicBoundaryLocationRow.Name), RingtoetsCommonFormsResources.HydraulicBoundaryDatabase_Location_Name_DisplayName); dataGridViewControl.AddTextBoxColumn(nameof(HydraulicBoundaryLocationRow.Id), RingtoetsCommonFormsResources.HydraulicBoundaryDatabase_Location_Id_DisplayName); dataGridViewControl.AddTextBoxColumn(nameof(HydraulicBoundaryLocationRow.Location), RingtoetsCommonFormsResources.HydraulicBoundaryDatabase_Location_Coordinates_DisplayName); } /// /// Handles the calculation of the . /// /// The enumeration of to use in the calculation. protected abstract void HandleCalculateSelectedLocations(IEnumerable locations); protected override void CalculateForSelectedRows() { if (CalculationGuiService == null) { return; } IEnumerable selectedLocations = GetSelectedCalculatableObjects(); HandleCalculateSelectedLocations(selectedLocations); } protected override void SetDataSource() { dataGridViewControl.SetDataSource(calculations?.Select(CreateNewRow).ToArray()); } protected override IEnumerable GetIllustrationPointControlItems() { DataGridViewRow currentRow = dataGridViewControl.CurrentRow; if (currentRow == null) { return Enumerable.Empty(); } HydraulicBoundaryLocation location = ((HydraulicBoundaryLocationRow) currentRow.DataBoundItem).CalculatableObject; HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation = GetCalculationFunc(location); HydraulicBoundaryLocationOutput hydraulicBoundaryLocationOutput = hydraulicBoundaryLocationCalculation.Output; if (hydraulicBoundaryLocationCalculation.HasOutput && hydraulicBoundaryLocationOutput.HasGeneralResult) { return hydraulicBoundaryLocationOutput.GeneralResult.TopLevelIllustrationPoints.Select( topLevelSubMechanismIllustrationPoint => { SubMechanismIllustrationPoint subMechanismIllustrationPoint = topLevelSubMechanismIllustrationPoint.SubMechanismIllustrationPoint; return new IllustrationPointControlItem(topLevelSubMechanismIllustrationPoint, topLevelSubMechanismIllustrationPoint.WindDirection.Name, topLevelSubMechanismIllustrationPoint.ClosingSituation, subMechanismIllustrationPoint.Stochasts, subMechanismIllustrationPoint.Beta); }).ToArray(); } return Enumerable.Empty(); } /// /// Creates a new row that is added to the data table. /// /// The location for which to create a new row. /// The newly created row. /// Thrown when is null or /// returns null. private HydraulicBoundaryLocationRow CreateNewRow(HydraulicBoundaryLocation location) { return new HydraulicBoundaryLocationRow(location, GetCalculationFunc(location)); } } }