Пример #1
0
        private void selectFileButton_Click(object sender, System.EventArgs e)
        {
            traceTextBox.Text = "selected: " + Project.togeotiffFileName;

            GeoTiff geoTiff = new GeoTiff(Project.togeotiffFileName);

            geoTiff.TopLeftLat     = geoTiff.TopRightLat = CameraManager.This.CoverageTopLeft34.Lat;
            geoTiff.TopLeftLng     = geoTiff.BottomLeftLng = CameraManager.This.CoverageTopLeft34.Lng;
            geoTiff.BottomRightLat = geoTiff.BottomLeftLat = CameraManager.This.CoverageBottomRight34.Lat;
            geoTiff.BottomRightLng = geoTiff.TopRightLng = CameraManager.This.CoverageBottomRight34.Lng;

            geoTiff.initImageOnly();

            if (geoTiff.isValid)
            {
                CustomMapsCache.RemoveCustomMapsBySource(Project.togeotiffFileName);

                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));

                string msg = "OK: read image file " + Project.togeotiffFileName;
                LibSys.StatusBar.Trace(msg);
                LibSys.StatusBar.Trace("* " + msg);

                toState(2);

                selectGeotiffPointButton.Enabled = true;
                selectMapPointButton.Enabled     = false;

                PictureManager.This.Refresh();
            }
            else
            {
                LibSys.StatusBar.Error("cannot make a GeoTIFF file: " + Project.togeotiffFileName);
            }
        }
Пример #2
0
        private static bool processGcPage(string url, byte[] dataDownloaded)
        {
            bool ret = false;

            int    lineno = 0;
            string line;
            int    state        = 0;
            string lineToSearch = "<span id=\"CacheName\">";
            int    pos;
            string cacheName = "";

            ASCIIEncoding enc      = new ASCIIEncoding();
            string        pageText = new String(enc.GetChars(dataDownloaded));

            CreateInfo createInfo = new CreateInfo();                   // we will recycle it in place, filling every time.

            StringReader stream = new StringReader(pageText);

            try
            {
                while ((line = stream.ReadLine()) != null && state < 99)
                {
                    lineno++;
                    switch (state)
                    {
                    case 0:
                        if ((pos = line.IndexOf(lineToSearch)) != -1)
                        {
                            pos += lineToSearch.Length;
                            int pos1 = line.IndexOf("</span>", pos);
                            if (pos1 > pos)
                            {
                                cacheName = line.Substring(pos, pos1 - pos).Trim();
                                LibSys.StatusBar.Trace("OK: cacheName='" + cacheName + "'");

                                state        = 1;
                                lineToSearch = "<span id=\"LatLon\"";
                            }
                        }
                        break;

                    case 1:
                        if ((pos = line.IndexOf(lineToSearch)) != -1)
                        {
                            pos += lineToSearch.Length;
                            int pos1 = line.IndexOf("</span>", pos);
                            if (pos1 > pos)
                            {
                                string sCacheCoords = line.Substring(pos, pos1 - pos).Trim();
                                LibSys.StatusBar.Trace("OK: cacheCoords='" + sCacheCoords + "'");
                                GeoCoord loc = getCleanLocation(sCacheCoords);
                                //LibSys.StatusBar.Trace("OK: loc='" + loc + "'");

                                createInfo.init("wpt");
                                createInfo.lat       = loc.Lat;
                                createInfo.lng       = loc.Lng;
                                createInfo.typeExtra = "geocache";
                                createInfo.source    = url;
                                createInfo.name      = cacheName;
                                createInfo.url       = url;

                                WaypointsCache.insertWaypoint(createInfo);

                                WaypointsCache.isDirty = true;

                                ret          = true;                                    // report successfully parsed page
                                state        = 99;
                                lineToSearch = "";
                            }
                        }
                        break;
                    }
                }
            }
            catch {}

            return(ret);
        }
