From 056a7c11a32aa12d4329c93e33fd2c5d234cc8d5 Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Wed, 20 Jul 2022 17:34:20 +0100 Subject: [PATCH] Copy Paste Wire Pins - for internal review, Commit may be reverted later - attempts to allow Copy/Paste for Pins (ConnectorPinModel) - working directly inside the Copy() and Paste() methods of DynamoModel --- src/DynamoCore/Models/DynamoModel.cs | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/DynamoCore/Models/DynamoModel.cs b/src/DynamoCore/Models/DynamoModel.cs index a5bdb7c74d4..34495395b37 100644 --- a/src/DynamoCore/Models/DynamoModel.cs +++ b/src/DynamoCore/Models/DynamoModel.cs @@ -2522,7 +2522,12 @@ var el in connector.End != null && connector.End.Owner.IsSelected && !ClipBoard.Contains(connector)); + var pins = + connectors.SelectMany(x => x.ConnectorPinModels); + ClipBoard.AddRange(connectors); + + ClipBoard.AddRange(pins); } } @@ -2574,6 +2579,7 @@ public void Paste(Point2D targetPoint, bool useOffset = true) var nodes = ClipBoard.OfType(); var connectors = ClipBoard.OfType(); var notes = ClipBoard.OfType(); + var pins = ClipBoard.OfType(); // we only want to get groups that either has nested groups // or does not belong to a group here. // We handle creation of nested groups when creating the @@ -2686,7 +2692,35 @@ from c in connectors select ConnectorModel.Make(startNode, endNode, c.Start.Index, c.End.Index); + + var newPins = new List(); + var oldAndNewConnectors = connectors.Zip(newConnectors, (o, n) => new { oldConnector = o, newConnector = n }); + + foreach (var on in oldAndNewConnectors) + { + modelLookup.Add(on.oldConnector.GUID, on.newConnector); + } + + foreach (var pin in pins) + { + ModelBase connectorModel; + var connector = modelLookup.TryGetValue(pin.ConnectorId, out connectorModel) && connectorModel as ConnectorModel != null ? connectorModel as ConnectorModel : null; + if (connector != null) + { + double x = pin.CenterX + shiftX + offset; + double y = pin.CenterY + shiftY + offset; + + var newPin = new ConnectorPinModel(x, y, Guid.NewGuid(), connector.GUID); + + connector.AddPin(newPin); + newPins.Add(newPin); + } + } + createdModels.AddRange(newConnectors); + createdModels.AddRange(newPins); + + newItems = newItems.Concat(newPins); //Grouping depends on the selected node models. //so adding the group after nodes / notes are added to workspace.