// 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 form a closed area. /// public class MapPolygonData : FeatureBasedMapData { /// /// Creates a new instance of with default styling. /// /// The name of the . /// Thrown when is /// null or only whitespace. public MapPolygonData(string name) : this(name, CreateDefaultPolygonStyle()) {} /// /// 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 MapPolygonData(string name, PolygonStyle style) : base(name) { if (style == null) { throw new ArgumentNullException(nameof(style)); } Style = style; } /// /// Gets the style of the polygon. /// public PolygonStyle Style { get; } /// /// This method validates newly set features. /// /// The new features to validate. /// Thrown when is null. /// Thrown when any feature in /// contains no point-collections. /// protected override void ValidateFeatures(IEnumerable featuresToValidate) { base.ValidateFeatures(featuresToValidate); if (HasFeatureWithEmptyPointCollections(featuresToValidate)) { throw new ArgumentException("MapPolygonData only accepts MapFeature instances whose MapGeometries contain at least one single point-collection."); } } private static PolygonStyle CreateDefaultPolygonStyle() { return new PolygonStyle { FillColor = Color.DarkGray, StrokeColor = Color.Black, StrokeThickness = 2 }; } private static bool HasFeatureWithEmptyPointCollections(IEnumerable lineFeatures) { return lineFeatures.SelectMany(feature => feature.MapGeometries) .Any(geometry => !geometry.PointCollections.Any()); } } }