public override void ElementAdded(ElementAddedEventArgs e)
        {
            ShapeElementContainsChildShapes con = e.ModelElement as ShapeElementContainsChildShapes;

            if (con != null)
            {
                NodeShape childShape  = con.ChildShape;
                NodeShape parentShape = con.ParentShape;

                if (childShape != null && parentShape != null)
                {
                    if (childShape.IsDeleted)
                    {
                        return;
                    }
                    if (parentShape.IsDeleted)
                    {
                        return;
                    }

                    parentShape.AddToShapeMapping(childShape);
                    childShape.UpdateAbsoluteLocation();

                    if (childShape.Location == PointD.Empty)
                    {
                        childShape.SetAtFreePositionOnParent();
                    }
                }
                else
                {
                    con.Delete();
                }
            }
        }
Exemplo n.º 2
0
        private static void ProcessNodeShape(NodeShape shapeElement, LinkedElementCollection <NodeShapeInfo> infos)
        {
            // try to find NodeShapeInfo for shape element
            NodeShapeInfo info = null;

            foreach (NodeShapeInfo i in infos)
            {
                if (i.ElementId == shapeElement.Element.Id)
                {
                    info = i;
                    break;
                }
            }

            if (info == null)
            {
                shapeElement.UpdateAbsoluteLocation();
                return;
            }

            shapeElement.Size = info.Size;
            shapeElement.SetLocation(info.RelativeLocation);

            // children
            foreach (NodeShape shape in shapeElement.Children)
            {
                ProcessNodeShape(shape, info.ChildrenInfos);
            }
        }