Пример #3
0
        //private void Run(object state, DateTime requestEnqueueTime)
        private void Run(object state)
        {
            string emailText    = importTextBox.Text;
            string lineToSearch = "http://www.geocaching.com/seek/cache_details.asp";

            m_errorCount = 0;

            //ArrayList links = new ArrayList();
            int    nCaches;
            int    gcCount = 0;
            int    lineno  = 0;
            string line;

            StringReader stream = new StringReader(emailText);

            // first, count the links to make sure there are some, and to set progress bar maximum:
            try
            {
                while ((line = stream.ReadLine()) != null)
                {
                    lineno++;
                    if (line.IndexOf(lineToSearch) != -1)
                    {
                        gcCount++;
                        //links.Add(line.Trim());
                    }
                }
            }
            catch {}

            nCaches = gcCount;

            if (nCaches == 0)
            {
                statusLabel.Text = "Error: pasted text does not contain links to geocache pages.";
            }
            else
            {
                statusLabel.Text    = "OK: email contains " + nCaches + " caches";
                progressBar.Maximum = nCaches;
                progressBar.Minimum = 0;

                // bring up Progress monitor form, first sleep in the loop will give it some time to initialize:
                //Project.threadPool.PostRequest (new WorkRequestDelegate (RunPM), "import geocache");
                ThreadPool2.QueueUserWorkItem(new WaitCallback(RunPM), "import geocache");

                lineno  = 0;
                gcCount = 0;

                try
                {
                    stream = new StringReader(emailText);

                    while ((line = stream.ReadLine()) != null && gcCount < m_maxLinks && !m_stop)
                    {
                        lineno++;
                        try
                        {
                            if (line.IndexOf(lineToSearch) != -1)
                            {
                                // try not to overload the server:
                                Thread.Sleep(gcCount == 0 ? 1000 : m_processingDelaySec * 1000);

                                gcCount++;
                                progressBar.Value = gcCount;
                                string link = line.Trim();
                                statusLabel.Text = "IP: processing " + link + " - " + gcCount + " of " + nCaches;

                                DownloadThread dt = new DownloadThread();
                                dt.DownloadUrl = link;
                                dt.tile        = null;
                                int pos = link.IndexOf("ID=");
                                dt.baseName           = pos < 0 ? link : link.Substring(pos);
                                dt.fileName           = "";
                                dt.CompleteCallback  += new DownloadCompleteHandler(gcDownloadCompleteCallback);
                                dt.ProgressCallback  += new DownloadProgressHandler(gcDownloadProgressCallback);
                                dt.addMonitoredMethod = new AddMonitoredMethod(ProgressMonitor.addMonitored);

                                //add dt worker method to the thread pool / queue a task
                                //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download), dt.baseName);
                                ThreadPool2.QueueUserWorkItem(new WaitCallback(dt.Download), dt.baseName);
                            }
                        }
                        catch (Exception ee)
                        {
                            LibSys.StatusBar.Error(" line=" + lineno + " " + ee.Message);
                        }
                    }
                }
                catch {}

                statusLabel.Text = "OK: finished processing, " + gcCount + " links processed, " + m_errorCount + " errors";
                if (gcCount >= m_maxLinks)
                {
                    statusLabel.Text += " [limit " + m_maxLinks + " reached]";
                }
                WaypointsCache.RefreshWaypointsDisplayed();
                m_pictureManager.Refresh();
            }
            importButton.Enabled = true;
        }
Пример #4
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();
                }
            }
        }
