Пример #1
0
        /// <summary>
        /// imageFileProcessor can be null - the default one will be used, same with insertWaypointHandler and insertEarthquakeHandler
        /// 
        /// for a .jpg file just calls image file processor.
        /// for .gpx, .loc, .zip, .gpz and .wpt files calls BaseFormat.processor() and adds to foldersToProcess
        /// 
        /// returns true on success
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="insertWaypointHandler"></param>
        /// <param name="insertEarthquakeHandler"></param>
        /// <param name="imageFileProcessor"></param>
        /// <param name="foldersToProcess"></param>
        /// <returns></returns>
        public static bool readFile(string fileName, InsertWaypoint insertWaypointHandler, InsertEarthquake insertEarthquakeHandler,
                                        ProcessFile imageFileProcessor, SortedList foldersToProcess, bool addToRecent)
        {
            bool isSuccess = false;

            fileName = Project.GetLongPathName(new FileInfo(fileName).FullName);	// make sure we are not dealing with 8.3 notation here

            if (insertWaypointHandler == null)
            {
                insertWaypointHandler = new InsertWaypoint(WaypointsCache.insertWaypoint);
            }

            if (insertEarthquakeHandler == null)
            {
                insertEarthquakeHandler = new InsertEarthquake(EarthquakesCache.insertEarthquake);
            }

            if (imageFileProcessor == null)
            {
                imageFileProcessor = new ProcessFile(FileAndZipIO.processImageFile);
            }

            if (AllFormats.isTiffFile(fileName))
            {
                #region  Handle a GeoTiff file

                GeoTiff geoTiff = new GeoTiff(fileName);
                try
                {
                    geoTiff.init();
                }
                catch { }

                if (geoTiff.isValid)
                {
                    CustomMapsCache.RemoveCustomMapsBySource(fileName);

                    CustomMap cm = new CustomMapGeotiff(geoTiff);
                    Project.customMapId++;
                    cm.Id = Project.customMapId;
                    CustomMapsCache.AddCustomMap(cm);

                    WaypointsCache.pushBoundaries(cm.Location);
                    WaypointsCache.pushBoundaries(new GeoCoord(geoTiff.BottomLeftLng, geoTiff.BottomLeftLat));
                    WaypointsCache.pushBoundaries(new GeoCoord(geoTiff.TopRightLng, geoTiff.TopRightLat));
                    WaypointsCache.pushBoundaries(new GeoCoord(geoTiff.BottomRightLng, geoTiff.BottomRightLat));

                    // success, worth adding to imported list, if not repeat read:
                    bool repeatRead = isRepeatRead(fileName);
                    if (!repeatRead)
                    {
                        FormattedFileDescr ffd = new FormattedFileDescr(fileName, FileGeoTIFF.FormatName, false);
                        Project.FileDescrList.Add(ffd);
                    }
                    string msg = "OK: read file " + fileName + (repeatRead ? " (repeat read)" : "");
                    LibSys.StatusBar.Trace(msg);
                    LibSys.StatusBar.Trace("* " + msg);

                    isSuccess = true;	// will ensure refresh is called
                }
                else
                {
                    LibSys.StatusBar.Error("readFile - not a GeoTIFF file: " + fileName);
                }
                #endregion  // Handle a GeoTiff file
            }
            else if (fileName.ToLower().EndsWith(".jpg"))
            {
                #region Single JPEG image probably dropped

                PhotoWaypoints.cleanPhotoTrackpoints(fileName);
                try
                {
                    LibSys.StatusBar.Trace("   ...readFile - processing image file: " + fileName);
                    if (imageFileProcessor(null, null, fileName, fileName) > 0)
                    {
                        Project.photoFileName = fileName;
                        isSuccess = true;	// will ensure refresh is called
                    }
                }
                catch (Exception exc)
                {
                    LibSys.StatusBar.Error("Exception: " + exc.Message);
                }
                #endregion // Single JPEG image probably dropped
            }
            else
            {
                LibSys.StatusBar.Trace("   ...readFile - processing formatted file: " + fileName);

                #region Processing formatted file - zip, gpx

                BaseFormat format = AllFormats.formatByFileName(fileName);
                if (format != null)
                {
                    string formatName = AllFormats.formatNameByFileName(fileName);
                    format.InsertWaypoint = insertWaypointHandler;
                    format.InsertEarthquake = insertEarthquakeHandler;
                    FileListStruct fls = new FileListStruct(fileName, formatName, new FormatProcessor(format.process), false);
                    WaypointsCache.RemoveWaypointsBySource(fls.filename);
                    // actually read the file. If ZIP processor is there, it will read all enclosed .GPX files.
                    if (fls.processor("", fls.filename, fls.filename))		// boundaries pushed in WaypointsCache.insertWaypoint()
                    {
                        // knows about .gpx files and Project.photoAnalyzeOnLoad:
                        enlistPhotoFolder(fls.filename, foldersToProcess, imageFileProcessor);

                        // success, worth adding to imported list, if not repeat read:
                        bool repeatRead = isRepeatRead(fileName);
                        if (!repeatRead)
                        {
                            FormattedFileDescr ffd = new FormattedFileDescr(fileName, formatName, false);
                            Project.FileDescrList.Add(ffd);
                        }
                        string msg = "OK: read file " + fileName + (repeatRead ? " (repeat read)" : "");
                        LibSys.StatusBar.Trace(msg);
                        LibSys.StatusBar.Trace("* " + msg);
                        isSuccess = true;
                    }
                    else
                    {
                        LibSys.StatusBar.Trace("* Error: while processing file " + fileName);
                        Project.ErrorBox(Project.mainForm, "Error processing file:\n\n" + fls.filename);
                    }
                }
                else
                {
                    LibSys.StatusBar.Trace("* Error: unrecognized format " + fileName);
                    Project.ErrorBox(Project.mainForm, "Unrecognized format:\n\n" + fileName);
                }
                #endregion // Processing formatted file - zip, gpx

            }
            if (addToRecent && isSuccess)
            {
                Project.insertRecentFile(fileName);
            }
            return isSuccess;
        }
