// 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.Collections.Generic; using System.Linq; using Ringtoets.Common.Data.Hydraulics.IllustrationPoints; using Ringtoets.HydraRing.Calculation.Parsers.IllustrationPoints; using GeneralResult = Ringtoets.Common.Data.Hydraulics.IllustrationPoints.GeneralResult; using HydraGeneralResult = Ringtoets.HydraRing.Calculation.Parsers.IllustrationPoints.GeneralResult; using IHydraRingIllustrationPoint = Ringtoets.HydraRing.Calculation.Parsers.IllustrationPoints.IIllustrationPoint; using Stochast = Ringtoets.Common.Data.Hydraulics.IllustrationPoints.Stochast; using WindDirection = Ringtoets.Common.Data.Hydraulics.IllustrationPoints.WindDirection; namespace Ringtoets.Common.Service.IllustrationPoints { /// /// Converter for related to creating a . /// public static class GeneralResultConverter { /// /// Creates a new instance of based on the information of . /// /// The to base the /// to create on. /// The newly created . /// Thrown when is null. public static GeneralResult CreateGeneralResult(HydraGeneralResult hydraGeneralResult) { if (hydraGeneralResult == null) { throw new ArgumentNullException(nameof(hydraGeneralResult)); } WindDirection windDirection = WindDirectionConverter.CreateWindDirection(hydraGeneralResult.GoverningWind); IEnumerable stochasts = GetStochasts(hydraGeneralResult); IEnumerable windDirectionClosingScenarioIllustrationPoints = GetWindDirectionClosingSituationIllustrationPoint(hydraGeneralResult); return new GeneralResult(hydraGeneralResult.Beta, windDirection, stochasts, windDirectionClosingScenarioIllustrationPoints); } private static IEnumerable GetStochasts(HydraGeneralResult hydraGeneralResult) { return hydraGeneralResult.Stochasts.Select(StochastConverter.CreateStochast); } private static IEnumerable GetWindDirectionClosingSituationIllustrationPoint( HydraGeneralResult hydraGeneralResult) { var combinations = new List(); foreach (KeyValuePair illustrationPointTreeNode in hydraGeneralResult.IllustrationPoints) { IHydraRingIllustrationPoint hydraIllustrationPoint = illustrationPointTreeNode.Value.Data; WindDirectionClosingSituation hydraWindDirectionClosingSituation = illustrationPointTreeNode.Key; var subMechanismIllustrationPoint = hydraIllustrationPoint as SubMechanismIllustrationPoint; if (subMechanismIllustrationPoint != null) { combinations.Add(WindDirectionClosingSituationIllustrationPointConverter.CreateWindDirectionClosingScenarioIllustrationPoint( hydraWindDirectionClosingSituation, subMechanismIllustrationPoint)); } } return combinations; } } }