/// <summary> /// draw evaluation tree to treeview /// </summary> /// <param name="parent">parent or null for root</param> /// <param name="node">node to draw</param> private void DrawTree(TreeNode parent, LeafNode node) { if (node != null) { // null parent is root if (parent == null) { parent = this.treeView1.Nodes.Add(node.Result.ToString()); parent = this.treeView1.Nodes[0]; } // create tree node TreeNode p = new TreeNode(node.ToString()); if (node.Type == NodeType.Operator) // operator - colorize and set tooltip { // farba p.ForeColor = Color.Green; // tooltip if (node.Right.Result < 0) // negative number to brackets p.ToolTipText = string.Format( System.Globalization.CultureInfo.CurrentCulture, "{0}{1}({2})={3}", node.Left.Result, node.ToString(), node.Right.Result, node.Result); else p.ToolTipText = string.Format( System.Globalization.CultureInfo.CurrentCulture, "{0}{1}{2}={3}", node.Left.Result, node.ToString(), node.Right.Result, node.Result); } parent.Nodes.Add(p); this.DrawTree(p, node.Left); // left this.DrawTree(p, node.Right); // right } }
private void MakeXmlTree(XmlElement parent, LeafNode node) { if (node != null) { // creating element XmlElement el = parent.OwnerDocument.CreateElement(node.Type.ToString()); XmlAttribute attr = parent.OwnerDocument.CreateAttribute("data"); attr.Value=node.ToString(); el.Attributes.Append(attr); if (node.Type == NodeType.Operator) // operator - expression and result attributes { XmlAttribute a = el.Attributes.Append(parent.OwnerDocument.CreateAttribute("expression")); if (node.Right.Result < 0) // negative number to bracket a.Value = string.Format( System.Globalization.CultureInfo.CurrentCulture, "{0}{1}({2})", node.Left.Result, node.ToString(), node.Right.Result); else a.Value = string.Format( System.Globalization.CultureInfo.CurrentCulture, "{0}{1}{2}", node.Left.Result, node.ToString(), node.Right.Result); el.Attributes.Append(a); a = el.Attributes.Append(parent.OwnerDocument.CreateAttribute("result")); a.Value = node.Result.ToString(); el.Attributes.Append(a); } parent.AppendChild(el); this.MakeXmlTree(el, node.Left); // left this.MakeXmlTree(el, node.Right); // right } }