Exemple #1
0
        private static void UpdateDocumentToCurrentVersion(Document doc)
        {
            var defaultRLS = SessionSettings.CreateDefaultRouteLineSettingsCollection();

              // ensure MonochromeColor is non-invisible
              foreach (Session s in doc.sessions)
              {
            foreach (var rls in s.Settings.RouteLineSettingsCollection.Values)
            {
              if (rls.MonochromeColor == Color.FromArgb(0, 0, 0, 0))
              {
            rls.MonochromeColor = rls.ColorRange.Gradient.GetColor(1);
            rls.MonochromeWidth = rls.Width;
              }
            }
              }

              // add some speed waypoint attribute settings, introduced in QR 2.1
              if (!doc.Settings.ColorRangeIntervalSliderSettings.ContainsKey(WaypointAttribute.Speed))
              {
            var defaultCRISS = DocumentSettings.CreateDefaultColorRangeIntervalSliderSettings();
            doc.Settings.ColorRangeIntervalSliderSettings.Add(WaypointAttribute.Speed, defaultCRISS[WaypointAttribute.Speed]);
              }

              if (!doc.Settings.LapHistogramSettings.ContainsKey(WaypointAttribute.Speed))
              {
            var defaultLHS = DocumentSettings.CreateDefaultLapHistogramSettings();
            doc.Settings.LapHistogramSettings.Add(WaypointAttribute.Speed, defaultLHS[WaypointAttribute.Speed]);
              }

              foreach (Session s in doc.sessions)
              {
            if (!s.Settings.RouteLineSettingsCollection.ContainsKey(WaypointAttribute.Speed))
            {
              s.Settings.RouteLineSettingsCollection.Add(WaypointAttribute.Speed, defaultRLS[WaypointAttribute.Speed]);
            }
              }

              // add some direction waypoint attribute settings, introduced in QR 2.1-4
              if (!doc.Settings.ColorRangeIntervalSliderSettings.ContainsKey(WaypointAttribute.DirectionDeviationToNextLap))
              {
            var defaultCRISS = DocumentSettings.CreateDefaultColorRangeIntervalSliderSettings();
            doc.Settings.ColorRangeIntervalSliderSettings.Add(WaypointAttribute.DirectionDeviationToNextLap, defaultCRISS[WaypointAttribute.DirectionDeviationToNextLap]);
              }

              if (!doc.Settings.LapHistogramSettings.ContainsKey(WaypointAttribute.DirectionDeviationToNextLap))
              {
            var defaultLHS = DocumentSettings.CreateDefaultLapHistogramSettings();
            doc.Settings.LapHistogramSettings.Add(WaypointAttribute.DirectionDeviationToNextLap, defaultLHS[WaypointAttribute.DirectionDeviationToNextLap]);
              }

              foreach (Session s in doc.sessions)
              {
            if (!s.Settings.RouteLineSettingsCollection.ContainsKey(WaypointAttribute.DirectionDeviationToNextLap))
            {
              s.Settings.RouteLineSettingsCollection.Add(WaypointAttribute.DirectionDeviationToNextLap, defaultRLS[WaypointAttribute.DirectionDeviationToNextLap]);
            }
              }

              // add circle time radius, introduced in QR 2.4
              foreach (var s in doc.sessions)
              {
            if (s.Settings.CircleTimeRadius == 0) s.Settings.CircleTimeRadius = 45;
              }

              // add map reading duration settings, introduced in QR 2.4
              // add cadence and power, introduced September 2014
              var attributes = new[] { WaypointAttribute.MapReadingDuration, WaypointAttribute.Cadence, WaypointAttribute.Power };

              foreach (var attribute in attributes)
              {
            if (!doc.Settings.ColorRangeIntervalSliderSettings.ContainsKey(attribute))
            {
              var defaultCRISS = DocumentSettings.CreateDefaultColorRangeIntervalSliderSettings();
              doc.Settings.ColorRangeIntervalSliderSettings.Add(attribute, defaultCRISS[attribute]);
            }

            if (!doc.Settings.LapHistogramSettings.ContainsKey(attribute))
            {
              var defaultLHS = DocumentSettings.CreateDefaultLapHistogramSettings();
              doc.Settings.LapHistogramSettings.Add(attribute, defaultLHS[attribute]);
            }

            if (!doc.Settings.DefaultSessionSettings.SmoothingIntervals.ContainsKey(attribute))
            {
              doc.Settings.DefaultSessionSettings.SmoothingIntervals[attribute] = new Interval(0, 0);
            }
              }

              foreach (Session s in doc.sessions)
              {
            foreach (var attribute in attributes)
            {
              if (!s.Settings.RouteLineSettingsCollection.ContainsKey(attribute))
              {
            s.Settings.RouteLineSettingsCollection.Add(attribute, defaultRLS[attribute]);
              }
            }
              }
        }
