/// <inheritdoc/> public override GraphNodePath GetNodePath() { var path = new GraphNodePath(Editor.NodeContainer.GetNode(Asset.Asset)); path.PushMember(nameof(EntityHierarchy.Hierarchy)); path.PushTarget(); path.PushMember(nameof(EntityHierarchy.Hierarchy.Parts)); path.PushTarget(); path.PushIndex(new NodeIndex(Id.ObjectId)); path.PushMember(nameof(EntityDesign.Entity)); path.PushTarget(); return(path); }
/// <inheritdoc/> GraphNodePath IAssetPropertyProviderViewModel.GetAbsolutePathToRootNode() { var asset = Method.Editor.Asset.Asset; var path = new GraphNodePath(Method.Editor.Session.AssetNodeContainer.GetNode(asset)); path.PushMember(nameof(VisualScriptAsset.Methods)); path.PushTarget(); path.PushIndex(new NodeIndex(asset.Methods.IndexOf(Method.Method.Method))); path.PushMember(nameof(Scripts.Method.Links)); path.PushTarget(); path.PushIndex(new NodeIndex(link.Id)); path.PushTarget(); return(path); }
/// <summary> /// Retrieves the path of the target node if the given source node content holds a reference or a sequence of references, or the given source node path otherwise. /// </summary> /// <param name="sourceNode">The source node for which to retrieve the target node.</param> /// <param name="index">The index of the target node to retrieve, if the source node contains a sequence of references. <see cref="Index.Empty"/> otherwise.</param> /// <param name="sourceNodePath">The path to the given <paramref name="sourceNode"/>.</param> /// <returns>The path to the corresponding target node if available, or the path to source node itself if it does not contain any reference or if its content should not process references.</returns> /// <remarks>This method can return null if the target node is null.</remarks> protected static GraphNodePath GetTargetNodePath(IGraphNode sourceNode, Index index, GraphNodePath sourceNodePath) { if (sourceNode == null) { throw new ArgumentNullException(nameof(sourceNode)); } if (sourceNodePath == null) { throw new ArgumentNullException(nameof(sourceNodePath)); } var objectReference = sourceNode.Content.Reference as ObjectReference; if (objectReference != null) { return(sourceNodePath.PushTarget()); } var referenceEnumerable = sourceNode.Content.Reference as ReferenceEnumerable; if (referenceEnumerable != null && !index.IsEmpty) { return(sourceNodePath.PushIndex(index)); } return(sourceNodePath.Clone()); }
public void TestPushIndexAndMember() { var obj = new Class { ListMember = { new Class(), new Class(), new Class() } }; var nodeContainer = new NodeContainer(); var rootNode = nodeContainer.GetOrCreateNode(obj); var path = new GraphNodePath(rootNode); path.PushMember(nameof(Class.ListMember)); path.PushTarget(); path.PushIndex(new NodeIndex(1)); path.PushMember(nameof(Class.IntMember)); var targetNode = nodeContainer.GetNode(obj.ListMember[1]); var intNode = targetNode[nameof(Class.IntMember)]; var nodes = new IGraphNode[] { rootNode, rootNode[nameof(Class.ListMember)], rootNode[nameof(Class.ListMember)].Target, targetNode, intNode }; Assert.NotNull(targetNode); Assert.NotNull(intNode); Assert.False(path.IsEmpty); AssertAreEqual(rootNode, path.RootNode); AssertAreEqual(intNode, path.GetNode()); var i = 0; foreach (var node in path) { AssertAreEqual(nodes[i++], node); } AssertAreEqual(nodes.Length, i); }
public void TestPushTarget() { var obj = new Class { ClassMember = new Class() }; var nodeContainer = new NodeContainer(); var rootNode = nodeContainer.GetOrCreateNode(obj); var path = new GraphNodePath(rootNode); path.PushMember(nameof(Class.ClassMember)); path.PushTarget(); var targetNode = nodeContainer.GetNode(obj.ClassMember); var nodes = new IGraphNode[] { rootNode, rootNode[nameof(Class.ClassMember)], targetNode }; Assert.NotNull(targetNode); Assert.False(path.IsEmpty); AssertAreEqual(rootNode, path.RootNode); AssertAreEqual(targetNode, path.GetNode()); var i = 0; foreach (var node in path) { AssertAreEqual(nodes[i++], node); } AssertAreEqual(nodes.Length, i); }
public void TestPushStructMember() { var obj = new Class { StructMember = { StringMember = "aa" } }; var nodeContainer = new NodeContainer(); var rootNode = nodeContainer.GetOrCreateNode(obj); var path = new GraphNodePath(rootNode); path.PushMember(nameof(Class.StructMember)); path.PushTarget(); path.PushMember(nameof(Struct.StringMember)); var structNode = rootNode[nameof(Class.StructMember)]; var targetNode = rootNode[nameof(Class.StructMember)].Target; var memberNode = rootNode[nameof(Class.StructMember)].Target[nameof(Struct.StringMember)]; var nodes = new IGraphNode[] { rootNode, structNode, targetNode, memberNode }; Assert.NotNull(targetNode); Assert.NotNull(memberNode); Assert.False(path.IsEmpty); AssertAreEqual(rootNode, path.RootNode); AssertAreEqual(memberNode, path.GetNode()); var i = 0; foreach (var node in path) { AssertAreEqual(nodes[i++], node); } AssertAreEqual(nodes.Length, i); }
/// <inheritdoc/> public override GraphNodePath GetNodePath() { var path = new GraphNodePath(Editor.NodeContainer.GetNode(Asset.Asset)); path.PushMember(nameof(UIAsset.Hierarchy)); path.PushTarget(); return(path); }
/// <inheritdoc /> protected override GraphNodePath GetNodePath() { var path = new GraphNodePath(Editor.Session.AssetNodeContainer.GetNode(Editor.Asset.Asset)); path.PushMember(nameof(GraphicsCompositorAsset.Cameras)); path.PushTarget(); path.PushIndex(new Index(Editor.Asset.Asset.Cameras.IndexOf(CameraSlot))); return(path); }
/// <inheritdoc /> protected override GraphNodePath GetNodePath() { var path = new GraphNodePath(Editor.Session.AssetNodeContainer.GetNode(Editor.Asset.Asset)); path.PushMember(nameof(GraphicsCompositorAsset.SharedRenderers)); path.PushTarget(); path.PushIndex(new NodeIndex(Editor.Asset.Asset.SharedRenderers.IndexOf(sharedRenderer))); return(path); }
GraphNodePath IAssetPropertyProviderViewModel.GetAbsolutePathToRootNode() { var path = new GraphNodePath(Editor.Session.AssetNodeContainer.GetNode(Editor.Asset.Asset)); path.PushMember(nameof(SpriteSheetAsset.Sprites)); path.PushIndex(new NodeIndex(Index)); path.PushTarget(); return(path); }
public void TestGetParent() { var obj = new Class { StructMember = { StringMember = "aa" }, ClassMember = new Class(), ListMember = { new Class(), new Class(), new Class() } }; var nodeContainer = new NodeContainer(); var rootNode = nodeContainer.GetOrCreateNode(obj); var path = new GraphNodePath(rootNode); path.PushMember(nameof(Class.IntMember)); var parentPath = new GraphNodePath(rootNode); AssertAreEqual(parentPath, path.GetParent()); path = new GraphNodePath(rootNode); path.PushMember(nameof(Class.StructMember)); path.PushMember(nameof(Struct.StringMember)); parentPath = new GraphNodePath(rootNode); parentPath.PushMember(nameof(Class.StructMember)); AssertAreEqual(parentPath, path.GetParent()); path = new GraphNodePath(rootNode); path.PushMember(nameof(Class.ClassMember)); path.PushTarget(); parentPath = new GraphNodePath(rootNode); parentPath.PushMember(nameof(Class.ClassMember)); AssertAreEqual(parentPath, path.GetParent()); path = new GraphNodePath(rootNode); path.PushMember(nameof(Class.ClassMember)); path.PushTarget(); path.PushMember(nameof(Class.IntMember)); parentPath = new GraphNodePath(rootNode); parentPath.PushMember(nameof(Class.ClassMember)); parentPath.PushTarget(); AssertAreEqual(parentPath, path.GetParent()); path = new GraphNodePath(rootNode); path.PushMember(nameof(Class.ListMember)); path.PushIndex(new NodeIndex(1)); parentPath = new GraphNodePath(rootNode); parentPath.PushMember(nameof(Class.ListMember)); AssertAreEqual(parentPath, path.GetParent()); path = new GraphNodePath(rootNode); path.PushMember(nameof(Class.ListMember)); path.PushIndex(new NodeIndex(1)); path.PushMember(nameof(Class.IntMember)); parentPath = new GraphNodePath(rootNode); parentPath.PushMember(nameof(Class.ListMember)); parentPath.PushIndex(new NodeIndex(1)); AssertAreEqual(parentPath, path.GetParent()); }
public void TestSimpleObjectInitialPath() { var nodeContainer = new NodeContainer(); var instance = new SimpleClass { Member1 = 3, Member2 = new SimpleClass() }; var rootNode = nodeContainer.GetOrCreateNode(instance); var container = new SimpleClass { Member2 = instance }; var containerNode = nodeContainer.GetOrCreateNode(container); var initialPath = new GraphNodePath(containerNode); initialPath.PushMember(nameof(SimpleClass.Member2)); initialPath.PushTarget(); var visitor = new TestVisitor(); visitor.Visit(rootNode, null, initialPath); var expectedNodes = new IGraphNode[] { rootNode, rootNode[nameof(SimpleClass.Member1)], rootNode[nameof(SimpleClass.Member2)], rootNode[nameof(SimpleClass.Member2)].Target, rootNode[nameof(SimpleClass.Member2)].Target[nameof(SimpleClass.Member1)], rootNode[nameof(SimpleClass.Member2)].Target[nameof(SimpleClass.Member2)], }; var expectedPaths = new GraphNodePath[6]; expectedPaths[0] = initialPath.Clone(); expectedPaths[1] = initialPath.Clone(); expectedPaths[1].PushMember(nameof(SimpleClass.Member1)); expectedPaths[2] = initialPath.Clone(); expectedPaths[2].PushMember(nameof(SimpleClass.Member2)); expectedPaths[3] = expectedPaths[2].Clone(); expectedPaths[3].PushTarget(); expectedPaths[4] = expectedPaths[3].Clone(); expectedPaths[4].PushMember(nameof(SimpleClass.Member1)); expectedPaths[5] = expectedPaths[3].Clone(); expectedPaths[5].PushMember(nameof(SimpleClass.Member2)); VerifyNodesAndPath(expectedNodes, expectedPaths, visitor); }
public void TestEquals() { // Note: comparing GraphNodePath.GetHashCode() returns true when the root node is equivalent. This is because the root node is the only invariant. var obj = new Class { StructMember = { StringMember = "aa" }, ClassMember = new Class(), ListMember = { new Class(), new Class(), new Class() } }; var nodeContainer = new NodeContainer(); var path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)); path1.PushMember(nameof(Class.IntMember)); var path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)); path2.PushMember(nameof(Class.IntMember)); AssertAreEqual(path1.GetHashCode(), path2.GetHashCode()); AssertAreEqual(path1, path2); path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)); path1.PushMember(nameof(Class.ClassMember)); AssertAreEqual(path1.GetHashCode(), path2.GetHashCode()); AssertAreNotEqual(path1, path2); path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)); path2.PushMember(nameof(Class.ClassMember)); AssertAreEqual(path1.GetHashCode(), path2.GetHashCode()); AssertAreEqual(path1, path2); path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)); path1.PushMember(nameof(Class.ClassMember)); path1.PushTarget(); AssertAreEqual(path1.GetHashCode(), path2.GetHashCode()); AssertAreNotEqual(path1, path2); path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)); path2.PushMember(nameof(Class.ClassMember)); path2.PushTarget(); AssertAreEqual(path1.GetHashCode(), path2.GetHashCode()); AssertAreEqual(path1, path2); path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)); path1.PushMember(nameof(Class.ClassMember)); path1.PushTarget(); path1.PushMember(nameof(Class.IntMember)); AssertAreEqual(path1.GetHashCode(), path2.GetHashCode()); AssertAreNotEqual(path1, path2); path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)); path2.PushMember(nameof(Class.ClassMember)); path2.PushTarget(); path2.PushMember(nameof(Class.IntMember)); AssertAreEqual(path1.GetHashCode(), path2.GetHashCode()); AssertAreEqual(path1, path2); path1 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)); path1.PushMember(nameof(Class.ListMember)); path1.PushIndex(new NodeIndex(0)); AssertAreEqual(path1.GetHashCode(), path2.GetHashCode()); AssertAreNotEqual(path1, path2); path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)); path2.PushMember(nameof(Class.ListMember)); path2.PushIndex(new NodeIndex(0)); AssertAreEqual(path1.GetHashCode(), path2.GetHashCode()); AssertAreEqual(path1, path2); path2 = new GraphNodePath(nodeContainer.GetOrCreateNode(obj)); path2.PushMember(nameof(Class.ListMember)); path2.PushIndex(new NodeIndex(1)); AssertAreEqual(path1.GetHashCode(), path2.GetHashCode()); AssertAreNotEqual(path1, path2); }