diff --git a/VectoCore/VectoCore/Models/Declaration/Axle.cs b/VectoCore/VectoCore/Models/Declaration/Axle.cs index 371ac5231afec5f3457e2f0d002a6af3d337e41f..4ab3df706321a42fbdb6c710d7066147d4bade70 100644 --- a/VectoCore/VectoCore/Models/Declaration/Axle.cs +++ b/VectoCore/VectoCore/Models/Declaration/Axle.cs @@ -29,31 +29,46 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.ComponentModel.DataAnnotations; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.Models.SimulationComponent.Data; - -namespace TUGraz.VectoCore.Models.Declaration -{ - public class Axle : SimulationComponentData - { - public string WheelsDimension { get; internal set; } - - [Required, SIRange(0, 100)] - public KilogramSquareMeter Inertia { get; internal set; } - - [Required, SIRange(0.003, 0.015)] - public double RollResistanceCoefficient { get; internal set; } - - [Required, SIRange(500, 100000)] - public Newton TyreTestLoad { get; internal set; } - - [Required, SIRange(0, 1, ExecutionMode.Engineering), SIRange(double.MinValue, 1, ExecutionMode.Declaration)] - public double AxleWeightShare { get; internal set; } - - public bool TwinTyres { get; internal set; } - - public AxleType AxleType { get; internal set; } - } -} \ No newline at end of file +using System; +using System.ComponentModel.DataAnnotations; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.SimulationComponent.Data; + +namespace TUGraz.VectoCore.Models.Declaration +{ + [CustomValidation(typeof(Axle), "ValidateAxleData")] + public class Axle : SimulationComponentData + { + public string WheelsDimension { get; internal set; } + + [Required, SIRange(0, 100)] + public KilogramSquareMeter Inertia { get; internal set; } + + [Required, SIRange(0.003, 0.015)] + public double RollResistanceCoefficient { get; internal set; } + + [Required, SIRange(500, 100000)] + public Newton TyreTestLoad { get; internal set; } + + [Required, SIRange(0, 1, ExecutionMode.Engineering), SIRange(double.MinValue, 1, ExecutionMode.Declaration)] + public double AxleWeightShare { get; internal set; } + + public bool TwinTyres { get; internal set; } + + public AxleType AxleType { get; internal set; } + + public static ValidationResult ValidateAxleData(Axle axle, ValidationContext validationContext) + { + var execMode = GetExecutionMode(validationContext); + if (execMode == ExecutionMode.Engineering) + return ValidationResult.Success; + try { + DeclarationData.Wheels.Lookup(axle.WheelsDimension); + } catch (Exception) { + return new ValidationResult(string.Format("Unknown Tyre dimenstion '{0}'", axle.WheelsDimension)); + } + return ValidationResult.Success; + } + } +}