Esempio n. 1
0
        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
        }
Esempio n. 2
0
        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
                    {
                    }
                }
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        // 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);
        }
Esempio n. 7
0
        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);
            }
        }