Index: Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsCalculationRow.cs =================================================================== diff -u -rc225ac27cdfd5aec62bbbc783762f275cd15fdd2 -r8dbe77c4864b019630360007c972593b2e91a753 --- Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsCalculationRow.cs (.../GrassCoverErosionInwardsCalculationRow.cs) (revision c225ac27cdfd5aec62bbbc783762f275cd15fdd2) +++ Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsCalculationRow.cs (.../GrassCoverErosionInwardsCalculationRow.cs) (revision 8dbe77c4864b019630360007c972593b2e91a753) @@ -23,223 +23,179 @@ using System.Collections.Generic; using System.Linq; using Core.Common.Base.Data; +using Core.Common.Base.Geometry; using Core.Common.Controls.DataGrid; using Riskeer.Common.Data.DikeProfiles; using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Forms.ChangeHandlers; using Riskeer.Common.Forms.Helpers; -using Riskeer.Common.Forms.PresentationObjects; using Riskeer.Common.Forms.PropertyClasses; +using Riskeer.Common.Forms.Views; using Riskeer.GrassCoverErosionInwards.Data; namespace Riskeer.GrassCoverErosionInwards.Forms.Views { /// /// This class represents a row in the . /// - internal class GrassCoverErosionInwardsCalculationRow : IHasColumnStateDefinitions + public class GrassCoverErosionInwardsCalculationRow : CalculationRow, IHasColumnStateDefinitions { private const int breakWaterTypeColumnIndex = 4; private const int breakWaterHeightColumnIndex = 5; private const int useForeshoreColumnIndex = 6; - private readonly IObservablePropertyChangeHandler propertyChangeHandler; /// /// Creates a new instance of . /// - /// The this row contains. + /// The this row contains. /// The handler responsible for handling effects of a property change. /// Thrown when any parameter is null. - public GrassCoverErosionInwardsCalculationRow(GrassCoverErosionInwardsCalculationScenario calculationScenario, - IObservablePropertyChangeHandler handler) + internal GrassCoverErosionInwardsCalculationRow(GrassCoverErosionInwardsCalculationScenario calculationScenario, + IObservablePropertyChangeHandler handler) : + base(calculationScenario, handler) { - if (calculationScenario == null) - { - throw new ArgumentNullException(nameof(calculationScenario)); - } - - if (handler == null) - { - throw new ArgumentNullException(nameof(handler)); - } - - CalculationScenario = calculationScenario; - propertyChangeHandler = handler; ColumnStateDefinitions = new Dictionary(); CreateColumnStateDefinitions(); UpdateUseBreakWaterColumnStateDefinitions(); UpdateUseForeshoreColumnStateDefinitions(); } /// - /// Gets the this row contains. + /// Gets or sets the dike profile of the . /// - public GrassCoverErosionInwardsCalculationScenario CalculationScenario { get; } - - /// - /// Gets or sets the name of the . - /// - public string Name - { - get => CalculationScenario.Name; - set - { - CalculationScenario.Name = value; - - CalculationScenario.NotifyObservers(); - } - } - - /// - /// Gets or sets the hydraulic boundary location of the . - /// - public DataGridViewComboBoxItemWrapper SelectableHydraulicBoundaryLocation - { - get - { - if (CalculationScenario.InputParameters.HydraulicBoundaryLocation == null) - { - return new DataGridViewComboBoxItemWrapper(null); - } - - return new DataGridViewComboBoxItemWrapper( - new SelectableHydraulicBoundaryLocation(CalculationScenario.InputParameters.HydraulicBoundaryLocation, null)); - } - set - { - HydraulicBoundaryLocation valueToSet = value?.WrappedObject?.HydraulicBoundaryLocation; - if (!ReferenceEquals(CalculationScenario.InputParameters.HydraulicBoundaryLocation, valueToSet)) - { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.HydraulicBoundaryLocation = valueToSet, propertyChangeHandler); - } - } - } - - /// - /// Gets or sets the dike profile of the . - /// public DataGridViewComboBoxItemWrapper DikeProfile { - get => new DataGridViewComboBoxItemWrapper(CalculationScenario.InputParameters.DikeProfile); + get => new DataGridViewComboBoxItemWrapper(Calculation.InputParameters.DikeProfile); set { DikeProfile valueToSet = value?.WrappedObject; - if (!ReferenceEquals(CalculationScenario.InputParameters.DikeProfile, valueToSet)) + if (!ReferenceEquals(Calculation.InputParameters.DikeProfile, valueToSet)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.DikeProfile = valueToSet, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.DikeProfile = valueToSet, PropertyChangeHandler); } } } /// - /// Gets or sets whether break water of the should be used. + /// Gets or sets whether break water of the should be used. /// public bool UseBreakWater { - get => CalculationScenario.InputParameters.UseBreakWater; + get => Calculation.InputParameters.UseBreakWater; set { - if (!CalculationScenario.InputParameters.UseBreakWater.Equals(value)) + if (!Calculation.InputParameters.UseBreakWater.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.UseBreakWater = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.UseBreakWater = value, PropertyChangeHandler); UpdateUseBreakWaterColumnStateDefinitions(); } } } /// - /// Gets or sets the break water type of the . + /// Gets or sets the break water type of the . /// public BreakWaterType BreakWaterType { - get => CalculationScenario.InputParameters.BreakWater.Type; + get => Calculation.InputParameters.BreakWater.Type; set { - if (!CalculationScenario.InputParameters.BreakWater.Type.Equals(value)) + if (!Calculation.InputParameters.BreakWater.Type.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.BreakWater.Type = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.BreakWater.Type = value, PropertyChangeHandler); } } } /// - /// Gets or sets the break water height of the . + /// Gets or sets the break water height of the . /// public RoundedDouble BreakWaterHeight { - get => CalculationScenario.InputParameters.BreakWater.Height; + get => Calculation.InputParameters.BreakWater.Height; set { - if (!CalculationScenario.InputParameters.BreakWater.Height.Equals(value)) + if (!Calculation.InputParameters.BreakWater.Height.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.BreakWater.Height = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.BreakWater.Height = value, PropertyChangeHandler); } } } /// - /// Gets or sets whether foreshore profile of the should be used. + /// Gets or sets whether foreshore profile of the should be used. /// public bool UseForeshoreGeometry { - get => CalculationScenario.InputParameters.UseForeshore; + get => Calculation.InputParameters.UseForeshore; set { - if (!CalculationScenario.InputParameters.UseForeshore.Equals(value)) + if (!Calculation.InputParameters.UseForeshore.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.UseForeshore = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.UseForeshore = value, PropertyChangeHandler); UpdateUseForeshoreColumnStateDefinitions(); } } } /// - /// Gets or sets the dike height of the . + /// Gets or sets the dike height of the . /// public RoundedDouble DikeHeight { - get => CalculationScenario.InputParameters.DikeHeight; + get => Calculation.InputParameters.DikeHeight; set { - if (!CalculationScenario.InputParameters.DikeHeight.Equals(value)) + if (!Calculation.InputParameters.DikeHeight.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.DikeHeight = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.DikeHeight = value, PropertyChangeHandler); } } } /// - /// Gets or sets the mean critical flow rate of the . + /// Gets or sets the mean critical flow rate of the . /// public RoundedDouble MeanCriticalFlowRate { - get => CalculationScenario.InputParameters.CriticalFlowRate.Mean; + get => Calculation.InputParameters.CriticalFlowRate.Mean; set { - if (!CalculationScenario.InputParameters.CriticalFlowRate.Mean.Equals(value)) + if (!Calculation.InputParameters.CriticalFlowRate.Mean.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.CriticalFlowRate.Mean = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.CriticalFlowRate.Mean = value, PropertyChangeHandler); } } } /// - /// Gets or sets the standard deviation critical flow rate of the . + /// Gets or sets the standard deviation critical flow rate of the . /// public RoundedDouble StandardDeviationCriticalFlowRate { - get => CalculationScenario.InputParameters.CriticalFlowRate.StandardDeviation; + get => Calculation.InputParameters.CriticalFlowRate.StandardDeviation; set { - if (!CalculationScenario.InputParameters.CriticalFlowRate.StandardDeviation.Equals(value)) + if (!Calculation.InputParameters.CriticalFlowRate.StandardDeviation.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.CriticalFlowRate.StandardDeviation = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.CriticalFlowRate.StandardDeviation = value, PropertyChangeHandler); } } } public IDictionary ColumnStateDefinitions { get; } + public override Point2D GetCalculationLocation() + { + return Calculation.InputParameters.DikeProfile?.WorldReferencePoint; + } + + protected override HydraulicBoundaryLocation HydraulicBoundaryLocation + { + get => Calculation.InputParameters.HydraulicBoundaryLocation; + set => Calculation.InputParameters.HydraulicBoundaryLocation = value; + } + private void CreateColumnStateDefinitions() { ColumnStateDefinitions.Add(breakWaterTypeColumnIndex, new DataGridViewColumnStateDefinition()); @@ -263,7 +219,7 @@ private void UpdateUseForeshoreColumnStateDefinitions() { - DikeProfile dikeProfileForeshoreGeometry = CalculationScenario.InputParameters.DikeProfile; + DikeProfile dikeProfileForeshoreGeometry = Calculation.InputParameters.DikeProfile; if (dikeProfileForeshoreGeometry == null || !dikeProfileForeshoreGeometry.ForeshoreGeometry.Any()) { ColumnStateHelper.DisableColumn(ColumnStateDefinitions[useForeshoreColumnIndex]); Fisheye: Tag 8dbe77c4864b019630360007c972593b2e91a753 refers to a dead (removed) revision in file `Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsCalculationsView.Designer.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsCalculationsView.cs =================================================================== diff -u -rc237d392efd465a39343760f0b7409cd6861b18a -r8dbe77c4864b019630360007c972593b2e91a753 --- Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsCalculationsView.cs (.../GrassCoverErosionInwardsCalculationsView.cs) (revision c237d392efd465a39343760f0b7409cd6861b18a) +++ Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsCalculationsView.cs (.../GrassCoverErosionInwardsCalculationsView.cs) (revision 8dbe77c4864b019630360007c972593b2e91a753) @@ -26,16 +26,13 @@ using Core.Common.Base; using Core.Common.Base.Geometry; using Core.Common.Controls.DataGrid; -using Core.Common.Controls.Views; using Core.Common.Util; using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; using Riskeer.Common.Data.DikeProfiles; -using Riskeer.Common.Data.FailureMechanism; -using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Forms.ChangeHandlers; using Riskeer.Common.Forms.Helpers; -using Riskeer.Common.Forms.PresentationObjects; +using Riskeer.Common.Forms.Views; using Riskeer.GrassCoverErosionInwards.Data; using Riskeer.GrassCoverErosionInwards.Forms.PresentationObjects; using Riskeer.GrassCoverErosionInwards.Forms.Properties; @@ -46,23 +43,12 @@ /// /// This class is a view for configuring grass cover erosion inwards calculations. /// - public partial class GrassCoverErosionInwardsCalculationsView : UserControl, ISelectionProvider, IView + public class GrassCoverErosionInwardsCalculationsView : CalculationsView { - private const int selectableHydraulicBoundaryLocationColumnIndex = 1; private const int selectableDikeProfileColumnIndex = 2; - private readonly IAssessmentSection assessmentSection; - private readonly GrassCoverErosionInwardsFailureMechanism failureMechanism; - private Observer failureMechanismObserver; - private Observer hydraulicBoundaryLocationsObserver; - private Observer dikeProfilesObserver; - private RecursiveObserver inputObserver; - private RecursiveObserver calculationScenarioObserver; - private RecursiveObserver calculationGroupObserver; - private CalculationGroup calculationGroup; + private readonly Observer dikeProfilesObserver; - public event EventHandler SelectionChanged; - /// /// Creates a new instance of . /// @@ -71,298 +57,166 @@ /// The assessment section. /// Thrown when any parameter is null. public GrassCoverErosionInwardsCalculationsView(CalculationGroup data, GrassCoverErosionInwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + : base(data, failureMechanism, assessmentSection) { - if (data == null) + dikeProfilesObserver = new Observer(() => { - throw new ArgumentNullException(nameof(data)); - } - - if (failureMechanism == null) + PrefillComboBoxListItemsAtColumnLevel(); + UpdateColumns(); + UpdateGenerateCalculationsButtonState(); + }) { - throw new ArgumentNullException(nameof(failureMechanism)); - } + Observable = FailureMechanism.DikeProfiles + }; + } - if (assessmentSection == null) + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + DataGridViewControl.CellFormatting += HandleCellStyling; + } + + protected override void Dispose(bool disposing) + { + if (disposing) { - throw new ArgumentNullException(nameof(assessmentSection)); + dikeProfilesObserver.Dispose(); } - this.failureMechanism = failureMechanism; - this.assessmentSection = assessmentSection; - calculationGroup = data; + base.Dispose(disposing); + } - InitializeObservers(); + protected override object CreateSelectedItemFromCurrentRow(GrassCoverErosionInwardsCalculationRow currentRow) + { + return new GrassCoverErosionInwardsInputContext( + currentRow.Calculation.InputParameters, + currentRow.Calculation, + FailureMechanism, + AssessmentSection); + } - InitializeComponent(); - InitializeListBox(); - InitializeDataGridView(); - - UpdateSectionsListBox(); - UpdateDataGridViewDataSource(); - UpdateSelectableHydraulicBoundaryLocationsColumn(); - UpdateDikeProfilesColumn(); - UpdateGenerateCalculationsButtonState(); + protected override IEnumerable GetReferenceLocations() + { + return FailureMechanism.DikeProfiles.Select(dp => dp.WorldReferencePoint); } - public object Selection => CreateSelectedItemFromCurrentRow(); - - public object Data + protected override bool IsCalculationIntersectionWithReferenceLineInSection(GrassCoverErosionInwardsCalculationScenario calculation, IEnumerable lineSegments) { - get => calculationGroup; - set => calculationGroup = value as CalculationGroup; + return calculation.IsDikeProfileIntersectionWithReferenceLineInSection(lineSegments); } - protected override void OnLoad(EventArgs e) + protected override GrassCoverErosionInwardsCalculationRow CreateRow(GrassCoverErosionInwardsCalculationScenario calculation) { - // Necessary to correctly load the content of the dropdown lists of the comboboxes... - UpdateDataGridViewDataSource(); + return new GrassCoverErosionInwardsCalculationRow(calculation, new ObservablePropertyChangeHandler(calculation, calculation.InputParameters)); + } - base.OnLoad(e); - - dataGridViewControl.CellFormatting += HandleCellStyling; + protected override bool CanGenerateCalculations() + { + return FailureMechanism.DikeProfiles.Any(); } - protected override void Dispose(bool disposing) + protected override void GenerateCalculations() { - if (disposing) + var calculationGroup = (CalculationGroup) Data; + using (var dialog = new GrassCoverErosionInwardsDikeProfileSelectionDialog(Parent, FailureMechanism.DikeProfiles)) { - failureMechanismObserver.Dispose(); - inputObserver.Dispose(); - calculationScenarioObserver.Dispose(); - calculationGroupObserver.Dispose(); + dialog.ShowDialog(); - hydraulicBoundaryLocationsObserver.Dispose(); - dikeProfilesObserver.Dispose(); - - components?.Dispose(); + if (dialog.SelectedItems.Any()) + { + GrassCoverErosionInwardsCalculationConfigurationHelper.GenerateCalculations(calculationGroup, dialog.SelectedItems); + calculationGroup.NotifyObservers(); + } } - - base.Dispose(disposing); } - private void InitializeDataGridView() + protected override void InitializeDataGridView() { - dataGridViewControl.CurrentRowChanged += DataGridViewOnCurrentRowChangedHandler; + base.InitializeDataGridView(); - dataGridViewControl.AddTextBoxColumn( - nameof(GrassCoverErosionInwardsCalculationRow.Name), - RiskeerCommonFormsResources.FailureMechanism_Name_DisplayName); - - dataGridViewControl.AddComboBoxColumn>( - nameof(GrassCoverErosionInwardsCalculationRow.SelectableHydraulicBoundaryLocation), - RiskeerCommonFormsResources.HydraulicBoundaryLocation_DisplayName, - null, - nameof(DataGridViewComboBoxItemWrapper.This), - nameof(DataGridViewComboBoxItemWrapper.DisplayName)); - - dataGridViewControl.AddComboBoxColumn>( + DataGridViewControl.AddComboBoxColumn>( nameof(GrassCoverErosionInwardsCalculationRow.DikeProfile), Resources.DikeProfile_DisplayName, null, nameof(DataGridViewComboBoxItemWrapper.This), nameof(DataGridViewComboBoxItemWrapper.DisplayName)); - dataGridViewControl.AddCheckBoxColumn(nameof(GrassCoverErosionInwardsCalculationRow.UseBreakWater), + DataGridViewControl.AddCheckBoxColumn(nameof(GrassCoverErosionInwardsCalculationRow.UseBreakWater), RiskeerCommonFormsResources.Use_BreakWater_DisplayName); - dataGridViewControl.AddComboBoxColumn(nameof(GrassCoverErosionInwardsCalculationRow.BreakWaterType), + DataGridViewControl.AddComboBoxColumn(nameof(GrassCoverErosionInwardsCalculationRow.BreakWaterType), RiskeerCommonFormsResources.CalculationsView_BreakWaterType_DisplayName, EnumDisplayWrapperHelper.GetEnumTypes(), nameof(EnumDisplayWrapper.Value), nameof(EnumDisplayWrapper.DisplayName)); - dataGridViewControl.AddTextBoxColumn( + DataGridViewControl.AddTextBoxColumn( nameof(GrassCoverErosionInwardsCalculationRow.BreakWaterHeight), RiskeerCommonFormsResources.CalculationsView_BreakWaterHeight_DisplayName); - dataGridViewControl.AddCheckBoxColumn(nameof(GrassCoverErosionInwardsCalculationRow.UseForeshoreGeometry), + DataGridViewControl.AddCheckBoxColumn(nameof(GrassCoverErosionInwardsCalculationRow.UseForeshoreGeometry), RiskeerCommonFormsResources.Use_Foreshore_DisplayName); - dataGridViewControl.AddTextBoxColumn( + DataGridViewControl.AddTextBoxColumn( nameof(GrassCoverErosionInwardsCalculationRow.DikeHeight), RiskeerCommonFormsResources.DikeHeight_DisplayName); - dataGridViewControl.AddTextBoxColumn( + DataGridViewControl.AddTextBoxColumn( nameof(GrassCoverErosionInwardsCalculationRow.MeanCriticalFlowRate), Resources.Mean_Critical_FlowRate_DisplayName); - dataGridViewControl.AddTextBoxColumn( + DataGridViewControl.AddTextBoxColumn( nameof(GrassCoverErosionInwardsCalculationRow.StandardDeviationCriticalFlowRate), Resources.StandardDeviation_Critical_FlowRate_DisplayName); } - private void InitializeListBox() - { - listBox.DisplayMember = nameof(FailureMechanismSection.Name); - listBox.SelectedValueChanged += ListBoxOnSelectedValueChanged; - } + #region Prefill combo box list items - private void UpdateGenerateCalculationsButtonState() + protected override void PrefillComboBoxListItemsAtColumnLevel() { - buttonGenerateCalculations.Enabled = failureMechanism.DikeProfiles.Any(); - } + base.PrefillComboBoxListItemsAtColumnLevel(); - private GrassCoverErosionInwardsInputContext CreateSelectedItemFromCurrentRow() - { - DataGridViewRow currentRow = dataGridViewControl.CurrentRow; + // Need to prefill for all possible data in order to guarantee 'combo box' columns + // do not generate errors when their cell value is not present in the list of available + // items. + var selectableDikeProfileColumn = (DataGridViewComboBoxColumn) DataGridViewControl.GetColumnFromIndex(selectableDikeProfileColumnIndex); - var calculationRow = (GrassCoverErosionInwardsCalculationRow) currentRow?.DataBoundItem; - - GrassCoverErosionInwardsInputContext selection = null; - if (calculationRow != null) + using (new SuspendDataGridViewColumnResizes(selectableDikeProfileColumn)) { - selection = new GrassCoverErosionInwardsInputContext( - calculationRow.CalculationScenario.InputParameters, - calculationRow.CalculationScenario, - failureMechanism, - assessmentSection); + SetItemsOnObjectCollection(selectableDikeProfileColumn.Items, + GetDikeProfileDataSource(FailureMechanism.DikeProfiles)); } - - return selection; } - private static void SetItemsOnObjectCollection(DataGridViewComboBoxCell.ObjectCollection objectCollection, object[] comboBoxItems) - { - objectCollection.Clear(); - objectCollection.AddRange(comboBoxItems); - } + #endregion - private static DataGridViewComboBoxItemWrapper[] GetSelectableHydraulicBoundaryLocationsDataSource( - IEnumerable selectableHydraulicBoundaryLocations = null) - { - var dataGridViewComboBoxItemWrappers = new List> - { - new DataGridViewComboBoxItemWrapper(null) - }; + #region Event handling - if (selectableHydraulicBoundaryLocations != null) - { - dataGridViewComboBoxItemWrappers.AddRange(selectableHydraulicBoundaryLocations.Select(hbl => new DataGridViewComboBoxItemWrapper(hbl))); - } - - return dataGridViewComboBoxItemWrappers.ToArray(); - } - - private void InitializeObservers() + private void HandleCellStyling(object sender, DataGridViewCellFormattingEventArgs e) { - failureMechanismObserver = new Observer(OnFailureMechanismUpdate) - { - Observable = failureMechanism - }; - hydraulicBoundaryLocationsObserver = new Observer(UpdateSelectableHydraulicBoundaryLocationsColumn) - { - Observable = assessmentSection.HydraulicBoundaryDatabase.Locations - }; - dikeProfilesObserver = new Observer(() => - { - UpdateDikeProfilesColumn(); - UpdateGenerateCalculationsButtonState(); - }) - { - Observable = failureMechanism.DikeProfiles - }; - - // The concat is needed to observe the input of calculations in child groups. - inputObserver = new RecursiveObserver(UpdateDataGridViewDataSource, pcg => pcg.Children.Concat(pcg.Children.OfType().Select(pc => pc.InputParameters))) - { - Observable = calculationGroup - }; - calculationScenarioObserver = new RecursiveObserver(() => dataGridViewControl.RefreshDataGridView(), pcg => pcg.Children) - { - Observable = calculationGroup - }; - calculationGroupObserver = new RecursiveObserver(UpdateDataGridViewDataSource, pcg => pcg.Children) - { - Observable = calculationGroup - }; + DataGridViewControl.FormatCellWithColumnStateDefinition(e.RowIndex, e.ColumnIndex); } - #region Data sources - - private void UpdateDataGridViewDataSource() - { - // Skip changes coming from the view itself - if (dataGridViewControl.IsCurrentCellInEditMode) - { - dataGridViewControl.AutoResizeColumns(); - } - - if (!(listBox.SelectedItem is FailureMechanismSection failureMechanismSection)) - { - dataGridViewControl.SetDataSource(null); - return; - } - - IEnumerable lineSegments = Math2D.ConvertPointsToLineSegments(failureMechanismSection.Points); - IEnumerable calculationScenarios = calculationGroup - .GetCalculations() - .OfType() - .Where(cs => cs.IsDikeProfileIntersectionWithReferenceLineInSection(lineSegments)); - - PrefillComboBoxListItemsAtColumnLevel(); - - List dataSource = calculationScenarios.Select(cs => new GrassCoverErosionInwardsCalculationRow(cs, new ObservablePropertyChangeHandler(cs, cs.InputParameters))).ToList(); - dataGridViewControl.SetDataSource(dataSource); - dataGridViewControl.ClearCurrentCell(); - - UpdateSelectableHydraulicBoundaryLocationsColumn(); - UpdateDikeProfilesColumn(); - } - #endregion #region Update combo box list items - #region Update SelectableHydraulicBoundaryLocations - - private void UpdateSelectableHydraulicBoundaryLocationsColumn() + protected override void UpdateColumns() { - var column = (DataGridViewComboBoxColumn) dataGridViewControl.GetColumnFromIndex(selectableHydraulicBoundaryLocationColumnIndex); - - using (new SuspendDataGridViewColumnResizes(column)) - { - foreach (DataGridViewRow dataGridViewRow in dataGridViewControl.Rows) - { - FillAvailableSelectableHydraulicBoundaryLocationsList(dataGridViewRow); - } - } + base.UpdateColumns(); + UpdateDikeProfilesColumn(); } - private void FillAvailableSelectableHydraulicBoundaryLocationsList(DataGridViewRow dataGridViewRow) - { - var rowData = (GrassCoverErosionInwardsCalculationRow) dataGridViewRow.DataBoundItem; - IEnumerable locations = GetSelectableHydraulicBoundaryLocationsForCalculation(rowData.CalculationScenario); - - var cell = (DataGridViewComboBoxCell) dataGridViewRow.Cells[selectableHydraulicBoundaryLocationColumnIndex]; - DataGridViewComboBoxItemWrapper[] dataGridViewComboBoxItemWrappers = GetSelectableHydraulicBoundaryLocationsDataSource(locations); - SetItemsOnObjectCollection(cell.Items, dataGridViewComboBoxItemWrappers); - } - - private IEnumerable GetSelectableHydraulicBoundaryLocationsForCalculation(GrassCoverErosionInwardsCalculationScenario calculationScenario) - { - return GetSelectableHydraulicBoundaryLocations(assessmentSection?.HydraulicBoundaryDatabase.Locations, - calculationScenario.InputParameters.DikeProfile); - } - - private static IEnumerable GetSelectableHydraulicBoundaryLocations( - IEnumerable hydraulicBoundaryLocations, DikeProfile dikeProfile) - { - Point2D referencePoint = dikeProfile?.WorldReferencePoint; - return SelectableHydraulicBoundaryLocationHelper.GetSortedSelectableHydraulicBoundaryLocations( - hydraulicBoundaryLocations, referencePoint); - } - - #endregion - #region Update DikeProfiles private void UpdateDikeProfilesColumn() { - var column = (DataGridViewComboBoxColumn) dataGridViewControl.GetColumnFromIndex(selectableDikeProfileColumnIndex); + var column = (DataGridViewComboBoxColumn) DataGridViewControl.GetColumnFromIndex(selectableDikeProfileColumnIndex); using (new SuspendDataGridViewColumnResizes(column)) { - foreach (DataGridViewRow dataGridViewRow in dataGridViewControl.Rows) + foreach (DataGridViewRow dataGridViewRow in DataGridViewControl.Rows) { FillAvailableDikeProfilesList(dataGridViewRow); } @@ -372,20 +226,20 @@ private void FillAvailableDikeProfilesList(DataGridViewRow dataGridViewRow) { var cell = (DataGridViewComboBoxCell) dataGridViewRow.Cells[selectableDikeProfileColumnIndex]; - DataGridViewComboBoxItemWrapper[] dataGridViewComboBoxItemWrappers = GetSelectableDikeProfileDataSource(failureMechanism.DikeProfiles); + DataGridViewComboBoxItemWrapper[] dataGridViewComboBoxItemWrappers = GetDikeProfileDataSource(FailureMechanism.DikeProfiles); SetItemsOnObjectCollection(cell.Items, dataGridViewComboBoxItemWrappers); } - private static DataGridViewComboBoxItemWrapper[] GetSelectableDikeProfileDataSource(IEnumerable selectableDikeProfiles = null) + private static DataGridViewComboBoxItemWrapper[] GetDikeProfileDataSource(IEnumerable dikeProfiles = null) { var dataGridViewComboBoxItemWrappers = new List> { new DataGridViewComboBoxItemWrapper(null) }; - if (selectableDikeProfiles != null) + if (dikeProfiles != null) { - dataGridViewComboBoxItemWrappers.AddRange(selectableDikeProfiles.Select(dp => new DataGridViewComboBoxItemWrapper(dp))); + dataGridViewComboBoxItemWrappers.AddRange(dikeProfiles.Select(dp => new DataGridViewComboBoxItemWrapper(dp))); } return dataGridViewComboBoxItemWrappers.ToArray(); @@ -394,99 +248,5 @@ #endregion #endregion - - #region Prefill combo box list items - - private void PrefillComboBoxListItemsAtColumnLevel() - { - var selectableHydraulicBoundaryLocationColumn = (DataGridViewComboBoxColumn) dataGridViewControl.GetColumnFromIndex(selectableHydraulicBoundaryLocationColumnIndex); - - // Need to prefill for all possible data in order to guarantee 'combo box' columns - // do not generate errors when their cell value is not present in the list of available - // items. - using (new SuspendDataGridViewColumnResizes(selectableHydraulicBoundaryLocationColumn)) - { - SetItemsOnObjectCollection(selectableHydraulicBoundaryLocationColumn.Items, - GetSelectableHydraulicBoundaryLocationsDataSource(GetSelectableHydraulicBoundaryLocationsFromFailureMechanism())); - } - - var selectableDikeProfileColumn = (DataGridViewComboBoxColumn) dataGridViewControl.GetColumnFromIndex(selectableDikeProfileColumnIndex); - - using (new SuspendDataGridViewColumnResizes(selectableDikeProfileColumn)) - { - SetItemsOnObjectCollection(selectableDikeProfileColumn.Items, - GetSelectableDikeProfileDataSource(failureMechanism.DikeProfiles)); - } - } - - private IEnumerable GetSelectableHydraulicBoundaryLocationsFromFailureMechanism() - { - List hydraulicBoundaryLocations = assessmentSection.HydraulicBoundaryDatabase.Locations; - - List selectableHydraulicBoundaryLocations = hydraulicBoundaryLocations.Select(hbl => new SelectableHydraulicBoundaryLocation(hbl, null)).ToList(); - - foreach (DikeProfile dikeProfile in failureMechanism.DikeProfiles) - { - selectableHydraulicBoundaryLocations.AddRange(GetSelectableHydraulicBoundaryLocations(hydraulicBoundaryLocations, dikeProfile)); - } - - return selectableHydraulicBoundaryLocations; - } - - #endregion - - #region Event handling - - private void DataGridViewOnCurrentRowChangedHandler(object sender, EventArgs e) - { - OnSelectionChanged(); - } - - private void ListBoxOnSelectedValueChanged(object sender, EventArgs e) - { - UpdateDataGridViewDataSource(); - } - - private void OnGenerateCalculationsButtonClick(object sender, EventArgs e) - { - using (var dialog = new GrassCoverErosionInwardsDikeProfileSelectionDialog(Parent, failureMechanism.DikeProfiles)) - { - dialog.ShowDialog(); - - if (dialog.SelectedItems.Any()) - { - GrassCoverErosionInwardsCalculationConfigurationHelper.GenerateCalculations(calculationGroup, dialog.SelectedItems); - calculationGroup.NotifyObservers(); - } - } - } - - private void OnFailureMechanismUpdate() - { - UpdateSectionsListBox(); - } - - private void UpdateSectionsListBox() - { - listBox.Items.Clear(); - - if (failureMechanism.Sections.Any()) - { - listBox.Items.AddRange(failureMechanism.Sections.Cast().ToArray()); - listBox.SelectedItem = failureMechanism.Sections.First(); - } - } - - private void OnSelectionChanged() - { - SelectionChanged?.Invoke(this, new EventArgs()); - } - - private void HandleCellStyling(object sender, DataGridViewCellFormattingEventArgs e) - { - dataGridViewControl.FormatCellWithColumnStateDefinition(e.RowIndex, e.ColumnIndex); - } - - #endregion } } \ No newline at end of file Fisheye: Tag 8dbe77c4864b019630360007c972593b2e91a753 refers to a dead (removed) revision in file `Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsCalculationsView.resx'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsCalculationRowTest.cs =================================================================== diff -u -r184759005a2e6f4ca8c2bb5f4f91ef1ed7a7c02f -r8dbe77c4864b019630360007c972593b2e91a753 --- Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsCalculationRowTest.cs (.../GrassCoverErosionInwardsCalculationRowTest.cs) (revision 184759005a2e6f4ca8c2bb5f4f91ef1ed7a7c02f) +++ Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsCalculationRowTest.cs (.../GrassCoverErosionInwardsCalculationRowTest.cs) (revision 8dbe77c4864b019630360007c972593b2e91a753) @@ -31,9 +31,9 @@ using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.TestUtil; using Riskeer.Common.Forms.ChangeHandlers; -using Riskeer.Common.Forms.PresentationObjects; using Riskeer.Common.Forms.PropertyClasses; using Riskeer.Common.Forms.TestUtil; +using Riskeer.Common.Forms.Views; using Riskeer.GrassCoverErosionInwards.Data; using Riskeer.GrassCoverErosionInwards.Data.TestUtil; using Riskeer.GrassCoverErosionInwards.Forms.Views; @@ -48,50 +48,24 @@ private const int useForeshoreColumnIndex = 6; [Test] - public void Constructor_CalculationScenarioNull_ThrowsArgumentNullException() + public void Constructor_ExpectedValues() { // Setup var mocks = new MockRepository(); var handler = mocks.Stub(); mocks.ReplayAll(); - // Call - void Call() => new GrassCoverErosionInwardsCalculationRow(null, handler); - - // Assert - var exception = Assert.Throws(Call); - Assert.AreEqual("calculationScenario", exception.ParamName); - mocks.VerifyAll(); - } - - [Test] - public void Constructor_HandlerNull_ThrowsArgumentNullException() - { - // Call - void Call() => new GrassCoverErosionInwardsCalculationRow(new GrassCoverErosionInwardsCalculationScenario(), null); - - // Assert - var exception = Assert.Throws(Call); - Assert.AreEqual("handler", exception.ParamName); - } - - [Test] - public void Constructor_WithCalculation_PropertiesCorrectlySet() - { - // Setup - var mocks = new MockRepository(); - var handler = mocks.Stub(); - mocks.ReplayAll(); - var calculationScenario = new GrassCoverErosionInwardsCalculationScenario(); // Call - var calculationRow = new GrassCoverErosionInwardsCalculationRow(calculationScenario, handler); + var row = new GrassCoverErosionInwardsCalculationRow(calculationScenario, handler); // Asserts - Assert.AreSame(calculationScenario, calculationRow.CalculationScenario); + Assert.IsInstanceOf>(row); + Assert.IsInstanceOf(row); + Assert.AreSame(calculationScenario, row.Calculation); - IDictionary columnStateDefinitions = calculationRow.ColumnStateDefinitions; + IDictionary columnStateDefinitions = row.ColumnStateDefinitions; Assert.AreEqual(3, columnStateDefinitions.Count); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateDefinition(columnStateDefinitions, breakWaterTypeColumnIndex); @@ -102,66 +76,6 @@ } [Test] - public void Name_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged() - { - // Setup - var mockRepository = new MockRepository(); - var observer = mockRepository.StrictMock(); - observer.Expect(o => o.UpdateObserver()); - var handler = mockRepository.Stub(); - mockRepository.ReplayAll(); - - const string newValue = "Test new name"; - - var calculation = new GrassCoverErosionInwardsCalculationScenario(); - var row = new GrassCoverErosionInwardsCalculationRow(calculation, handler); - - calculation.Attach(observer); - - // Call - row.Name = newValue; - - // Assert - Assert.AreEqual(newValue, calculation.Name); - mockRepository.VerifyAll(); - } - - [Test] - public void SelectableHydraulicBoundaryLocation_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged() - { - // Setup - var newLocation = new TestHydraulicBoundaryLocation(); - var selectableHydraulicBoundaryLocation = new SelectableHydraulicBoundaryLocation(newLocation, new Point2D(0, 0)); - var newValue = new DataGridViewComboBoxItemWrapper(selectableHydraulicBoundaryLocation); - - var calculation = new GrassCoverErosionInwardsCalculationScenario(); - - // Call & Assert - SetPropertyAndVerifyNotificationsAndOutputForCalculation(row => row.SelectableHydraulicBoundaryLocation = newValue, calculation); - } - - [Test] - public void SelectableHydraulicBoundaryLocation_ChangeToEqualValue_NoNotificationsOutputNotCleared() - { - // Setup - DataGridViewComboBoxItemWrapper oldValue = null; - - // Call - AssertPropertyNotChanged( - row => - { - oldValue = row.SelectableHydraulicBoundaryLocation; - row.SelectableHydraulicBoundaryLocation = row.SelectableHydraulicBoundaryLocation; - }, - calculation => - { - // Assert - Assert.NotNull(oldValue); - Assert.AreEqual(oldValue.WrappedObject.HydraulicBoundaryLocation, calculation.InputParameters.HydraulicBoundaryLocation); - }); - } - - [Test] public void DikeProfile_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged() { // Setup Index: Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsCalculationsViewTest.cs =================================================================== diff -u -r184759005a2e6f4ca8c2bb5f4f91ef1ed7a7c02f -r8dbe77c4864b019630360007c972593b2e91a753 --- Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsCalculationsViewTest.cs (.../GrassCoverErosionInwardsCalculationsViewTest.cs) (revision 184759005a2e6f4ca8c2bb5f4f91ef1ed7a7c02f) +++ Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsCalculationsViewTest.cs (.../GrassCoverErosionInwardsCalculationsViewTest.cs) (revision 8dbe77c4864b019630360007c972593b2e91a753) @@ -1,4 +1,4 @@ -// Copyright (C) Stichting Deltares 2019. All rights reserved. +// Copyright (C) Stichting Deltares 2019. All rights reserved. // // This file is part of Riskeer. // @@ -23,15 +23,12 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Threading; using System.Windows.Forms; using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Base.Geometry; -using Core.Common.Controls.DataGrid; using Core.Common.Controls.Views; using Core.Common.TestUtil; -using Core.Common.Util.Reflection; using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; @@ -64,52 +61,6 @@ private Form testForm; [Test] - public void Constructor_CalculationGroupNull_ThrowsArgumentNullException() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - // Call - void Call() => new GrassCoverErosionInwardsCalculationsView(null, new TestGrassCoverErosionInwardsFailureMechanism(), assessmentSection); - - // Assert - var exception = Assert.Throws(Call); - Assert.AreEqual("data", exception.ParamName); - mocks.VerifyAll(); - } - - [Test] - public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() - { - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - void Call() => new GrassCoverErosionInwardsCalculationsView(new CalculationGroup(), null, assessmentSection); - - // Assert - var exception = Assert.Throws(Call); - Assert.AreEqual("failureMechanism", exception.ParamName); - mocks.VerifyAll(); - } - - [Test] - public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() - { - // Setup - GrassCoverErosionInwardsFailureMechanism failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); - - // Call - void Call() => new GrassCoverErosionInwardsCalculationsView(new CalculationGroup(), failureMechanism, null); - - // Assert - var exception = Assert.Throws(Call); - Assert.AreEqual("assessmentSection", exception.ParamName); - } - - [Test] public void Constructor_ExpectedValues() { // Setup @@ -148,61 +99,33 @@ // Assert Assert.IsFalse(dataGridView.AutoGenerateColumns); + Assert.AreEqual(10, dataGridView.ColumnCount); + Assert.AreEqual("Naam", dataGridView.Columns[nameColumnIndex].HeaderText); + Assert.AreEqual("Hydraulische belastingenlocatie", dataGridView.Columns[selectableHydraulicBoundaryLocationsColumnIndex].HeaderText); + Assert.AreEqual("Dijkprofiel", dataGridView.Columns[dikeProfileColumnIndex].HeaderText); + Assert.AreEqual("Gebruik dam", dataGridView.Columns[useBreakWaterColumnIndex].HeaderText); + Assert.AreEqual("Damtype", dataGridView.Columns[breakWaterTypeColumnIndex].HeaderText); + Assert.AreEqual("Damhoogte [m+NAP]", dataGridView.Columns[breakWaterHeightColumnIndex].HeaderText); + Assert.AreEqual("Gebruik voorlandgeometrie", dataGridView.Columns[useForeShoreGeometryColumnIndex].HeaderText); + Assert.AreEqual("Dijkhoogte [m+NAP]", dataGridView.Columns[dikeHeightColumnIndex].HeaderText); + Assert.AreEqual("Verwachtingswaarde kritiek overslagdebiet [m3/m/s]", dataGridView.Columns[meanCriticalFlowRateColumnIndex].HeaderText); + Assert.AreEqual("Standaardafwijking kritiek overslagdebiet [m3/m/s]", dataGridView.Columns[standardDeviationCriticalFlowRateColumnIndex].HeaderText); - AssertColumnMembers(dataGridView.Columns.OfType().ToArray()); - AssertDataGridViewControlColumnHeaders(dataGridView); - mocks.VerifyAll(); - } + Assert.AreEqual(10, dataGridView.ColumnCount); - [Test] - public void Constructor_ListBoxCorrectlyInitialized() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); + foreach (DataGridViewComboBoxColumn column in dataGridView.Columns.OfType().ToArray()) + { + Assert.AreEqual("DisplayName", column.DisplayMember); + } - ConfigureHydraulicBoundaryDatabase(assessmentSection); - GrassCoverErosionInwardsFailureMechanism failureMechanism = ConfigureFailureMechanism(); - - // Call - ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); - - var listBox = (ListBox) new ControlTester("listBox").TheObject; - - // Assert - Assert.AreEqual(2, listBox.Items.Count); + Assert.AreEqual("This", ((IReadOnlyList) dataGridView.Columns.OfType().ToArray())[0].ValueMember); + Assert.AreEqual("This", ((IReadOnlyList) dataGridView.Columns.OfType().ToArray())[1].ValueMember); + Assert.AreEqual("Value", ((IReadOnlyList) dataGridView.Columns.OfType().ToArray())[2].ValueMember); mocks.VerifyAll(); } [Test] - public void AssessmentSection_HydraulicBoundaryDatabaseWithLocations_SelectableHydraulicBoundaryLocationsComboboxCorrectlyInitialized() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - // Call - ShowFullyConfiguredCalculationsView(assessmentSection); - - // Assert - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - var hydraulicBoundaryLocationCombobox = (DataGridViewComboBoxColumn) dataGridView.Columns[selectableHydraulicBoundaryLocationsColumnIndex]; - DataGridViewComboBoxCell.ObjectCollection hydraulicBoundaryLocationComboboxItems = hydraulicBoundaryLocationCombobox.Items; - Assert.AreEqual(7, hydraulicBoundaryLocationComboboxItems.Count); - Assert.AreEqual("", hydraulicBoundaryLocationComboboxItems[0].ToString()); - Assert.AreEqual("Location 1", hydraulicBoundaryLocationComboboxItems[1].ToString()); - Assert.AreEqual("Location 2", hydraulicBoundaryLocationComboboxItems[2].ToString()); - Assert.AreEqual("Location 1 (2 m)", hydraulicBoundaryLocationComboboxItems[3].ToString()); - Assert.AreEqual("Location 2 (6 m)", hydraulicBoundaryLocationComboboxItems[4].ToString()); - Assert.AreEqual("Location 1 (4 m)", hydraulicBoundaryLocationComboboxItems[5].ToString()); - Assert.AreEqual("Location 2 (5 m)", hydraulicBoundaryLocationComboboxItems[6].ToString()); - mocks.VerifyAll(); - } - - [Test] public void ButtonGenerateCalculations_DikeProfilesPresent_ButtonEnabled() { // Setup @@ -212,9 +135,9 @@ ConfigureHydraulicBoundaryDatabase(assessmentSection); - GrassCoverErosionInwardsCalculationsView calculationsView = ShowFullyConfiguredCalculationsView(assessmentSection); + ShowFullyConfiguredCalculationsView(assessmentSection); - var button = (Button) calculationsView.Controls.Find("buttonGenerateCalculations", true)[0]; + var button = (Button) new ControlTester("generateButton").TheObject; // Call bool state = button.Enabled; @@ -224,7 +147,6 @@ mocks.VerifyAll(); } - [Test] public void CalculationsView_ChangingDikeProfiles_ButtonCorrectState() { @@ -236,10 +158,10 @@ ConfigureHydraulicBoundaryDatabase(assessmentSection); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - GrassCoverErosionInwardsCalculationsView calculationsView = ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); + ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); // Precondition - var button = (Button) calculationsView.Controls.Find("buttonGenerateCalculations", true)[0]; + var button = (Button) new ControlTester("generateButton").TheObject; Assert.IsFalse(button.Enabled); var failureMechanismSection1 = new FailureMechanismSection("Section 1", new[] @@ -267,57 +189,6 @@ } [Test] - public void FailureMechanism_FailureMechanismWithSections_SectionsListBoxCorrectlyInitialized() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - ConfigureHydraulicBoundaryDatabase(assessmentSection); - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - var failureMechanismSection1 = new FailureMechanismSection("Section 1", new[] - { - new Point2D(0.0, 0.0), - new Point2D(5.0, 0.0) - }); - var failureMechanismSection2 = new FailureMechanismSection("Section 2", new[] - { - new Point2D(5.0, 0.0), - new Point2D(10.0, 0.0) - }); - var failureMechanismSection3 = new FailureMechanismSection("Section 3", new[] - { - new Point2D(10.0, 0.0), - new Point2D(15.0, 0.0) - }); - - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - failureMechanismSection1, - failureMechanismSection2, - failureMechanismSection3 - }); - - failureMechanism.DikeProfiles.AddRange(new List - { - DikeProfileTestFactory.CreateDikeProfile(new Point2D(0.0, 0.0), "profiel 1"), - DikeProfileTestFactory.CreateDikeProfile(new Point2D(5.0, 0.0), "profiel 2") - }, string.Empty); - - // Call - ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); - - // Assert - var listBox = (ListBox) new ControlTester("listBox").TheObject; - Assert.AreEqual(3, listBox.Items.Count); - Assert.AreSame(failureMechanismSection1, listBox.Items[0]); - Assert.AreSame(failureMechanismSection2, listBox.Items[1]); - Assert.AreSame(failureMechanismSection3, listBox.Items[2]); - mocks.VerifyAll(); - } - - [Test] public void CalculationsView_CalculationsWithAllDataSet_DataGridViewCorrectlyInitialized() { // Setup @@ -338,7 +209,7 @@ Assert.AreEqual(10, cells.Count); Assert.AreEqual("Calculation 1", cells[nameColumnIndex].FormattedValue); Assert.AreEqual("Location 1 (2 m)", cells[selectableHydraulicBoundaryLocationsColumnIndex].FormattedValue); - Assert.AreEqual("name", cells[dikeProfileColumnIndex].FormattedValue); + Assert.AreEqual("Profiel 1", cells[dikeProfileColumnIndex].FormattedValue); Assert.AreEqual(false, cells[useBreakWaterColumnIndex].FormattedValue); Assert.AreEqual("Havendam", cells[breakWaterTypeColumnIndex].FormattedValue); Assert.AreEqual(3.30.ToString("0.00", CultureInfo.CurrentCulture), cells[breakWaterHeightColumnIndex].FormattedValue); @@ -351,7 +222,7 @@ Assert.AreEqual(10, cells.Count); Assert.AreEqual("Calculation 2", cells[nameColumnIndex].FormattedValue); Assert.AreEqual("Location 2 (5 m)", cells[selectableHydraulicBoundaryLocationsColumnIndex].FormattedValue); - Assert.AreEqual("name", cells[dikeProfileColumnIndex].FormattedValue); + Assert.AreEqual("Profiel 2", cells[dikeProfileColumnIndex].FormattedValue); Assert.AreEqual(false, cells[useBreakWaterColumnIndex].FormattedValue); Assert.AreEqual("Havendam", cells[breakWaterTypeColumnIndex].FormattedValue); Assert.AreEqual(3.30.ToString("0.00", CultureInfo.CurrentCulture), cells[breakWaterHeightColumnIndex].FormattedValue); @@ -363,71 +234,6 @@ } [Test] - [Apartment(ApartmentState.STA)] - public void CalculationsView_SelectingCellInRow_SelectionChangedFired() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - ConfigureHydraulicBoundaryDatabase(assessmentSection); - - GrassCoverErosionInwardsFailureMechanism failureMechanism = ConfigureFailureMechanism(); - using (var calculationsView = new GrassCoverErosionInwardsCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection)) - { - var selectionChangedCount = 0; - calculationsView.SelectionChanged += (sender, args) => selectionChangedCount++; - - var control = TypeUtils.GetField(calculationsView, "dataGridViewControl"); - WindowsFormsTestHelper.Show(control); - - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - dataGridView.CurrentCell = dataGridView.Rows[0].Cells[0]; - - // Call - EventHelper.RaiseEvent(dataGridView, "CellClick", new DataGridViewCellEventArgs(1, 0)); - - // Assert - Assert.AreEqual(1, selectionChangedCount); - } - - WindowsFormsTestHelper.CloseAll(); - mocks.VerifyAll(); - } - - [Test] - public void CalculationsView_ChangingListBoxSelection_DataGridViewCorrectlySyncedAndSelectionChangedFired() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - GrassCoverErosionInwardsCalculationsView calculationsView = ShowFullyConfiguredCalculationsView(assessmentSection); - - var selectionChangedCount = 0; - calculationsView.SelectionChanged += (sender, args) => selectionChangedCount++; - - var listBox = (ListBox) new ControlTester("listBox").TheObject; - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - - // Precondition - Assert.AreEqual(2, dataGridView.Rows.Count); - Assert.AreEqual("Calculation 1", dataGridView.Rows[0].Cells[nameColumnIndex].FormattedValue); - Assert.AreEqual("Calculation 2", dataGridView.Rows[1].Cells[nameColumnIndex].FormattedValue); - - // Call - listBox.SelectedIndex = 1; - - // Assert - Assert.AreEqual(1, dataGridView.Rows.Count); - Assert.AreEqual("Calculation 2", dataGridView.Rows[0].Cells[nameColumnIndex].FormattedValue); - Assert.AreEqual(2, selectionChangedCount); - mocks.VerifyAll(); - } - - [Test] [TestCase("test", breakWaterHeightColumnIndex)] [TestCase("test", dikeHeightColumnIndex)] [TestCase("test", meanCriticalFlowRateColumnIndex)] @@ -499,74 +305,6 @@ } [Test] - public void CalculationsViewWithFailureMechanism_WhenSectionsAddedAndFailureMechanismNotified_ThenSectionsListBoxCorrectlyUpdated() - { - // Given - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - ConfigureHydraulicBoundaryDatabase(assessmentSection); - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - var failureMechanismSection1 = new FailureMechanismSection("Section 1", new[] - { - new Point2D(0.0, 0.0), - new Point2D(5.0, 0.0) - }); - var failureMechanismSection2 = new FailureMechanismSection("Section 2", new[] - { - new Point2D(5.0, 0.0), - new Point2D(10.0, 0.0) - }); - var failureMechanismSection3 = new FailureMechanismSection("Section 3", new[] - { - new Point2D(10.0, 0.0), - new Point2D(15.0, 0.0) - }); - - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - failureMechanismSection1, - failureMechanismSection2 - }); - - failureMechanism.DikeProfiles.AddRange(new List - { - DikeProfileTestFactory.CreateDikeProfile(new Point2D(0.0, 0.0), "profiel 1"), - DikeProfileTestFactory.CreateDikeProfile(new Point2D(5.0, 0.0), "profiel 2"), - }, string.Empty); - - ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); - - var listBox = (ListBox) new ControlTester("listBox").TheObject; - - // Precondition - Assert.AreEqual(2, listBox.Items.Count); - - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - failureMechanismSection1, - failureMechanismSection2, - failureMechanismSection3 - }); - - failureMechanism.DikeProfiles.AddRange(new List - { - DikeProfileTestFactory.CreateDikeProfile(new Point2D(10.0, 0.0), "profiel 3") - }, string.Empty); - - // When - failureMechanism.NotifyObservers(); - - // Then - Assert.AreEqual(3, listBox.Items.Count); - Assert.AreSame(failureMechanismSection1, listBox.Items[0]); - Assert.AreSame(failureMechanismSection2, listBox.Items[1]); - Assert.AreSame(failureMechanismSection3, listBox.Items[2]); - mocks.VerifyAll(); - } - - [Test] [TestCase(0)] [TestCase(-123.45)] [TestCase(1e-5)] @@ -745,62 +483,10 @@ // Assert Assert.IsInstanceOf(selection); var dataRow = (GrassCoverErosionInwardsCalculationRow) dataGridView.Rows[selectedRow].DataBoundItem; - Assert.AreSame(dataRow.CalculationScenario, ((GrassCoverErosionInwardsInputContext) selection).Calculation); + Assert.AreSame(dataRow.Calculation, ((GrassCoverErosionInwardsInputContext) selection).Calculation); mocks.VerifyAll(); } - [Test] - [TestCase(true)] - [TestCase(false)] - public void CalculationsView_EditingNameViaDataGridView_ObserversCorrectlyNotified(bool useCalculationWithOutput) - { - // Setup - var mocks = new MockRepository(); - var calculationObserver = mocks.StrictMock(); - var calculationInputObserver = mocks.StrictMock(); - - calculationObserver.Expect(o => o.UpdateObserver()); - - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - GrassCoverErosionInwardsCalculationsView calculationsView = ShowFullyConfiguredCalculationsView(assessmentSection); - - var data = (CalculationGroup) calculationsView.Data; - var calculation = (GrassCoverErosionInwardsCalculationScenario) data.Children.First(); - - if (useCalculationWithOutput) - { - calculation.Output = new GrassCoverErosionInwardsOutput(new TestOvertoppingOutput(2.4), - new TestDikeHeightOutput(4.2), - new TestOvertoppingRateOutput(1.0)); - } - - calculation.Attach(calculationObserver); - calculation.InputParameters.Attach(calculationInputObserver); - - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - - // Call - dataGridView.Rows[0].Cells[nameColumnIndex].Value = "New name"; - - // Assert - calculation.Output = null; - mocks.VerifyAll(); - } - - private static void AssertColumnMembers(IReadOnlyList dataGridViewColumns) - { - foreach (DataGridViewComboBoxColumn column in dataGridViewColumns) - { - Assert.AreEqual("DisplayName", column.DisplayMember); - } - - Assert.AreEqual("This", dataGridViewColumns[0].ValueMember); - Assert.AreEqual("This", dataGridViewColumns[1].ValueMember); - Assert.AreEqual("Value", dataGridViewColumns[2].ValueMember); - } - public override void Setup() { base.Setup(); @@ -948,20 +634,5 @@ return calculationsView; } - - private static void AssertDataGridViewControlColumnHeaders(DataGridView dataGridView) - { - Assert.AreEqual(10, dataGridView.ColumnCount); - Assert.AreEqual("Naam", dataGridView.Columns[nameColumnIndex].HeaderText); - Assert.AreEqual("Hydraulische belastingenlocatie", dataGridView.Columns[selectableHydraulicBoundaryLocationsColumnIndex].HeaderText); - Assert.AreEqual("Dijkprofiel", dataGridView.Columns[dikeProfileColumnIndex].HeaderText); - Assert.AreEqual("Gebruik dam", dataGridView.Columns[useBreakWaterColumnIndex].HeaderText); - Assert.AreEqual("Damtype", dataGridView.Columns[breakWaterTypeColumnIndex].HeaderText); - Assert.AreEqual("Damhoogte [m+NAP]", dataGridView.Columns[breakWaterHeightColumnIndex].HeaderText); - Assert.AreEqual("Gebruik voorlandgeometrie", dataGridView.Columns[useForeShoreGeometryColumnIndex].HeaderText); - Assert.AreEqual("Dijkhoogte [m+NAP]", dataGridView.Columns[dikeHeightColumnIndex].HeaderText); - Assert.AreEqual("Verwachtingswaarde kritiek overslagdebiet [m3/m/s]", dataGridView.Columns[meanCriticalFlowRateColumnIndex].HeaderText); - Assert.AreEqual("Standaardafwijking kritiek overslagdebiet [m3/m/s]", dataGridView.Columns[standardDeviationCriticalFlowRateColumnIndex].HeaderText); - } } } \ No newline at end of file