Exemplo n.º 1
0
        private void realtimeCallback( GpsRealTimeData rtData )
        {
            if(!closing)
            {
                this.timeLabel.Text = rtData.time.Equals(DateTime.MinValue) ? "" : ("" + Project.zuluToLocal(rtData.time));
                this.fixLabel.Text = rtData.fixStr;
                this.statusLabel.Text = "PC: " + DateTime.Now.ToLongTimeString() + " - " + rtData.comment;
                switch (rtData.fix)
                {
                    case 0:
                    case 1:
                    case -1:
                        this.positionLabel.Text = "No GPS fix";
                        this.altLabel.Text = "";
                        this.accuracyLabel.Text = "";
                        this.speedLabel.Text = "";
                        this.magnHeadingLabel.Text = "";
                        this.trueHeadingLabel.Text = "";
                        this.slopeLabel.Text = "";
                        lastFixLoc = null;
                        gpsBasicsGroupBox.BackColor = Color.Pink;
                        gpsBasicsGroupBox.Text = "";
                        break;
                    default:
                        if(rtData.location != null)
                        {
                            string sLoc = rtData.location.ToString();		// alt not included
                            this.positionLabel.Text = sLoc.Replace(" ", "   ");
                            //LibSys.StatusBar.Trace2(sLoc);
                            Distance dAlt = new Distance(rtData.location.Elev);
                            this.altLabel.Text = "" + dAlt.ToString(Distance.UNITS_DISTANCE_FEET);
                        }
                        else
                        {
                            this.positionLabel.Text = "";
                            this.altLabel.Text = "";
                            //LibSys.StatusBar.Trace2("GPS: no fix");
                        }
                        Distance dAccH = new Distance(rtData.posErrorH);
                        Distance dAccV = new Distance(rtData.posErrorV);
                        this.accuracyLabel.Text =
                            (rtData.posErrorH > 0 ? (dAccH.ToString(Distance.UNITS_DISTANCE_FEET) + "(Horiz)") : "") + "   "
                            + (rtData.posErrorV > 0 ? (dAccV.ToString(Distance.UNITS_DISTANCE_FEET) + "(Vert)") : "");

                        double variation = Math.Round(rtData.location.magneticVariation());
                        string variationDir = variation > 0.0d ? "W" : "E";

                        bool hasHeading = false;
                        double headingTrue = 0.0d;
                        double headingMagn = 0.0d;
                        string slopeInfo = "";

                        if(lastFixLoc != null)
                        {
                            headingTrue = Math.Round(lastFixLoc.bearing(rtData.location) * 180.0d / Math.PI, 1);
                            headingMagn = (headingTrue + variation + 360.0d) % 360.0d;
                            hasHeading = true;

                            double dAlt = rtData.location.Elev - lastFixLoc.Elev;	// meters
                            double dDist = rtData.location.distanceFrom(lastFixLoc).Meters;
                            double dSlope = Math.Atan(dAlt / dDist) * 180.0d / Math.PI;
                            double dTimeMs = (DateTime.Now - lastFixDateTime).TotalMilliseconds + 1.0d;		// 1.0d to avoid 0
                            double fpm = dAlt / dTimeMs / Distance.METERS_PER_FOOT * 1000.0d * 60.0d;
                            string fpmFormat = Math.Abs(fpm) > 20.0d ? "1:F0" : "1:F1";

                            if(fpm > 1.0d || dSlope >= 0.1d)
                            {
                                slopeInfo = String.Format("slope: {0:F1}° (up) - climbing at {" + fpmFormat + "} fpm", dSlope, fpm);
                            }
                            else if(fpm < -1.0d || dSlope <= -0.1d)
                            {
                                slopeInfo = String.Format("slope: {0:F1}° (down) - descending at {" + fpmFormat + "} fpm", -dSlope, -fpm);
                            }
                        }

                        Speed dSpeed = new Speed(rtData.velocity * 3600.0d);		// rtData.velocity is in meters/sec, Speed requires meters/hr
                        if(dSpeed.Meters < 300)
                        {
                            this.speedLabel.Text = "0";
                            this.magnHeadingLabel.Text = "";
                            this.trueHeadingLabel.Text = "";
                        }
                        else
                        {
                            this.speedLabel.Text = dSpeed.ToString();
                        }

                        this.magnHeadingLabel.Text = (hasHeading ? String.Format("{0:000}°", Math.Round(headingMagn)) : "");
                        this.trueHeadingLabel.Text = (hasHeading ? String.Format("true heading: {0:000}°", Math.Round(headingTrue)) : "") + String.Format("  variation {0:F0}{1}", Math.Abs(variation), variationDir);

                        this.slopeLabel.Text = slopeInfo;

                        lastFixLoc = new GeoCoord(rtData.location);
                        lastFixDateTime = DateTime.Now;
                        gpsBasicsGroupBox.BackColor = Color.LightGreen;
                        gpsBasicsGroupBox.Text = "";
                        break;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// returns a formatted string suitable for popups
        /// </summary>
        /// <returns></returns>
        public string toStringPopup()
        {
            StringBuilder builder = new StringBuilder();
            string speedLbl = null;
            string odometerLbl = null;
            string timeTraveledLbl = null;
            string timeThisLegLbl = null;
            string timeRemainingLbl = null;

            if(m_wptFrom.TrackId != -1)
            {
                Track trk = (Track)Project.mainCommand.getTrackById(m_wptFrom.TrackId);
                Distance dOdometer;

                if(trk != null)
                {
                    int i = trk.Trackpoints.IndexOfValue(this);
                    builder.Append("Leg : " + m_wptFrom.Name + " --> " + m_wptTo.Name);
                    builder.Append("\nof " + (trk.isRoute ? "Route" : "Track") + m_wptFrom.TrackId + " : " + trk.Name + "\n");

                    if(HasSpeed)
                    {
                        Speed dSpeed = new Speed(this.Speed);				// meters per hour
                        speedLbl = dSpeed.ToString();
                    }

                    TimeSpan ts = m_wptFrom.DateTime - trk.Start;
                    timeTraveledLbl = Project.TimeSpanToString(ts);

                    timeThisLegLbl = Project.TimeSpanToString(m_duration);

                    ts = trk.End - m_wptTo.DateTime;
                    timeRemainingLbl = Project.TimeSpanToString(ts);

                    dOdometer = new Distance(m_wptFrom.Odometer);	// meters
                    odometerLbl = dOdometer.ToString() + " plus this leg: " + Dist.ToString();
                }
            }
            builder.Append(m_wptFrom.Location.toString00(false, Project.coordStyle));
            Distance dElev = new Distance(m_wptFrom.Location.Elev);
            if(dElev.Meters != 0.0d)
            {
                builder.Append("  elev: " + dElev.ToStringCompl() + "\n");
            }

            if(m_wptFrom.DateTime.Ticks > minDateTimeTicks)
                // waypoint times are added to to avoid duplicates, we need to compare with tolerance
            {
                builder.Append("\n  " + Project.zuluToLocal(m_wptFrom.DateTime));
            }
            if(odometerLbl != null)
            {
                builder.Append((speedLbl == null ? "\n" : "  ") +  "odometer: " + odometerLbl);
            }
            if(speedLbl != null)
            {
                builder.Append("\n  speed: " + speedLbl);
            }
            builder.Append("\n time");
            if(timeTraveledLbl != null)
            {
                builder.Append(" traveled: " + timeTraveledLbl);
            }
            builder.Append(" this leg: " + timeThisLegLbl);
            if(timeRemainingLbl != null)
            {
                builder.Append("   remaining: " + timeRemainingLbl);
            }

            addCourseData(builder, false);

            return builder.ToString();
        }
Exemplo n.º 3
0
        protected void setFormFields()
        {
            if(m_wpt.LiveObjectType == LiveObjectTypes.LiveObjectTypeGeocache)
            {
                waypointTypeComboBox.SelectedIndex = m_wpt.Found ? 2 : 1;
            }
            else
            {
                waypointTypeComboBox.SelectedIndex = 0;
            }

            waypointNameTextBox.Text = m_wpt.WptName;
            urlNameTextBox.Text = m_wpt.UrlName;
            urlTextBox.Text = (m_wpt.Url.Trim().Length == 0) ? "http://" : m_wpt.Url.Trim();
            commentTextBox.Text = m_wpt.Comment;
            symbolTextBox.Text = m_wpt.Sym;
            timePicker.dateTime = Project.zuluToLocal(m_wpt.DateTime);

            if(m_wpt.TrackId != -1)
            {
                headerLabel.Visible = true;
                headerLabel.Text = m_wpt.trackInfoString();
                coordFormatLabel.Visible = false;
                waypointNameTextBox.Enabled = false;
                waypointNameTextBox.Text = m_wpt.Name;
                waypointTypeComboBox.Visible = false;
                typeLabel.Visible = false;
                //timePicker.Enabled = false;
                longitudeTextBox.Enabled = false;
                latitudeTextBox.Enabled = false;
                Track trk = (Track)Project.mainCommand.getTrackById(m_wpt.TrackId);
                if(trk != null)
                {
                    if(!trk.isRoute)
                    {
                        // do not allow track elevation editing
                        elevationTextBox.Enabled = false;
                    }
                }
                else
                {
                    elevationTextBox.Enabled = false;
                }

                if(m_wpt.ThumbImage != null)
                {
                    // can't edit photo points, they are transient
                    coordFormatLabel.Text = "Can't edit photo point";
                    urlNameTextBox.Enabled = false;
                    commentTextBox.Enabled = false;
                    symbolTextBox.Enabled = false;
                    urlTextBox.Enabled = false;
                    detailTextBox.Enabled = false;
                    goButton.Enabled = false;
                    cancelButton.Focus();
                }
                else
                {
                    detailTextBox.Focus();
                }

                if(m_wpt.HasSpeed)
                {
                    speedLabel.Visible = true;
                    speedTextBox.Visible = true;
                    Speed dSpeed = new Speed(m_wpt.Speed);				// meters per hour
                    string speedLbl = dSpeed.toStringN(Project.unitsDistance);
                    speedTextBox.Text = speedLbl;
                    speedUnitsLabel.Visible = true;
                    speedUnitsLabel.Text = dSpeed.toStringU(Project.unitsDistance);
                }
                else
                {
                    speedLabel.Visible = false;
                    speedTextBox.Visible = false;
                    speedUnitsLabel.Visible = false;
                }
            }
            else
            {
                speedLabel.Visible = false;
                speedTextBox.Visible = false;
                speedUnitsLabel.Visible = false;

                waypointNameTextBox.Focus();
            }

            try
            {
                StringReader reader = new StringReader(m_wpt.Desc);

                string str;
                StringBuilder sb = new StringBuilder();
                while((str=reader.ReadLine()) != null)
                {
                    sb.Append(str);
                    sb.Append("\r\n");
                }
                detailTextBox.Text = sb.ToString().Trim();
            }
            catch {}
        }
Exemplo n.º 4
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);
                }
            }
        }
