Example #1
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);
            }