Пример #5
0
        public static void processApiCall(string strArgs)
        {
            ArrayList files  = new ArrayList();                 // of string
            bool      doMove = false;

            char[]   splitter = { '|' };
            string[] args     = strArgs.Split(splitter);
            GeoCoord pos      = PictureManager.This.CameraManager.Location.Clone();

            switch (args[0])
            {
            case "api":                                 // something like "api|cmd|data...."
                switch (args[1])
                {
                case "refresh":
                    PictureManager.This.CameraManager.ProcessCameraMove();
                    break;

                case "resetzoom":
                    WaypointsCache.resetBoundaries();
                    break;

                case "dozoom":
                    PictureManager.This.CameraManager.zoomToCorners();
                    break;

                case "newwpt":
                {
                    double   lat       = Convert.ToDouble(args[2]);
                    double   lng       = Convert.ToDouble(args[3]);
                    double   elev      = Convert.ToDouble(args[4]);
                    DateTime dateTime  = Convert.ToDateTime(args[5]);
                    string   name      = args[6];                                       // like "GC12345"
                    string   urlName   = args[7];                                       // like "Mike's cache"
                    string   type      = args[8];                                       // like "geocache"
                    string   typeExtra = args[9];                                       // like "Geocache Found"
                    string   sym       = args[10];                                      // like "Geocache"
                    long     trackid   = Convert.ToInt64(args[11]);                     // -1 is none, -2 - last track created
                    if (trackid == -2)
                    {
                        trackid = Project.trackId;
                    }
                    string url        = args[12];                                       // can be empty
                    string descr      = args[13];                                       // can be empty
                    string source     = args[14];                                       // can be empty
                    bool   keepInView = "true".Equals(args[15].ToLower());

                    CreateInfo ci = new CreateInfo();

                    ci.init(type);

                    ci.comment  = "";
                    ci.dateTime = dateTime;
                    ci.desc     = descr;
                    ci.elev     = elev;
                    ci.id       = trackid;
                    ci.lat      = lat;
                    ci.lng      = lng;
                    //ci.magn = 0.0d;
                    ci.name      = name;
                    ci.source    = source;
                    ci.sym       = sym;
                    ci.typeExtra = typeExtra;
                    ci.url       = url;
                    ci.urlName   = urlName;

                    WaypointsCache.insertWaypoint(ci);
                    if (keepInView)
                    {
                        GeoCoord loc = new GeoCoord(lng, lat);
                        PictureManager.This.CameraManager.keepInView(loc);
                    }
                }
                break;

                case "delwpt":
                {
                    string name    = args[2];                                           // like "GC12345"
                    string urlName = args[3];                                           // like "Mike's cache"
                    string source  = args[4];

                    if (name.Length > 0)
                    {
                        WaypointsCache.RemoveWaypointByName(name);
                    }
                    else if (urlName.Length > 0)
                    {
                        WaypointsCache.RemoveWaypointByUrlname(urlName);
                    }
                    else if (source.Length > 0)
                    {
                        WaypointsCache.RemoveWaypointsBySource(source);
                    }

                    //PictureManager.This.CameraManager.ProcessCameraMove();
                }
                break;

                case "newtrk":
                {
                    string trackName = args[2];                                                 // like "trip home"
                    string type      = args[3];                                                 // like "trk" or "rte"
                    string source    = args[4];                                                 // can be empty

                    CreateInfo ci = new CreateInfo();

                    Project.trackId++;

                    ci.init(type);
                    ci.name   = trackName;
                    ci.id     = Project.trackId;
                    ci.source = source;

                    WaypointsCache.insertWaypoint(ci);
                }
                break;

                case "deltrk":                                  // or route
                {
                    string name   = args[2];                    // like "track45"			- if empty, use source
                    string source = args[3];                    // can delete by source		- if empty, delete the last one

                    if (name.Length > 0)
                    {
                        WaypointsCache.RemoveTracksByName(name);
                    }
                    else if (source.Length > 0)
                    {
                        WaypointsCache.RemoveTracksBySource(source);
                    }
                    else
                    {
                        // move ID pointer to the highest yet existing track/route:
                        while (Project.trackId > 0 && WaypointsCache.getTrackById(Project.trackId) == null)
                        {
                            Project.trackId--;
                        }

                        if (Project.trackId >= 0)
                        {
                            WaypointsCache.RemoveTrackById(Project.trackId);

                            // move ID pointer to the highest yet existing track/route:
                            while (Project.trackId > 0 && WaypointsCache.getTrackById(Project.trackId) == null)
                            {
                                Project.trackId--;
                            }
                        }
                    }

                    PictureManager.This.CameraManager.ProcessCameraMove();
                }
                break;

                case "newvehicle":
                {
                    double   lat        = Convert.ToDouble(args[2]);
                    double   lng        = Convert.ToDouble(args[3]);
                    double   elev       = Convert.ToDouble(args[4]);
                    DateTime dateTime   = args[5].Length > 0 ? Convert.ToDateTime(args[5]) : Project.localToZulu(DateTime.Now);
                    string   name       = args[6];                                                              // like "My Chevy"
                    string   sym        = args[7];                                                              // like "1" "2"...  or empty
                    string   url        = args[8];                                                              // can be empty
                    string   source     = args[9];                                                              // can be empty
                    string   desc       = args[10];                                                             // can be empty
                    bool     keepInView = "true".Equals(args[11].ToLower());
                    bool     doTrackLog = "true".Equals(args[12].ToLower());

                    GeoCoord loc = new GeoCoord(lng, lat, elev);

                    GpsRealTimeData rtData = new GpsRealTimeData();
                    rtData.location = loc;
                    rtData.fix      = 2;
                    rtData.time     = dateTime;

                    VehicleGps vehicle = new VehicleGps(rtData, name, sym, source, url, desc, doTrackLog);                              // also adds to VehicleCache
                    vehicle.KeepInView = keepInView;
                    VehiclesCache.addVehicle(vehicle);
                }
                break;

                case "movevehicle":
                {
                    double   lat        = Convert.ToDouble(args[2]);
                    double   lng        = Convert.ToDouble(args[3]);
                    double   elev       = Convert.ToDouble(args[4]);
                    DateTime dateTime   = args[5].Length > 0 ? Convert.ToDateTime(args[5]) : Project.localToZulu(DateTime.Now);
                    string   name       = args[6];                                                              // like "My Chevy"
                    string   sym        = args[7];                                                              // like "1" "2"...  or empty
                    string   url        = args[8];                                                              // can be empty
                    string   source     = args[9];                                                              // can be empty
                    string   desc       = args[10];                                                             // can be empty
                    bool     keepInView = "true".Equals(args[11].ToLower());
                    bool     doTrackLog = "true".Equals(args[12].ToLower());

                    GeoCoord loc = new GeoCoord(lng, lat, elev);

                    GpsRealTimeData rtData = new GpsRealTimeData();
                    rtData.location = loc;
                    rtData.fix      = 2;
                    rtData.time     = dateTime;

                    VehicleGps vehicle = (VehicleGps)VehiclesCache.getVehicleByName(name);
                    if (vehicle != null)
                    {
                        if (url.Length > 0)
                        {
                            vehicle.Url = url;
                        }
                        if (sym.Length > 0)
                        {
                            vehicle.Sym = sym;
                            vehicle.setImage(sym);
                        }
                        if (desc.Length > 0)
                        {
                            vehicle.Desc = desc;
                        }
                        vehicle.KeepInView = keepInView;
                        vehicle.doTrackLog = doTrackLog;
                        vehicle.ProcessMove(rtData);
                    }
                }
                break;

                case "delvehicle":
                {
                    string name   = args[2];                                                                    // like "My Chevy" or empty
                    string source = args[3];                                                                    // can be empty

                    VehicleGps vehicle = (VehicleGps)VehiclesCache.getVehicleByName(name);
                    if (vehicle != null)
                    {
                        bool wasTracking = vehicle.doTrackLog;
                        VehiclesCache.deleteVehicle(vehicle);                                   // takes care of removing it from LayerVehicle
                        if (wasTracking)
                        {
                            PictureManager.This.CameraManager.ProcessCameraMove();                                      // refresh to have track endpoints
                        }
                    }
                }
                break;

                case "exporttofile":
                {
                    string fileName = args[2];

                    int waypointCount = 0;
                    int trkpointCount = 0;
                    int tracksCount   = 0;

                    FileAndZipIO.saveGpx(fileName, WaypointsCache.TracksAll, true,
                                         WaypointsCache.WaypointsAll, true, out waypointCount, out trkpointCount, out tracksCount);

                    if (waypointCount > 0 || trkpointCount > 0)
                    {
                        LibSys.StatusBar.Trace("OK: " + waypointCount + " waypoints and " + trkpointCount + " legs saved to file " + fileName);
                    }
                    else
                    {
                        LibSys.StatusBar.Error("failed to save to file (0 waypoints, 0 legs): " + fileName);
                    }
                }
                break;
                }
                break;

            default:                            // regular command-line style messages - lon, lat, elev, map, file

                foreach (string arg in args)
                {
                    if (arg.StartsWith("/"))
                    {
#if DEBUG
                        LibSys.StatusBar.Trace("option: '" + arg + "'");
#endif
                        try
                        {
                            if (arg.ToLower().StartsWith("/lat="))
                            {
                                double lat = Convert.ToDouble(arg.Substring(5));
                                if (lat < 90.0d && lat > -90.0d)
                                {
                                    pos.Lat = lat;
                                    doMove  = true;
                                }
                            }
                            else if (arg.ToLower().StartsWith("/lon="))
                            {
                                double lon = Convert.ToDouble(arg.Substring(5));
                                if (lon < 180.0d && lon > -180.0d)
                                {
                                    pos.Lng = lon;
                                    doMove  = true;
                                }
                            }
                            else if (arg.ToLower().StartsWith("/elev="))
                            {
                                double elev = Convert.ToDouble(arg.Substring(6));
                                if (elev < Project.CAMERA_HEIGHT_MAX * 1000.0d && elev > Project.CAMERA_HEIGHT_MIN_DEFAULT * 1000.0d)
                                {
                                    pos.Elev = elev;
                                    doMove   = true;
                                }
                            }
                            else if (arg.ToLower().StartsWith("/map="))
                            {
                                string mode = arg.Substring(5);
                                Project.mainCommand.setMapMode(mode);
                                doMove = true;
                            }
                        }
                        catch (Exception ee)
                        {
                            string message = "argument '" + arg + "' - wrong format (" + ee.Message + ")";
                            LibSys.StatusBar.Error(message);
                            Project.ErrorBox(null, message);
                        }
                    }
                    else
                    {
#if DEBUG
                        LibSys.StatusBar.Trace("file: '" + arg + "'");
#endif
                        files.Add(arg);
                    }
                }

                if (files.Count > 0)
                {
                    // similar to drag&drop:
                    Cursor.Current = Cursors.WaitCursor;
                    Project.mainForm.Focus();
                    Project.mainForm.BringToFront();

                    try
                    {
                        string[] fileNames = new string[files.Count];

                        int ii = 0;
                        foreach (string fileName in files)
                        {
                            fileNames[ii] = fileName;
                            ii++;
                        }

                        bool anySuccess = FileAndZipIO.readFiles(fileNames);

                        if (anySuccess)                                 // we need to zoom into whole set of dropped files, or refresh in case of JPG
                        {
                            Project.mainCommand.wptEnabled(true);
                            if (!PictureManager.This.CameraManager.zoomToCorners())
                            {
                                PictureManager.This.CameraManager.ProcessCameraMove();                                          // nowhere to zoom in - just refresh
                            }
                        }
                    }
                    catch
                    {
                        LibSys.StatusBar.Trace("* API: cannot accept arguments '" + strArgs + "'");
                    }
                    Cursor.Current = Cursors.Default;
                }
                break;
            }                   // end switch

            if (doMove)
            {
                PictureManager.This.CameraManager.Location = pos;                               // calls ProcesCameraMove()
            }
        }