public void splitLeg(Leg leg, GeoCoord midLoc) { Distance dFrom = leg.WptFrom.distanceFrom(midLoc); Distance dTo = leg.WptTo.distanceFrom(midLoc); double ratio = dFrom.Meters / (dFrom.Meters + dTo.Meters); DateTime dt = leg.WptFrom.DateTime.AddTicks((long)(leg.Duration.Ticks * ratio)); if (leg.Duration.TotalSeconds > 60.0d) { dt = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second); // round to a second } // assuming that midLoc has been already "new" and will attach to the new waypoint: Waypoint wpt = new Waypoint(midLoc, dt, leg.WptFrom.LiveObjectType, leg.WptFrom.TrackId, "", leg.WptFrom.Source, ""); insertWaypoint(wpt); rebuildTrackBoundaries(); }
public override void ProcessMouseUp(Point upPoint, GeoCoord mouseGeoLocation, bool controlDown, bool shiftDown, bool altDown) { //LibSys.StatusBar.Trace("LayerWaypoints:ProcessMouseUp()"); if(movePointMode) { movePointMode = false; if(wptToMove != null) { if(!upPoint.Equals(m_downPoint)) { wptToMove.Location = mouseGeoLocation; WaypointsCache.isDirty = true; wptToMove = null; CameraManager.This.SpoilPicture(upPoint); CameraManager.This.ProcessCameraMove(); } else { Point screenPoint = m_pictureManager.PointToScreen(upPoint); Project.ShowPopup(m_pictureManager.PictureBox, " you can move this waypoint by dragging mouse where you want new waypoint location to be. ", screenPoint); wptToMove = null; } } } if(moveLegMode) { moveLegMode = false; if(!upPoint.Equals(m_downPoint)) { CameraManager.This.SpoilPicture(upPoint); legToMove.split(mouseGeoLocation); legToMove = null; CameraManager.This.ProcessCameraMove(); } else { Point screenPoint = m_pictureManager.PointToScreen(upPoint); Project.ShowPopup(m_pictureManager.PictureBox, " you can split this leg by dragging mouse where you want new waypoint location to be. ", screenPoint); legToMove = null; } } }
public override void ProcessMouseMove(Point movePoint, GeoCoord mouseGeoLocation, bool controlDown, bool shiftDown, bool altDown) { try { m_movePoint = movePoint; if(controlDown || altDown || m_cameraManager.HasDragRectangle) { LibSys.StatusBar.WriteLine("* " + m_cameraManager.DragEndHint); // will not be added to log return; } if(shiftDown && movePointMode) { LibSys.StatusBar.WriteLine("* drag waypoint to new location"); // will not be added to log Point screenPoint = m_pictureManager.PointToScreen(movePoint); Project.MapShowPopup(m_pictureManager.PictureBox, "dragging", screenPoint); Cursor.Current = Cursors.Hand; return; } if(moveLegMode) { int MARK_RADIUS = 5; int minX = Math.Min(Math.Min(m_movePoint.X - MARK_RADIUS - 1, hotLeg.WptFrom.PixelLocation.X), hotLeg.WptTo.PixelLocation.X); int maxX = Math.Max(Math.Max(m_movePoint.X + MARK_RADIUS + 1, hotLeg.WptFrom.PixelLocation.X), hotLeg.WptTo.PixelLocation.X); int minY = Math.Min(Math.Min(m_movePoint.Y - MARK_RADIUS - 1, hotLeg.WptFrom.PixelLocation.Y), hotLeg.WptTo.PixelLocation.Y); int maxY = Math.Max(Math.Max(m_movePoint.Y + MARK_RADIUS + 1, hotLeg.WptFrom.PixelLocation.Y), hotLeg.WptTo.PixelLocation.Y); if(!m_lastMoveLegRect.IsEmpty) { minX = Math.Min(m_lastMoveLegRect.X, minX); maxX = Math.Max(m_lastMoveLegRect.X + m_lastMoveLegRect.Width, maxX); minY = Math.Min(m_lastMoveLegRect.Y, minY); maxY = Math.Max(m_lastMoveLegRect.Y + m_lastMoveLegRect.Height, maxY); } Rectangle r = new Rectangle(minX - 20, minY - 20, maxX - minX + 22, maxY - minY + 22); m_pictureManager.Invalidate(r); Cursor.Current = Cursors.Hand; return; } else if(!m_lastMoveLegRect.IsEmpty) { m_pictureManager.Invalidate(m_lastMoveLegRect); } Waypoint hoverWpt = WaypointByPoint(movePoint); Leg hoverLeg = null; if(hoverWpt != null) { Point wptPoint = hoverWpt.PixelLocation; if(hoverWpt != hotWpt || (DateTime.Now - timeHotWptRectDrawn).TotalMilliseconds > 500) { if(hoverWpt != hotWpt) { hideHotWptRect(); } int MARK_RADIUS = 5; hotWptRect = new Rectangle(wptPoint.X - MARK_RADIUS, wptPoint.Y - MARK_RADIUS, MARK_RADIUS * 2, MARK_RADIUS * 2); m_pictureManager.Graphics.DrawRectangle(Pens.Yellow, hotWptRect); timeHotWptRectDrawn = DateTime.Now; } string tmp = hoverWpt.toStringPopup(); if(!tmp.Equals(sLiveObjectPopup)) // && movePoint.Y > 30) // make sure the popup will not overlap menu { sLiveObjectPopup = tmp; LibSys.StatusBar.WriteLine("* " + sLiveObjectPopup); // will not be added to log //movePoint.Offset(0, 0); Point screenPoint = m_pictureManager.PointToScreen(wptPoint); Project.MapShowPopup(m_pictureManager.PictureBox, sLiveObjectPopup, screenPoint); } Cursor.Current = Cursors.Hand; } if(hoverWpt == null) { hoverLeg = LegByPoint(movePoint); if(hoverLeg != null) { if(hoverLeg != hotLeg || (DateTime.Now - timeHotLegRectDrawn).TotalMilliseconds > 500) { if(hoverLeg != hotLeg) { hideHotLegRect(); } Point middleLegPoint = hoverLeg.MiddlePoint; int MARK_RADIUS = 5; hotLegRect = new Rectangle(middleLegPoint.X - MARK_RADIUS, middleLegPoint.Y - MARK_RADIUS, MARK_RADIUS * 2, MARK_RADIUS * 2); m_pictureManager.Graphics.DrawRectangle(Pens.Yellow, hotLegRect); timeHotLegRectDrawn = DateTime.Now; } string tmp = hoverLeg.toStringPopup(); if(!tmp.Equals(sLiveObjectPopup)) // && movePoint.Y > 30) // make sure the popup will not overlap menu { sLiveObjectPopup = tmp; LibSys.StatusBar.WriteLine("* " + sLiveObjectPopup); // will not be added to log //movePoint.Offset(0, 0); Point screenPoint = m_pictureManager.PointToScreen(movePoint); Project.MapShowPopup(m_pictureManager.PictureBox, sLiveObjectPopup, screenPoint); } Cursor.Current = Cursors.Hand; } } hotLeg = hoverLeg; if(hoverLeg == null) { hideHotLegRect(); } hotWpt = hoverWpt; if(hoverWpt == null) { hideHotWptRect(); } if(hoverWpt == null && hoverLeg == null) { sLiveObjectPopup = null; // mouse reentry into the same label is allowed } } catch {} }
public override void ProcessMouseDown(Point downPoint, GeoCoord mouseGeoLocation, bool controlDown, bool shiftDown, bool altDown) { try { // LibSys.StatusBar.Trace("LayerWaypoints:ProcessMouseDown()"); if(m_cameraManager.CanDrillDown) { Waypoint clickWpt = null; if(!moveLegMode && !hotLegRect.IsEmpty && hotLegRect.Contains(downPoint)) { moveLegMode = true; legToMove = hotLeg; m_downPoint = downPoint; } else if(!movePointMode && !hotWptRect.IsEmpty && hotWptRect.Contains(downPoint)) { if((clickWpt = WaypointByPoint(downPoint)) != null && (shiftDown || clickWpt.TrackId != -1)) { Point screenPoint = m_pictureManager.PointToScreen(downPoint); movePointMode = true; wptToMove = clickWpt; } } } } catch {} }
public void splitLeg(Leg leg, GeoCoord midLoc) { Distance dFrom = leg.WptFrom.distanceFrom(midLoc); Distance dTo = leg.WptTo.distanceFrom(midLoc); double ratio = dFrom.Meters / (dFrom.Meters + dTo.Meters); DateTime dt = leg.WptFrom.DateTime.AddTicks((long)(leg.Duration.Ticks * ratio)); if(leg.Duration.TotalSeconds > 60.0d) { dt = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second); // round to a second } // assuming that midLoc has been already "new" and will attach to the new waypoint: Waypoint wpt = new Waypoint(midLoc, dt, leg.WptFrom.LiveObjectType, leg.WptFrom.TrackId, "", leg.WptFrom.Source, ""); insertWaypoint(wpt); rebuildTrackBoundaries(); }
public void rebuildTrackBoundaries() { m_topLeft.Lng = 180.0d; m_topLeft.Lat = -90.0d; m_bottomRight.Lng = -180.0d; m_bottomRight.Lat = 90.0d; ElevMax = -100000.0d; ElevMin = 100000.0d; SpeedMax = -1000000001.0f; SpeedMin = 1000000001.0f; double odometer = 0.0d; // meters Waypoint prevWpt = null; for(int i=0; i < m_trackpoints.Count ;i++) { Waypoint wpt = (Waypoint)m_trackpoints.GetByIndex(i); pushBoundaries(wpt); // compute speed: if(prevWpt != null) { Leg leg = new Leg(this, prevWpt, wpt); prevWpt.LegFrom = leg; wpt.LegTo = leg; // compute odometer and speed: Distance dSpeed = new Distance(leg.Dist); // wpt.Location.distanceFrom(prevWpt.Location); // meters odometer += dSpeed.Meters; if(!isRoute) { TimeSpan dt = wpt.DateTime - prevWpt.DateTime; dSpeed.Meters = dSpeed.Meters * 36000000000.0d / dt.Ticks; // meters per hour if(dSpeed.Meters > 1000.0d && dSpeed.Meters < 330.0d * 3600.0d) // sanity check - speed of sound, m/hr { wpt.Speed = (float)dSpeed.Meters; leg.Speed = wpt.Speed; if(wpt.Speed > this.SpeedMax) { this.SpeedMax = wpt.Speed; } if(wpt.Speed < this.SpeedMin) { this.SpeedMin = wpt.Speed; } } else { wpt.HasSpeed = false; leg.HasSpeed = false; } } } wpt.Odometer = (float)odometer; prevWpt = wpt; } }