protected internal virtual System.Drawing.Color getBackgroundColorForNode(ViewGraphNode node) { System.Drawing.Color bg = System.Drawing.Color.Black; if (node.ReteNode is TerminalNode) { bg = System.Drawing.Color.Black; } if (node.ReteNode is BaseJoin) { bg = System.Drawing.Color.Green; } if (node.ReteNode is LIANode) { bg = System.Drawing.Color.Cyan; } if (node.ReteNode is ObjectTypeNode) { bg = System.Drawing.Color.Orange; } if (node.ReteNode is AlphaNodePredConstr) { bg = System.Drawing.Color.Red; } if (node.ReteNode is BaseAlpha2) { bg = System.Drawing.Color.Red; } return(bg); }
/// <summary> Add a Node to its childs /// </summary> /// <param name="n">new node /// /// </param> public virtual void addToChilds(BaseNode n) { ViewGraphNode node = new ViewGraphNode(n); childs.add(node); node.parents.add(this); invalidateSubtreeWidth(); }
/// <summary> Returns the logical width of this node. It is 1 iff /// whichSubtree is the first parent. else 0 /// </summary> /// <param name="">whichSubtree /// /// </param> protected internal virtual int getMyWidth(ViewGraphNode whichSubtree) { if (parents.get(0) == whichSubtree) { return(2); } return(0); }
protected internal virtual void checkForValidAlignment() { if (x == -1) { ViewGraphNode r = this; while (!r.parents.isEmpty()) { r = (ViewGraphNode)parents.get(0); } r.calculateAlignment(0, 0); } }
/// <summary> Builds a complete Graph by traversing root /// </summary> /// <param name="">root /// /// </param> public static ViewGraphNode buildFromRete(RootNode root) { Collection firstLevel = root.ObjectTypeNodes.values(); ViewGraphNode res = new ViewGraphNode(); System.Collections.Hashtable ht = new System.Collections.Hashtable(); for (Iterator iter = firstLevel.iterator(); iter.hasNext();) { BaseNode b = (BaseNode)iter.next(); res.addToChilds(buildFromRete(b, ht)); } return(res); }
protected internal virtual void reloadView() { this.coordinates.Clear(); RootNode root = engine.RootNode; ViewGraphNode t = ViewGraphNode.buildFromRete(root); this.root = t; container.removeAllPrimitives(); radar.removeAllPrimitives(); createPrimitives(t); if (myFrame != null) { myFrame.setTitle(getCaption(System.DateTime.Now)); } }
protected internal virtual void getCorrespondingTerminalNodes(ViewGraphNode root, Set target) { BaseNode n = root.ReteNode; if (n is TerminalNode) { target.add(n); } Iterator it = root.childs.iterator(); while (it.hasNext()) { ViewGraphNode succ = (ViewGraphNode)it.next(); getCorrespondingTerminalNodes(succ, target); } }
protected internal virtual void calculateAlignment(int offsetX, int offsetY) { x = SubtreeWidth / 2 - 1 + offsetX; if (x < offsetX) { x = offsetX; } y = offsetY; offsetY++; for (Iterator it = childs.iterator(); it.hasNext();) { ViewGraphNode sub = (ViewGraphNode)it.next(); sub.calculateAlignment(offsetX, offsetY); offsetX += sub.SubtreeWidth; if (sub.SubtreeWidth == 0) { offsetX += 2; } } }
protected internal static ViewGraphNode buildFromRete(BaseNode root, System.Collections.Hashtable ht) { System.Object[] succ = root.SuccessorNodes; ViewGraphNode foo = (ViewGraphNode)ht[root]; ViewGraphNode res = null; if (foo == null) { res = new ViewGraphNode(root); for (int i = 0; i < succ.Length; i++) { res.addToChilds(buildFromRete((BaseNode)succ[i], ht)); } SupportClass.PutElement(ht, root, res); } else { res = foo; } return(res); }
protected internal virtual void createPrimitives(ViewGraphNode root) { LinkedList queue = new LinkedList(); queue.add(root); while (!queue.isEmpty()) { ViewGraphNode act = (ViewGraphNode)queue.remove(0); Shape s = null; if (act.Shape == null) { s = makeShapeFromNode(act, queue); } else { s = act.Shape; } if (act.ParentsChecked) { continue; } act.ParentsChecked = true; for (Iterator it = act.Parents.iterator(); it.hasNext();) { ViewGraphNode n = (ViewGraphNode)it.next(); Shape s1 = n.Shape; if (s1 == null) { s1 = makeShapeFromNode(n, queue); } ConnectorLine line = new ConnectorLine(s1, s); line.Color = System.Drawing.Color.Blue; if (n.ReteNode is BaseJoin) { line.Color = System.Drawing.Color.Red; } addPrimitive(line); } } }
protected internal virtual void getCorrespondingTerminalNodes(ViewGraphNode root, Set target) { BaseNode n = root.ReteNode; if (n is TerminalNode) target.add(n); Iterator it = root.childs.iterator(); while (it.hasNext()) { ViewGraphNode succ = (ViewGraphNode) it.next(); getCorrespondingTerminalNodes(succ, target); } }
protected internal virtual System.Drawing.Color getBorderColorForNode(ViewGraphNode node) { System.Drawing.Color temp_Color; temp_Color = getBackgroundColorForNode(node); return System.Drawing.Color.FromArgb(System.Convert.ToInt32(temp_Color.R * 0.7), System.Convert.ToInt32(temp_Color.G * 0.7), System.Convert.ToInt32(temp_Color.B * 0.7)); }
protected internal virtual System.Drawing.Color getBackgroundColorForNode(ViewGraphNode node) { System.Drawing.Color bg = System.Drawing.Color.Black; if (node.ReteNode is TerminalNode) bg = System.Drawing.Color.Black; if (node.ReteNode is BaseJoin) bg = System.Drawing.Color.Green; if (node.ReteNode is LIANode) bg = System.Drawing.Color.Cyan; if (node.ReteNode is ObjectTypeNode) bg = System.Drawing.Color.Orange; if (node.ReteNode is AlphaNodePredConstr) bg = System.Drawing.Color.Red; if (node.ReteNode is BaseAlpha2) bg = System.Drawing.Color.Red; return bg; }
protected internal virtual void createPrimitives(ViewGraphNode root) { LinkedList queue = new LinkedList(); queue.add(root); while (!queue.isEmpty()) { ViewGraphNode act = (ViewGraphNode) queue.remove(0); Shape s = null; if (act.Shape == null) { s = makeShapeFromNode(act, queue); } else { s = act.Shape; } if (act.ParentsChecked) continue; act.ParentsChecked = true; for (Iterator it = act.Parents.iterator(); it.hasNext(); ) { ViewGraphNode n = (ViewGraphNode) it.next(); Shape s1 = n.Shape; if (s1 == null) s1 = makeShapeFromNode(n, queue); ConnectorLine line = new ConnectorLine(s1, s); line.Color = System.Drawing.Color.Blue; if (n.ReteNode is BaseJoin) line.Color = System.Drawing.Color.Red; addPrimitive(line); } } }
/// <summary> Add a Node to its childs /// </summary> /// <param name="n">new node /// /// </param> public virtual void addToChilds(ViewGraphNode n) { childs.add(n); n.parents.add(this); invalidateSubtreeWidth(); }
protected internal static ViewGraphNode buildFromRete(BaseNode root, System.Collections.Hashtable ht) { System.Object[] succ = root.SuccessorNodes; ViewGraphNode foo = (ViewGraphNode) ht[root]; ViewGraphNode res = null; if (foo == null) { res = new ViewGraphNode(root); for (int i = 0; i < succ.Length; i++) { res.addToChilds(buildFromRete((BaseNode) succ[i], ht)); } SupportClass.PutElement(ht, root, res); } else { res = foo; } return res; }
/// <summary> Returns the logical width of this node. It is 1 iff /// whichSubtree is the first parent. else 0 /// </summary> /// <param name="">whichSubtree /// /// </param> protected internal virtual int getMyWidth(ViewGraphNode whichSubtree) { if (parents.get(0) == whichSubtree) return 2; return 0; }
protected internal virtual Shape makeShapeFromNode(ViewGraphNode act, LinkedList queue) { System.Drawing.Color bg = getBackgroundColorForNode(act); System.Drawing.Color border = getBorderColorForNode(act); System.String desc = ""; BaseNode reteNode = act.ReteNode; HashSet terminalNodes = new HashSet(); getCorrespondingTerminalNodes(act, terminalNodes); if (reteNode != null) desc = reteNode.NodeId.ToString(); Shape s; if (reteNode == null) { // ROOT NODE s = new Ellipse(); } else if (reteNode is BaseJoin || act.ReteNode is BaseAlpha2) { s = new Trapezoid(); } else if (reteNode is TerminalNode) { s = new RoundedRectangle(); } else if (reteNode is LIANode) { s = new Ellipse(); } else { s = new Rectangle(); } s.Bgcolor = bg; s.Bordercolor = border; //UPGRADE_WARNING: Narrowing conversions may produce unexpected results in C#. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1042"' int x = (spaceHorizontal / 2) + (int) ((float) (act.X * (spaceHorizontal + nodeHorizontal)) / 2.0); int y = (spaceVertical / 2) + act.Y * (spaceVertical + nodeVertical); System.String key = x + "," + y; // if there is already a node at the given location, we shift it right while (this.coordinates.ContainsKey(key)) { x = x + ((spaceHorizontal + nodeHorizontal) * 2); key = x + "," + y; } SupportClass.PutElement(coordinates, key, s); s.X = x; s.Y = y; s.Width = nodeHorizontal; s.Height = nodeVertical; System.String longdesc = ""; if (reteNode == null) { longdesc = "Root Node"; } else { longdesc = "ID:" + reteNode.NodeId + " NodeType:" + reteNode.GetType().FullName; longdesc += " Details:" + reteNode.toPPString(); } longdesc += " Rules:"; Iterator iter = terminalNodes.iterator(); while (iter.hasNext()) { TerminalNode t = (TerminalNode) iter.next(); longdesc += t.Rule.Name; if (iter.hasNext()) longdesc += ";"; } s.LongDescription = longdesc; if (reteNode is LIANode) s.incWidth(- nodeHorizontal / 3); s.Text = desc; act.Shape = s; addPrimitive(s); for (Iterator it = act.Successors.iterator(); it.hasNext(); ) { ViewGraphNode n = (ViewGraphNode) it.next(); queue.add(n); } return s; }
protected internal virtual System.Drawing.Color getBorderColorForNode(ViewGraphNode node) { System.Drawing.Color temp_Color; temp_Color = getBackgroundColorForNode(node); return(System.Drawing.Color.FromArgb(System.Convert.ToInt32(temp_Color.R * 0.7), System.Convert.ToInt32(temp_Color.G * 0.7), System.Convert.ToInt32(temp_Color.B * 0.7))); }
protected internal virtual Shape makeShapeFromNode(ViewGraphNode act, LinkedList queue) { System.Drawing.Color bg = getBackgroundColorForNode(act); System.Drawing.Color border = getBorderColorForNode(act); System.String desc = ""; BaseNode reteNode = act.ReteNode; HashSet terminalNodes = new HashSet(); getCorrespondingTerminalNodes(act, terminalNodes); if (reteNode != null) { desc = reteNode.NodeId.ToString(); } Shape s; if (reteNode == null) { // ROOT NODE s = new Ellipse(); } else if (reteNode is BaseJoin || act.ReteNode is BaseAlpha2) { s = new Trapezoid(); } else if (reteNode is TerminalNode) { s = new RoundedRectangle(); } else if (reteNode is LIANode) { s = new Ellipse(); } else { s = new Rectangle(); } s.Bgcolor = bg; s.Bordercolor = border; //UPGRADE_WARNING: Narrowing conversions may produce unexpected results in C#. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1042"' int x = (spaceHorizontal / 2) + (int)((float)(act.X * (spaceHorizontal + nodeHorizontal)) / 2.0); int y = (spaceVertical / 2) + act.Y * (spaceVertical + nodeVertical); System.String key = x + "," + y; // if there is already a node at the given location, we shift it right while (this.coordinates.ContainsKey(key)) { x = x + ((spaceHorizontal + nodeHorizontal) * 2); key = x + "," + y; } SupportClass.PutElement(coordinates, key, s); s.X = x; s.Y = y; s.Width = nodeHorizontal; s.Height = nodeVertical; System.String longdesc = ""; if (reteNode == null) { longdesc = "Root Node"; } else { longdesc = "ID:" + reteNode.NodeId + " NodeType:" + reteNode.GetType().FullName; longdesc += " Details:" + reteNode.toPPString(); } longdesc += " Rules:"; Iterator iter = terminalNodes.iterator(); while (iter.hasNext()) { TerminalNode t = (TerminalNode)iter.next(); longdesc += t.Rule.Name; if (iter.hasNext()) { longdesc += ";"; } } s.LongDescription = longdesc; if (reteNode is LIANode) { s.incWidth(-nodeHorizontal / 3); } s.Text = desc; act.Shape = s; addPrimitive(s); for (Iterator it = act.Successors.iterator(); it.hasNext();) { ViewGraphNode n = (ViewGraphNode)it.next(); queue.add(n); } return(s); }
/// <summary> Builds a complete Graph by traversing root /// </summary> /// <param name="">root /// /// </param> public static ViewGraphNode buildFromRete(RootNode root) { Collection firstLevel = root.ObjectTypeNodes.values(); ViewGraphNode res = new ViewGraphNode(); System.Collections.Hashtable ht = new System.Collections.Hashtable(); for (Iterator iter = firstLevel.iterator(); iter.hasNext(); ) { BaseNode b = (BaseNode) iter.next(); res.addToChilds(buildFromRete(b, ht)); } return res; }