Exemplo n.º 5
0
        public string ToStringProfile()
        {
            StringBuilder builder = new StringBuilder();
            Waypoint nextWpt = null;
            string speedLbl = null;
            string odometerLbl = null;
            string timeTraveledLbl = null;
            string timeRemainingLbl = null;

            bool doTime = true;
            if(this.Desc != null && this.Desc.Length > 0 && !this.Desc.Equals(this.Name))
            {
                builder.Append(this.Desc.Trim() + "  ");
            }
            if(this.TrackId != -1)
            {
                Track trk = (Track)Project.mainCommand.getTrackById(this.TrackId);
                if(trk != null)
                {
                    int i = trk.Trackpoints.IndexOfValue(this);
                    nextWpt = (i < trk.Trackpoints.Count-1) ? (Waypoint)trk.Trackpoints.GetByIndex(i+1) : null;
                    string name = this.Name;
                    if(trk.isRoute)
                    {
                        builder.Append(name + " | ");
                        doTime = false;
                        if(HasOdometer)
                        {
                            Distance dOdometer = new Distance(this.Odometer);	// meters
                            odometerLbl = dOdometer.ToString();
                        }
                    }
                    else
                    {
                        builder.Append(name + " | ");
                        if(HasSpeed)
                        {
                            Speed dSpeed = new Speed(this.Speed);				// meters per hour
                            speedLbl = dSpeed.ToString();
                        }
                        TimeSpan ts = this.DateTime - trk.Start;
                        timeTraveledLbl = Project.TimeSpanToString(ts);

                        ts = trk.End - this.DateTime;
                        timeRemainingLbl = Project.TimeSpanToString(ts);
                    }
                    if(HasOdometer)
                    {
                        Distance dOdometer = new Distance(this.Odometer);	// meters
                        odometerLbl = dOdometer.ToString();
                    }
                }
            }
            builder.Append(this.Location.toString00(false, Project.coordStyle));
            Distance dElev = new Distance(this.Location.Elev);
            if(dElev.Meters != 0.0d)
            {
                builder.Append("  elev: " + dElev.ToStringCompl() + " ");
            }

            if(doTime && this.DateTime.Ticks > minDateTimeTicks)
                // waypoint times are added to to avoid duplicates, we need to compare with tolerance
            {
                builder.Append(" " + Project.zuluToLocal(this.DateTime));
            }
            if(speedLbl != null)
            {
                builder.Append("  speed: " + speedLbl);
            }
            if(odometerLbl != null)
            {
                builder.Append("  odometer: " + odometerLbl);
            }
            if(timeTraveledLbl != null)
            {
                builder.Append("  time traveled: " + timeTraveledLbl);
            }
            if(timeRemainingLbl != null)
            {
                builder.Append("  time remaining: " + timeRemainingLbl);
            }
            if(nextWpt != null && !this.Location.sameAs(nextWpt.Location))
            {
                addCourseData(builder, nextWpt, false);
            }
            if(this.WptName != null && this.WptName.Length > 0)
            {
                builder.Append(" Name: " + this.WptName.Trim());
            }
            if(this.TrackId == -1 && this.LiveObjectType == LiveObjectTypes.LiveObjectTypeGeocache && this.DateTime.Ticks > minDateTimeTicks)
            {
                builder.Append("      Hidden: " + Project.zuluToLocal(this.DateTime).ToShortDateString());
            }
            if(this.UrlName != null && this.UrlName.Length > 0)
            {
                builder.Append(" Url Name: " + this.UrlName.Trim());
            }
            if(this.Comment != null && this.Comment.Length > 0)
            {
                builder.Append(" Comment: " + this.Comment.Trim());
            }
            if(this.ThumbImage != null && this.ThumbSource != null && this.ThumbSource.Length > 0)
            {
                string sTimeShift  = toDelayString(PhotoTimeShift);
                builder.Append((imageWidth > 0 && imageHeight > 0 ? (" " + imageWidth + "x" + imageHeight + "       ") : " "));
                builder.Append("camera time shift: " + sTimeShift + " ");
                builder.Append(this.ThumbSource);
            }

            builder.Replace("\n", " ");

            return builder.ToString();
        }
