// 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.ComponentModel; using System.Windows.Media; using Core.Components.GraphSharp.Data; using Core.Components.PointedTree.Data; namespace Core.Components.GraphSharp.Converters { /// /// Converter to change a to . /// public static class GraphNodeConverter { /// /// Converts a to a . /// /// The graph node to convert. /// The created . /// Thrown when /// is null. /// Thrown when /// is an invalid value. public static PointedTreeElementVertex Convert(GraphNode graphNode) { if (graphNode == null) { throw new ArgumentNullException(nameof(graphNode)); } GraphNodeStyle style = graphNode.Style; return new PointedTreeElementVertex( graphNode.Content, ConvertColor(style.FillColor), ConvertColor(style.LineColor), style.LineWidth, ConvertType(style.Shape), graphNode.IsSelectable); } private static SolidColorBrush ConvertColor(System.Drawing.Color color) { return new SolidColorBrush( Color.FromArgb( color.A, color.R, color.G, color.B)); } /// /// Converts a to a . /// /// The shape to convert. /// The converted . /// Thrown when /// is an invalid value. private static PointedTreeVertexType ConvertType(GraphNodeShape shape) { switch(shape) { case GraphNodeShape.Rectangle: return PointedTreeVertexType.Rectangle; case GraphNodeShape.Diamond: return PointedTreeVertexType.Diamond; default: throw new InvalidEnumArgumentException(nameof(shape), (int) shape, typeof(GraphNodeShape)); } } } }