コード例 #1
0
 /// <summary>
 /// Creating a new document using the specified map, route, laps, initial transformation matrix, projection origin and document settings, and adding one new session with the specified route and laps.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="route"></param>
 /// <param name="laps"></param>
 /// <param name="initialTransformationMatrix"></param>
 /// <param name="projectionOrigin"></param>
 /// <param name="settings"></param>
 public Document(Map map, Route route, LapCollection laps, GeneralMatrix initialTransformationMatrix, LongLat projectionOrigin, DocumentSettings settings)
 {
     Map = map;
     sessions.Add(new Session(route, laps, map.Image.Size, initialTransformationMatrix, projectionOrigin, settings.DefaultSessionSettings));
     this.settings = settings;
     UpdateDocumentToCurrentVersion(this);
 }
コード例 #2
0
ファイル: Document.cs プロジェクト: romanbdev/quickroute-gps
 /// <summary>
 /// Creating a new document using the specified map, route, laps, initial transformation matrix, projection origin and document settings, and adding one new session with the specified route and laps.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="route"></param>
 /// <param name="laps"></param>
 /// <param name="initialTransformationMatrix"></param>
 /// <param name="projectionOrigin"></param>
 /// <param name="settings"></param>
 public Document(Map map, Route route, LapCollection laps, GeneralMatrix initialTransformationMatrix, LongLat projectionOrigin, DocumentSettings settings)
 {
     Map = map;
       sessions.Add(new Session(route, laps, map.Image.Size, initialTransformationMatrix, projectionOrigin, settings.DefaultSessionSettings));
       this.settings = settings;
       UpdateDocumentToCurrentVersion(this);
 }
コード例 #3
0
 protected Document(SerializationInfo info, StreamingContext context)
 {
     Map              = (Map)(info.GetValue("map", typeof(Map)));
     settings         = (DocumentSettings)(info.GetValue("settings", typeof(DocumentSettings)));
     sessions         = (SessionCollection)(info.GetValue("sessions", typeof(SessionCollection)));
     projectionOrigin = (LongLat)(info.GetValue("projectionOrigin", typeof(LongLat)));
     // todo: how handle non-existing properties field?
     try
     {
         properties = (DocumentProperties)(info.GetValue("properties", typeof(DocumentProperties)));
     }
     catch (Exception)
     { }
 }
コード例 #4
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);
            }
        }
コード例 #5
0
        public static Document Open(string fileName, DocumentSettings defaultSettings)
        {
            fileName = CommonUtil.GetDownloadedFileName(fileName);
            switch (GetFileFormat(fileName))
            {
            case QuickRouteFileFormat.Qrt:
                return(OpenFromQrt(fileName));

            case QuickRouteFileFormat.Jpeg:
                return(OpenFromJpeg(fileName, defaultSettings));

            case QuickRouteFileFormat.Xml:
                return(OpenFromXml(fileName, defaultSettings));
            }
            return(null);
        }
コード例 #6
0
ファイル: Document.cs プロジェクト: romanbdev/quickroute-gps
 /// <summary>
 /// Creating a new document using the specified map, route, laps, initial transformation matrix and document settings, and adding one new session with the specified route and laps.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="route"></param>
 /// <param name="laps"></param>
 /// <param name="initialTransformationMatrix"></param>
 /// <param name="settings"></param>
 public Document(Map map, Route route, LapCollection laps, GeneralMatrix initialTransformationMatrix, DocumentSettings settings)
     : this(map, route, laps, initialTransformationMatrix, null, settings)
 {
 }
コード例 #7
0
ファイル: Document.cs プロジェクト: romanbdev/quickroute-gps
 /// <summary>
 /// Creating a new document using the specified map, route, laps, and document settings, and adding one new session with the specified route and laps.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="route"></param>
 /// <param name="laps"></param>
 /// <param name="settings"></param>
 public Document(Map map, Route route, LapCollection laps, DocumentSettings settings)
     : this(map, route, laps, null, settings)
 {
 }
コード例 #8
0
ファイル: Document.cs プロジェクト: romanbdev/quickroute-gps
 /// <summary>
 /// Creates a new document using the specified map and document settings. No sessions are added.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="settings"></param>
 public Document(Map map, DocumentSettings settings)
 {
     Map = map;
       Settings = settings;
 }
コード例 #9
0
ファイル: Document.cs プロジェクト: romanbdev/quickroute-gps
        /// <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;
        }
コード例 #10
0
ファイル: Document.cs プロジェクト: romanbdev/quickroute-gps
        /// <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;
              }
        }
コード例 #11
0
ファイル: Document.cs プロジェクト: romanbdev/quickroute-gps
 public static Document Open(string fileName, DocumentSettings defaultSettings)
 {
     fileName = CommonUtil.GetDownloadedFileName(fileName);
       switch(GetFileFormat(fileName))
       {
     case QuickRouteFileFormat.Qrt:
       return OpenFromQrt(fileName);
     case QuickRouteFileFormat.Jpeg:
       return OpenFromJpeg(fileName, defaultSettings);
     case QuickRouteFileFormat.Xml:
       return OpenFromXml(fileName, defaultSettings);
       }
       return null;
 }
コード例 #12
0
 /// <summary>
 /// Creates a new document using the specified map and document settings. No sessions are added.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="settings"></param>
 public Document(Map map, DocumentSettings settings)
 {
     Map      = map;
     Settings = settings;
 }
コード例 #13
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);
        }
コード例 #14
0
 /// <summary>
 /// Creating a new document using the specified map, route, laps, initial transformation matrix and document settings, and adding one new session with the specified route and laps.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="route"></param>
 /// <param name="laps"></param>
 /// <param name="initialTransformationMatrix"></param>
 /// <param name="settings"></param>
 public Document(Map map, Route route, LapCollection laps, GeneralMatrix initialTransformationMatrix, DocumentSettings settings)
     : this(map, route, laps, initialTransformationMatrix, null, settings)
 {
 }
コード例 #15
0
 /// <summary>
 /// Creating a new document using the specified map, route, laps, and document settings, and adding one new session with the specified route and laps.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="route"></param>
 /// <param name="laps"></param>
 /// <param name="settings"></param>
 public Document(Map map, Route route, LapCollection laps, DocumentSettings settings)
     : this(map, route, laps, null, settings)
 {
 }
コード例 #16
0
ファイル: Document.cs プロジェクト: romanbdev/quickroute-gps
 protected Document(SerializationInfo info, StreamingContext context)
 {
     Map = (Map)(info.GetValue("map", typeof(Map)));
       settings = (DocumentSettings)(info.GetValue("settings", typeof(DocumentSettings)));
       sessions = (SessionCollection)(info.GetValue("sessions", typeof(SessionCollection)));
       projectionOrigin = (LongLat)(info.GetValue("projectionOrigin", typeof(LongLat)));
       // todo: how handle non-existing properties field?
       try
       {
     properties = (DocumentProperties)(info.GetValue("properties", typeof(DocumentProperties)));
       }
       catch (Exception)
       { }
 }
コード例 #17
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
            if (!doc.Settings.ColorRangeIntervalSliderSettings.ContainsKey(WaypointAttribute.MapReadingDuration))
            {
                var defaultCRISS = DocumentSettings.CreateDefaultColorRangeIntervalSliderSettings();
                doc.Settings.ColorRangeIntervalSliderSettings.Add(WaypointAttribute.MapReadingDuration, defaultCRISS[WaypointAttribute.MapReadingDuration]);
            }

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

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


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