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();
                }
            }
        }
Exemple #2
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();
                }
            }
        }
Exemple #3
0
            /// <summary>
            /// Adds shapes for a given element.
            /// </summary>
            /// <param name="parent">Model element.</param>
            /// <param name="child"></param>
            internal void AddShapesForElement(DomainModelElement parent, DomainModelElement child)
            {
                if (parent == null || child == null)
                {
                    return;
                }

                DiagramDomainDataDirectory data    = child.Store.DomainDataAdvDirectory.ResolveExtensionDirectory <DiagramDomainDataDirectory>();
                IDomainModelServices       topMost = child.GetDomainModelServices().TopMostService;

                // find parent shapes
                List <Guid> shapeIds = DiagramsShapeStore.GetFromStore(parent.Id);

                if (shapeIds != null)
                {
                    foreach (Guid shapeId in shapeIds)
                    {
                        // see if each parent shape has a child shape already added to it
                        NodeShape parentShape = child.Store.ElementDirectory.FindElement(shapeId) as NodeShape;
                        if (parentShape == null)
                        {
                            continue;
                        }

                        foreach (Guid elementShapeId in data.GetShapeTypesForElement(child.GetDomainClassId(), parentShape.GetDomainClassId()))
                        {
                            if (!DiagramHelper.IsElementDisplayedOn(parentShape, elementShapeId, child.Id))
                            {
                                NodeShape shape = topMost.ShapeProvider.CreateShapeForElement(elementShapeId, child) as NodeShape;
                                if (shape.IsRelativeChildShape)
                                {
                                    parentShape.AddRelativeChild(shape);
                                }
                                else
                                {
                                    parentShape.AddNestedChild(shape);
                                }
                                shape.SetAtFreePositionOnParent();
                            }
                        }
                    }
                }

                //AddRootShapesForElement(child, false);
                AddRootShapesForElement(child);
            }