/// <summary> /// Initializes a new instance of the <see cref="ruleArc"/> class. /// Converts an arc to a ruleArc and returns it with default Booleans. /// The original arc is unaffected. /// </summary> /// <param name="a">A.</param> public ruleArc(arc a) : this(a.name) { TargetType = a.GetType().ToString(); directed = a.directed; DisplayShape = a.DisplayShape; doublyDirected = a.doublyDirected; From = a.From; To = a.To; localLabels.AddRange(a.localLabels); localVariables.AddRange(a.localVariables); }
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); } }