/// <summary>
 /// write the comma seperated value list of turns out to a file
 /// </summary>
 public override void writeCueSheet(string fileName, string gpxFileName
                                    , List <Address> locs, List <Turn> turns, string units)
 {
     try {
         StreamWriter sr = new StreamWriter(fileName);
         //case for meters, kilometers, and miles
         sr.WriteLine("Start at " + locs[0].AddressString.Replace(",", ""));
         sr.WriteLine("Interval " + units + ",Total " + units + ",Turn"
                      + ",Degrees,Street,Notes,Latitude,Longitude,Elevation (m)"
                      + ",UTM Zone,Easting,Northing");
         for (int i = 0; i < turns.Count; i++)
         {
             sr.WriteLine(DirectionsPrinter.getDistanceGivenUnits(turns[i].Distance, units)
                          + "," + DirectionsPrinter.getDistanceGivenUnits(turns[i].Locs[1].GpxLocation.Distance, units)
                          + "," + turns[i].TurnDirection
                          + "," + Math.Round(turns[i].TurnMagnitude)
                          + "," + turns[i].Locs[2].StreetName + "," + turns[i].Notes
                          + "," + turns[i].Locs[1].GpxLocation.Lat
                          + "," + turns[i].Locs[1].GpxLocation.Lon
                          + "," + turns[i].Locs[1].GpxLocation.Elevation
                          + "," + turns[i].Locs[1].GpxLocation.Zone
                          + "," + turns[i].Locs[1].GpxLocation.Easting
                          + "," + turns[i].Locs[1].GpxLocation.Northing);
         }
         sr.WriteLine("End at " + locs[locs.Count - 1].AddressString.Replace(",", "")
                      + "\r\ntotal distance: " + DirectionsPrinter.getDistanceGivenUnits(locs[locs.Count - 1]
                                                                                         .GpxLocation.Distance, units) + " " + units);
         sr.Close();
     } catch (Exception e) {
         _status = e.Message;
     }
 }
        public static Bitmap getElevationProfile(List <Location> locs, string units)
        {
            if (locs == null || locs.Count < 1)
            {
                return(new Bitmap(100, 100));
            }
            _maxHeight = 0;
            _minHeight = double.PositiveInfinity;
            foreach (Location loc in locs)
            {
                if (loc.Elevation > _maxHeight)
                {
                    _maxHeight = loc.Elevation;
                }
                if (loc.Elevation < _minHeight)
                {
                    _minHeight = loc.Elevation;
                }
            }
            int delta = (int)(_maxHeight - _minHeight);

            Bitmap     profile = new Bitmap(locs.Count, delta + 40);
            Graphics   g       = Graphics.FromImage(profile);
            SolidBrush b       = new SolidBrush(Color.SkyBlue);
            Pen        p       = new Pen(Color.White);

            g.FillRectangle(b, 0, 0, profile.Width, profile.Height);
            int height = profile.Height;
            int width  = profile.Width;

            for (int i = 0; i < width; i++)
            {
                g.DrawLine(p, i, height, i, height - (int)(locs[i].Elevation - _minHeight));
            }
            SolidBrush sb = new SolidBrush(Color.Black);
            Font       f  = new Font(FontFamily.GenericSerif, 8);
            Pen        p2 = new Pen(sb);
            Point      pt = new Point(0, height - 15);

            for (int i = 40; i < width; i += 40)
            {
                pt.X = i;
                g.DrawLine(p2, i, height, i, 0);
                g.DrawString(DirectionsPrinter.getDistanceGivenUnits(locs[i].Distance, units).ToString(), f, sb, pt);
            }
            pt.X = 0;
            for (int i = 40; i < delta; i += 40)
            {
                pt.Y = (height - i) - 15;
                g.DrawLine(p2, 0, (height - i), width, (height - i));
                g.DrawString((_minHeight + i).ToString(), f, sb, pt);
            }
            return(profile);
        }
 /// <summary>
 /// write the comma seperated value list of turns out to a file
 /// </summary>
 public override void writeCueSheet(string fileName, string gpxFileName
                                    , List <Address> locs, List <Turn> turns, string units)
 {
     try {
         string shortFileName    = null;
         string shortGpxFimeName = null;
         if (fileName.Contains("\\"))
         {
             shortFileName    = fileName.Remove(0, fileName.LastIndexOf("\\") + 1);
             shortGpxFimeName = gpxFileName.Remove(0, gpxFileName.LastIndexOf("\\") + 1);
         }
         else if (fileName.Contains("/"))
         {
             shortFileName    = fileName.Remove(0, fileName.LastIndexOf("/") + 1);
             shortGpxFimeName = gpxFileName.Remove(0, gpxFileName.LastIndexOf("/"));
         }
         StreamWriter sr = new StreamWriter(fileName);
         sr.WriteLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
         sr.WriteLine("<html><head><meta content=\"text/html; charset=ISO-8859-1\" http-equiv=\"content-type\">");
         sr.WriteLine("<title>Cue Sheet for: " + shortGpxFimeName + "</title></head><body>");
         sr.WriteLine("<table style=\"text-align: left; width: 100%;\" cellpadding=\"2\" cellspacing=\"2\">");
         sr.WriteLine("<tbody><tr><td style=\"vertical-align: top;\">");
         sr.WriteLine("<tbody><tr><td style=\"vertical-align: top;\">");
         sr.WriteLine("<table style=\"text-align: left; width: 100%;\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">");
         sr.WriteLine("<tbody><tr><td><b>Directions for: " + shortGpxFimeName + "</b><br>");
         sr.WriteLine("</td></tr><tr><td>Start at " + locs[0].AddressString + "</td></tr><tr><td>");
         sr.WriteLine("<table style=\"text-align: left; width: 100%;\" border=\"1\" cellpadding=\"4\" cellspacing=\"0\"><tbody>");
         sr.WriteLine("<tr><td><b>Turn #</b></td><td><b>Distance</b></td><td><b>Turn</b></td><td><b>Street Name</b></td></tr>");
         for (int i = 0; i < turns.Count; i++)
         {
             sr.WriteLine("<tr><td>" + (i + 1) + "</td><td>"
                          + DirectionsPrinter.getDistanceGivenUnits(turns[i].Locs[1].GpxLocation.Distance, units) + "</td><td>"
                          + turns[i].TurnDirection + "</td><td>"
                          + turns[i].Locs[2].StreetName + "</td></tr>");
         }
         sr.WriteLine("</tbody></table></td></tr><tr>");
         sr.WriteLine("<td>End at " + locs[locs.Count - 1].AddressString + "<br>");
         sr.Write("Total distance: " + DirectionsPrinter.getDistanceGivenUnits(locs[locs.Count - 1].GpxLocation.Distance, units) + " ");
         sr.WriteLine(units + "</td></tr></tbody></table></td>");
         sr.WriteLine("<td style=\"vertical-align: top;\"><img style=\"width: 600px; height: 600px;\" alt=\"ride map\" src=\"" + shortFileName + ".bmp\"></td>");
         sr.WriteLine("</tr></tbody></table></body>");
         sr.WriteLine("<img style=\"width: 950px; height: 250px;\" alt=\"elevation profile\" src=\"" + shortFileName + ".ele.bmp\"></html>");
         sr.Close();
     } catch (Exception e) {
         _status = e.Message;
     }
 }