Exemplo n.º 6
0
        /// <summary>
        /// short info string about the trackpoint for elevation graph
        /// </summary>
        /// <returns></returns>
        public string graphInfoString()
        {
            string tmp = "";

            string speedLbl = null;
            string odometerLbl = null;

            Track trk = (Track)Project.mainCommand.getTrackById(this.TrackId);
            if(trk != null)
            {
                if(trk.isRoute)
                {
                    tmp += "Route " + this.TrackId + ": " + trk.Name;
                    if(HasOdometer)
                    {
                        Distance dOdometer = new Distance(this.Odometer);	// meters
                        odometerLbl = dOdometer.ToString();
                    }
                }
                else
                {
                    tmp += "Track " + this.TrackId + ": " + trk.Name;
                    if(HasSpeed)
                    {
                        Speed dSpeed = new Speed(this.Speed);				// meters per hour
                        speedLbl = dSpeed.ToString();
                    }
                    if(HasOdometer)
                    {
                        Distance dOdometer = new Distance(this.Odometer);	// meters
                        odometerLbl = dOdometer.ToString();
                    }
                }
            }

            Distance dElev = new Distance(this.Location.Elev);
            string elevLbl = dElev.ToStringCompl();

            tmp += "       elevation: " + elevLbl;

            if(speedLbl != null)
            {
                tmp += "  speed: " + speedLbl;
            }
            if(odometerLbl != null)
            {
                tmp += "  odometer: " + odometerLbl;
            }

            return tmp;
        }
