// 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 Lesser 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser 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.Drawing; using System.Linq; using Core.Components.Gis.Features; using Core.Components.Gis.Style; namespace Core.Components.Gis.Data { /// /// This class represents features that are visible as a line. /// public class MapLineData : FeatureBasedMapData { /// /// Creates a new instance of with default styling. /// /// The name of the . /// Thrown when is /// null or only whitespace. public MapLineData(string name) : this(name, CreateDefaultLineStyle()) {} /// /// Creates a new instance of . /// /// The name of the . /// The style of the data. /// Thrown when is /// null or only whitespace. /// Thrown when /// is null. public MapLineData(string name, LineStyle style) : base(name) { if (style == null) { throw new ArgumentNullException(nameof(style)); } Style = style; } /// /// Gets the style of the line. /// public LineStyle Style { get; } /// /// This method validates newly set features. /// /// The new features to validate. /// Thrown when is null. /// Thrown when any feature in /// contains multiple point-collections. /// protected override void ValidateFeatures(IEnumerable featuresToValidate) { base.ValidateFeatures(featuresToValidate); if (HasFeatureWithMultiplePointCollections(featuresToValidate)) { throw new ArgumentException("MapLineData only accepts MapFeature instances whose MapGeometries contain a single point-collection."); } } private static LineStyle CreateDefaultLineStyle() { return new LineStyle { Color = Color.Black, Width = 2, DashStyle = LineDashStyle.Solid }; } private static bool HasFeatureWithMultiplePointCollections(IEnumerable lineFeatures) { return lineFeatures.SelectMany(feature => feature.MapGeometries) .Any(geometry => geometry.PointCollections.Count() != 1); } } }