/// <summary>
        /// Removes display objects matching a certain filter
        /// </summary>
        /// <param name="filter"></param>
        public void RemoveDisplayObjectType(DisplayObjectFilter filter)
        {
            // recreation of object list
            List<IDisplayObject> newDisplayObjects = new List<IDisplayObject>();

            // loop over display objects
            foreach (IDisplayObject ido in this.displayObjects)
            {
                // check type
                if (!(filter(ido)))
                {
                    // add to new list
                    newDisplayObjects.Add(ido);
                }
            }

            // set display object
            this.displayObjects = newDisplayObjects;
        }
        public HitTestResult HitTest(UrbanChallenge.Common.Coordinates loc, float tol, WorldTransform wt, DisplayObjectFilter filter)
        {
            if (this.SafetyPolygon == null)
            {
                /*if (this.safetyZoneBegin.Equals(this.safetyZoneEnd))
                 * {
                 *      Console.WriteLine("dupilicate safety zone changed" + this.safetyZoneBegin.Location.ToString());
                 *      this.safetyZoneBegin = this.lane.LanePath().StartPoint;
                 * }*/

                this.GenerateSafetyZone();
            }

            if (this.SafetyPolygon.IsInside(loc) && DrawingUtility.DrawArbiterSafetyZones)
            {
                Coordinates center = new Coordinates((this.safetyZoneBegin.Location.X + this.safetyZoneEnd.Location.X) / 2.0,
                                                     (this.safetyZoneEnd.Location.Y + this.safetyZoneBegin.Location.Y) / 2.0);
                return(new HitTestResult(this, true, (float)loc.DistanceTo(center)));
            }
            else
            {
                return(new HitTestResult(this, false, float.MaxValue));
            }
        }
        /// <summary>
        /// What to do when mouse moves
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            #region Left

            if (e.Button == MouseButtons.Left)
            {
                // dragging vehicle
                if (this.selected != null && this.selected is CarDisplayObject && isDragging && this.temporaryCoordinate.HasValue)
                {
                    // Get the offset.
                    Point point = e.Location;

                    // new coord
                    Coordinates newCoord = this.transform.GetWorldPoint(new PointF(point.X, point.Y));

                    // calc offse
                    Coordinates offset = newCoord - this.temporaryCoordinate.Value;

                    // moving object
                    CarDisplayObject cdo = (CarDisplayObject)this.selected;

                    // check we are not tracking
                    if (this.tracked != null && cdo.Equals(this.tracked))
                    {
                        this.tracked = null;
                    }

                    // move
                    cdo.InMove(this.temporaryCoordinate.Value, offset, this.transform);

                    // check snap pos or heading
                    if (cdo.SnapHeading || cdo.SnapPosition)
                    {
                        // filter for vehicles
                        DisplayObjectFilter partitionDof = delegate(IDisplayObject target)
                        {
                            // check if target is network object
                            if (target is ArbiterLanePartition)
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        };

                        // check to see if selected a partition
                        HitTestResult vhcHtr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), partitionDof);

                        // check hit
                        if (vhcHtr.Hit)
                        {
                            // get partition
                            ArbiterLanePartition alp = (ArbiterLanePartition)vhcHtr.DisplayObject;

                            // heading
                            Coordinates heading = alp.Vector();

                            // position
                            Coordinates closest = alp.PartitionPath.GetPoint(alp.PartitionPath.GetClosestPoint(transform.GetWorldPoint(new PointF(e.X, e.Y))));

                            if (cdo.SnapPosition)
                            {
                                cdo.Position = closest;
                            }

                            if (cdo.SnapHeading)
                            {
                                cdo.Heading = heading;
                            }
                        }
                    }
                }
                else if (this.selected != null && this.selected is SimObstacle && isDragging && this.temporaryCoordinate.HasValue)
                {
                    // Get the offset.
                    Point point = e.Location;

                    // new coord
                    Coordinates newCoord = this.transform.GetWorldPoint(new PointF(point.X, point.Y));

                    // calc offse
                    Coordinates offset = newCoord - this.temporaryCoordinate.Value;

                    // moving object
                    SimObstacle so = (SimObstacle)this.selected;

                    // move
                    so.InMove(this.temporaryCoordinate.Value, offset, this.transform);
                }
                // check if user is dragging
                else if (isDragging)
                {
                    // Get the offset.
                    Point point = (Point)controlTag;

                    // Calculate change in position
                    double deltaX = e.X - point.X;
                    double deltaY = e.Y - point.Y;

                    // Update the world
                    Coordinates tempCenter = WorldTransform.CenterPoint;
                    tempCenter.X -= deltaX / WorldTransform.Scale;
                    tempCenter.Y += deltaY / WorldTransform.Scale;
                    WorldTransform.CenterPoint = tempCenter;

                    // update control
                    controlTag = new Point(e.X, e.Y);
                }

                // redraw
                this.Invalidate();
            }

            #endregion

            #region Right

            else if (e.Button == MouseButtons.Right)
            {
                if (this.selected != null && this.selected is SimObstacle && isDragging && this.temporaryCoordinate.HasValue)
                {
                    // Get the offset.
                    Point point = e.Location;

                    // new coord
                    Coordinates newCoord = this.transform.GetWorldPoint(new PointF(point.X, point.Y));

                    // moving object
                    SimObstacle so = (SimObstacle)this.selected;

                    // calc new rel heading
                    Coordinates offset = newCoord - so.Position;

                    // calc degree diff
                    //double rotDiff = offset.ToDegrees() - this.temporaryCoordinate.Value.ToDegrees();

                    // new head
                    //Coordinates newHead = so.Heading.Rotate(rotDiff);

                    // set
                    so.Heading = offset;

                    this.Invalidate();
                }
            }

            #endregion

            base.OnMouseMove(e);
        }
        /// <summary>
        /// Performs a hit test over all display objects, starting with the currently selected object (and its parents).
        /// </summary>
        /// <param name="worldCoords">World coordinates (i.e. in meters) of the location to test.</param>
        /// <param name="filter">Delegate used for filtering the hit test results.</param>
        /// <returns>A valid hit test object with the Hit property set to true if a hit occurred. Hit is false otherwise.</returns>
        /// <remarks>This does not set the selected object. It is up to the caller to decide what to do with the results.</remarks>
        public HitTestResult HitTest(Coordinates worldCoords, DisplayObjectFilter filter)
        {
            // calculate the hit tolerance (make it scale independent)
            float tol = hitPixelTol / transform.Scale;

            // current min
            HitTestResult min = new HitTestResult(null, false, float.MaxValue);

            // loop through the display objects and check each and return one if found
            for (int i = displayObjects.Count - 1; i >= 0; --i)
            {
                if (filter(displayObjects[i]))
                {
                    HitTestResult tmp = displayObjects[i].HitTest(worldCoords, tol, this.transform, filter);

                    if (tmp.Hit == true && (min.DisplayObject == null || min.Dist > tmp.Dist))
                    {
                        min = tmp;
                    }
                }
            }

            // return the minimum
            return min;
        }
 public HitTestResult HitTest(Coordinates loc, float tol, WorldTransform wt, DisplayObjectFilter filter)
 {
     throw new Exception("The method or operation is not implemented.");
 }
        /// <summary>
        /// What to do when user clicks display
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            #region Hit Test

            // filter for vehicles or obstacles
            DisplayObjectFilter dof = delegate(IDisplayObject target)
            {
                // check if target is network object
                if (target is CarDisplayObject || target is SimObstacle)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            };

            // perform the hit test over the filter
            HitTestResult htr = this.HitTest(transform.GetWorldPoint(new PointF(e.X, e.Y)), dof);

            // check current selection if need to set as not selected
            if (this.selected != null && (htr.Hit && !this.selected.Equals(htr.DisplayObject)) ||
                (!htr.Hit))
            {
                if (this.selected != null)
                {
                    // remove current selection
                    this.selected.Selected = SelectionType.NotSelected;
                }

                this.selected = null;
                this.Simulation.simEngine.SetPropertyGridDefault();
            }

            #endregion

            #region Left

            if (e.Button == MouseButtons.Left)
            {
                // check if we hit a vehicle
                if (htr.Hit && htr.DisplayObject is SimVehicle)
                {
                    // display obj
                    CarDisplayObject cdo = (CarDisplayObject)htr.DisplayObject;

                    // set the vehicles as selected
                    cdo.Selected  = SelectionType.SingleSelected;
                    this.selected = cdo;
                    this.Simulation.simEngine.propertyGrid.SelectedObject = cdo;

                    // check if we can move the vehicle
                    if (!((SimVehicle)cdo).VehicleState.IsBound)
                    {
                        // set dragging
                        isDragging     = true;
                        Cursor.Current = Cursors.Hand;

                        // set temp
                        this.temporaryCoordinate = cdo.Position;
                    }

                    // redraw
                    this.Invalidate();
                }
                // check if hit obstacle
                else if (htr.Hit && htr.DisplayObject is SimObstacle)
                {
                    // set selected
                    this.selected          = htr.DisplayObject;
                    this.selected.Selected = SelectionType.SingleSelected;
                    this.Simulation.simEngine.propertyGrid.SelectedObject = this.selected;

                    // check if can move
                    if (((SimObstacle)htr.DisplayObject).MoveAllowed)
                    {
                        // set dragging
                        isDragging     = true;
                        Cursor.Current = Cursors.Hand;

                        // set temp
                        this.temporaryCoordinate = ((SimObstacle)this.selected).Position;
                    }

                    // redraw
                    this.Invalidate();
                }
                else
                {
                    controlTag     = new Point(e.X, e.Y);
                    isDragging     = true;
                    Cursor.Current = Cursors.Hand;
                }
            }

            #endregion

            #region Right

            else if (e.Button == MouseButtons.Right)
            {
                if (htr.Hit && htr.DisplayObject is CarDisplayObject)
                {
                    this.selected = htr.DisplayObject;
                    this.Simulation.simEngine.propertyGrid.SelectedObject = this.selected;
                    this.vehicleContextMenuStrip1.Show(this, e.X, e.Y);
                    ((CarDisplayObject)this.selected).Selected = SelectionType.SingleSelected;
                }
                else if (htr.Hit && htr.DisplayObject is SimObstacle)
                {
                    // set selected
                    this.selected          = htr.DisplayObject;
                    this.selected.Selected = SelectionType.SingleSelected;
                    this.Simulation.simEngine.propertyGrid.SelectedObject = this.selected;

                    // check if we can move the obstacle
                    if (((SimObstacle)htr.DisplayObject).MoveAllowed)
                    {
                        // set dragging
                        isDragging     = true;
                        Cursor.Current = Cursors.Hand;

                        // set temp
                        this.temporaryCoordinate = transform.GetWorldPoint(new PointF(e.X, e.Y)) - ((SimObstacle)this.selected).Position;
                    }

                    // redraw
                    this.Invalidate();
                }
            }

            #endregion

            base.OnMouseDown(e);
            this.Invalidate();
        }
 /// <summary>
 /// Perform a test to see if this is selected
 /// </summary>
 /// <param name="loc"></param>
 /// <param name="tol"></param>
 /// <param name="filter"></param>
 /// <returns></returns>
 public HitTestResult HitTest(Coordinates loc, float tol, WorldTransform wt, DisplayObjectFilter filter)
 {
     // return a no-hit
     return(new HitTestResult(this, false, float.MaxValue));
 }
 public HitTestResult HitTest(UrbanChallenge.Common.Coordinates loc, float tol, WorldTransform wt, DisplayObjectFilter filter)
 {
     return new HitTestResult(this, false, float.MaxValue);
 }
        public HitTestResult HitTest(UrbanChallenge.Common.Coordinates loc, float tol, WorldTransform wt, DisplayObjectFilter filter)
        {
            double dist = this.PartitionPath.GetClosestPoint(loc).Location.DistanceTo(loc);

            if (dist < 5)
            {
                return new HitTestResult(this, true, (float)dist);
            }
            else
            {
                return new HitTestResult(this, false, float.MaxValue);
            }
        }
