void CelestialNavigationDialog::OnDuplicate(wxCommandEvent &event) { long selected_index = m_lSights->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (selected_index < 0) return; Sight *psight = (Sight*)wxUIntToPtr(m_lSights->GetItemData(selected_index)); Sight *ns = new Sight(*psight); ns->RebuildPolygons(); InsertSight(ns); RequestRefresh( GetParent() ); }
void CelestialNavigationDialog::OnNew(wxCommandEvent &event) { wxDateTime now = wxDateTime::Now().ToUTC(); Sight s(Sight::ALTITUDE, _("Sun"), Sight::LOWER, now, 0, 0, 10); SightDialog dialog(GetParent(), s, m_ClockCorrectionDialog.m_sClockCorrection->GetValue()); if( dialog.ShowModal() == wxID_OK ) { Sight *ns = new Sight(s); dialog.Recompute(); ns->RebuildPolygons(); InsertSight(ns); RequestRefresh( GetParent() ); } }
void CelestialNavigationDialog::OnEdit( ) { // Manipulate selected_index sight/track long selected_index = m_lSights->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (selected_index < 0) return; Sight *psight = (Sight*)wxUIntToPtr(m_lSights->GetItemData(selected_index)); Sight originalsight = *psight; /* in case of cancel */ SightDialog dialog(GetParent(), *psight, m_ClockCorrectionDialog.m_sClockCorrection->GetValue()); if( dialog.ShowModal() == wxID_OK ) { dialog.Recompute(); psight->RebuildPolygons(); UpdateSight(selected_index); } else *psight = originalsight; RequestRefresh( 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; }