private bool PasteShapes()
        {
            // Get prototypes from clipboard, if they exist
            IDataObject           dataObject            = Clipboard.GetDataObject();
            ElementGroupPrototype elementGroupPrototype = ElementOperations.GetElementGroupPrototype(ServiceProvider, dataObject);

            // if we're not pasting on the diagram (i.e., the ModelRoot), we're pasting the prototype
            if (TargetElement is ModelRoot &&
                CurrentModelingDocView is EFModelDocView efModelDocView &&
                efModelDocView.Diagram is EFModelDiagram currentDiagram &&
                currentDiagram?.Store != null &&
                elementGroupPrototype != null)
            {
                Store store = efModelDocView.Diagram.Store;

                // get matching elements from the store
                List <ModelElement> modelElements = elementGroupPrototype.ProtoElements
                                                    .Select(p => store.ElementDirectory.FindElement(p.ElementId))
                                                    .Where(e => e != null)
                                                    .ToList();

                if (modelElements.Any())
                {
                    List <ModelClass>   modelClasses   = modelElements.OfType <ModelClass>().ToList();
                    List <Comment>      comments       = modelElements.OfType <Comment>().ToList();
                    List <ModelElement> everythingElse = modelElements.Except(modelClasses).Except(comments).ToList();
                    List <ShapeElement> newShapes      = new List <ShapeElement>();

                    using (Transaction t = store.TransactionManager.BeginTransaction())
                    {
                        // paste classes and comments first to ensure that any possible connector end is present before the connectors arrive
                        newShapes.AddRange(modelClasses.Select(e => EFModelDiagram.AddExistingModelElement(currentDiagram, e)));
                        newShapes.AddRange(comments.Select(e => EFModelDiagram.AddExistingModelElement(currentDiagram, e)));
                        newShapes.AddRange(everythingElse.Select(e => EFModelDiagram.AddExistingModelElement(currentDiagram, e)));
                        newShapes = newShapes.Where(s => s != null).ToList();

                        // if nothing got pasted (because it's already there), we succeeded in our paste but didn't really change
                        // the display, so nothing further needs done
                        if (!newShapes.Any())
                        {
                            return(true);
                        }

                        t.Commit();
                    }

                    using (Transaction t = store.TransactionManager.BeginTransaction())
                    {
                        Commands.LayoutDiagram(currentDiagram, newShapes);
                        t.Commit();
                    }

                    currentDiagram.Invalidate();

                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        private bool PasteShapes(List <ModelElement> modelElements)
        {
            if (TargetElement is ModelRoot &&
                CurrentModelingDocView is EFModelDocView efModelDocView &&
                efModelDocView.Diagram is EFModelDiagram currentDiagram &&
                currentDiagram.Store != null &&
                modelElements.Any())
            {
                Store store = efModelDocView.Diagram.Store;

                List <ModelClass>   modelClasses   = modelElements.OfType <ModelClass>().ToList();
                List <Comment>      comments       = modelElements.OfType <Comment>().ToList();
                List <ModelElement> everythingElse = modelElements.Except(modelClasses).Except(comments).ToList();
                List <ShapeElement> newShapes      = new List <ShapeElement>();

                using (Transaction t = store.TransactionManager.BeginTransaction())
                {
                    // paste classes and comments first to ensure that any possible connector end is present before the connectors arrive
                    newShapes.AddRange(modelClasses.Select(e => EFModelDiagram.AddExistingModelElement(currentDiagram, e)));
                    newShapes.AddRange(comments.Select(e => EFModelDiagram.AddExistingModelElement(currentDiagram, e)));
                    newShapes = newShapes.Where(s => s != null).ToList();

                    // select and show the new or existing shape. Search, in order, classes, comments, then everything else
                    ModelElement firstElement = modelClasses.FirstOrDefault() ?? comments.FirstOrDefault() ?? everythingElse.FirstOrDefault();

                    if (firstElement != null)
                    {
                        currentDiagram.ActiveDiagramView.SelectModelElement(firstElement, true);
                    }

                    // if nothing got pasted (because it's already there), we succeeded in our paste but didn't really change
                    // the display, so nothing further needs done
                    if (!newShapes.Any())
                    {
                        return(false);
                    }

                    t.Commit();
                }

                //using (Transaction t = store.TransactionManager.BeginTransaction())
                //{
                //   Commands.LayoutDiagram(currentDiagram, newShapes);
                //   t.Commit();
                //}
                currentDiagram.Invalidate();

                return(true);
            }

            return(false);
        }
Пример #3
0
        private void ObjectModelBrowser_OnNodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Node is ExplorerTreeNode elementNode && elementNode.RepresentedElement != null)
            {
                ModelElement element = elementNode.RepresentedElement;

                if (ModelingDocData is EFModelDocData docData)
                {
                    Diagram diagram = docData.CurrentDocView?.CurrentDiagram;

                    if (diagram != null && diagram is EFModelDiagram efModelDiagram && !element.LocateInActiveDiagram(true))
                    {
                        EFModelDiagram.AddExistingModelElement(efModelDiagram, element);
                    }
                }
            }
        }