示例#10
0
        public HitTestResult HitTest(UrbanChallenge.Common.Coordinates loc, float tol, WorldTransform wt, DisplayObjectFilter filter)
        {
            // check filter
            if (filter.Target == null || filter.Target is ArbiterParkingSpotWaypoint)
            {
                // 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));
        }
 public HitTestResult HitTest(Coordinates loc, float tol, WorldTransform wt, DisplayObjectFilter filter)
 {
     throw new Exception("The method or operation is not implemented.");
 }
示例#12
0
        public HitTestResult HitTest(UrbanChallenge.Common.Coordinates loc, float tol, WorldTransform wt, DisplayObjectFilter filter)
        {
            if (filter(this))
            {
                Coordinates closest = this.GetClosest(loc);

                if ((float)loc.DistanceTo(closest) < 5 + tol)
                {
                    return(new HitTestResult(this, true, (float)loc.DistanceTo(closest)));
                }
            }

            return(new HitTestResult(this, false, float.MaxValue));
        }
        public HitTestResult HitTest(UrbanChallenge.Common.Coordinates loc, float tol, WorldTransform wt, DisplayObjectFilter filter)
        {
            if (this.SafetyPolygon == null)
            {
                /*if (this.safetyZoneBegin.Equals(this.safetyZoneEnd))
                {
                    Console.WriteLine("dupilicate safety zone changed" + this.safetyZoneBegin.Location.ToString());
                    this.safetyZoneBegin = this.lane.LanePath().StartPoint;
                }*/

                this.GenerateSafetyZone();
            }

            if (this.SafetyPolygon.IsInside(loc) && DrawingUtility.DrawArbiterSafetyZones)
            {
                Coordinates center = new Coordinates((this.safetyZoneBegin.Location.X + this.safetyZoneEnd.Location.X) / 2.0,
                    (this.safetyZoneEnd.Location.Y + this.safetyZoneBegin.Location.Y) / 2.0);
                return new HitTestResult(this, true, (float)loc.DistanceTo(center));
            }
            else
                return new HitTestResult(this, false, float.MaxValue);
        }
 /// <summary>
 /// Perform a test to see if this is selected
 /// </summary>
 /// <param name="loc"></param>
 /// <param name="tol"></param>
 /// <param name="filter"></param>
 /// <returns></returns>
 public HitTestResult HitTest(Coordinates loc, float tol, WorldTransform wt, DisplayObjectFilter filter)
 {
     // return a no-hit
     return new HitTestResult(this, false, float.MaxValue);
 }
        public HitTestResult HitTest(UrbanChallenge.Common.Coordinates loc, float tol, WorldTransform wt, DisplayObjectFilter filter)
        {
            if (filter(this))
            {
                Coordinates closest = this.GetClosest(loc);

                if ((float)loc.DistanceTo(closest) < 5 + tol)
                {
                    return new HitTestResult(this, true, (float)loc.DistanceTo(closest));
                }
            }

            return new HitTestResult(this, false, float.MaxValue);
        }
        public HitTestResult HitTest(UrbanChallenge.Common.Coordinates loc, float tol, WorldTransform wt, DisplayObjectFilter filter)
        {
            // check filter
            if (filter.Target == null || filter.Target is ArbiterParkingSpotWaypoint)
            {
                // 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);
        }
示例#17
0
        public HitTestResult HitTest(UrbanChallenge.Common.Coordinates loc, float tol, WorldTransform wt, DisplayObjectFilter filter)
        {
            double dist = this.PartitionPath.GetClosestPoint(loc).Location.DistanceTo(loc);

            if (dist < 5)
            {
                return(new HitTestResult(this, true, (float)dist));
            }
            else
            {
                return(new HitTestResult(this, false, float.MaxValue));
            }
        }
 public HitTestResult HitTest(UrbanChallenge.Common.Coordinates loc, float tol, WorldTransform wt, DisplayObjectFilter filter)
 {
     return(new HitTestResult(this, false, float.MaxValue));
 }
        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.Center));
                }
            }

            return new HitTestResult(this, false, float.MaxValue);
        }