示例#1
0
        /// <summary>
        /// returns true if it could actually find something to display
        /// </summary>
        /// <returns></returns>
        private bool preview()
        {
            bool ret = false;

            disableButtons();
            // Create an Image object from the specified file.
            try
            {
                m_wpt = PhotoWaypoints.CurrentWaypoint();
                if (m_wpt != null)
                {
                    PhotoDescr photoDescr = PhotoDescr.FromThumbnail(m_wpt.ThumbSource);

                    photoViewerControl.photoDescr = m_photoDescr = photoDescr;

                    setPhotoDetail();
                    if (m_keepInView)
                    {
                        PictureManager.This.CameraManager.keepInView(m_wpt.Location);
                    }
                    PictureManager.This.CameraManager.MarkLocation(m_wpt.Location, 0);
                    ret = true;
                }
                else
                {
                    photoViewerControl.photoDescr = m_photoDescr = null;
                }
            }
            // An invalid image will throw an OutOfMemoryException
            // exception
            catch (OutOfMemoryException)
            {
                throw new InvalidOperationException("'" + m_wpt.ThumbSource + "' is not a valid image file.");
            }

            if (ret)
            {
                setupButtons();
            }
            DlgPhotoManager.sync(false);
            this.BringToFront();

            return(ret);
        }
示例#2
0
        private void deleteButton_Click(object sender, System.EventArgs e)
        {
            if (m_photoDescr != null && m_photoDescr.imageSourceIsLocal)
            {
                string imageSource = m_photoDescr.imageSource;
                try
                {
                    string msg;
                    int    pos = imageSource.IndexOf("|");
                    if (pos > 0)
                    {
                        // this is a .zip or .gpz file
                        string zipFileName   = imageSource.Substring(0, pos);
                        string photoFileName = imageSource.Substring(pos + 1);
                        msg = "Will permanently delete entry '" + photoFileName + "' from the zip archive '" + zipFileName
                              + "'.\n\nThe zip archive file will NOT be deleted.\n\nAre you sure?";
                    }
                    else
                    {
                        // plain file
                        msg = "Will permanently delete file '" + imageSource + "' from disk.\n\nAre you sure?";
                    }

                    string fileToDelete = null;

                    if (Project.YesNoBox(this, msg))
                    {
                        if (m_wpt != null)
                        {
                            if (m_wpt.TrackId == -1)
                            {
                                WaypointsCache.RemoveWaypointById(m_wpt.Id);
                            }
                            PhotoWaypoints.RemoveWaypoint(m_wpt);                                       // from track too, if any

                            photoViewerControl.photoDescr = null;

                            fileToDelete = m_photoDescr.deleteFromDisk();

                            if (preview())                                      // will find current waypoint, if any, and set m_photoDescr
                            {
                                setPhotoDetail();
                                photoViewerControl.Refresh();
                            }
                            else
                            {
                                // no image to display, need to wrap up
                                m_photoDescr = null;
                                this.Close();
                            }
                            PictureManager.This.Refresh();
                        }
                        else
                        {
                            PhotoWaypoints.RemoveUnrelatedById(m_photoDescr.Id);

                            fileToDelete = m_photoDescr.deleteFromDisk();

                            if (PhotoWaypoints.PhotosUnrelated.Count > 0)
                            {
                                photoViewerControl.photoDescr = m_photoDescr = (PhotoDescr)PhotoWaypoints.PhotosUnrelated.GetByIndex(0);
                                setPhotoDetail();
                                photoViewerControl.Refresh();
                                this.setupButtons();
                                this.BringToFront();
                            }
                            else
                            {
                                photoViewerControl.photoDescr = m_photoDescr = null;
                                this.Close();
                            }
                        }

                        DlgPhotoManager.sync(true);

                        if (fileToDelete != null)
                        {
                            GC.Collect();
                            FileInfo fi = new FileInfo(fileToDelete);
                            fi.Delete();
                        }
                    }
                }
                catch (Exception exc)
                {
                    Project.ErrorBox(this, "Failed to delete " + imageSource + "\n\nException: " + exc.Message);
                    this.Close();
                }
            }
        }
