Exemple #1
0
        /// <summary>
        /// Called whenever a child element is added to a diagram.
        /// </summary>
        /// <param name="e"></param>
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            base.ElementAdded(e);

            DiagramHasChildren con = e.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);

                    if (nodeShape.Location == PointD.Empty)
                    {
                        nodeShape.SetAtFreePositionOnParent();
                    }
                }
                else
                {
                    con.Delete();
                }
            }
        }
        /// <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);
                    }
                }
            }
        }
Exemple #3
0
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            base.ElementAdded(e);

            DiagramHasLinkShapes con = e.ModelElement as DiagramHasLinkShapes;

            if (con != null)
            {
                LinkShape linkShape = con.LinkShape;
                Diagram   diagram   = con.Diagram;

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

                    if (linkShape.SourceAnchor == null || linkShape.TargetAnchor == null)
                    {
                        throw new InvalidOperationException("LinkShape needs to have from and to anchors.");
                    }

                    if (linkShape.SourceAnchor.FromShape == null || linkShape.TargetAnchor.ToShape == null)
                    {
                        throw new InvalidOperationException("LinkShape anchors need to have from and to shape.");
                    }

                    diagram.AddToShapeMapping(linkShape);

                    if (linkShape.EdgePoints.Count == 0)
                    {
                        linkShape.Layout(FixedGeometryPoints.None);
                    }
                    else
                    {
                        linkShape.UpdateLinkPlacement();

                        if (!con.Store.InSerializationTransaction)
                        {
                            linkShape.Layout(FixedGeometryPoints.SourceAndTarget);
                        }
                    }
                }
            }
        }