示例#1
0
 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();
 }
示例#2
0
        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;
        }
示例#3
0
 private void Connect(Node to)
 {
     var inputSocket = to.GetFreeInputSocket();
     var outputSocket = GetFreeOutputSocket();
     if (null == inputSocket) return;
     Connect(outputSocket, inputSocket);
 }
示例#4
0
 public bool IsConnected(Node otherNode)
 {
     return GetConnectedInputs().Contains(otherNode) || GetConnectedOutputs().Contains(otherNode);
 }
示例#5
0
 public bool QueryCanConnectOutput(Node toOtherNode)
 {
     if (null == toOtherNode) return false;
     return !ReferenceEquals(this, toOtherNode) && !toOtherNode.OutputChainContains(this);
 }
示例#6
0
 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));
             });
 }
示例#7
0
 public void RemoveNode(Node node)
 {
     Items.Remove(node);
 }
示例#8
0
 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;
 }