public void DeleteNodeDoesRemoveTheDependency() { var mgr = new PositionDependenciesManager(GraphView, GraphView.window.Preferences); BinaryOperatorNodeModel operatorModel = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, new Vector2(-100, -100)); IConstantNodeModel intModel = GraphModel.CreateConstantNode("int", typeof(int).GenerateTypeHandle(GraphModel.Stencil), new Vector2(-150, -100)); var edge = GraphModel.CreateEdge(operatorModel.InputPortA, intModel.OutputPort); mgr.AddPositionDependency(edge); mgr.Remove(operatorModel.Guid, intModel.Guid); Assert.That(mgr.GetDependencies(operatorModel), Is.Null); }
public IEnumerator MovingAFloatingNodeMovesConnectedToken([Values] TestingMode mode) { BinaryOperatorNodeModel operatorModel = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, new Vector2(-100, -100)); IConstantNodeModel intModel = GraphModel.CreateConstantNode("int", typeof(int).GenerateTypeHandle(GraphModel.Stencil), new Vector2(-150, -100)); GraphModel.CreateEdge(operatorModel.InputPortA, intModel.OutputPort); yield return(TestMove(mode, mouseDelta: new Vector2(20, 10), movedNodes: new INodeModel[] { operatorModel }, expectedMovedDependencies: new INodeModel[] { intModel } )); }
public IEnumerator MovingAStackMovesStackedNodeConnectedFloatingNode([Values] TestingMode mode) { var stackModel0 = GraphModel.CreateStack(string.Empty, new Vector2(-100, -100)); UnaryOperatorNodeModel unary = stackModel0.CreateStackedNode <UnaryOperatorNodeModel>("postDecr", setup: n => n.kind = UnaryOperatorKind.PostDecrement); BinaryOperatorNodeModel operatorModel = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, new Vector2(-100, -100)); IConstantNodeModel intModel = GraphModel.CreateConstantNode("int", typeof(int).GenerateTypeHandle(GraphModel.Stencil), new Vector2(-150, -100)); GraphModel.CreateEdge(unary.InputPort, operatorModel.OutputPort); GraphModel.CreateEdge(operatorModel.InputPortA, intModel.OutputPort); yield return(TestMove(mode, mouseDelta: new Vector2(20, 10), movedNodes: new INodeModel[] { stackModel0 }, expectedMovedDependencies: new INodeModel[] { operatorModel, intModel } )); }
public IEnumerator PanToNodeChangesViewTransform() { BinaryOperatorNodeModel operatorModel = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, new Vector2(-100, -100)); var stackModel0 = GraphModel.CreateStack("Stack 1", new Vector2(100, -100)); var stackModel1 = GraphModel.CreateStack("Stack 2", new Vector2(100, 100)); GraphModel.CreateEdge(stackModel1.InputPorts[0], stackModel0.OutputPorts[0]); var nodeA = stackModel0.CreateStackedNode <Type0FakeNodeModel>("A"); var nodeB = stackModel0.CreateStackedNode <Type0FakeNodeModel>("B"); Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); GraphView.viewTransformChanged += view => m_Changed = true; yield return(SendPanToNodeAndRefresh(stackModel0)); yield return(SendPanToNodeAndRefresh(stackModel1)); yield return(SendPanToNodeAndRefresh(operatorModel)); yield return(SendPanToNodeAndRefresh(nodeA)); yield return(SendPanToNodeAndRefresh(nodeB)); IEnumerator SendPanToNodeAndRefresh(NodeModel nodeModel) { m_Changed = false; Store.Dispatch(new PanToNodeAction(nodeModel.Guid)); yield return(null); Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); Assert.IsTrue(m_Changed, "ViewTransform didn't change"); Assert.That(GraphView.selection. OfType <IHasGraphElementModel>(). Where(x => x.GraphElementModel is INodeModel n && n.Guid == nodeModel.Guid).Any, () => { var graphViewSelection = String.Join(",", GraphView.selection); return($"Selection doesn't contain {nodeModel} {nodeModel.Title} but {graphViewSelection}"); }); } }
public IEnumerator PanToNodeChangesViewTransform() { BinaryOperatorNodeModel operatorModel = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, new Vector2(-100, -100)); var stackModel0 = GraphModel.CreateStack(string.Empty, new Vector2(100, -100)); var stackModel1 = GraphModel.CreateStack(string.Empty, new Vector2(100, 100)); GraphModel.CreateEdge(stackModel1.InputPorts[0], stackModel0.OutputPorts[0]); var nodeA = stackModel0.CreateStackedNode <Type0FakeNodeModel>("A"); var nodeB = stackModel0.CreateStackedNode <Type0FakeNodeModel>("B"); Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); GraphView.viewTransformChanged += view => m_Changed = true; yield return(SendPanToNodeAndRefresh(stackModel0)); yield return(SendPanToNodeAndRefresh(stackModel1)); yield return(SendPanToNodeAndRefresh(operatorModel)); yield return(SendPanToNodeAndRefresh(nodeA)); yield return(SendPanToNodeAndRefresh(nodeB)); IEnumerator SendPanToNodeAndRefresh(NodeModel nodeModel) { m_Changed = false; Store.Dispatch(new PanToNodeAction(nodeModel.Guid)); yield return(null); Store.Dispatch(new RefreshUIAction(UpdateFlags.All)); yield return(null); Assert.IsTrue(m_Changed); Assert.That(GraphView.selection. OfType <IHasGraphElementModel>(). ToList(). Where(x => ReferenceEquals(x.GraphElementModel, nodeModel)).Any); } }
public void Test_CreateEdgeAction_Itemize(TestingMode testingMode, ItemizeOptions options, ItemizeTestType itemizeTest, Func <VSGraphModel, IHasMainOutputPort> makeNode) { // save initial itemize options VSPreferences pref = ((TestState)m_Store.GetState()).Preferences; ItemizeOptions initialOptions = pref.CurrentItemizeOptions; try { // create int node IHasMainOutputPort node0 = makeNode(GraphModel); // create Addition node BinaryOperatorNodeModel opNode = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero); // enable Itemize depending on the test case var itemizeOptions = ItemizeOptions.Nothing; pref.CurrentItemizeOptions = (itemizeTest == ItemizeTestType.Enabled) ? options : itemizeOptions; // connect int to first input m_Store.Dispatch(new CreateEdgeAction(opNode.InputPortA, node0.OutputPort)); m_Store.Update(); // test how the node reacts to getting connected a second time TestPrereqActionPostreq(testingMode, () => { RefreshReference(ref node0); RefreshReference(ref opNode); var binOp = GraphModel.GetAllNodes().OfType <BinaryOperatorNodeModel>().First(); IPortModel input0 = binOp.InputPortA; IPortModel input1 = binOp.InputPortB; IPortModel binOutput = binOp.OutputPort; Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); Assert.That(input0, Is.ConnectedTo(node0.OutputPort)); Assert.That(input1, Is.Not.ConnectedTo(node0.OutputPort)); Assert.That(binOutput.Connected, Is.False); return(new CreateEdgeAction(input1, node0.OutputPort)); }, () => { RefreshReference(ref node0); RefreshReference(ref opNode); var binOp = GraphModel.GetAllNodes().OfType <BinaryOperatorNodeModel>().First(); IPortModel input0 = binOp.InputPortA; IPortModel input1 = binOp.InputPortB; IPortModel binOutput = binOp.OutputPort; Assert.That(GetEdgeCount(), Is.EqualTo(2)); Assert.That(input0, Is.ConnectedTo(node0.OutputPort)); Assert.That(binOutput.Connected, Is.False); if (itemizeTest == ItemizeTestType.Enabled) { Assert.That(GetNodeCount(), Is.EqualTo(3)); IHasMainOutputPort newNode = GetNode(2) as IHasMainOutputPort; Assert.NotNull(newNode); Assert.That(newNode, Is.TypeOf(node0.GetType())); IPortModel output1 = newNode.OutputPort; Assert.That(input1, Is.ConnectedTo(output1)); } else { Assert.That(GetNodeCount(), Is.EqualTo(2)); } }); } finally { // restore itemize options pref.CurrentItemizeOptions = initialOptions; } }
public static IEnumerable <SyntaxNode> BuildBinaryOperator(this RoslynTranslator translator, BinaryOperatorNodeModel model, IPortModel portModel) { yield return(RoslynBuilder.BinaryOperator(model.kind, translator.BuildPort(model.InputPortA).SingleOrDefault(), translator.BuildPort(model.InputPortB).SingleOrDefault())); }
public static IGraphElement CreateBinaryOperator(this ElementBuilder elementBuilder, IStore store, BinaryOperatorNodeModel model) { var ui = new Node(); ui.Setup(model, store, elementBuilder.GraphView); ui.CustomSearcherHandler = (node, nStore, pos, _) => { SearcherService.ShowEnumValues("Pick a new operator type", typeof(BinaryOperatorKind), pos, (pickedEnum, __) => { if (pickedEnum != null) { ((BinaryOperatorNodeModel)node.NodeModel).Kind = (BinaryOperatorKind)pickedEnum; nStore.Dispatch(new RefreshUIAction(UpdateFlags.GraphTopology)); } }); return(true); }; return(ui); }
public static IEnumerable <SyntaxNode> BuildBinaryOperator(this RoslynEcsTranslator translator, BinaryOperatorNodeModel model, IPortModel portModel) { if (model.kind == BinaryOperatorKind.Equals) { yield return(InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, PredefinedType(Token(SyntaxKind.ObjectKeyword)), IdentifierName("Equals"))) .WithArgumentList( ArgumentList( SeparatedList(new[] { Argument((ExpressionSyntax)translator.BuildPort(model.InputPortA).SingleOrDefault()), Argument((ExpressionSyntax)translator.BuildPort(model.InputPortB).SingleOrDefault()) })))); } else { yield return(RoslynBuilder.BinaryOperator(model.kind, translator.BuildPort(model.InputPortA).SingleOrDefault(), translator.BuildPort(model.InputPortB).SingleOrDefault())); } }
public void MultiplyTypeTests(Type x, Type y, Type expected) { Type inferredType = BinaryOperatorNodeModel.GetOutputTypeFromInputs(BinaryOperatorKind.Multiply, x, y); Assert.That(inferredType, Is.EqualTo(expected)); }
public void CustomBooleanTypeTest(BinaryOperatorKind kind, Type x, Type y, Type expected) { Type inferredType = BinaryOperatorNodeModel.GetOutputTypeFromInputs(kind, x, y); Assert.That(inferredType, Is.EqualTo(expected)); }
public void BooleanTypeTest(BinaryOperatorKind kind, Type x, Type y) { Type inferredType = BinaryOperatorNodeModel.GetOutputTypeFromInputs(kind, x, y); Assert.That(inferredType, Is.EqualTo(typeof(bool))); }
public void IncompleteInputTests(BinaryOperatorKind kind, Type x, Type y, Type expected) { Type inferredType = BinaryOperatorNodeModel.GetOutputTypeFromInputs(kind, x, y); Assert.That(inferredType, Is.EqualTo(expected)); }
public static GraphElement CreateBinaryOperator(this INodeBuilder builder, Store store, BinaryOperatorNodeModel model) { return(new Node(model, store, builder.GraphView) { CustomSearcherHandler = (node, nStore, pos, _) => { SearcherService.ShowEnumValues("Pick a new operator type", typeof(BinaryOperatorKind), pos, (pickedEnum, __) => { if (pickedEnum != null) { ((BinaryOperatorNodeModel)node.model).Kind = (BinaryOperatorKind)pickedEnum; nStore.Dispatch(new RefreshUIAction(UpdateFlags.GraphTopology)); } }); return true; } }); }