예제 #1
0
        public void initializeGraphControl(Netron.GraphLib.UI.GraphControl graphControl1,
            Label globalLabelsText)
        {
            Random rnd = new Random();

            #region display the nodes
            for (int i = nodes.Count - 1; i >= 0; i--)
            {
                node n = nodes[i];
                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);
                }
                List<string> shapeData = StringCollectionConverter.convert(n.shapekey);
                if (shapeData.Count == 0) shapeData.Add("");
                n.displayShape = graphControl1.AddShape(shapeData[0], new PointF(n.screenX, n.screenY));
                if (shapeData.Count > 1)
                {
                    n.displayShape.ShapeColor = Color.FromArgb(int.Parse(shapeData[1]));
                    n.displayShape.Width = float.Parse(shapeData[2]);
                    n.displayShape.Height = float.Parse(shapeData[3]);
                }
            }
            #endregion
            #region display the arcs
            foreach (arc a in arcs)
            {
                node fromNode = a.From;
                node toNode = a.To;

                Connector fromConnect = null;
                Connector toConnect = null;
                if ((fromNode == null) || (fromNode.displayShape == null))
                {
                    a.fromConnector = 0;
                    fromConnect = addNullShape(graphControl1, 0).Connectors[0];
                }
                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;
                    toConnect = addNullShape(graphControl1, 1).Connectors[0];
                }
                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]; }

                a.displayShape = graphControl1.AddConnection(fromConnect, toConnect);
                a.displayShape.ShowLabel = true;

                List<string> styleData = StringCollectionConverter.convert(a.styleKey);
                if (styleData.Count > 0) a.displayShape.LinePath = styleData[0];
                if (styleData.Count > 1)
                {
                    a.displayShape.LineColor = Color.FromArgb(int.Parse(styleData[1]));
                    a.displayShape.LineWeight = (ConnectionWeight)int.Parse(styleData[2]);
                    a.displayShape.LineStyle = (System.Drawing.Drawing2D.DashStyle)int.Parse(styleData[3]);
                }
            }
            #endregion
            this.updateGraphControl(graphControl1, globalLabelsText);
        }
예제 #2
0
        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);
            }
        }