示例#3
0
        /*
         * see http://www.topografix.com/GPX/1/0 for more info
         *
         * Validating your GPX document
         *              Validation is done using the Xerces XML parser. Download the latest Xerces distribution from the Apache website.
         *               Windows users should download the "Latest Xerces-C++ Binary Package for Windows". Unzip the files, and locate the
         *               SAXCount.exe program in the bin folder. This is a command-line utility that will validate your GPX file.
         *
         *      Assuming your GPX file is named my_gpx_file.gpx, and is located in the same folder as SaxCount.exe, use the following
         *       command line to validate your file:
         *
         *                      SaxCount.exe -v=always -n -s -f test.gpx
         *
         *      If your file validates successfully, SAXCount will display a count of the elements in your file, like the following:
         *
         *                      test.gpx: 1012 ms (4025 elems, 1916 attrs, 8048 spaces, 36109 chars)
         *
         *      Any other output from SAXCount.exe indicates that your GPX file is incorrect. It is your responsibility to ensure that any GPX files you create validate successfully against the GPX schema.
         */

        public void doWrite()
        {
            string diag = "Selected format: " + m_selectedFormat + "\r\n\r\n";

            trkpointCount = 0;
            waypointCount = 0;
            // could be "new DateTimeFormatInfo().UniversalSortableDateTimePattern;" - but it has space instead of 'T'

            messageBoxDirty     = true;
            messageTextBox.Text = diag;

            try
            {
                if (m_selectedFormat.Equals(FileStreetsTripsCsv.FormatName))
                {
                    hasSaved = FileAndZipIO.saveCsv(m_selectedFileName, m_tracks, m_saveTracks,
                                                    m_waypoints, m_saveWaypoints, out waypointCount, out trkpointCount);
                }
                else if (m_selectedFormat.Equals(FileEasyGps.FormatName))
                {
                    int tracksCount;
                    hasSaved = FileAndZipIO.saveGpx(m_selectedFileName, m_tracks, m_saveTracks,
                                                    m_waypoints, m_saveWaypoints, out waypointCount, out trkpointCount, out tracksCount);

                    // try suggesting JPEG correlation here, if the folder has any .JPG files
                    if (tracksCount > 0)
                    {
                        bool hasJpegs = false;
                        try
                        {
                            FileInfo      fi = new FileInfo(m_selectedFileName);
                            DirectoryInfo di = fi.Directory;
                            foreach (FileInfo fii in di.GetFiles())
                            {
                                if (fii.Name.ToLower().EndsWith(".jpg"))
                                {
                                    hasJpegs = true;
                                    break;
                                }
                            }
                        }
                        catch
                        {
                        }
                        if (hasJpegs)
                        {
                            string message = "The folder you selected contains images\r\n\r\nDo you want to relate them to trackpoints?";
                            if (Project.YesNoBox(this, message))
                            {
                                Project.photoFileName = m_selectedFileName;
                                Project.pmLastTabMode = 0;
                                DlgPhotoManager dlg = new DlgPhotoManager(0);
                                dlg.setImportButtonsAgitated();
                                dlg.ShowDialog();
                            }
                        }
                    }
                }
                else if (m_selectedFormat.Equals(FileKml.FormatName))
                {
                    string name = new FileInfo(m_selectedFileName).Name;

                    name = name.Substring(0, name.Length - FileKml.FileExtension.Length);

                    GoogleEarthManager.saveTracksWaypoints(
                        m_selectedFileName, name, m_tracks, m_saveTracks,
                        m_waypoints, m_saveWaypoints, out waypointCount, out trkpointCount
                        );
                }
                else
                {
                    messageTextBox.Text = "Error: format " + m_selectedFormat + " not supported for writing.";
                    LibSys.StatusBar.Error("FileExportForm:doWrite() format " + m_selectedFormat + " not supported for writing.");
                    return;
                }

                WaypointsCache.isDirty = false;

                if (waypointCount > 0 || trkpointCount > 0)
                {
                    diag += "OK: " + waypointCount + " waypoints and " + trkpointCount + " legs saved to file.";
                    messageTextBox.ForeColor = Color.Black;

                    FileInfo           fi = new FileInfo(Project.GetLongPathName(m_selectedFileName));
                    FormattedFileDescr fd = new FormattedFileDescr(fi.FullName, m_selectedFormat, persistCheckBox.Checked);
                    Project.FileDescrListAdd(fd);

                    if (!m_selectedFormat.Equals(FileKml.FormatName))                           // can't read back kmz
                    {
                        Project.insertRecentFile(fi.FullName);
                    }
                }
                else
                {
                    diag += "Error: failed to save to file (0 waypoints, 0 legs).";
                    messageTextBox.ForeColor = Color.Red;
                }

                messageTextBox.Text = diag;
            }
            catch (Exception e)
            {
                LibSys.StatusBar.Error("FileExportForm:doWrite() " + e);                 //.Message);
                messageTextBox.Text      = diag + e.Message;
                messageTextBox.ForeColor = Color.Red;
            }
        }