Example #1
0
        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 DlgPreloadTilesAlongRoute(Track trk)
        {
            m_trk = trk;

            InitializeComponent();

            progressBar1.Visible = false;

            hintLabel.Text = "Terraserver tiles will be loaded to:\r\n" + Project.GetTerraserverMapsBasePath()
                    + "\r\n\r\nPlease note that loading too many tiles wastes valuable resources.";

            selectParametersGroupBox.Enabled = false;

            this.scaleComboBox.Items.Clear();
            this.scaleComboBox.Items.AddRange(new object[] {
                                                                "1",
                                                                "2",
                                                                "4",
                                                                "8",
                                                                "16",
                                                                "32",
                                                                "64"
                                                           });
            scaleComboBox.SelectedIndex = m_preloadScale;

            this.spreadComboBox.Items.AddRange(new object[] {
                                                                "0.25 mile",
                                                                "0.5 mile",
                                                                "1 mile",
                                                                "2 miles",
                                                                "4 miles",
                                                                "8 miles",
                                                                "16 miles"
                                                            });

            spreadComboBox.SelectedIndex = m_spreadIndex;
            m_spread = m_spreads[spreadComboBox.SelectedIndex];

            scaleUpCheckBox.Checked = scaleUpDefaultChecked;

            pdaExportOptions.Dock = DockStyle.Fill;
            exportOptionsGroupBox.Controls.Add(pdaExportOptions);
            pdaExportOptions.OptionsChanged += new EventHandler(pdaOptionsChanged);

            Project.setDlgIcon(this);
        }
Example #3
0
        // 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;
        }
Example #4
0
 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;
         }
     }
 }
Example #5
0
        // 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;
        }
Example #6
0
 // finishing make route mode
 private void finishMakeRoute()
 {
     if(m_routeTrack != null)
     {
         if(m_routeTrack.Trackpoints.Count < 2)
         {
             // that was an empty or one-point route, delete it.
             WaypointsCache.TracksAll.Remove(m_routeTrack);
             m_cameraManager.ProcessCameraMove();		// make sure that single label, if any, is removed the map
         }
         else
         {
             // real route, show it all with the endpoint named appropriately:
             Waypoint wpt = (Waypoint)m_routeTrack.Trackpoints.GetByIndex(m_routeTrack.Trackpoints.Count - 1);
             string wptName = "End route";
             wpt.NameDisplayed = wptName;
             m_cameraManager.ProcessCameraMove();		// make sure label is positionsed on the map
             WaypointsCache.isDirty = true;
         }
         m_routeTrack = null;
     }
 }
Example #7
0
        // 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 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);
            }
        }
Example #9
0
        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);
                }
            }
        }
Example #10
0
 public static void reset()
 {
     track = null;
     fromTrkpt = null;
     toTrkpt = null;
     Enabled = false;
 }
        private void duatsConvertButton_Click(object sender, System.EventArgs e)
        {
            string duatsPlanTxt = duatsTextBox.Text;

            TextReader reader = new StringReader(duatsPlanTxt);

            Track route = null;

            int state = 0;
            string str;

            string fromName = null;
            string toName = null;
            string wptName = null;
            string wptDescr = null;
            string wptLon = null;
            string wptLat = null;
            string wptAlt = null;
            string wptUrl = "";

            string wptFuel = null;
            string wptTime = null;
            string wptDist = null;

            string legFuel = null;
            string legTime = null;
            string legDist = null;

            int wptcnt = 0;
            DateTime startDate = Project.localToZulu(new DateTime(7000, 1, 1));

            try
            {
                while ((str=reader.ReadLine()) != null)
                {
                    switch(state)
                    {
                        case 0:
                            if(str.StartsWith("From:"))
                            {
                                fromName = str.Substring(5);
                            }
                            if(str.StartsWith("To:"))
                            {
                                toName = str.Substring(3);
                                state = 100;

                                CreateInfo createInfo = new CreateInfo();
                                createInfo.init("rte");
                                Project.trackId++;
                                createInfo.id = Project.trackId;
                                createInfo.name = fromName + " ->> " + toName;
                                createInfo.source = "From DUATS.COM flight plan";

                                route = new Track(createInfo);
                            }
                            break;

                        case 100:
                            if(str.StartsWith("---+--------+---------+-----"))
                            {
                                state = 110;
                            }
                            break;

                        case 110:
                            if(str.Length > 51 && str.Substring(2,1) == ".")
                            {
                                wptFuel = str.Substring(54).Trim();
                                wptName = str.Substring(4, 24).Replace("Apt.", "").Trim();
                                state = 120;
                            }
                            else
                            {
                                state = 900;
                            }
                            break;

                        case 120:
                            wptTime = str.Substring(54).Trim();
                            wptDescr = str.Substring(4, 24).Trim();
                            state = 130;
                            break;

                        case 130:
                        {
                            wptDist = str.Substring(54).Trim();

                            wptLat = str.Substring(4, 8);
                            wptLon = str.Substring(13, 9);
                            wptAlt = str.Substring(22, 5).Trim() + "00";	// feet
                            //LibSys.StatusBar.Trace("lat='" + wptLat + "' lon='" + wptLon + "' alt='" + wptAlt + "'");

                            double altMeters = Convert.ToDouble(wptAlt) * Distance.METERS_PER_FOOT;
                            // sPos in form: W117.23'45" N36.44'48" [or N33,27.661 W117,42.945]
                            string sPos = "W" + wptLon.Substring(0,3).Trim() + "." + wptLon.Substring(4,2) + "'" + wptLon.Substring(7) + "\" "
                                + "N" + wptLat.Substring(0,2).Trim() + "." + wptLat.Substring(3,2) + "'" + wptLat.Substring(6) + "\"";
                            //LibSys.StatusBar.Trace("sPos='" + sPos + "'");
                            GeoCoord loc = new GeoCoord(sPos);
                            loc.Elev = altMeters;
                            //LibSys.StatusBar.Trace("wpt='" + loc + "'");

                            //DateTime wptDateTime = DateTime.Now.AddMilliseconds(wptcnt);

                            string[] split = wptTime.Split(new Char[] { ':' });
                            double hours = Convert.ToDouble(split[0]);
                            double minutes = Convert.ToDouble(split[1]);
                            DateTime wptDateTime = startDate.AddHours(hours).AddMinutes(minutes);

                            Waypoint wpt = new Waypoint(loc, wptDateTime, LiveObjectTypes.LiveObjectTypeRoutepoint, route.Id, wptName, route.Source, wptUrl);
                            wpt.Desc = wptDescr + "\nFuelSpent: " + wptFuel + " TimeInFlight: " + wptTime + " DistLeft: " + wptDist;
                            wptcnt++;

                            route.Trackpoints.Add(wpt.DateTime, wpt);
                        }

                            state = 100;
                            break;
                    }
                }
            }
            catch (Exception exc)
            {
                LibSys.StatusBar.Error("Exception: " + exc);
            }

            if(route == null)
            {
                System.Windows.Forms.MessageBox.Show(this, "Error: No data to parse.\n\nPlease copy DUATS.COM generated flight plan into the text field.\n\nIt should look like this:\n\n" + m_duatsSample);
            }
            else
            {
                WaypointsCache.TracksAll.Add(route);
                route.rebuildTrackBoundaries();
                route.PutOnMap(LayerWaypoints.This, null, LayerWaypoints.This);
                m_routeIdToSelect = route.Id;

                // refresh map and rebind the datagrid:
                PutOnMap();
                WaypointsCache.isDirty = true;
                //rebuildTracksTab();
                rebuildRoutesTab();
                tabControl1.SelectedTab = this.routesTabPage;
                prevSelectedTab = this.routesTabPage;
            }
        }
