Beispiel #1
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);
     }
 }
Beispiel #2
0
        /// <summary>
        /// When Add is clicked, it switches to Done. A popup of AddPoly appears asking for
        /// what type of new item is desired. Then the actual drawing is commenced.
        /// If one wishes to stop before finishing a object, region, or field, click Stop and
        /// the shape will be deleted.
        /// If one wishes to stop creating walls, then click Stop and that set of walls will remain.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Add_Click(object sender, EventArgs e)
        {
            if (Add.Text == "Add")  //Button said add so new polygon
            {
                AddPoly popup = new AddPoly(accRobot, mainField.walls.Keys.ToList<string>(),
                    mainField.objects.Keys.ToList<string>(), mainField.regions.Keys.ToList<string>(),
                    subFields.Keys.ToList<string>());
                popup.ShowDialog();
                accRobot = popup.accRobot;
                if (popup.finished)
                {
                    Add.Text = "Stop";
                    rend.Tool = polyTool;
                    newName = popup.name;
                    drawType = popup.drawType;
                    Ctrl_press.Show();
                }
                popup.Dispose();
            }
            else        //Button said Stop so stop current job.
            {
                if (drawType == types.walls && newPoly.Count > 1)
                {
                    double thickness = accRobot ? robotR : wallR;
                    mainField.addWall(newName, newPoly.points, thickness);
                    List<Polygon> comp = new List<Polygon>();
                    foreach (List<Polygon> p in mainField.walls.Values)
                    {
                        comp.AddRange(p);
                    }
                    wallsRend.Polygons = comp;
                    Walls_Box.Items.Add(newName);
                }
                else if (newPoly.Count > 2)
                {
                        bool intersects = false;
                        Vector2 v2 = newPoly[0] - newPoly[newPoly.Count - 1];
                        DEASL.Core.Mathematics.Shapes.LineSegment line2 = new DEASL.Core.Mathematics.Shapes.
                            LineSegment(newPoly[0] - 0.00001 * v2, newPoly[newPoly.Count - 1] + 0.00001 * v2);

                        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(line2, out temp))
                            {
                                intersects = true;
                                break;
                            }
                        }
                        if (intersects)
                        {
                            Error intersect = new Error(errorTypes.Intersect);
                            intersect.ShowDialog();
                            intersect.Dispose();
                        }
                        else
                        {
                            AddPolygon();
                        }
                }
                resetParameters();
                Ctrl_press.Hide();
            }
        }