protected override async Task Invoke(MapDocument document, CommandParameters parameters) { if (_clipboard.Value.CanPaste()) { var content = _clipboard.Value.GetPastedContent(document).ToList(); if (!content.Any()) { return; } using (var psd = new PasteSpecialDialog(new Box(content.Select(x => x.BoundingBox)))) { _translator.Value.Translate(psd); if (psd.ShowDialog() == DialogResult.OK) { var objs = GetPastedContent(document, content, psd); if (objs.Any()) { var op = new Attach(document.Map.Root.ID, objs); await MapDocumentOperation.Perform(document, op); } } } } }
public void OperationsPasteSpecial() { if (!ClipboardManager.CanPaste()) { return; } var content = ClipboardManager.GetPastedContent(_document); if (content == null) { return; } var list = content.ToList(); if (!list.Any()) { return; } var box = new Box(list.Select(x => x.BoundingBox)); using (var psd = new PasteSpecialDialog(box)) { if (psd.ShowDialog() == DialogResult.OK) { var name = "Paste special (" + psd.NumberOfCopies + (psd.NumberOfCopies == 1 ? " copy)" : " copies)"); var action = new PasteSpecial(list, psd.NumberOfCopies, psd.StartPoint, psd.Grouping, psd.AccumulativeOffset, psd.AccumulativeRotation, psd.MakeEntitiesUnique, psd.PrefixEntityNames, psd.EntityNamePrefix); _document.PerformAction(name, action); } } }
private List <IMapObject> GetPastedContent(MapDocument document, List <IMapObject> objectsToPaste, PasteSpecialDialog dialog) { var origin = GetPasteOrigin(document, dialog.StartPoint, objectsToPaste); var objects = new List <IMapObject>(); var grouping = dialog.Grouping; var makeEntitesUnique = dialog.MakeEntitiesUnique; var numCopies = dialog.NumberOfCopies; var offset = dialog.AccumulativeOffset; var rotation = dialog.AccumulativeRotation; if (objectsToPaste.Count == 1) { // Only one object - no need to group. grouping = PasteSpecialDialog.PasteSpecialGrouping.None; } Group allGroup = null; if (grouping == PasteSpecialDialog.PasteSpecialGrouping.All) { // Use one group for all copies allGroup = new Group(document.Map.NumberGenerator.Next("MapObject")); // Add the group to the tree objects.Add(allGroup); } // Get a list of all entity names if needed var names = new List <string>(); if (makeEntitesUnique) { names = document.Map.Root.Find(x => x is Entity) .Select(x => x.Data.GetOne <EntityData>()) .Where(x => x != null && x.Properties.ContainsKey("targetname")) .Select(x => x.Properties["targetname"]) .ToList(); } // Start at i = 1 so the original isn't duped with no offets for (var i = 1; i <= numCopies; i++) { var copyOrigin = origin + (offset * i); var copyRotation = rotation * i; var copy = CreateCopy(document.Map.NumberGenerator, copyOrigin, copyRotation, names, objectsToPaste, makeEntitesUnique, dialog.PrefixEntityNames, dialog.EntityNamePrefix).ToList(); var grouped = GroupCopy(document.Map.NumberGenerator, allGroup, copy, grouping); objects.AddRange(grouped); } return(objects); }