public static bool beforeFrom(Waypoint trkpt) { int fromIndex = track.Trackpoints.IndexOfValue(fromTrkpt); int thisIndex = track.Trackpoints.IndexOfValue(trkpt); return thisIndex < fromIndex; }
public static bool afterTo(Waypoint trkpt) { int toIndex = track.Trackpoints.IndexOfValue(toTrkpt); int thisIndex = track.Trackpoints.IndexOfValue(trkpt); return thisIndex > toIndex; }
public static bool passes(Waypoint trkpt) { if(track == null) { return false; } int fromIndex = track.Trackpoints.IndexOfValue(fromTrkpt); int toIndex = track.Trackpoints.IndexOfValue(toTrkpt); int thisIndex = track.Trackpoints.IndexOfValue(trkpt); return thisIndex >= fromIndex && thisIndex <= toIndex; }
public Leg(Track track, Waypoint wptFrom, Waypoint wptTo) { m_track = track; m_wptFrom = wptFrom; m_wptTo = wptTo; m_dist = m_wptTo.distanceFrom(m_wptFrom.Location); // it is a new Distance() m_duration = wptTo.DateTime - wptFrom.DateTime; if(m_wptFrom.DateTime.Ticks > minDateTimeTicks && m_wptTo.DateTime.Ticks > minDateTimeTicks) // waypoint times are added to to avoid duplicates, we need to compare with tolerance { this.Speed = (float)(Dist.Meters / m_duration.TotalHours); } }
public DlgEditWaypoint(CameraManager cameraManager, Waypoint wpt) : base(cameraManager) { m_wpt = wpt; if(m_wpt.TrackId == -1) { this.Text = "Edit Waypoint"; elevLabel.Text = "Elevation:"; } else { elevLabel.Text = "Altitude:"; Track trk = (Track)Project.mainCommand.getTrackById(m_wpt.TrackId); if(trk != null) { if(trk.isRoute) { this.Text = "Edit Route Point"; } else { this.Text = "Edit Trackpoint"; } } } GeoCoord location = m_wpt.Location; setCoordFields(location); setFormFields(); Project.setDlgIcon(this); if(waypointNameTextBox.Enabled) { waypointNameTextBox.Focus(); } else { urlNameTextBox.Focus(); } }
private static int InsertWaypointToDisplay(Waypoint wp) { double lng = wp.Location.Lng; double lat = wp.Location.Lat; int ii; for (ii=0; ii < m_waypointsDisplayed.Count ;ii++) { Waypoint other = (Waypoint)m_waypointsDisplayed[ii]; double lato = other.Location.Lat; if(lato == lat) { if(wp.sameAs(other)) { //LibSys.StatusBar.Trace(" ---- ignored duplicate waypoint (orig from " + other.Source + ") : " + wp); return 0; // ignore if it ain't new } } else if(lato < lat) // sort north to south { break; } } if(ii == m_waypointsDisplayed.Count) { m_waypointsDisplayed.Add(wp); } else { m_waypointsDisplayed.Insert(ii, wp); } m_waypointsDisplayedNotSorted.Add(wp); return 1; }
protected virtual void act() { double lng; double lat; double elev; bool allcool = validateCoord(out lng, out lat, out elev); if(waypointNameTextBox.Text.Length == 0) { waypointNameLabel.ForeColor = Color.Red; allcool = false; } else { waypointNameLabel.ForeColor = Color.Black; } DateTime dateTime = timePicker.isActive ? Project.localToZulu(timePicker.dateTime) : DateTime.MinValue; if(allcool) { try { GeoCoord location = m_clickLocation; if(!m_latText.Equals(latitudeTextBox.Text) || !m_lngText.Equals(longitudeTextBox.Text) || !m_elevText.Equals(elevationTextBox.Text)) { location = new GeoCoord(lng, lat, elev); } location.Normalize(); LiveObjectTypes type = LiveObjectTypes.LiveObjectTypeWaypoint; bool isFound = false; switch(waypointTypeComboBox.SelectedIndex) { case 0: type = LiveObjectTypes.LiveObjectTypeWaypoint; break; case 1: type = LiveObjectTypes.LiveObjectTypeGeocache; break; case 2: type = LiveObjectTypes.LiveObjectTypeGeocache; isFound = true; break; } string wptName = waypointNameTextBox.Text; Waypoint wpt = new Waypoint(location, dateTime, type, -1L, wptName, "", ""); wpt.Found = isFound; wpt.UrlName = urlNameTextBox.Text.Trim(); wpt.Sym = symbolTextBox.Text.Trim(); wpt.Comment = commentTextBox.Text.Trim(); wpt.Desc = detailTextBox.Text.Trim(); string url = urlTextBox.Text.Trim(); if(url.Length > 0 && !url.Equals("http://")) // if something meaningful has been entered { wpt.Url = url; } if(m_photoDescr != null) { wpt.ThumbSource = m_photoDescr.imageThumbSource; wpt.ThumbImage = PhotoDescr.rebuildThumbnailImage(wpt.ThumbSource); wpt.ThumbPosition = Project.thumbPosition; wpt.imageWidth = m_photoDescr.Width; wpt.imageHeight = m_photoDescr.Height; wpt.PhotoTimeShift = new TimeSpan(0L); } WaypointsCache.WaypointsAll.Add(wpt); WaypointsCache.WaypointsDisplayed.Add(wpt); WaypointsCache.isDirty = true; Project.drawWaypoints = true; m_wpt = wpt; // in case the caller needs it m_cameraManager.MarkLocation(location, 0); m_cameraManager.PictureManager.LayersManager.ShowWaypoints = true; m_cameraManager.ProcessCameraMove(); this.Close(); } catch { elevLabel.ForeColor = Color.Red; allcool = false; } } }
// can be called from different thread: public static void BringFormUp(PhotoDescr photoDescr, Waypoint wpt) { try { if(wpt != null) { m_wpt = wpt; PhotoWaypoints.SetCurrentWaypoint(m_wpt); } else { m_wpt = PhotoWaypoints.CurrentWaypoint(); } if(photoDescr == null) { try { photoDescr = PhotoDescr.FromThumbnail(m_wpt.ThumbSource); } // An invalid image will throw an OutOfMemoryException // exception catch (OutOfMemoryException) { } } else if(wpt == null) { m_wpt = null; // from Unrelated photos } m_photoDescr = photoDescr; if(This == null) { if(Project.mainForm.InvokeRequired) { Project.mainForm.Invoke(new MethodInvoker(RunPhotoFullSizeForm)); } else { RunPhotoFullSizeForm(); } } else { if(Project.mainForm.InvokeRequired) { Project.mainForm.Invoke(new MethodInvoker(RunBringUp)); } else { RunBringUp(); } } } catch {} }
// try to set the pointer to the given waypoint public static bool SetCurrentWaypoint(Waypoint wpt) { if(!hasCurrentWaypoint()) { return false; } for (int i=0; i < WaypointsWithThumbs.Count ;i++) { Waypoint curWpt = (Waypoint)WaypointsWithThumbs.GetByIndex(i); if(wpt == curWpt) { CurrentWptIndex = i; return true; } } return false; }
public static Waypoint createPhotoTrackpoint(PhotoDescr photoDescr, TimeSpan photoTimeShift, int tzId) { if(photoDescr.hasCoordinates) { // There is EXIF coordinates set, use it. GeoCoord loc = new GeoCoord(photoDescr.Longitude, photoDescr.Latitude, photoDescr.Altitude); string name = photoDescr.imageName; string source = photoDescr.imageSource; string url = photoDescr.imageUrl; Waypoint wpt0 = new Waypoint(loc, Project.localToZulu(photoDescr.DTOrig), LiveObjectTypes.LiveObjectTypeWaypoint, -1, name, source, url) ; wpt0.Desc = photoDescr.imageName; wpt0.ThumbImage = photoDescr.ThumbnailImage; wpt0.ThumbSource = photoDescr.imageThumbSource; wpt0.ThumbPosition = Project.thumbPosition; wpt0.imageWidth = photoDescr.Width; wpt0.imageHeight = photoDescr.Height; wpt0.PhotoTimeShift = new TimeSpan(0L); // we need to shift the timestamp a bit if the spot is taken: while(WaypointsWithThumbs.ContainsKey(wpt0.DateTime)) { DateTime tmp = wpt0.DateTime; wpt0.DateTime = tmp.AddMilliseconds(1); } // make sure the new waypoint is accounted for in the cache: WaypointsWithThumbs.Add(wpt0.DateTime, wpt0); CurrentWptIndex = WaypointsWithThumbs.Count - 1; WaypointsCache.addWaypoint(wpt0); return wpt0; } if(photoDescr.DTOrig.Equals(DateTime.MinValue)) { // try to get it from file name: photoDescr.ensureImageExists(); Waypoint wpt0 = WaypointsCache.getWaypointByName(photoDescr.imageName); if(wpt0 != null) { //wpt0.Desc = photoDescr.imageName; wpt0.ThumbImage = photoDescr.ThumbnailImage; wpt0.ThumbSource = photoDescr.imageThumbSource; wpt0.ThumbPosition = Project.thumbPosition; wpt0.imageWidth = photoDescr.Width; wpt0.imageHeight = photoDescr.Height; wpt0.PhotoTimeShift = new TimeSpan(0L); // we need to shift the timestamp a bit if the spot is taken: while(WaypointsWithThumbs.ContainsKey(wpt0.DateTime)) { DateTime tmp = wpt0.DateTime; wpt0.DateTime = tmp.AddMilliseconds(1); } // make sure the new waypoint is accounted for in the cache: WaypointsWithThumbs.Add(wpt0.DateTime, wpt0); CurrentWptIndex = WaypointsWithThumbs.Count - 1; return wpt0; } else { registerUnrelatedPhoto(photoDescr); } return null; } TimeSpan timeZoneSpan = MyTimeZone.timeSpanById(tzId); DateTime timeStamp = Project.localToZulu(photoDescr.DTOrig + photoTimeShift + MyTimeZone.zoneTimeShift - timeZoneSpan); //LibSys.StatusBar.Trace("adjusted zulu time=" + timeStamp); registerImageTimestamp(timeStamp); if(photoDescr.imageSourceIsLocal && photoDescr.image == null) { // try to get it from file name: photoDescr.ensureImageExists(); registerUnrelatedPhoto(photoDescr); return null; } Waypoint wpt = null; Waypoint wpt1; Waypoint wpt2; // wpt2 is hit if exact match on the timestamp; wpt1 may turn null, but not wpt2. if(WaypointsCache.trackpointByTime(timeStamp, out wpt1, out wpt2)) { // create duplicate waypoint and add it to the same track - to hold the image wpt = new Waypoint(wpt2); if(wpt1 == null) { // exact match on wpt2 } else { // somewhere between wpt1 and wpt2 double dt = (wpt2.DateTime - wpt1.DateTime).Ticks; double dt1 = (timeStamp - wpt1.DateTime).Ticks; if(dt > 0) { double ratio = dt1 / dt; wpt.Location.Lat = wpt1.Location.Lat + (wpt2.Location.Lat - wpt1.Location.Lat) * ratio; wpt.Location.Lng = wpt1.Location.Lng + (wpt2.Location.Lng - wpt1.Location.Lng) * ratio; } } wpt.DateTime = timeStamp; wpt.Desc = photoDescr.imageName; Track trk = WaypointsCache.getTrackById(wpt.TrackId); // we need to shift the timestamp a bit if the spot is taken: while(WaypointsWithThumbs.ContainsKey(wpt.DateTime) || trk.Trackpoints.ContainsKey(wpt.DateTime)) { DateTime tmp = wpt.DateTime; wpt.DateTime = tmp.AddMilliseconds(1); } trk.insertWaypoint(wpt); wpt.ThumbImage = photoDescr.ThumbnailImage; wpt.ThumbSource = photoDescr.imageThumbSource; wpt.ThumbPosition = Project.thumbPosition; wpt.imageWidth = photoDescr.Width; wpt.imageHeight = photoDescr.Height; wpt.PhotoTimeShift = photoTimeShift; // make sure the new waypoint is accounted for in the cache: WaypointsWithThumbs.Add(wpt.DateTime, wpt); CurrentWptIndex = WaypointsWithThumbs.Count - 1; } else { registerUnrelatedPhoto(photoDescr); } return wpt; }
// return array of track IDs or null (if track can't be ungrouped) public static ArrayList ungroupTrack(Track trk, double breakTimeMinutes) { double maxJumpMeters = 5000.0d; // for sanity filter. make sure it is big enough, as GPSV makes big gaps. DateTime lastTime = DateTime.MinValue; GeoCoord lastLoc = null; int trip = 0; int i; // first count how many trips we can break the track into: for(i=0; i < trk.Trackpoints.Count ;i++) { Waypoint wpt = (Waypoint)trk.Trackpoints.GetByIndex(i); DateTime wptTime = wpt.DateTime; if(wptTime.CompareTo(lastTime.AddMinutes(breakTimeMinutes)) > 0 || (lastLoc != null && wpt.Location.distanceFrom(lastLoc).Meters > maxJumpMeters)) { trip++; } if(trip > 0) { lastTime = wptTime; } lastLoc = wpt.Location; } if(trip < 2) { return null; } // more than one trip, go ahead break it: string[] infos = new string[8]; string newTrackSource = trk.Source; lastTime = DateTime.MinValue; lastLoc = null; trip = 0; ArrayList ret = new ArrayList(); for(i=0; i < trk.Trackpoints.Count ;i++) { Waypoint wpt = (Waypoint)trk.Trackpoints.GetByIndex(i); DateTime wptTime = wpt.DateTime; if(wptTime.CompareTo(lastTime.AddMinutes(breakTimeMinutes)) > 0 || (lastLoc != null && wpt.Location.distanceFrom(lastLoc).Meters > maxJumpMeters)) { Project.trackId++; trip++; string newTrackName = trk.Name + "-trip-" + trip; CreateInfo createInfo = new CreateInfo(); createInfo.init(trk.Type); createInfo.id = Project.trackId; createInfo.name = newTrackName; createInfo.source = newTrackSource; createInfo.url = trk.Url; currentTrack = new Track(createInfo); m_tracksAll.Add(currentTrack); ret.Add(Project.trackId); } if(trip > 0) { Waypoint cloneWpt = new Waypoint(wpt); cloneWpt.TrackId = Project.trackId; currentTrack.insertWaypoint(cloneWpt); lastTime = wptTime; } lastLoc = wpt.Location; } // make sure the speed and odometer values are computed: foreach(long trackId in ret) { Track ttrk = getTrackById(trackId); ttrk.rebuildTrackBoundaries(); } // now apply Sanity Filter: if(Project.sanityFilter) { ArrayList ret1 = new ArrayList(); foreach(long trackId in ret) { Track ttrk = getTrackById(trackId); if(ttrk.Trackpoints.Count >= 5 && ttrk.Odometer > 10.0f) // odometer in meters, eliminates standing points { ret1.Add(trackId); } else { RemoveTrackById(trackId); } } if(ret1.Count < 2) { //return null; } ret = ret1; } if(ret != null) { isDirty = true; } return ret; }
public static void insertWaypoint(CreateInfo createInfo) { lock(m_waypointsAll) { switch(createInfo.type) { case "trk": case "rte": currentTrack = new Track(createInfo); m_tracksAll.Add(currentTrack); break; default: Waypoint wpt = new Waypoint(createInfo); addWaypoint(wpt); break; } } }
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 addWptToRoute(Waypoint wpt) { addToRoute(null, wpt, null); }
private void act() { double lng = 0.0d; double lat = 0.0d; double elev = 0.0d; bool allcool = true; if(Project.coordStyle == 3) // UTM? { // something like "11S 0432345E 3712345N" in the latitudeTextBox allcool = Project.mainCommand.fromUtmString(latitudeTextBox.Text, out lng, out lat); if(allcool) { latLabel.ForeColor = Color.Black; } else { latLabel.ForeColor = Color.Red; } } else { try { lng = GeoCoord.stringLngToDouble(longitudeTextBox.Text); lngLabel.ForeColor = Color.Black; } catch { lngLabel.ForeColor = Color.Red; allcool = false; } try { lat = GeoCoord.stringLatToDouble(latitudeTextBox.Text); latLabel.ForeColor = Color.Black; } catch { latLabel.ForeColor = Color.Red; allcool = false; } } try { Distance elevDist = new Distance(0.0d); int unitsCompl = elevDist.UnitsCompl; double nuElev = Convert.ToDouble(elevationTextBox.Text.Replace(",","")); elevDist.byUnits(nuElev, unitsCompl); elev = elevDist.Meters; if(elev < Project.cameraHeightMin*1000.0d) { elevDist.byUnits(Project.cameraHeightMin*1000.0d, Distance.UNITS_DISTANCE_M); elev = elevDist.Meters; } else if(elev > Project.CAMERA_HEIGHT_MAX*1000.0d) { elevDist.byUnits(Project.CAMERA_HEIGHT_MAX*1000.0d, Distance.UNITS_DISTANCE_M); elev = elevDist.Meters; } elevationUnitsLabel.Text = elevDist.toStringU(unitsCompl); elevLabel.ForeColor = Color.Black; } catch { elevLabel.ForeColor = Color.Red; allcool = false; } if(makeWaypointCheckBox.Checked && waypointNameTextBox.Text.Length == 0) { waypointNameLabel.ForeColor = Color.Red; allcool = false; } else { waypointNameLabel.ForeColor = Color.Black; } if(allcool) { try { GeoCoord location = new GeoCoord(lng, lat, elev); location.Normalize(); m_cameraManager.MarkLocation(location, 0); if(makeWaypointCheckBox.Checked) { LiveObjectTypes type = LiveObjectTypes.LiveObjectTypeWaypoint; bool isFound = false; switch(waypointTypeComboBox.SelectedIndex) { case 0: type = LiveObjectTypes.LiveObjectTypeWaypoint; break; case 1: type = LiveObjectTypes.LiveObjectTypeGeocache; break; case 2: type = LiveObjectTypes.LiveObjectTypeGeocache; isFound = true; break; } string stype = "" + waypointTypeComboBox.SelectedItem; string comment = waypointNameTextBox.Text; Waypoint wpt = new Waypoint(location, Project.localToZulu(DateTime.Now), type, -1L, comment, "", ""); wpt.Found = isFound; WaypointsCache.WaypointsAll.Add(wpt); WaypointsCache.WaypointsDisplayed.Add(wpt); WaypointsCache.isDirty = true; Project.drawWaypoints = true; m_cameraManager.PictureManager.LayersManager.ShowWaypoints = true; if(!moveCameraCheckBox.Checked) { Cursor.Current = Cursors.WaitCursor; } m_cameraManager.PictureManager.Refresh(); } if(moveCameraCheckBox.Checked) { Cursor.Current = Cursors.WaitCursor; m_cameraManager.SpoilPicture(); m_cameraManager.Location = new GeoCoord(location); // must be a new instance of GeoCoord setCoordTextBoxes(); Cursor.Current = Cursors.Default; } } catch { elevLabel.ForeColor = Color.Red; allcool = false; } } }
public static void setTrackByTrackpoint(Waypoint trkpt) { if(trkpt == null) { resetTrack(); } if(Project.mainCommand.PlannerPaneVisible()) { track = WaypointsCache.getTrackById(trkpt.TrackId); This.m_trkpt = trkpt; if(trkpt != null) { This.infoLabel.Text += " | " + trkpt.ToStringProfile(); if(Project.mainCommand.PlannerPaneVisible()) { GeoCoord loc = new GeoCoord(trkpt.Location.X, trkpt.Location.Y, PictureManager.This.CameraManager.Elev); PictureManager.This.CameraManager.MarkLocation(loc, 3); } else { PictureManager.This.CameraManager.removeMarkLocation(); } } This.tgc.setTrackAndTrackpoint(track, This.m_trkpt); } }
/// <summary> /// returns true if it could actually find something to display /// </summary> /// <returns></returns> private bool preview() { bool ret = false; disableButtons(); // Create an Image object from the specified file. try { m_wpt = PhotoWaypoints.CurrentWaypoint(); if(m_wpt != null) { PhotoDescr photoDescr = PhotoDescr.FromThumbnail(m_wpt.ThumbSource); photoViewerControl.photoDescr = m_photoDescr = photoDescr; setPhotoDetail(); if(m_keepInView) { PictureManager.This.CameraManager.keepInView(m_wpt.Location); } PictureManager.This.CameraManager.MarkLocation(m_wpt.Location, 0); ret = true; } else { photoViewerControl.photoDescr = m_photoDescr = null; } } // An invalid image will throw an OutOfMemoryException // exception catch (OutOfMemoryException) { throw new InvalidOperationException("'" + m_wpt.ThumbSource + "' is not a valid image file."); } if(ret) { setupButtons(); } DlgPhotoManager.sync(false); this.BringToFront(); return ret; }
// keep in mind to lock(m_waypointsAll) public static void addWaypoint(Waypoint wp) { WaypointsCache.pushBoundaries(wp.Location); // need this for files dropped on the icon at start, or on the program /* if (wp.Location.X > -127 || wp.Location.X < -130 || wp.Location.Y > 45 || wp.Location.Y < 43) { return; } */ Track _currentTrack; if(currentTrack != null && wp.TrackId == currentTrack.Id) // save some time { currentTrack.insertWaypoint(wp); } else if(wp.TrackId != -1 && (_currentTrack=WaypointsCache.getTrackById(wp.TrackId)) != null) { _currentTrack.insertWaypoint(wp); } else { //double lng = wp.Location.Lng; double lat = wp.Location.Lat; int ii = 0; for (ii=0; ii < m_waypointsAll.Count ;ii++) { Waypoint other = (Waypoint)m_waypointsAll[ii]; double lngo = other.Location.Lng; double lato = other.Location.Lat; //if(lngo == lng) if(lato == lat) { if(wp.LiveObjectType != LiveObjectTypes.LiveObjectTypeTrackpoint && wp.LiveObjectType != LiveObjectTypes.LiveObjectTypeRoutepoint && wp.sameAs(other)) { //LibSys.StatusBar.Trace(" ---- ignored duplicate waypoint (orig from " + other.Source + ") : " + wp); return; // ignore if it ain't new, but push boundaries for zooming } } //else if(lngo < lng) // sort east to west //else if(lato > lat) // sort south to north else if(lato < lat) // sort north to south { break; } } if(ii == m_waypointsAll.Count) { m_waypointsAll.Add(wp); } else { m_waypointsAll.Insert(ii, wp); } } // invalidating every object's drawing area is VERY expensive, we do PictureManager.Refresh() instead // at the end of interpreting all files. So the next line is commented out. //DynamicObjectCreateCallback(wp); }
// takes array of Track public static Track groupTracks(ArrayList tracks) { Project.trackId++; string tType = ((Track)tracks[0]).Type; string newTrackSource = "joined" + ("trk".Equals(tType) ? (" " + DateTime.Now) : ("-" + Project.trackId)); string newTrackName = newTrackSource; CreateInfo createInfo = new CreateInfo(); createInfo.init(tType); createInfo.id = Project.trackId; createInfo.name = newTrackName; createInfo.source = newTrackSource; Track joinedTrack = new Track(createInfo); m_tracksAll.Add(joinedTrack); DateTime dateTime = new DateTime(8888, 1, 1, 1, 1, 1, 1); // for routes, we make new time sequence foreach(Track trk in tracks) { for(int i=0; i < trk.Trackpoints.Count ;i++) { Waypoint wpt = (Waypoint)trk.Trackpoints.GetByIndex(i); Waypoint cloneWpt = new Waypoint(wpt); cloneWpt.TrackId = joinedTrack.Id; if(joinedTrack.isRoute) { cloneWpt.DateTime = dateTime; dateTime = dateTime.AddSeconds(1); cloneWpt.NameDisplayed = ""; // let it be the number or Detail } joinedTrack.insertWaypoint(cloneWpt); } } joinedTrack.rebuildTrackBoundaries(); return joinedTrack; }
public void removeWptFromRoute(Waypoint wpt) { m_routeTrack.removeWaypoint(wpt); m_cameraManager.ProcessCameraMove(); }
// returns two trackpoints around the given time - used to relate photos to trackpoints. P2 is a possible exact match: public static bool trackpointByTime(DateTime timeStamp, out Waypoint p1, out Waypoint p2) { Waypoint wpt = null; Waypoint wptPrev = null; // good to have it stay between tracks (unless too old), so that interrupted tracks take photos ok at the beginning. for(int j = WaypointsCache.TracksAll.Count-1; j >= 0 ;j--) { Track trk = (Track)WaypointsCache.TracksAll[j]; if(trk.Enabled && !trk.isRoute) // timestamps on routes are for sorting only, they don't have any other meaning { for(int i=0; i < trk.Trackpoints.Count ;i++) { wpt = (Waypoint)trk.Trackpoints.GetByIndex(i); if(wptPrev != null && Math.Abs((wpt.DateTime - wptPrev.DateTime).TotalMinutes) > 20.0d) { // we don't want very old tracks be part of our scope. wptPrev = null; } if(wptPrev != null && wptPrev.DateTime.CompareTo(timeStamp) < 0 && wpt.DateTime.CompareTo(timeStamp) >= 0 ) { goto found; } else if(wptPrev == null && wpt.DateTime.CompareTo(timeStamp) == 0 ) { // exact match goto found; } wptPrev = wpt; } } } p1 = null; p2 = null; return false; found: p1 = wptPrev; p2 = wpt; return true; }
private void addToRoute(GeoCoord location, Waypoint wpt, Earthquake eq) { rteptNumber++; string wptName = "" + rteptNumber; if(m_routeTrack == null) { // first route-making click on the map, create track to hold the new route string newTrackSource = "route - user created " + DateTime.Now; Project.trackId++; rteptNumber = 1; m_lastWpt = null; string newTrackName = "Route-" + Project.trackId; CreateInfo createInfo = new CreateInfo(); createInfo.init("rte"); createInfo.id = Project.trackId; createInfo.name = newTrackName; createInfo.source = newTrackSource; createInfo.par1 = "" + rteNumber; rteNumber++; if(rteNumber > 20) { rteNumber = 1; } m_routeTrack = new Track(createInfo); m_routeTrack.isRoute = true; WaypointsCache.TracksAll.Add(m_routeTrack); wptName = "Start route"; } m_speed = null; if(m_lastWpt != null && m_lastWpt.HasSpeed) { m_speed = new Speed(m_lastWpt.Speed); } else { m_speed = new Speed(Project.routeSpeed); } TimeSpan dur = new TimeSpan(100000); Waypoint routeWpt = null; bool wasNew = false; if(wpt != null) { routeWpt = new Waypoint(wpt); routeWpt.LiveObjectType = LiveObjectTypes.LiveObjectTypeRoutepoint; routeWpt.DateTime = m_dateTimeRte; } else if(eq != null) { //wptName = eq.ToString(); wptName = string.Format("{0:F1} - ", eq.Magn) + eq.sDateTime + " - " + eq.Comment; routeWpt = new Waypoint(eq.Location, m_dateTimeRte, LiveObjectTypes.LiveObjectTypeRoutepoint, Project.trackId, wptName, eq.Source, eq.Url); } else { // location must not be null then: routeWpt = new Waypoint(location, m_dateTimeRte, LiveObjectTypes.LiveObjectTypeRoutepoint, Project.trackId, "", "user created", ""); // no URL routeWpt.NameDisplayed = wptName; wasNew = true; } if(m_speed != null) { routeWpt.Speed = (float)m_speed.Meters; } if(m_lastWpt != null && m_lastWpt.TrackId == Project.trackId) { Distance dist = routeWpt.distanceFrom(m_lastWpt.Location); double durSeconds = m_speed.Meters <= 0.0d ? 0.000001d : (dist.Meters / m_speed.Meters * 3600.0d); dur = new TimeSpan((long)(durSeconds * 10000000.0d)); m_dateTimeRte += dur; } routeWpt.DateTime = m_dateTimeRte; m_lastWpt = routeWpt; // we need to make sure that the point added is different from the last point in track. // Magellan will not accept routes with zero-length legs. Waypoint lastWpt = null; if(m_routeTrack.Trackpoints.Count > 0) { lastWpt = (Waypoint)m_routeTrack.Trackpoints.GetByIndex(m_routeTrack.Trackpoints.Count - 1); } if(lastWpt == null || lastWpt.Location.distanceFrom(routeWpt.Location).Meters > 2.0d) { if(wasNew && lastWpt != null) { routeWpt.Location.Elev = lastWpt.Location.Elev; } m_routeTrack.Trackpoints.Add(routeWpt.DateTime, routeWpt); m_routeTrack.PutOnMap(this, null, this); if(wptName.Length > 2) { //m_cameraManager.MarkLocation(mouseGeoLocation, 0); m_cameraManager.ProcessCameraMove(); // make sure label is positionsed on the map } else { // invalidate picture region around just created leg: Waypoint prevWpt = (Waypoint)m_routeTrack.Trackpoints.GetByIndex(m_routeTrack.Trackpoints.Count - 2); Point p1 = m_cameraManager.toPixelLocation(routeWpt.Location, null); Point p2 = m_cameraManager.toPixelLocation(prevWpt.Location, null); int x = Math.Min(p1.X, p2.X); int y = Math.Min(p1.Y, p2.Y); int w = Math.Abs(p1.X - p2.X); int h = Math.Abs(p1.Y - p2.Y); Rectangle toInv = new Rectangle(x, y, w, h); toInv.Offset(-5, -5); toInv.Inflate(10, 10); m_pictureManager.Invalidate(toInv); } } }
// return array of (two) track IDs or null (if track can't be ungrouped for some reason) public static ArrayList ungroupTrackAtTrackpoint(Track trk, Waypoint trkptBreak) { int trip = 0; int i; // more than one trip, go ahead break it: string newTrackSource = trk.Source; trip = 0; ArrayList ret = new ArrayList(); for(i=0; i < trk.Trackpoints.Count ;i++) { Waypoint wpt = (Waypoint)trk.Trackpoints.GetByIndex(i); if(i == 0 || wpt == trkptBreak) { Project.trackId++; trip++; string newTrackName = trk.Name + "-trip-" + trip; CreateInfo createInfo = new CreateInfo(); createInfo.init(trk.Type); createInfo.id = Project.trackId; createInfo.name = newTrackName; createInfo.source = newTrackSource; createInfo.url = trk.Url; currentTrack = new Track(createInfo); m_tracksAll.Add(currentTrack); ret.Add(Project.trackId); } if(trip > 0) { Waypoint cloneWpt = new Waypoint(wpt); cloneWpt.TrackId = Project.trackId; currentTrack.insertWaypoint(cloneWpt); } } foreach(long id in ret) { Track ttrk = getTrackById(id); if(ttrk != null) { ttrk.rebuildTrackBoundaries(); } } isDirty = true; return ret; }
public DlgPhotoDraw(Waypoint wpt, PhotoDescr photoDescr) { if(photoDescr != null) { // from DlgPhotoFullSize, wpt may be null m_photoDescr = PhotoDescr.FromPhotoDescr(photoDescr); // with null image m_photoDescr.imageDisposable = false; m_photoDescr.ensureOriginalImageExists(); // local will be still invoked if not a gallery } else { // from right-click on a waypoint; wpt must be non-null try { m_photoDescr = PhotoDescr.FromThumbnail(wpt.ThumbSource); m_photoDescr.imageDisposable = false; m_photoDescr.ensureOriginalImageExists(); // local will be still invoked if not a gallery } // An invalid image will throw an OutOfMemoryException // exception catch (OutOfMemoryException) { throw new Exception("Corrupted image file?"); } } originalOrientation = m_photoDescr.Orientation; m_photoDescr.Orientation = 1; // will force display to actual orientation, no adjustment originalBitmap = new Bitmap(m_photoDescr.image); whRatio = (double)originalBitmap.Width / (double)originalBitmap.Height; foreach(PropertyItem item in m_photoDescr.image.PropertyItems) { //string str = "" + item.Type + ": " + item.Id + "=" + item.Value; //LibSys.StatusBar.Trace(str); originalBitmap.SetPropertyItem(item); } m_wpt = wpt; InitializeComponent(); addExifCoordsCheckBox.Enabled = (m_wpt != null); addExifCoordsCheckBox.Checked = m_addExifCoords; this.linkToWptLinkLabel.Enabled = (m_wpt == null || m_wpt.TrackId == -1); this.photoViewerControl = new LibSys.PhotoViewerControl(); this.picturePanel.Controls.AddRange(new System.Windows.Forms.Control[] { this.photoViewerControl}); // // photoViewerControl // this.photoViewerControl.Dock = System.Windows.Forms.DockStyle.Fill; this.photoViewerControl.Name = "photoViewerControl"; //this.photoViewerControl.photoDescr = null; this.photoViewerControl.TabIndex = 1; photoViewerControl.fitToSize = m_fitToSize; fitToSizeCheckBox.Checked = m_fitToSize; this.fitToSizeCheckBox.CheckedChanged += new System.EventHandler(this.fitToSizeCheckBox_CheckedChanged); if(m_wpt != null && m_wpt.TrackId != -1) { timeTptRadioButton.Checked = true; this.timePanel.Enabled = true; } else { timeExifRadioButton.Checked = true; timePanel.Enabled = false; } setTextTextBox(); widthTextBox.Text = "" + originalBitmap.Width; // Y will be set in validation widthTextBox_Validating(null, null); draw(false); if(Project.fitsScreen(m_dlgSizeX, m_dlgSizeY, m_dlgSizeWidth, m_dlgSizeHeight)) { inResize = true; this.Location = new Point(m_dlgSizeX, m_dlgSizeY); this.ClientSize = new System.Drawing.Size(m_dlgSizeWidth, m_dlgSizeHeight); // causes Resize() } // PhotoProperties related: // Create an instance of a ListView column sorter and // assign it to the _listView control. lvwColumnSorter = new ListViewColumnSorter(); this._listView.ListViewItemSorter = lvwColumnSorter; _resultOptions = new ResultOptions(); // end of PhotoProperties related. positionComboBox.SelectedIndex = m_position; this.positionComboBox.SelectedIndexChanged += new System.EventHandler(this.positionComboBox_SelectedIndexChanged); m_fontSize = (int)Math.Round(Math.Max(originalBitmap.Width / 50.0d, m_fontSize)); fontNumericUpDown.Value = Math.Min(m_fontSize, fontNumericUpDown.Maximum); qualityNumericUpDown.Value = Project.photoSaveQuality; this.qualityNumericUpDown.ValueChanged += new System.EventHandler(this.qualityNumericUpDown_ValueChanged); applyTextCheckBox.Checked = true; pickColorButton.BackColor = m_color; pickBgColorButton.BackColor = m_bgColor; this.useBgColorCheckBox.Checked = m_useBgColor; this.Text += " - " + m_photoDescr.imageName; switch(originalOrientation) { // see PhotoDescr.cs for EXIF orientation codes: // case 4: // //thumb.RotateFlip(RotateFlipType.Rotate180FlipNone); // break; case 8: this.rotate270RadioButton.Checked = true; //thumb.RotateFlip(RotateFlipType.Rotate270FlipNone); break; case 6: this.rotate90RadioButton.Checked = true; //thumb.RotateFlip(RotateFlipType.Rotate90FlipNone); break; default: this.rotate0RadioButton.Checked = true; break; } this.saveButton.Enabled = false; this.previewLinkLabel.Enabled = false; Project.setDlgIcon(this); }
public static void RemoveWaypoint(Waypoint _wpt) { lock(m_waypointsWithThumbs) { for (int i=WaypointsWithThumbs.Count-1; i >=0 ;i--) { Waypoint wpt = (Waypoint)WaypointsWithThumbs.GetByIndex(i); try { if(wpt == _wpt) { WaypointsWithThumbs.RemoveAt(i); Track trk = WaypointsCache.getTrackById(wpt.TrackId); if(trk != null) { trk.Trackpoints.Remove(wpt.DateTime); } break; } } catch { } } } }
public DlgMakeWaypoint(CameraManager cameraManager, PhotoDescr photoDescr, Waypoint wpt) : this(cameraManager) { this.TopMost = true; if(wpt == null) { m_clickLocation = m_cameraManager.Location.Clone(); m_clickLocation.Elev = 0.0d; } else { m_clickLocation = wpt.Location.Clone(); elevLabel.Text = wpt.TrackId == -1 ? "Elevation:" : "Altitude"; } setCoordFields(m_clickLocation); m_photoDescr = photoDescr; this.waypointNameTextBox.Text = m_photoDescr.imageName; this.urlTextBox.Text = m_photoDescr.imageUrl; this.detailTextBox.Text = m_photoDescr.imageSource; this.timePicker.dateTime = m_photoDescr.DTOrig; // all we can realistically change here is coordinates and elevation, so disable other conrols: this.symbolTextBox.Enabled = false; this.waypointNameTextBox.Enabled = false; this.waypointTypeComboBox.Enabled = false; this.urlNameTextBox.Enabled = false; this.urlTextBox.Enabled = false; this.detailTextBox.Enabled = false; this.commentTextBox.Enabled = false; //this.timePicker.Enabled = false; Project.setDlgIcon(this); waypointNameTextBox.Focus(); }
private void linkToWptLinkLabel_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { DlgMakeWaypoint dlg = new DlgMakeWaypoint(CameraManager.This, m_photoDescr, m_wpt); dlg.ShowDialog(); Waypoint wpt = dlg.m_wpt; if(wpt != null) { if(m_wpt != null) { // remove the old one: WaypointsCache.RemoveWaypointById(m_wpt.Id); PhotoWaypoints.RemoveWaypoint(m_wpt); } // make sure the new waypoint is accounted for in the cache: if(PhotoWaypoints.WaypointsWithThumbs.ContainsKey(wpt.DateTime)) { PhotoWaypoints.WaypointsWithThumbs.Remove(wpt.DateTime); } PhotoWaypoints.WaypointsWithThumbs.Add(wpt.DateTime, wpt); PhotoWaypoints.CurrentWptIndex = PhotoWaypoints.WaypointsWithThumbs.Count - 1; m_wpt = wpt; addExifCoordsCheckBox.Enabled = (m_wpt != null); setTextTextBox(); if(m_wpt != null) { CameraManager.This.keepInView(m_wpt.Location); CameraManager.This.ProcessCameraMove(); } configureCloseButtons(); } }
private void exportButton_Click(object sender, System.EventArgs e) { ArrayList waypoints = new ArrayList(); // array of Waypoint for (int i=0; i < PhotoWaypoints.WaypointsWithThumbs.Count; i++) { Waypoint wpt = (Waypoint)PhotoWaypoints.WaypointsWithThumbs.GetByIndex(i); Waypoint wptClone = new Waypoint(wpt); wptClone.LiveObjectType = LiveObjectTypes.LiveObjectTypeWaypoint; if(wptClone.WptName == null || wptClone.WptName.Length == 0) { wptClone.WptName = wpt.Desc; } wptClone.Url = wpt.ThumbSource; waypoints.Add(wptClone); } if(waypoints.Count > 0) { FileExportForm fileExportForm = new FileExportForm(null, false, waypoints, true); fileExportForm.ShowDialog(); } else { Project.ShowPopup(exportButton, "\nno photo points to export", Point.Empty); } }