Example #12
0
 public static int getStep(Track track, double elev)
 {
     int step = 1;
     if(elev > BIG_STEP_TRESHOLD)
     {
         step = track.Trackpoints.Count / BIG_STEP_DIVIDER;
         if(step < 1)
         {
             step = 1;
         }
     }
     return step;
 }
Example #13
0
        /// <summary>
        /// for tracks only
        /// </summary>
        /// <returns></returns>
        public Track toRoute()
        {
            if(!this.isRoute)
            {
                CreateInfo createInfo = new CreateInfo();
                createInfo.init("rte");
                Project.trackId++;
                createInfo.id = Project.trackId;
                createInfo.name = "From " + this.Name;
                createInfo.source = "From " + m_source;

                Track route = new Track(createInfo);

                int step = (int)Math.Ceiling((double)m_trackpoints.Count / (double)Project.gpsMaxPointsPerRoute);
                if(step <= 0)
                {
                    step = 1;
                }

                int iLast = 0;
                for(int i=0; i < m_trackpoints.Count && route.Trackpoints.Count < Project.gpsMaxPointsPerRoute - 1 ;i+=step)
                {
                    Waypoint wpt = (Waypoint)m_trackpoints.GetByIndex(i);
                    if(wpt.ThumbImage != null)
                    {
                        i -= step - 1;		// move to a trackpoint immediately after the photo point
                        continue;
                    }
                    iLast = i;

                    Waypoint wptClone = new Waypoint(wpt);
                    wptClone.LiveObjectType = LiveObjectTypes.LiveObjectTypeRoutepoint;
                    wptClone.TrackId = route.Id;
                    wptClone.Source = route.Source;
                    route.Trackpoints.Add(wptClone.DateTime, wptClone);
                }

                // we want the end of the route to be the end track point:
                if(iLast < m_trackpoints.Count - 1)
                {
                    Waypoint wpt = (Waypoint)m_trackpoints.GetByIndex(m_trackpoints.Count - 1);

                    Waypoint wptClone = new Waypoint(wpt);
                    wptClone.TrackId = route.Id;
                    wptClone.Source = route.Source;
                    route.Trackpoints.Add(wptClone.DateTime, wptClone);
                }
                route.rebuildTrackBoundaries();

                return route;
            }
            return null;
        }
Example #14
0
        public void setTrackAndTrackpoint(Track trk, Waypoint trkpt)
        {
            m_track = trk;
            m_trkpt = trkpt;

            rebuildGraph();
        }
        public static void runTrack(Track trk)
        {
            KmlDocument kmlDoc = createKmlTrack(trk);

            kmlDoc.run();
        }
        public static KmlDocument createKmlTrack(Track trk)
        {
            KmlDocument kmlDoc = new KmlDocument(trk.Name, 1);

            KmlFolder waypointsFolder = kmlDoc.CreateFolder("Waypoints");

            KmlFolder tracksFolder = kmlDoc.CreateFolder("Tracks");

            KmlTrack kTrack = new KmlTrack(tracksFolder, trk);

            kmlDoc.CreateAbout();

            return kmlDoc;
        }