Index: Riskeer/Common/src/Riskeer.Common.Forms/Views/HydraulicBoundaryCalculationsView.cs =================================================================== diff -u -radad4f2015cc373b12032ee223b9fde3657581a1 -rbafb4d318466dac452919c07593591fb50f3ea60 --- Riskeer/Common/src/Riskeer.Common.Forms/Views/HydraulicBoundaryCalculationsView.cs (.../HydraulicBoundaryCalculationsView.cs) (revision adad4f2015cc373b12032ee223b9fde3657581a1) +++ Riskeer/Common/src/Riskeer.Common.Forms/Views/HydraulicBoundaryCalculationsView.cs (.../HydraulicBoundaryCalculationsView.cs) (revision bafb4d318466dac452919c07593591fb50f3ea60) @@ -55,85 +55,5 @@ { UpdateDataGridViewDataSource(); } - - public override object Data { get; set; } - - /// - /// Gets or sets the . - /// - public IHydraulicBoundaryLocationCalculationGuiService CalculationGuiService { get; set; } - - /// - /// Performs the selected . - /// - /// The calculations to perform. - protected abstract void PerformSelectedCalculations(IEnumerable calculations); - - protected override void CalculateForSelectedRows() - { - if (CalculationGuiService == null) - { - return; - } - - PerformSelectedCalculations(GetSelectedCalculatableObjects()); - } - - protected override void SetDataSource() - { - Dictionary lookup = GetHydraulicBoundaryLocationLookup(); - dataGridViewControl.SetDataSource(calculations?.Select(c => CreateNewRow(c, lookup)).ToArray()); - } - - protected override IEnumerable GetIllustrationPointControlItems() - { - DataGridViewRow currentRow = dataGridViewControl.CurrentRow; - if (currentRow == null) - { - return Enumerable.Empty(); - } - - HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation = ((HydraulicBoundaryLocationCalculationRow) currentRow.DataBoundItem).CalculatableObject; - - HydraulicBoundaryLocationCalculationOutput hydraulicBoundaryLocationCalculationOutput = hydraulicBoundaryLocationCalculation.Output; - if (hydraulicBoundaryLocationCalculation.HasOutput - && hydraulicBoundaryLocationCalculationOutput.HasGeneralResult) - { - return hydraulicBoundaryLocationCalculationOutput.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(); - } - - private static HydraulicBoundaryLocationCalculationRow CreateNewRow(HydraulicBoundaryLocationCalculation calculation, - IReadOnlyDictionary lookup) - { - return new HydraulicBoundaryLocationCalculationRow(calculation, lookup[calculation.HydraulicBoundaryLocation]); - } - - - private Dictionary GetHydraulicBoundaryLocationLookup() - { - var lookup = new Dictionary(); - foreach (HydraulicBoundaryDatabase database in AssessmentSection.HydraulicBoundaryData.HydraulicBoundaryDatabases) - { - foreach (HydraulicBoundaryLocation location in database.Locations) - { - lookup[location] = Path.GetFileName(database.FilePath); - } - } - - return lookup; - } } } \ No newline at end of file Index: Riskeer/Common/src/Riskeer.Common.Forms/Views/LocationCalculationsView.cs =================================================================== diff -u -radad4f2015cc373b12032ee223b9fde3657581a1 -rbafb4d318466dac452919c07593591fb50f3ea60 --- Riskeer/Common/src/Riskeer.Common.Forms/Views/LocationCalculationsView.cs (.../LocationCalculationsView.cs) (revision adad4f2015cc373b12032ee223b9fde3657581a1) +++ Riskeer/Common/src/Riskeer.Common.Forms/Views/LocationCalculationsView.cs (.../LocationCalculationsView.cs) (revision bafb4d318466dac452919c07593591fb50f3ea60) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Windows.Forms; using Core.Common.Base; @@ -29,6 +30,7 @@ using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Data.IllustrationPoints; +using Riskeer.Common.Forms.GuiServices; using Riskeer.Common.Forms.PresentationObjects; using Riskeer.Common.Forms.Properties; @@ -69,7 +71,8 @@ AssessmentSection = assessmentSection; calculationsObserver = new Observer(UpdateDataGridViewDataSource); - calculationObserver = new RecursiveObserver, HydraulicBoundaryLocationCalculation>(HandleHydraulicBoundaryLocationCalculationUpdate, hblc => hblc); + calculationObserver = new RecursiveObserver, HydraulicBoundaryLocationCalculation>( + HandleHydraulicBoundaryLocationCalculationUpdate, hblc => hblc); this.calculations = calculations; @@ -79,16 +82,23 @@ InitializeComponent(); LocalizeControls(); InitializeEventHandlers(); + + UpdateDataGridViewDataSource(); } /// /// Gets or sets the . /// public IAssessmentSection AssessmentSection { get; protected set; } + /// + /// Gets or sets the . + /// + public IHydraulicBoundaryLocationCalculationGuiService CalculationGuiService { get; set; } + public object Selection { get; private set; } - public abstract object Data { get; set; } + public object Data { get; set; } protected override void OnLoad(EventArgs e) { @@ -97,6 +107,12 @@ } /// + /// Performs the selected . + /// + /// The calculations to perform. + protected abstract void PerformSelectedCalculations(IEnumerable calculations); + + /// /// Updates the data source of the data table based on the . /// protected void UpdateDataGridViewDataSource() @@ -134,11 +150,6 @@ /// The newly created object. protected abstract object CreateSelectedItemFromCurrentRow(); - /// - /// Sets the data source on the . - /// - protected abstract void SetDataSource(); - protected override void Dispose(bool disposing) { if (disposing && (components != null)) @@ -153,24 +164,19 @@ } /// - /// Handles the calculation routine for the currently selected rows. - /// - protected abstract void CalculateForSelectedRows(); - - /// /// Gets all the row items from the . /// - protected IEnumerable> GetCalculatableRows() + protected IEnumerable> GetCalculatableRows() { return dataGridViewControl.Rows .Cast() - .Select(row => (CalculatableRow) row.DataBoundItem); + .Select(row => (CalculatableRow) row.DataBoundItem); } /// /// Gets all the selected calculatable objects. /// - protected IEnumerable GetSelectedCalculatableObjects() + private IEnumerable GetSelectedCalculatableObjects() { return GetCalculatableRows().Where(r => r.ShouldCalculate) .Select(r => r.CalculatableObject); @@ -190,6 +196,42 @@ HandlePossibleOutdatedIllustrationPointsSelection(); } + private void SetDataSource() + { + Dictionary lookup = GetHydraulicBoundaryLocationLookup(); + dataGridViewControl.SetDataSource(calculations?.Select(c => CreateNewRow(c, lookup)).ToArray()); + } + + private static HydraulicBoundaryLocationCalculationRow CreateNewRow(HydraulicBoundaryLocationCalculation calculation, + IReadOnlyDictionary lookup) + { + return new HydraulicBoundaryLocationCalculationRow(calculation, lookup[calculation.HydraulicBoundaryLocation]); + } + + private Dictionary GetHydraulicBoundaryLocationLookup() + { + var lookup = new Dictionary(); + foreach (HydraulicBoundaryDatabase database in AssessmentSection.HydraulicBoundaryData.HydraulicBoundaryDatabases) + { + foreach (HydraulicBoundaryLocation location in database.Locations) + { + lookup[location] = Path.GetFileName(database.FilePath); + } + } + + return lookup; + } + + private void CalculateForSelectedRows() + { + if (CalculationGuiService == null) + { + return; + } + + PerformSelectedCalculations(GetSelectedCalculatableObjects()); + } + private string ValidateCalculatableObjects() { if (!GetCalculatableRows().Any(r => r.ShouldCalculate)) @@ -302,13 +344,36 @@ OnSelectionChanged(); } - /// - /// Gets the illustration point control items based on the data of the illustration points. - /// - /// The illustration point control items if it has obtained as part of the calculation, null - /// otherwise. - protected abstract IEnumerable GetIllustrationPointControlItems(); + private IEnumerable GetIllustrationPointControlItems() + { + DataGridViewRow currentRow = dataGridViewControl.CurrentRow; + if (currentRow == null) + { + return Enumerable.Empty(); + } + HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation = ((HydraulicBoundaryLocationCalculationRow) currentRow.DataBoundItem).CalculatableObject; + + HydraulicBoundaryLocationCalculationOutput hydraulicBoundaryLocationCalculationOutput = hydraulicBoundaryLocationCalculation.Output; + if (hydraulicBoundaryLocationCalculation.HasOutput + && hydraulicBoundaryLocationCalculationOutput.HasGeneralResult) + { + return hydraulicBoundaryLocationCalculationOutput.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(); + } + private void SelectAllButton_Click(object sender, EventArgs e) { SetShouldCalculateForAllRowsAndRefresh(true);