// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using Core.Common.Controls.DataGrid; using Ringtoets.AssemblyTool.Data; using Ringtoets.AssemblyTool.Forms; using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.Views; using Ringtoets.Common.Primitives; using Ringtoets.StabilityStoneCover.Data; namespace Ringtoets.StabilityStoneCover.Forms.Views { /// /// Class for displaying /// as a row in a grid view. /// public class StabilityStoneCoverSectionResultRow : FailureMechanismSectionResultRow { private readonly int simpleAssessmentResultIndex; private readonly int detailedAssessmentResultForFactorizedSignalingNormIndex; private readonly int detailedAssessmentResultForSignalingNormIndex; private readonly int detailedAssessmentResultForMechanismSpecificLowerLimitNormIndex; private readonly int detailedAssessmentResultForLowerLimitNormIndex; private readonly int detailedAssessmentResultForFactorizedLowerLimitNormIndex; private readonly int tailorMadeAssessmentResultIndex; private readonly int simpleAssemblyCategoryGroupIndex; private readonly int detailedAssemblyCategoryGroupIndex; private readonly int tailorMadeAssemblyCategoryGroupIndex; private readonly int combinedAssemblyCategoryGroupIndex; private readonly int manualAssemblyCategoryGroupIndex; private FailureMechanismSectionAssemblyCategoryGroup simpleAssemblyCategoryGroup; private FailureMechanismSectionAssemblyCategoryGroup detailedAssemblyCategoryGroup; private FailureMechanismSectionAssemblyCategoryGroup tailorMadeAssemblyCategoryGroup; private FailureMechanismSectionAssemblyCategoryGroup combinedAssemblyCategoryGroup; /// /// Creates a new instance of . /// /// The /// to wrap so that it can be displayed as a row. /// The property values required to create an instance of /// . /// Thrown when any parameter is null. public StabilityStoneCoverSectionResultRow(StabilityStoneCoverFailureMechanismSectionResult sectionResult, ConstructionProperties constructionProperties) : base(sectionResult) { if (constructionProperties == null) { throw new ArgumentNullException(nameof(constructionProperties)); } simpleAssessmentResultIndex = constructionProperties.SimpleAssessmentResultIndex; detailedAssessmentResultForFactorizedSignalingNormIndex = constructionProperties.DetailedAssessmentResultForFactorizedSignalingNormIndex; detailedAssessmentResultForSignalingNormIndex = constructionProperties.DetailedAssessmentResultForSignalingNormIndex; detailedAssessmentResultForMechanismSpecificLowerLimitNormIndex = constructionProperties.DetailedAssessmentResultForMechanismSpecificLowerLimitNormIndex; detailedAssessmentResultForLowerLimitNormIndex = constructionProperties.DetailedAssessmentResultForLowerLimitNormIndex; detailedAssessmentResultForFactorizedLowerLimitNormIndex = constructionProperties.DetailedAssessmentResultForFactorizedLowerLimitNormIndex; tailorMadeAssessmentResultIndex = constructionProperties.TailorMadeAssessmentResultIndex; simpleAssemblyCategoryGroupIndex = constructionProperties.SimpleAssemblyCategoryGroupIndex; detailedAssemblyCategoryGroupIndex = constructionProperties.DetailedAssemblyCategoryGroupIndex; tailorMadeAssemblyCategoryGroupIndex = constructionProperties.TailorMadeAssemblyCategoryGroupIndex; combinedAssemblyCategoryGroupIndex = constructionProperties.CombinedAssemblyCategoryGroupIndex; manualAssemblyCategoryGroupIndex = constructionProperties.ManualAssemblyCategoryGroupIndex; CreateColumnStateDefinitions(); Update(); } /// /// Gets or sets the value representing the simple assessment result. /// public SimpleAssessmentValidityOnlyResultType SimpleAssessmentResult { get { return SectionResult.SimpleAssessmentResult; } set { SectionResult.SimpleAssessmentResult = value; UpdateInternalData(); } } /// /// Gets or sets the value of the detailed assessment of safety per failure mechanism section /// for the factorized signaling norm (Cat Iv - IIv). /// public DetailedAssessmentResultType DetailedAssessmentResultForFactorizedSignalingNorm { get { return SectionResult.DetailedAssessmentResultForFactorizedSignalingNorm; } set { SectionResult.DetailedAssessmentResultForFactorizedSignalingNorm = value; UpdateInternalData(); } } /// /// Gets or sets the value of the detailed assessment of safety per failure mechanism section /// for the signaling norm (Cat IIv - IIIv). /// public DetailedAssessmentResultType DetailedAssessmentResultForSignalingNorm { get { return SectionResult.DetailedAssessmentResultForSignalingNorm; } set { SectionResult.DetailedAssessmentResultForSignalingNorm = value; UpdateInternalData(); } } /// /// Gets or sets the value of the detailed assessment of safety per failure mechanism section /// for the signaling norm (Cat IIIv - IVv). /// public DetailedAssessmentResultType DetailedAssessmentResultForMechanismSpecificLowerLimitNorm { get { return SectionResult.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm; } set { SectionResult.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm = value; UpdateInternalData(); } } /// /// Gets or sets the value of the detailed assessment of safety per failure mechanism section /// for the signaling norm (Cat IVv - Vv). /// public DetailedAssessmentResultType DetailedAssessmentResultForLowerLimitNorm { get { return SectionResult.DetailedAssessmentResultForLowerLimitNorm; } set { SectionResult.DetailedAssessmentResultForLowerLimitNorm = value; UpdateInternalData(); } } /// /// Gets or sets the value of the detailed assessment of safety per failure mechanism section /// for the signaling norm (Cat Vv - VIv). /// public DetailedAssessmentResultType DetailedAssessmentResultForFactorizedLowerLimitNorm { get { return SectionResult.DetailedAssessmentResultForFactorizedLowerLimitNorm; } set { SectionResult.DetailedAssessmentResultForFactorizedLowerLimitNorm = value; UpdateInternalData(); } } /// /// Gets or sets the tailor made assessment result. /// public SelectableFailureMechanismSectionAssemblyCategoryGroup TailorMadeAssessmentResult { get { return SelectableFailureMechanismSectionAssemblyCategoryGroupConverter.ConvertTo(SectionResult.TailorMadeAssessmentResult); } set { SectionResult.TailorMadeAssessmentResult = SelectableFailureMechanismSectionAssemblyCategoryGroupConverter.ConvertFrom(value); UpdateInternalData(); } } /// /// Gets the simple assembly category group. /// public string SimpleAssemblyCategoryGroup { get { return FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(simpleAssemblyCategoryGroup); } } /// /// Gets the detailed assembly category group. /// public string DetailedAssemblyCategoryGroup { get { return FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(detailedAssemblyCategoryGroup); } } /// /// Gets the tailor made assembly category group. /// public string TailorMadeAssemblyCategoryGroup { get { return FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(tailorMadeAssemblyCategoryGroup); } } /// /// Gets the combined assembly category group. /// public string CombinedAssemblyCategoryGroup { get { return FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(combinedAssemblyCategoryGroup); } } /// /// Gets or sets the indicator whether the combined assembly should be overwritten by . /// /// Thrown when /// is a valid value, but unsupported. public bool UseManualAssemblyCategoryGroup { get { return SectionResult.UseManualAssemblyCategoryGroup; } set { SectionResult.UseManualAssemblyCategoryGroup = value; UpdateInternalData(); } } /// /// Gets or sets the manually selected assembly category group. /// public SelectableFailureMechanismSectionAssemblyCategoryGroup ManualAssemblyCategoryGroup { get { return SelectableFailureMechanismSectionAssemblyCategoryGroupConverter.ConvertTo(SectionResult.ManualAssemblyCategoryGroup); } set { SectionResult.ManualAssemblyCategoryGroup = SelectableFailureMechanismSectionAssemblyCategoryGroupConverter.ConvertFrom(value); UpdateInternalData(); } } public override void Update() { UpdateDerivedData(); UpdateColumnStateDefinitionStates(); } private void CreateColumnStateDefinitions() { ColumnStateDefinitions.Add(simpleAssessmentResultIndex, new DataGridViewColumnStateDefinition()); ColumnStateDefinitions.Add(detailedAssessmentResultForFactorizedSignalingNormIndex, new DataGridViewColumnStateDefinition()); ColumnStateDefinitions.Add(detailedAssessmentResultForSignalingNormIndex, new DataGridViewColumnStateDefinition()); ColumnStateDefinitions.Add(detailedAssessmentResultForMechanismSpecificLowerLimitNormIndex, new DataGridViewColumnStateDefinition()); ColumnStateDefinitions.Add(detailedAssessmentResultForLowerLimitNormIndex, new DataGridViewColumnStateDefinition()); ColumnStateDefinitions.Add(detailedAssessmentResultForFactorizedLowerLimitNormIndex, new DataGridViewColumnStateDefinition()); ColumnStateDefinitions.Add(tailorMadeAssessmentResultIndex, new DataGridViewColumnStateDefinition()); ColumnStateDefinitions.Add(simpleAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition { ReadOnly = true }); ColumnStateDefinitions.Add(detailedAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition { ReadOnly = true }); ColumnStateDefinitions.Add(tailorMadeAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition { ReadOnly = true }); ColumnStateDefinitions.Add(combinedAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition { ReadOnly = true }); ColumnStateDefinitions.Add(manualAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition()); } private void UpdateDerivedData() { ResetErrorTexts(); TryGetSimpleAssemblyCategoryGroup(); TryGetDetailedAssemblyCategoryGroup(); TryGetTailorMadeAssemblyCategoryGroup(); TryGetCombinedAssemblyCategoryGroup(); } private void ResetErrorTexts() { ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex].ErrorText = string.Empty; ColumnStateDefinitions[detailedAssemblyCategoryGroupIndex].ErrorText = string.Empty; ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex].ErrorText = string.Empty; ColumnStateDefinitions[combinedAssemblyCategoryGroupIndex].ErrorText = string.Empty; } private void TryGetSimpleAssemblyCategoryGroup() { try { simpleAssemblyCategoryGroup = StabilityStoneCoverFailureMechanismSectionResultAssemblyFactory.AssembleSimpleAssessment(SectionResult); } catch (AssemblyException e) { simpleAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex].ErrorText = e.InnerException.Message; } } private void TryGetDetailedAssemblyCategoryGroup() { try { detailedAssemblyCategoryGroup = StabilityStoneCoverFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssessment(SectionResult); } catch (AssemblyException e) { detailedAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; ColumnStateDefinitions[detailedAssemblyCategoryGroupIndex].ErrorText = e.InnerException.Message; } } private void TryGetTailorMadeAssemblyCategoryGroup() { try { tailorMadeAssemblyCategoryGroup = StabilityStoneCoverFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssessment(SectionResult); } catch (AssemblyException e) { tailorMadeAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex].ErrorText = e.InnerException.Message; } } private void TryGetCombinedAssemblyCategoryGroup() { try { combinedAssemblyCategoryGroup = StabilityStoneCoverFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssessment( SectionResult); } catch (AssemblyException e) { combinedAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; ColumnStateDefinitions[combinedAssemblyCategoryGroupIndex].ErrorText = e.InnerException.Message; } } /// /// Updates the column state definitions. /// /// Thrown when /// is a valid value, but unsupported. private void UpdateColumnStateDefinitionStates() { bool simpleAssessmentSufficient = FailureMechanismSectionResultRowHelper.SimpleAssessmentIsSufficient(SimpleAssessmentResult); FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[detailedAssessmentResultForFactorizedSignalingNormIndex], simpleAssessmentSufficient); FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[detailedAssessmentResultForSignalingNormIndex], simpleAssessmentSufficient); FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[detailedAssessmentResultForMechanismSpecificLowerLimitNormIndex], simpleAssessmentSufficient); FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[detailedAssessmentResultForLowerLimitNormIndex], simpleAssessmentSufficient); FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[detailedAssessmentResultForFactorizedLowerLimitNormIndex], simpleAssessmentSufficient); FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[tailorMadeAssessmentResultIndex], simpleAssessmentSufficient); } /// /// Class holding the various construction parameters for . /// public class ConstructionProperties { /// /// Sets the simple assessment result index. /// public int SimpleAssessmentResultIndex { internal get; set; } /// /// Sets the detailed assessment result for factorized signaling norm index. /// public int DetailedAssessmentResultForFactorizedSignalingNormIndex { internal get; set; } /// /// Sets the detailed assessment result for signaling norm index. /// public int DetailedAssessmentResultForSignalingNormIndex { internal get; set; } /// /// Sets the detailed assessment result for mechanism specific lower limit norm index. /// public int DetailedAssessmentResultForMechanismSpecificLowerLimitNormIndex { internal get; set; } /// /// Sets the detailed assessment result for lower limit norm index. /// public int DetailedAssessmentResultForLowerLimitNormIndex { internal get; set; } /// /// Sets the detailed assessment result for factorized lower limit norm index. /// public int DetailedAssessmentResultForFactorizedLowerLimitNormIndex { internal get; set; } /// /// Sets the tailor made assessment result index. /// public int TailorMadeAssessmentResultIndex { internal get; set; } /// /// Sets the simple assembly category group index. /// public int SimpleAssemblyCategoryGroupIndex { internal get; set; } /// /// Sets the detailed assembly category group index. /// public int DetailedAssemblyCategoryGroupIndex { internal get; set; } /// /// Sets the tailor made assembly category group index. /// public int TailorMadeAssemblyCategoryGroupIndex { internal get; set; } /// /// Sets the combined assembly category group index. /// public int CombinedAssemblyCategoryGroupIndex { internal get; set; } /// /// Sets the manual assembly category group index. /// public int ManualAssemblyCategoryGroupIndex { internal get; set; } } } }