protected override void OnVisualParentChanged(DependencyObject oldParent) { base.OnVisualParentChanged(oldParent); if (null != Node) Node.LayoutUpdated -= NodeOnLayoutUpdated; Node = this.FindVisualParent<Node>(); rootPanel = this.FindVisualParent<NodePanel>(); if (null == rootPanel) return; if (null == Node) return; addConnectorCallback = x => rootPanel.AddConnector(x); Node.LayoutUpdated += NodeOnLayoutUpdated; SetGlobalPosition(); }
public static bool RunCalculation(Node node, out object result) { result = null; if (null == node) return false; var content = node.Content; if (null == content) return false; var calculator = node.Content as INode; if (null == calculator) return false; var inputs = new List<object>(); // ReSharper disable LoopCanBeConvertedToQuery foreach (var inputNode in node.GetConnectedInputs()) // ReSharper restore LoopCanBeConvertedToQuery { object inputResult; if (!RunCalculation(inputNode, out inputResult)) continue; inputs.Add(inputResult); } result = calculator.Compute(inputs.ToArray()); return true; }
private void Connect(Node to) { var inputSocket = to.GetFreeInputSocket(); var outputSocket = GetFreeOutputSocket(); if (null == inputSocket) return; Connect(outputSocket, inputSocket); }
public bool IsConnected(Node otherNode) { return GetConnectedInputs().Contains(otherNode) || GetConnectedOutputs().Contains(otherNode); }
public bool QueryCanConnectOutput(Node toOtherNode) { if (null == toOtherNode) return false; return !ReferenceEquals(this, toOtherNode) && !toOtherNode.OutputChainContains(this); }
public bool OutputChainContains(Node otherNode) { return OutputSockets .Select(x => x.GetTargetNodes()) .Where(x => null != x) .Any(nodes => { var ns = nodes.ToArray(); return ns.Contains(otherNode) || ns.Any(x => x.OutputChainContains(otherNode)); }); }
public void RemoveNode(Node node) { Items.Remove(node); }
private void AddNode(object forItem) { var node = new Node { DataContext = forItem, Content = forItem, ContentTemplate = NodeTemplate, HeaderTemplate = NodeHeaderTemplate }; Items.Add(node); var calculator = forItem as IRequestRecalculate; if (null == calculator) return; calculator.RequestRecalculate += CalculatorOnRequestRecalculate; }