示例#1
0
        /// <summary>
        /// Renders the lane splint
        /// </summary>
        /// <param name="g"></param>
        /// <param name="t"></param>
        /// <remarks>TODO: set lane spline</remarks>
        public void Render(System.Drawing.Graphics g, WorldTransform t)
        {
            Color c = DrawingUtility.ColorArbiterLaneSpline;

            if (DrawingUtility.DisplayArbiterLanes)
            {
                Coordinates cp = t.GetWorldPoint(new PointF(t.ScreenSize.Width / 2, t.ScreenSize.Height / 2));
                Coordinates lp = this.LanePath().GetClosestPoint(cp).Location;
                string      s  = this.LaneId.ToString();
                DrawingUtility.DrawControlLabel(lp, Color.DarkBlue, s, ContentAlignment.MiddleCenter, ControlPointStyle.None, g, t);
            }

            bool displayPolygon = false;

            switch (this.LaneId.Number)
            {
            case 1:
                displayPolygon = DrawingUtility.DisplayArbiterLanePolygon1;
                break;

            case 2:
                displayPolygon = DrawingUtility.DisplayArbiterLanePolygon2;
                break;

            case 3:
                displayPolygon = DrawingUtility.DisplayArbiterLanePolygon3;
                break;

            case 4:
                displayPolygon = DrawingUtility.DisplayArbiterLanePolygon4;
                break;
            }

            if (displayPolygon && this.LanePolygon != null)
            {
                // show intersection polygon
                HatchBrush hBrush1 = new HatchBrush(HatchStyle.ForwardDiagonal, DrawingUtility.ColorArbiterLanePolygon, Color.White);

                // populate polygon
                List <PointF> polyPoints = new List <PointF>();
                foreach (Coordinates lpp in this.LanePolygon.points)
                {
                    polyPoints.Add(DrawingUtility.ToPointF(lpp));
                }

                // draw poly and fill
                g.FillPolygon(hBrush1, polyPoints.ToArray());

                DrawingUtility.DrawControlPolygon(this.LanePolygon, DrawingUtility.ColorArbiterLanePolygon, System.Drawing.Drawing2D.DashStyle.Solid, g, t);
            }

            if (DrawingUtility.DisplayArbiterLanePath)
            {
                DrawingUtility.DrawControlLine(this.laneLinePath, g, t, new Pen(Color.MediumVioletRed), Color.MediumVioletRed);
            }
        }
示例#2
0
        public void Render(System.Drawing.Graphics g, WorldTransform t)
        {
            // show intersection safetyzone if supposed to show safety zone (polygon red hatch)
            if (DrawingUtility.DrawArbiterSafetyZones)
            {
                // show intersection polygon
                HatchBrush hBrush1 = new HatchBrush(HatchStyle.ForwardDiagonal, DrawingUtility.ColorArbiterSafetyZone, Color.White);

                // populate polygon
                List <PointF> polyPoints = new List <PointF>();
                foreach (Coordinates c in this.IntersectionPolygon.points)
                {
                    polyPoints.Add(DrawingUtility.ToPointF(c));
                }

                // draw poly and fill
                g.FillPolygon(hBrush1, polyPoints.ToArray());
            }

            // render stopped exits
            foreach (ArbiterStoppedExit ase in this.StoppedExits)
            {
                ase.Render(g, t);
            }

            // draw intersection polygon
            DrawingUtility.DrawControlPolygon(this.IntersectionPolygon,
                                              DrawingUtility.ColorArbiterIntersection,
                                              DashStyle.DashDotDot,
                                              g, t);

            // show incoming lane points (disjoint from exits)
            foreach (KeyValuePair <ArbiterLane, LinePath.PointOnPath> pop in this.IncomingLanePoints)
            {
                DrawingUtility.DrawControlPoint(pop.Key.LanePath().GetPoint(pop.Value), DrawingUtility.ColorArbiterIntersectionIncomingLanePoints, null,
                                                ContentAlignment.MiddleCenter, ControlPointStyle.SmallX, g, t);
            }

            // show all entries
            foreach (ITraversableWaypoint aw in this.AllEntries.Values)
            {
                DrawingUtility.DrawControlPoint(aw.Position, DrawingUtility.ColorArbiterIntersectionEntries, null,
                                                ContentAlignment.MiddleCenter, ControlPointStyle.LargeCircle, g, t);
            }

            // show all exits
            foreach (ITraversableWaypoint aw in this.AllExits.Values)
            {
                DrawingUtility.DrawControlPoint(aw.Position, DrawingUtility.ColorArbiterIntersectionExits, null,
                                                ContentAlignment.MiddleCenter, ControlPointStyle.LargeCircle, g, t);
            }

            // draw center point
            DrawingUtility.DrawControlPoint(this.Center, DrawingUtility.ColorArbiterIntersection, null, ContentAlignment.MiddleCenter, ControlPointStyle.LargeX, g, t);
        }
        public void Render(System.Drawing.Graphics g, WorldTransform t)
        {
            Color      c  = DrawingUtility.ColorArbiterSafetyZone;
            HatchBrush hb = new HatchBrush(HatchStyle.ForwardDiagonal, c, Color.White);

            using (Pen p = new Pen(hb, 3))
            {
                g.DrawLine(p,
                           DrawingUtility.ToPointF(safetyZoneBegin.Location),
                           DrawingUtility.ToPointF(safetyZoneEnd.Location));
            }
        }
