Exemplo n.º 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);
 }
Exemplo n.º 2
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)
 {
 }
Exemplo n.º 3
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)
 {
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
0
        private DialogResult Import()
        {
            // validate file names
              if (imageSourceType != SourceType.Url && mapImageFileName.Text != "" && !File.Exists(mapImageFileName.Text))
              {
            MessageBox.Show(Strings.MapImageFileDoesNotExist, Strings.InvalidMapImage, MessageBoxButtons.OK,
                      MessageBoxIcon.Error);
            return DialogResult.Cancel;
              }
              if (routeFromFile.Checked && !File.Exists(routeFileName.Text))
              {
            MessageBox.Show(Strings.RouteFileDoesNotExist, Strings.InvalidRoute, MessageBoxButtons.OK,
                      MessageBoxIcon.Error);
            return DialogResult.Cancel;
              }

              IRouteImporter routeImporter = null;
              if (routeFromFile.Checked)
              {
            IRouteFileImporter routeFileImporter = ((RouteFileFormat)routeFileFormatComboBox.SelectedItem).Importer;
            routeFileImporter.FileName = routeFileName.Text;
            routeImporter = routeFileImporter;
              }
              else if (routeFromGpsDevice.Checked)
              {
            GPSDevice gpsDevice = routeGpsDevice.SelectedItem as GPSDevice;
            if (gpsDevice == null)
            {
              MessageBox.Show(Strings.NoGPSDevicesConnectedMessageBox, Strings.InvalidRoute, MessageBoxButtons.OK,
                          MessageBoxIcon.Error);
              return DialogResult.Cancel;
            }
            routeImporter = gpsDevice.Importer;
              }

              routeImporter.BeginWork += routeImporter_BeginWork;
              routeImporter.WorkProgress += routeImporter_WorkProgress;
              routeImporter.EndWork += routeImporter_EndWork;

              DialogResult result;
              try
              {
            result = routeImporter.ShowPreImportDialogs();
              }
              catch (Exception ex)
              {
            Cursor = Cursors.Default;
            Util.ShowExceptionMessageBox(ex, Strings.InvalidRoute);
            return DialogResult.Cancel;
              }
              if (result == DialogResult.OK)
              {
            try
            {
              routeImporter.Import();
            }
            catch (Exception ex)
            {
              routeImporter.ImportResult.Succeeded = false;
              routeImporter.ImportResult.Error = ImportError.Unknown;
              routeImporter.ImportResult.ErrorMessage = ex.Message;
              routeImporter.ImportResult.Exception = ex;
            }

            if (!routeImporter.ImportResult.Succeeded)
            {
              // an error occured, show relevant error info and cancel creation of new document.
              switch (routeImporter.ImportResult.Error)
              {
            case ImportError.NoWaypoints:
              routeImporter.ImportResult.ErrorMessage = Strings.RouteImportError_NoWaypoints;
              break;

            case ImportError.NoWaypointTimes:
              routeImporter.ImportResult.ErrorMessage = Strings.RouteImportError_NoWaypointTimes;
              break;

              }
              Cursor = Cursors.Default;
              if (routeImporter.ImportResult.Exception != null)
              {
            Util.ShowExceptionMessageBox(routeImporter.ImportResult.Exception, Strings.InvalidRoute);
              }
              else
              {
            MessageBox.Show(routeImporter.ImportResult.ErrorMessage, Strings.InvalidRoute, MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
              }
              return DialogResult.Cancel;
            }

            try
            {
              if (string.IsNullOrEmpty(mapImageFileName.Text))
              {
            var blankMap = new Bitmap(1500, 1500);
            using (Graphics g = Graphics.FromImage(blankMap))
            {
              g.Clear(Color.White);
            }
            Map = new Map(blankMap);
              }
              else if (!ImageHasBeenTransformed)
              {
            CreateMapAndSetInitialTransformations();
              }
              else
              {
            // don't care about transformations embedded in jpg, qrt or kmz files since the original file has been transformed
            Map = new Map(new Bitmap(transformedImage));
              }
            }
            catch (Exception ex)
            {
              Cursor = Cursors.Default;
              Util.ShowExceptionMessageBox(ex, Strings.InvalidMapImage);
              return DialogResult.Cancel;
            }
            ImportResult = routeImporter.ImportResult;

            if (!string.IsNullOrEmpty(mapImageFileName.Text)) Util.ApplicationSettings.AddRecentMapImageFileName(mapImageFileName.Text);
            if (routeFromFile.Checked) Util.ApplicationSettings.AddRecentRouteFileName(routeFileName.Text);
              }
              return result;
        }
Exemplo n.º 7
0
        private void CreateMapAndSetInitialTransformations()
        {
            switch (SelectedImageFileFormat)
              {
            case ImageFileFormat.ImageFile:
              using (var ms = new MemoryStream(originalMapBytes))
              {
            Map = new Map(ms);
            ms.Position = 0;
            var ed = QuickRouteJpegExtensionData.FromStream(ms);
            // is it a QuickRoute image? if yes, use embedded transformation matrix
            if (ed != null && ed.Sessions != null && ed.Sessions.Count > 0)
            {
              InitialTransformation = ed.Sessions.CalculateAverageTransformation();
            }
            break;
              }

            case ImageFileFormat.QuickRouteFile:
              using (var ms = new MemoryStream(originalMapBytes))
              {
            var d = Document.OpenFromQrt(ms);
            if (d != null)
            {
              Map = d.Map;
              InitialTransformation = d.Sessions.CalculateAverageTransformation();
            }
              }
              break;

            case ImageFileFormat.KmzFile:
              using (var ms = new MemoryStream(originalMapBytes))
              {
            var kmz = new KmzDocument(ms);
            if (kmz.ImageStream != null)
            {
              Map = new Map(kmz.ImageStream);
              InitialTransformation = kmz.Transformation;
            }
            break;
              }
              }
        }