Пример #2
0
 public FileCnssSavedSearch(InsertEarthquake insertEarthquake)
     : base(insertEarthquake)
 {
 }
Пример #3
0
 public BaseFormat(InsertEarthquake insertEarthquake)
 {
     m_insertEarthquake = insertEarthquake;
 }
Пример #4
0
 public FileSignificantSavedSearch(InsertEarthquake insertEarthquake) : base(insertEarthquake)
 {
 }
Пример #5
0
 public BaseFormat(InsertEarthquake insertEarthquake)
 {
     m_insertEarthquake = insertEarthquake;
 }
 public FileIntensitySavedSearch(InsertEarthquake insertEarthquake)
     : base(insertEarthquake)
 {
 }
 public FileSignificantSavedSearch(InsertEarthquake insertEarthquake)
     : base(insertEarthquake)
 {
 }
Пример #8
0
 public FileCnssSavedSearch(InsertEarthquake insertEarthquake) : base(insertEarthquake)
 {
 }
Пример #9
0
        /*
        // debugging ThreadPool2
        private void timeEater(object state)
        {
            LibSys.StatusBar.WriteLine("timeEater started");
            int i = 0;
            while(true)
            {
                i++;
            }
        }
        */
        // this method is run in a worker thread:
        //private void runInit(object state, DateTime requestEnqueueTime)
        private void runInit(object state)
        {
            LibSys.StatusBar.WriteLine("Initializing");
            //Thread.Sleep(1000);	// it somehow goes smoother when we sleep here. frame and buttons appear faster.

            double elev = m_cameraManager.Location.Elev;	// meters
            double elevKm = elev / 1000.0d;
            setScrollBarValue(elevKm);
            setCameraAltitudeTextBoxValue(elevKm);
            //m_cameraManager.Elev = elev;

            if(Project.eqFetchOnStart && Project.upgradeMessage.Length == 0 && Project.serverAvailable)
            {
                LibSys.StatusBar.WriteLine("Progress monitor UP - fetching eq info");
                progressFormTimer.Interval = 3000;
                progressFormTimer.Tick += new EventHandler(RunProgressMonitorForm);
                progressFormTimer.Start();
            }

            // at this moment camera manager has location (after init()) but has not yet calculated it's
            // coverage etc. Make sure it has a chance to do so:
            m_cameraManager.ProcessCameraMove();

            switch(Project.earthquakeStyle)
            {
                default:
                case Earthquake.STYLE_DOT:
                    radioButton1.Checked = true;
                    break;
                case Earthquake.STYLE_CIRCLES:
                    radioButton2.Checked = true;
                    break;
                case Earthquake.STYLE_FILLCIRCLES:
                    radioButton3.Checked = true;
                    break;
                case Earthquake.STYLE_CONCENTRICCIRCLES:
                    radioButton4.Checked = true;
                    break;
                case Earthquake.STYLE_SQUARES:
                    radioButton5.Checked = true;
                    break;
                case Earthquake.STYLE_FILLSQUARES:
                    radioButton6.Checked = true;
                    break;
                case Earthquake.STYLE_TRIANGLE:
                    radioButton7.Checked = true;
                    break;
            }

            mainPictureBox.Paint += new System.Windows.Forms.PaintEventHandler(m_pictureManager.LayersManager.Paint);
            mainPictureBox.Resize += new System.EventHandler(m_pictureManager.PictureManager_Resize);
            statusBar.Click += new System.EventHandler(LibSys.StatusBar.statusBar_Click);

            // Make the list of files marked for persistent loading:
            // create a delegate to pass to processor:
            InsertWaypoint insertWaypoint = new InsertWaypoint(WaypointsCache.insertWaypoint);
            InsertEarthquake insertEarthquake = new InsertEarthquake(EarthquakesCache.insertEarthquake);
            formatAgain:
            foreach(FormattedFileDescr ffd in Project.FileDescrList)
            {
                BaseFormat format = AllFormats.formatByName(ffd.formatName);
                if(format != null)
                {
                    format.InsertWaypoint = insertWaypoint;
                    format.InsertEarthquake = insertEarthquake;
                    Project.FileList.Add(new FileListStruct(ffd.filename, ffd.formatName, new FormatProcessor(format.process), true));
                }
                else
                {
                    // something wrong got stuck there. Remove it.
                    Project.FileDescrList.Remove(ffd);
                    goto formatAgain;
                }
            }

            // now see if any files were dropped on our icon (or supplied as cmd line args):
            if(m_args != null && m_args.Length > 0)
            {
                foreach (string arg in m_args)
                {
                    if(arg != null)
                    {
                        if(arg.StartsWith("/"))
                        {
                            Project.ErrorBox(this, "Invalid option \"" + arg + "\"");
                        }
                        else
                        {
                            try
                            {
                                if(File.Exists(arg))
                                {
                                    string fileNameFull = Project.GetLongPathName(new FileInfo(arg).FullName);	// make sure we are not dealing with 8.3 notation here

                                    BaseFormat format = AllFormats.formatByFileName(fileNameFull);
                                    if(format != null)
                                    {
                                        string formatName = AllFormats.formatNameByFileName(fileNameFull);
                                        format.InsertWaypoint = insertWaypoint;
                                        format.InsertEarthquake = insertEarthquake;
                                        Project.FileList.Add(new FileListStruct(fileNameFull, formatName, new FormatProcessor(format.process), false));
                                    }
                                    else
                                    {
                                        Project.ErrorBox(this, "Unrecognized format:\n\n" + fileNameFull);
                                    }
                                }
                                else
                                {
                                    Project.ErrorBox(this, "Non-existent file:\n\n" + arg);
                                }
                            }
                            catch
                            {
                                Project.ErrorBox(this, "Error processing file:\n\n" + arg);
                            }
                        }
                    }
                }
            }

            FileAndZipIO.readPersistentAndDroppedFiles(!m_hadLonLatArgs, initialMessageLabel);	// dropped on icon or command line arguments

            rebuildFavoritesMenu();

            loadSetDlgIcon();

            // default page layout for printing:
            m_pgSettings.Landscape = true;
            m_pgSettings.Margins.Left = 0;
            m_pgSettings.Margins.Right = 0;
            m_pgSettings.Margins.Top = 0;
            m_pgSettings.Margins.Bottom = 0;
            mainPrintDocument.DefaultPageSettings = m_pgSettings;

            EarthquakesCache.goFetch = Project.eqFetchOnStart;
            //add dt worker method to the thread pool; queue a task that will run forever:
            //Project.threadPool.PostRequest (new WorkRequestDelegate (EarthquakesCache.Run), "fetch eq");
            ThreadPool2.QueueUserWorkItem (new WaitCallback (EarthquakesCache.Run), "fetch eq");

            WaypointsCache.RefreshWaypointsDisplayed();
            if(!Project.eqFetchOnStart)		// or it will be refreshed when the fetching is complete.
            {
                EarthquakesCache.RefreshEarthquakesDisplayed();
            }
            else if(Project.drawEarthquakes)
            {
                initialMessageLabel.Text = "...fetching earthquakes...";
            }

            if(Project.drawLandmarks)
            {
                initLandmarkService();

                warnWsOff();
            }

            initialMessageLabel.Size = new Size(1,1);
            initialMessageLabel.Visible = false;
            LibSys.StatusBar.WriteLine("Ready");

            /*
            for(double ddd=2.0d; ddd < 1000.0d ;ddd *= 2)
            {
                LibSys.StatusBar.WriteLine("ddd=" + ddd + " m/sec");
                Speed dSpeed = new Speed(ddd * 3600.0d);
                LibSys.StatusBar.WriteLine("      FEET: " + dSpeed.ToString(Distance.UNITS_DISTANCE_FEET));
                LibSys.StatusBar.WriteLine("      KM: " + dSpeed.ToString(Distance.UNITS_DISTANCE_KM));
                LibSys.StatusBar.WriteLine("      M: " + dSpeed.ToString(Distance.UNITS_DISTANCE_M));
                LibSys.StatusBar.WriteLine("      MILES: " + dSpeed.ToString(Distance.UNITS_DISTANCE_MILES));
                LibSys.StatusBar.WriteLine("      NMILES: " + dSpeed.ToString(Distance.UNITS_DISTANCE_NMILES));
            }
            */
        }
Пример #10
0
 public FileIntensitySavedSearch(InsertEarthquake insertEarthquake) : base(insertEarthquake)
 {
 }