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 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); } }
public static void cleanPhotoTrackpoints(string thumbFileName) // thumbFileName may be null - then clean all, else clean one { for (int i = 0; i < WaypointsWithThumbs.Count; i++) { Waypoint wpt = (Waypoint)WaypointsWithThumbs.GetByIndex(i); if (thumbFileName == null || thumbFileName.Equals(wpt.ThumbSource)) { Track trk = WaypointsCache.getTrackById(wpt.TrackId); if (trk != null) { trk.Trackpoints.Remove(wpt.DateTime); } if (thumbFileName != null) { WaypointsWithThumbs.RemoveAt(i); break; } } } if (thumbFileName == null) { WaypointsWithThumbs.Clear(); } hasCurrentWaypoint(); // make sure the pointer is as sane as it can be }
// real-time track logging: private bool logTrack(GpsRealTimeData rtData) { bool ret = false; // only good fixes with non-null location reach here string source = this.Label + " " + DateTime.Now; if (trackId == -1) { trackId = ++Project.trackId; string trackName = "VEHICLE-LOG-" + trackId + " " + this.Label; CreateInfo createInfo = new CreateInfo(); createInfo.init("trk"); createInfo.name = trackName; createInfo.id = trackId; createInfo.source = source; totalTrkpt = 0; WaypointsCache.insertWaypoint(createInfo); // actually inserts a track WaypointsCache.isDirty = true; } // garmin sends data every second, even if it is same point. Ignore repetetions to save memory. double[] howfars = new Double[] { 0.0d, 1.0d, 10.0d, 20.0d, 50.0d, 100.0d }; double howFarMeters = howfars[howfarIndex]; GeoCoord loc = new GeoCoord(rtData.location.Lng, rtData.location.Lat, rtData.location.Elev); // tolerance 0.0001 degree = 10 meters if (howfarIndex == 0 || !loc.almostAs(lastLoc, howFarMeters * 0.00001d)) // 0 means every incoming reading { CreateInfo createInfo = new CreateInfo(); createInfo.init("trkpt"); createInfo.id = trackId; // relate waypoint to track createInfo.dateTime = rtData.time; createInfo.lat = rtData.location.Lat; createInfo.lng = rtData.location.Lng; createInfo.elev = rtData.location.Elev; createInfo.source = source; //createInfo.name = "" + totalTrkpt; // track point name lastLat = rtData.location.Lat; lastLng = rtData.location.Lng; lastElev = rtData.location.Elev; totalTrkpt++; ret = true; WaypointsCache.insertWaypoint(createInfo); lastLoc = loc; } return(ret); }
public LayerWaypoints(PictureManager pm, CameraManager cm) : base(pm, cm) { WaypointsCache.PictureManager = pm; WaypointsCache.CameraManager = cm; WaypointsCache.init(); This = this; }
public override void CameraMoved() { // LibSys.StatusBar.Trace("IP: LayerWaypoints::CameraMoved() drawableReady=" + Project.drawableReady); init(); base.CameraMoved(); WaypointsCache.RefreshWaypointsDisplayed(); sLiveObjectPopup = null; logCamtrackFrame(); }
public static void cleanPhotoTrackpointsBySource(string sourceFileName) { for (int i = WaypointsWithThumbs.Count - 1; i >= 0; i--) { Waypoint wpt = (Waypoint)WaypointsWithThumbs.GetByIndex(i); string wptSource = wpt.Source; if (wptSource.StartsWith(sourceFileName)) { string rem = wptSource.Substring(sourceFileName.Length); if (rem.IndexOf("\\") <= 0) // can start with \, like in "\trip.gpx" { Track trk = WaypointsCache.getTrackById(wpt.TrackId); if (trk != null) { trk.Trackpoints.Remove(wpt.DateTime); } WaypointsWithThumbs.RemoveAt(i); } } else if (wptSource.IndexOf("\\") <= 0) // came from GPS, not from file - try if thumbSource matches { string wptImgSource = wpt.ThumbSource; if (wptImgSource.StartsWith(sourceFileName)) { Track trk = WaypointsCache.getTrackById(wpt.TrackId); if (trk != null) { trk.Trackpoints.Remove(wpt.DateTime); } WaypointsWithThumbs.RemoveAt(i); } } } hasCurrentWaypoint(); // make sure the pointer is as sane as it can be }
public void communicate() { if (Project.gpsSimulate) { m_gps.init(); switch (command) { case "uploadTracks": case "uploadRoutes": case "downloadRoutes": case "uploadWaypoints": case "downloadWaypoints": case "getDeviceInfo": MessageCallback("FYI: operation '" + command + "' ignored by GPS simulator"); break; case "startRealtime": simulateStartRealTime(RealTimeCallback); break; default: MessageCallback("Error: GPS operation '" + command + "' not supported"); break; } CompleteCallback("GPS communication complete (simulated)", true); m_gps.Dispose(); return; } try { bool isSuccess = false; m_gps.init(); for (int cnt = 0; cnt < 3; cnt++) { m_gps.IdentifyDeviceType(); if (m_gps.DeviceValid()) { break; } Thread.Sleep(2000); } if (m_gps.DeviceValid()) { // now we know type of device and it's capabilities, do the task. string strDeviceInfo = ""; if (!"getDeviceInfo".Equals(command)) { ProgressCallback(m_gps.ToString(), -1, 0); } else { ProgressCallback("", -1, 0); } wptBuffer.Clear(); switch (command) { case "uploadTracks": Project.inhibitRefresh = true; WaypointsCache.resetBoundaries(); m_gps.GetTracks(new GpsInsertWaypoint(bufferWaypoint), ProgressCallback); MessageCallback("IP: drawing tracks on the map\n\nUse 'Wpt Trk Rte' button to see the track."); // now when all waypoint/track infos are buffered, use them to fill cache foreach (CreateInfo createInfo in wptBuffer) { m_insertWaypoint(createInfo); isSuccess = true; } WaypointsCache.isDirty = isSuccess; break; case "uploadRoutes": Project.inhibitRefresh = true; WaypointsCache.resetBoundaries(); m_gps.GetRoutes(new GpsInsertWaypoint(bufferWaypoint), ProgressCallback); MessageCallback("IP: drawing routes on the map\n\nUse 'Wpt Trk Rte' button to see the routes."); // now when all waypoint/route infos are buffered, use them to fill cache foreach (CreateInfo createInfo in wptBuffer) { m_insertWaypoint(createInfo); isSuccess = true; } WaypointsCache.isDirty = isSuccess; break; case "uploadWaypoints": Project.inhibitRefresh = true; WaypointsCache.resetBoundaries(); m_gps.GetWaypoints(new GpsInsertWaypoint(bufferWaypoint), ProgressCallback); MessageCallback("IP: drawing waypoints on the map\n\nUse 'Wpt Trk Rte' button to see the list of waypoints."); // now when all waypoint/track infos are buffered, use them to fill cache foreach (CreateInfo createInfo in wptBuffer) { m_insertWaypoint(createInfo); isSuccess = true; } WaypointsCache.isDirty = isSuccess; break; case "downloadWaypoints": Project.inhibitRefresh = true; m_gps.PutWaypoints(m_waypoints, ProgressCallback); isSuccess = true; break; case "downloadRoutes": Project.inhibitRefresh = true; m_gps.PutRoutes(m_routes, ProgressCallback, Project.startRouteNumber); isSuccess = true; break; case "startRealtime": m_gps.StartRealTime(RealTimeCallback); isSuccess = true; break; //case "stopRealtime": // cannot do it here, as it doesn't require separate thread // m_gps.StopRealTime(); // break; default: MessageCallback("Error: ThreadGpsControl operation '" + command + "' not supported"); break; case "getDeviceInfo": strDeviceInfo = m_gps.ToString() + "\n\n"; isSuccess = true; break; } wptBuffer.Clear(); CompleteCallback(strDeviceInfo + "GPS communication complete", isSuccess); } else { switch (m_errorAdviceTry++) { case 0: CompleteCallback("GPS not responding, check cable and baud rate.\nMake sure your GPS communication protocol is set to " + AllGpsDevices.AllMakesNames[Project.gpsMakeIndex] + ".", false); break; default: CompleteCallback("GPS not responding, check cable and baud rate.", false); break; } } } catch (Exception exc) { switch (m_errorAdviceTry++) { case 0: CompleteCallback("" + exc.Message + " -- make sure your GPS communication protocol is set to " + AllGpsDevices.AllMakesNames[Project.gpsMakeIndex] + ".", false); break; default: CompleteCallback("" + exc.Message, false); break; } } finally { Project.inhibitRefresh = false; m_gps.Dispose(); } }
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); }
// 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); }
private void logCamtrackFrame() { if (Project.camTrackOn) { CameraTrack cameraTrack = WaypointsCache.CameraManager.CameraTrack; XmlDocument xmlDoc = cameraTrack.XmlDoc; XmlNode wNode = xmlDoc.CreateNode(XmlNodeType.Element, "waypoints", null); XmlAttribute attr = xmlDoc.CreateAttribute("description"); attr.InnerText = "Waypoints: " + DateTime.Now; wNode.Attributes.Append(attr); XmlNode tNode = xmlDoc.CreateNode(XmlNodeType.Element, "trackpoints", null); attr = xmlDoc.CreateAttribute("description"); attr.InnerText = "Trackpoints: " + DateTime.Now; tNode.Attributes.Append(attr); ArrayList trackIds = new ArrayList(); SortedList tmpList = new SortedList(); // trackpoints are added to tmplist, other waypoints are added directly to <waypoints>: foreach (Waypoint wpt in WaypointsCache.WaypointsDisplayed) { try { if (wpt.TrackId != -1) { tmpList.Add(wpt.DateTime, wpt); } else { XmlNode wptNode = wpt.ToCamtrackXmlNode(xmlDoc); wNode.AppendChild(wptNode); } } // we will probably lose some trackpoints (with same time, up to second). The benefit is that we will have a sorted list. #if DEBUG catch (Exception e) { LibSys.StatusBar.Error("" + e); } #else catch { } #endif } attr = xmlDoc.CreateAttribute("count"); attr.InnerText = "" + wNode.ChildNodes.Count; wNode.Attributes.Append(attr); cameraTrack.log(wNode); // now convert trackpoints list to nodes under <trackpoints> for (int i = 0; i < tmpList.Count; i++) { Waypoint wpt = (Waypoint)tmpList.GetByIndex(i); XmlNode wptNode = wpt.ToCamtrackXmlNode(xmlDoc); tNode.AppendChild(wptNode); if (!trackIds.Contains(wpt.TrackId)) { trackIds.Add(wpt.TrackId); } } tmpList.Clear(); attr = xmlDoc.CreateAttribute("count"); attr.InnerText = "" + tNode.ChildNodes.Count; tNode.Attributes.Append(attr); cameraTrack.log(tNode); // make a list of track IDs used by trackpoints under <tracks>: XmlNode node = xmlDoc.CreateNode(XmlNodeType.Element, "tracks", null); foreach (long trackId in trackIds) { Track trk = WaypointsCache.getTrackById(trackId); if (trk != null) { XmlNode trkNode = xmlDoc.CreateNode(XmlNodeType.Element, "trk", null); attr = xmlDoc.CreateAttribute("trkid"); attr.InnerText = "" + trk.Id; trkNode.Attributes.Append(attr); trkNode.InnerText = trk.Name; node.AppendChild(trkNode); } } attr = xmlDoc.CreateAttribute("count"); attr.InnerText = "" + node.ChildNodes.Count; node.Attributes.Append(attr); cameraTrack.log(node); } }
private void PutOnMap() { #if DEBUG LibSys.StatusBar.Trace("IP: LayerWaypoints:PutOnMap() " + WaypointsCache.WaypointsAll.Count); #endif foreach (LiveObject lo in WaypointsCache.WaypointsAll) { try { lo.init(true); } catch (Exception e) { LibSys.StatusBar.Error("LW:PutOnMap(): lo=" + lo + " " + e.Message); } } foreach (LiveObject lo in WaypointsCache.WaypointsAll) { try { if (m_cameraManager.insideScreenRectangle(lo.Location)) { lo.PutOnMap(this, null, this); } } catch (Exception e) { LibSys.StatusBar.Error("LW:PutOnMap(): lo=" + lo + " " + e.Message); } } foreach (LiveObject lo in WaypointsCache.WaypointsAll) { try { if (m_cameraManager.insideScreenRectangle(lo.Location)) { lo.AdjustPlacement(this, null, this); } } catch (Exception e) { LibSys.StatusBar.Error("LW:PutOnMap() - AdjustPlacement: lo=" + lo + " " + e.Message); } } foreach (Track trk in WaypointsCache.TracksAll) { try { trk.PutOnMap(this, null, this); } catch (Exception e) { LibSys.StatusBar.Error("LW:PutOnMap(): trk=" + trk + " " + e.Message); } } /* * foreach(Track trk in WaypointsCache.TracksAll) * { * try * { * trk.AdjustPlacement(this, null, this); * } * catch(Exception e) * { * LibSys.StatusBar.Error("LW:PutOnMap(): trk=" + trk + " " + e.Message); * } * } */ m_hasPutOnMap = true; WaypointsCache.RefreshWaypointsDisplayed(); //logCamtrackFrame(); }
public override void shutdown() { WaypointsCache.shutdown(); }