Exemplo n.º 7
0
        /*
        private const string m_aaa = @"<b>Trackpoint</b>&nbsp;=&nbsp;248&nbsp;of&nbsp;1415<br/>
        <b>Latitude</b>&nbsp;=&nbsp;31.6947°<br/>
        <b>Longitude</b>&nbsp;=&nbsp;-110.86196°<br/>
        <b>UTM</b>&nbsp;=&nbsp;12R 513082E 3506603N<br/>
        <b>Heading</b>&nbsp;=&nbsp;132.7°<br/>
        <b>Slope</b>&nbsp;=&nbsp;7.25% (up)<br/>
        <b>Distance&nbsp;Completed</b>&nbsp;=&nbsp;21%<br/>
        <b>Distance&nbsp;Traveled</b>&nbsp;=&nbsp;2.5&nbsp;miles<br/>
        <b>Distance&nbsp;Remaining</b>&nbsp;=&nbsp;9.3&nbsp;miles<br/>
        <b>Net&nbsp;Distance</b>&nbsp;=&nbsp;1.5&nbsp;miles<br/>
        <b>Net&nbsp;Distance&nbsp;Remaining</b>&nbsp;=&nbsp;1.5&nbsp;miles</td>

        <td><b>Altitude</b>&nbsp;=&nbsp;6919&nbsp;ft<br/>
        <b>Altitude&nbsp;Completed</b>&nbsp;=&nbsp;36%<br/>
        <b>Net&nbsp;Altitude</b>&nbsp;=&nbsp;1503&nbsp;ft<br/>
        <b>Net&nbsp;Altitude&nbsp;Remaining</b>&nbsp;=&nbsp;2630&nbsp;ft<br/>
        <b>Time&nbsp;Completed</b>&nbsp;=&nbsp;4%<br/>
        <b>Time&nbsp;Elapsed</b>&nbsp;=&nbsp;01:58:59<br/>
        <b>Time&nbsp;Remaining</b>&nbsp;=&nbsp;44:20:21<br/>
        <b>Ground&nbsp;Speed</b>&nbsp;=&nbsp;0.8989&nbsp;mph<br/>
        <b>Moving&nbsp;Average</b>&nbsp;=&nbsp;1.345&nbsp;mph<br/>
        <b>Vertical&nbsp;Speed</b>&nbsp;=&nbsp;0.096&nbsp;ft/sec&nbsp;(up)<br/>
        <b>Acceleration</b>&nbsp;=&nbsp;-0.009&nbsp;ft/sec/sec";
        */
        /// <summary>
        /// returns a formatted string suitable for popups
        /// </summary>
        /// <returns></returns>
        public string toStringKmlDescr()
        {
            StringBuilder builder = new StringBuilder();

            if(this.ThumbImage != null)
            {
                if(this.UrlName != null && this.UrlName.Length > 0)
                {
                    builder.Append("<b>Url Name:</b> " + this.UrlName.Trim() + "<br/>");
                }
                if(this.DateTime.Ticks > minDateTimeTicks)
                // waypoint times are added to to avoid duplicates, we need to compare with tolerance
                {
                    builder.Append("<b>Taken:</b> " + Project.zuluToLocal(this.DateTime) + "<br/>");
                }
                if(this.Comment != null && this.Comment.Length > 0)
                {
                    builder.Append("<b>Comment:</b> " + this.Comment.Trim() + "<br/>");
                }

                addKmlCoords(builder, false);

                builder.Append("<img src='images/" + m_name + ".jpg' width='" + imageWidth + "' height='" + imageHeight + "'><br/>");
            }
            else
            {
                builder.Append(m_startTable);
                builder.Append(m_startTr1);
            //				builder.Append(m_aaa);
            //				builder.Append(m_endTable);

                Waypoint nextWpt = null;
                string speedLbl = null;
                string odometerLbl = null;
                string timeTraveledLbl = null;
                string timeRemainingLbl = null;

                if(this.Desc != null && this.Desc.Length > 0)
                {
                    builder.Append(this.Desc.Replace("\n","<br/>\n").Trim() + "<br/>\n");
                }
                if(this.Url != null && this.Url.Length > 0)
                {
                    builder.Append(String.Format("<a href=\"{0}\">{0}</a><br/>\n", this.Url));
                }
                if(this.TrackId != -1)
                {
                    Track trk = (Track)Project.mainCommand.getTrackById(this.TrackId);
                    if(trk != null)
                    {
                        int i = trk.Trackpoints.IndexOfValue(this);
                        nextWpt = (i < trk.Trackpoints.Count-1) ? (Waypoint)trk.Trackpoints.GetByIndex(i+1) : null;
                        string pointOfLabel = "<b>Point:</b> " + (i+1) + " of " + trk.Trackpoints.Count + "<br/>\n";

                        if(trk.isRoute)
                        {
                            builder.Append("<b>Route:</b> " + trk.Name + "<br/>\n");
                            builder.Append(pointOfLabel);
                        }
                        else
                        {
                            builder.Append("<b>Track:</b> " + trk.Name + "<br/>\n");
                            builder.Append(pointOfLabel);
                            if(this.DateTime.Ticks > minDateTimeTicks)
                                // waypoint times are added to to avoid duplicates, we need to compare with tolerance
                            {
                                builder.Append("<b>Time:</b> " + Project.zuluToLocal(this.DateTime) + "<br/>\n");
                            }
                            if(HasSpeed)
                            {
                                Speed dSpeed = new Speed(this.Speed);				// meters per hour
                                speedLbl = dSpeed.ToString();
                            }
                            TimeSpan ts = this.DateTime - trk.Start;
                            timeTraveledLbl = Project.TimeSpanToString(ts);

                            ts = trk.End - this.DateTime;
                            timeRemainingLbl = Project.TimeSpanToString(ts);
                        }
                        if(HasOdometer)
                        {
                            Distance dOdometer = new Distance(this.Odometer);		// meters
                            odometerLbl = dOdometer.ToString() + " of " + (new Distance(trk.Odometer)).ToString() + "<br/>";
                        }
                    }
                }

                addKmlCoords(builder, true);

                if(nextWpt != null && !this.Location.sameAs(nextWpt.Location))
                {
                    addCourseData(builder, nextWpt, true);
                }

                if(this.TrackId != -1)
                {
                    builder.Append(m_endTr);
                    builder.Append(m_startTr2);

                    if(speedLbl != null)
                    {
                        builder.Append("<b>Speed:</b> " + speedLbl + "<br/>");
                    }
                    if(odometerLbl != null)
                    {
                        builder.Append("<b>Distance:</b> " + odometerLbl + "<br/>");
                    }

                    builder.Append(m_nextTd);

                    if(timeTraveledLbl != null)
                    {
                        builder.Append("<b>Time traveled:</b> " + timeTraveledLbl + "<br/>");
                    }
                    if(timeRemainingLbl != null)
                    {
                        builder.Append("<b>Time remaining:</b> " + timeRemainingLbl + "<br/>");
                    }

                    builder.Append(m_endTr);
                    builder.Append(m_startTr1);
                }

                if(this.TrackId == -1)
                {
                    string strLoType = this.LiveObjectTypeToString();
                    builder.Append("<b>Type:</b> " + strLoType + (this.Found ? " - FOUND" : "") + " ");
                }
                if(m_wptType.Length > 0)
                {
                    builder.Append(" " + m_wptType + (this.Found ? " - FOUND" : "") + " ");
                }

                if(this.TrackId == -1 && this.LiveObjectType == LiveObjectTypes.LiveObjectTypeGeocache && this.DateTime.Ticks > minDateTimeTicks)
                {
                    builder.Append("<b>Hidden:</b> " + Project.zuluToLocal(this.DateTime).ToShortDateString() + "<br/>");
                }
                if(this.UrlName != null && this.UrlName.Length > 0)
                {
                    builder.Append("<b>Url Name:</b> " + this.UrlName.Trim() + "<br/>");
                }
                if(this.Sym != null && this.Sym.Length > 0)
                {
                    builder.Append("<b>Symbol:</b> " + this.Sym.Trim() + "<br/>");
                }
                if(this.Comment != null && this.Comment.Length > 0)
                {
                    builder.Append("<b>Comment:</b> " + this.Comment.Trim() + "<br/>");
                }
                if(groundspeakCache != null)
                {
                    builder.Append("<br/>" + groundspeakCache.ToStringPopup().Replace("\n","<br>\n"));
                }

                builder.Append(m_endTr);
                builder.Append(m_endTable);
            }

            builder.Replace("<br><br>","<br>");
            builder.Replace("<br>\n<br>","<br>");

            return builder.ToString();
        }
