Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/CustomFailureMechanismSectionResultRow.cs =================================================================== diff -u -rea99af5c043eadf5c2ba83b82a847ae009181191 -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/CustomFailureMechanismSectionResultRow.cs (.../CustomFailureMechanismSectionResultRow.cs) (revision ea99af5c043eadf5c2ba83b82a847ae009181191) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/CustomFailureMechanismSectionResultRow.cs (.../CustomFailureMechanismSectionResultRow.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -1,4 +1,25 @@ -using System; +// Copyright (C) Stichting Deltares 2016. 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 Core.Common.Base.Data; using Ringtoets.Common.Data.FailureMechanism; Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismResultView.cs =================================================================== diff -u -r80744f9014a001284116723df29bab8b319c38b7 -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismResultView.cs (.../FailureMechanismResultView.cs) (revision 80744f9014a001284116723df29bab8b319c38b7) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismResultView.cs (.../FailureMechanismResultView.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -59,7 +59,7 @@ /// /// Sets the failure mechanism. /// - public IFailureMechanism FailureMechanism + public virtual IFailureMechanism FailureMechanism { set { @@ -127,15 +127,14 @@ } /// - /// Gives the cell at , an - /// enabled style. + /// Restore the initial style of the cell at , . /// /// The row index of the cell. /// The column index of the cell. - protected void EnableCell(int rowIndex, int columnIndex) + protected void RestoreCell(int rowIndex, int columnIndex) { var cell = dataGridView.Rows[rowIndex].Cells[columnIndex]; - cell.ReadOnly = false; + cell.ReadOnly = GetDataGridColumns().ElementAt(columnIndex).ReadOnly; SetCellStyle(cell, CellStyle.Enabled); } @@ -147,11 +146,16 @@ /// The column index of the cell. protected void DisableCell(int rowIndex, int columnIndex) { - var cell = dataGridView.Rows[rowIndex].Cells[columnIndex]; + var cell = GetCell(rowIndex, columnIndex); cell.ReadOnly = true; SetCellStyle(cell, CellStyle.Disabled); } + protected DataGridViewCell GetCell(int rowIndex, int columnIndex) + { + return dataGridView.Rows[rowIndex].Cells[columnIndex]; + } + /// /// Gets all the columns that should be added to the on the /// . @@ -176,6 +180,25 @@ } /// + /// Updates the data source of the data grid view with the current known failure mechanism section results. + /// + protected void UpdataDataGridViewDataSource() + { + EndEdit(); + dataGridView.DataSource = failureMechanismSectionResult.Select(CreateFailureMechanismSectionResultRow).ToList(); + } + + /// + /// Gets data that is visualized on the row a the given . + /// + /// The position of the row in the data source. + /// The data bound to the row at index . + protected object GetDataAtRow(int rowIndex) + { + return dataGridView.Rows[rowIndex].DataBoundItem; + } + + /// /// Creates a display object for which is added to the /// on the . /// @@ -204,13 +227,6 @@ cell.Style.ForeColor = style.TextColor; } - private void UpdataDataGridViewDataSource() - { - EndEdit(); - - dataGridView.DataSource = failureMechanismSectionResult.Select(sr => CreateFailureMechanismSectionResultRow(sr)).ToList(); - } - private void RefreshDataGridView() { dataGridView.Refresh(); Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/SimpleFailureMechanismSectionResultRow.cs =================================================================== diff -u -rea99af5c043eadf5c2ba83b82a847ae009181191 -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/SimpleFailureMechanismSectionResultRow.cs (.../SimpleFailureMechanismSectionResultRow.cs) (revision ea99af5c043eadf5c2ba83b82a847ae009181191) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/SimpleFailureMechanismSectionResultRow.cs (.../SimpleFailureMechanismSectionResultRow.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -1,4 +1,25 @@ -using System; +// Copyright (C) Stichting Deltares 2016. 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 Core.Common.Base.Data; using Ringtoets.Common.Data.FailureMechanism; Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/CustomFailureMechanismSectionResultTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/CustomFailureMechanismSectionResultTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/CustomFailureMechanismSectionResultTest.cs (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -0,0 +1,61 @@ +// Copyright (C) Stichting Deltares 2016. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; + +namespace Ringtoets.Common.Data.Test.FailureMechanism +{ + [TestFixture] + public class CustomFailureMechanismSectionResultTest + { + [Test] + public void Constructor_WithoutSection_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new CustomFailureMechanismSectionResult(null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("section", paramName); + } + + [Test] + public void Constructor_WithSection_ResultCreatedForSection() + { + // Setup + var section = new FailureMechanismSection("Section", new[] { new Point2D(0, 0) }); + + // Call + var result = new CustomFailureMechanismSectionResult(section); + + // Assert + Assert.IsInstanceOf(result); + Assert.AreSame(section, result.Section); + Assert.IsFalse(result.AssessmentLayerOne); + Assert.AreEqual(0, result.AssessmentLayerTwoA.Value); + Assert.AreEqual(0, result.AssessmentLayerTwoB.Value); + Assert.AreEqual(0, result.AssessmentLayerThree.Value); + } + } +} \ No newline at end of file Fisheye: Tag 64d5609bb2912cd52dc74deffdd189222e240599 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/FailureMechanismSectionResultTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/SimpleFailureMechanismSectionResultTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/SimpleFailureMechanismSectionResultTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/SimpleFailureMechanismSectionResultTest.cs (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -0,0 +1,64 @@ +// Copyright (C) Stichting Deltares 2016. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; + +namespace Ringtoets.Common.Data.Test.FailureMechanism +{ + [TestFixture] + public class SimpleFailureMechanismSectionResultTest + { + [Test] + public void Constructor_WithoutSection_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new SimpleFailureMechanismSectionResult(null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("section", paramName); + } + + [Test] + public void Constructor_WithSection_ResultCreatedForSection() + { + // Setup + var section = new FailureMechanismSection("Section", new[] + { + new Point2D(0, 0) + }); + + // Call + var result = new SimpleFailureMechanismSectionResult(section); + + // Assert + Assert.IsInstanceOf(result); + Assert.AreSame(section, result.Section); + Assert.IsFalse(result.AssessmentLayerOne); + Assert.AreEqual((AssessmentLayerTwoAResult)0, result.AssessmentLayerTwoA); + Assert.AreEqual(0, result.AssessmentLayerTwoB.Value); + Assert.AreEqual(0, result.AssessmentLayerThree.Value); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj =================================================================== diff -u -r4936ea40e490dd8a3ed500e1c5a8f8390ff31491 -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision 4936ea40e490dd8a3ed500e1c5a8f8390ff31491) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -62,9 +62,12 @@ + + + Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/CustomFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -rea99af5c043eadf5c2ba83b82a847ae009181191 -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/CustomFailureMechanismSectionResultRowTest.cs (.../CustomFailureMechanismSectionResultRowTest.cs) (revision ea99af5c043eadf5c2ba83b82a847ae009181191) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/CustomFailureMechanismSectionResultRowTest.cs (.../CustomFailureMechanismSectionResultRowTest.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -1,4 +1,25 @@ -using System; +// Copyright (C) Stichting Deltares 2016. 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 Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Base.Geometry; Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/SimpleFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -rea99af5c043eadf5c2ba83b82a847ae009181191 -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/SimpleFailureMechanismSectionResultRowTest.cs (.../SimpleFailureMechanismSectionResultRowTest.cs) (revision ea99af5c043eadf5c2ba83b82a847ae009181191) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/SimpleFailureMechanismSectionResultRowTest.cs (.../SimpleFailureMechanismSectionResultRowTest.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -1,4 +1,25 @@ -using System; +// Copyright (C) Stichting Deltares 2016. 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 Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Base.Geometry; Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Properties/AssemblyInfo.cs =================================================================== diff -u -rd2b3e26fb42063a071bf4fc65b6198ef2369db30 -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Properties/AssemblyInfo.cs (.../AssemblyInfo.cs) (revision d2b3e26fb42063a071bf4fc65b6198ef2369db30) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Properties/AssemblyInfo.cs (.../AssemblyInfo.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -20,7 +20,9 @@ // All rights reserved. using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: AssemblyTitle("Ringtoets.GrassCoverErosionInwards.Forms")] [assembly: AssemblyProduct("Ringtoets.GrassCoverErosionInwards.Forms")] -[assembly: Guid("5f6091d8-2b96-427a-b6cb-8f629bcd2f0f")] \ No newline at end of file +[assembly: Guid("5f6091d8-2b96-427a-b6cb-8f629bcd2f0f")] +[assembly: InternalsVisibleTo("Ringtoets.GrassCoverErosionInwards.Forms.Test")] \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismResultView.cs =================================================================== diff -u -re24eab2c6007074685556ec97dbe45940a520687 -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismResultView.cs (.../GrassCoverErosionInwardsFailureMechanismResultView.cs) (revision e24eab2c6007074685556ec97dbe45940a520687) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismResultView.cs (.../GrassCoverErosionInwardsFailureMechanismResultView.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -19,16 +19,14 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using System.Collections.Generic; -using System.Drawing; using System.Linq; using System.Windows.Forms; using Core.Common.Base; -using Core.Common.Controls.Views; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.Properties; +using Ringtoets.Common.Forms.Views; using Ringtoets.GrassCoverErosionInwards.Data; using CoreCommonResources = Core.Common.Base.Properties.Resources; @@ -37,55 +35,32 @@ /// /// The view for the . /// - public partial class GrassCoverErosionInwardsFailureMechanismResultView : UserControl, IView + public partial class GrassCoverErosionInwardsFailureMechanismResultView : FailureMechanismResultView { - private const double tolerance = 1e-6; - private readonly Observer failureMechanismObserver; - private readonly RecursiveObserver failureMechanismSectionResultObserver; private readonly RecursiveObserver calculationInputObserver; private readonly RecursiveObserver calculationOutputObserver; private readonly RecursiveObserver calculationGroupObserver; - private IEnumerable failureMechanismSectionResult; - private GrassCoverErosionInwardsFailureMechanism failureMechanism; - private DataGridViewTextBoxColumn assessmentLayerTwoA; - private DataGridViewTextBoxColumn assessmentLayerTwoB; - private DataGridViewTextBoxColumn assessmentLayerThree; - /// /// Creates a new instance of . /// public GrassCoverErosionInwardsFailureMechanismResultView() { - InitializeComponent(); - InitializeDataGridView(); + AddCellFormattingHandler(DisableIrrelevantFieldsFormatting); - failureMechanismObserver = new Observer(UpdataDataGridViewDataSource); - failureMechanismSectionResultObserver = new RecursiveObserver(RefreshDataGridView, mechanism => mechanism.SectionResults); // The concat is needed to observe the input of calculations in child groups. calculationInputObserver = new RecursiveObserver(UpdataDataGridViewDataSource, cg => cg.Children.Concat(cg.Children.OfType().Select(c => c.GetObservableInput()))); calculationOutputObserver = new RecursiveObserver(UpdataDataGridViewDataSource, cg => cg.Children.Concat(cg.Children.OfType().Select(c => c.GetObservableOutput()))); calculationGroupObserver = new RecursiveObserver(UpdataDataGridViewDataSource, c => c.Children); - Load += OnLoad; } - /// - /// Gets or sets the failure mechanism. - /// - public IFailureMechanism FailureMechanism + public override IFailureMechanism FailureMechanism { - get - { - return failureMechanism; - } set { - failureMechanism = value as GrassCoverErosionInwardsFailureMechanism; + base.FailureMechanism = value; - failureMechanismObserver.Observable = failureMechanism; - failureMechanismSectionResultObserver.Observable = failureMechanism; - - var calculatableFailureMechanism = failureMechanism as ICalculatableFailureMechanism; + var calculatableFailureMechanism = value as ICalculatableFailureMechanism; CalculationGroup observableGroup = calculatableFailureMechanism != null ? calculatableFailureMechanism.CalculationsGroup : null; calculationInputObserver.Observable = observableGroup; @@ -94,201 +69,63 @@ } } - public object Data - { - get - { - return failureMechanismSectionResult; - } - set - { - failureMechanismSectionResult = value as IEnumerable; - - if (failureMechanismSectionResult != null) - { - UpdataDataGridViewDataSource(); - } - else - { - dataGridView.DataSource = null; - } - } - } - protected override void Dispose(bool disposing) { - FailureMechanism = null; - - failureMechanismObserver.Dispose(); - failureMechanismSectionResultObserver.Dispose(); calculationInputObserver.Dispose(); calculationOutputObserver.Dispose(); calculationGroupObserver.Dispose(); - if (disposing && (components != null)) - { - components.Dispose(); - } base.Dispose(disposing); } - private void OnLoad(object sender, EventArgs e) + private void DisableIrrelevantFieldsFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) { - if (failureMechanismSectionResult != null && failureMechanismSectionResult.Any()) + if (eventArgs.ColumnIndex > 1) { - SetRowStyling(); + if (HasPassedLevelZero(eventArgs.RowIndex)) + { + DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + } + else + { + RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + } } } - private void InitializeDataGridView() + protected override IEnumerable GetDataGridColumns() { - dataGridView.CurrentCellDirtyStateChanged += DataGridViewCurrentCellDirtyStateChanged; - dataGridView.CellValidating += DataGridViewCellValidating; - dataGridView.DataError += DataGridViewDataError; - dataGridView.GotFocus += DataGridViewGotFocus; - dataGridView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; - dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; - - var sectionName = new DataGridViewTextBoxColumn + foreach (var baseColumn in base.GetDataGridColumns()) { - DataPropertyName = "Name", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Section_name, - Name = "column_Name" - }; + yield return baseColumn; + } - var assessmentLayerOne = new DataGridViewCheckBoxColumn + yield return new DataGridViewTextBoxColumn { - DataPropertyName = "AssessmentLayerOne", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_one, - Name = "column_AssessmentLayerOne" - }; - - assessmentLayerTwoA = new DataGridViewTextBoxColumn - { DataPropertyName = "AssessmentLayerTwoA", HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, Name = "column_AssessmentLayerTwoA", ReadOnly = true }; - assessmentLayerTwoB = new DataGridViewTextBoxColumn + yield return new DataGridViewTextBoxColumn { DataPropertyName = "AssessmentLayerTwoB", HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_b, Name = "column_AssessmentLayerTwoB" }; - assessmentLayerThree = new DataGridViewTextBoxColumn + yield return new DataGridViewTextBoxColumn { DataPropertyName = "AssessmentLayerThree", HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three, Name = "column_AssessmentLayerThree" }; - - dataGridView.AutoGenerateColumns = false; - dataGridView.Columns.AddRange(sectionName, assessmentLayerOne, assessmentLayerTwoA, assessmentLayerTwoB, assessmentLayerThree); } - private void UpdataDataGridViewDataSource() + protected override object CreateFailureMechanismSectionResultRow(GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult) { - dataGridView.DataSource = failureMechanismSectionResult.Select(sr => new GrassCoverErosionInwardsFailureMechanismSectionResultRow(sr)).ToList(); - SetRowStyling(); + return new GrassCoverErosionInwardsFailureMechanismSectionResultRow(sectionResult); } - - private void RefreshDataGridView() - { - dataGridView.Refresh(); - dataGridView.AutoResizeColumns(); - - SetRowStyling(); - } - - private void SetRowStyling() - { - foreach (DataGridViewRow row in dataGridView.Rows) - { - var checkboxSelected = (bool) row.Cells[1].Value; - - SetRowEditMode(row, checkboxSelected); - - SetRowStyle(checkboxSelected, row); - } - } - - private void SetRowEditMode(DataGridViewRow row, bool checkboxSelected) - { - row.Cells[assessmentLayerTwoB.Index].ReadOnly = checkboxSelected; - row.Cells[assessmentLayerThree.Index].ReadOnly = checkboxSelected; - } - - private void SetRowStyle(bool checkboxSelected, DataGridViewRow row) - { - if (checkboxSelected) - { - SetCellStyle(row.Cells[assessmentLayerTwoA.Index], Color.FromKnownColor(KnownColor.DarkGray), Color.FromKnownColor(KnownColor.GrayText)); - SetCellStyle(row.Cells[assessmentLayerTwoB.Index], Color.FromKnownColor(KnownColor.DarkGray), Color.FromKnownColor(KnownColor.GrayText)); - SetCellStyle(row.Cells[assessmentLayerThree.Index], Color.FromKnownColor(KnownColor.DarkGray), Color.FromKnownColor(KnownColor.GrayText)); - } - else - { - SetCellStyle(row.Cells[assessmentLayerTwoA.Index], Color.FromKnownColor(KnownColor.White), Color.FromKnownColor(KnownColor.ControlText)); - SetCellStyle(row.Cells[assessmentLayerTwoB.Index], Color.FromKnownColor(KnownColor.White), Color.FromKnownColor(KnownColor.ControlText)); - SetCellStyle(row.Cells[assessmentLayerThree.Index], Color.FromKnownColor(KnownColor.White), Color.FromKnownColor(KnownColor.ControlText)); - } - } - - private void SetCellStyle(DataGridViewCell cell, Color backgroundColor, Color textColor) - { - cell.Style.BackColor = backgroundColor; - cell.Style.ForeColor = textColor; - } - - private void DataGridViewGotFocus(object sender, EventArgs eventArgs) - { - if (dataGridView.CurrentCell != null) - { - dataGridView.BeginEdit(true); // Always start editing after setting the focus (otherwise data grid view cell dirty events are no longer fired when using the keyboard...) - } - } - - #region Nested types - - #endregion - - #region Event handling - - private void DataGridViewCurrentCellDirtyStateChanged(object sender, EventArgs e) - { - // Ensure checkbox values are directly committed - DataGridViewColumn currentColumn = dataGridView.Columns[dataGridView.CurrentCell.ColumnIndex]; - if (currentColumn is DataGridViewCheckBoxColumn) - { - dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit); - } - } - - private void DataGridViewCellValidating(object sender, DataGridViewCellValidatingEventArgs e) - { - dataGridView.Rows[e.RowIndex].ErrorText = String.Empty; - - var cellEditValue = e.FormattedValue.ToString(); - if (string.IsNullOrWhiteSpace(cellEditValue)) - { - dataGridView.Rows[e.RowIndex].ErrorText = Resources.DataGridViewCellValidating_Text_may_not_be_empty; - } - } - - private void DataGridViewDataError(object sender, DataGridViewDataErrorEventArgs e) - { - e.ThrowException = false; - e.Cancel = true; - - if (string.IsNullOrWhiteSpace(dataGridView.Rows[e.RowIndex].ErrorText) && e.Exception != null) - { - dataGridView.Rows[e.RowIndex].ErrorText = e.Exception.Message; - } - } - - #endregion } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs =================================================================== diff -u -rea99af5c043eadf5c2ba83b82a847ae009181191 -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs) (revision ea99af5c043eadf5c2ba83b82a847ae009181191) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -25,7 +25,7 @@ namespace Ringtoets.GrassCoverErosionInwards.Forms.Views { - public class GrassCoverErosionInwardsFailureMechanismSectionResultRow + internal class GrassCoverErosionInwardsFailureMechanismSectionResultRow { public GrassCoverErosionInwardsFailureMechanismSectionResultRow(GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult) { Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultTest.cs (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -0,0 +1,61 @@ +// Copyright (C) Stichting Deltares 2016. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; + +namespace Ringtoets.GrassCoverErosionInwards.Data.Test +{ + [TestFixture] + public class GrassCoverErosionInwardsFailureMechanismSectionResultTest + { + [Test] + public void Constructor_WithoutSection_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new GrassCoverErosionInwardsFailureMechanismSectionResult(null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("section", paramName); + } + + [Test] + public void Constructor_WithSection_ResultCreatedForSection() + { + // Setup + var section = new FailureMechanismSection("Section", new[] { new Point2D(0, 0) }); + + // Call + var result = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + + // Assert + Assert.IsInstanceOf(result); + Assert.AreSame(section, result.Section); + Assert.IsFalse(result.AssessmentLayerOne); + Assert.AreEqual(0, result.AssessmentLayerTwoA.Value); + Assert.AreEqual(0, result.AssessmentLayerTwoB.Value); + Assert.AreEqual(0, result.AssessmentLayerThree.Value); + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/Ringtoets.GrassCoverErosionInwards.Data.Test.csproj =================================================================== diff -u -rd2f9b4f26f69988ea1c55caaa58af0831152458f -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/Ringtoets.GrassCoverErosionInwards.Data.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Data.Test.csproj) (revision d2f9b4f26f69988ea1c55caaa58af0831152458f) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/Ringtoets.GrassCoverErosionInwards.Data.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Data.Test.csproj) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -56,6 +56,7 @@ + Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismResultViewTest.cs =================================================================== diff -u -rea99af5c043eadf5c2ba83b82a847ae009181191 -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismResultViewTest.cs (.../GrassCoverErosionInwardsFailureMechanismResultViewTest.cs) (revision ea99af5c043eadf5c2ba83b82a847ae009181191) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismResultViewTest.cs (.../GrassCoverErosionInwardsFailureMechanismResultViewTest.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -29,7 +29,6 @@ using Core.Common.Controls.Views; using NUnit.Extensions.Forms; using NUnit.Framework; -using Rhino.Mocks; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Forms.Views; @@ -63,7 +62,6 @@ Assert.IsInstanceOf(view); Assert.IsInstanceOf(view); Assert.IsNull(view.Data); - Assert.IsNull(view.FailureMechanism); } } @@ -140,38 +138,11 @@ // Assert Assert.IsNull(view.Data); - Assert.AreEqual(1, dataGridView.RowCount); - foreach (DataGridViewCell cell in dataGridView.Rows[0].Cells) - { - Assert.IsNull(cell.Value); - } + Assert.AreEqual(0, dataGridView.RowCount); } } [Test] - public void Dispose_FailureMechanismResultViewWithAdditionalPropertiesSet_AdditionalPropertiesSetToNull() - { - // Setup - var mocks = new MockRepository(); - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - mocks.ReplayAll(); - using (var view = new GrassCoverErosionInwardsFailureMechanismResultView - { - FailureMechanism = failureMechanism - }) - { - // Precondition - Assert.IsNotNull(view.FailureMechanism); - - // Call - view.Dispose(); - - // Assert - Assert.IsNull(view.FailureMechanism); - } - } - - [Test] public void FailureMechanismResultsView_AllDataSet_DataGridViewCorrectlyInitialized() { // Setup & Call Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/CustomFailureMechanismResultView.cs =================================================================== diff -u -r80744f9014a001284116723df29bab8b319c38b7 -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/CustomFailureMechanismResultView.cs (.../CustomFailureMechanismResultView.cs) (revision 80744f9014a001284116723df29bab8b319c38b7) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/CustomFailureMechanismResultView.cs (.../CustomFailureMechanismResultView.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -30,7 +30,7 @@ } else { - EnableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } } } Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/SimpleFailureMechanismResultView.cs =================================================================== diff -u -r80744f9014a001284116723df29bab8b319c38b7 -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/SimpleFailureMechanismResultView.cs (.../SimpleFailureMechanismResultView.cs) (revision 80744f9014a001284116723df29bab8b319c38b7) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/SimpleFailureMechanismResultView.cs (.../SimpleFailureMechanismResultView.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -33,7 +33,7 @@ } else { - EnableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } } } Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj =================================================================== diff -u -ra6b3a4921ffd42f54f6be60ebc2eef3c12cab10e -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision a6b3a4921ffd42f54f6be60ebc2eef3c12cab10e) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -104,9 +104,7 @@ UserControl - - PipingFailureMechanismResultView.cs - + UserControl @@ -212,10 +210,6 @@ PipingCalculationsView.cs Designer - - PipingFailureMechanismResultView.cs - Designer - PipingFailureMechanismView.cs Fisheye: Tag 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismResultView.Designer.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismResultView.cs =================================================================== diff -u -r41fac7fff0a505c08945108d795dcb877f10b816 -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismResultView.cs (.../PipingFailureMechanismResultView.cs) (revision 41fac7fff0a505c08945108d795dcb877f10b816) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismResultView.cs (.../PipingFailureMechanismResultView.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -21,73 +21,50 @@ using System; using System.Collections.Generic; -using System.Drawing; -using System.Globalization; using System.Linq; using System.Windows.Forms; using Core.Common.Base; -using Core.Common.Base.Data; -using Core.Common.Controls.Views; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.Properties; +using Ringtoets.Common.Forms.Views; using Ringtoets.Piping.Data; -using CoreCommonResources = Core.Common.Base.Properties.Resources; namespace Ringtoets.Piping.Forms.Views { /// - /// The view for the . + /// The view for the . /// - public partial class PipingFailureMechanismResultView : UserControl, IView + public class PipingFailureMechanismResultView : FailureMechanismResultView { private const double tolerance = 1e-6; - private readonly Observer failureMechanismObserver; - private readonly RecursiveObserver failureMechanismSectionResultObserver; private readonly RecursiveObserver calculationInputObserver; private readonly RecursiveObserver calculationOutputObserver; private readonly RecursiveObserver calculationGroupObserver; - private IEnumerable failureMechanismSectionResult; - private PipingFailureMechanism failureMechanism; - private DataGridViewTextBoxColumn assessmentLayerTwoA; - private DataGridViewTextBoxColumn assessmentLayerTwoB; - private DataGridViewTextBoxColumn assessmentLayerThree; + private int assessmentLayerTwoAIndex = 2; /// /// Creates a new instance of . /// public PipingFailureMechanismResultView() { - InitializeComponent(); - InitializeDataGridView(); + AddCellFormattingHandler(ShowAssementLayerTwoAErrors); + AddCellFormattingHandler(DisableIrrelevantFieldsFormatting); - failureMechanismObserver = new Observer(UpdataDataGridViewDataSource); - failureMechanismSectionResultObserver = new RecursiveObserver(RefreshDataGridView, mechanism => mechanism.SectionResults); // The concat is needed to observe the input of calculations in child groups. calculationInputObserver = new RecursiveObserver(UpdataDataGridViewDataSource, cg => cg.Children.Concat(cg.Children.OfType().Select(c => c.GetObservableInput()))); calculationOutputObserver = new RecursiveObserver(UpdataDataGridViewDataSource, cg => cg.Children.Concat(cg.Children.OfType().Select(c => c.GetObservableOutput()))); calculationGroupObserver = new RecursiveObserver(UpdataDataGridViewDataSource, c => c.Children); - Load += OnLoad; } - /// - /// Gets or sets the failure mechanism. - /// - public IFailureMechanism FailureMechanism + public override IFailureMechanism FailureMechanism { - get - { - return failureMechanism; - } set { - failureMechanism = value as PipingFailureMechanism; + base.FailureMechanism = value; - failureMechanismObserver.Observable = failureMechanism; - failureMechanismSectionResultObserver.Observable = failureMechanism; - - var calculatableFailureMechanism = failureMechanism as ICalculatableFailureMechanism; + var calculatableFailureMechanism = value as ICalculatableFailureMechanism; CalculationGroup observableGroup = calculatableFailureMechanism != null ? calculatableFailureMechanism.CalculationsGroup : null; calculationInputObserver.Observable = observableGroup; @@ -96,296 +73,77 @@ } } - public object Data - { - get - { - return failureMechanismSectionResult; - } - set - { - failureMechanismSectionResult = value as IEnumerable; - - if (failureMechanismSectionResult != null) - { - UpdataDataGridViewDataSource(); - } - else - { - dataGridView.DataSource = null; - } - } - } - protected override void Dispose(bool disposing) { - FailureMechanism = null; - - failureMechanismObserver.Dispose(); - failureMechanismSectionResultObserver.Dispose(); calculationInputObserver.Dispose(); calculationOutputObserver.Dispose(); calculationGroupObserver.Dispose(); - if (disposing && (components != null)) - { - components.Dispose(); - } base.Dispose(disposing); } - private void OnLoad(object sender, EventArgs e) + protected override IEnumerable GetDataGridColumns() { - if (failureMechanismSectionResult != null && failureMechanismSectionResult.Any()) + foreach (var baseColumn in base.GetDataGridColumns()) { - SetRowStyling(); + yield return baseColumn; } - } - private void InitializeDataGridView() - { - dataGridView.CurrentCellDirtyStateChanged += DataGridViewCurrentCellDirtyStateChanged; - dataGridView.CellValidating += DataGridViewCellValidating; - dataGridView.DataError += DataGridViewDataError; - dataGridView.CellFormatting += DataGridViewCellFormatting; - dataGridView.GotFocus += DataGridViewGotFocus; - - var sectionName = new DataGridViewTextBoxColumn + yield return new DataGridViewTextBoxColumn { - DataPropertyName = "Name", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Section_name, - Name = "column_Name" - }; - - var assessmentLayerOne = new DataGridViewCheckBoxColumn - { - DataPropertyName = "AssessmentLayerOne", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_one, - Name = "column_AssessmentLayerOne" - }; - - assessmentLayerTwoA = new DataGridViewTextBoxColumn - { DataPropertyName = "AssessmentLayerTwoA", HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, Name = "column_AssessmentLayerTwoA", ReadOnly = true }; - assessmentLayerTwoB = new DataGridViewTextBoxColumn + yield return new DataGridViewTextBoxColumn { DataPropertyName = "AssessmentLayerTwoB", HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_b, Name = "column_AssessmentLayerTwoB" }; - assessmentLayerThree = new DataGridViewTextBoxColumn + yield return new DataGridViewTextBoxColumn { DataPropertyName = "AssessmentLayerThree", HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three, Name = "column_AssessmentLayerThree" }; - - dataGridView.AutoGenerateColumns = false; - dataGridView.Columns.AddRange(sectionName, assessmentLayerOne, assessmentLayerTwoA, assessmentLayerTwoB, assessmentLayerThree); - - foreach (var column in dataGridView.Columns.OfType()) - { - column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; - column.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; - } } - private void UpdataDataGridViewDataSource() + protected override object CreateFailureMechanismSectionResultRow(PipingFailureMechanismSectionResult sectionResult) { - dataGridView.DataSource = failureMechanismSectionResult.Select(sr => new FailureMechanismSectionResultRow(sr)).ToList(); - SetRowStyling(); + return new PipingFailureMechanismSectionResultRow(sectionResult); } + + #region Event handling - private void RefreshDataGridView() + private void DisableIrrelevantFieldsFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) { - dataGridView.Refresh(); - dataGridView.AutoResizeColumns(); - - SetRowStyling(); - } - - private void SetRowStyling() - { - foreach (DataGridViewRow row in dataGridView.Rows) + if (eventArgs.ColumnIndex > 1) { - var checkboxSelected = (bool) row.Cells[1].Value; - - SetRowEditMode(row, checkboxSelected); - - SetRowStyle(checkboxSelected, row); - } - } - - private void SetRowEditMode(DataGridViewRow row, bool checkboxSelected) - { - row.Cells[assessmentLayerTwoB.Index].ReadOnly = checkboxSelected; - row.Cells[assessmentLayerThree.Index].ReadOnly = checkboxSelected; - } - - private void SetRowStyle(bool checkboxSelected, DataGridViewRow row) - { - if (checkboxSelected) - { - SetCellStyle(row.Cells[assessmentLayerTwoA.Index], Color.FromKnownColor(KnownColor.DarkGray), Color.FromKnownColor(KnownColor.GrayText)); - SetCellStyle(row.Cells[assessmentLayerTwoB.Index], Color.FromKnownColor(KnownColor.DarkGray), Color.FromKnownColor(KnownColor.GrayText)); - SetCellStyle(row.Cells[assessmentLayerThree.Index], Color.FromKnownColor(KnownColor.DarkGray), Color.FromKnownColor(KnownColor.GrayText)); - } - else - { - SetCellStyle(row.Cells[assessmentLayerTwoA.Index], Color.FromKnownColor(KnownColor.White), Color.FromKnownColor(KnownColor.ControlText)); - SetCellStyle(row.Cells[assessmentLayerTwoB.Index], Color.FromKnownColor(KnownColor.White), Color.FromKnownColor(KnownColor.ControlText)); - SetCellStyle(row.Cells[assessmentLayerThree.Index], Color.FromKnownColor(KnownColor.White), Color.FromKnownColor(KnownColor.ControlText)); - } - } - - private void SetCellStyle(DataGridViewCell cell, Color backgroundColor, Color textColor) - { - cell.Style.BackColor = backgroundColor; - cell.Style.ForeColor = textColor; - } - - private void DataGridViewGotFocus(object sender, EventArgs eventArgs) - { - if (dataGridView.CurrentCell != null) - { - dataGridView.BeginEdit(true); // Always start editing after setting the focus (otherwise data grid view cell dirty events are no longer fired when using the keyboard...) - } - } - - #region Nested types - - private class FailureMechanismSectionResultRow - { - public FailureMechanismSectionResultRow(PipingFailureMechanismSectionResult pipingFailureMechanismSectionResult) - { - PipingFailureMechanismSectionResult = pipingFailureMechanismSectionResult; - } - - public string Name - { - get + if (HasPassedLevelZero(eventArgs.RowIndex)) { - return PipingFailureMechanismSectionResult.Section.Name; + DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } - } - - public bool AssessmentLayerOne - { - get + else { - return PipingFailureMechanismSectionResult.AssessmentLayerOne; + RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } - set - { - PipingFailureMechanismSectionResult.AssessmentLayerOne = value; - PipingFailureMechanismSectionResult.NotifyObservers(); - } } - - public string AssessmentLayerTwoA - { - get - { - var relevantScenarios = PipingFailureMechanismSectionResult.CalculationScenarios.Where(cs => cs.IsRelevant).ToArray(); - bool relevantScenarioAvailable = relevantScenarios.Length != 0; - - if (relevantScenarioAvailable && Math.Abs(PipingFailureMechanismSectionResult.TotalContribution - 1.0) > tolerance) - { - return double.NaN.ToString(CultureInfo.CurrentCulture); - } - - if (!relevantScenarioAvailable - || PipingFailureMechanismSectionResult.CalculationScenarioStatus != CalculationScenarioStatus.Done) - { - return Resources.FailureMechanismSectionResultRow_AssessmentLayerTwoA_No_result_dash; - } - - var layerTwoA = PipingFailureMechanismSectionResult.AssessmentLayerTwoA; - - return string.Format(CoreCommonResources.ProbabilityPerYearFormat, layerTwoA.Value); - } - } - - public RoundedDouble AssessmentLayerTwoB - { - get - { - return PipingFailureMechanismSectionResult.AssessmentLayerTwoB; - } - set - { - PipingFailureMechanismSectionResult.AssessmentLayerTwoB = value; - } - } - - public RoundedDouble AssessmentLayerThree - { - get - { - return PipingFailureMechanismSectionResult.AssessmentLayerThree; - } - set - { - PipingFailureMechanismSectionResult.AssessmentLayerThree = value; - } - } - - public PipingFailureMechanismSectionResult PipingFailureMechanismSectionResult { get; private set; } } - - #endregion - - #region Event handling - - private void DataGridViewCurrentCellDirtyStateChanged(object sender, EventArgs e) + + private void ShowAssementLayerTwoAErrors(object sender, DataGridViewCellFormattingEventArgs e) { - // Ensure checkbox values are directly committed - DataGridViewColumn currentColumn = dataGridView.Columns[dataGridView.CurrentCell.ColumnIndex]; - if (currentColumn is DataGridViewCheckBoxColumn) - { - dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit); - } - } + var currentDataGridViewCell = GetCell(e.RowIndex, e.ColumnIndex); - private void DataGridViewCellValidating(object sender, DataGridViewCellValidatingEventArgs e) - { - dataGridView.Rows[e.RowIndex].ErrorText = String.Empty; + PipingFailureMechanismSectionResultRow resultRow = (PipingFailureMechanismSectionResultRow) GetDataAtRow(e.RowIndex); - var cellEditValue = e.FormattedValue.ToString(); - if (string.IsNullOrWhiteSpace(cellEditValue)) + if (resultRow != null && e.ColumnIndex == assessmentLayerTwoAIndex) { - dataGridView.Rows[e.RowIndex].ErrorText = Resources.DataGridViewCellValidating_Text_may_not_be_empty; - } - } + PipingFailureMechanismSectionResult rowObject = resultRow.SectionResult; - private void DataGridViewDataError(object sender, DataGridViewDataErrorEventArgs e) - { - e.ThrowException = false; - e.Cancel = true; - - if (string.IsNullOrWhiteSpace(dataGridView.Rows[e.RowIndex].ErrorText) && e.Exception != null) - { - dataGridView.Rows[e.RowIndex].ErrorText = e.Exception.Message; - } - } - - private void DataGridViewCellFormatting(object sender, DataGridViewCellFormattingEventArgs e) - { - var currentDataGridViewRow = dataGridView.Rows[e.RowIndex]; - var currentDataGridViewCell = currentDataGridViewRow.Cells[e.ColumnIndex]; - - FailureMechanismSectionResultRow resultRow = (FailureMechanismSectionResultRow) currentDataGridViewRow.DataBoundItem; - - if (resultRow != null && e.ColumnIndex == assessmentLayerTwoA.Index) - { - PipingFailureMechanismSectionResult rowObject = resultRow.PipingFailureMechanismSectionResult; - var relevantScenarios = rowObject.CalculationScenarios.Where(cs => cs.IsRelevant).ToArray(); bool relevantScenarioAvailable = relevantScenarios.Length != 0; Fisheye: Tag 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismResultView.resx'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismSectionResultRow.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismSectionResultRow.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismSectionResultRow.cs (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -0,0 +1,95 @@ +using System; +using System.Linq; +using Core.Common.Base.Data; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Forms.Properties; +using Ringtoets.Piping.Data; + +using CommonBaseResources = Core.Common.Base.Properties.Resources; + +namespace Ringtoets.Piping.Forms.Views +{ + internal class PipingFailureMechanismSectionResultRow + { + private const double tolerance = 1e-6; + + public PipingFailureMechanismSectionResultRow(PipingFailureMechanismSectionResult sectionResult) + { + if (sectionResult == null) + { + throw new ArgumentNullException("sectionResult"); + } + SectionResult = sectionResult; + } + + public string Name + { + get + { + return SectionResult.Section.Name; + } + } + + public bool AssessmentLayerOne + { + get + { + return SectionResult.AssessmentLayerOne; + } + set + { + SectionResult.AssessmentLayerOne = value; + SectionResult.NotifyObservers(); + } + } + + public string AssessmentLayerTwoA + { + get + { + var relevantScenarios = SectionResult.CalculationScenarios.Where(cs => cs.IsRelevant).ToArray(); + bool relevantScenarioAvailable = relevantScenarios.Length != 0; + + if (relevantScenarioAvailable && Math.Abs(SectionResult.TotalContribution - 1.0) > tolerance) + { + return string.Format("{0}", double.NaN); + } + + if (!relevantScenarioAvailable || SectionResult.CalculationScenarioStatus != CalculationScenarioStatus.Done) + { + return Resources.FailureMechanismSectionResultRow_AssessmentLayerTwoA_No_result_dash; + } + + var layerTwoA = SectionResult.AssessmentLayerTwoA.Value; + + return string.Format(CommonBaseResources.ProbabilityPerYearFormat, layerTwoA); + } + } + + public RoundedDouble AssessmentLayerTwoB + { + get + { + return SectionResult.AssessmentLayerTwoB; + } + set + { + SectionResult.AssessmentLayerTwoB = value; + } + } + + public RoundedDouble AssessmentLayerThree + { + get + { + return SectionResult.AssessmentLayerThree; + } + set + { + SectionResult.AssessmentLayerThree = value; + } + } + + public PipingFailureMechanismSectionResult SectionResult { get; private set; } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj =================================================================== diff -u -rc196992ccccf32ce0fd55b83a17e3f3574467a1e -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision c196992ccccf32ce0fd55b83a17e3f3574467a1e) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -102,6 +102,7 @@ + Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismResultViewTest.cs =================================================================== diff -u -r41fac7fff0a505c08945108d795dcb877f10b816 -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismResultViewTest.cs (.../PipingFailureMechanismResultViewTest.cs) (revision 41fac7fff0a505c08945108d795dcb877f10b816) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismResultViewTest.cs (.../PipingFailureMechanismResultViewTest.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -65,7 +65,6 @@ Assert.IsInstanceOf(view); Assert.IsInstanceOf(view); Assert.IsNull(view.Data); - Assert.IsNull(view.FailureMechanism); } } @@ -81,17 +80,14 @@ Assert.AreEqual(5, dataGridView.ColumnCount); Assert.IsTrue(dataGridView.Columns[assessmentLayerTwoAIndex].ReadOnly); + Assert.AreEqual(DataGridViewAutoSizeColumnsMode.AllCells, dataGridView.AutoSizeColumnsMode); + Assert.AreEqual(DataGridViewContentAlignment.MiddleCenter, dataGridView.ColumnHeadersDefaultCellStyle.Alignment); + foreach (var column in dataGridView.Columns.OfType()) { Assert.AreEqual("This", column.ValueMember); Assert.AreEqual("DisplayName", column.DisplayMember); } - - foreach (var column in dataGridView.Columns.OfType()) - { - Assert.AreEqual(DataGridViewAutoSizeColumnMode.AllCells, column.AutoSizeMode); - Assert.AreEqual(DataGridViewContentAlignment.MiddleCenter, column.HeaderCell.Style.Alignment); - } } } @@ -131,7 +127,7 @@ } [Test] - public void Data_SetOtherThanFailureMechanismSectionResultListData_DataNullAndDataGridViewOneEmtpyRow() + public void Data_SetOtherThanFailureMechanismSectionResultListData_DataNullAndEmptyGrid() { // Setup var testData = new object(); @@ -145,38 +141,11 @@ // Assert Assert.IsNull(view.Data); - Assert.AreEqual(1, dataGridView.RowCount); - foreach (DataGridViewCell cell in dataGridView.Rows[0].Cells) - { - Assert.IsNull(cell.Value); - } + Assert.AreEqual(0, dataGridView.RowCount); } } [Test] - public void Dispose_FailureMechanismResultViewWithAdditionalPropertiesSet_AdditionalPropertiesSetToNull() - { - // Setup - var mocks = new MockRepository(); - var failureMechanism = new PipingFailureMechanism(); - mocks.ReplayAll(); - using (var view = new PipingFailureMechanismResultView - { - FailureMechanism = failureMechanism - }) - { - // Precondition - Assert.IsNotNull(view.FailureMechanism); - - // Call - view.Dispose(); - - // Assert - Assert.IsNull(view.FailureMechanism); - } - } - - [Test] public void FailureMechanismResultsView_AllDataSet_DataGridViewCorrectlyInitialized() { // Setup & Call Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismSectionResultRowTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismSectionResultRowTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismSectionResultRowTest.cs (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) @@ -0,0 +1,237 @@ +// Copyright (C) Stichting Deltares 2016. 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 Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.Properties; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.Views; + +using CommonBaseResources = Core.Common.Base.Properties.Resources; + +namespace Ringtoets.Piping.Forms.Test.Views +{ + public class PipingFailureMechanismSectionResultRowTest + { + + [Test] + public void Constructor_WithoutSectionResult_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new PipingFailureMechanismSectionResultRow(null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("sectionResult", paramName); + } + + [Test] + public void Constructor_WithSectionResult_PropertiesFromSectionAndResult() + { + // Setup + var section = CreateSection(); + var result = new PipingFailureMechanismSectionResult(section); + + // Call + var row = new PipingFailureMechanismSectionResultRow(result); + + // Assert + Assert.AreEqual(section.Name, row.Name); + Assert.AreEqual(result.AssessmentLayerOne, row.AssessmentLayerOne); + Assert.AreEqual(result.AssessmentLayerTwoB, row.AssessmentLayerTwoB); + Assert.AreEqual(result.AssessmentLayerThree, row.AssessmentLayerThree); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void AssessmentLayerOne_AlwaysOnChange_NotifyObserversOfResultAndResultPropertyChanged(bool newValue) + { + // Setup + var section = CreateSection(); + var result = new PipingFailureMechanismSectionResult(section); + var row = new PipingFailureMechanismSectionResultRow(result); + + int counter = 0; + using (new Observer(() => counter++) + { + Observable = result + }) + { + // Call + row.AssessmentLayerOne = newValue; + + // Assert + Assert.AreEqual(1, counter); + Assert.AreEqual(newValue, result.AssessmentLayerOne); + } + } + + [Test] + public void AssessmentLayerTwoA_NoScenarios_ShowDash() + { + // Setup + var section = CreateSection(); + var result = new PipingFailureMechanismSectionResult(section); + + // Call + var row = new PipingFailureMechanismSectionResultRow(result); + + // Assert + Assert.AreEqual(Resources.FailureMechanismSectionResultRow_AssessmentLayerTwoA_No_result_dash, row.AssessmentLayerTwoA); + } + + [Test] + [TestCase(0.2,0.8-1e5)] + [TestCase(0.0,0.5)] + [TestCase(0.3,0.7+1e-5)] + [TestCase(-5,-8)] + [TestCase(13,2)] + public void AssessmentLayerTwoA_RelevantScenarioContributionDontAddUpTo1_NaN(double contributionA, double contributionB) + { + // Setup + var mocks = new MockRepository(); + var scenarioA = mocks.Stub(); + var scenarioB = mocks.Stub(); + scenarioA.Contribution = (RoundedDouble)contributionA; + scenarioA.IsRelevant = true; + scenarioA.Stub(s => s.Status).Return(CalculationScenarioStatus.Done); + scenarioB.Contribution = (RoundedDouble)contributionB; + scenarioB.IsRelevant = true; + scenarioB.Stub(s => s.Status).Return(CalculationScenarioStatus.Done); + mocks.ReplayAll(); + + var section = CreateSection(); + var result = new PipingFailureMechanismSectionResult(section); + var row = new PipingFailureMechanismSectionResultRow(result); + result.CalculationScenarios.Add(scenarioA); + result.CalculationScenarios.Add(scenarioB); + + // Call + var assessmentLayerTwoA = row.AssessmentLayerTwoA; + + // Assert + Assert.AreEqual(string.Format("{0}", double.NaN), assessmentLayerTwoA); + mocks.VerifyAll(); + } + + [Test] + [TestCase(CalculationScenarioStatus.NotCalculated)] + [TestCase(CalculationScenarioStatus.Failed)] + public void AssessmentLayerTwoA_NoRelevantScenariosDone_Dash(CalculationScenarioStatus status) + { + // Setup + var mocks = new MockRepository(); + var scenario = mocks.Stub(); + scenario.Stub(cs => cs.Status).Return(status); + scenario.Contribution = (RoundedDouble)1.0; + scenario.IsRelevant = true; + mocks.ReplayAll(); + + var section = CreateSection(); + var result = new PipingFailureMechanismSectionResult(section); + var row = new PipingFailureMechanismSectionResultRow(result); + result.CalculationScenarios.Add(scenario); + + // Call + var assessmentLayerTwoA = row.AssessmentLayerTwoA; + + // Assert + Assert.AreEqual(Resources.FailureMechanismSectionResultRow_AssessmentLayerTwoA_No_result_dash, assessmentLayerTwoA); + mocks.VerifyAll(); + } + + [Test] + public void AssessmentLayerTwoA_RelevantScenariosDone_ResultOfSection() + { + // Setup + var mocks = new MockRepository(); + var scenario = mocks.Stub(); + scenario.Stub(cs => cs.Status).Return(CalculationScenarioStatus.Done); + scenario.Stub(cs => cs.Probability).Return((RoundedDouble)0.2); + scenario.Contribution = (RoundedDouble)1.0; + scenario.IsRelevant = true; + mocks.ReplayAll(); + + var section = CreateSection(); + var result = new PipingFailureMechanismSectionResult(section); + var row = new PipingFailureMechanismSectionResultRow(result); + result.CalculationScenarios.Add(scenario); + + // Call + var assessmentLayerTwoA = row.AssessmentLayerTwoA; + + // Assert + var expected = string.Format(CommonBaseResources.ProbabilityPerYearFormat, result.AssessmentLayerTwoA); + Assert.AreEqual(expected, assessmentLayerTwoA); + mocks.VerifyAll(); + } + + [Test] + public void AssessmentLayerTwoB_AlwaysOnChange_ResultPropertyChanged() + { + // Setup + var random = new Random(21); + var newValue = random.NextDouble(); + var section = CreateSection(); + var result = new PipingFailureMechanismSectionResult(section); + var row = new PipingFailureMechanismSectionResultRow(result); + + // Call + row.AssessmentLayerTwoB = (RoundedDouble) newValue; + + // Assert + Assert.AreEqual(newValue, result.AssessmentLayerTwoB, row.AssessmentLayerTwoB.GetAccuracy()); + } + + [Test] + public void AssessmentLayerThree_AlwaysOnChange_ResultPropertyChanged() + { + // Setup + var random = new Random(21); + var newValue = random.NextDouble(); + var section = CreateSection(); + var result = new PipingFailureMechanismSectionResult(section); + var row = new PipingFailureMechanismSectionResultRow(result); + + // Call + row.AssessmentLayerThree = (RoundedDouble) newValue; + + // Assert + Assert.AreEqual(newValue, result.AssessmentLayerThree, row.AssessmentLayerThree.GetAccuracy()); + } + + private static FailureMechanismSection CreateSection() + { + return new FailureMechanismSection("name", new[] + { + new Point2D(0, 0) + }); + } + } +} \ No newline at end of file