Пример #1
0
        public void Initialize(BaseGraphView owner, BaseNode node)
        {
            nodeTarget = node;
            this.owner = owner;

            owner.computeOrderUpdated += ComputeOrderUpdatedCallback;
            node.onMessageAdded       += AddMessageView;
            node.onMessageRemoved     += RemoveMessageView;
            node.onPortsUpdated       += UpdatePortsForField;

            styleSheets.Add(Resources.Load <StyleSheet>(baseNodeStyle));

            if (!string.IsNullOrEmpty(node.layoutStyle))
            {
                styleSheets.Add(Resources.Load <StyleSheet>(node.layoutStyle));
            }

            InitializePorts();
            InitializeView();
            // InitializeDebug();
            ComputeOrderUpdatedCallback();

            ExceptionToLog.Call(() => Enable());

            InitializeSettings();

            RefreshExpandedState();

            this.RefreshPorts();

            RegisterCallback <GeometryChangedEvent>(OnGeometryChanged);
            OnGeometryChanged(null);
        }
Пример #2
0
        // called by the BaseGraph when the node is added to the graph
        public void Initialize(BaseGraph graph)
        {
            this.graph = graph;

            ExceptionToLog.Call(() => Enable());

            InitializePorts();
        }
Пример #3
0
        internal void DisableInternal()
        {
            // port containers are initialized in the OnEnable
            inputPorts.Clear();
            outputPorts.Clear();

            ExceptionToLog.Call(() => Disable());
        }
Пример #4
0
        GraphViewChange GraphViewChangedCallback(GraphViewChange changes)
        {
            if (changes.elementsToRemove != null)
            {
                RegisterCompleteObjectUndo("Remove Graph Elements");

                // Destroy priority of objects
                // We need nodes to be destroyed first because we can have a destroy operation that uses node connections
                changes.elementsToRemove.Sort((e1, e2) => {
                    int GetPriority(GraphElement e)
                    {
                        if (e is BaseNodeView)
                        {
                            return(0);
                        }
                        else
                        {
                            return(1);
                        }
                    }
                    return(GetPriority(e1).CompareTo(GetPriority(e2)));
                });

                //Handle ourselves the edge and node remove
                changes.elementsToRemove.RemoveAll(e => {
                    switch (e)
                    {
                    case EdgeView edge:
                        Disconnect(edge);
                        return(true);

                    case BaseNodeView nodeView:
                        ExceptionToLog.Call(() => nodeView.OnRemoved());
                        graph.RemoveNode(nodeView.nodeTarget);
                        RemoveElement(nodeView);
                        return(true);

                    case GroupView group:
                        graph.RemoveGroup(group.group);
                        RemoveElement(group);
                        return(true);

                    case ExposedParameterFieldView blackboardField:
                        graph.RemoveExposedParameter(blackboardField.parameter);
                        return(true);

                    case BaseStackNodeView stackNodeView:
                        graph.RemoveStackNode(stackNodeView.stackNode);
                        RemoveElement(stackNodeView);
                        return(true);
                    }
                    return(false);
                });
            }

            return(changes);
        }
Пример #5
0
        public void OnProcess()
        {
            inputPorts.PullDatas();

            ExceptionToLog.Call(() => Process());

            InvokeOnProcessed();

            outputPorts.PushDatas();
        }
Пример #6
0
        // called by the BaseGraph when the node is added to the graph
        public void Initialize(BaseGraph graph)
        {
            this.graph = graph;

            ExceptionToLog.Call(() => Enable());
            inputPorts  = new NodeInputPortContainer(this);
            outputPorts = new NodeOutputPortContainer(this);
            nodeFields  = new Dictionary <string, NodeFieldInformation>();
            customPortTypeBehaviorMap = new Dictionary <Type, CustomPortTypeBehaviorDelegate>();

            InitializeInOutDatas();
            InitializePorts();
        }
Пример #7
0
        public void Initialize(BaseGraphView owner, BaseNode node)
        {
            nodeTarget = node;
            this.owner = owner;

            if (!node.deletable)
            {
                capabilities &= ~Capabilities.Deletable;
            }
            // Note that the Renamable capability is useless right now as it haven't been implemented in Graphview
            if (node.isRenamable)
            {
                capabilities |= Capabilities.Renamable;
            }

            owner.computeOrderUpdated += ComputeOrderUpdatedCallback;
            node.onMessageAdded       += AddMessageView;
            node.onMessageRemoved     += RemoveMessageView;
            node.onPortsUpdated       += a => schedule.Execute(_ => UpdatePortsForField(a)).ExecuteLater(0);

            styleSheets.Add(Resources.Load <StyleSheet>(baseNodeStyle));

            if (!string.IsNullOrEmpty(node.layoutStyle))
            {
                styleSheets.Add(Resources.Load <StyleSheet>(node.layoutStyle));
            }

            InitializeView();
            InitializePorts();
            InitializeDebug();

            // If the standard Enable method is still overwritten, we call it
            if (GetType().GetMethod(nameof(Enable), new Type[] {}).DeclaringType != typeof(BaseNodeView))
            {
                ExceptionToLog.Call(() => Enable());
            }
            else
            {
                ExceptionToLog.Call(() => Enable(false));
            }

            InitializeSettings();

            RefreshExpandedState();

            this.RefreshPorts();

            RegisterCallback <GeometryChangedEvent>(OnGeometryChanged);
            RegisterCallback <DetachFromPanelEvent>(e => ExceptionToLog.Call(Disable));
            OnGeometryChanged(null);
        }