Exemplo n.º 8
0
        /// <summary>
        /// returns a formatted string suitable for popups
        /// </summary>
        /// <returns></returns>
        public string toStringPopup()
        {
            StringBuilder builder = new StringBuilder();
            Waypoint nextWpt = null;
            string speedLbl = null;
            string odometerLbl = null;
            //Waypoint prevWpt = null;
            string timeTraveledLbl = null;
            string timeRemainingLbl = null;

            bool doTime = this.DateTime.Ticks > minDateTimeTicks;

            if(this.Desc != null && this.Desc.Length > 0)
            {
                builder.Append(this.Desc.Trim() + "\n\n");
            }
            if(this.Url != null && this.Url.Length > 0)
            {
                builder.Append(Project.serverAvailable ? "[click waypoint or label to browse]\n\n" : "[can't browse offline]\n\n");
            }
            if(this.TrackId != -1)
            {
                Track trk = (Track)Project.mainCommand.getTrackById(this.TrackId);
                if(trk != null)
                {
                    int i = trk.Trackpoints.IndexOfValue(this);
                    nextWpt = (i < trk.Trackpoints.Count-1) ? (Waypoint)trk.Trackpoints.GetByIndex(i+1) : null;
                    string name = " : " + this.Name;
                    if(name.Length > 7)
                    {
                        name = "";
                    }

                    if(builder.Length == 0)
                    {
                        builder.Append("Waypoint on ");
                    }

                    builder.Append((trk.isRoute ? "Route " : "Track ") + this.TrackId + ": " + trk.Name + name + "\n");

                    if(HasSpeed)
                    {
                        Speed dSpeed = new Speed(this.Speed);				// meters per hour
                        speedLbl = dSpeed.ToString();
                    }
                    TimeSpan ts = this.DateTime - trk.Start;
                    timeTraveledLbl = Project.TimeSpanToString(ts);

                    ts = trk.End - this.DateTime;
                    timeRemainingLbl = Project.TimeSpanToString(ts);

                    if(HasOdometer)
                    {
                        Distance dOdometer = new Distance(this.Odometer);	// meters
                        odometerLbl = dOdometer.ToString();
                    }
                }
            }
            builder.Append(this.Location.toString00(false, Project.coordStyle));
            Distance dElev = new Distance(this.Location.Elev);
            if(dElev.Meters != 0.0d)
            {
                builder.Append("  elev: " + dElev.ToStringCompl() + "\n");
            }

            if(this.TrackId == -1)
            {
                string strLoType = this.LiveObjectTypeToString();
                builder.Append("Type: (" + strLoType + (this.Found ? " - FOUND" : "") + ")");
            }
            if(m_wptType.Length > 0)
            {
                builder.Append(" (" + m_wptType + (this.Found ? " - FOUND" : "") + ")");
            }
            if(doTime && this.DateTime.Ticks > minDateTimeTicks)
                // waypoint times are added to to avoid duplicates, we need to compare with tolerance
            {
                builder.Append("\n  " + Project.zuluToLocal(this.DateTime));
            }
            if(speedLbl != null)
            {
                builder.Append("\n  speed: " + speedLbl);
            }
            if(odometerLbl != null)
            {
                builder.Append((speedLbl == null ? "\n" : "  ") +  "odometer: " + odometerLbl);
            }
            if(timeTraveledLbl != null)
            {
                builder.Append("\n time traveled: " + timeTraveledLbl);
            }
            if(timeRemainingLbl != null)
            {
                builder.Append("  time remaining: " + timeRemainingLbl);
            }
            if(nextWpt != null && !this.Location.sameAs(nextWpt.Location))
            {
                addCourseData(builder, nextWpt, false);
            }
            if(this.WptName != null && this.WptName.Length > 0)
            {
                builder.Append("\nName: " + this.WptName.Trim());
            }
            if(this.TrackId == -1 && this.LiveObjectType == LiveObjectTypes.LiveObjectTypeGeocache && this.DateTime.Ticks > minDateTimeTicks)
            {
                builder.Append("      Hidden: " + Project.zuluToLocal(this.DateTime).ToShortDateString());
            }
            if(this.UrlName != null && this.UrlName.Length > 0)
            {
                builder.Append("\nUrl Name: " + this.UrlName.Trim());
            }
            if(this.Sym != null && this.Sym.Length > 0)
            {
                builder.Append("\nSymbol: " + this.Sym.Trim());
            }
            if(this.Comment != null && this.Comment.Length > 0)
            {
                builder.Append("\nComment: " + this.Comment.Trim());
            }
            if(groundspeakCache != null)
            {
                builder.Append("\n\n" + groundspeakCache.ToStringPopup());
            }
            if(this.ThumbImage != null && this.ThumbSource != null && this.ThumbSource.Length > 0)
            {
                string sTimeShift  = toDelayString(PhotoTimeShift);
                builder.Append((imageWidth > 0 && imageHeight > 0 ? ("\n" + imageWidth + "x" + imageHeight + "       ") : "\n"));
                builder.Append("camera time shift: " + sTimeShift + "\n");
                builder.Append(this.ThumbSource);
            }
            if(LegTo != null)
            {
                builder.Append("\nIncoming " + this.LegTo);
            }
            if(LegFrom != null)
            {
                builder.Append("\nOutgoing " + this.LegFrom);
            }

            return builder.ToString();
        }
