예제 #1
0
        /// <ToBeCompleted></ToBeCompleted>
        public virtual void CopyFrom(IShapeCollection source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            Clear();
            foreach (Shape shape in source.BottomUp)
            {
                Shape shapeClone = null;
                // If the parent shape has no template, we assume that this is
                // the shape of the template itself, so it's children should be
                // template-free, too
                if (Owner.Template == null)
                {
                    shapeClone = shape.Type.CreateInstance();
                    shapeClone.CopyFrom(shape);
                }
                else
                {
                    shapeClone = shape.Clone();
                }
                shapeClone.ZOrder         = shape.ZOrder;
                shapeClone.Parent         = this.Owner;
                shapeClone.DisplayService = this.Owner.DisplayService;

                this.shapes.Add(shapeClone);
                this.AddShapeToIndex(shapeClone);
            }
            if (source is ShapeAggregation)
            {
                ShapeAggregation src = (ShapeAggregation)source;
                this.aggregationAngle = src.aggregationAngle;
                this.rotationCenter   = src.rotationCenter;
                // Copy center points of the shapes
                this.shapePositions.Clear();
                for (int i = 0; i < shapes.Count; ++i)
                {
                    Point shapePos = src.shapePositions[src.shapes[i]];
                    this.shapePositions.Add(this.shapes[i], shapePos);
                }
            }
            else
            {
                // if the source ShapeCollection is not a ShapeAggregation,
                // store unrotated ShapePositions nevertheless
                this.shapePositions.Clear();
                for (int i = 0; i < shapes.Count; ++i)
                {
                    Point shapePos = Point.Empty;
                    shapePos.Offset(shapes[i].X, shapes[i].Y);
                    this.shapePositions.Add(shapes[i], shapePos);
                }
            }
        }
예제 #2
0
        /// <ToBeCompleted></ToBeCompleted>
        public virtual void CopyFrom(IShapeCollection source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            Clear();
            foreach (Shape shape in source.BottomUp)
            {
                Shape shapeClone = null;
                // If the parent shape has no template, we assume that this is
                // the shape of the template itself, so it's children should be
                // template-free, too
                if (Owner.Template == null)
                {
                    shapeClone = shape.Type.CreateInstance();
                    shapeClone.CopyFrom(shape);
                }
                else
                {
                    shapeClone = shape.Clone();
                }
                shapeClone.ZOrder         = shape.ZOrder;
                shapeClone.Parent         = this.Owner;
                shapeClone.DisplayService = this.Owner.DisplayService;

                this.shapes.Add(shapeClone);
                this.AddShapeToIndex(shapeClone);
            }

            // Experimental version of copying shapes
            //// Copy shape properties over. If number of items does not match,
            //// create new shape clones.
            //IEnumerator<Shape> sourceShapes = source.BottomUp.GetEnumerator();
            //IEnumerator<Shape> destShapes = this.BottomUp.GetEnumerator();
            //while (sourceShapes.MoveNext()) {
            //    Shape shape = sourceShapes.Current;
            //    Shape shapeClone = null;
            //    bool shapeExists = destShapes.MoveNext();
            //    if (shapeExists) {
            //        shapeClone = destShapes.Current;
            //        shapeClone.CopyFrom(shape);
            //    } else {
            //        shapeClone = shape.Clone();
            //        shapeClone.Parent = this.Owner;
            //    }
            //    shapeClone.ZOrder = shape.ZOrder;
            //    shapeClone.DisplayService = this.Owner.DisplayService;

            //    // Add new shape to collection
            //    if (!shapeExists) {
            //        this.shapes.Add(shapeClone);
            //        this.AddShapeToIndex(shapeClone);
            //    }
            //}

            if (source is ShapeAggregation)
            {
                ShapeAggregation src = (ShapeAggregation)source;
                this.aggregationAngle = src.aggregationAngle;
                this.rotationCenter   = src.rotationCenter;
                // Copy center points of the shapes
                this.shapePositions.Clear();
                for (int i = 0; i < shapes.Count; ++i)
                {
                    Point shapePos = src.shapePositions[src.shapes[i]];
                    this.shapePositions.Add(this.shapes[i], shapePos);
                }
            }
            else
            {
                // if the source ShapeCollection is not a ShapeAggregation,
                // store unrotated ShapePositions nevertheless
                this.shapePositions.Clear();
                for (int i = 0; i < shapes.Count; ++i)
                {
                    Point shapePos = Point.Empty;
                    shapePos.Offset(shapes[i].X, shapes[i].Y);
                    this.shapePositions.Add(shapes[i], shapePos);
                }
            }
        }