示例#1
0
/*
	Synchronises the options data with what is held in the gui structures 
	(the gui holds the "latest" data, so this is copied into here)

	This should be used when the application wants to store the settings on disk
	i.e save them in the configuration file

	or when the application wants to use the new settings with the screamer system
	since it will not ask the gui for this information, when the gui structures are updated
	(this is the only way the user can alter the configuration, apart from hand editing the configuration file)
	any attempt to run screamer must be done with the new configuration, so when the options are updated and ok'd
	they need to be synchronised with the backend options structures, so screamer can use those changes in the options
*/
void Options::Update(void)
{
#define GET_TEXT(name)		gtk_entry_get_text(GTK_ENTRY(lookup_widget(OptionsWindow,name)))
#define GET_NUM(name)			atoi(gtk_entry_get_text(GTK_ENTRY(lookup_widget(OptionsWindow,name))))
#define GET_SPIN(name)		gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lookup_widget(OptionsWindow,name)))
#define	GET_TOGGLE(name)	gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(OptionsWindow,name)))
	
	ScreamerName					=	GET_TEXT("ScreamerName");
	ScreamerCPUNumbers		=	GET_NUM("ScreamerCPUNumbers");
	NumberFrames					=	GET_SPIN("NumberFrames");
	CommandDirectory			=	GET_TEXT("CommandDirectory");
	ScreamerExecutable		=	GET_TEXT("ScreamerExecutable");
	ScreamerConfigDir			=	GET_TEXT("ScreamerConfigDir");
	ScreamerPriority			=	GET_SPIN("ScreamerPriority");
	FindScreamerInterval	=	GET_SPIN("ScreamerInterval");
	WineCmd								=	GET_TEXT("WineCmd");
}
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();
}
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();
}