Exemplo n.º 9
0
        private void makeTracksDS()
        {
            DataTable tracksTable;

            rebuildingTracks = true;

            // we cannot reuse the table, as boolean "Show" checkboxes will otherwise have their events messed up badly.
            if(m_tracksDS != null)
            {
                m_tracksDS.Dispose();
            }

            tracksTable = new DataTable("tracks");

            DataColumn myDataColumn;

            // Create new DataColumn, set DataType, ColumnName and add to DataTable.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.Int32");
            myDataColumn.ColumnName = "id";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = true;
            tracksTable.Columns.Add(myDataColumn);

            // Create name column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.String");
            myDataColumn.ColumnName = "name";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Name";
            myDataColumn.ReadOnly = false;
            myDataColumn.Unique = false;
            tracksTable.Columns.Add(myDataColumn);

            // Create distance traveled column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = (new Distance(0.0d)).GetType();
            myDataColumn.ColumnName = "distance";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Distance";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            tracksTable.Columns.Add(myDataColumn);

            // Create source column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.String");
            myDataColumn.ColumnName = "source";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Source";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            tracksTable.Columns.Add(myDataColumn);

            // Create "legs" column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.Int32");
            myDataColumn.ColumnName = "legs";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Legs";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            tracksTable.Columns.Add(myDataColumn);

            // Create start column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = sortableDateTime.GetType();
            myDataColumn.ColumnName = "start";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Start";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            tracksTable.Columns.Add(myDataColumn);

            // Create end column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = sortableDateTime.GetType();
            myDataColumn.ColumnName = "end";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "End";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            tracksTable.Columns.Add(myDataColumn);

            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.Boolean");
            myDataColumn.ColumnName = "displayed";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Display";
            myDataColumn.ReadOnly = false;
            myDataColumn.Unique = false;
            tracksTable.Columns.Add(myDataColumn);

            // Make the ID column the primary key column.
            DataColumn[] PrimaryKeyColumns = new DataColumn[1];
            PrimaryKeyColumns[0] = tracksTable.Columns["id"];
            tracksTable.PrimaryKey = PrimaryKeyColumns;

            // Add the new DataTable to the DataSet.
            m_tracksDS = new DataSet();
            m_tracksDS.Tables.Add(tracksTable);

            tracksTable = m_tracksDS.Tables[0];
            tracksTable.ColumnChanging -= new DataColumnChangeEventHandler(this.tracks_ColumnChanging);
            tracksTable.RowDeleting -= new DataRowChangeEventHandler(this.tracks_RowDeleting);

            // Create DataRow objects and add them to the DataTable
            DataRow myDataRow;
            for (int i = 0; i < WaypointsCache.TracksAll.Count; i++)
            {
                Track track = (Track)WaypointsCache.TracksAll[i];
                if(!track.isRoute)
                {
                    myDataRow = tracksTable.NewRow();
                    myDataRow["id"] = track.Id;

                    Speed dMaxSpeed = new Speed(track.SpeedMax);		// meters per hour
                    Speed dMinSpeed = new Speed(track.SpeedMin);		// meters per hour
                    Distance dOdometer = new Distance(track.Odometer);	// meters

                    myDataRow["name"] = track.Name;
                    string sSpeed = dMinSpeed.ToString() + " to " + dMaxSpeed.ToString();
                    if(!dMinSpeed.isSane && !dMaxSpeed.isSane)
                    {
                        sSpeed = "n/a";
                    }
                    myDataRow["source"] = "speed:" + sSpeed + "   source: " + track.Source;
                    myDataRow["legs"] = track.Trackpoints.Count;
                    myDataRow["start"] = new SortableDateTime(track.Start, DateTimeDisplayMode.ConvertToLocal);
                    myDataRow["end"] = new SortableDateTime(track.End, DateTimeDisplayMode.ConvertToLocal);
                    myDataRow["distance"] = dOdometer;
                    myDataRow["displayed"] = track.Enabled;
                    tracksTable.Rows.Add(myDataRow);
                }
            }

            tracksTable.ColumnChanging += new DataColumnChangeEventHandler(this.tracks_ColumnChanging);
            tracksTable.RowDeleting += new DataRowChangeEventHandler(this.tracks_RowDeleting);

            rebuildingTracks = false;
        }