Exemplo n.º 3
0
        private static void UpdateAbsoluteLocation(NodeShape shapeElement)
        {
            shapeElement.UpdateAbsoluteLocation();

            foreach (NodeShape shape in shapeElement.Children)
            {
                UpdateAbsoluteLocation(shape);
            }
        }
        private static void UpdateAbsoluteLocation(NodeShape shapeElement)
        {
            shapeElement.UpdateAbsoluteLocation();

            foreach (NodeShape shape in shapeElement.Children)
            {
                UpdateAbsoluteLocation(shape);
            }
        }
        private static void ProcessNodeShape(NodeShape shapeElement, LinkedElementCollection<NodeShapeInfo> infos)
        {
            // try to find NodeShapeInfo for shape element
            NodeShapeInfo info = null;
            foreach (NodeShapeInfo i in infos)
            {
                if (i.ElementId == shapeElement.Element.Id)
                {
                    info = i;
                    break;
                }
            }

            if (info == null)
            {
                shapeElement.UpdateAbsoluteLocation();
                return;
            }

            shapeElement.Size = info.Size;
            shapeElement.SetLocation(info.RelativeLocation);

            // children
            foreach (NodeShape shape in shapeElement.Children)
            {
                ProcessNodeShape(shape, info.ChildrenInfos);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// This function corrects the given proposed location if the given child shape is a relative shape and
        /// is only allowed to be placed on the edge of its parent.
        /// </summary>
        /// <param name="placement">Proposed placement.</param>
        /// <param name="parentShape">Parent shape.</param>
        /// <param name="childShape">Child shape.</param>
        /// <param name="proposedLocation">Proposed location.</param>
        /// <remarks>
        /// This function needs to be called withing a modeling transaction.
        /// 
        /// This function assigns new values to Location and PortPlacement if necessary.
        /// </remarks>
        /// <returns>
        /// Location that was assigned to the shape. It might have the same value as the location 
        /// the shape had before calling this function.
        /// </returns>
        public static PointD CorrectPortLocation(PortPlacement placement, NodeShape parentShape, NodeShape childShape, PointD proposedLocation)
        {
            PointD newLocation = proposedLocation;
            RectangleD rectParent = parentShape.Bounds;

            switch (placement)
            {
                case PortPlacement.Left:
                    newLocation.X = -childShape.Size.Width / 2.0;
                    if (newLocation.Y < 0.0)
                        newLocation.Y = 0.0;
                    else if (newLocation.Y > (rectParent.Height - childShape.Size.Height))
                        newLocation.Y = rectParent.Height - childShape.Size.Height;
                    break;

                case PortPlacement.Top:
                    newLocation.Y = -childShape.Size.Height / 2.0;
                    if (newLocation.X < 0.0)
                        newLocation.X = 0.0;
                    else if (newLocation.X > (rectParent.Width - childShape.Size.Width))
                        newLocation.X = rectParent.Width - childShape.Size.Width;
                    break;

                case PortPlacement.Right:
                    newLocation.X = rectParent.Width - (childShape.Size.Width / 2.0);
                    if (newLocation.Y < 0.0)
                        newLocation.Y = 0.0;
                    else if (newLocation.Y > (rectParent.Height - childShape.Size.Height))
                        newLocation.Y = rectParent.Height - childShape.Size.Height;
                    break;

                case PortPlacement.Bottom:
                    newLocation.Y = rectParent.Height - (childShape.Size.Height / 2.0);
                    if (newLocation.X < 0.0)
                        newLocation.X = 0.0;
                    else if (newLocation.X > (rectParent.Width - childShape.Size.Width))
                        newLocation.X = rectParent.Width - childShape.Size.Width;
                    break;
            }

            if (childShape.Location != newLocation)
            {
                childShape.Location = newLocation;
                childShape.PlacementSide = placement;
                childShape.UpdateAbsoluteLocation();
            }

            return newLocation;
        }
Exemplo n.º 7
0
        /// <summary>
        /// This function corrects the given proposed location if the given child shape is a relative shape and
        /// is only allowed to be placed on the edge of its parent.
        /// </summary>
        /// <param name="placement">Proposed placement.</param>
        /// <param name="parentShape">Parent shape.</param>
        /// <param name="childShape">Child shape.</param>
        /// <param name="proposedLocation">Proposed location.</param>
        /// <remarks>
        /// This function needs to be called withing a modeling transaction.
        ///
        /// This function assigns new values to Location and PortPlacement if necessary.
        /// </remarks>
        /// <returns>
        /// Location that was assigned to the shape. It might have the same value as the location
        /// the shape had before calling this function.
        /// </returns>
        public static PointD CorrectPortLocation(PortPlacement placement, NodeShape parentShape, NodeShape childShape, PointD proposedLocation)
        {
            PointD     newLocation = proposedLocation;
            RectangleD rectParent  = parentShape.Bounds;

            switch (placement)
            {
            case PortPlacement.Left:
                newLocation.X = -childShape.Size.Width / 2.0;
                if (newLocation.Y < 0.0)
                {
                    newLocation.Y = 0.0;
                }
                else if (newLocation.Y > (rectParent.Height - childShape.Size.Height))
                {
                    newLocation.Y = rectParent.Height - childShape.Size.Height;
                }
                break;

            case PortPlacement.Top:
                newLocation.Y = -childShape.Size.Height / 2.0;
                if (newLocation.X < 0.0)
                {
                    newLocation.X = 0.0;
                }
                else if (newLocation.X > (rectParent.Width - childShape.Size.Width))
                {
                    newLocation.X = rectParent.Width - childShape.Size.Width;
                }
                break;

            case PortPlacement.Right:
                newLocation.X = rectParent.Width - (childShape.Size.Width / 2.0);
                if (newLocation.Y < 0.0)
                {
                    newLocation.Y = 0.0;
                }
                else if (newLocation.Y > (rectParent.Height - childShape.Size.Height))
                {
                    newLocation.Y = rectParent.Height - childShape.Size.Height;
                }
                break;

            case PortPlacement.Bottom:
                newLocation.Y = rectParent.Height - (childShape.Size.Height / 2.0);
                if (newLocation.X < 0.0)
                {
                    newLocation.X = 0.0;
                }
                else if (newLocation.X > (rectParent.Width - childShape.Size.Width))
                {
                    newLocation.X = rectParent.Width - childShape.Size.Width;
                }
                break;
            }

            if (childShape.Location != newLocation)
            {
                childShape.Location      = newLocation;
                childShape.PlacementSide = placement;
                childShape.UpdateAbsoluteLocation();
            }

            return(newLocation);
        }