Example #1
0
        private static GraphReference New(GraphPointer model)
        {
            var reference = new GraphReference();

            reference.CopyFrom(model);
            return(reference);
        }
Example #2
0
        public static void OpenTab(GraphReference reference)
        {
            var tab = CreateInstance <GraphWindow>();

            tab.reference = reference;
            tab.Show();
        }
Example #3
0
 private void OnButtonGUI(Rect sourcePosition)
 {
     if (GUI.Button(sourcePosition, "Edit Graph"))
     {
         GraphWindow.OpenActive(GraphReference.New((IMacro)metadata.value, true));
     }
 }
        // To minimize the amount of implementation needed, and simplify inversion of control,
        // we provide instantiation routines that fit most types of elements in the right order and
        // we provide implemented defaults for interfaces that the element could implement.
        // Normally, an element shouldn't have to override instantiate or uninstantiate directly.

        public virtual void Instantiate(GraphReference instance)
        {
            // Create the data for this graph, non-recursively, that is
            // required for the nest instantiation, so we do it first.
            if (this is IGraphElementWithData withData)
            {
                instance.data.CreateElementData(withData);
            }

            // Nest instantiation is a recursive operation that will
            // call Instantiate on descendant graphs and elements.
            // Because event listening will descend graph data recursively,
            // we need to create it before.
            if (this is IGraphNesterElement nester && nester.nest.graph != null)
            {
                GraphInstances.Instantiate(instance.ChildReference(nester, true));
            }

            // StartListening is a recursive operation that will
            // descend graphs recursively. It must be called after
            // instantiation of all child graphs because it will require
            // their data. The drawback with this approach is that it will be
            // called at each step bubbling up, whereas it will only
            // effectively trigger once we reach the top level.
            // Traversal is currently O(n!) where n is the number of descendants,
            // ideally it would be O(n) if only triggered from the root.

            // => Listening has to be implemented by Bolt classes, because Graphs isn't aware of the event system
        }
Example #5
0
        public virtual void Uninstantiate(GraphReference instance)
        {
            // Debug.Log($"Uninstantiating graph {instance}");

            foreach (var element in elements)
            {
                element.Uninstantiate(instance);
            }
        }
Example #6
0
        protected GraphContext(GraphReference reference)
        {
            Ensure.That(nameof(reference)).IsNotNull(reference);
            Ensure.That(nameof(reference.graph)).IsOfType <TGraph>(reference.graph);

            this.reference = reference;

            analyserProvider = new AnalyserProvider(reference);
            graphMetadata    = Metadata.Root().StaticObject(reference.graph);
            extensions       = this.Extensions().ToList().AsReadOnly();
            sidebarPanels    = SidebarPanels().ToList().AsReadOnly();
        }
        public static void Uninstantiate(GraphReference instance)
        {
            lock (@lock)
            {
                instance.graph.Uninstantiate(instance);

                if (!byGraph.TryGetValue(instance.graph, out var instancesWithGraph))
                {
                    throw new InvalidOperationException("Graph instance not found via graph.");
                }

                if (instancesWithGraph.Remove(instance))
                {
                    // Debug.Log($"Removed graph instance mapping:\n{instance.graph} => {instance}");

                    // Free the key references for GC collection
                    if (instancesWithGraph.Count == 0)
                    {
                        byGraph.Remove(instance.graph);
                    }
                }
                else
                {
                    Debug.LogWarning($"Could not find graph instance mapping to remove:\n{instance.graph} => {instance}");
                }

                if (!byParent.TryGetValue(instance.parent, out var instancesWithParent))
                {
                    throw new InvalidOperationException("Graph instance not found via parent.");
                }

                if (instancesWithParent.Remove(instance))
                {
                    // Debug.Log($"Removed parent instance mapping:\n{instance.parent.ToSafeString()} => {instance}");

                    // Free the key references for GC collection
                    if (instancesWithParent.Count == 0)
                    {
                        byParent.Remove(instance.parent);
                    }
                }
                else
                {
                    Debug.LogWarning($"Could not find parent instance mapping to remove:\n{instance.parent.ToSafeString()} => {instance}");
                }

                // It's important to only free the graph data after
                // dissociating the instance mapping, because the data
                // is used as part of the equality comparison for pointers
                instance.FreeGraphData();
            }
        }
Example #8
0
        public static GraphReference New(IGraphRoot root, bool ensureValid)
        {
            if (!ensureValid && !IsValidRoot(root))
            {
                return(null);
            }

            var reference = new GraphReference();

            reference.Initialize(root);
            reference.Hash();
            return(reference);
        }
