Example #1
0
        void ToolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
        {
            foreach (NodeTypeEntry nte in m_NodeTypes)
            {
                if (nte.Button == e.Button)
                {
                    var center = new Point();
                    var random = new Random(1);

                    var   rect1 = gViewer.ClientRectangle; //gViewer.Graph.GeometryGraph.BoundingBox;
                    var   rect2 = gViewer.Graph.BoundingBox;
                    Point p     = gViewer.ScreenToSource(rect1.Location);
                    Point p2    = gViewer.ScreenToSource(rect1.Location + rect1.Size);
                    if (p.X < rect2.Left)
                    {
                        p.X = rect2.Left;
                    }
                    if (p2.X > rect2.Right)
                    {
                        p2.X = rect2.Right;
                    }
                    if (p.Y > rect2.Top)
                    {
                        p.Y = rect2.Top;
                    }
                    if (p2.Y < rect2.Bottom)
                    {
                        p2.Y = rect2.Bottom;
                    }
                    var rect = new Microsoft.Msagl.Core.Geometry.Rectangle(p, p2);

                    center.X = rect.Left + random.NextDouble() * rect.Width;
                    center.Y = rect.Bottom + random.NextDouble() * rect.Height;

                    DrawingNode n = InsertNode(center, nte);
                    if (NodeInsertedByUser != null)
                    {
                        NodeInsertedByUser(n);
                    }
                }
            }
        }
Example #2
0
        void gviewer_mouseup(object sender, MsaglMouseEventArgs e)
        {
            if (_useOpMode == UserOprationMode.Select)
            {
                var obj = gViewer.GetObjectAt(new Point(e.X, e.Y));
                if (obj == null)
                {
                    return;
                }
                var node = obj as DNode;
                if (node != null)
                {
                    Text = node.DrawingNode.Id;
                }
                else
                {
                    var edge = obj as DEdge;
                    Text = edge.Edge.Source;
                }
            }
            else if (_useOpMode == UserOprationMode.AddNode)
            {
                var pos = gViewer.ScreenToSource(e);
                //var node = new Node("smt");

                var gv = gViewer;
                gv.AddNode(gv.CreateIViewerNode(new Node("ssss"), pos, null), true);
                var ggg = gv.Graph;
                if (ggg.NodeCount > 100)
                {
                    ;
                }
                ////(gv as IViewer).a   .add(), pos, null);
                ////node.LabelText = "smt show";
                //var graph = gViewer.Graph;
                ////graph.AddNode(node);
                //graph.AddEdge("11", "222");
                ////DrawingUtilsForSamples.AddNode("smt", graph.GeometryGraph, 10, 2);
                //gViewer.Graph = graph;
                //var gv = gViewer;
                ////IViewerNode n=gViewer.CreateIViewerNode(new Node("smart"));
                ////gViewer.CreateIViewerNode(new Node("marks"), pos, null);
                ////gViewer.AddNode(n, true);
            }

            //var viewer = gViewer as IViewer;
            //viewer.
        }