Exemplo n.º 1
0
        /// <summary>
        /// Статический метод для создания копии фигуры
        /// </summary>
        /// <param name="figure">Фигура для копирования</param>
        /// <param name="copyType">Тип копирования</param>
        /// <returns>Копия фигуры</returns>
        public static BaseFigure CreateCopy(BaseFigure figure,
                                            CopyType copyType = CopyType.NormalCopy)
        {
            BaseFigure resultFigure = null;

            if (figure.GetType() == typeof(Line))
            {
                resultFigure = new Line
                {
                    LineProperties =
                    {
                        Color     = figure.LineProperties.Color,
                        Thickness = figure.LineProperties.Thickness,
                        Style     = figure.LineProperties.Style
                    }
                };

                CopyPoints(figure, resultFigure, copyType);
            }
            else if (figure.GetType() == typeof(Polyline))
            {
                resultFigure = new Polyline
                {
                    LineProperties =
                    {
                        Color     = figure.LineProperties.Color,
                        Thickness = figure.LineProperties.Thickness,
                        Style     = figure.LineProperties.Style
                    }
                };

                CopyPoints(figure, resultFigure, copyType);
            }
            else if (figure.GetType() == typeof(Circle))
            {
                var circle = new Circle
                {
                    LineProperties =
                    {
                        Color     = figure.LineProperties.Color,
                        Thickness = figure.LineProperties.Thickness,
                        Style     = figure.LineProperties.Style
                    }
                };

                var temp = figure as FillableFigure;
                if (temp != null)
                {
                    circle.FillProperty.FillColor = temp.FillProperty.FillColor;
                }


                CopyPoints(figure, circle, copyType);

                resultFigure = circle;
            }
            else if (figure.GetType() == typeof(Ellipse))
            {
                var ellipse = new Ellipse
                {
                    LineProperties =
                    {
                        Color     = figure.LineProperties.Color,
                        Thickness = figure.LineProperties.Thickness,
                        Style     = figure.LineProperties.Style
                    }
                };

                var temp = figure as FillableFigure;
                if (temp != null)
                {
                    ellipse.FillProperty.FillColor = temp.FillProperty.FillColor;
                }

                CopyPoints(figure, ellipse, copyType);

                resultFigure = ellipse;
            }
            else if (figure.GetType() == typeof(Polygon))
            {
                var polygon = new Polygon
                {
                    LineProperties =
                    {
                        Color     = figure.LineProperties.Color,
                        Thickness = figure.LineProperties.Thickness,
                        Style     = figure.LineProperties.Style
                    }
                };

                var temp = figure as FillableFigure;
                if (temp != null)
                {
                    polygon.FillProperty.FillColor = temp.FillProperty.FillColor;
                }

                CopyPoints(figure, polygon, copyType);

                resultFigure = polygon;
            }

            return(resultFigure);
        }