// 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 System.Windows.Forms;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Forms.Properties;
using Ringtoets.Common.Forms.Views;
using Ringtoets.Common.Primitives;
namespace Ringtoets.Common.Forms.Helpers
{
///
/// Helper class for showing error messages in .
///
public static class FailureMechanismSectionResultRowHelper
{
///
/// Sets the when the detailed assessment fails.
///
/// The current data grid view cell.
/// The value representing the simple assessment result type.
/// 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.
/// Thrown when is null.
public static void SetDetailedAssessmentError(DataGridViewCell dataGridViewCell,
SimpleAssessmentResultType simpleAssessmentResult,
double detailedAssessmentProbability,
ICalculation normativeCalculation)
{
if (dataGridViewCell == null)
{
throw new ArgumentNullException(nameof(dataGridViewCell));
}
if (simpleAssessmentResult == SimpleAssessmentResultType.NotApplicable
|| simpleAssessmentResult == SimpleAssessmentResultType.ProbabilityNegligible)
{
dataGridViewCell.ErrorText = string.Empty;
return;
}
dataGridViewCell.ErrorText = GetDetailedAssessmentError(detailedAssessmentProbability, normativeCalculation);
}
///
/// Sets the when the detailed assessment fails.
///
/// The current data grid view cell.
/// The value representing the simple assessment result.
/// 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.
/// Thrown when is null.
public static void SetDetailedAssessmentError(DataGridViewCell dataGridViewCell,
SimpleAssessmentResultValidityOnlyType simpleAssessmentResult,
double detailedAssessmentProbability,
ICalculation normativeCalculation)
{
if (dataGridViewCell == null)
{
throw new ArgumentNullException(nameof(dataGridViewCell));
}
if (simpleAssessmentResult == SimpleAssessmentResultValidityOnlyType.NotApplicable)
{
dataGridViewCell.ErrorText = string.Empty;
return;
}
dataGridViewCell.ErrorText = GetDetailedAssessmentError(detailedAssessmentProbability, normativeCalculation);
}
///
/// 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;
}
private static CalculationScenarioStatus GetCalculationStatus(ICalculation calculation,
double detailedAssessmentProbability)
{
if (!calculation.HasOutput)
{
return CalculationScenarioStatus.NotCalculated;
}
if (double.IsNaN(detailedAssessmentProbability))
{
return CalculationScenarioStatus.Failed;
}
return CalculationScenarioStatus.Done;
}
}
}