void exifGpsView_TagFromGpsLogClick(object sender, EventArgs e)
        {
            // the filename of the gps log
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title  = "Open gps nmea file";
            ofd.Filter = "*.txt|*.txt";
            if (ofd.ShowDialog(mainForm) != DialogResult.OK)
            {
                return;
            }

            this.lastGpsFile = ofd.FileName;

            // read the gps log
            mainForm.WaitCursor(true);
            GpsLog log = GpsLogFactory.FromFile(ofd.FileName);

            mainForm.WaitCursor(false);

            // empty log -> exit
            if (log.Count == 0)
            {
                MessageBox.Show("The gps log file is empty or PhotoTagStudio cannot read it.", mainForm.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // ask for gps time offset
            PictureGpsOffsetDialog d = new PictureGpsOffsetDialog(currentPicture, log.FirstTime.Value, log.LastTime.Value);

            d.Offset = Settings.Default.GPSTimeOffset;
            if (d.ShowDialog(mainForm) != DialogResult.OK)
            {
                return;
            }

            // set offset to gps log
            Settings.Default.GPSTimeOffset = d.Offset;
            log.Offset = d.Offset;

            PauseOtherWorker();
            gpsBackgroundWorker.RunWorkerAsync(new GpsWorkerArguemnts(log));
        }
Exemple #2
0
        private void buttonGetGpsData_Click(object sender, EventArgs e)
        {
            // a picture is need for the offset dialog
            if (this.currentPicture == null)
            {
                return;
            }

            // the filename of the gps log
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title  = "Open gps nmea file";
            ofd.Filter = "*.txt|*.txt";
            if (ofd.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            this.lastGpsFile = ofd.FileName;

            // read the gps log
            GpsLog log = GpsLogFactory.FromFile(ofd.FileName);

            // empty log -> exit
            if (log.Count == 0)
            {
                return;
            }

            // ask for gps time offset
            PictureGpsOffsetDialog d = new PictureGpsOffsetDialog(currentPicture, log.FirstTime.Value, log.LastTime.Value);

            d.Offset = Settings.Default.GPSTimeOffset;
            if (d.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            // set offset to gps log
            Settings.Default.GPSTimeOffset = d.Offset;
            log.Offset = d.Offset;

            IStatusDisplay statusDisplay = (IStatusDisplay)this.FindForm();

            List <string> filenames = this.GetAllFileList(false);

            statusDisplay.WorkStart(filenames.Count);

            // compute the timespan of all pictures
            DateTime firstPicture           = new DateTime(4000, 1, 1);
            DateTime lastPicture            = new DateTime(1, 1, 1);
            List <PictureMetaData> pictures = new List <PictureMetaData>();

            foreach (string filename in filenames)
            {
                PictureMetaData pmd;
                if (this.currentPicture != null &&
                    this.currentPicture.Filename == filename)
                {
                    pmd = currentPicture;
                }
                else
                {
                    pmd = new PictureMetaData(filename);
                }

                if (pmd.ExifOriginalDateTime.HasValue)
                {
                    DateTime time = pmd.ExifOriginalDateTime.Value;

                    if (time > lastPicture)
                    {
                        lastPicture = time;
                    }
                    if (time < firstPicture)
                    {
                        firstPicture = time;
                    }

                    pictures.Add(pmd);
                }
                statusDisplay.WorkNextPart();
            }
            statusDisplay.WorkFinished();

            // ask the user: do it now?
            string text =
                String.Format(
                    "The GPS time is between {0} and {1}.\nThe picture time is between {2} and {3} ({4} and {5}).\n\nContinue?",
                    log.FirstTime,
                    log.LastTime,
                    firstPicture.Add(log.Offset),
                    lastPicture.Add(log.Offset),
                    firstPicture,
                    lastPicture);

            if (MessageBox.Show(text, "Continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                statusDisplay.WorkStart(pictures.Count);
                foreach (PictureMetaData pmd in pictures)
                {
                    UpdateGpsData(pmd, log);

                    if (pmd != currentPicture)
                    {
                        pmd.Close();
                    }
                    statusDisplay.WorkNextPart();
                }

                FireDataChanged();
                statusDisplay.WorkFinished();
            }
            else
            {
                foreach (PictureMetaData pmd in pictures)
                {
                    if (pmd != currentPicture)
                    {
                        pmd.Close();
                    }
                }
            }
        }