// Copyright (C) Stichting Deltares 2018. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.ComponentModel; using System.Drawing; using Core.Common.Controls.DataGrid; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Forms.Properties; using Ringtoets.Common.Forms.Views; using Ringtoets.Common.Primitives; using Riskeer.AssemblyTool.Data; namespace Ringtoets.Common.Forms.Helpers { /// /// Helper class for updating states of a /// in a . /// public static class FailureMechanismSectionResultRowHelper { /// /// Gets the error text to display when the detailed assessment fails. /// /// The value representing the probability of the detailed assessment. /// The set for the /// section result. May be null if the section result does not have a calculation set. public static string GetDetailedAssessmentError(double detailedAssessmentProbability, ICalculation normativeCalculation) { if (normativeCalculation == null) { return Resources.FailureMechanismResultView_DataGridViewCellFormatting_Calculation_not_set; } CalculationScenarioStatus calculationScenarioStatus = GetCalculationStatus(normativeCalculation, detailedAssessmentProbability); if (calculationScenarioStatus == CalculationScenarioStatus.NotCalculated) { return Resources.FailureMechanismResultView_DataGridViewCellFormatting_Calculation_not_calculated; } if (calculationScenarioStatus == CalculationScenarioStatus.Failed) { return Resources.FailureMechanismResultView_DataGridViewCellFormatting_Calculation_must_have_valid_output; } return string.Empty; } /// /// Helper method that determines whether the simple assessment is sufficient. /// /// The simple assessment result to check. /// true when the simple assessment is /// or , false otherwise. public static bool SimpleAssessmentIsSufficient(SimpleAssessmentResultType simpleAssessmentResult) { return simpleAssessmentResult == SimpleAssessmentResultType.ProbabilityNegligible || simpleAssessmentResult == SimpleAssessmentResultType.NotApplicable; } /// /// Helper method that determines whether the simple assessment is sufficient. /// /// The simple assessment result to check. /// true when the simple assessment is , /// false otherwise. public static bool SimpleAssessmentIsSufficient(SimpleAssessmentValidityOnlyResultType simpleAssessmentResult) { return simpleAssessmentResult == SimpleAssessmentValidityOnlyResultType.NotApplicable; } /// /// Helper method that determines whether the detailed assessment /// is . /// /// The detailed assessment result to check. /// true when the detailed assessment is /// , false otherwise. public static bool DetailedAssessmentResultIsProbability(DetailedAssessmentProbabilityOnlyResultType detailedAssessmentResult) { return detailedAssessmentResult == DetailedAssessmentProbabilityOnlyResultType.Probability; } /// /// Helper method that determines whether the tailor made assessment /// is . /// /// The tailor made assessment result to check. /// true when the tailor made assessment /// is , false otherwise. public static bool TailorMadeAssessmentResultIsProbability(TailorMadeAssessmentProbabilityCalculationResultType tailorMadeAssessmentResult) { return tailorMadeAssessmentResult == TailorMadeAssessmentProbabilityCalculationResultType.Probability; } /// /// Helper method that determines whether the tailor made assessment /// is . /// /// The tailor made assessment result to check. /// true when the tailor made assessment /// is , false otherwise. public static bool TailorMadeAssessmentResultIsProbability(TailorMadeAssessmentProbabilityAndDetailedCalculationResultType tailorMadeAssessmentResult) { return tailorMadeAssessmentResult == TailorMadeAssessmentProbabilityAndDetailedCalculationResultType.Probability; } /// /// Helper method that sets the style of a based on a /// . /// /// The column state definition to set the style for. /// The assembly category group to base the style on. /// Thrown when /// has an invalid value for . /// Thrown when /// is not supported. /// Thrown when /// is null. public static void SetAssemblyCategoryGroupStyle(DataGridViewColumnStateDefinition columnStateDefinition, FailureMechanismSectionAssemblyCategoryGroup assemblyCategoryGroup) { if (columnStateDefinition == null) { throw new ArgumentNullException(nameof(columnStateDefinition)); } columnStateDefinition.Style = new CellStyle( Color.FromKnownColor(KnownColor.ControlText), AssemblyCategoryGroupColorHelper.GetFailureMechanismSectionAssemblyCategoryGroupColor(assemblyCategoryGroup)); } /// /// Helper method that sets the state of the /// based on . /// /// The column state definition to set the state for. /// Indicator whether the column should be disabled or not. /// Thrown when /// is null. public static void SetColumnState(DataGridViewColumnStateDefinition columnStateDefinition, bool shouldDisable) { if (columnStateDefinition == null) { throw new ArgumentNullException(nameof(columnStateDefinition)); } if (shouldDisable) { DisableColumn(columnStateDefinition); } else { EnableColumn(columnStateDefinition); } } /// /// Helper method that enables the . /// /// The column state definition to enable. /// Indicator whether the column should be read-only or not. /// Thrown when /// is null. public static void EnableColumn(DataGridViewColumnStateDefinition columnStateDefinition, bool readOnly = false) { if (columnStateDefinition == null) { throw new ArgumentNullException(nameof(columnStateDefinition)); } columnStateDefinition.ReadOnly = readOnly; columnStateDefinition.Style = CellStyle.Enabled; } /// /// Helper method that disables the . /// /// The column state definition to enable. /// Thrown when /// is null. public static void DisableColumn(DataGridViewColumnStateDefinition columnStateDefinition) { if (columnStateDefinition == null) { throw new ArgumentNullException(nameof(columnStateDefinition)); } columnStateDefinition.ReadOnly = true; columnStateDefinition.Style = CellStyle.Disabled; } private static CalculationScenarioStatus GetCalculationStatus(ICalculation calculation, double detailedAssessmentProbability) { if (!calculation.HasOutput) { return CalculationScenarioStatus.NotCalculated; } if (double.IsNaN(detailedAssessmentProbability)) { return CalculationScenarioStatus.Failed; } return CalculationScenarioStatus.Done; } } }