private static void AddNode(Canvas canvas, NodePort parentInput, ExpressionTreeNode expressionNode, List<NumberParam> variables, Point location, Int32 levelStep, Int32 minY, Int32 maxY) { Int32 leafs = (expressionNode.LeftNode != null ? 1 : 0) + (expressionNode.RightNode != null ? 1 : 0); NodeBase node = null; if (expressionNode.Token.IsNumber) { node = new VisiTypes.Number(Double.Parse(expressionNode.Token.TokenBody)); canvas.AddNode(node, location); } if (expressionNode.Token.IsVariable) { Boolean exist = false; foreach (NumberParam param in variables) { if (param.Name == expressionNode.Token.TokenBody) { exist = true; node = param; break; } } if (!exist) { node = new NumberParam(); ((NumberParam)node).Name = expressionNode.Token.TokenBody; ((NumberParam)node).Header = expressionNode.Token.TokenBody; variables.Add((NumberParam)node); canvas.AddNode(node, location); } } if (expressionNode.Token.IsOperator) { node = new Operator(expressionNode.Token.OperatorDescriptor); canvas.AddNode(node, location); switch (leafs) { case 1: { AddNode(canvas, node.GetInput(0), expressionNode.LeftNode, variables, new Point(location.X - levelStep, location.Y), levelStep, minY, maxY); break; } case 2: { Int32 y2 = (maxY - minY) / 2; AddNode(canvas, node.GetInput(0), expressionNode.LeftNode, variables, new Point(location.X - levelStep, minY + y2 / 2), levelStep, minY, minY + y2); AddNode(canvas, node.GetInput(1), expressionNode.RightNode, variables, new Point(location.X - levelStep, maxY - y2 / 2), levelStep, maxY - y2, maxY); break; } } } if (parentInput != null && node != null) { parentInput.Connection = node.GetOutput(0); } }
private static void AddNode(Canvas canvas, NodePort parentInput, ExpressionTreeNode expressionNode, List <NumberParam> variables, Point location, Int32 levelStep, Int32 minY, Int32 maxY) { Int32 leafs = (expressionNode.LeftNode != null ? 1 : 0) + (expressionNode.RightNode != null ? 1 : 0); NodeBase node = null; if (expressionNode.Token.IsNumber) { node = new VisiTypes.Number(Double.Parse(expressionNode.Token.TokenBody)); canvas.AddNode(node, location); } if (expressionNode.Token.IsVariable) { Boolean exist = false; foreach (NumberParam param in variables) { if (param.Name == expressionNode.Token.TokenBody) { exist = true; node = param; break; } } if (!exist) { node = new NumberParam(); ((NumberParam)node).Name = expressionNode.Token.TokenBody; ((NumberParam)node).Header = expressionNode.Token.TokenBody; variables.Add((NumberParam)node); canvas.AddNode(node, location); } } if (expressionNode.Token.IsOperator) { node = new Operator(expressionNode.Token.OperatorDescriptor); canvas.AddNode(node, location); switch (leafs) { case 1: { AddNode(canvas, node.GetInput(0), expressionNode.LeftNode, variables, new Point(location.X - levelStep, location.Y), levelStep, minY, maxY); break; } case 2: { Int32 y2 = (maxY - minY) / 2; AddNode(canvas, node.GetInput(0), expressionNode.LeftNode, variables, new Point(location.X - levelStep, minY + y2 / 2), levelStep, minY, minY + y2); AddNode(canvas, node.GetInput(1), expressionNode.RightNode, variables, new Point(location.X - levelStep, maxY - y2 / 2), levelStep, maxY - y2, maxY); break; } } } if (parentInput != null && node != null) { parentInput.Connection = node.GetOutput(0); } }