Exemplo n.º 10
0
        private void makeTrackpointsDS(ArrayList selectedTracksRows)
        {
            DataTable trackpointsTable;

            rebuildingTrackpoints = true;

            string sortOrder = "";

            if(m_trackpointsDS != null)
            {
                sortOrder = m_trackpointsDS.Tables["trackpoints"].DefaultView.Sort;	// we will restore it later
                m_trackpointsDS.Tables.Clear();
                m_trackpointsDS.Dispose();
            }

            trackpointsTable = new DataTable("trackpoints");

            DataColumn myDataColumn;

            // Create new DataColumn, set DataType, ColumnName and add to DataTable.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.Int32");
            myDataColumn.ColumnName = "id";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = true;
            trackpointsTable.Columns.Add(myDataColumn);

            // needed to relate waypoint to track
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.Int32");
            myDataColumn.ColumnName = "trackid";
            myDataColumn.ReadOnly = true;
            trackpointsTable.Columns.Add(myDataColumn);

            // needed to index waypoint inside a track
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.Int32");
            myDataColumn.ColumnName = "wptidx";
            myDataColumn.ReadOnly = true;
            trackpointsTable.Columns.Add(myDataColumn);

            // Create name column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.String");
            myDataColumn.ColumnName = "name";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Name";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            trackpointsTable.Columns.Add(myDataColumn);

            // Create date/time column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = sortableDateTime.GetType();
            myDataColumn.ColumnName = "time";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Time";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            trackpointsTable.Columns.Add(myDataColumn);

            // Create location column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.String");
            myDataColumn.ColumnName = "location";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Location";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            trackpointsTable.Columns.Add(myDataColumn);

            // Create elevation column (for graph).
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.Double");
            myDataColumn.ColumnName = "elevation";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Elevation";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            trackpointsTable.Columns.Add(myDataColumn);

            // Create speed column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = (new Speed(0.0d)).GetType();
            myDataColumn.ColumnName = "speed";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Speed";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            trackpointsTable.Columns.Add(myDataColumn);

            // Create heading column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.String");
            myDataColumn.ColumnName = "heading";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Heading";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            trackpointsTable.Columns.Add(myDataColumn);

            // Create leg distance column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = (new Distance(0.0d)).GetType();
            myDataColumn.ColumnName = "leg";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Leg";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            trackpointsTable.Columns.Add(myDataColumn);

            // Create distance traveled (odometer) column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = (new Distance(0.0d)).GetType();
            myDataColumn.ColumnName = "distance";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Distance";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            trackpointsTable.Columns.Add(myDataColumn);

            // Create track column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.String");
            myDataColumn.ColumnName = "track";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Track";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            trackpointsTable.Columns.Add(myDataColumn);

            // Create source column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.String");
            myDataColumn.ColumnName = "source";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Source";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            trackpointsTable.Columns.Add(myDataColumn);

            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.Boolean");
            myDataColumn.ColumnName = "displayed";
            myDataColumn.AutoIncrement = false;
            myDataColumn.Caption = "Display";
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            trackpointsTable.Columns.Add(myDataColumn);

            // Create real location column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = GeoCoord.This.GetType();
            myDataColumn.ColumnName = "locationReal";
            myDataColumn.AutoIncrement = false;
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            trackpointsTable.Columns.Add(myDataColumn);

            // Create real heading column.
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.Double");
            myDataColumn.ColumnName = "headingReal";
            myDataColumn.AutoIncrement = false;
            myDataColumn.ReadOnly = true;
            myDataColumn.Unique = false;
            trackpointsTable.Columns.Add(myDataColumn);

            // Make the ID column the primary key column.
            DataColumn[] PrimaryKeyColumns = new DataColumn[1];
            PrimaryKeyColumns[0] = trackpointsTable.Columns["id"];
            trackpointsTable.PrimaryKey = PrimaryKeyColumns;

            // Add the new DataTable to the DataSet.
            m_trackpointsDS = new DataSet();
            m_trackpointsDS.Tables.Add(trackpointsTable);

            // Create DataRow objects and add them to the DataTable
            DataRow myDataRow;
            int column = 0;
            int count = 0;
            m_elevMax = 0.0d;	// meters
            m_elevMin = 0.0d;
            bool fromRoutes = this.prevSelectedTab == this.routesTabPage;
            this.messageTrkptLabel.Text = fromRoutes ? "Routes:" : "Tracks:";
            foreach (int row in selectedTracksRows)
            {
                long trackId = (long)((int)(fromRoutes ? routesDataGrid[row, column] : tracksDataGrid[row, column]));
                Track trk = WaypointsCache.getTrackById(trackId);
                Waypoint prevWpt = null;
                if(trk != null)
                {
                    this.messageTrkptLabel.Text += (" " + trk.Name + " ");

                    double odometer = 0.0d;	// meters

                    for (int i = 0; i < trk.Trackpoints.Count; i++)
                    {
                        Waypoint wpt = (Waypoint)trk.Trackpoints.GetByIndex(i);
                        Waypoint nextWpt = (i < trk.Trackpoints.Count-1) ? (Waypoint)trk.Trackpoints.GetByIndex(i+1) : null;

                        // wpt.Location.Lng, wpt.Location.Lat, wpt.Location.Elev
                        if(wpt != null)
                        {
                            count++;
                            myDataRow = trackpointsTable.NewRow();
                            myDataRow["id"] = wpt.Id;
                            myDataRow["trackid"] = trackId;
                            myDataRow["wptidx"] = i;		// in track
                            string contentOrUrl = (wpt.Desc != null && wpt.Desc.Length > 0) ? "*" : "";
                            contentOrUrl += (wpt.Url != null && wpt.Url.Length > 0) ? "@" : "";
                            string name = contentOrUrl;

                            name += ((wpt.Name == null || wpt.Name.Length == 0) ? ("" + (i+1)) : wpt.Name);
                            if(wpt.WptName.Length > 0 && !name.ToLower().StartsWith(wpt.WptName.ToLower()))		// avoid duplicates like "2: 2"
                            {
                                name += ": " + wpt.WptName;
                            }
                            myDataRow["name"] = name.Trim();
                            myDataRow["time"] = new SortableDateTime(wpt.DateTime, DateTimeDisplayMode.ConvertToLocal);
                            myDataRow["location"] = wpt.Location.ToStringWithElev();
                            myDataRow["locationReal"] = new GeoCoord(wpt.Location);

                            double elev = wpt.Location.Elev;
                            myDataRow["elevation"] = elev;

                            m_elevMax = Math.Max(m_elevMax, elev);
                            m_elevMin = Math.Min(m_elevMin, elev);

                            Speed speed = null;
                            Distance leg = null;
                            if(prevWpt != null)
                            {
                                // compute odometer and speed:
                                TimeSpan dt = wpt.DateTime - prevWpt.DateTime;
                                leg = wpt.Location.distanceFrom(prevWpt.Location);	// meters
                                double legMeters = leg.Meters;
                                odometer += legMeters;
                                double legMetersPerHour = legMeters * 36000000000.0d / dt.Ticks;		// meters per hour
                                if(!fromRoutes && legMetersPerHour > 1000.0d && legMetersPerHour < 330.0d * 3600.0d)	// sanity check - speed of sound, m/hr
                                {
                                    wpt.Speed = (float)legMetersPerHour;
                                    if(wpt.Speed > trk.SpeedMax)
                                    {
                                        trk.SpeedMax = wpt.Speed;
                                    }
                                    if(wpt.Speed < trk.SpeedMin)
                                    {
                                        trk.SpeedMin = wpt.Speed;
                                    }
                                    speed = new Speed(legMetersPerHour);
                                }
                            }
                            wpt.Odometer = (float)odometer;

                            myDataRow["speed"] = speed == null ? new Speed(-1.0d) : speed;

                            double variation = Math.Round(wpt.Location.magneticVariation());
                            double headingTrue = (nextWpt == null || wpt.Location.sameAs(nextWpt.Location)) ? 999.0d : (wpt.Location.bearing(nextWpt.Location) * 180.0d / Math.PI);
                            double headingMagn = (headingTrue == 999.0d) ? 999.0d : ((headingTrue + variation + 360.0d) % 360.0d);

                            myDataRow["headingReal"] = headingMagn;
                            myDataRow["heading"] = (headingTrue == 999.0d) ? "" : String.Format("{0:000}°", Math.Round(headingMagn));
                            myDataRow["leg"] = leg == null ? new Distance(0.0d) : leg;
                            myDataRow["distance"] = new Distance(odometer);
                            myDataRow["track"] = trk.Name;
                            myDataRow["source"] = wpt.Source;
                            myDataRow["displayed"] = true;
                            trackpointsTable.Rows.Add(myDataRow);
                            prevWpt = wpt;
                        }
                    }
                }
            }
            this.messageTrkptLabel.Text += ("   - total " + count + " points");

            trackpointsTable.RowDeleting += new DataRowChangeEventHandler(this.trackpoints_RowDeleting);

            trackpointsTable.DefaultView.Sort = sortOrder;

            if(trackpointsTable.DefaultView.Sort.Length == 0)
            {
                trackpointsTable.DefaultView.Sort = "time";
            }

            rebuildingTrackpoints = false;
        }
