예제 #1
0
        internal static Geometry Copy(Geometry g)
        {
            if (g == null)
            {
                return(null);
            }

            RectangleGeometry rg = g as RectangleGeometry;

            if (rg != null)
            {
                return(new RectangleGeometry()
                {
                    Rect = rg.Bounds, RadiusX = rg.RadiusX, RadiusY = rg.RadiusY, Transform = rg.Transform
                });
            }
            EllipseGeometry eg = g as EllipseGeometry;

            if (eg != null)
            {
                return(new EllipseGeometry()
                {
                    Center = eg.Center, RadiusX = eg.RadiusX, RadiusY = eg.RadiusY, Transform = eg.Transform
                });
            }
            LineGeometry lg = g as LineGeometry;

            if (lg != null)
            {
                return(new LineGeometry()
                {
                    StartPoint = lg.StartPoint, EndPoint = lg.EndPoint, Transform = lg.Transform
                });
            }
            PathGeometry pg = g as PathGeometry;

            if (pg != null)
            {
                if (!Geo.PathGeometryHasFigures(pg))
                {
                    return(new RectangleGeometry()
                    {
                        Rect = pg.Bounds, RadiusX = 0, RadiusY = 0, Transform = pg.Transform
                    });
                }
                else
                {
                    PathGeometry pg2 = new PathGeometry();
                    pg2.FillRule = pg.FillRule;
                    pg2.Figures  = new PathFigureCollection(); // required for Geo.PathGeometryHasFigures to work
                    foreach (PathFigure pf in pg.Figures)
                    {
                        PathFigure pf2 = new PathFigure();
                        pf2.StartPoint = pf.StartPoint;
                        foreach (PathSegment ps in pf.Segments)
                        {
                            pf2.Segments.Add(Copy(ps));
                        }
                        pf2.IsClosed = pf.IsClosed;
                        pf2.IsFilled = pf.IsFilled;
                        pg2.Figures.Add(pf2);
                    }
                    pg2.Transform = pg.Transform;
                    return(pg2);
                }
            }
            GeometryGroup gg = g as GeometryGroup;

            if (gg != null)
            {
                GeometryGroup gg2 = new GeometryGroup();
                gg2.FillRule = gg.FillRule;
                foreach (Geometry x in gg.Children)
                {
                    gg2.Children.Add(Copy(x));
                }
                gg2.Transform = gg.Transform;
                return(gg2);
            }
            Diagram.Error("Copying an unknown kind of Geometry: " + g.ToString());
            return(null);
        }