// 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.Collections.Generic; using System.Linq; using Core.Common.Base.Geometry; using Core.Components.Gis.Data; using Core.Components.Gis.Features; using Ringtoets.Common.Forms.Factories; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.MacroStabilityInwards.Data; using Ringtoets.MacroStabilityInwards.Primitives; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.MacroStabilityInwards.Forms.Factories { /// /// Factory for creating arrays of to use in /// (created via ). /// internal static class MacroStabilityInwardsMapDataFeaturesFactory { /// /// Create surface line features based on the provided . /// /// The collection of to create the surface line features for. /// An array of features or an empty array when is null or empty. public static MapFeature[] CreateSurfaceLineFeatures(MacroStabilityInwardsSurfaceLine[] surfaceLines) { if (surfaceLines != null && surfaceLines.Any()) { var features = new MapFeature[surfaceLines.Length]; for (var i = 0; i < surfaceLines.Length; i++) { MacroStabilityInwardsSurfaceLine surfaceLine = surfaceLines[i]; MapFeature feature = RingtoetsMapDataFeaturesFactory.CreateSingleLineMapFeature(GetWorldPoints(surfaceLine)); feature.MetaData[RingtoetsCommonFormsResources.MetaData_Name] = surfaceLine.Name; features[i] = feature; } return features; } return new MapFeature[0]; } /// /// Create stochastic soil model features based on the provided . /// /// The collection of to create the stochastic soil model features for. /// An array of features or an empty array when is null or empty. public static MapFeature[] CreateStochasticSoilModelFeatures(StochasticSoilModel[] stochasticSoilModels) { if (stochasticSoilModels != null && stochasticSoilModels.Any()) { var features = new MapFeature[stochasticSoilModels.Length]; for (var i = 0; i < stochasticSoilModels.Length; i++) { StochasticSoilModel stochasticSoilModel = stochasticSoilModels[i]; MapFeature feature = RingtoetsMapDataFeaturesFactory.CreateSingleLineMapFeature(GetWorldPoints(stochasticSoilModel)); feature.MetaData[RingtoetsCommonFormsResources.MetaData_Name] = stochasticSoilModel.Name; features[i] = feature; } return features; } return new MapFeature[0]; } /// /// Create calculation features based on the provided . /// /// The collection of to create the calculation features for. /// An array of features or an empty array when is null or empty. public static MapFeature[] CreateCalculationFeatures(IEnumerable calculations) { bool hasCalculations = calculations != null && calculations.Any(); if (!hasCalculations) { return new MapFeature[0]; } IEnumerable calculationsWithLocationAndHydraulicBoundaryLocation = calculations.Where(c => c.InputParameters.SurfaceLine != null && c.InputParameters.HydraulicBoundaryLocation != null); MapCalculationData[] calculationData = calculationsWithLocationAndHydraulicBoundaryLocation.Select( calculation => new MapCalculationData( calculation.Name, calculation.InputParameters.SurfaceLine.ReferenceLineIntersectionWorldPoint, calculation.InputParameters.HydraulicBoundaryLocation)).ToArray(); return RingtoetsMapDataFeaturesFactory.CreateCalculationFeatures(calculationData); } private static IEnumerable GetWorldPoints(MacroStabilityInwardsSurfaceLine surfaceLine) { return surfaceLine.Points.Select(p => new Point2D(p.X, p.Y)); } private static IEnumerable GetWorldPoints(StochasticSoilModel stochasticSoilModel) { return stochasticSoilModel.Geometry.Select(p => new Point2D(p)); } } }