示例#4
0
        public static GpcWrapper.Polygon ToGpcPolygon(UrbanChallenge.Common.Shapes.Polygon input)
        {
            GraphicsPath gp = new GraphicsPath();

            PointF[] polyPoints = new PointF[input.Count];

            for (int i = 0; i < input.Count; i++)
            {
                polyPoints[i] = DrawingUtility.ToPointF(input[i]);
            }

            gp.AddPolygon(polyPoints);
            return(new GpcWrapper.Polygon(gp));
        }
        public void Render(System.Drawing.Graphics g, WorldTransform t)
        {
            // show stopped exits (blue diags)
            HatchBrush hBrush1 = new HatchBrush(HatchStyle.ForwardDiagonal, DrawingUtility.ColorArbiterIntersectionStoppedExit, Color.White);

            // populate polygon
            List <PointF> polyPoints = new List <PointF>();

            foreach (Coordinates c in this.ExitPolygon.points)
            {
                polyPoints.Add(DrawingUtility.ToPointF(c));
            }

            // draw poly and fill
            g.FillPolygon(hBrush1, polyPoints.ToArray());
        }
示例#6
0
        public HitTestResult HitTest(Coordinates loc, float tol, WorldTransform wt, DisplayObjectFilter filter)
        {
            // check filter
            if (filter(this))
            {
                // get bounding box dependent on tolerance
                RectangleF bounding = this.GetBoundingBox(wt);
                bounding.Inflate(tol, tol);

                // check if contains point
                if (bounding.Contains(DrawingUtility.ToPointF(loc)))
                {
                    return(new HitTestResult(this, true, (float)loc.DistanceTo(this.Position)));
                }
            }

            return(new HitTestResult(this, false, float.MaxValue));
        }
        /// <summary>
        /// Renders the grid
        /// </summary>
        /// <param name="g"></param>
        /// <param name="t"></param>
        public void Render(System.Drawing.Graphics g, WorldTransform t)
        {
            // check if we are showinghte grid
            Coordinates wll = t.WorldLowerLeft;
            Coordinates wur = t.WorldUpperRight;

            // sapcing
            double tmpSpacing = (double)spacing;

            // num x lines
            double xNum = Math.Ceiling(Math.Abs(wll.X - wur.X) / tmpSpacing);

            // num y lines
            double yNum = Math.Ceiling(Math.Abs(wll.Y - wur.Y) / tmpSpacing);

            // check length
            if (xNum < 400 && yNum < 400)
            {
                // pen width
                float pw = 1.25f / t.Scale;

                // pen
                using (Pen p = new Pen(color, pw))
                {
                    // draw x lines
                    for (double i = Math.Floor(wll.X / tmpSpacing) * tmpSpacing; i <= Math.Ceiling(wur.X / tmpSpacing) * tmpSpacing; i += tmpSpacing)
                    {
                        g.DrawLine(p, DrawingUtility.ToPointF(new Coordinates(i, wur.Y)), DrawingUtility.ToPointF(new Coordinates(i, wll.Y)));
                    }

                    // draw y lines
                    for (double j = Math.Floor(wll.Y / tmpSpacing) * tmpSpacing; j <= Math.Ceiling(wur.Y / tmpSpacing) * tmpSpacing; j += tmpSpacing)
                    {
                        g.DrawLine(p, DrawingUtility.ToPointF(new Coordinates(wll.X, j)), DrawingUtility.ToPointF(new Coordinates(wur.X, j)));
                    }
                }
            }

            /*PointF ll = new PointF((float)wll.X, (float)wll.Y);
             * PointF ur = new PointF((float)wur.X, (float)wur.Y);
             *
             * float startX = (float)Math.Floor(wll.X / spacing) * spacing;
             * float endX = (float)Math.Ceiling(wur.X / spacing) * spacing;
             * float startY = (float)Math.Floor(wll.Y / spacing) * spacing;
             * float endY = (float)Math.Ceiling(wur.Y / spacing) * spacing;
             *
             * using (Pen p = new Pen(color, 1 / t.Scale))
             * {
             *      if (endX - startX / spacing < 400 && endY - startY / spacing < 400)
             *      {
             *              for (float x = startX; x <= endX; x += spacing)
             *              {
             *                      g.DrawLine(p, x, ll.Y, x, ur.Y);
             *              }
             *
             *              for (float y = startY; y <= endY; y += spacing)
             *              {
             *                      g.DrawLine(p, ll.X, y, ur.X, y);
             *              }
             *      }
             * }*/
        }
        public void NavigationHitTest(Coordinates c, out INavigableNode node, out NavigableEdge edge)
        {
            if (this.zt.current != null)
            {
                // Determine size of bounding box
                float scaled_offset = 1 / this.rd.WorldTransform.Scale;

                // invert the scale
                float scaled_size = DrawingUtility.cp_large_size;

                // assume that the world transform is currently applied correctly to the graphics
                RectangleF rect = new RectangleF((float)c.X - scaled_size / 2, (float)c.Y - scaled_size / 2, scaled_size, scaled_size);

                foreach (ArbiterParkingSpotWaypoint apsw in this.zt.current.ParkingSpotWaypoints.Values)
                {
                    if (apsw.Position.DistanceTo(c) < 1.0)
                    {
                        node = apsw;
                        edge = null;
                        return;
                    }
                }

                foreach (ArbiterPerimeterWaypoint apw in this.zt.current.Perimeter.PerimeterPoints.Values)
                {
                    if ((apw.IsExit || apw.IsEntry) && rect.Contains(DrawingUtility.ToPointF(apw.Position)) &&
                        (this.PreviousNode == null || !this.PreviousNode.Equals(apw)) &&
                        apw.Position.DistanceTo(c) < 1.0)
                    {
                        node = apw;
                        edge = null;
                        return;
                    }
                }

                foreach (INavigableNode inn in this.zt.current.NavigationNodes)
                {
                    if (rect.Contains(DrawingUtility.ToPointF(inn.Position)) &&
                        (this.PreviousNode == null || !this.PreviousNode.Equals(inn)) &&
                        inn.Position.DistanceTo(c) < 1.0)
                    {
                        node = inn;
                        edge = null;
                        return;
                    }
                }

                NavigableEdge closest  = null;
                double        distance = double.MaxValue;
                foreach (NavigableEdge ne in this.zt.current.NavigableEdges)
                {
                    LinePath lp   = new LinePath(new Coordinates[] { ne.Start.Position, ne.End.Position });
                    double   dist = lp.GetClosestPoint(c).Location.DistanceTo(c);
                    if (dist < rect.Width && (dist < distance || closest == null) && dist < 1.0)
                    {
                        closest  = ne;
                        distance = dist;
                    }
                }

                if (closest != null)
                {
                    node = null;
                    edge = closest;
                    return;
                }
            }

            node = null;
            edge = null;
            return;
        }
        public void Click(Coordinates c)
        {
            if (this.zt.Mode == ZoneToolboxMode.Selection)
            {
                this.zt.SelectZone(c);
            }
            else if (this.Mode == ZoneToolboxMode.NavNodes && this.zt.current != null)
            {
                // save undo point
                this.ed.SaveUndoPoint();

                // check if we hit any of hte edges or nodes part of the zone
                ArbiterZone az = this.zt.current;

                // check if hit node or edge
                NavigableEdge  ne;
                INavigableNode nn;
                this.NavigationHitTest(c, out nn, out ne);

                if (nn != null)
                {
                    // create new node
                    INavigableNode aznn = nn;

                    if (this.PreviousNode != null)
                    {
                        // create new edges
                        NavigableEdge newE1 = new NavigableEdge(true, this.zt.current, false, null, new List <IConnectAreaWaypoints>(), this.PreviousNode, aznn);
                        this.PreviousNode.OutgoingConnections.Add(newE1);
                        this.zt.current.NavigableEdges.Add(newE1);
                    }

                    this.PreviousNode = aznn;
                }
                else if (ne != null)
                {
                    // remove old
                    this.zt.current.NavigableEdges.Remove(ne);

                    // remove all references
                    ne.Start.OutgoingConnections.Remove(ne);

                    // create new node
                    ArbiterZoneNavigableNode aznn = new ArbiterZoneNavigableNode(c);

                    // create new edges
                    NavigableEdge newE1 = new NavigableEdge(true, this.zt.current, false, null, new List <IConnectAreaWaypoints>(), ne.Start, aznn);
                    NavigableEdge newE2 = new NavigableEdge(true, this.zt.current, false, null, new List <IConnectAreaWaypoints>(), aznn, ne.End);

                    // add edges
                    ne.Start.OutgoingConnections.Add(newE1);
                    aznn.OutgoingConnections.Add(newE2);

                    // add all to lists
                    this.zt.current.NavigableEdges.Add(newE1);
                    this.zt.current.NavigableEdges.Add(newE2);
                    this.zt.current.NavigationNodes.Add(aznn);

                    if (this.PreviousNode != null)
                    {
                        NavigableEdge newE3 = new NavigableEdge(true, this.zt.current, false, null, new List <IConnectAreaWaypoints>(), this.PreviousNode, aznn);
                        this.PreviousNode.OutgoingConnections.Add(newE3);
                        this.zt.current.NavigableEdges.Add(newE3);
                    }

                    this.PreviousNode = aznn;
                }
                else
                {
                    // create new node
                    ArbiterZoneNavigableNode aznn = new ArbiterZoneNavigableNode(c);

                    if (this.PreviousNode != null)
                    {
                        // create new edges
                        NavigableEdge newE1 = new NavigableEdge(true, this.zt.current, false, null, new List <IConnectAreaWaypoints>(), this.PreviousNode, aznn);
                        this.PreviousNode.OutgoingConnections.Add(newE1);
                        this.zt.current.NavigableEdges.Add(newE1);
                    }

                    this.PreviousNode = aznn;
                    this.zt.current.NavigationNodes.Add(aznn);
                }
            }
            else if (this.zt.Mode == ZoneToolboxMode.StayOut && this.zt.current != null)
            {
                if (this.WrappingHelpers.Count == 0)
                {
                    this.WrappingHelpers.Add(c);
                }
                else
                {
                    // Determine size of bounding box
                    float scaled_offset = 1 / this.rd.WorldTransform.Scale;

                    // invert the scale
                    float scaled_size = DrawingUtility.cp_large_size;

                    // assume that the world transform is currently applied correctly to the graphics
                    RectangleF rect = new RectangleF((float)c.X - scaled_size / 2, (float)c.Y - scaled_size / 2, scaled_size, scaled_size);

                    if (rect.Contains(DrawingUtility.ToPointF(this.WrappingHelpers[0])) &&
                        c.DistanceTo(this.WrappingHelpers[0]) < 1)
                    {
                        ed.SaveUndoPoint();
                        Polygon p = new Polygon(this.WrappingHelpers);
                        this.zt.current.StayOutAreas.Add(p);
                        this.WrappingHelpers = new List <Coordinates>();
                    }
                    else
                    {
                        this.WrappingHelpers.Add(c);
                    }
                }

                this.rd.Invalidate();
            }
        }