RouteMapConfiguration ConfigurationDialog::Configuration() { RouteMapConfiguration configuration; configuration.Start = m_cStart->GetValue(); configuration.StartTime = m_dpStartDate->GetValue(); double hour; m_tStartHour->GetValue().ToDouble(&hour); configuration.StartTime.SetHour((int)hour); configuration.StartTime.SetMinute((int)(60*hour)%60); configuration.boatFileName = m_fpBoat->GetPath(); configuration.dt = 60*(60*m_sTimeStepHours->GetValue() + m_sTimeStepMinutes->GetValue()) + m_sTimeStepSeconds->GetValue(); if(configuration.dt == 0) { wxMessageDialog mdlg(this, _("Zero Time Step invalid"), _("Weather Routing"), wxOK | wxICON_WARNING); mdlg.ShowModal(); } configuration.End = m_cEnd->GetValue(); if(m_lDegreeSteps->GetCount() < 4) { wxMessageDialog mdlg(this, _("Warning: less than 4 different degree steps specified\n"), wxString(_("Weather Routing"), wxOK | wxICON_WARNING)); mdlg.ShowModal(); } configuration.DegreeSteps.clear(); for(unsigned int i=0; i<m_lDegreeSteps->GetCount(); i++) { double step; m_lDegreeSteps->GetString(i).ToDouble(&step); configuration.DegreeSteps.push_back(positive_degrees(step)); } configuration.DegreeSteps.sort(); configuration.MaxDivertedCourse = m_sMaxDivertedCourse->GetValue(); configuration.MaxWindKnots = m_sMaxWindKnots->GetValue(); configuration.MaxSwellMeters = m_sMaxSwellMeters->GetValue(); configuration.MaxLatitude = m_sMaxLatitude->GetValue(); configuration.MaxTacks = m_sMaxTacks->GetValue(); configuration.TackingTime = m_sTackingTime->GetValue(); configuration.DetectLand = m_cbDetectLand->GetValue(); configuration.Currents = m_cbCurrents->GetValue(); configuration.InvertedRegions = m_cbInvertedRegions->GetValue(); configuration.Anchoring = m_cbAnchoring->GetValue(); configuration.AllowDataDeficient = m_cbAllowDataDeficient->GetValue(); configuration.UseGrib = m_cbUseGrib->GetValue(); configuration.UseClimatology = m_cbUseClimatology->GetValue(); return configuration; }
void WeatherRouting::AddPosition(double lat, double lon) { wxTextEntryDialog pd( this, _("Enter Name"), _("New Position") ); if(pd.ShowModal() == wxID_OK) { wxString name = pd.GetValue(); for(std::list<RouteMapPosition>::iterator it = RouteMap::Positions.begin(); it != RouteMap::Positions.end(); it++) { if((*it).Name == name) { wxMessageDialog mdlg(this, _("This name already exists, replace?\n"), _("Weather Routing"), wxYES | wxNO | wxICON_ERROR); if(mdlg.ShowModal() == wxID_YES) { long index = m_lPositions->FindItem(0, name); (*it).lat = lat; (*it).lon = lon; m_lPositions->SetItem(index, POSITION_LAT, wxString::Format(_T("%.5f"), lat)); m_lPositions->SetItem(index, POSITION_LON, wxString::Format(_T("%.5f"), lon)); } UpdateConfigurations(); return; } } // for AddPosition(lat, lon, name); } }
void InternetRetrievalDialog::OnUrlsSort( wxListEvent& event ) { sortcol = event.GetColumn(); sortorder = -sortorder; if(sortcol == 0) { #if 0 m_SelectedInternetRetrieval.clear(); for(std::list<FaxUrl*>::iterator it = m_InternetRetrieval.begin(); it != m_InternetRetrieval.end(); it++) { (*it)->Selected = sortorder == 1; if(sortorder == 1) m_SelectedInternetRetrieval.push_back(*it); } RebuildList(); #endif } else if(m_lUrls->GetItemCount() > 500) { wxMessageDialog mdlg(this, _("Sorting this many urls might take too long"), _("weatherfax"), wxOK | wxICON_ERROR); mdlg.ShowModal(); } else m_lUrls->SortItems(SortUrl, (long)m_lUrls); }
void WeatherRouting::Export(RouteMapOverlay &routemapoverlay) { std::list<PlotData> plotdata = routemapoverlay.GetPlotData(); if(plotdata.size() == 0) { wxMessageDialog mdlg(this, _("Empty Route, nothing to export\n"), _("Weather Routing"), wxOK | wxICON_WARNING); mdlg.ShowModal(); return; } PlugIn_Track* newTrack = new PlugIn_Track; newTrack->m_NameString = _("Weather Route"); for(std::list<PlotData>::iterator it = plotdata.begin(); it != plotdata.end(); it++) { PlugIn_Waypoint* newPoint = new PlugIn_Waypoint ((*it).lat, (*it).lon, _T("circle"), _("Weather Route Point")); newPoint->m_CreateTime = (*it).time; newTrack->pWaypointList->Append(newPoint); } AddPlugInTrack(newTrack); GetParent()->Refresh(); }
void CelestialNavigationDialog::SaveXML(wxString filename) { TiXmlDocument doc; TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "utf-8", "" ); doc.LinkEndChild( decl ); TiXmlElement * root = new TiXmlElement( "OpenCPNCelestialNavigation" ); doc.LinkEndChild( root ); char version[24]; sprintf(version, "%d.%d", PLUGIN_VERSION_MAJOR, PLUGIN_VERSION_MINOR); root->SetAttribute("version", version); root->SetAttribute("creator", "Opencpn Celestial Navigation plugin"); TiXmlElement *c = new TiXmlElement( "ClockError" ); c->SetAttribute("Seconds", m_ClockCorrectionDialog.m_sClockCorrection->GetValue()); root->LinkEndChild(c); for(int i = 0; i<m_lSights->GetItemCount(); i++) { TiXmlElement *c = new TiXmlElement( "Sight" ); Sight *s = (Sight*)wxUIntToPtr(m_lSights->GetItemData(i)); c->SetAttribute("Visible", s->m_bVisible); c->SetAttribute("Type", s->m_Type); c->SetAttribute("Body", s->m_Body.mb_str()); c->SetAttribute("BodyLimb", s->m_BodyLimb); c->SetAttribute("Date", s->m_DateTime.FormatISODate().mb_str()); c->SetAttribute("Time", s->m_DateTime.FormatISOTime().mb_str()); c->SetDoubleAttribute("TimeCertainty", s->m_TimeCertainty); c->SetDoubleAttribute("Measurement", s->m_Measurement); c->SetDoubleAttribute("MeasurementCertainty", s->m_MeasurementCertainty); c->SetDoubleAttribute("EyeHeight", s->m_EyeHeight); c->SetDoubleAttribute("Temperature", s->m_Temperature); c->SetDoubleAttribute("Pressure", s->m_Pressure); c->SetDoubleAttribute("IndexError", s->m_IndexError); c->SetDoubleAttribute("ShiftNm", s->m_ShiftNm); c->SetDoubleAttribute("ShiftBearing", s->m_ShiftBearing); c->SetDoubleAttribute("MagneticShiftBearing", s->m_bMagneticShiftBearing); c->SetAttribute("ColourName", s->m_ColourName.mb_str()); c->SetAttribute("Colour", s->m_Colour.GetAsString().mb_str()); c->SetAttribute("Transparency", s->m_Colour.Alpha()); root->LinkEndChild(c); } if(!doc.SaveFile(filename.mb_str())) { wxMessageDialog mdlg(this, _("Failed to save xml file: ") + filename, _("Celestial Navigation"), wxOK | wxICON_ERROR); mdlg.ShowModal(); } }
void CelestialNavigationDialog::OnDeleteAll(wxCommandEvent &event) { wxMessageDialog mdlg(this, _("Are you sure you want to delete all sights?"), _("Celestial Navigation"), wxYES_NO); if(mdlg.ShowModal() == wxID_YES) { m_lSights->DeleteAllItems(); RequestRefresh( GetParent() ); } }
void ConfigurationDialog::SetStartDateTime(wxDateTime datetime) { if(datetime.IsValid()) { m_dpStartDate->SetValue(datetime); m_tStartHour->SetValue(wxString::Format(_T("%.3f"), datetime.GetHour() +datetime.GetMinute() / 60.0)); } else { wxMessageDialog mdlg(this, _("Invalid Date Time."), wxString(_("Weather Routing"), wxOK | wxICON_WARNING)); mdlg.ShowModal(); } }
void WeatherRouting::GenerateBatch() { RouteMapOverlay *routemapoverlay = CurrentRouteMap(true); if(!routemapoverlay) { wxMessageDialog mdlg(this, _("Must select a configuration to generate from"), _("Weather Routing"), wxOK | wxICON_ERROR); mdlg.ShowModal(); return; } RouteMapConfiguration configuration = routemapoverlay->GetConfiguration(); ConfigurationBatchDialog &dlg = m_ConfigurationBatchDialog; wxTimeSpan StartSpan, StartSpacingSpan; double days, hours; dlg.m_tStartDays->GetValue().ToDouble(&days); StartSpan = wxTimeSpan::Days(days); dlg.m_tStartHours->GetValue().ToDouble(&hours); StartSpan += wxTimeSpan::Hours(hours); dlg.m_tStartSpacingDays->GetValue().ToDouble(&days); StartSpacingSpan = wxTimeSpan::Days(days); dlg.m_tStartSpacingHours->GetValue().ToDouble(&hours); StartSpacingSpan += wxTimeSpan::Hours(hours); wxDateTime EndTime = configuration.StartTime+StartSpan; for(; configuration.StartTime <= EndTime; configuration.StartTime += StartSpacingSpan) { for(std::vector<BatchSource*>::iterator it = dlg.sources.begin(); it != dlg.sources.end(); it++) { configuration.Start = (*it)->Name; for(std::list<BatchDestination*>::iterator it2 = (*it)->destinations.begin(); it2 != (*it)->destinations.end(); it2++) { configuration.End = (*it2)->Name; for(unsigned int boatindex = 0; boatindex < dlg.m_lBoats->GetCount(); boatindex++) { configuration.boatFileName = dlg.m_lBoats->GetString(boatindex); AddConfiguration(configuration); } } } } DeleteRouteMap(routemapoverlay); }
void iMenuView::Start() { while (1) { iMainMenuDlg mdlg(&gApp.ViewMgr()); sint32 res = mdlg.DoModal(); if (res == 100) { // Start new game iScenListDlg sldlg(&gApp.ViewMgr()); res = sldlg.DoModal(); if (res == DRC_OK) { iMapInfo scenProps = sldlg.SelScen(); iScenPropsDlg spdlg(&gApp.ViewMgr(), scenProps, false); if (spdlg.DoModal() == DRC_OK) { scenProps.ReorderPlayers(); gGame.StartNewGame(scenProps, true); break; } } else { continue; } } else if (res == 101) { // Load saved game iSaveDlg saveDlg(&gApp.ViewMgr(), false); res = saveDlg.DoModal(); if (res == DRC_OK) { iMapInfo scenProps = saveDlg.SelScenario(); iScenPropsDlg spdlg(&gApp.ViewMgr(), scenProps, true); if (spdlg.DoModal() == DRC_OK) { scenProps.ReorderPlayers(); gGame.StartNewGame(scenProps, false); break; } } else { continue; } } else if (res == 102) { iDlg_HallOfFame dlg(&gApp.ViewMgr(), gRootPath + _T("PalmHeroes.hsc")); dlg.DoModal(); } else if (res == 103) { StartCredits(); break; } else if (res == 104) { // Quit to WM200x gGame.Quit(); break; } } }
void ConfigurationDialog::SetStartDateTime(wxDateTime datetime) { if(datetime.IsValid()) { if(m_WeatherRouting.m_SettingsDialog.m_cbUseLocalTime->GetValue()) datetime = datetime.FromUTC(); m_dpStartDate->SetValue(datetime); m_tpTime->SetValue(datetime); m_edited_controls.push_back(m_tpTime); m_edited_controls.push_back(m_dpStartDate); } else { wxMessageDialog mdlg(this, _("Invalid Date Time."), wxString(_("Weather Routing"), wxOK | wxICON_WARNING)); mdlg.ShowModal(); } }
void WeatherRouting::Start(RouteMapOverlay *routemapoverlay) { if(!routemapoverlay || (routemapoverlay->Finished() && !routemapoverlay->GribFailed() && !routemapoverlay->ClimatologyFailed())) return; wxString error = routemapoverlay->Reset(); if(error.empty()) m_WaitingRouteMaps.push_back(routemapoverlay); else { wxMessageDialog mdlg(this, error, _("Weather Routing"), wxOK | wxICON_ERROR); mdlg.ShowModal(); } }
RouteMapOverlay *WeatherRouting::CurrentRouteMap(bool messagedialog) { long index = m_lWeatherRoutes->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); RouteMapOverlay *routemapoverlay = NULL; if (index >= 0) routemapoverlay = reinterpret_cast<WeatherRoute*> (wxUIntToPtr(m_lWeatherRoutes->GetItemData(index)))->routemapoverlay; if(messagedialog && !routemapoverlay) { wxMessageDialog mdlg(this, _("No Weather Route selected"), _("Weather Routing"), wxOK | wxICON_WARNING); mdlg.ShowModal(); } return routemapoverlay; }
void CMainFrame::OnTriangle(wxCommandEvent& event) { wxString strs8[] = { wxT("triangle 1"), wxT("triangle 2")}; ManagementDialog mdlg(m_toolbar, -1, wxT("Gestion de triangles")); //Suppression des éléments de la liste mdlg.list->Clear(); //Ajout de triangle 1 et 2 mdlg.list->Append(strs8[0]); mdlg.list->Append(strs8[1]); mdlg.list->SetSelection(1); //Affichage mdlg.ShowModal(); }
void WeatherRouting::OnInformation ( wxCommandEvent& event ) { InformationDialog dlg(GetParent()); #ifdef __WXOSX__ wxStandardPathsBase& std_path = wxStandardPathsBase::Get(); wxString infolocation = std_path.GetUserConfigDir() + _("/opencpn/plugins/weather_routing/data/WeatherRoutingInformation.html"); #else wxString infolocation = *GetpSharedDataLocation() + _("plugins/weather_routing_pi/data/WeatherRoutingInformation.html"); #endif if(dlg.m_htmlInformation->LoadFile(infolocation)) dlg.ShowModal(); else { wxMessageDialog mdlg(this, _("Failed to load file:\n") + infolocation, _("Weather Routing"), wxOK | wxICON_ERROR); mdlg.ShowModal(); } }
void InternetRetrievalDialog::OnUrlsSort( wxListEvent& event ) { sortcol = event.GetColumn(); sortorder = -sortorder; if(sortcol == 0) { for(int i=0; i < m_lUrls->GetItemCount(); i++) { FaxUrl *faxurl = reinterpret_cast<FaxUrl*> (wxUIntToPtr(m_lUrls->GetItemData(i))); faxurl->Scheduled = sortorder == 1; UpdateItem(i); } } else if(m_lUrls->GetItemCount() > 500) { wxMessageDialog mdlg(this, _("Sorting this many urls might take too long"), _("weatherfax"), wxOK | wxICON_ERROR); mdlg.ShowModal(); } else m_lUrls->SortItems(SortUrl, (long)m_lUrls); }
void ConfigurationDialog::OnGenerateDegreeSteps( wxCommandEvent& event ) { double from, to, by; m_tFromDegrees->GetValue().ToDouble(&from); m_tToDegrees->GetValue().ToDouble(&to); m_tByDegrees->GetValue().ToDouble(&by); if(from < 0 || from >= 180 || to <= 0 || to > 180 || from >= to || by <= 0 || by >= 180) { wxMessageDialog mdlg(this, _("Invalid settings, nothing will be done."), wxString(_("Weather Routing"), wxOK | wxICON_WARNING)); mdlg.ShowModal(); return; } m_lDegreeSteps->Clear(); for(double v = from; v <= to; v+=by) { m_lDegreeSteps->Append(wxString::Format(_T("%.1f"), v)); m_lDegreeSteps->Append(wxString::Format(_T("%.1f"), -v)); } Update(); }
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); }
void SettingsDialog::OnHelp( wxCommandEvent& event ) { wxMessageDialog mdlg(this, _("help text goes here"), _("Weather Routing"), wxOK | wxICON_INFORMATION); mdlg.ShowModal(); }
void WeatherRouting::SaveXML(wxString filename) { TiXmlDocument doc; TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "utf-8", "" ); doc.LinkEndChild( decl ); TiXmlElement * root = new TiXmlElement( "OpenCPNWeatherRoutingConfiguration" ); doc.LinkEndChild( root ); char version[24]; sprintf(version, "%d.%d", PLUGIN_VERSION_MAJOR, PLUGIN_VERSION_MINOR); root->SetAttribute("version", version); root->SetAttribute("creator", "Opencpn Weather Routing plugin"); for(std::list<RouteMapPosition>::iterator it = RouteMap::Positions.begin(); it != RouteMap::Positions.end(); it++) { TiXmlElement *c = new TiXmlElement( "Position" ); c->SetAttribute("Name", (*it).Name.mb_str()); c->SetAttribute("Latitude", wxString::Format(_T("%.5f"), (*it).lat).mb_str()); c->SetAttribute("Longitude", wxString::Format(_T("%.5f"), (*it).lon).mb_str()); root->LinkEndChild(c); } for(std::list<WeatherRoute*>::iterator it = m_WeatherRoutes.begin(); it != m_WeatherRoutes.end(); it++) { TiXmlElement *c = new TiXmlElement( "Configuration" ); RouteMapConfiguration configuration = (*it)->routemapoverlay->GetConfiguration(); c->SetAttribute("Start", configuration.Start.mb_str()); c->SetAttribute("StartDate", configuration.StartTime.FormatDate().mb_str()); c->SetAttribute("StartTime", configuration.StartTime.FormatTime().mb_str()); c->SetAttribute("End", configuration.End.mb_str()); c->SetAttribute("dt", configuration.dt); c->SetAttribute("Boat", configuration.boatFileName.ToUTF8()); c->SetAttribute("MaxDivertedCourse", configuration.MaxDivertedCourse); c->SetAttribute("MaxWindKnots", configuration.MaxWindKnots); c->SetAttribute("MaxSwellMeters", configuration.MaxSwellMeters); c->SetAttribute("MaxLatitude", configuration.MaxLatitude); c->SetAttribute("MaxTacks", configuration.MaxTacks); c->SetAttribute("TackingTime", configuration.TackingTime); c->SetAttribute("UseGrib", configuration.UseGrib); c->SetAttribute("UseClimatology", configuration.UseClimatology); c->SetAttribute("AllowDataDeficient", configuration.AllowDataDeficient); c->SetAttribute("DetectLand", configuration.DetectLand); c->SetAttribute("Currents", configuration.Currents); c->SetAttribute("InvertedRegions", configuration.InvertedRegions); c->SetAttribute("Anchoring", configuration.Anchoring); wxString degreesteps; for(std::list<double>::iterator it = configuration.DegreeSteps.begin(); it != configuration.DegreeSteps.end(); it++) degreesteps += wxString::Format(_T("%.1f;"), *it); c->SetAttribute("DegreeSteps", degreesteps.mb_str()); root->LinkEndChild(c); } if(!doc.SaveFile(filename.mb_str())) { wxMessageDialog mdlg(this, _("Failed to save xml file: ") + filename, _("Weather Routing"), wxOK | wxICON_ERROR); mdlg.ShowModal(); } }
bool InternetRetrievalDialog::OpenXML(wxString filename) { ClearInternetRetrieval(); m_lServers->Clear(); TiXmlDocument doc; wxString error; wxProgressDialog *progressdialog = NULL; // wxDateTime start = wxDateTime::Now(); if(!doc.LoadFile(filename.mb_str())) FAIL(_("Failed to load file: ") + filename); else { TiXmlElement *root = doc.RootElement(); if(strcmp(root->Value(), "OCPNWeatherFaxInternetRetrieval")) FAIL(_("Invalid xml file")); int count = 0; for(TiXmlElement* e = root->FirstChildElement(); e; e = e->NextSiblingElement()) count++; int i=0; for(TiXmlElement* e = root->FirstChildElement(); e; e = e->NextSiblingElement(), i++) { if(progressdialog) { if(!progressdialog->Update(i)) return true; } else { // wxDateTime now = wxDateTime::Now(); if(1/*(now-start).GetMilliseconds() > 1000 && i < count/2*/) { progressdialog = new wxProgressDialog( _("WeatherFax InternetRetrieval"), _("Loading"), count, this, wxPD_CAN_ABORT | wxPD_ELAPSED_TIME | wxPD_REMAINING_TIME); } } if(!strcmp(e->Value(), "Server")) { wxString server = wxString::FromUTF8(e->Attribute("Name")); m_lServers->Append(server); std::list<FaxUrl> urls; std::list<FaxArea> Areas; for(TiXmlElement* f = e->FirstChildElement(); f; f = f->NextSiblingElement()) { if(!strcmp(f->Value(), "Map")) { FaxUrl url; url.Selected = false; url.Server = server; url.Url = wxString::FromUTF8(f->Attribute("Url")); url.Contents = wxString::FromUTF8(f->Attribute("Contents")); urls.push_back(url); } else if(!strcmp(f->Value(), "Area")) { FaxArea Area; Area.name = wxString::FromUTF8(f->Attribute("Name")); Area.description = wxString::FromUTF8(f->Attribute("Description")); Area.lat1 = ParseLatLon(wxString::FromUTF8(f->Attribute("lat1"))); Area.lat2 = ParseLatLon(wxString::FromUTF8(f->Attribute("lat2"))); Area.lon1 = ParseLatLon(wxString::FromUTF8(f->Attribute("lon1"))); Area.lon2 = ParseLatLon(wxString::FromUTF8(f->Attribute("lon2"))); Areas.push_back(Area); } else FAIL(_("Unrecognized xml node")); } for(std::list<FaxUrl>::iterator it = urls.begin(); it != urls.end(); it++) { if((*it).area_name.size()) { for(std::list<FaxArea>::iterator it2 = Areas.begin(); it2 != Areas.end(); it2++) if((*it).area_name == (*it2).name) { (*it).Area = *it2; goto resolved; } FAIL(_("Failed to match Area: ") + (*it).area_name); } resolved: FaxUrl *s = new FaxUrl(*it); m_InternetRetrieval.push_back(s); } } else FAIL(_("Unrecognized xml node")); } } delete progressdialog; return true; failed: delete progressdialog; wxMessageDialog mdlg(this, error, _("Weather Fax"), wxOK | wxICON_ERROR); mdlg.ShowModal(); return false; }
void ConfigurationDialog::Update() { if(m_bBlockUpdate) return; bool refresh = false; RouteMapConfiguration configuration; std::list<RouteMapOverlay*> currentroutemaps = m_WeatherRouting.CurrentRouteMaps(); for(std::list<RouteMapOverlay*>::iterator it = currentroutemaps.begin(); it != currentroutemaps.end(); it++) { configuration = (*it)->GetConfiguration(); GET_CHOICE(Start); GET_CHOICE(End); if(NO_EDITED_CONTROLS || std::find(m_edited_controls.begin(), m_edited_controls.end(), (wxObject*)m_dpStartDate) != m_edited_controls.end()) { if(!m_dpStartDate->GetDateCtrlValue().IsValid()) continue; // We must preserve the time in case only date but not time, is being changed by the user... // configuration.StartTime is UTC, m_dpStartDate Local or UTC so adjust wxDateTime time = configuration.StartTime; if(m_WeatherRouting.m_SettingsDialog.m_cbUseLocalTime->GetValue()) time = time.FromUTC(); wxDateTime date = m_dpStartDate->GetDateCtrlValue(); // ... and add it afterwards date.SetHour(time.GetHour()); date.SetMinute(time.GetMinute()); date.SetSecond(time.GetSecond()); if(m_WeatherRouting.m_SettingsDialog.m_cbUseLocalTime->GetValue()) date = date.ToUTC(); configuration.StartTime = date; m_dpStartDate->SetForegroundColour(wxColour(0, 0, 0)); } if(NO_EDITED_CONTROLS || std::find(m_edited_controls.begin(), m_edited_controls.end(), (wxObject*)m_tpTime) != m_edited_controls.end()) { // must use correct data on UTC conversion to preserve Daylight Savings Time changes across dates wxDateTime time = configuration.StartTime; if(m_WeatherRouting.m_SettingsDialog.m_cbUseLocalTime->GetValue()) time = time.FromUTC(); time.SetHour(m_tpTime->GetTimeCtrlValue().GetHour()); time.SetMinute(m_tpTime->GetTimeCtrlValue().GetMinute()); time.SetSecond(m_tpTime->GetTimeCtrlValue().GetSecond()); if(m_WeatherRouting.m_SettingsDialog.m_cbUseLocalTime->GetValue()) time = time.ToUTC(); configuration.StartTime = time; m_tpTime->SetForegroundColour(wxColour(0, 0, 0)); } if(!m_tBoat->GetValue().empty()) { configuration.boatFileName = m_tBoat->GetValue(); m_tBoat->SetForegroundColour(wxColour(0, 0, 0)); } if(NO_EDITED_CONTROLS || std::find(m_edited_controls.begin(), m_edited_controls.end(), (wxObject*)m_sTimeStepHours) != m_edited_controls.end() || std::find(m_edited_controls.begin(), m_edited_controls.end(), (wxObject*)m_sTimeStepMinutes) != m_edited_controls.end() || std::find(m_edited_controls.begin(), m_edited_controls.end(), (wxObject*)m_sTimeStepSeconds) != m_edited_controls.end()) { configuration.DeltaTime = 60*(60*m_sTimeStepHours->GetValue() + m_sTimeStepMinutes->GetValue()) + m_sTimeStepSeconds->GetValue(); m_sTimeStepHours->SetForegroundColour(wxColour(0, 0, 0)); m_sTimeStepMinutes->SetForegroundColour(wxColour(0, 0, 0)); m_sTimeStepSeconds->SetForegroundColour(wxColour(0, 0, 0)); } if(m_cIntegrator->GetValue() == _T("Newton")) configuration.Integrator = RouteMapConfiguration::NEWTON; else if(m_cIntegrator->GetValue() == _T("Runge Kutta")) configuration.Integrator = RouteMapConfiguration::RUNGE_KUTTA; GET_SPIN(MaxDivertedCourse); GET_SPIN(MaxCourseAngle); GET_SPIN(MaxSearchAngle); GET_SPIN(MaxTrueWindKnots); GET_SPIN(MaxApparentWindKnots); GET_SPIN(MaxSwellMeters); GET_SPIN(MaxLatitude); GET_SPIN(TackingTime); GET_SPIN(WindVSCurrent); GET_CHECKBOX(AvoidCycloneTracks); GET_SPIN(CycloneMonths); GET_SPIN(CycloneDays); GET_SPIN(SafetyMarginLand); GET_CHECKBOX(DetectLand); GET_CHECKBOX(DetectBoundary); GET_CHECKBOX(Currents); GET_CHECKBOX(OptimizeTacking); GET_CHECKBOX(InvertedRegions); GET_CHECKBOX(Anchoring); GET_CHECKBOX(UseGrib); if(m_cClimatologyType->GetSelection() != -1) configuration.ClimatologyType = (RouteMapConfiguration::ClimatologyDataType) m_cClimatologyType->GetSelection(); GET_CHECKBOX(AllowDataDeficient); if(m_sWindStrength->IsEnabled()) \ configuration.WindStrength = m_sWindStrength->GetValue() / 100.0; GET_SPIN(FromDegree); GET_SPIN(ToDegree); if(!m_tByDegrees->GetValue().empty()) m_tByDegrees->GetValue().ToDouble(&configuration.ByDegrees); (*it)->SetConfiguration(configuration); /* if the start position changed, we must reset the route */ RouteMapConfiguration newc = (*it)->GetConfiguration(); if(newc.StartLat != configuration.StartLat || newc.StartLon != configuration.StartLon) { (*it)->Reset(); refresh = true; } else if(newc.EndLat != configuration.EndLat || newc.EndLon != configuration.EndLon) refresh = true; // update drawing } double by; m_tByDegrees->GetValue().ToDouble(&by); if(m_sToDegree->GetValue() - m_sFromDegree->GetValue() < 2*by) { wxMessageDialog mdlg(this, _("Warning: less than 4 different degree steps specified\n"), wxString(_("Weather Routing"), wxOK | wxICON_WARNING)); mdlg.ShowModal(); } m_WeatherRouting.UpdateCurrentConfigurations(); if(refresh) m_WeatherRouting.GetParent()->Refresh(); }
bool WeatherRouting::OpenXML(wxString filename, bool reportfailure) { TiXmlDocument doc; wxString error; wxFileName fn(filename); SetTitle(_("Weather Routing") + wxString(_T(" - ")) + fn.GetFullName()); wxProgressDialog *progressdialog = NULL; wxDateTime start = wxDateTime::Now(); if(!doc.LoadFile(filename.mb_str())) FAIL(_("Failed to load file.")); else { TiXmlHandle root(doc.RootElement()); if(strcmp(root.Element()->Value(), "OpenCPNWeatherRoutingConfiguration")) FAIL(_("Invalid xml file")); RouteMap::Positions.clear(); int count = 0; for(TiXmlElement* e = root.FirstChild().Element(); e; e = e->NextSiblingElement()) count++; int i=0; for(TiXmlElement* e = root.FirstChild().Element(); e; e = e->NextSiblingElement(), i++) { if(progressdialog) { if(!progressdialog->Update(i)) return true; } else { wxDateTime now = wxDateTime::Now(); /* if it's going to take more than a half second, show a progress dialog */ if((now-start).GetMilliseconds() > 250 && i < count/2) { progressdialog = new wxProgressDialog( _("Load"), _("Weather Routing"), count, this, wxPD_CAN_ABORT | wxPD_ELAPSED_TIME | wxPD_REMAINING_TIME); } } if(!strcmp(e->Value(), "Position")) { wxString name = wxString::FromUTF8(e->Attribute("Name")); double lat = AttributeDouble(e, "Latitude", NAN); double lon = AttributeDouble(e, "Longitude", NAN); for(std::list<RouteMapPosition>::iterator it = RouteMap::Positions.begin(); it != RouteMap::Positions.end(); it++) { if((*it).Name == name) { static bool warnonce = true; if(warnonce) { warnonce = false; wxMessageDialog mdlg(this, _("File contains duplicate position name, discaring\n"), _("Weather Routing"), wxOK | wxICON_WARNING); mdlg.ShowModal(); } goto skipadd; } } AddPosition(lat, lon, name); } else skipadd: if(!strcmp(e->Value(), "Configuration")) { RouteMapConfiguration configuration; configuration.Start = wxString::FromUTF8(e->Attribute("Start")); wxDateTime date; date.ParseDate(wxString::FromUTF8(e->Attribute("StartDate"))); wxDateTime time; time.ParseTime(wxString::FromUTF8(e->Attribute("StartTime"))); if(date.IsValid()) { if(time.IsValid()) { date.SetHour(time.GetHour()); date.SetMinute(time.GetMinute()); date.SetSecond(time.GetSecond()); } configuration.StartTime = date; } else configuration.StartTime = wxDateTime::Now(); configuration.End = wxString::FromUTF8(e->Attribute("End")); configuration.dt = AttributeDouble(e, "dt", 0); configuration.boatFileName = wxString::FromUTF8(e->Attribute("Boat")); configuration.MaxDivertedCourse = AttributeDouble(e, "MaxDivertedCourse", 180); configuration.MaxWindKnots = AttributeDouble(e, "MaxWindKnots", 100); configuration.MaxSwellMeters = AttributeDouble(e, "MaxSwellMeters", 20); configuration.MaxLatitude = AttributeDouble(e, "MaxLatitude", 90); configuration.MaxTacks = AttributeDouble(e, "MaxTacks", -1); configuration.TackingTime = AttributeDouble(e, "TackingTime", 0); configuration.UseGrib = AttributeBool(e, "UseGrib", true); configuration.UseClimatology = AttributeBool(e, "UseClimatology", true); configuration.AllowDataDeficient = AttributeBool(e, "AllowDataDeficient", false); configuration.DetectLand = AttributeBool(e, "DetectLand", true); configuration.Currents = AttributeBool(e, "Currents", true); configuration.InvertedRegions = AttributeBool(e, "InvertedRegions", false); configuration.Anchoring = AttributeBool(e, "Anchoring", false); wxString degreesteps = wxString::FromUTF8(e->Attribute("DegreeSteps")); while(degreesteps.size()) { double step; if(degreesteps.BeforeFirst(';').ToDouble(&step)) configuration.DegreeSteps.push_back(step); degreesteps = degreesteps.AfterFirst(';'); } configuration.StartTime = date; } else FAIL(_("Unrecognized xml node")); } } delete progressdialog; return true; failed: if(reportfailure) { wxMessageDialog mdlg(this, error, _("Weather Routing"), wxOK | wxICON_ERROR); mdlg.ShowModal(); } return false; }
bool Dlg::OpenXML() { Position my_position; my_positions.clear(); int response = wxID_CANCEL; int my_count = 0; wxArrayString file_array; wxString filename; wxFileDialog openDialog( this, _( "Import GPX Route file" ), m_gpx_path, wxT ( "" ), wxT ( "GPX files (*.gpx)|*.gpx|All files (*.*)|*.*" ), wxFD_OPEN | wxFD_MULTIPLE ); response = openDialog.ShowModal(); if( response == wxID_OK ) { openDialog.GetPaths( file_array ); // Record the currently selected directory for later use if( file_array.GetCount() ) { wxFileName fn( file_array[0] ); filename = file_array[0]; m_gpx_path = fn.GetPath(); } } else if(response = wxID_CANCEL){ return false; } TiXmlDocument doc; wxString error; wxProgressDialog *progressdialog = NULL; if(!doc.LoadFile(filename.mb_str())){ FAIL(_("Failed to load file: ") + filename); } else { TiXmlElement *root = doc.RootElement(); if(!strcmp(root->Value(), "rte")) FAIL(_("rte Invalid xml file")); int count = 0; for(TiXmlElement* e = root->FirstChildElement(); e; e = e->NextSiblingElement()) count++; int i=0; for(TiXmlElement* e = root->FirstChildElement(); e; e = e->NextSiblingElement(), i++) { if(progressdialog) { if(!progressdialog->Update(i)) return true; } else { if(1) { progressdialog = new wxProgressDialog( _("Route"), _("Loading"), count, this, wxPD_CAN_ABORT | wxPD_ELAPSED_TIME | wxPD_REMAINING_TIME); } } for(TiXmlElement* f = e->FirstChildElement(); f; f = f->NextSiblingElement()) { if(!strcmp(f->Value(), "rtept")) { wxString rte_lat = wxString::FromUTF8(f->Attribute("lat")); wxString rte_lon = wxString::FromUTF8(f->Attribute("lon")); my_position.lat = rte_lat; my_position.lon = rte_lon; my_positions.push_back(my_position); } //else if(!strcmp(f->Value(), "extensions")) { //rte_start = wxString::FromUTF8(f->Attribute("opencpn:start")); //rte_end = wxString::FromUTF8(f->Attribute("opencpn:end")); //} } } } delete progressdialog; return true; failed: delete progressdialog; wxMessageDialog mdlg(this, error, _("DR"), wxOK | wxICON_ERROR); mdlg.ShowModal(); return false; }
bool InternetRetrievalDialog::OpenXML(wxString filename) { ClearInternetRetrieval(); m_lServers->Clear(); TiXmlDocument doc; wxString error; wxProgressDialog *progressdialog = NULL; wxDateTime start = wxDateTime::UNow(); if(!doc.LoadFile(filename.mb_str())) FAIL(_("Failed to load file: ") + filename); else { TiXmlElement *root = doc.RootElement(); if(strcmp(root->Value(), "OCPNWeatherFaxInternetRetrieval")) FAIL(_("Invalid xml file")); int count = 0; for(TiXmlElement* e = root->FirstChildElement(); e; e = e->NextSiblingElement()) count++; int i=0; for(TiXmlElement* e = root->FirstChildElement(); e; e = e->NextSiblingElement(), i++) { if(progressdialog) { if(!progressdialog->Update(i)) return true; } else { wxDateTime now = wxDateTime::UNow(); if((now-start).GetMilliseconds() > 500 && i < count/3) { progressdialog = new wxProgressDialog( _("WeatherFax Internet Retrieval"), _("Loading"), count, this, wxPD_CAN_ABORT | wxPD_ELAPSED_TIME | wxPD_REMAINING_TIME); } } if(!strcmp(e->Value(), "Server")) { FaxServer server; server.Name = wxString::FromUTF8(e->Attribute("Name")); m_Servers.push_back(server); wxString server_url = wxString::FromUTF8(e->Attribute("Url")); m_lServers->Append(server.Name); for(TiXmlElement* f = e->FirstChildElement(); f; f = f->NextSiblingElement()) { if(!strcmp(f->Value(), "Region")) { FaxRegion region; region.Name = wxString::FromUTF8(f->Attribute("Name")); region.Server = server.Name; for(std::list<FaxRegion>::iterator it = m_Regions.begin(); it != m_Regions.end(); it++) if(it->Name == region.Name && it->Server == region.Server) goto duplicate_region; m_Regions.push_back(region); duplicate_region: wxString region_url = server_url + wxString::FromUTF8(f->Attribute("Url")); std::list<FaxUrl> urls; std::list<FaxArea> Areas; for(TiXmlElement* g = f->FirstChildElement(); g; g = g->NextSiblingElement()) { if(!strcmp(g->Value(), "Iterator")) { wxString s_start = wxString::FromUTF8(g->Attribute("From")); wxString s_to = wxString::FromUTF8(g->Attribute("To")); wxString s_by = wxString::FromUTF8(g->Attribute("By")); if(s_start.size() == 0 || s_to.size() == 0 || s_by.size() == 0) FAIL(_("Invalid iterator: ") + wxString::FromUTF8(g->Value())); long start, to, by; s_start.ToLong(&start); s_to.ToLong(&to); s_by.ToLong(&by); for(TiXmlElement* h = g->FirstChildElement(); h; h = h->NextSiblingElement()) { if(!strcmp(h->Value(), "Map")) { FaxUrl url; url.Scheduled = false; url.Server = server.Name; url.Region = region.Name; for(int index = start; index <= to; index += by) { wxString iurl = wxString::FromUTF8(h->Attribute("Url")); url.Url = region_url + wxString::Format (iurl, index); url.Contents = wxString::Format (wxString::FromUTF8(h->Attribute("Contents")), index); url.area_name = wxString::FromUTF8(h->Attribute("Area")); urls.push_back(url); } } else FAIL(_("Unrecognized xml node: ") + wxString::FromUTF8(g->Value())); } } else if(!strcmp(g->Value(), "Map")) { FaxUrl url; url.Scheduled = false; url.Server = server.Name; url.Region = region.Name; url.Url = region_url + wxString::FromUTF8(g->Attribute("Url")); url.Contents = wxString::FromUTF8(g->Attribute("Contents")); url.area_name = wxString::FromUTF8(g->Attribute("Area")); urls.push_back(url); } else if(!strcmp(g->Value(), "Area")) { FaxArea Area; Area.name = wxString::FromUTF8(g->Attribute("Name")); Area.description = wxString::FromUTF8(g->Attribute("Description")); Area.lat1 = ParseLatLon(wxString::FromUTF8(g->Attribute("lat1"))); Area.lat2 = ParseLatLon(wxString::FromUTF8(g->Attribute("lat2"))); Area.lon1 = ParseLatLon(wxString::FromUTF8(g->Attribute("lon1"))); Area.lon2 = ParseLatLon(wxString::FromUTF8(g->Attribute("lon2"))); Areas.push_back(Area); } else FAIL(_("Unrecognized xml node: ") + wxString::FromUTF8(g->Value())); } for(std::list<FaxUrl>::iterator it = urls.begin(); it != urls.end(); it++) { if((*it).area_name.size()) { for(std::list<FaxArea>::iterator it2 = Areas.begin(); it2 != Areas.end(); it2++) if((*it).area_name == (*it2).name) { (*it).Area = *it2; goto resolved; } FAIL(_("Failed to match Area: ") + (*it).area_name); } resolved: FaxUrl *s = new FaxUrl(*it); m_InternetRetrieval.push_back(s); } } else FAIL(_("Unrecognized xml node: ") + wxString::FromUTF8(f->Value())); } } else FAIL(_("Unrecognized xml node: ") + wxString::FromUTF8(e->Value())); } } delete progressdialog; return true; failed: delete progressdialog; wxMessageDialog mdlg(this, error, _("Weather Fax"), wxOK | wxICON_ERROR); mdlg.ShowModal(); return false; }
CelestialNavigationDialog::CelestialNavigationDialog(wxWindow *parent) : CelestialNavigationDialogBase(parent), m_FixDialog(this), m_ClockCorrectionDialog(this) { wxFileConfig *pConf = GetOCPNConfigObject(); pConf->SetPath( _T("/PlugIns/CelestialNavigation") ); //#ifdef __WXGTK__ // Move(0, 0); // workaround for gtk autocentre dialog behavior //#endif // Move(pConf->Read ( _T ( "DialogPosX" ), 20L ), pConf->Read ( _T ( "DialogPosY" ), 20L )); wxPoint p = GetPosition(); pConf->Read ( _T ( "DialogX" ), &p.x, p.x); pConf->Read ( _T ( "DialogY" ), &p.y, p.y); SetPosition(p); wxSize s = GetSize(); pConf->Read ( _T ( "DialogWidth" ), &s.x, s.x); pConf->Read ( _T ( "DialogHeight" ), &s.y, s.y); SetSize(s); // create a image list for the list with just the eye icon wxImageList *imglist = new wxImageList(20, 20, true, 1); imglist->Add(wxBitmap(eye)); m_lSights->AssignImageList(imglist, wxIMAGE_LIST_SMALL); m_lSights->InsertColumn(rmVISIBLE, wxT("")); m_lSights->SetColumnWidth(0, 28); m_lSights->InsertColumn(rmTYPE, _("Type")); m_lSights->InsertColumn(rmBODY, _("Body")); m_lSights->InsertColumn(rmTIME, _("Time (UT)")); m_lSights->InsertColumn(rmMEASUREMENT, _("Measurement")); m_lSights->InsertColumn(rmCOLOR, _("Color")); m_sights_path = celestial_navigation_pi::StandardPath() + _T("Sights.xml"); if(!OpenXML(m_sights_path, false)) { /* create directory for plugin files if it doesn't already exist */ wxFileName fn(m_sights_path); wxFileName fn2 = fn.GetPath(); if(!fn.DirExists()) { fn2.Mkdir(); fn.Mkdir(); } } wxString filename = DataDirectory() + "vsop87d.txt"; wxFileName fn(filename); if(!fn.Exists()) filename = UserDataDirectory() + "vsop87d.txt"; astrolabe::globals::vsop87d_text_path = (const char *)filename.mb_str(); #ifndef WIN32 // never hit because data is distribued easier to not compile compression support wxMessageDialog mdlg(this, _("Astrolab data unavailable.\n") + _("\nWould you like to download?"), _("Failure Alert"), wxYES | wxNO | wxICON_ERROR); if(mdlg.ShowModal() == wxID_YES) { wxString url = "https://cfhcable.dl.sourceforge.net/project/opencpnplugins/celestial_navigation_pi/"; wxString path = UserDataDirectory(); wxString fn = "vsop87d.txt.gz"; _OCPN_DLStatus status = OCPN_downloadFile( url+fn, path+fn, _("downloading celestial navigation data file"), "downloading...", *_img_celestial_navigation, this, OCPN_DLDS_CAN_ABORT|OCPN_DLDS_ELAPSED_TIME|OCPN_DLDS_ESTIMATED_TIME|OCPN_DLDS_REMAINING_TIME|OCPN_DLDS_SPEED|OCPN_DLDS_SIZE|OCPN_DLDS_URL|OCPN_DLDS_AUTO_CLOSE, 20); if(status == OCPN_DL_NO_ERROR) { // now decompress downloaded file ZUFILE *f = zu_open(path+fn.mb_str(), "rb", ZU_COMPRESS_AUTO); if(f) { FILE *out = fopen(path+"vsop87d.txt", "w"); if(out) { char buf[1024]; for(;;) { size_t size = zu_read(f, buf, sizeof buf); fwrite(buf, size, 1, out); if(size != sizeof buf) break; } fclose(out); } zu_close(f); } } } #endif #ifdef __OCPN__ANDROID__ GetHandle()->setStyleSheet( qtStyleSheet); Move(0, 0); #endif }
bool CelestialNavigationDialog::OpenXML(wxString filename, bool reportfailure) { TiXmlDocument doc; wxString error; wxFileName fn(filename); if(!doc.LoadFile(filename.mb_str())) FAIL(_("Failed to load file: ") + filename); else { TiXmlHandle root(doc.RootElement()); if(strcmp(root.Element()->Value(), "OpenCPNCelestialNavigation")) FAIL(_("Invalid xml file")); m_lSights->DeleteAllItems(); for(TiXmlElement* e = root.FirstChild().Element(); e; e = e->NextSiblingElement()) { if(!strcmp(e->Value(), "ClockError")) { m_ClockCorrectionDialog.m_sClockCorrection->SetValue(AttributeInt(e, "Seconds", 0)); } else if(!strcmp(e->Value(), "Sight")) { Sight s; s.m_bVisible = AttributeBool(e, "Visible", true); s.m_Type = (Sight::Type)AttributeInt(e, "Type", 0); s.m_Body = wxString::FromUTF8(e->Attribute("Body")); s.m_BodyLimb = (Sight::BodyLimb)AttributeInt(e, "BodyLimb", 0); s.m_DateTime.ParseISODate(wxString::FromUTF8(e->Attribute("Date"))); wxDateTime time; time.ParseISOTime(wxString::FromUTF8(e->Attribute("Time"))); if(s.m_DateTime.IsValid() && time.IsValid()) { s.m_DateTime.SetHour(time.GetHour()); s.m_DateTime.SetMinute(time.GetMinute()); s.m_DateTime.SetSecond(time.GetSecond()); } else continue; /* skip if invalid */ s.m_TimeCertainty = AttributeDouble(e, "TimeCertainty", 0); s.m_Measurement = AttributeDouble(e, "Measurement", 0); s.m_MeasurementCertainty = AttributeDouble(e, "MeasurementCertainty", .25); s.m_EyeHeight = AttributeDouble(e, "EyeHeight", 2); s.m_Temperature = AttributeDouble(e, "Temperature", 10); s.m_Pressure = AttributeDouble(e, "Pressure", 1010); s.m_IndexError = AttributeDouble(e, "IndexError", 0); s.m_ShiftNm = AttributeDouble(e, "ShiftNm", 0); s.m_ShiftBearing = AttributeDouble(e, "ShiftBearing", 0); s.m_bMagneticShiftBearing = AttributeBool(e, "MagneticShiftBearing", 0); s.m_ColourName = wxString::FromUTF8(e->Attribute("ColourName")); s.m_Colour = wxColour(wxString::FromUTF8(e->Attribute("Colour"))); s.m_Colour.Set(s.m_Colour.Red(), s.m_Colour.Green(), s.m_Colour.Blue(), AttributeInt(e, "Transparency", 150)); Sight *ns = new Sight(s); ns->Recompute(m_ClockCorrectionDialog.m_sClockCorrection->GetValue()); ns->RebuildPolygons(); InsertSight(ns, false); } else FAIL(_("Unrecognized xml node")); } } RequestRefresh( GetParent() ); return true; failed: if(reportfailure) { wxMessageDialog mdlg(this, error, _("Celestial Navigation"), wxOK | wxICON_ERROR); mdlg.ShowModal(); } return false; }
void ConfigurationDialog::Update() { if(m_bBlockUpdate) return; bool refresh = false; RouteMapConfiguration configuration; std::list<RouteMapOverlay*> currentroutemaps = m_WeatherRouting.CurrentRouteMaps(); for(std::list<RouteMapOverlay*>::iterator it = currentroutemaps.begin(); it != currentroutemaps.end(); it++) { configuration = (*it)->GetConfiguration(); GET_CHOICE(Start); GET_CHOICE(End); if(m_dpStartDate->GetValue().IsValid()) configuration.StartTime = m_dpStartDate->GetValue(); if(!m_tStartHour->GetValue().empty()) { double hour; m_tStartHour->GetValue().ToDouble(&hour); configuration.StartTime.SetHour((int)hour); configuration.StartTime.SetMinute((int)(60*hour)%60); } if(m_WeatherRouting.m_SettingsDialog.m_cbUseLocalTime->GetValue()) configuration.StartTime = configuration.StartTime.ToUTC(); if(!m_tBoat->GetValue().empty()) configuration.boatFileName = m_tBoat->GetValue(); if(m_sTimeStepHours->IsEnabled()) { configuration.dt = 60*(60*m_sTimeStepHours->GetValue() + m_sTimeStepMinutes->GetValue()) + m_sTimeStepSeconds->GetValue(); } if(m_cIntegrator->GetValue() == _T("Newton")) configuration.Integrator = RouteMapConfiguration::NEWTON; else if(m_cIntegrator->GetValue() == _T("Runge Kutta")) configuration.Integrator = RouteMapConfiguration::RUNGE_KUTTA; GET_SPIN(MaxDivertedCourse); GET_SPIN(MaxCourseAngle); GET_SPIN(MaxSearchAngle); GET_SPIN(MaxTrueWindKnots); GET_SPIN(MaxApparentWindKnots); GET_SPIN(MaxSwellMeters); GET_SPIN(MaxLatitude); GET_SPIN(TackingTime); GET_SPIN(WindVSCurrent); GET_CHECKBOX(AvoidCycloneTracks); GET_SPIN(CycloneMonths); GET_SPIN(CycloneDays); GET_CHECKBOX(DetectLand); GET_CHECKBOX(Currents); GET_CHECKBOX(InvertedRegions); GET_CHECKBOX(Anchoring); GET_CHECKBOX(UseGrib); if(m_cClimatologyType->GetSelection() != -1) configuration.ClimatologyType = (RouteMapConfiguration::ClimatologyDataType) m_cClimatologyType->GetSelection(); GET_CHECKBOX(AllowDataDeficient); if(m_sWindStrength->IsEnabled()) \ configuration.WindStrength = m_sWindStrength->GetValue() / 100.0; GET_SPIN(FromDegree); GET_SPIN(ToDegree); if(!m_tByDegrees->GetValue().empty()) m_tByDegrees->GetValue().ToDouble(&configuration.ByDegrees); (*it)->SetConfiguration(configuration); /* if the start position changed, we must reset the route */ RouteMapConfiguration newc = (*it)->GetConfiguration(); if(newc.StartLat != configuration.StartLat || newc.StartLon != configuration.StartLon) { (*it)->Reset(); refresh = true; } else if(newc.EndLat != configuration.EndLat || newc.EndLon != configuration.EndLon) refresh = true; // update drawing } double by; m_tByDegrees->GetValue().ToDouble(&by); if(m_sToDegree->GetValue() - m_sFromDegree->GetValue() < 2*by) { wxMessageDialog mdlg(this, _("Warning: less than 4 different degree steps specified\n"), wxString(_("Weather Routing"), wxOK | wxICON_WARNING)); mdlg.ShowModal(); } m_WeatherRouting.UpdateCurrentConfigurations(); if(refresh) m_WeatherRouting.GetParent()->Refresh(); }
void rtlsdrPrefs::OnAutoCalibrate( wxCommandEvent& event ) { wxProgressDialog progress(_("rtlsdr error calibration"), _T(""), 256, this, wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_CAN_ABORT); m_rtlsdr_pi.Stop(); int i; for(i = 0; i < 96; i+=4) { m_rtlsdr_pi.m_AISError = i; m_rtlsdr_pi.m_AISCount = 0; m_rtlsdr_pi.Start(); for(int c = 0; c<6 && !m_rtlsdr_pi.m_AISCount; c++) { wxThread::Sleep(2500); if(!progress.Update(i*3/2+c)) goto abort; } m_rtlsdr_pi.Stop(); if(m_rtlsdr_pi.m_AISCount) goto havecount; } for(i = -6; i > -96; i-=4) { if(!progress.Update(64 - i )) break; m_rtlsdr_pi.m_AISError = i; m_rtlsdr_pi.m_AISCount = 0; m_rtlsdr_pi.Start(); for(int c = 0; c<6 && !m_rtlsdr_pi.m_AISCount; c++) { wxThread::Sleep(2500); if(!progress.Update(64-i*3/2+c)) goto abort; } m_rtlsdr_pi.Stop(); if(m_rtlsdr_pi.m_AISCount) goto havecount; } havecount: { int e = i; int pos = 128; do { i--; m_rtlsdr_pi.m_AISError = i; m_rtlsdr_pi.m_AISCount = 0; m_rtlsdr_pi.Start(); for(int c = 0; c<6 && !m_rtlsdr_pi.m_AISCount; c++) { wxThread::Sleep(3500); if(!progress.Update(pos++)) goto abort; if(pos == 256) pos = 255; } m_rtlsdr_pi.Stop(); } while(i > -128 && m_rtlsdr_pi.m_AISCount); do { e++; m_rtlsdr_pi.m_AISError = e; m_rtlsdr_pi.m_AISCount = 0; m_rtlsdr_pi.Start(); for(int c = 0; c<6 && !m_rtlsdr_pi.m_AISCount; c++) { wxThread::Sleep(3500); if(!progress.Update(pos++)) goto abort; if(pos == 256) pos = 255; } m_rtlsdr_pi.Stop(); } while(e < 128 && m_rtlsdr_pi.m_AISCount); m_sAISError->SetValue((i + e)/2); m_rtlsdr_pi.Restart(); return; } abort: m_rtlsdr_pi.Stop(); { wxMessageDialog mdlg(this, _("No AIS messages received\nCalibration Failed"), _("rtlsdr error calibration"), wxOK | wxICON_ERROR); mdlg.ShowModal(); return; } }
void weather_routing_pi::SetPluginMessage(wxString &message_id, wxString &message_body) { if(message_id == _T("GRIB_TIMELINE")) { wxJSONReader r; wxJSONValue v; r.Parse(message_body, &v); wxDateTime time; time.Set (v[_T("Day")].AsInt(), (wxDateTime::Month)v[_T("Month")].AsInt(), v[_T("Year")].AsInt(), v[_T("Hour")].AsInt(), v[_T("Minute")].AsInt(), v[_T("Second")].AsInt()); if(m_pWeather_Routing) { m_pWeather_Routing->m_ConfigurationDialog.m_GribTimelineTime = time.ToUTC(); // m_pWeather_Routing->m_ConfigurationDialog.m_cbUseGrib->Enable(); RequestRefresh(m_parent_window); } } if(message_id == _T("GRIB_TIMELINE_RECORD")) { wxJSONReader r; wxJSONValue v; r.Parse(message_body, &v); static bool shown_warnings; if(!shown_warnings) { shown_warnings = true; int grib_version_major = v[_T("GribVersionMajor")].AsInt(); int grib_version_minor = v[_T("GribVersionMinor")].AsInt(); int grib_version = 1000*grib_version_major + grib_version_minor; int grib_min = 1000*GRIB_MIN_MAJOR + GRIB_MIN_MINOR; int grib_max = 1000*GRIB_MAX_MAJOR + GRIB_MAX_MINOR; if(grib_version < grib_min || grib_version > grib_max) { wxMessageDialog mdlg(m_parent_window, _("Grib plugin version not supported.") + _T("\n\n") + wxString::Format(_("Use versions %d.%d to %d.%d"), GRIB_MIN_MAJOR, GRIB_MIN_MINOR, GRIB_MAX_MAJOR, GRIB_MAX_MINOR), _("Weather Routing"), wxOK | wxICON_WARNING); mdlg.ShowModal(); } } wxString sptr = v[_T("TimelineSetPtr")].AsString(); wxCharBuffer bptr = sptr.To8BitData(); const char* ptr = bptr.data(); GribRecordSet *gptr; sscanf(ptr, "%p", &gptr); if(m_pWeather_Routing) { RouteMapOverlay *routemapoverlay = m_pWeather_Routing->m_RouteMapOverlayNeedingGrib; if(routemapoverlay) { routemapoverlay->Lock(); routemapoverlay->SetNewGrib(gptr); routemapoverlay->Unlock(); } } } if(message_id == _T("CLIMATOLOGY")) { if(!m_pWeather_Routing) return; /* not ready */ wxJSONReader r; wxJSONValue v; r.Parse(message_body, &v); static bool shown_warnings; if(!shown_warnings) { shown_warnings = true; int climatology_version_major = v[_T("ClimatologyVersionMajor")].AsInt(); int climatology_version_minor = v[_T("ClimatologyVersionMinor")].AsInt(); int climatology_version = 1000*climatology_version_major + climatology_version_minor; int climatology_min = 1000*CLIMATOLOGY_MIN_MAJOR + CLIMATOLOGY_MIN_MINOR; int climatology_max = 1000*CLIMATOLOGY_MAX_MAJOR + CLIMATOLOGY_MAX_MINOR; if(climatology_version < climatology_min || climatology_version > climatology_max) { wxMessageDialog mdlg(m_parent_window, _("Climatology plugin version not supported, no climatology data.") + _T("\n\n") + wxString::Format(_("Use versions %d.%d to %d.%d"), CLIMATOLOGY_MIN_MAJOR, CLIMATOLOGY_MIN_MINOR, CLIMATOLOGY_MAX_MAJOR, CLIMATOLOGY_MAX_MINOR), _("Weather Routing"), wxOK | wxICON_WARNING); mdlg.ShowModal(); return; } } wxString sptr = v[_T("ClimatologyDataPtr")].AsString(); sscanf(sptr.To8BitData().data(), "%p", &RouteMap::ClimatologyData); sptr = v[_T("ClimatologyWindAtlasDataPtr")].AsString(); sscanf(sptr.To8BitData().data(), "%p", &RouteMap::ClimatologyWindAtlasData); sptr = v[_T("ClimatologyCycloneTrackCrossingsPtr")].AsString(); sscanf(sptr.To8BitData().data(), "%p", &RouteMap::ClimatologyCycloneTrackCrossings); if(m_pWeather_Routing) { m_pWeather_Routing->m_ConfigurationDialog.m_cClimatologyType->Enable (RouteMap::ClimatologyData!=NULL); m_pWeather_Routing->m_ConfigurationDialog.m_pCyclones->Enable (RouteMap::ClimatologyCycloneTrackCrossings!=NULL); } } if(message_id == wxS("WEATHER_ROUTING_PI")) { // construct the JSON root object wxJSONValue root; // construct a JSON parser wxJSONReader reader; // now read the JSON text and store it in the 'root' structure // check for errors before retreiving values... int numErrors = reader.Parse( message_body, &root ); if ( numErrors > 0 ) { wxLogMessage(_T("weather_routing_pi: Error parsing JSON message - ")); const wxArrayString& errors = reader.GetErrors(); for(int i = 0; i < (int)errors.GetCount(); i++) { wxLogMessage( errors.Item( i ) ); return; } } if(root[wxS("Type")].AsString() == wxS("Response") && root[wxS("Source")].AsString() == wxS("OCPN_DRAW_PI")) { if(root[wxS("Msg")].AsString() == wxS("Version") ) { if(root[wxS("MsgId")].AsString() == wxS("version")) g_ReceivedODVersionJSONMsg = root; } else if(root[wxS("Msg")].AsString() == wxS("GetAPIAddresses") ) { wxString sptr = root[_T("OD_FindClosestBoundaryLineCrossing")].AsString(); sscanf(sptr.To8BitData().data(), "%p", &RouteMap::ODFindClosestBoundaryLineCrossing); } } } }