Skip to content

Commit

Permalink
Copy Paste Wire Pins
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
dnenov committed Jul 20, 2022
1 parent 321e3b9 commit 056a7c1
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -2574,6 +2579,7 @@ public void Paste(Point2D targetPoint, bool useOffset = true)
var nodes = ClipBoard.OfType<NodeModel>();
var connectors = ClipBoard.OfType<ConnectorModel>();
var notes = ClipBoard.OfType<NoteModel>();
var pins = ClipBoard.OfType<ConnectorPinModel>();
// 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
Expand Down Expand Up @@ -2686,7 +2692,35 @@ from c in connectors
select
ConnectorModel.Make(startNode, endNode, c.Start.Index, c.End.Index);


var newPins = new List<ConnectorPinModel>();
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.
Expand Down

0 comments on commit 056a7c1

Please sign in to comment.