private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.selected is SimVehicle)
            {
                // vehicle
                SimVehicle isv = (SimVehicle)this.selected;

                // notfy
                SimulatorOutput.WriteLine("Removed Vehicle: " + isv.SimVehicleState.VehicleID.ToString());

                // remove
                this.displayObjects.Remove(this.selected);
                this.Simulation.simEngine.Vehicles.Remove(isv.VehicleId);
                this.Simulation.clientHandler.Remove(isv.VehicleId);
                this.Simulation.OnClientsChanged();

                if (this.tracked != null && this.tracked.VehicleId.Equals(isv.VehicleId))
                {
                    this.tracked = null;
                }

                // remove selecation
                this.selected = null;

                // properties
                this.Simulation.simEngine.SetPropertyGridDefault();

                // redraw
                this.Invalidate();
            }
        }
        private void vehicleContextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {
            if (this.selected is SimVehicle)
            {
                // vehicle
                SimVehicle isv = (SimVehicle)this.selected;

                if (isv.SimVehicleState.IsBound)
                {
                    this.bindToolStripMenuItem.Enabled      = false;
                    this.trackToolStripMenuItem.Enabled     = true;
                    this.unbindToolStripMenuItem.Enabled    = true;
                    this.stopTrackToolStripMenuItem.Enabled = true;
                    this.deleteToolStripMenuItem.Enabled    = true;
                }
                else
                {
                    this.bindToolStripMenuItem.Enabled      = true;
                    this.trackToolStripMenuItem.Enabled     = true;
                    this.unbindToolStripMenuItem.Enabled    = false;
                    this.stopTrackToolStripMenuItem.Enabled = true;
                    this.deleteToolStripMenuItem.Enabled    = true;
                }
            }
            else
            {
                this.bindToolStripMenuItem.Enabled      = false;
                this.trackToolStripMenuItem.Enabled     = false;
                this.unbindToolStripMenuItem.Enabled    = false;
                this.stopTrackToolStripMenuItem.Enabled = false;
                this.deleteToolStripMenuItem.Enabled    = false;
            }
        }
        private void unbindToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SimVehicle isv = (SimVehicle)this.selected;

            if (this.tracked != null && this.tracked.VehicleId.Equals(isv.VehicleId))
            {
                this.tracked = null;
            }

            ((SimVehicle)this.selected).SimVehicleState.IsBound = false;
            this.Invalidate();
        }
 private void stopTrackToolStripMenuItem_Click(object sender, EventArgs e)
 {
     this.tracked = null;
     this.Invalidate();
 }
 private void trackToolStripMenuItem_Click(object sender, EventArgs e)
 {
     this.tracked = (SimVehicle)this.selected;
     this.Invalidate();
 }
        /// <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);
        }