Exemple #2
0
        /// <summary>
        /// Opens a document stored in the old QuickRoute XML file format. This version can't save documents in this file format.
        /// </summary>
        /// <param name="fileName">The file name of the QuickRoute 1.0 xml document.</param>
        /// <param name="settings">The document settings to apply.</param>
        /// <returns></returns>
        public static Document OpenFromXml(string fileName, DocumentSettings settings)
        {
            XmlTextReader reader = null;

              RouteSegment rs = new RouteSegment();
              HandleCollection handles = new HandleCollection();
              Map map;

              try
              {

            reader = new XmlTextReader(fileName);
            reader.WhitespaceHandling = WhitespaceHandling.None;

            reader.ReadStartElement("QuickRoute");

            reader.ReadStartElement("Route");

            while (reader.Read() && reader.NodeType != XmlNodeType.EndElement)
            {
              while (reader.NodeType != XmlNodeType.Element) reader.Read();
              Waypoint t = new Waypoint();
              t.Time = DateTime.Parse(reader.GetAttribute("time"));
              t.LongLat = new LongLat();
              t.LongLat.Longitude = double.Parse(reader.GetAttribute("longitude"));
              t.LongLat.Latitude = double.Parse(reader.GetAttribute("latitude"));
              t.Altitude = double.Parse(reader.GetAttribute("altitude"));
              t.HeartRate = int.Parse(reader.GetAttribute("heartRate"));
              rs.Waypoints.Add(t);
            }
            reader.ReadEndElement();

            reader.ReadStartElement("Markers");
            while (reader.Name == "Handle")
            {
              reader.Read();
              Handle h = new Handle();
              h.ParameterizedLocation = new ParameterizedLocation(0, double.Parse(reader.GetAttribute("value")));
              reader.Read();
              double x = double.Parse(reader.GetAttribute("x"));
              double y = double.Parse(reader.GetAttribute("y"));
              h.Location = new PointD(x, y);
              reader.Read();
              h.TransformationMatrix = new GeneralMatrix(3, 3);
              h.MarkerDrawer = (new ApplicationSettings()).DefaultDocumentSettings.DefaultSessionSettings.MarkerDrawers[MarkerType.Handle];
              for (int row = 0; row < 3; row++)
              {
            for (int col = 0; col < 3; col++)
            {
              reader.Read();
              h.TransformationMatrix.SetElement(row, col, double.Parse(reader.GetAttribute("value")));
            }
              }
              reader.Read();
              reader.ReadEndElement();
              reader.ReadEndElement();
              handles.Add(h);
            }
            reader.ReadEndElement();

            map = new Map(Base64StringToBitmap(reader.ReadElementContentAsString()));

              }
              catch (Exception ex)
              {
            if (reader != null) reader.Close();
            throw new Exception(ex.Message);
              }
              reader.Close();

              List<RouteSegment> routeSegments = new List<RouteSegment>();
              routeSegments.Add(rs);
              Document doc = new Document(map, new Route(routeSegments), new LapCollection(), null, settings);
              foreach (var h in handles)
              {
            doc.Sessions[0].AddHandle(h);
              }
              doc.FileFormat = QuickRouteFileFormat.Xml;
              doc.Initialize();
              UpdateDocumentToCurrentVersion(doc);
              return doc;
        }
Exemple #3
0
        /// <summary>
        /// Opens a document from a jpeg file with embedded QuickRoute Jpeg Extension Data.
        /// </summary>
        /// <param name="fileName">The file name of the jpeg file.</param>
        /// <param name="settings">The document settings to apply.</param>
        /// <returns>A QuickRoute document if the jpeg file contains QuickRoute Jpeg Extension Data, otherwise null.</returns>
        public static Document OpenFromJpeg(string fileName, DocumentSettings settings)
        {
            var ed = QuickRouteJpegExtensionData.FromJpegFile(fileName);
              if (ed == null) return null;
              var mapAndBorderImage = (Bitmap)Image.FromFile(fileName);

              var mapImage = new Bitmap(ed.MapLocationAndSizeInPixels.Width, ed.MapLocationAndSizeInPixels.Height);
              using(var g = Graphics.FromImage(mapImage))
              {
            g.DrawImage(mapAndBorderImage,
                    new Rectangle(0, 0, ed.MapLocationAndSizeInPixels.Width, ed.MapLocationAndSizeInPixels.Height),
                    ed.MapLocationAndSizeInPixels,
                    GraphicsUnit.Pixel);
              }
              foreach(var pi in mapAndBorderImage.PropertyItems)
              {
            mapImage.SetPropertyItem(pi);
              }

              var exif = new ExifWorks.ExifWorks(ref mapAndBorderImage);
              var qualityByteArray = exif.GetProperty((int)ExifWorks.ExifWorks.TagNames.JPEGQuality, new byte[] { 80 });

              var encodingInfo = new JpegEncodingInfo((double)qualityByteArray[0] / 100);
              using (var ms = new MemoryStream())
              {
            mapImage.Save(ms, encodingInfo.Encoder, encodingInfo.EncoderParams);
            var document = new Document(new Map(ms), settings) { Sessions = ed.Sessions };
            if (document.Sessions.Count > 0) document.ProjectionOrigin = document.Sessions[0].ProjectionOrigin;
            document.FileName = fileName;
            document.FileFormat = QuickRouteFileFormat.Jpeg;
            document.Initialize();
            mapAndBorderImage.Dispose();
            mapImage.Dispose();
            return document;
              }
        }
 public static QuickRouteJpegExtensionData FromQuickRouteDocument(Document document, SessionCollection sessions, Rectangle imageBounds, Rectangle mapBounds, double percentualSize)
 {
     var data = new QuickRouteJpegExtensionData
            {
              Version = currentVersion,
              ImageCornerPositions = document.GetImageCornersLongLat(imageBounds, mapBounds, percentualSize),
              MapCornerPositions = document.GetMapCornersLongLat(),
              MapLocationAndSizeInPixels = mapBounds,
              Sessions = sessions,
              PercentualSize = percentualSize
            };
       return data;
 }
 public static QuickRouteJpegExtensionData FromQuickRouteDocument(Document document, Rectangle imageBounds, Rectangle mapBounds, double percentualSize)
 {
     return FromQuickRouteDocument(document, document.Sessions, imageBounds, mapBounds, percentualSize);
 }
 public static QuickRouteJpegExtensionData FromQuickRouteDocument(Document document)
 {
     var data = new QuickRouteJpegExtensionData {Version = currentVersion, Sessions = document.Sessions, PercentualSize = 1};
       return data;
 }