Esempio n. 1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics gfx = e.Graphics;

            try
            {
                gfx.SmoothingMode = SmoothingMode.AntiAlias;

                foreach (ArborNode node in fSys.Nodes)
                {
                    var xnode = node as ArborNodeEx;

                    xnode.Box = getNodeRect(gfx, node);
                    gfx.FillRectangle(new SolidBrush(xnode.Color), xnode.Box);
                    gfx.DrawString(node.Sign, fDrawFont, fWhiteBrush, xnode.Box, fStrFormat);
                }

                using (Pen grayPen = new Pen(Color.Gray, 1))
                {
                    grayPen.StartCap = LineCap.NoAnchor;
                    grayPen.EndCap   = LineCap.ArrowAnchor;

                    foreach (ArborEdge edge in fSys.Edges)
                    {
                        var srcNode = edge.Source as ArborNodeEx;
                        var tgtNode = edge.Target as ArborNodeEx;

                        ArborPoint pt1 = fSys.GetViewCoords(srcNode.Pt);
                        ArborPoint pt2 = fSys.GetViewCoords(tgtNode.Pt);

                        ArborPoint tail = intersect_line_box(pt1, pt2, srcNode.Box);
                        ArborPoint head = (tail.IsNull()) ? ArborPoint.Null : intersect_line_box(tail, pt2, tgtNode.Box);

                        if (!head.IsNull() && !tail.IsNull())
                        {
                            gfx.DrawLine(grayPen, (int)tail.X, (int)tail.Y, (int)head.X, (int)head.Y);
                        }
                    }
                }

                if (fEnergyDebug)
                {
                    string energy = "max=" + fSys.EnergyMax.ToString("0.00000") + ", mean=" + fSys.EnergyMean.ToString("0.00000");
                    gfx.DrawString(energy, fDrawFont, fBlackBrush, 10, 10);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ArborViewer.OnPaint(): " + ex.Message);
            }

            base.OnPaint(e);
        }
Esempio n. 2
0
        private void AV_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            try {
                var gfx = args.DrawingSession;
                gfx.Antialiasing = CanvasAntialiasing.Antialiased;

                for (int i = 0, edgesCount = fSystem.Edges.Count; i < edgesCount; i++)
                {
                    ArborEdge edge = fSystem.Edges[i];

                    var sourceNode = (ArborNodeEx)edge.Source;
                    var targetNode = (ArborNodeEx)edge.Target;

                    ArborPoint pt1 = fSystem.GetViewCoords(sourceNode.Pt);
                    ArborPoint pt2 = fSystem.GetViewCoords(targetNode.Pt);

                    ArborPoint tail = IntersectLineBox(pt1, pt2, sourceNode.Box);
                    ArborPoint head = (tail.IsNull()) ? ArborPoint.Null : IntersectLineBox(tail, pt2, targetNode.Box);

                    if (!head.IsNull() && !tail.IsNull())
                    {
                        gfx.DrawLine((float)tail.X, (float)tail.Y, (float)head.X, (float)head.Y, Colors.Gray, 1);
                    }
                }

                for (int i = 0, nodesCount = fSystem.Nodes.Count; i < nodesCount; i++)
                {
                    ArborNodeEx node = (ArborNodeEx)fSystem.Nodes[i];

                    node.Box = GetNodeRect(gfx, node);
                    gfx.FillRectangle(node.Box, node.Color);
                    gfx.DrawText(node.Sign, node.Box, Colors.White, fStrFormat);
                }

                if (fEnergyDebug)
                {
                    string energy = "max=" + fSystem.EnergyMax.ToString("0.00000") + ", mean=" + fSystem.EnergyMean.ToString("0.00000");
                    gfx.DrawText(energy, 10, 10, Colors.Black);
                }
            } catch (Exception ex) {
                Debug.WriteLine("ArborViewer.OnPaint(): " + ex.Message);
            }
        }