Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selective shift + click output connections grabs connectors for selected nodes only #9585

Merged
merged 3 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/DynamoCore/Models/DynamoModelCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,21 +362,31 @@ private void BeginShiftReconnections(Guid nodeId, int portIndex, PortType portTy
PortModel selectedPort = node.OutPorts[portIndex];

var connectorsForDeletion = new List<ModelBase>();
int numOfConnectors = selectedPort.Connectors.Count;

var selectedConnectors = new List<ConnectorModel>();
selectedConnectors = selectedPort.Connectors.Where(x => x.End.Owner.IsSelected).ToList();

// If no connectors are selected, process all of the associated nodes
if (selectedConnectors.Count() <= 0)
{
selectedConnectors = selectedPort.Connectors.ToList();
}

int numOfConnectors = selectedConnectors.Count();
if (numOfConnectors == 0) return;

activeStartPorts = new PortModel[numOfConnectors];

for (int i = 0; i < numOfConnectors; i++)
{
ConnectorModel connector = selectedPort.Connectors[i];
ConnectorModel connector = selectedConnectors[i];
connectorsForDeletion.Add(connector);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connectorsForDeletion seems a dup to me after the refactor? What do you think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's still required as removing it will break undo/redo. Below we call CurrentWorkspace.SaveAndDeleteModels(connectorsForDeletion) where SaveAndDeleteModels() is a method in UndoRedo.cs which is a partial class of the WorkspaceModel. Several new and old recorded tests break as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand before the refactor it is required, but after the refactor, it contains exactly all the connectors in selectedConnectors.
Can we call code below to preserve the undo/redo behavior?

CurrentWorkspace.SaveAndDeleteModels(selectedConnectors);

Copy link
Contributor Author

@alfarok alfarok Mar 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do this:

CurrentWorkspace.SaveAndDeleteModels(selectedConnectors.ToList<ModelBase>());

Since connectorsForDeletion = List<ModelBase> while selectedConnectors = List<ConnectorModel> and ConnectorModel is derived from ModelBase

activeStartPorts[i] = connector.End;
}
CurrentWorkspace.SaveAndDeleteModels(connectorsForDeletion);
for (int i = 0; i < numOfConnectors; i++) //delete the connectors
{
selectedPort.Connectors[0].Delete();
selectedConnectors[i].Delete();
}
return;
}
Expand Down
20 changes: 15 additions & 5 deletions src/DynamoCoreWpf/ViewModels/Core/StateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,23 @@ internal void BeginShiftReconnections(Guid nodeId, int portIndex, PortType portT

PortModel portModel = node.OutPorts[portIndex];
if (portModel.Connectors.Count <= 0) return;

var connectorsAr = new ConnectorViewModel[portModel.Connectors.Count];
for (int i = 0; i < portModel.Connectors.Count; i++)

// Try to obtain connectors for selected nodes
var selected = portModel.Connectors.Where(x => x.End.Owner.IsSelected).Select(y => y.End);

// If there are no selected nodes, obtain all the associated connectors
if (selected.Count() <= 0)
{
var c = new ConnectorViewModel(this, portModel.Connectors[i].End);
selected = portModel.Connectors.Select(y => y.End);
}

var connectorsAr = new ConnectorViewModel[selected.Count()];
for (int i = 0; i < selected.Count(); i++)
{
var c = new ConnectorViewModel(this, selected.ElementAt(i));
connectorsAr[i] = c;
}
}

this.SetActiveConnectors(connectorsAr);
return;
}
Expand Down
109 changes: 109 additions & 0 deletions test/DynamoCoreWpfTests/RecordedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,115 @@ public void TestCtrlClickInputConnectionsUndoRedo()
AssertPreviewValue("5a42348373b94a11920feeaa680834fd", 10);
}

