void InternetRetrievalDialog::RebuildList()
{
    /* as we have a progress dialog, calling update calls event loop which
       can cause recursion here and problems */
    if(m_bRebuilding)
        return;
    m_bRebuilding = true;

    m_lUrls->DeleteAllItems();

    wxProgressDialog progressdialog(_("WeatherFax InternetRetrieval"), 
                                    _("Populating List"), m_InternetRetrieval.size(),
                                    this, wxPD_ELAPSED_TIME | wxPD_REMAINING_TIME);
    int i=0;
    for(std::list<FaxUrl*>::iterator it = m_InternetRetrieval.begin();
        it != m_InternetRetrieval.end(); it++, i++) {
        if(i%100 == 0)
            progressdialog.Update(i);
        if(!(*it)->Filtered) {
            wxListItem item;
            item.SetData(*it);
            UpdateItem(m_lUrls->InsertItem(item));
        }
    }
    m_bRebuilding = false;
}
Пример #2
0
bool nextneighbours3x3(QImage *image, unsigned char maxneighbours)
{
	unsigned int width, baseline, neighbourcount=0;

	QProgressDialog progressdialog("Eroding (Next Neighbors 3x3)", "Cancel", 0, image->height());
	progressdialog.setWindowTitle("Eroding (Next Neighbors 3x3)");
	progressdialog.setWindowModality(Qt::WindowModal);
	progressdialog.show();
	progressdialog.setValue(0);
	
	// Navigate in Pixmap
	// Pattern:
	// - - -
	// - . -
	// - - -
	int Xoffset[9] = { -1, 0, 1, -1, 0, 1, -1, 0, 1};
	int Yoffset[9] = { -1, -1, -1, 0, 0, 0, 1, 1, 1};

	width=image->width();
	QRgb *RGB;
	QRgb *RGBtmp;
	for (int y=1; y<image->height()-1; y++)
		for (int x=0; x<image->width(); x++)
		{
			baseline=y;
			RGB=(QRgb *)image->scanLine(y)+x;
			// Check, if center Pixel's got black neighbor(s)
			if(qBlue(*RGB)==0)
			{
				for (int i=0; i<9; i++)
				{
					RGBtmp=(QRgb *)image->scanLine(baseline+Yoffset[i])+x+Xoffset[i];
					if(qBlue(*RGBtmp)==0)
						neighbourcount++;
				}
				if(neighbourcount<=maxneighbours)
					image->setPixel(x, y, qRgb(255, 255, 255));
			}
			neighbourcount=0;

			progressdialog.setValue(y);
			if(progressdialog.wasCanceled())
			return false;
		}
	return true;
}
void InternetRetrievalDialog::OnRetrieve( wxCommandEvent& event )
{
    int count = 0;
    for(int i=0; i < m_lUrls->GetItemCount(); i++) {
        FaxUrl *faxurl = reinterpret_cast<FaxUrl*>
            (wxUIntToPtr(m_lUrls->GetItemData(i)));

        if(event.GetEventObject() == m_bRetrieveScheduled) {
            if(!faxurl->Scheduled)
                continue;
        } else
            if(m_lUrls->GetNextItem(i - 1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED) != i)
                continue;

        count++;

        wxString path = weatherfax_pi::StandardPath();

        wxString filename = faxurl->Url;
        filename.Replace(_T("/"), _T("!"));
        filename.Replace(_T(":"), _T("!"));

        filename = path + wxFileName::GetPathSeparator() + filename;

        wxFileName fn(filename);
        if(fn.FileExists() && (wxDateTime::Now() - fn.GetModificationTime()).GetMinutes() < 180) {
            wxMessageDialog mdlg(this, _("Fax already retrieved less than 180 minutes ago.\n\
Use existing file?"), _("Weather Fax"), wxYES | wxNO | wxCANCEL);
            switch(mdlg.ShowModal()) {
            case wxID_YES:
                goto loadimage;
            case wxID_NO:
                break;
            default:
                return;
            }
        }

        {
#if 0
            wxProgressDialog progressdialog(_("WeatherFax InternetRetrieval"),
                                            _("Reading Headers: ") + faxurl->Contents, 1000, this,
                                            wxPD_CAN_ABORT | wxPD_ELAPSED_TIME | wxPD_REMAINING_TIME);
            progressdialog.Update(0);
            
            DownloadThread *dl = new DownloadThread(faxurl->Url, filename);
            dl->Run();

            while(dl->IsRunning()) {
                bool ok;
                if(dl->size)
                    ok = progressdialog.Update(1000*dl->position / dl->size,
                                               _("Reading") + wxString(_T(": "))
                                               + faxurl->Contents);
                else
                    ok = progressdialog.Update(0);
                if(!ok) {
                    dl->please_quit = true;
                    return;
                }
                wxThread::Sleep(250);
            }

            dl->please_quit = true;

            switch(dl->exitcode) {
            case 1:
            case 2:
            {
                wxMessageDialog mdlg(this, _("Timed out waiting for headers for: ") +
                                     faxurl->Contents + _T("\n") + faxurl->Url + _T("\n") +
                                     _("Verify there is a working internet connection.") + _T("\n") +
                                     _("Possibly the server is down temporarily.") + _T("\n") +
                                     _("If the url is incorrect please edit the xml and/or post a bug report."),
                                     _("Weather Fax"), wxOK | wxICON_ERROR);
                mdlg.ShowModal();
            } return;
            case 3:
            { wxMessageDialog mdlg(this, _("Failed to read file size aborting."),
                                     _("Weather Fax"), wxOK | wxICON_INFORMATION);
                mdlg.ShowModal();
            } return;
            }
#else

        wxFileOutputStream output(filename);
        wxCurlDownloadDialog ddlg(faxurl->Url, &output, _("WeatherFax InternetRetrieval"),
                                  _("Reading Headers: ") + faxurl->Contents, wxNullBitmap, this,
                                  wxCTDS_CAN_PAUSE|wxCTDS_CAN_ABORT|wxCTDS_SHOW_ALL|wxCTDS_AUTO_CLOSE);

        switch(ddlg.RunModal()) {
        case wxCDRF_SUCCESS: break;
        case wxCDRF_FAILED:
        {
            wxMessageDialog mdlg(this, _("Failed to Download: ") +
                                 faxurl->Contents + _T("\n") +
                                 faxurl->Url + _T("\n") +
                                 _("Verify there is a working internet connection.") + _T("\n") +
                                 _("If the url is incorrect please edit the xml and/or post a bug report."),
                                 _("Weather Fax"), wxOK | wxICON_ERROR);
            mdlg.ShowModal();
            wxRemoveFile( filename );
        }
        case wxCDRF_USER_ABORTED: return;
        }
#endif
    }

    loadimage:
        m_weatherfax_pi.m_pWeatherFax->OpenImage
            (filename, faxurl->Server + _T(" - ") + faxurl->Region, faxurl->area_name, faxurl->Contents);

    }
Пример #4
0
void ReportDialog::GenerateRoutesReport()
{
    if(!m_bReportStale)
        return;
    m_bReportStale = false;

    /* sort configurations interate over each group of configurations
       with the same start and end to determine best and worst times,
       and cyclone crossings to determine cyclone times
    */

    std::map<wxString, std::list<RouteMapOverlay *> > routes;
    for(std::list<WeatherRoute*>::iterator it = m_WeatherRouting.m_WeatherRoutes.begin();
        it != m_WeatherRouting.m_WeatherRoutes.end(); it++) {
        if(!(*it)->routemapoverlay->ReachedDestination())
            continue;
        wxString route_string = (*it)->Start + _T(" - ") + (*it)->End;
        std::list<RouteMapOverlay *> overlays = routes[route_string];
        overlays.push_back((*it)->routemapoverlay);
        routes[route_string] = overlays;
    }

    if(routes.size() == 0) {
        m_htmlRoutesReport->SetPage(_("No routes to report yet."));
        return;
    }

    wxString page;
    for(std::map<wxString, std::list<RouteMapOverlay *> >::iterator it = routes.begin();
                          it != routes.end(); it++)
    {
        std::list<RouteMapOverlay *> overlays = it->second;
        if (overlays.begin() == overlays.end()) {
            // XXX not possible? but shut up compilers warnings
            continue;
        }
        RouteMapOverlay *first = *overlays.begin();

        RouteMapConfiguration c = first->GetConfiguration();
        page += _T("<p>");
        page += c.Start + _T(" ") + _("to") + _T(" ") + c.End + _T(" ") + wxString::Format
            (_T("(%ld ") + wxString(_("configurations")) + _T(")\n"), overlays.size());

        /* determine fastest time */
        wxTimeSpan fastest_time;
        RouteMapOverlay *fastest;

        std::multimap< wxDateTime, RouteMapOverlay * > sort_by_start;
        bool any_bad = false;
        bool any_good = false;

        for(std::list<RouteMapOverlay *>::iterator it2 = overlays.begin(); it2 != overlays.end(); it2++) {
            RouteMapOverlay *r = *it2;
            wxTimeSpan current_time = r->EndTime() - r->StartTime();
            sort_by_start.insert(std::pair< wxDateTime, RouteMapOverlay * >(r->StartTime() , r));
            if(r == first || current_time < fastest_time) {
                fastest_time = current_time;
                fastest = r;
            }
            if (r->RouteInfo(RouteMapOverlay::PERCENTAGE_UPWIND) > 50) {
                any_bad = true;
            } else {
                any_good = true;
            }
        }

        page += _("<dt>Fastest configuration ") + FormatTime(fastest->StartTime());
        page += wxString(_T(" ")) + _("avg speed") + wxString::Format
            (_T(": %.2f "), fastest->RouteInfo(RouteMapOverlay::AVGSPEED))
	    + _("knots");

        /* determine best times if upwind percentage is below 50 */
        page += _T("<dt>");
        page += _("Best Times (mostly downwind)") + wxString(_T(": "));
        if (any_good == false) {
            // no downwind route
            page += _("none");
        }
        else if (any_bad == false) {
            // all routes are downwind
            page += _("any");
        }
        else {
            bool first_print = true;
            std::multimap< wxDateTime, RouteMapOverlay * > reduce_by_start;
            // merge downwind routes in bigger interval
            // assume most routes with same start time are of same kind (downwind or upwind)
            std::multimap< wxDateTime, RouteMapOverlay * >::iterator it = sort_by_start.begin();
            while (it != sort_by_start.end() ) {
                // remove first upwind routes, from any_good test there's at least one downwind route
                for(; it != sort_by_start.end(); it++) {
                    RouteMapOverlay *r = it->second;
                    if (r->RouteInfo(RouteMapOverlay::PERCENTAGE_UPWIND) <= 50) {
                        break;
                     }
                }
                if (it == sort_by_start.end()) 
                    break;

                RouteMapOverlay *r = it->second;
                wxDateTime s = DisplayedTime(r->StartTime());
                wxDateTime e = DisplayedTime(r->EndTime());
                // merge downwind
                for(; it != sort_by_start.end(); it++) {
                    RouteMapOverlay *r = it->second;
                    if (r->RouteInfo(RouteMapOverlay::PERCENTAGE_UPWIND) > 50) {
                        break;
                    }
                    e = r->EndTime();
                }
                if(first_print)
                    first_print = false;
                else
                    page += _(" and ");
                page += s.Format(_T("%d %B ")) + _("to") + e.Format(_T(" %d %B"));
            }
        }
        
        // CUSTOMIZATION
        // Display the best option to travel in order
        // to get the most comfortable sailing
        page += _T("<dt>");
        page += _("Best Sailing Comfort") + wxString(_T(": "));
        wxDateTime best_comfort_date;
        int best_sailing_comfort = 6;
        for(std::multimap< wxDateTime, RouteMapOverlay * >::iterator it3 = sort_by_start.begin(); it3 != sort_by_start.end(); it3++) {
            RouteMapOverlay *r = it3->second;
            if (!best_comfort_date.IsValid() ||
                (best_comfort_date < r->StartTime() && best_sailing_comfort > r->RouteInfo(RouteMapOverlay::COMFORT)))
            {
                best_comfort_date = r->StartTime();
                best_sailing_comfort = r->RouteInfo(RouteMapOverlay::COMFORT);
            }
        }
        page += RouteMapOverlay::sailingConditionText(best_sailing_comfort);
        page += _T(" on ");
        page += FormatTime(best_comfort_date);
        
        page += _T("<dt>");
        page += _("Cyclones") + wxString(_T(": "));

        wxProgressDialog progressdialog(_("Weather Routing"), _("Calculating Cyclone Crossings"),
                                        overlays.size(), this, wxPD_ELAPSED_TIME);
        int pdi = 0;

        int cyclonemonths[12] = {0};
        std::list<RouteMapOverlay *> cyclone_safe_routes;
        bool allsafe = true, nonesafe = true;
        for(std::list<RouteMapOverlay *>::iterator it2 = overlays.begin(); it2 != overlays.end(); it2++) {
            switch((*it2)->Cyclones(cyclonemonths)) {
            case -1:
                page += _("Climatology data unavailable.");
                goto cyclonesfailed;
            case 0:
                cyclone_safe_routes.push_back(*it2);
                nonesafe = false;
            default:
                cyclone_safe_routes.push_back(NULL);
                allsafe = false;
            }

            progressdialog.Update(pdi++);
        }
        
        int i, j;
        for(i=0, j=11; i<12; j=i++)
            /* get first cyclone month */
            if(cyclonemonths[i] && !cyclonemonths[j]) {
                int lm = i;
                page += wxDateTime::GetMonthName((wxDateTime::Month)i);
                for(int k=i+1, l=i; ; l = k++) {
                    if(k==12) k = 0;
                    if(k == i)
                        break;
                    if(cyclonemonths[k] && !cyclonemonths[l]) {
                        page += _(" and ") + wxDateTime::GetMonthName((wxDateTime::Month)k);
                        lm = k;
                    } else if(!cyclonemonths[k] && cyclonemonths[l] && l!=lm)
                        page += _(" to ") + wxDateTime::GetMonthName((wxDateTime::Month)l);
                }
                goto had_some_cyclones;
            }
                    
        if(cyclonemonths[0])
            page += _("all months");
        else
            page += _("none");

    had_some_cyclones:;

        page += _T("<dt>");
        if(allsafe)
            page += _("All routes are safe from cyclones.");
        else if(nonesafe)
            page += _("No routes found to be safe from cyclones.");
        else {
            page += _("Start times for cyclone safe routes: ");
            /* note: does not merge beginning and end of linked list for safe times,
               this sometimes might be nice, but they will be in different years. */
            bool first = true;
            for(std::list<RouteMapOverlay *>::iterator it2 = cyclone_safe_routes.begin(); it2 != cyclone_safe_routes.end();
                        it2++)
            {
                if(!*it2) continue;
                if(!first)
                    page += _(" and ");
                first = false;
                page += DisplayedTime((*it2)->StartTime()).Format(_T("%x"));

                if(++it2 == cyclone_safe_routes.end())
                    break;

                if(!*it2)
                    continue;

                while(*it2 && ++it2 != cyclone_safe_routes.end());

                it2--;
                page += _(" to ") + DisplayedTime((*it2)->StartTime()).Format(_T("%x"));
            }
        }
    cyclonesfailed:;
    }

    m_htmlRoutesReport->SetPage(page);
}
Пример #5
0
void ReportDialog::GenerateRoutesReport()
{
    if(!m_bReportStale)
        return;
    m_bReportStale = false;

    /* sort configurations interate over each group of configurations
       with the same start and end to determine best and worst times,
       and cyclone crossings to determine cyclone times
    */

    std::map<wxString, std::list<RouteMapOverlay *> > routes;
    for(std::list<WeatherRoute*>::iterator it = m_WeatherRouting.m_WeatherRoutes.begin();
        it != m_WeatherRouting.m_WeatherRoutes.end(); it++) {
        if(!(*it)->routemapoverlay->ReachedDestination())
            continue;
        wxString route_string = (*it)->Start + _T(" - ") + (*it)->End;
        std::list<RouteMapOverlay *> overlays = routes[route_string];
        overlays.push_back((*it)->routemapoverlay);
        routes[route_string] = overlays;
    }

    if(routes.size() == 0) {
        m_htmlRoutesReport->SetPage(_("No routes to report yet."));
        return;
    }

    wxString page;
    for(std::map<wxString, std::list<RouteMapOverlay *> >::iterator it = routes.begin();
        it != routes.end(); it++) {
        std::list<RouteMapOverlay *> overlays = it->second;
        RouteMapOverlay *first = *overlays.begin();
        RouteMapConfiguration c = first->GetConfiguration();
        page += _T("<p>");
        page += c.Start + _T(" ") + _("to") + _T(" ") + c.End + _T(" ") + wxString::Format
            (_T("(%ld ") + wxString(_("configurations")) + _T(")\n"), overlays.size());

        /* determine fastest time */
        wxTimeSpan fastest_time;
        RouteMapOverlay *fastest = NULL;
        for(std::list<RouteMapOverlay *>::iterator it2 = overlays.begin(); it2 != overlays.end(); it2++) {
            wxTimeSpan current_time = ((*it2)->EndTime() - (*it2)->StartTime());
            if(*it2 == first || current_time < fastest_time) {
                fastest_time = current_time;
                fastest = *it2;
            }
        }
        page += _("<dt>Fastest configuration ") + fastest->StartTime().Format(_T("%x"));
        page += wxString(_T(" ")) + _("avg speed") + wxString::Format
            (_T(": %.2f knots"), fastest->RouteInfo(RouteMapOverlay::AVGSPEED));

        /* determine best times if upwind percentage is below 50 */
        page += _T("<dt>");
        page += _("Best Times (mostly downwind)") + wxString(_T(": "));

        bool last_bad, any_bad, any_good = false, first_print = true;

        wxDateTime best_time_start;

        std::list<RouteMapOverlay *>::iterator it2, it2end = overlays.begin(), prev;
        last_bad = overlays.back()->RouteInfo(RouteMapOverlay::PERCENTAGE_UPWIND) > 50;

        for(it2 = overlays.begin(); it2 != overlays.end(); it2++)
            if((*it2)->RouteInfo(RouteMapOverlay::PERCENTAGE_UPWIND) > 50) {
                any_bad = last_bad = true;
            } else {
                if(!best_time_start.IsValid() && last_bad) {
                    best_time_start = (*it2)->StartTime();
                    it2end = it2;
                    it2++;
                    break;
                }
                last_bad = false;
            }

        if(it2 == overlays.end())
            it2++;
        for(;;) {
            if(it2 == it2end)
                break;
            it2++;
            if(it2 == overlays.end())
                it2++;

            if((*it2)->RouteInfo(RouteMapOverlay::PERCENTAGE_UPWIND) > 50) {
                if(!last_bad) {
                    prev = it2;
                    prev--;
                    if(prev == overlays.end()) prev--;
                    if(first_print)
                        first_print = false;
                    else
                        page += _(" and ");
                    page += best_time_start.Format(_T("%d %B ")) +
                        _("to") + (*prev)->EndTime().Format(_T(" %d %B"));
                }
                last_bad = any_bad = true;
            } else {
                if(last_bad)
                    best_time_start = (*it2)->StartTime();
                last_bad = false;
                any_good = true;
            }
        }

        if(!any_bad)
            page += _("any");
        else if(!any_good)
            page += _("none");

        page += _T("<dt>");
        page += _("Cyclones") + wxString(_T(": "));

        wxProgressDialog progressdialog(_("Weather Routing"), _("Calculating Cyclone Crossings"),
                                        overlays.size(), this, wxPD_ELAPSED_TIME);
        int pdi = 0;

        int cyclonemonths[12] = {0};
        std::list<RouteMapOverlay *> cyclone_safe_routes;
        bool allsafe = true, nonesafe = true;
        for(it2 = overlays.begin(); it2 != overlays.end(); it2++) {
            switch((*it2)->Cyclones(cyclonemonths)) {
            case -1:
                page += _("Climatology data unavailable.");
                goto cyclonesfailed;
            case 0:
                cyclone_safe_routes.push_back(*it2);
                nonesafe = false;
            default:
                cyclone_safe_routes.push_back(NULL);
                allsafe = false;
            }

            progressdialog.Update(pdi++);
        }
        
        int i, j;
        for(i=0, j=11; i<12; j=i++)
            /* get first cyclone month */
            if(cyclonemonths[i] && !cyclonemonths[j]) {
                int lm = i;
                page += wxDateTime::GetMonthName((wxDateTime::Month)i);
                for(int k=i+1, l=i; ; l = k++) {
                    if(k==12) k = 0;
                    if(k == i)
                        break;
                    if(cyclonemonths[k] && !cyclonemonths[l]) {
                        page += _(" and ") + wxDateTime::GetMonthName((wxDateTime::Month)k);
                        lm = k;
                    } else if(!cyclonemonths[k] && cyclonemonths[l] && l!=lm)
                        page += _(" to ") + wxDateTime::GetMonthName((wxDateTime::Month)l);
                }
                goto had_some_cyclones;
            }
                    
        if(cyclonemonths[0])
            page += _("all months");
        else
            page += _("none");

    had_some_cyclones:;

        page += _T("<dt>");
        if(allsafe)
            page += _("All routes are safe from cyclones.");
        else if(nonesafe)
            page += _("No routes found to be safe from cyclones.");
        else {
            page += _("Start times for cyclone safe routes: ");
            /* note: does not merge beginning and end of linked list for safe times,
               this sometimes might be nice, but they will be in different years. */
            bool first = true;
            for(it2 = cyclone_safe_routes.begin(); it2 != cyclone_safe_routes.end(); it2++) {
                if(!*it2) continue;
                if(!first)
                    page += _(" and ");
                first = false;
                page += (*it2)->StartTime().Format(_T("%x"));

                if(++it2 == cyclone_safe_routes.end())
                    break;

                if(!*it2)
                    continue;

                while(*it2 && ++it2 != cyclone_safe_routes.end());

                it2--;
                page += _(" to ") + (*it2)->StartTime().Format(_T("%x"));
            }
        }
    cyclonesfailed:;
    }

    m_htmlRoutesReport->SetPage(page);
}