private bool RestoreCildrenPositions()
        {
            bool result = true;

            try {
                SuspendUpdate();
                Rectangle ownerBounds = Owner.GetBoundingRectangle(true);
                // move children to their new absolute position calculated from relativePosition
                for (int i = 0; i < shapes.Count; ++i)
                {
                    PointPositions ptPositions = relativePositions[shapes[i]];
                    Debug.Assert(ptPositions != null);
                    // This will be the desired solution, but it does not work well for all shapes.
                    foreach (KeyValuePair <ControlPointId, RelativePosition> item in ptPositions.Items)
                    {
                        Debug.Assert(item.Value != RelativePosition.Empty);
                        Point p = Owner.CalculateAbsolutePosition(item.Value);
                        Debug.Assert(Geometry.IsValid(p));
                        shapes[i].MoveControlPointTo(item.Key, p.X, p.Y, ResizeModifiers.None);
                    }
                }
                boundingRectangleLoose = boundingRectangleTight = Geometry.InvalidRectangle;
            } finally {
                ResumeUpdate();
            }
            return(result);
        }
 /// <override></override>
 public override void CopyFrom(IShapeCollection source)
 {
     base.CopyFrom(source);
     if (source is CompositeShapeAggregation)
     {
         ResizableShapeAggregation src = (ResizableShapeAggregation)source;
         // Copy relative positions of the children
         relativePositions.Clear();
         int cnt = shapes.Count;
         for (int i = 0; i < cnt; ++i)
         {
             // Copy all items
             PointPositions srcPtPositions = src.relativePositions[src.shapes[i]];
             PointPositions dstPtPositions = new PointPositions();
             foreach (KeyValuePair <ControlPointId, RelativePosition> item in srcPtPositions.Items)
             {
                 dstPtPositions.Items.Add(item.Key, item.Value);
             }
             relativePositions.Add(shapes[i], dstPtPositions);
         }
     }
 }
        private void AddRelativePosition(Shape shape)
        {
            PointPositions ptPositions = new PointPositions(shape, Owner);

            relativePositions.Add(shape, ptPositions);
        }
Esempio n. 4
0
		private void AddRelativePosition(Shape shape) {
			PointPositions ptPositions = new PointPositions(shape, Owner);
			relativePositions.Add(shape, ptPositions);
		}
Esempio n. 5
0
		/// <override></override>
		public override void CopyFrom(IShapeCollection source) {
			base.CopyFrom(source);
			if (source is CompositeShapeAggregation) {
				CompositeShapeAggregation src = (CompositeShapeAggregation)source;
				// Copy relative positions of the children
				relativePositions.Clear();
				int cnt = shapes.Count;
				for (int i = 0; i < cnt; ++i) {
					// Copy all items
					PointPositions srcPtPositions = src.relativePositions[src.shapes[i]];
					PointPositions dstPtPositions = new PointPositions();
					foreach (KeyValuePair<ControlPointId, RelativePosition> item in srcPtPositions.Items)
						dstPtPositions.Items.Add(item.Key, item.Value);
					relativePositions.Add(shapes[i], dstPtPositions);
				}
			}
		}
Esempio n. 6
0
        private bool RestoreCildrenPositions()
        {
            bool result = true;

            try {
                SuspendUpdate();
                Rectangle ownerBounds = Owner.GetBoundingRectangle(true);
                // Move children to their new absolute position calculated from relativePosition
                for (int i = 0; i < shapes.Count; ++i)
                {
                    // Get the state of the shape's glue points
                    GluePointState gluePointState = GetGluePointState(shapes[i]);
                    if (gluePointState == GluePointState.AllConnected)
                    {
                        continue;
                    }

                    PointPositions ptPositions = relativePositions[shapes[i]];
                    Debug.Assert(ptPositions != null);
                    // Get the 'Anchor' points of the child shapes and move them to the new positions
                    IEnumerable <ControlPointId> anchorPointIds;
                    // As long as we do not have attributes for control points that specify move restrictions etc, we
                    // use specific implementations that work better and/or faster for some shape types and a default
                    // implementation that works for all other shapes.
                    if (shapes[i] is ILinearShape)
                    {
                        anchorPointIds = GetLineAnchorPoints(shapes[i]);
                    }
                    else if (shapes[i] is DiameterShapeBase)
                    {
                        Rectangle dstBounds = Rectangle.Empty;
                        Geometry.CalcBoundingRectangle(GetPointPositions(Owner, ptPositions.Items.Values), out dstBounds);
                        anchorPointIds = GetDiameterShapeAnchorPoints((DiameterShapeBase)shapes[i], dstBounds);
                    }
                    else if (shapes[i] is ImageBasedShape)
                    {
                        anchorPointIds = GetImageAnchorPoints((ImageBasedShape)shapes[i]);
                    }
                    else if (shapes[i] is IsoscelesTriangleBase)
                    {
                        anchorPointIds = GetIsoscelesTriangleAnchorPoints((IsoscelesTriangleBase)shapes[i]);
                    }
                    else if (shapes[i] is RegularPolygoneBase)
                    {
                        Rectangle dstBounds = Rectangle.Empty;
                        Geometry.CalcBoundingRectangle(GetPointPositions(Owner, ptPositions.Items.Values), out dstBounds);
                        anchorPointIds = GetRegularPolygonAnchorPoints((RegularPolygoneBase)shapes[i], dstBounds);
                    }
                    else
                    {
                        anchorPointIds = GetShapeAnchorPoints(shapes[i]);
                    }
                    // Now restore positions of the anchor points
                    foreach (ControlPointId id in anchorPointIds)
                    {
                        // Skip connected glue points
                        if (gluePointState == GluePointState.SomeConnected)
                        {
                            if (shapes[i].HasControlPointCapability(id, ControlPointCapabilities.Glue) &&
                                shapes[i].IsConnected(id, null) != ControlPointId.None)
                            {
                                continue;
                            }
                        }
                        RelativePosition relPos;
                        if (ptPositions.Items.TryGetValue(id, out relPos))
                        {
                            Debug.Assert(relPos != RelativePosition.Empty);
                            Point p = Owner.CalculateAbsolutePosition(relPos);
                            Debug.Assert(Geometry.IsValid(p));
                            if (!shapes[i].MoveControlPointTo(id, p.X, p.Y, ResizeModifiers.None))
                            {
                                result = false;
                            }
                        }
                        else
                        {
                            Debug.Fail("Unable to restore controlpoint's position: Control point not found in list of original positions");
                        }
                    }
                }
                boundingRectangleLoose = boundingRectangleTight = Geometry.InvalidRectangle;
            } finally {
                ResumeUpdate();
            }
            return(result);
        }