/* this boolean is to distinguish that a particular node * of L has all of the arcs of the host node. Again, * if true then use equal * if false then use subset * NOTE: this is commonly misunderstood to be the same as induced. The difference is that this * applies to each node in the LHS and includes arcs that reference nodes not found on the LHS*/ #endregion #region Methods public Boolean matchWith(node hostNode) { if (hostNode != null) { if (((strictDegreeMatch && (this.degree == hostNode.degree)) || (!strictDegreeMatch && (this.degree <= hostNode.degree))) && (labelsMatch(this.localLabels, hostNode.localLabels)) && (intendedTypesMatch(this.nodeType, hostNode.nodeType))) return true; else return false; } else return false; }
public virtual node copy(node copyOfNode) { copyOfNode.name = this.name; copyOfNode.shapekey = this.shapekey.ToString(); copyOfNode.screenX = this.screenX; copyOfNode.screenY = this.screenY; copyOfNode.nodeType = this.nodeType; foreach (string label in this.localLabels) copyOfNode.localLabels.Add(label.ToString()); foreach (double var in this.localVariables) copyOfNode.localVariables.Add(var); return copyOfNode; }
/* for a lack of a better name - this play on "no means no" applies to dangling arcs that point * to null instead of pointing to another node. If this is set to false, then we are saying a * null reference on an arc can be matched with a null in the graph or any node in the graph. * Like the above, a false value is like a subset in that null is a subset of any actual node. * And a true value means it must match exactly or in otherwords, "null means null" - null * matches only with a null in the host. If you want the rule to be recognized only when an actual * node is present simply add a dummy node with no distinguishing characteristics. That would * in turn nullify this boolean since this boolean only applies when a null pointer exists in * the rule. */ #endregion #region Methods public Boolean matchWith(arc hostArc, node fromHostNode, node toHostNode, Boolean traverseForward) { if (matchWith(hostArc)) { if (this.directed && (((hostArc.To == toHostNode) && (hostArc.From == fromHostNode) && traverseForward) || ((hostArc.From == toHostNode) && (hostArc.To == fromHostNode) && !traverseForward))) return true; else if (((hostArc.To == toHostNode) && (hostArc.From == fromHostNode)) || ((hostArc.From == toHostNode) && (hostArc.To == fromHostNode))) return true; else return false; } else return false; }
/* if allowArcDuplication is true then for each rule that matches with the arc the arc will be * duplicated. */ public static Boolean arcIsFree(arc a, designGraph host, out sbyte freeEndIdentifier, node neighborNode) { if (a.From != null && a.To != null && !host.nodes.Contains(a.From) && !host.nodes.Contains(a.To)) { freeEndIdentifier = 0; /* if the nodes on either end of the freeArc are pointing to previous nodes * that were deleted in the first pushout then neighborNode is null (and as * a result any rules using the neighborNodeLabel will not apply) and the * freeEndIdentifier is zero. */ neighborNode = null; return true; } else if (a.From != null && !host.nodes.Contains(a.From)) { freeEndIdentifier = -1; /* freeEndIdentifier set to -1 means that the From end of the arc must be the free end.*/ neighborNode = a.To; return true; } else if (a.To != null && !host.nodes.Contains(a.To)) { freeEndIdentifier = +1; /* freeEndIdentifier set to +1 means that the To end of the arc must be the free end.*/ neighborNode = a.From; return true; } else { /* else, the arc is not a free arc after all and we simply break out * of this loop and try the next arc. */ freeEndIdentifier = 0; neighborNode = null; return false; } }
/// <summary> /// Adds the node to the graph. This is very simple, and is in fact identical to /// doing graph.nodes.Add(n); /// </summary> /// <param name = "n">The n.</param> public void addNode(node n) { nodes.Add(n); }
/// <summary> /// Adds the arc to the graph and connects it between these two nodes. /// </summary> /// <param name = "newArc">The new arc.</param> /// <param name = "fromNode">From node.</param> /// <param name = "toNode">To node.</param> public void addArc(arc newArc, node fromNode, node toNode) { newArc.From = fromNode; newArc.To = toNode; arcs.Add(newArc); }
public void addArc(string name, Type arcType, node fromNode, node toNode) { if (arcType == null) addArc(name, fromNode, toNode); else { Type[] types = new Type[3]; types[0] = typeof(string); types[1] = typeof(node); types[2] = typeof(node); System.Reflection.ConstructorInfo arcConstructor = arcType.GetConstructor(types); object[] inputs = new object[3]; inputs[0] = name; inputs[1] = fromNode; inputs[2] = toNode; arcs.Add((arc)arcConstructor.Invoke(inputs)); if (fromNode != null) { fromNode.arcs.Add(arcs[lastArc]); fromNode.arcsFrom.Add(arcs[lastArc]); } if (toNode != null) { toNode.arcs.Add(arcs[lastArc]); toNode.arcsTo.Add(arcs[lastArc]); } } }
public void addArc(arc newArc, node fromNode, node toNode) { newArc.From = fromNode; newArc.To = toNode; arcs.Add(newArc); }
private void case4ConnectingBackToPrevRecNode(designGraph host, List<node> locatedNodes, List<arc> locatedArcs, ruleNode nextLNode, node fromHostNode, int currentLArcIndex, Boolean traverseForward) { ruleArc currentLArc = (ruleArc)L.arcs[currentLArcIndex]; /* first we must match the arc to a possible arc * leaving the fromHostNode .*/ node nextHostNode = locatedNodes[L.nodes.IndexOf(nextLNode)]; List<arc> neighborHostArcs = host.arcs.FindAll(delegate(arc a) /* there maybe several possible arcs*/ { /* that match with currentLArc, so we*/ return (!locatedArcs.Contains(a) /* make a list called neighborHostArcs*/ && currentLArc.matchWith(a, fromHostNode, nextHostNode, traverseForward)); }); if (neighborHostArcs.Count > 0) /* if there are no recognized arcs we just leave. */ { foreach (arc HostArc in neighborHostArcs) { List<node> newlocatedNodes = new List<node>(locatedNodes); newlocatedNodes[L.nodes.FindIndex(delegate(node a) { return (a == nextLNode); })] = nextHostNode; List<arc> newlocatedArcs = new List<arc>(locatedArcs); newlocatedArcs[currentLArcIndex] = HostArc; recognizeRecursion(host, newlocatedNodes, newlocatedArcs, nextLNode, nextHostNode); } } }
public void removeNode(node nodeToRemove, Boolean removeArcsToo) { removeNode(nodeToRemove, removeArcsToo, true); }
public edge(string name, node from, node to) : base(name, from, to) { }
public void addNodesFromGraphControl(Netron.GraphLib.UI.GraphControl graphControl1, Boolean ruleGraph) { node tempnode; foreach (Shape a in graphControl1.Shapes) { if (!nodes.Exists(delegate(node b) { return (b.displayShape == a); })) { if (ruleGraph) tempnode = new ruleNode(nameFromText(a.Text)); else tempnode = new node(nameFromText(a.Text)); this.nodes.Add(tempnode); } else tempnode = nodes.Find(delegate(node b) { return (b.displayShape == a); }); if (a.Text != "[Not_set]") { tempnode.name = nameFromText(a.Text); tempnode.localLabels = labelsFromText(a.Text); } tempnode.screenX = a.X; tempnode.screenY = a.Y; tempnode.displayShape = a; tempnode.setShapeKeyFromDisplayShape(); } }
public void updateGraphControl(Netron.GraphLib.UI.GraphControl graphControl1, Label globalLabelsText) { try { string defaultShapeKey = "8ED1469D-90B2-43ab-B000-4FF5C682F530"; Boolean isFixed = true; Random rnd = new Random(); #region Global Labels if (this.globalLabels.Count > 0) { globalLabelsText.Text = StringCollectionConverter.convert(this.globalLabels); } else { globalLabelsText.Text = " "; } #endregion #region display the nodes for (int i = nodes.Count - 1; i >= 0; i--) { node n = nodes[i]; #region if it has no displayShape if (n.displayShape == null) { if (n.shapekey == null) { n.shapekey = defaultShapeKey; } if (n.screenX == 0.0 && n.screenY == 0.0) { n.screenX = rnd.Next(50, graphControl1.Width - 100); n.screenY = rnd.Next(20, graphControl1.Height - 20); isFixed = false; } else { isFixed = true; } n.displayShape = graphControl1.AddShape(n.shapekey, new PointF(n.screenX, n.screenY)); /* if the prev. statement didn't take, it's likely the shapekey wasn't recognized. * there we try again with the default ShapeKey. */ if (n.displayShape == null) { n.displayShape = graphControl1.AddShape(defaultShapeKey, new PointF(n.screenX, n.screenY)); } } #endregion else if (!graphControl1.Shapes.Contains(n.displayShape)) { /* a shape is defined for the node but is not displayed */ n.displayShape = graphControl1.AddShape(n.displayShape); } n.displayShape.Text = textForNode(n); n.displayShape.IsFixed = isFixed; /* make sure node is of right type - if not call the replacement function */ if ((n.nodeType != null) && (n.GetType() != typeof(GraphSynth.Representation.ruleNode)) && (n.GetType() != n.nodeType)) { replaceNodeWithInheritedType(n); } } #endregion #region display the arcs for (int i = arcs.Count - 1; i >= 0; i--) { arc a = arcs[i]; node fromNode = a.From; node toNode = a.To; Connector fromConnect = null; Connector toConnect = null; if ((fromNode == null) || (fromNode.displayShape == null)) { a.fromConnector = 0; if (a.displayShape == null || a.displayShape.From.BelongsTo == null) { fromConnect = addNullShape(graphControl1, 0).Connectors[0]; } else { fromConnect = a.displayShape.From; } } else if ((a.fromConnector == -1) || (a.fromConnector >= fromNode.displayShape.Connectors.Count)) { a.fromConnector = rnd.Next(fromNode.displayShape.Connectors.Count); fromConnect = fromNode.displayShape.Connectors[a.fromConnector]; } else { fromConnect = fromNode.displayShape.Connectors[a.fromConnector]; } /* now repeat same process for To */ if ((toNode == null) || (toNode.displayShape == null)) { a.toConnector = 0; if (a.displayShape == null || a.displayShape.To.BelongsTo == null) { toConnect = addNullShape(graphControl1, 1).Connectors[0]; } else { toConnect = a.displayShape.To; } } else if ((a.toConnector == -1) || (a.toConnector >= toNode.displayShape.Connectors.Count)) { a.toConnector = rnd.Next(toNode.displayShape.Connectors.Count); toConnect = toNode.displayShape.Connectors[a.toConnector]; } else { toConnect = toNode.displayShape.Connectors[a.toConnector]; } if (((a.displayShape != null) && (!graphControl1.Connections.Contains(a.displayShape)) && ((a.displayShape.From == null) || (a.displayShape.To == null))) || ((a.displayShape == null) && (fromConnect == null) && (toConnect == null))) { removeArc(a); } else { if (a.displayShape == null) { a.displayShape = graphControl1.AddConnection(fromConnect, toConnect); } else if (!graphControl1.Connections.Contains(a.displayShape)) { a.displayShape = graphControl1.AddConnection(a.displayShape.From, a.displayShape.To); } /* a shape is defined for the node but is not displayed * Rectangular, Default, Bezier */ if (a.curveStyle != null) { a.displayShape.LinePath = a.curveStyle; } if (a.doublyDirected) { a.displayShape.LineEnd = ConnectionEnd.BothFilledArrow; } else if (a.directed) { a.displayShape.LineEnd = ConnectionEnd.RightFilledArrow; } else { a.displayShape.LineEnd = ConnectionEnd.NoEnds; } a.displayShape.Text = textForArc(a); a.displayShape.ShowLabel = true; } /* make sure node is of right type - if not call the replacement function */ if ((a.arcType != null) && (a.GetType() != typeof(GraphSynth.Representation.ruleArc)) && (a.GetType() != a.arcType)) { replaceArcWithInheritedType(a, fromNode, toNode); } } #endregion } catch (Exception e) { MessageBox.Show("There was an error displaying the graph. Please save work and re-open. (Error: " + e.ToString() + ")", "Error Displaying Graph", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public string textForNode(node a) { return(textFromNameAndLabels(a.name, a.localLabels)); }
public void updateFromGraphControl(Netron.GraphLib.UI.GraphControl graphControl1) { try { node tempnode; List <node> tempNodes = new List <node>(); arc temparc; List <arc> tempArcs = new List <arc>(); Shape fromShape, toShape; foreach (Shape a in graphControl1.Shapes) { if (!nodes.Exists(delegate(node b) { return(b.displayShape == a); })) { tempnode = new node(nameFromText(a.Text)); tempNodes.Add(tempnode); } else { tempnode = nodes.Find(delegate(node b) { return(b.displayShape == a); }); tempNodes.Add(tempnode); } if (a.Text != "[Not_set]") { tempnode.name = nameFromText(a.Text); tempnode.localLabels = labelsFromText(a.Text); } tempnode.screenX = a.X; tempnode.screenY = a.Y; tempnode.shapekey = node.lookupShapeKey(a); tempnode.displayShape = a; } nodes = tempNodes; foreach (Connection a in graphControl1.Connections) { if (!arcs.Exists(delegate(arc b) { return(b.displayShape == a); })) { temparc = new arc(nameFromText(a.Text)); tempArcs.Add(temparc); } else { temparc = arcs.Find(delegate(arc b) { return(b.displayShape == a); }); tempArcs.Add(temparc); } fromShape = a.From.BelongsTo; toShape = a.To.BelongsTo; temparc.From = nodes.Find(delegate(node c) { return(sameName(c.name, fromShape.Text)); }); temparc.To = nodes.Find(delegate(node c) { return(sameName(c.name, toShape.Text)); }); for (int i = 0; i != fromShape.Connectors.Count; i++) { if (fromShape.Connectors[i] == a.From) { temparc.fromConnector = i; } } for (int i = 0; i != toShape.Connectors.Count; i++) { if (toShape.Connectors[i] == a.To) { temparc.toConnector = i; } } if (a.Text != "[Not_set]") { temparc.name = nameFromText(a.Text); temparc.localLabels = labelsFromText(a.Text); } temparc.curveStyle = a.LinePath; if (a.LineEnd == ConnectionEnd.NoEnds) { temparc.directed = false; } else if (a.LineEnd == ConnectionEnd.BothFilledArrow || a.LineEnd == ConnectionEnd.BothOpenArrow) { temparc.doublyDirected = true; } else { temparc.doublyDirected = false; temparc.directed = true; if (a.LineEnd == ConnectionEnd.LeftFilledArrow || a.LineEnd == ConnectionEnd.LeftOpenArrow) { /* we have a little situation on our hands here. the user drew the arc * from one node to another but now wants it to go the other way. */ tempnode = temparc.To; temparc.To = temparc.From; temparc.From = tempnode; } } temparc.displayShape = a; } arcs = tempArcs; this.internallyConnectGraph(); } catch (Exception e) { MessageBox.Show("There was an error updating graph from the display. Please save work and re-open. (Error: " + e.ToString() + ")", "Error Updating Graph", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/* Here is a series of important graph management functions * while it would be easy to just call, for example, ".arcs.add", * the difficulty comes in properly linking the nodes * likewise with the nodes and their dangling arcs. */ #region addArc public void addArc(string newName, node fromNode, node toNode) { /* this is the main addArc. the remaining three all invoke this one. */ arcs.Add(new arc(newName, fromNode, toNode)); arcs[lastArc].From = fromNode; arcs[lastArc].To = toNode; }
public void removeNode(node nodeToRemove) { removeNode(nodeToRemove, false, true); }
/// <summary> /// Copies the specified make deep copy. /// </summary> /// <param name = "MakeDeepCopy">if set to <c>true</c> [make deep copy].</param> /// <returns></returns> public designGraph copy(Boolean MakeDeepCopy = true) { /* at times we want to copy a graph and not refer to the same objects. This happens mainly * (rather initially what inspired this function) when the seed graph is copied into a candidate.*/ var copyOfGraph = new designGraph { name = name }; foreach (var label in globalLabels) { copyOfGraph.globalLabels.Add(label); } foreach (var v in globalVariables) { copyOfGraph.globalVariables.Add(v); } foreach (var origNode in nodes) { copyOfGraph.addNode(MakeDeepCopy ? origNode.copy() : origNode); } foreach (var origArc in arcs) { if (MakeDeepCopy) { var copyOfArc = origArc.copy(); var toIndex = nodes.FindIndex(a => (a == origArc.To)); var fromIndex = nodes.FindIndex(b => (b == origArc.From)); node fromNode = null; if (fromIndex > -1) { fromNode = copyOfGraph.nodes[fromIndex]; } node toNode = null; if (toIndex > -1) { toNode = copyOfGraph.nodes[toIndex]; } copyOfGraph.addArc(copyOfArc, fromNode, toNode); } else { copyOfGraph.arcs.Add(origArc); } } foreach (var origHyperArc in hyperarcs) { if (MakeDeepCopy) { var copyOfHyperArc = origHyperArc.copy(); var attachedNodes = new List <node>(); foreach (var n in origHyperArc.nodes) { var index = nodes.FindIndex(a => (a == n)); attachedNodes.Add(copyOfGraph.nodes[index]); } copyOfGraph.addHyperArc(copyOfHyperArc, attachedNodes); } else { copyOfGraph.hyperarcs.Add(origHyperArc); } } return(copyOfGraph); }
private void replaceArcWithInheritedType(arc origArc, node fromNode, node toNode) { this.addArc(origArc.name, origArc.arcType, fromNode, toNode); origArc.copy(arcs[lastArc]); arcs[lastArc].displayShape = origArc.displayShape; this.removeArc(origArc); }
public Boolean ruleIsRecognized(sbyte freeEndIdentifier, arc freeArc, node neighborNode, node nodeRemoved) { if (freeEndIdentifier * originalDirection >= 0) { /* this one is a little bit of enigmatic but clever coding if I do say so myself. Both * of these variables can be either +1, 0, -1. If in multiplying the two together you * get -1 then this is the only incompability. Combinations of +1&+1, or +1&0, or * -1&-1 all mean that the arc has a free end on the requested side (From or To). */ if ((freeArcLabel == null) || (freeArcLabel == "") || (freeArc.localLabels.Contains(freeArcLabel))) { if ((neighborNodeLabel == null) || (neighborNodeLabel == "") || ((neighborNode != null) && (neighborNode.localLabels.Contains(neighborNodeLabel)))) { if ((nodeRemoved == null) || ((freeArc.To == nodeRemoved) && (freeEndIdentifier >= 0)) || ((freeArc.From == nodeRemoved) && (freeEndIdentifier <= 0))) { return true; } } } } return false; }
private void recognizeRecursion(designGraph host, List<node> locatedNodes, List<arc> locatedArcs, ruleNode fromLNode, node fromHostNode) { /* Here is the main recursive function. Based on the current conditions within the recursion * one of four cases maybe invoked. * 1. (case1LocationFound) All nodes and arcs within locatedNodes and locatedArcs have been * filled with pointers to nodes and arcs in the host. If this is the case, then we can add * the location. however, you will need to check the enigmatic INDUCED condition. */ if (!locatedNodes.Contains(null) && !locatedArcs.Contains(null)) case1LocationFound(host, locatedNodes, locatedArcs); else { /* the last thing the recursion did was find a new node to start from. * see if there are any valid arcs on the L that still need to be matched with * the host. Here, currentLArcIndex is used instead of the actual reference * to the L arc. Why? Because, the index is useful both to the L and to locatedArcs * which lists arcs in the same way as they appear in the L. */ int currentLArcIndex = -1; Boolean traverseForward = false; /* this odd little boolean is used to indicate whether or not we are following the * arc in the proper direction regardless of the direction. We want to be able to follow * arcs backwards for recognition sake, so this is only useful in the eventual matchWith * method if direction is important. */ for (int i = 0; i != L.arcs.Count; i++) { /* this for loop seeks a L node leaving our fromLNode. If there is more than one arc, than * the loop may re-write currentLArcIndex and traverseForward. That's okay. Because we only * want one at this point. The recursion will eventually come around to any others that may * be skipped over here. */ if ((L.arcs[i].From == fromLNode) && (locatedArcs[i] == null)) { currentLArcIndex = i; traverseForward = true; } else if ((L.arcs[i].To == fromLNode) && (locatedArcs[i] == null)) { currentLArcIndex = i; traverseForward = false; } } if (currentLArcIndex == -1) { /* 2. (case2FindNewFromNode) if you get here, then it means that then were no more arcs * leaving the last node. Unfortunately, since Case 1 was not met, there are still * openings in the locations - either arcs and/or nodes. */ case2FindNewFromNode(host, locatedNodes, locatedArcs, fromLNode); } else { /* so, currentLArcIndex now, points to a LArc that has yet to be recognized. What we do from * this point depends on whether that LArc points to an L node we have yet to recognize, an L * node we have recognized, or null. */ ruleNode nextLNode = (ruleNode)L.arcs[currentLArcIndex].otherNode(fromLNode); if (nextLNode == null) { /* 3. (case3DanglingNodes) If nextLNode is null then we need to simply find a match for * the arc indicated by currentLArcIndex. Similar to case2, this function will need to * find a new starting point in matching the graphs. */ case3DanglingLNode (host, locatedNodes, locatedArcs, fromLNode, fromHostNode, currentLArcIndex, traverseForward); } else if (locatedNodes[L.nodes.IndexOf(nextLNode)] != null) { /* 4. (case4ConnectingBackToPrevRecNode) So, a proper arc was found leaving the * last L node. Problem is, it points back to a node that we've already located. * That means that we also already found what host node it connects to. */ case4ConnectingBackToPrevRecNode (host, locatedNodes, locatedArcs, nextLNode, fromHostNode, currentLArcIndex, traverseForward); } else { /* 5. (case5FindingNewNodes) Okay, so nothing strange here. You are following an arc * that is leading to a yet undiscovered node. Good luck! */ case5FindingNewNodes (host, locatedNodes, locatedArcs, nextLNode, fromHostNode, currentLArcIndex, traverseForward); } } } }
public void updateFromGraphControl(Netron.GraphLib.UI.GraphControl graphControl1) { try { node tempnode; List<node> tempNodes = new List<node>(); arc temparc; List<arc> tempArcs = new List<arc>(); Shape fromShape, toShape; foreach (Shape a in graphControl1.Shapes) { if (!nodes.Exists(delegate(node b) { return (b.displayShape == a); })) { tempnode = new node(nameFromText(a.Text)); tempNodes.Add(tempnode); } else { tempnode = nodes.Find(delegate(node b) { return (b.displayShape == a); }); tempNodes.Add(tempnode); } if (a.Text != "[Not_set]") { tempnode.name = nameFromText(a.Text); tempnode.localLabels = labelsFromText(a.Text); } tempnode.screenX = a.X; tempnode.screenY = a.Y; tempnode.shapekey = node.lookupShapeKey(a); tempnode.displayShape = a; } nodes = tempNodes; foreach (Connection a in graphControl1.Connections) { if (!arcs.Exists(delegate(arc b) { return (b.displayShape == a); })) { temparc = new arc(nameFromText(a.Text)); tempArcs.Add(temparc); } else { temparc = arcs.Find(delegate(arc b) { return (b.displayShape == a); }); tempArcs.Add(temparc); } fromShape = a.From.BelongsTo; toShape = a.To.BelongsTo; temparc.From = nodes.Find(delegate(node c) { return (sameName(c.name, fromShape.Text)); }); temparc.To = nodes.Find(delegate(node c) { return (sameName(c.name, toShape.Text)); }); for (int i = 0; i != fromShape.Connectors.Count; i++) { if (fromShape.Connectors[i] == a.From) temparc.fromConnector = i; } for (int i = 0; i != toShape.Connectors.Count; i++) { if (toShape.Connectors[i] == a.To) temparc.toConnector = i; } if (a.Text != "[Not_set]") { temparc.name = nameFromText(a.Text); temparc.localLabels = labelsFromText(a.Text); } temparc.curveStyle = a.LinePath; if (a.LineEnd == ConnectionEnd.NoEnds) temparc.directed = false; else if (a.LineEnd == ConnectionEnd.BothFilledArrow || a.LineEnd == ConnectionEnd.BothOpenArrow) temparc.doublyDirected = true; else { temparc.doublyDirected = false; temparc.directed = true; if (a.LineEnd == ConnectionEnd.LeftFilledArrow || a.LineEnd == ConnectionEnd.LeftOpenArrow) { /* we have a little situation on our hands here. the user drew the arc * from one node to another but now wants it to go the other way. */ tempnode = temparc.To; temparc.To = temparc.From; temparc.From = tempnode; } } temparc.displayShape = a; } arcs = tempArcs; this.internallyConnectGraph(); } catch (Exception e) { MessageBox.Show("There was an error updating graph from the display. Please save work and re-open. (Error: " + e.ToString() + ")", "Error Updating Graph", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/* removing a node is a little more complicated than removing arcs * since we need to decide what to do with dangling arcs. As a result * there are two booleans that specify how to handle the arcs. * removeArcToo will simply delete the attached arcs if true, otherwise it * will leave them dangling (default is false). * removeNodeRef will change the references within the attached arcs to null * if set to true, or will leave them if false (default is true). */ public void removeNode(node nodeToRemove, Boolean removeArcsToo, Boolean removeNodeRef) { /* this is the main method, all other overloads eventually funnel into this one. */ if (removeArcsToo) { foreach (arc connectedArc in nodeToRemove.arcs) removeArc(connectedArc); nodes.Remove(nodeToRemove); } else if (removeNodeRef) { List<arc> connectedArcs = new List<arc>(); connectedArcs.AddRange(nodeToRemove.arcs); foreach (arc connectedArc in connectedArcs) if (connectedArc.From == nodeToRemove) connectedArc.From = null; else connectedArc.To = null; nodes.Remove(nodeToRemove); } else nodes.Remove(nodeToRemove); }
public string textForNode(node a) { return textFromNameAndLabels(a.name, a.localLabels); }
private void replaceNodeWithInheritedType(node origNode) { this.addNode(origNode.name, origNode.nodeType); origNode.copy(nodes[lastNode]); nodes[lastNode].displayShape = origNode.displayShape; foreach (arc a in origNode.arcsFrom) a.From = nodes[lastNode]; foreach (arc a in origNode.arcsTo) a.To = nodes[lastNode]; this.removeNode(origNode); }
private void replaceNodeWithInheritedType(node origNode) { this.addNode(origNode.name, origNode.nodeType); origNode.copy(nodes[lastNode]); nodes[lastNode].displayShape = origNode.displayShape; for (int i = 0; i != origNode.arcsFrom.Count; i++) origNode.arcsFrom[i].From = nodes[lastNode]; for (int i = 0; i != origNode.arcsTo.Count; i++) origNode.arcsTo[i].To = nodes[lastNode]; this.removeNode(origNode); }
public node otherNode(node node1) /* well, this isn't exactly a property, but it's kinda used like one. * here, we know one of the nodes that the arc is connected to, but not * the other. So, we are simply asking for the node other than the one we know.*/ { if (this.from == node1) return this.to; else if (this.to == node1) return this.from; else return null; }
private void case3DanglingLNode(designGraph host, List<node> locatedNodes, List<arc> locatedArcs, ruleNode fromLNode, node fromHostNode, int currentLArcIndex, Boolean traverseForward) { ruleArc currentLArc = (ruleArc)L.arcs[currentLArcIndex]; /* first we must match the arc to a possible arc * leaving the fromHostNode .*/ node nextHostNode; List<arc> neighborHostArcs = host.arcs.FindAll(delegate(arc a) /* there maybe several possible arcs*/ { /* that match with currentLArc, so we*/ return (!locatedArcs.Contains(a) /* make a list called neighborHostArcs*/ && currentLArc.matchWith(a, fromHostNode, traverseForward)); }); if (neighborHostArcs.Count > 0) /* if there are no recognized arcs we just leave. */ { foreach (arc HostArc in neighborHostArcs) { /* for each arc that was recognized, we now need to check that the destination node matches. */ nextHostNode = HostArc.otherNode(fromHostNode); if (!currentLArc.nullMeansNull || (nextHostNode == null)) { /* if nullMeansNull is false than ANY host node is fine even if its also null. If nullMeansNull * is true, however, than we need to make sure fromHostNode is also null. */ List<arc> newlocatedArcs = new List<arc>(locatedArcs); newlocatedArcs[currentLArcIndex] = HostArc; /* re-invoking the recursion is "tough" from this point. since we just hit a dead end in L. * the best thing to do is just use the very same fromLnode and fromHostNode that were * used in the previous recognizeRecursion. */ recognizeRecursion(host, locatedNodes, newlocatedArcs, fromLNode, fromHostNode); } } } }
/* either make new arc with a prescribed name, or give it a name never seen before. * additionally one can provide the connecting nodes at this time or later. */ public arc(string newName, node fromNode, node toNode) { name = newName; from = fromNode; to = toNode; }
private void case5FindingNewNodes(designGraph host, List<node> locatedNodes, List<arc> locatedArcs, ruleNode nextLNode, node fromHostNode, int currentLArcIndex, Boolean traverseForward) { /* this function starts very similar to Case 4. It is, however, more comlex since we need to match * the next node in L to a node in the host. The function begin the same as above by gathering the * potential arcs leaving the host and checking them for compatibility. */ ruleArc currentLArc = (ruleArc)L.arcs[currentLArcIndex]; node nextHostNode; List<arc> neighborHostArcs = host.arcs.FindAll(delegate(arc a) { return (!locatedArcs.Contains(a) && currentLArc.matchWith(a, fromHostNode, traverseForward)); }); if (neighborHostArcs.Count > 0) { foreach (arc HostArc in neighborHostArcs) { /* for each arc that was recognized, we now need to check that the destination node matches. */ nextHostNode = HostArc.otherNode(fromHostNode); if (nextLNode.matchWith(nextHostNode)) { /* if the nodes match than we can update locations and re-invoke the recursion. It is important * to copy the locatedNodes to a new list, just in case the above foreach statement finds * several matches for our new new L node.*/ List<node> newlocatedNodes = new List<node>(locatedNodes); newlocatedNodes[L.nodes.FindIndex(delegate(node a) { return (a == nextLNode); })] = nextHostNode; List<arc> newlocatedArcs = new List<arc>(locatedArcs); newlocatedArcs[currentLArcIndex] = HostArc; recognizeRecursion(host, newlocatedNodes, newlocatedArcs, nextLNode, nextHostNode); } } } }
/// <summary> /// Is the arc a free arc from this grammar rule? /// </summary> /// <param name = "a">A.</param> /// <param name = "host">The host.</param> /// <param name = "freeEndIdentifier">The free end identifier.</param> /// <param name = "neighborNode">The neighbor node.</param> /// <returns></returns> public static Boolean arcIsFree(arc a, designGraph host, out sbyte freeEndIdentifier, out node neighborNode) { if (a.From != null && a.To != null && !host.nodes.Contains(a.From) && !host.nodes.Contains(a.To)) { freeEndIdentifier = 0; /* if the nodes on either end of the freeArc are pointing to previous nodes * that were deleted in the first pushout then neighborNode is null (and as * a result any rules using the neighborNodeLabel will not apply) and the * freeEndIdentifier is zero. */ neighborNode = null; return true; } if (a.From != null && !host.nodes.Contains(a.From)) { freeEndIdentifier = -1; /* freeEndIdentifier set to -1 means that the From end of the arc must be the free end.*/ neighborNode = a.To; return true; } if (a.To != null && !host.nodes.Contains(a.To)) { freeEndIdentifier = +1; /* freeEndIdentifier set to +1 means that the To end of the arc must be the free end.*/ neighborNode = a.From; return true; } /* else, the arc is not a free arc after all and we simply break out * of this loop and try the next arc. */ freeEndIdentifier = 0; neighborNode = null; return false; }
internal Boolean ruleIsRecognized(hyperarc dangleHyperArc, List<node> neighborNodes, node nodeRemoved) { IEnumerable<string> neighborlabels = null ; neighborlabels = neighborNodes.Aggregate(neighborlabels, (current, n) => current.Union(n.localLabels)); return ((labelsMatch(dangleHyperArc.localLabels, neighborlabels.ToList())) && ((nodeRemoved == null) || (dangleHyperArc.nodes.Contains(nodeRemoved)))); }
public void addArc(Type arcType, node fromNode, node toNode) { string name = Guid.NewGuid().ToString(); addArc(name, arcType, fromNode, toNode); }