internal void AddModelType(Func <Store, BaseConfigurationType> elementFactory, PointD creationPoint)
        {
            using (var t = Store.TransactionManager.BeginTransaction("Add new"))
            {
                var element = elementFactory(Store);

                var model = ModelElement as ConfigurationSectionModel;
                if (model != null)
                {
                    model.ConfigurationElements.Add(element);

                    var shapeType = Type.GetType(element.GetType().FullName + "Shape", false);
                    if (shapeType != null)
                    {
                        var shape = Activator.CreateInstance(shapeType, new object[] { Store, new PropertyAssignment[0] }) as ConfigurationShape;
                        if (shape != null)
                        {
                            shape.ModelElement   = element;
                            shape.AbsoluteBounds = new RectangleD(creationPoint, shape.DefaultSize);

                            NestedChildShapes.Add(shape);

                            t.Commit();
                        }
                    }
                }
            }
        }
Beispiel #2
0
        private void AddElementsToActiveDiagram(List <ModelElement> newElements)
        {
            // TODO: Needs sped up
            int elementCount = newElements.Count;
            List <ShapeElement> newShapes = new List <ShapeElement>();

            using (Transaction t = Store.TransactionManager.BeginTransaction("adding diagram elements"))
            {
                for (int index = 0; index < elementCount; index++)
                {
                    ModelElement newElement = newElements[index];
                    StatusDisplay.Show($"Adding element {index + 1} of {elementCount}");

                    ForceAddShape = true;
                    FixUpAllDiagrams.FixUp(this, newElement);
                    newShapes.Add(newElement.GetFirstShapeElement());
                    ForceAddShape = false;
                }

                t.Commit();
            }

            using (Transaction t = Store.TransactionManager.BeginTransaction("adding diagram links"))
            {
                for (int index = 0; index < elementCount; index++)
                {
                    ModelElement newElement = newElements[index];
                    StatusDisplay.Show($"Linking {index + 1} of {elementCount}");

                    // find all element links that are attached to our element where the ends are in the diagram but the link isn't already in the diagram
                    List <ElementLink> elementLinks = Store.GetAll <ElementLink>()
                                                      .Where(link => link.LinkedElements.Contains(newElement) &&
                                                             link.LinkedElements.All(linkedElement => DisplayedElements.Contains(linkedElement)) &&
                                                             !DisplayedElements.Contains(link))
                                                      .ToList();

                    foreach (ElementLink elementLink in elementLinks)
                    {
                        BinaryLinkShape linkShape = CreateChildShape(elementLink) as BinaryLinkShape;
                        newShapes.Add(linkShape);
                        NestedChildShapes.Add(linkShape);

                        switch (elementLink)
                        {
                        case Association a:
                            linkShape.FromShape = a.Source.GetFirstShapeElement() as NodeShape;
                            linkShape.ToShape   = a.Target.GetFirstShapeElement() as NodeShape;

                            break;

                        case Generalization g:
                            linkShape.FromShape = g.Subclass.GetFirstShapeElement() as NodeShape;
                            linkShape.ToShape   = g.Superclass.GetFirstShapeElement() as NodeShape;

                            break;
                        }
                    }
                }

                AutoLayoutShapeElements(newShapes);
                t.Commit();
            }
        }