/// <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);
        }
Exemplo n.º 2
0
        /// <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());
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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());
        }
Exemplo n.º 8
0
        /// <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);
        }
Exemplo n.º 9
0
        private void GenerateChildren(IGraphNode targetNode, GraphNodePath targetNodePath)
        {
            // Node representing a member with a reference to another object
            if (SourceNode != targetNode && SourceNode.Content.IsReference)
            {
                var objectReference = SourceNode.Content.Reference as ObjectReference;
                // Discard the children of the referenced object if requested by the property provider
                if (objectReference != null && !Owner.PropertiesProvider.ShouldExpandReference(SourceNode.Content as MemberContent, objectReference))
                {
                    return;
                }
            }

            var dictionary = targetNode.Content.Descriptor as DictionaryDescriptor;
            var list       = targetNode.Content.Descriptor as CollectionDescriptor;

            // Node containing a collection of references to other objects
            if (targetNode.Content.IsReference)
            {
                var referenceEnumerable = targetNode.Content.Reference as ReferenceEnumerable;
                if (referenceEnumerable != null)
                {
                    // We create one node per item of the collection, unless requested by the property provide to not expand the reference.
                    foreach (var reference in referenceEnumerable)
                    {
                        // The type might be a boxed primitive type, such as float, if the collection has object as generic argument.
                        // In this case, we must set the actual type to have type converter working, since they usually can't convert
                        // a boxed float to double for example. Otherwise, we don't want to have a node type that is value-dependent.
                        var type       = reference.TargetNode != null && reference.TargetNode.Content.IsPrimitive ? reference.TargetNode.Content.Type : reference.Type;
                        var actualPath = targetNodePath.PushIndex(reference.Index);
                        if (Owner.PropertiesProvider.ShouldExpandReference(SourceNode.Content as MemberContent, reference))
                        {
                            var observableNode = Owner.ObservableViewModelService.ObservableNodeFactory(Owner, null, false, targetNode, targetNodePath, type, reference.Index);
                            AddChild(observableNode);
                            observableNode.Initialize();
                        }
                    }
                }
            }
            // Node containing a dictionary of primitive values
            else if (dictionary != null && targetNode.Content.Value != null)
            {
                // TODO: there is no way to discard items of such collections, without discarding the collection itself. Could this be needed at some point?
                // We create one node per item of the collection.
                foreach (var key in dictionary.GetKeys(targetNode.Content.Value))
                {
                    var index           = new Index(key);
                    var observableChild = Owner.ObservableViewModelService.ObservableNodeFactory(Owner, null, true, targetNode, targetNodePath, dictionary.ValueType, index);
                    AddChild(observableChild);
                    observableChild.Initialize();
                }
            }
            // Node containing a list of primitive values
            else if (list != null && targetNode.Content.Value != null)
            {
                // TODO: there is no way to discard items of such collections, without discarding the collection itself. Could this be needed at some point?
                // We create one node per item of the collection.
                for (int i = 0; i < list.GetCollectionCount(targetNode.Content.Value); ++i)
                {
                    var index           = new Index(i);
                    var observableChild = Owner.ObservableViewModelService.ObservableNodeFactory(Owner, null, true, targetNode, targetNodePath, list.ElementType, index);
                    AddChild(observableChild);
                    observableChild.Initialize();
                }
            }
            // Node containing a single non-reference primitive object
            else
            {
                foreach (var child in targetNode.Children)
                {
                    var memberContent    = (MemberContent)child.Content;
                    var descriptor       = (MemberDescriptorBase)memberContent.Member;
                    var displayAttribute = TypeDescriptorFactory.Default.AttributeRegistry.GetAttribute <DisplayAttribute>(descriptor.MemberInfo);
                    if (displayAttribute == null || displayAttribute.Browsable)
                    {
                        // The path is the source path here - the target path might contain the target resolution that we don't want at that point
                        if (Owner.PropertiesProvider.ShouldConstructMember(memberContent))
                        {
                            var childPath       = targetNodePath.PushMember(child.Name);
                            var observableChild = Owner.ObservableViewModelService.ObservableNodeFactory(Owner, child.Name, child.Content.IsPrimitive, child, childPath, child.Content.Type, Index.Empty);
                            AddChild(observableChild);
                            observableChild.Initialize();
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
        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);
        }