﻿using System;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace XXXX.Converter
{
    public class PathConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null) return null;

            PathGeometry pg = new PathGeometry();

            foreach (PathFigure figure in ((System.Windows.Media.PathGeometry)value).Figures)
            {
                PathFigure pf = new PathFigure {StartPoint = new Point(figure.StartPoint.X, figure.StartPoint.Y)};
                foreach (LineSegment newLine in figure.Segments
                    .OfType<LineSegment>()
                    .Select(line => new LineSegment {Point = new Point(line.Point.X, line.Point.Y)}))
                {
                    pf.Segments.Add(newLine);
                }
                pg.Figures.Add(pf);
            }

            return pg;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