Exemplo n.º 11
0
        private void rebuildGraph()
        {
            if(m_track == null)
            {
                m_allItems = null;
                m_graphItems = null;
                this.Invalidate();

                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            m_elevMax = -100000.0d;	// feet
            m_elevMin =  100000.0d;
            m_speedMax = -1000.0d;

            SortedList graphItems = new SortedList();
            Waypoint prevWpt = null;
            double odometer = 0.0d;		// meters

            for(int i=0; i < m_track.Trackpoints.Count ;i++)
            {
                Waypoint wpt = (Waypoint)m_track.Trackpoints.GetByIndex(i);

                Speed speed = null;
                Distance leg = null;
                double dSpeedCurrentUnits = 0.0d;

                if(prevWpt != null)
                {
                    // compute odometer and speed:
                    TimeSpan dt = wpt.DateTime - prevWpt.DateTime;
                    leg = wpt.Location.distanceFrom(prevWpt.Location);	// meters
                    double legMeters = leg.Meters;
                    odometer += legMeters;
                    double legMetersPerHour = legMeters * 36000000000.0d / dt.Ticks;		// meters per hour
                    if(!m_track.isRoute && legMetersPerHour > 1000.0d && legMetersPerHour < 330.0d * 3600.0d)	// sanity check - speed of sound, m/hr
                    {
                        speed = new Speed(legMetersPerHour);
                        dSpeedCurrentUnits = speed.ToDouble();
                    }
                }
                odometer = (float)odometer;

                long id = (long)i;
                double elevCurrentUnits = new Distance(wpt.Location.Elev).ToDoubleCompl();
                string properties = wpt.toTableString();

                m_elevMax = Math.Max(elevCurrentUnits, m_elevMax);
                m_elevMin = Math.Min(elevCurrentUnits, m_elevMin);
                m_speedMax = Math.Max(dSpeedCurrentUnits, m_speedMax);

                long[] ids = new long[2];
                ids[0] = id;
                ids[1] = id;
                double[] values = new double[2];
                values[0] = elevCurrentUnits;
                values[1] = dSpeedCurrentUnits;
                string[] sValues = new string[2];
                sValues[0] = properties;
                sValues[1] = "";

                GraphItem ev = new GraphItem(odometer, wpt, values, sValues, ids, 2);

                while(true)
                {
                    try
                    {
                        graphItems.Add(odometer, ev);
                        break;
                    }
                    catch
                    {
                        odometer += 0.01d;
                    }
                }
                prevWpt = wpt;
            }

            if(m_elevMax > 0.0d && m_speedMax > 0.0d)
            {
                // make speed graph match the elevation:
                double speedFactor = 0.6d * m_elevMax / m_speedMax;
                foreach(GraphItem ev in graphItems.Values)
                {
                    double[] values = ev.values(Project.FORMAT_TRACK_ELEVATION);
                    values[1] = Math.Round(values[1] * speedFactor);
                }
            }

            string selHint = "Click into grey area to see selected interval";
            StringById dZoomById = new StringById(zoomById);
            StringById dDescrById = new StringById(descrById);

            double rounder = 200.0d;
            if(this.m_elevMax > 10000.0d)
            {
                rounder = 2000.0d;
            }
            else if(this.m_elevMax > 1000.0d)
            {
                rounder = 1000.0d;
            }
            else if(this.m_elevMax <= 50.0d)
            {
                this.m_elevMax = 50.0d;
                rounder = 100.0d;
            }
            double graphGridMaxValue = Math.Ceiling(this.m_elevMax / rounder) * rounder;
            int steps = (int) (graphGridMaxValue / rounder);
            this.MaxValueY = graphGridMaxValue;
            this.MinKeyDblMargin = 100.0d;
            this.StepY = graphGridMaxValue / steps;

            this.MarginLeft = 45;
            this.MarginRight = 30;

            this.initialHint = "Click on graph to see details. Use arrow keys. Drag mouse to select a "
                                    + (m_track.isRoute ? "route" : "track") + " segment, click into it to zoom.";

            this.init(this.enableDisable, "", "", selHint, dDescrById, dZoomById, dBrowseById, new MethodInvoker(showSelected));
            this.setGraphData(graphItems, Project.FORMAT_TRACK_ELEVATION, 2, false);
            this.SelectItemByObject(m_trkpt);

            this.resetLegends();
            this.setLegend(0, "elevation");
            this.setLegend(1, "speed");

            this.Invalidate();

            Cursor.Current = Cursors.Default;
        }
Exemplo n.º 12
0
        private void goButton_Click(object sender, System.EventArgs e)
        {
            bool allcool = true;

            try
            {
                Distance elevDist = new Distance(0.0d);
                int unitsCompl = elevDist.UnitsCompl;

                double nuElev = Convert.ToDouble(elevationTextBox.Text.Replace(",",""));
                elevDist.byUnits(nuElev, unitsCompl);

                altitude = elevDist.Meters;

                elevationUnitsLabel.Text = elevDist.toStringU(unitsCompl);

                elevLabel.ForeColor = Color.Black;
            }
            catch
            {
                elevLabel.ForeColor = Color.Red;
                allcool = false;
            }

            try
            {
                Speed speedDist = new Speed(0.0d);
                int units = speedDist.Units;

                double nuSpeed = Convert.ToDouble(speedTextBox.Text.Replace(",",""));
                speedDist.byUnits(nuSpeed, units);

                speed = speedDist.Meters;

                speedUnitsLabel.Text = speedDist.toStringU(units);

                elevLabel.ForeColor = Color.Black;
            }
            catch
            {
                elevLabel.ForeColor = Color.Red;
                allcool = false;
            }

            try
            {
                startTime = timePicker.isDateTimeValid ? timePicker.dateTime : DateTime.MinValue; //new DateTime(7000, 1, 1);
            }
            catch
            {
                allcool = false;
            }

            if(allcool)
            {
                result = true;
                this.Close();
            }
        }
Exemplo n.º 13
0
        protected void setFields()
        {
            Distance elevDist = new Distance(altitude);
            int elevUnitsCompl = elevDist.UnitsCompl;
            elevationTextBox.Text = elevDist.toStringN(elevUnitsCompl);
            elevationUnitsLabel.Text = elevDist.toStringU(elevUnitsCompl);

            Speed speedDist = new Speed(speed);
            int speedUnits = speedDist.Units;
            speedTextBox.Text = speedDist.toStringN(speedUnits);
            speedUnitsLabel.Text = speedDist.toStringU(speedUnits);
        }