/// <summary>
 /// This occurs when the renderer's tool is set to clickTool. It gets the
 /// location of the mouseclick relative to the rederer.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void FieldViewClick(object sender, ClickedEventArgs e)
 {
     if (!complete)
     {
         bool outside = !f.shape.IsInside(e.Location);
         if (outside)
         {
             reset();
             Error_OutsideField.Show();
         }
         bool inside = false;
         foreach (Polygon p in f.blocks())
         {
             if (p.IsInside(e.Location))
             {
                 inside = true;
                 break;
             }
         }
         if (!outside && inside)
         {
             reset();
             Error_InsideItem.Show();
         }
         if (!outside && !inside)
         {
             reset();
             point = e.Location;
             pointRend.Coordinates2D = e.Location;
             pointRend.Show = true;
             OK.Enabled = true;
         }
     }
     else
     {
         bool outside = true;
         bool inside = false;
         foreach (Field s in fields)
         {
             if (s.shape.IsInside(e.Location))
             {
                 outside = false;
                 f = s;
             }
             foreach (Polygon p in s.blocks())
             {
                 if (p.IsInside(e.Location))
                 {
                     inside = true;
                     break;
                 }
             }
         }
         if (outside)
         {
             reset();
             OK.Enabled = true;
             Error_OutsideField.Show();
         }
         else if (inside)
         {
             reset();
             OK.Enabled = true;
             Error_InsideItem.Show();
         }
         else
         {
             PRMs[fields.IndexOf(f)].addPoint(e.Location.X, e.Location.Y);
             PointRenderable p = new PointRenderable(e.Location);
             rend.AddRenderable(p);
             pm = new PRMNavigationPlanner(PRMs, "").getPathMap();
             foreach (PathRenderable pr in lines)
             {
                 rend.RemoveRenderable(pr);
             }
             foreach (PathMapNode pmn in pm.map)
             {
                 PathRenderable line = new PathRenderable(new List<Vector2>() { pmn.v1.Item1, pmn.v2.Item1 });
                 line.DisplayColor = Color.Blue;
                 lines.Add(line);
                 rend.AddRenderable(line);
             }
         }
     }
 }
Exemple #2
0
 /// <summary>
 /// This occurs when the renderer's tool is set to clickTool. It gets the
 /// location of the mouseclick relative to the rederer.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void FieldViewClick(object sender, ClickedEventArgs e)
 {
     Vector2 location = e.Location;
     if (drawType == types.fields)
     {
         location = getNearest(location, 0.3, subFields.Values.ToList());
         if (checkInside(location))
         {
             Error inside = new Error(errorTypes.PointInside);
             inside.ShowDialog();
             inside.Dispose();
             return;
         }
     }
     bool intersects = false;
     Vector2 v1 = location - newPoly[newPoly.Count - 1];
     DEASL.Core.Mathematics.Shapes.LineSegment line1 =
         new DEASL.Core.Mathematics.Shapes.LineSegment(location, newPoly[newPoly.Count - 1] + 0.00001 * v1);
     for (int i = 1; i < newPoly.Count; i++)
     {
         Vector2 temp;
         DEASL.Core.Mathematics.Shapes.LineSegment ls = new DEASL.Core.Mathematics.
             Shapes.LineSegment(newPoly[i], newPoly[i - 1]);
         if (ls.Intersect(line1, out temp))
         {
             intersects = true;
             break;
         }
     }
     if (intersects)
     {
         Error intersect = new Error(errorTypes.Intersect);
         intersect.ShowDialog();
         intersect.Dispose();
     }
     else
     {
         newPoly.Add(location);
         firstPointRend.Coordinates2D = newPoly.points[0];
         firstPointRend.Show = true;
         newPolyRend.UpdatePoints(newPoly.points);
     }
 }