Пример #8
0
        public BaseNodeView AddNode(BaseNode node)
        {
            // This will initialize the node using the graph instance
            graph.AddNode(node);

            var view = AddNodeView(node);

            // Call create after the node have been initialized
            ExceptionToLog.Call(() => view.OnCreated());

            UpdateComputeOrder();

            return(view);
        }
Пример #9
0
        /// <summary>
        /// Creates a node of type nodeType at a certain position
        /// </summary>
        /// <param name="position">position in the graph in pixels</param>
        /// <typeparam name="nodeType">type of the node</typeparam>
        /// <returns>the node instance</returns>
        public static BaseNode CreateFromType(Type nodeType, Vector2 position)
        {
            if (!nodeType.IsSubclassOf(typeof(BaseNode)))
            {
                return(null);
            }

            var node = Activator.CreateInstance(nodeType) as BaseNode;

            node.position = new Rect(position, new Vector2(100, 100));

            ExceptionToLog.Call(() => node.OnNodeCreated());

            return(node);
        }
Пример #10
0
        public void Initialize(BaseGraphView owner, BaseNode node)
        {
            nodeTarget = node;
            this.owner = owner;

            if (!node.deletable)
            {
                capabilities &= ~Capabilities.Deletable;
            }

            owner.computeOrderUpdated += ComputeOrderUpdatedCallback;
            node.onMessageAdded       += AddMessageView;
            node.onMessageRemoved     += RemoveMessageView;
            node.onPortsUpdated       += UpdatePortsForField;

            styleSheets.Add(Resources.Load <StyleSheet>(baseNodeStyle));

            if (!string.IsNullOrEmpty(node.layoutStyle))
            {
                styleSheets.Add(Resources.Load <StyleSheet>(node.layoutStyle));
            }

            InitializePorts();
            InitializeView();
            InitializeDebug();

            // If the standard Enable method is still overwritten, we call it
            if (GetType().GetMethod(nameof(Enable), new Type[] {}).DeclaringType != typeof(BaseNodeView))
            {
                ExceptionToLog.Call(() => Enable());
            }
            else
            {
                ExceptionToLog.Call(() => Enable(false));
            }

            InitializeSettings();

            RefreshExpandedState();

            this.RefreshPorts();

            RegisterCallback <GeometryChangedEvent>(OnGeometryChanged);
            OnGeometryChanged(null);
        }
Пример #11
0
        GraphViewChange GraphViewChangedCallback(GraphViewChange changes)
        {
            if (changes.elementsToRemove != null)
            {
                RegisterCompleteObjectUndo("Remove Graph Elements");

                //Handle ourselves the edge and node remove
                changes.elementsToRemove.RemoveAll(e => {
                    switch (e)
                    {
                    case EdgeView edge:
                        Disconnect(edge);
                        return(true);

                    case BaseNodeView node:
                        ExceptionToLog.Call(() => node.OnRemoved());
                        graph.RemoveNode(node.nodeTarget);
                        RemoveElement(node);
                        UpdateNodeInspectorSelection();
                        return(true);

                    case GroupView group:
                        graph.RemoveGroup(group.group);
                        RemoveElement(group);
                        return(true);

                    case ExposedParameterFieldView blackboardField:
                        graph.RemoveExposedParameter(blackboardField.parameter);
                        return(true);

                    case BaseStackNodeView stackNodeView:
                        graph.RemoveStackNode(stackNodeView.stackNode);
                        RemoveElement(stackNodeView);
                        return(true);
                    }

                    return(false);
                });
            }

            return(changes);
        }
Пример #12
0
        // called by the BaseGraph when the node is added to the graph
        public void Initialize(BaseGraph graph)
        {
            this.graph = graph;

            ExceptionToLog.Call(() => Enable());

            foreach (var nodeFieldKP in nodeFields)
            {
                var nodeField = nodeFieldKP.Value;

                if (nodeField.behavior != null)
                {
                    UpdatePortsForField(nodeField.fieldName);
                }
                else
                {
                    // If we don't have a custom behavior on the node, we just have to create a simple port
                    AddPort(nodeField.input, nodeField.fieldName, new PortData {
                        acceptMultipleEdges = nodeField.isMultiple, displayName = nodeField.name
                    });
                }
            }
        }
Пример #13
0
 internal void DestroyInternal() => ExceptionToLog.Call(() => Destroy());
Пример #14
0
 internal void DisableInternal() => ExceptionToLog.Call(() => Disable());
Пример #15
0
        public void OnProcess()
        {
            ExceptionToLog.Call(() => Process());

            InvokeOnProcessed();
        }