Example #9
0
        public static GraphReference New(IGraphRoot root, IEnumerable <IGraphParentElement> parentElements, bool ensureValid)
        {
            if (!ensureValid && !IsValidRoot(root))
            {
                return(null);
            }

            var reference = new GraphReference();

            reference.Initialize(root, parentElements, ensureValid);
            reference.Hash();
            return(reference);
        }
Example #10
0
        public static GraphReference New(UnityObject rootObject, IEnumerable <Guid> parentElementGuids, bool ensureValid)
        {
            if (!ensureValid && !IsValidRoot(rootObject))
            {
                return(null);
            }

            var reference = new GraphReference();

            reference.Initialize(rootObject, parentElementGuids, ensureValid);
            reference.Hash();
            return(reference);
        }
Example #11
0
 public static void OpenActive(GraphReference reference)
 {
     if (active == null)
     {
         active           = GetWindow <GraphWindow>();
         active.reference = reference;
         active.Show();
     }
     else
     {
         active.reference = reference;
         active.Focus();
     }
 }
        public virtual void Uninstantiate(GraphReference instance)
        {
            // See above comments, in reverse order.

            if (this is IGraphNesterElement nester && nester.nest.graph != null)
            {
                GraphInstances.Uninstantiate(instance.ChildReference(nester, true));
            }

            if (this is IGraphElementWithData withData)
            {
                instance.data.FreeElementData(withData);
            }
        }
        public static void Instantiate(GraphReference instance)
        {
            lock (@lock)
            {
                Ensure.That(nameof(instance)).IsNotNull(instance);

                instance.CreateGraphData();

                instance.graph.Instantiate(instance);

                if (!byGraph.TryGetValue(instance.graph, out var instancesWithGraph))
                {
                    instancesWithGraph = new HashSet <GraphReference>();
                    byGraph.Add(instance.graph, instancesWithGraph);
                }

                if (instancesWithGraph.Add(instance))
                {
                    // Debug.Log($"Added graph instance mapping:\n{instance.graph} => {instance}");
                }
                else
                {
                    Debug.LogWarning($"Attempting to add duplicate graph instance mapping:\n{instance.graph} => {instance}");
                }

                if (!byParent.TryGetValue(instance.parent, out var instancesWithParent))
                {
                    instancesWithParent = new HashSet <GraphReference>();
                    byParent.Add(instance.parent, instancesWithParent);
                }

                if (instancesWithParent.Add(instance))
                {
                    // Debug.Log($"Added parent instance mapping:\n{instance.parent.ToSafeString()} => {instance}");
                }
                else
                {
                    Debug.LogWarning($"Attempting to add duplicate parent instance mapping:\n{instance.parent.ToSafeString()} => {instance}");
                }
            }
        }
        private static bool HandledIn(this Exception ex, GraphReference reference)
        {
            Ensure.That(nameof(ex)).IsNotNull(ex);

            if (!ex.Data.Contains(handledKey))
            {
                ex.Data.Add(handledKey, new HashSet <GraphReference>());
            }

            var handled = (HashSet <GraphReference>)ex.Data[handledKey];

            if (handled.Contains(reference))
            {
                return(true);
            }
            else
            {
                handled.Add(reference);
                return(false);
            }
        }
Example #15
0
 public GraphReference ToReference()
 {
     return(GraphReference.Intern(this));
 }
 public GraphReference ToReference(bool ensureValid)
 {
     return(GraphReference.New(EditorUtility.InstanceIDToObject(rootObjectInstanceID), parentElementGuids, ensureValid));
 }
Example #17
0
 public static T Context <T>(this GraphReference reference) where T : IGraphContext
 {
     return(GraphContextProvider.instance.GetDecorator <T>(reference));
 }
Example #18
0
 public AnalyserProvider(GraphReference reference)
 {
     this.reference = reference;
 }
Example #19
0
 public static TAnalyser Analyser <TAnalyser>(this object target, GraphReference reference) where TAnalyser : IAnalyser
 {
     return(target.Analyser <TAnalyser>(reference.Context()));
 }
Example #20
0
 public static IAnalysis Analysis(this object target, GraphReference reference)
 {
     return(target.Analysis(reference.Context()));
 }
Example #21
0
 public static TAnalysis Analysis <TAnalysis>(this object target, GraphReference reference) where TAnalysis : IAnalysis
 {
     return(target.Analysis <TAnalysis>(reference.Context()));
 }
Example #22
0
 public static IGraphContext Context(this GraphReference reference)
 {
     return(GraphContextProvider.instance.GetDecorator(reference));
 }