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();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Called whenever a model element is added to the store.
        /// </summary>
        /// <param name="sender">ViewModelStore</param>
        /// <param name="args">Event Arguments for notification of the creation of new model element.</param>
        private void OnElementAdded(object sender, ElementAddedEventArgs args)
        {
            if (!ModelData.DoSendModelEvents)
            {
                return;
            }

            // update shape mapping (this is required, becauso undo/redo does not trigger events)
            if (args.ModelElement is DiagramHasChildren)
            {
                DiagramHasChildren con = args.ModelElement as DiagramHasChildren;
                if (con != null)
                {
                    NodeShape nodeShape = con.ChildShape;
                    Diagram   diagram   = con.Diagram;

                    if (nodeShape != null && diagram != null)
                    {
                        if (nodeShape.IsDeleted)
                        {
                            return;
                        }

                        diagram.AddToShapeMapping(nodeShape);
                    }
                }
            }
            else if (args.ModelElement is ShapeElementContainsChildShapes)
            {
                ShapeElementContainsChildShapes con = args.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);
                    }
                }
            }
        }
Пример #3
0
        public override void RolePlayerChanged(RolePlayerChangedEventArgs e)
        {
            ShapeElementContainsChildShapes con = e.ElementLink as ShapeElementContainsChildShapes;

            if (con == null)
            {
                return;
            }

            if (e.DomainRole.Id == ShapeElementContainsChildShapes.DomainClassId)
            {
                NodeShape childShape = con.ChildShape;

                NodeShape parentShapeOld = e.OldRolePlayer as NodeShape;
                NodeShape parentShapeNew = e.NewRolePlayer as NodeShape;

                // delete from old parent shape
                if (childShape != null && parentShapeOld != null)
                {
                    if (childShape.IsDeleted)
                    {
                        return;
                    }

                    parentShapeOld.RemoveFromShapeMapping(childShape);
                }

                // add to new parent shape
                if (childShape != null && parentShapeNew != null)
                {
                    if (childShape.IsDeleted)
                    {
                        return;
                    }

                    parentShapeNew.AddToShapeMapping(childShape);

                    if (childShape.IsRelativeChildShape && childShape.MovementBehaviour == ShapeMovementBehaviour.PositionOnEdgeOfParent)
                    {
                        childShape.CorrectLocation();
                    }

                    if (!childShape.IsRelativeChildShape)
                    {
                        childShape.ResizeParentIfRequired();
                    }
                }
            }
        }
Пример #4
0
        public override void ElementDeleted(ElementDeletedEventArgs e)
        {
            base.ElementDeleted(e);

            ShapeElementContainsChildShapes con = e.ModelElement as ShapeElementContainsChildShapes;

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

                if (childShape != null && parentShape != null)
                {
                    parentShape.RemoveFromShapeMapping(childShape);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Called whenever a model element is deleted from the store.
        /// </summary>
        /// <param name="sender">ViewModelStore</param>
        /// <param name="args">Event Arguments for notification of the removal of an ModelElement.</param>
        private void OnElementDeleted(object sender, ElementDeletedEventArgs args)
        {
            if (args.ModelElement is DiagramHasChildren)
            {
                DiagramHasChildren con = args.ModelElement as DiagramHasChildren;
                if (con != null)
                {
                    NodeShape nodeShape = con.ChildShape;
                    Diagram   diagram   = con.Diagram;

                    if (nodeShape != null && diagram != null)
                    {
                        if (nodeShape.Element != null)
                        {
                            diagram.RemoveFromShapeMapping(nodeShape);
                        }
                    }
                }
            }
            else if (args.ModelElement is ShapeElementContainsChildShapes)
            {
                ShapeElementContainsChildShapes con = args.ModelElement as ShapeElementContainsChildShapes;
                if (con != null)
                {
                    NodeShape childShape  = con.ChildShape;
                    NodeShape parentShape = con.ParentShape;

                    if (childShape != null && parentShape != null)
                    {
                        if (childShape.Element != null)
                        {
                            parentShape.RemoveFromShapeMapping(childShape);
                        }
                    }
                }
            }
        }