Skip to content

Commit

Permalink
Dyn5272 (#13334) (#13335)
Browse files Browse the repository at this point in the history
tests pass - merging this then will send cherry pick
  • Loading branch information
mjkkirschner authored Sep 23, 2022
1 parent 83e57d1 commit bfdb43d
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Engine/ProtoScript/Runners/LiveRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,26 @@ private List<AssociativeNode> GetModifiedNodes(Subtree subtree, bool redefinitio
// It can then be handled normally regardless of its ForceExecution state
subtree.ForceExecution = false;

//Check if the subtree (ie a node in graph) is an input and has primitive Right hand Node type
if (redefinitionAllowed && st.IsInput && node is BinaryExpressionNode bne && CoreUtils.IsPrimitiveASTNode(bne.RightNode))
//search the cached subtree(node's asts) for a binary expression containing a matching LHS identifer node.
//we can currently only apply input optimizations if the previous assignment was also from a primitive.
BinaryExpressionNode prevBNE = null;
var bne = node as BinaryExpressionNode;
if (bne != null){
foreach (var prevNode in st.AstNodes)
{
if(prevNode is BinaryExpressionNode PrevNodeBNE && PrevNodeBNE.LeftNode is IdentifierNode prevId &&
bne.LeftNode is IdentifierNode curId && prevId.Value == curId.Value)
{
prevBNE = PrevNodeBNE;
break;
}
}
}

//Check if the subtree (ie a node in graph) is an input and has primitive Right hand Node type, also
//ensure that the previous RHS of this assignment was a primitive value, or we'll have generated incorrect instructions.
if (redefinitionAllowed && st.IsInput && bne != null && CoreUtils.IsPrimitiveASTNode(bne.RightNode)
&& (prevBNE == null || CoreUtils.IsPrimitiveASTNode(prevBNE.RightNode)))
{
// An input node is not re-compiled and executed
// It is handled by the ChangeSetApply by re-executing the modified node with the updated changes
Expand Down
48 changes: 48 additions & 0 deletions test/DynamoCoreWpfTests/NodeExecutionUITest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Collections.Generic;
using CoreNodeModels.Input;
using DesignScript.Builtin;
using Dynamo.Graph.Nodes;
Expand All @@ -10,12 +11,21 @@
using CoreNodeModelsWpf;
using NUnit.Framework;
using ProtoCore.Namespace;
using TestUINodes;

namespace DynamoCoreWpfTests
{
[TestFixture]
public class NodeExecutionUITest : DynamoViewModelUnitTest
{
protected override void GetLibrariesToPreload(List<string> libraries)
{
libraries.Add("DesignScriptBuiltin.dll");
libraries.Add("DSCoreNodes.dll");

base.GetLibrariesToPreload(libraries);
}

//case 1 : Node in Freeze and Not execute state. True for all parent nodes.
[Test]
[Category("DynamoUI")]
Expand Down Expand Up @@ -280,5 +290,43 @@ public void TestCustomSelectionNodeUpdate()

AssertPreviewValue(cdn.GUID.ToString(), 2);
}

[Test]
public void TestSelectionNodeUpdate()
{
var model = GetModel();
var tsn = new TestSelectionNode2();

tsn.UpdateSelection(new List<int> { 1, 2, 3 });
var command = new DynamoModel.CreateNodeCommand(tsn, 0, 0, true, false);
model.ExecuteCommand(command);

AssertPreviewValue(tsn.GUID.ToString(), 3);

tsn.ClearSelections();

AssertPreviewValue(tsn.GUID.ToString(), 0);
}
[Test]
public void TestSelectionNodeUpdate2()
{
var model = GetModel();
var tsn = new TestSelectionNode2();

tsn.UpdateSelection(new List<int> { 1, 2, 3 });
var command = new DynamoModel.CreateNodeCommand(tsn, 0, 0, true, false);
model.ExecuteCommand(command);
AssertPreviewValue(tsn.GUID.ToString(), 3);

tsn.ClearSelections();
AssertPreviewValue(tsn.GUID.ToString(), 0);

tsn.UpdateSelection(new List<int> { 2, 4, 6,8 });
AssertPreviewValue(tsn.GUID.ToString(), 4);

tsn.ClearSelections();
AssertPreviewValue(tsn.GUID.ToString(), 0);

}
}
}
60 changes: 60 additions & 0 deletions test/TestUINodes/TestUINodes.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Drawing;
using Autodesk.DesignScript.Runtime;
using Dynamo.Graph.Nodes;
using CoreNodeModels;
using Newtonsoft.Json;
using ProtoCore.AST.AssociativeAST;
using DSCore.IO;
using System.Linq;

namespace TestUINodes
{
Expand Down Expand Up @@ -80,4 +83,61 @@ public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode
};
}
}

[NodeName("Test Selection Node2")]
[NodeCategory("TestUINodes")]
[NodeDescription("A test selection node.")]
[OutPortTypes("var")]
[IsDesignScriptCompatible]
[IsVisibleInDynamoLibrary(false)]
public class TestSelectionNode2 : SelectionBase<int, int>
{
public TestSelectionNode2() : base(
SelectionType.One,
SelectionObjectType.None,
"message",
"prefix")
{
}

public override IModelSelectionHelper<int> SelectionHelper => throw new NotImplementedException();

public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
{
AssociativeNode node;
Func<IList, int> func = DSCore.List.Count;

var results = SelectionResults.ToList();

if (SelectionResults == null || !results.Any())
{
node = AstFactory.BuildNullNode();
}
else
{
node = AstFactory.BuildFunctionCall(func,
new List<AssociativeNode> { AstFactory.BuildExprList(SelectionResults.Select(i => AstFactory.BuildIntNode((long)i) as AssociativeNode).ToList()) });
}

return new[]
{
AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node)
};
}

protected override IEnumerable<int> ExtractSelectionResults(int selections)
{
return new List<int> { selections };
}

protected override string GetIdentifierFromModelObject(int modelObject)
{
return modelObject.ToString();
}

protected override int GetModelObjectFromIdentifer(string id)
{
return id.Length;
}
}
}

0 comments on commit bfdb43d

Please sign in to comment.