void ClockCorrectionDialog::OnUpdate( wxSpinEvent& event )
{
    CelestialNavigationDialog *parent((CelestialNavigationDialog*)GetParent());
    wxListCtrl *lSights = parent->m_lSights;
    for(int i = 0; i<lSights->GetItemCount(); i++) {
        Sight *s = (Sight*)wxUIntToPtr(lSights->GetItemData(i));
        s->Recompute(m_sClockCorrection->GetValue());
    }

    parent->UpdateSights();
    RequestRefresh( parent->GetParent() );
}
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;
}