/// <summary>
/// The following recorded test verifies that selecting a subset of nodes
/// and shift-clicking the parent output of these nodes only grabs the
/// connectors from the node that are selected.
/// This is accomplished in the following steps:
/// 1) Start with 2 code blocks with output values of 5 and 10.
/// 2) Create 3 code blocks with variables a, b, c
/// 3) Connnect the initial code block with a value of 5 to a, b, c
/// 3) Select code blocks containing variables a and c
/// 4) Shift click the output of the code block which contains the value of 5
/// 5) This should grab the connectors from only a and c (skipping b as it was not selected)
/// 6) Place these connectors on the code block containing a value of 10
/// 7) Verify a, b, c sums to 25 (a=10, b=5, c=10)
/// </summary>
[Test]
public void TestSelectiveShiftClickOutput()
{
RunCommandsFromFile("SelectiveShiftClickTest_Recording.xml");

// Verify final node and connector state
Assert.AreEqual(7, workspace.Nodes.Count());
Assert.AreEqual(7, workspace.Connectors.Count());

// Value of a
AssertPreviewValue("36a4604aeb684e1ca310a53e4d2c96c3", 10);
// Value of b
AssertPreviewValue("39842043c1894371899c5e1666e596ee", 5);
// Value of c
AssertPreviewValue("96007af3534d4581bca84d053f7ec043", 10);
// Value of a + b + c
AssertPreviewValue("e15ad50a3cd54c3485b482a21c786d46", 25);
}

/// <summary>
/// This test follows very similar logic compared withTestSelectiveShiftClickOutput()
/// but it makes calls an undo command after moving connectors with selective shift click
/// putting the graph back into its original state.
/// </summary>
[Test]
public void TestSelectiveShiftClickdOutputUndo()
{
RunCommandsFromFile("SelectiveShiftClickTestUndo_Recording.xml");

// Verify final node and connector state
Assert.AreEqual(7, workspace.Nodes.Count());
Assert.AreEqual(7, workspace.Connectors.Count());

// Value of a
AssertPreviewValue("9c757fd3c692490d85a13962c52114c8", 5);
// Value of b
AssertPreviewValue("1d45a1ba9d604687a509bd942852c276", 5);
// Value of c
AssertPreviewValue("26125cb52f5b4f289fefdcc0a9356f97", 5);
// Value of a + b + c
AssertPreviewValue("e7b387ded1ca422581eb09c2e2ad0c71", 15);
}

/// <summary>
/// This test follows very similar logic compared withTestSelectiveShiftClickOutput()
/// and TestSelectiveShiftClickdOutputUndo() but conducts undo's back to an empty workspace
/// and redo's back to the final state.
/// </summary>
[Test]
public void TestSelectiveShiftClickdOutputUndoRedo()
{
RunCommandsFromFile("SelectiveShiftClickTestUndoRedo_Recording.xml");

// Verify final node and connector state
Assert.AreEqual(7, workspace.Nodes.Count());
Assert.AreEqual(7, workspace.Connectors.Count());

// Value of a
AssertPreviewValue("6373cf7669a14d43a2f068f86bac30cb", 10);
// Value of b
AssertPreviewValue("ac768f631a2842e19a58c49974077d49", 5);
// Value of c
AssertPreviewValue("a693b9a7fb4648bd905df66394cba26a", 10);
// Value of a + b + c
AssertPreviewValue("4cfa20a57edf42588288f7ef2ed0a1c6", 25);
}

/// <summary>
/// Perform a large series of shift-clicks and ctrl-clicks with and without
/// selected nodes to test these commands in successive combinations
/// while verifying the graph still arrives at specific numeric state.
/// </summary>
[Test]
public void CombinationOfConnectorHotKeys()
{
RunCommandsFromFile("CombinationOfConnectorHotKeys_Recording.xml");

// Verify final node and connector state
Assert.AreEqual(6, workspace.Nodes.Count());
Assert.AreEqual(6, workspace.Connectors.Count());

// Code Block: value of 3
AssertPreviewValue("6f74b47d46e54a69b9de466c347531f0", 3);
// Code Block: value of 6
AssertPreviewValue("46ce4a8fcf354d1aa8f9ff0e7e587105", 6);
// Code Block: value of 9
AssertPreviewValue("6173dd048d5943898ed52e53aed57a00", 9);

// Operation Result #1: 6 + 9
AssertPreviewValue("58c21031df374168a093f9b5eeacade7", 15);
// Operation Result #2: 3 + 6
AssertPreviewValue("f6929752825c4f49b5e9e70947eb8a03", 9);
// Operation Result #3: Result #1 * Result #2
AssertPreviewValue("50964fcc782d418a8ca6bec40e7ad440", 135);
}
#endregion

#region General Node Operations Test Cases
Expand Down
Loading