示例#1
0
        /// <summary>
        /// Searches for a vertex based on a screen position
        /// </summary>
        /// <param name="position">The screen position</param>
        /// <returns>The closest vertex or null if no vertex is within a certain range</returns>
        string GetVertexFromPosition(System.Drawing.Point position)
        {
            Vector3 screencoord = new Vector3(position.X, position.Y, 0);
            Vector3 worldcoord  = ScreenToWorld(screencoord);

            string selected = null;
            double dist     = double.MaxValue;

            Vector3 clickPos = new Vector3(worldcoord.X, worldcoord.Y, 0f);

            foreach (string v in _network.GetVertexArray())
            {
                Vector3 p = Layout.GetPositionOfNode(v);
                p.Z = 0f;

                if ((p - clickPos).Length < dist && (p - clickPos).Length < MarkerSize)
                {
                    dist     = (p - clickPos).Length;
                    selected = v;
                }
            }
            if (selected != null)
            {
                Console.WriteLine("Selected node: " + selected);
            }
            else
            {
                Console.WriteLine("No node. Clicked at " + position.X + "," + position.Y);
            }
            return(selected);
        }
 private static void Draw(XGraphics g, IRenderableNet n, LayoutProvider layout, NetworkColorizer colorizer)
 {
     lock (n)
     {
         if (g == null)
             return;
         g.SmoothingMode = PdfSharp.Drawing.XSmoothingMode.HighQuality;
         g.Clear(Color.White);
         foreach (var e in n.GetEdgeArray())
             if (string.Compare(e.Item1, e.Item2) >= 0)
                 DrawEdge(g, e, layout, colorizer);
         foreach (string v in n.GetVertexArray())
             DrawVertex(g, v, layout, colorizer);
     }
 }
 private static void Draw(XGraphics g, IRenderableNet n, LayoutProvider layout, NetworkColorizer colorizer)
 {
     lock (n)
     {
         if (g == null)
         {
             return;
         }
         g.SmoothingMode = PdfSharp.Drawing.XSmoothingMode.HighQuality;
         g.Clear(Color.White);
         foreach (var e in n.GetEdgeArray())
         {
             if (string.Compare(e.Item1, e.Item2) >= 0)
             {
                 DrawEdge(g, e, layout, colorizer);
             }
         }
         foreach (string v in n.GetVertexArray())
         {
             DrawVertex(g, v, layout, colorizer);
         }
     }
 }