// 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.Linq; using Ringtoets.Common.IO.Exceptions; using Ringtoets.Common.IO.SoilProfile; using Ringtoets.MacroStabilityInwards.Data.SoilProfile; using Ringtoets.MacroStabilityInwards.Primitives; using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources; namespace Ringtoets.MacroStabilityInwards.IO.SoilProfiles { /// /// Transforms generic into /// or . /// internal static class MacroStabilityInwardsSoilProfileTransformer { /// /// Transforms the generic into an . /// /// The soil profile to use in the transformation. /// A new based on the given data. /// Thrown when is null. /// Thrown when transformation would not result /// in a valid transformed instance. public static IMacroStabilityInwardsSoilProfile Transform(ISoilProfile soilProfile) { if (soilProfile == null) { throw new ArgumentNullException(nameof(soilProfile)); } var soilProfile1D = soilProfile as SoilProfile1D; if (soilProfile1D != null) { return Transform(soilProfile1D); } var soilProfile2D = soilProfile as SoilProfile2D; if (soilProfile2D != null) { return Transform(soilProfile2D); } string message = string.Format(RingtoetsCommonIOResources.SoilProfileTransformer_Cannot_tranform_Type_0_Only_types_Type_1_and_Type_2_are_supported, soilProfile.GetType().Name, nameof(SoilProfile1D), nameof(SoilProfile2D)); throw new ImportedDataTransformException(message); } /// /// Transforms the generic into a /// . /// /// The soil profile to use in the transformation. /// A based on the given data. /// Thrown when cannot be /// transformed in a . private static MacroStabilityInwardsSoilProfile1D Transform(SoilProfile1D soilProfile) { try { return new MacroStabilityInwardsSoilProfile1D(soilProfile.Name, soilProfile.Bottom, soilProfile.Layers .Select(MacroStabilityInwardsSoilLayerTransformer.Transform) .ToArray()); } catch (ArgumentException e) { throw new ImportedDataTransformException(e.Message, e); } } /// /// Transforms the generic into a /// . /// /// The soil profile to use in the transformation. /// A based on the given data. /// Thrown when cannot be /// transformed in a . private static MacroStabilityInwardsSoilProfile2D Transform(SoilProfile2D soilProfile) { try { return new MacroStabilityInwardsSoilProfile2D(soilProfile.Name, soilProfile.Layers .Select(MacroStabilityInwardsSoilLayerTransformer.Transform) .ToArray(), soilProfile.PreconsolidationStresses .Select(MacroStabilityInwardsPreconsolidationStressTransformer.Transform) .ToArray()); } catch (ArgumentException e) { throw new ImportedDataTransformException(e.Message, e); } } } }