35#ifndef __OCPN__ANDROID__ 
   40#include "GL/gl_private.h" 
   46float g_piGLMinSymbolLineWidth = 0.9;
 
   48void WMMLogMessage1(wxString s) { wxLogMessage(_T(
"WMM: ") + s); }
 
   49extern "C" void WMMLogMessage(
const char *s) {
 
   50  WMMLogMessage1(wxString::FromAscii(s));
 
   61extern "C" DECL_EXP 
void destroy_pi(
opencpn_plugin *p) { 
delete p; }
 
   75void WmmUIDialog::EnablePlotChanged(wxCommandEvent &event) {
 
   76  if (m_cbEnablePlot->GetValue()) m_wmm_pi.RecomputePlot();
 
   77  m_wmm_pi.SetShowPlot(m_cbEnablePlot->GetValue());
 
   81void WmmUIDialog::PlotSettings(wxCommandEvent &event) {
 
   85void WmmPlotSettingsDialog::About(wxCommandEvent &event) {
 
   88World Magnetic Model Plotting allows users to cross reference the\ 
   89 magnetic variation values printed on many raster charts.\n\n\ 
   90Variation is the angle between true and magnetic north.\n\ 
   91Inclination or dip, is the vertical angle of the magnetic field.\n\ 
   92\t(+- 90 at the magnetic poles)\n\ 
   93Field Strength is the magnetic field in nano tesla from\n\ 
   95The plotted lines are similar to a topographic map.  The \ 
   96space between them can be adjusted; more space takes \ 
   97less time to calculate.\n\n\ 
   98The Step size and Pole accuracy sliders allow a trade off \ 
   99for speed vs computation time.\n\n\ 
  100The World Magnetic Model Plugin was written by Pavel Kalian \ 
  101and extended by Sean D'Epagnier to support plotting."));
 
  103  wxMessageDialog dlg(
this, msg0, _(
"WMM Plugin"), wxOK);
 
  114wmm_pi::wmm_pi(
void *ppimgr)
 
  117      m_DeclinationMap(DECLINATION_PLOT, MagneticModel, TimedMagneticModel,
 
  119      m_InclinationMap(INCLINATION_PLOT, MagneticModel, TimedMagneticModel,
 
  121      m_FieldStrengthMap(FIELD_STRENGTH_PLOT, MagneticModel, TimedMagneticModel,
 
  123      m_bComputingPlot(false) {
 
  137  MagneticModel = NULL;
 
  138  TimedMagneticModel = NULL;
 
  140  ::wxDisplaySize(&m_display_width, &m_display_height);
 
  152#ifdef __OCPN__ANDROID__ 
  154  m_bShowPlotOptions = 
false;
 
  160  m_LastVal = wxEmptyString;
 
  167                wxFileName::GetPathSeparator() + _T(
"wmm_pi") +
 
  168                wxFileName::GetPathSeparator() + _T(
"data") +
 
  169                wxFileName::GetPathSeparator();
 
  174  int NumTerms, epochs = 1, nMax = 0;
 
  175  wxString cof_filename = m_shareLocn + 
"WMM.COF";
 
  177  if (!MAG_robustReadMagModels(
 
  178          const_cast<char *
>((
const char *)cof_filename.mb_str()),
 
  180    WMMLogMessage1(_T(
"initialization error"));
 
  183    WMMLogMessage1(wxString::Format(_T(
"WMM model data loaded from file %s."),
 
  184                                    cof_filename.c_str()));
 
  185    for (
int i = 0; i < epochs; i++) {
 
  186      if (MagneticModels[i]->nMax > nMax) {
 
  187        nMax = MagneticModels[i]->nMax;
 
  190    NumTerms = ((nMax + 1) * (nMax + 2) / 2);
 
  192    TimedMagneticModel = MAG_AllocateModelMemory(
 
  195    for (
int i = 0; i < epochs; i++) {
 
  196      if (MagneticModels[i] == NULL || TimedMagneticModel == NULL) {
 
  197        WMMLogMessage1(_T(
"initialization error MAG_Error(2)"));
 
  202    MagneticModel = MagneticModels[0];
 
  204    MAG_SetDefaults(&Ellip, &Geoid); 
 
  208    Geoid.GeoidHeightBuffer = GeoidHeightBuffer;
 
  209    Geoid.Geoid_Initialized = 1;
 
  220    m_leftclick_tool_id =
 
  222                         _T(
""), NULL, WMM_TOOL_POSITION, 0, 
this);
 
 
  237  if (NULL != m_pWmmDialog) {
 
  238    wxPoint p = m_pWmmDialog->GetPosition();
 
  242    m_pWmmDialog->Close();
 
  248    MAG_FreeMagneticModelMemory(MagneticModel);
 
  250  if (TimedMagneticModel) {
 
  251    MAG_FreeMagneticModelMemory(TimedMagneticModel);
 
  264  if (m_oDC) 
delete m_oDC;
 
 
  282  return _(
"World Magnetic Model PlugIn for OpenCPN");
 
 
  287      "World Magnetic Model PlugIn for OpenCPN\n\ 
  288Implements the NOAA World Magnetic Model\n\ 
  290https://www.ngdc.noaa.gov/geomag/WMM/DoDWMM.shtml\n\ 
  291The bundled WMM2025 model is valid until late 2029.\n\ 
  292After then, if new version of the plugin will not be released\n\ 
  293in time, get a new WMM.COF from NOAA and place it to the\n\ 
  294location you can find in the OpenCPN logfile.");
 
 
  300  if (NULL == m_pWmmDialog) 
return;
 
 
  304void wmm_pi::SetIconType() {
 
  305  if (m_bShowLiveIcon) {
 
  310    wxString normalIcon = m_shareLocn + _T(
"wmm_pi.svg");
 
  311    wxString toggledIcon = m_shareLocn + _T(
"wmm_pi.svg");
 
  312    wxString rolloverIcon = m_shareLocn + _T(
"wmm_pi.svg");
 
  319void wmm_pi::RearrangeWindow() {
 
  320  if (NULL == m_pWmmDialog) 
return;
 
  321  if (m_iViewType == 1) {
 
  322    m_pWmmDialog->sbScursor->Hide(m_pWmmDialog->gScursor, 
true);
 
  323    m_pWmmDialog->sbSboat->Hide(m_pWmmDialog->gSboat, 
true);
 
  325    m_pWmmDialog->sbScursor->Show(m_pWmmDialog->gScursor, 
true, 
true);
 
  326    m_pWmmDialog->sbSboat->Show(m_pWmmDialog->gSboat, 
true, 
true);
 
  329  m_pWmmDialog->m_cbEnablePlot->Show(m_bShowPlotOptions);
 
  330  m_pWmmDialog->m_bPlotSettings->Show(m_bShowPlotOptions);
 
  332  if (!m_bShowAtCursor) {
 
  333    m_pWmmDialog->bSframe->Hide(m_pWmmDialog->sbScursor, 
true);
 
  335    m_pWmmDialog->bSframe->Show(m_pWmmDialog->sbScursor, 
true, 
true);
 
  336    if (m_iViewType == 1)
 
  337      m_pWmmDialog->sbScursor->Hide(m_pWmmDialog->gScursor, 
true);
 
  348  wxFileConfig *pConf = (wxFileConfig *)m_pconfig;
 
  351    pConf->SetPath(_T(
"/Settings"));
 
  352    pConf->Read(_T(
"OpenGL"), &gl, 
false);
 
  355  if (!(gl && wxPlatformInfo::Get().GetOSMajorVersion() == 5 &&
 
  356        wxPlatformInfo::Get().GetOSMinorVersion() == 1))
 
  358    if (m_pWmmDialog->CanSetTransparent())
 
  359      m_pWmmDialog->SetTransparent(m_iOpacity);
 
  363  if (!m_buseable) 
return;
 
  364  if (NULL == m_pWmmDialog) {
 
  365    m_pWmmDialog = 
new WmmUIDialog(*
this, m_parent_window);
 
  367    m_pWmmDialog->SetFont(*pFont);
 
  369    m_pWmmDialog->Move(wxPoint(m_wmm_dialog_x, m_wmm_dialog_y));
 
  375  m_pWmmDialog->Show(!m_pWmmDialog->IsShown());
 
  376  m_pWmmDialog->Layout();  
 
  378  if (m_pWmmDialog->IsShown())
 
  383  wxPoint p = m_pWmmDialog->GetPosition();
 
  384  m_pWmmDialog->Move(0, 0);  
 
  385  m_pWmmDialog->Move(p);
 
  387#ifdef __OCPN__ANDROID__ 
  388  m_pWmmDialog->CentreOnScreen();
 
  389  m_pWmmDialog->Move(-1, 0);
 
 
  394  if (!m_bShowPlot) 
return;
 
  396  m_DeclinationMap.Plot(dc, vp, wxColour(255, 0, 90, 220));
 
  397  m_InclinationMap.Plot(dc, vp, wxColour(60, 255, 30, 220));
 
  398  m_FieldStrengthMap.Plot(dc, vp, wxColour(0, 60, 255, 220));
 
  402  if (!m_bShowPlot) 
return true;
 
  409  RenderOverlayBoth(m_oDC, vp);
 
  415  if (!m_bShowPlot) 
return true;
 
  421#ifndef USE_ANDROID_GLES2 
  422    glGetIntegerv(GL_SMOOTH_LINE_WIDTH_RANGE, &parms[0]);
 
  424    glGetIntegerv(GL_ALIASED_LINE_WIDTH_RANGE, &parms[0]);
 
  426    g_piGLMinSymbolLineWidth = wxMax(parms[0], 1);
 
  434#ifndef USE_ANDROID_GLES2 
  435  glPushAttrib(GL_COLOR_BUFFER_BIT | GL_LINE_BIT | GL_ENABLE_BIT |
 
  436               GL_POLYGON_BIT | GL_HINT_BIT);
 
  438  glEnable(GL_LINE_SMOOTH);
 
  440  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
  441  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
 
  444  RenderOverlayBoth(m_oDC, vp);
 
  446#ifndef USE_ANDROID_GLES2 
 
  453void wmm_pi::RecomputePlot() {
 
  454  if (m_bCachedPlotOk) 
return;
 
  456  if (m_bComputingPlot) 
return;
 
  457  m_bComputingPlot = 
true;
 
  459  if (!m_DeclinationMap.Recompute(m_MapDate) ||
 
  460      !m_InclinationMap.Recompute(m_MapDate) ||
 
  461      !m_FieldStrengthMap.Recompute(m_MapDate)) {
 
  463    if (m_pWmmDialog) m_pWmmDialog->m_cbEnablePlot->SetValue(
false);
 
  465    m_bCachedPlotOk = 
true;
 
  467  m_bComputingPlot = 
false;
 
  471  if (!m_pWmmDialog) 
return;
 
  473  if (!m_bShowAtCursor)
 
  475  if (lat < -90 || lat > 90 || lon < -180 || lon > 180 ||
 
  476      NULL == m_pWmmDialog || !m_pWmmDialog->IsShown())
 
  479    m_pWmmDialog->m_tbD->SetValue(_(
"Error, see log."));
 
  482  CoordGeodetic.lambda = lon;
 
  483  CoordGeodetic.phi = lat;
 
  484  CoordGeodetic.HeightAboveEllipsoid = 0;
 
  485  CoordGeodetic.HeightAboveGeoid = 0;
 
  486  CoordGeodetic.UseGeoid = 0;
 
  487  UserDate.Year = wxDateTime::GetCurrentYear();
 
  489      wxDateTime::GetCurrentMonth() + 1;  
 
  490  UserDate.Day = wxDateTime::Now().GetDay();
 
  492  MAG_DateToYear(&UserDate, err);
 
  493  MAG_GeodeticToSpherical(
 
  494      Ellip, CoordGeodetic,
 
  497  MAG_TimelyModifyMagneticModel(
 
  498      UserDate, MagneticModel,
 
  501  MAG_Geomag(Ellip, CoordSpherical, CoordGeodetic, TimedMagneticModel,
 
  502             &GeoMagneticElements); 
 
  504  MAG_CalculateGridVariation(CoordGeodetic, &GeoMagneticElements);
 
  507  m_pWmmDialog->m_tcF->SetValue(
 
  508      wxString::Format(_T(
"%-9.1lf nT"), GeoMagneticElements.F));
 
  509  m_pWmmDialog->m_tcH->SetValue(
 
  510      wxString::Format(_T(
"%-9.1lf nT"), GeoMagneticElements.H));
 
  511  m_pWmmDialog->m_tcX->SetValue(
 
  512      wxString::Format(_T(
"%-9.1lf nT"), GeoMagneticElements.X));
 
  513  m_pWmmDialog->m_tcY->SetValue(
 
  514      wxString::Format(_T(
"%-9.1lf nT"), GeoMagneticElements.Y));
 
  515  m_pWmmDialog->m_tcZ->SetValue(
 
  516      wxString::Format(_T(
"%-9.1lf nT"), GeoMagneticElements.Z));
 
  517  m_pWmmDialog->m_tcD->SetValue(
 
  518      wxString::Format(_T(
"%-5.1lf%c (%s)"), GeoMagneticElements.Decl, 0x00B0,
 
  519                       AngleToText(GeoMagneticElements.Decl).c_str()));
 
  520  m_pWmmDialog->m_tcI->SetValue(
 
  521      wxString::Format(_T(
"%-5.1lf%c"), GeoMagneticElements.Incl, 0x00B0));
 
  523  m_cursorVariation = GeoMagneticElements;
 
  524  SendCursorVariation();
 
 
  531  CoordGeodetic.lambda = pfix.
Lon;
 
  532  CoordGeodetic.phi = pfix.
Lat;
 
  533  CoordGeodetic.HeightAboveEllipsoid = 0;
 
  534  CoordGeodetic.UseGeoid = 0;
 
  535  UserDate.Year = wxDateTime::GetCurrentYear();
 
  537      wxDateTime::GetCurrentMonth() + 1;  
 
  538  UserDate.Day = wxDateTime::Now().GetDay();
 
  540  MAG_DateToYear(&UserDate, err);
 
  541  MAG_GeodeticToSpherical(
 
  542      Ellip, CoordGeodetic,
 
  545  MAG_TimelyModifyMagneticModel(
 
  546      UserDate, MagneticModel,
 
  549  MAG_Geomag(Ellip, CoordSpherical, CoordGeodetic, TimedMagneticModel,
 
  550             &GeoMagneticElements); 
 
  552  MAG_CalculateGridVariation(CoordGeodetic, &GeoMagneticElements);
 
  556  m_boatVariation = GeoMagneticElements;
 
  559  wxString NewVal = wxString::Format(_T(
"%.1f"), GeoMagneticElements.Decl);
 
  567  if (m_bShowIcon && m_bShowLiveIcon &&
 
  568      ((m_LastVal != NewVal) || (
scale != m_scale))) {
 
  571    int w = _img_wmm_live->GetWidth() * 
scale;
 
  572    int h = _img_wmm_live->GetHeight() * 
scale;
 
  580      icon = wxBitmap(_img_wmm_live->GetWidth(), _img_wmm_live->GetHeight());
 
  581      dc.SelectObject(icon);
 
  582      dc.DrawBitmap(*_img_wmm_live, 0, 0, 
true);
 
  584      icon = wxBitmap(w, h);
 
  585      dc.SelectObject(icon);
 
  587      dc.SetBackground(*wxTRANSPARENT_BRUSH);
 
  590      dc.DrawBitmap(live, 0, 0, 
true);
 
  594    GetGlobalColor(_T(
"CHWHT"), &cf);
 
  595    dc.SetTextForeground(cf);
 
  596    if (pFontSmall->IsOk()) {
 
  598        int point_size = wxMax(10, 10 * 
scale);
 
  599        pFontSmall->SetPointSize(point_size);
 
  605        sdc.GetTextExtent(NewVal, &w, NULL, NULL, NULL, pFontSmall);
 
  607        while ((w > (icon.GetWidth() * 8 / 10)) && (point_size >= 8)) {
 
  609          pFontSmall->SetPointSize(point_size);
 
  610          sdc.GetTextExtent(NewVal, &w, NULL, NULL, NULL, pFontSmall);
 
  613      dc.SetFont(*pFontSmall);
 
  615    wxSize s = dc.GetTextExtent(NewVal);
 
  616    dc.DrawText(NewVal, (icon.GetWidth() - s.GetWidth()) / 2,
 
  617                (icon.GetHeight() - s.GetHeight()) / 2);
 
  618    dc.SelectObject(wxNullBitmap);
 
  624      wxImage imo = live.ConvertToImage();
 
  625      wxImage im = icon.ConvertToImage();
 
  627      if (!imo.HasAlpha()) imo.InitAlpha();
 
  628      if (!im.HasAlpha()) im.InitAlpha();
 
  630      unsigned char *alive = imo.GetAlpha();
 
  631      unsigned char *target = im.GetAlpha();
 
  633      for (
int i = 0; i < h; i++) {
 
  634        for (
int j = 0; j < w; j++) {
 
  635          int index = (i * w) + j;
 
  636          target[index] = alive[index];
 
  645  if (NULL == m_pWmmDialog || !m_pWmmDialog->IsShown()) 
return;
 
  647    m_pWmmDialog->m_tbD->SetValue(_(
"Error, see log."));
 
  650  m_pWmmDialog->m_tbF->SetValue(
 
  651      wxString::Format(_T(
"%-9.1lf nT"), GeoMagneticElements.F));
 
  652  m_pWmmDialog->m_tbH->SetValue(
 
  653      wxString::Format(_T(
"%-9.1lf nT"), GeoMagneticElements.H));
 
  654  m_pWmmDialog->m_tbX->SetValue(
 
  655      wxString::Format(_T(
"%-9.1lf nT"), GeoMagneticElements.X));
 
  656  m_pWmmDialog->m_tbY->SetValue(
 
  657      wxString::Format(_T(
"%-9.1lf nT"), GeoMagneticElements.Y));
 
  658  m_pWmmDialog->m_tbZ->SetValue(
 
  659      wxString::Format(_T(
"%-9.1lf nT"), GeoMagneticElements.Z));
 
  660  m_pWmmDialog->m_tbD->SetValue(
 
  661      wxString::Format(_T(
"%-5.1lf%c (%s)"), GeoMagneticElements.Decl, 0x00B0,
 
  662                       AngleToText(GeoMagneticElements.Decl).c_str()));
 
  663  m_pWmmDialog->m_tbI->SetValue(
 
  664      wxString::Format(_T(
"%-5.1lf%c"), GeoMagneticElements.Incl, 0x00B0));
 
 
  668void wmm_pi::SetPluginMessage(wxString &message_id, wxString &message_body) {
 
  669  if (message_id == _T(
"WMM_VARIATION_REQUEST")) {
 
  672    r.
Parse(message_body, &v);
 
  673    double lat = v[_T(
"Lat")].
AsDouble();
 
  674    double lon = v[_T(
"Lon")].
AsDouble();
 
  675    int year = v[_T(
"Year")].
AsInt();
 
  676    int month = v[_T(
"Month")].
AsInt();
 
  677    int day = v[_T(
"Day")].
AsInt();
 
  678    SendVariationAt(lat, lon, year, month, day);
 
  679  } 
else if (message_id == _T(
"WMM_VARIATION_BOAT_REQUEST")) {
 
  681  } 
else if (message_id == _T(
"WMM_VARIATION_CURSOR_REQUEST")) {
 
  682    SendCursorVariation();
 
  686void wmm_pi::SendVariationAt(
double lat, 
double lon, 
int year, 
int month,
 
  691  v[_T(
"Year")] = year;
 
  692  v[_T(
"Month")] = month;
 
  694  CoordGeodetic.lambda = lon;
 
  695  CoordGeodetic.phi = lat;
 
  696  CoordGeodetic.HeightAboveEllipsoid = 0;
 
  697  CoordGeodetic.UseGeoid = 0;
 
  698  UserDate.Year = year;
 
  699  UserDate.Month = month;
 
  702  MAG_DateToYear(&UserDate, err);
 
  703  MAG_GeodeticToSpherical(
 
  704      Ellip, CoordGeodetic,
 
  707  MAG_TimelyModifyMagneticModel(
 
  708      UserDate, MagneticModel,
 
  711  MAG_Geomag(Ellip, CoordSpherical, CoordGeodetic, TimedMagneticModel,
 
  712             &GeoMagneticElements); 
 
  714  MAG_CalculateGridVariation(CoordGeodetic, &GeoMagneticElements);
 
  715  v[_T(
"Decl")] = GeoMagneticElements.Decl;
 
  716  v[_T(
"Decldot")] = GeoMagneticElements.Decldot;
 
  717  v[_T(
"F")] = GeoMagneticElements.F;
 
  718  v[_T(
"Fdot")] = GeoMagneticElements.Fdot;
 
  719  v[_T(
"GV")] = GeoMagneticElements.GV;
 
  720  v[_T(
"GVdot")] = GeoMagneticElements.GVdot;
 
  721  v[_T(
"H")] = GeoMagneticElements.H;
 
  722  v[_T(
"Hdot")] = GeoMagneticElements.Hdot;
 
  723  v[_T(
"Incl")] = GeoMagneticElements.Incl;
 
  724  v[_T(
"Incldot")] = GeoMagneticElements.Incldot;
 
  725  v[_T(
"X")] = GeoMagneticElements.X;
 
  726  v[_T(
"Xdot")] = GeoMagneticElements.Xdot;
 
  727  v[_T(
"Y")] = GeoMagneticElements.Y;
 
  728  v[_T(
"Ydot")] = GeoMagneticElements.Ydot;
 
  729  v[_T(
"Z")] = GeoMagneticElements.Z;
 
  730  v[_T(
"Zdot")] = GeoMagneticElements.Zdot;
 
  737void wmm_pi::SendBoatVariation() {
 
  739  v[_T(
"Decl")] = m_boatVariation.Decl;
 
  740  v[_T(
"Decldot")] = m_boatVariation.Decldot;
 
  741  v[_T(
"F")] = m_boatVariation.F;
 
  742  v[_T(
"Fdot")] = m_boatVariation.Fdot;
 
  743  v[_T(
"GV")] = m_boatVariation.GV;
 
  744  v[_T(
"GVdot")] = m_boatVariation.GVdot;
 
  745  v[_T(
"H")] = m_boatVariation.H;
 
  746  v[_T(
"Hdot")] = m_boatVariation.Hdot;
 
  747  v[_T(
"Incl")] = m_boatVariation.Incl;
 
  748  v[_T(
"Incldot")] = m_boatVariation.Incldot;
 
  749  v[_T(
"X")] = m_boatVariation.X;
 
  750  v[_T(
"Xdot")] = m_boatVariation.Xdot;
 
  751  v[_T(
"Y")] = m_boatVariation.Y;
 
  752  v[_T(
"Ydot")] = m_boatVariation.Ydot;
 
  753  v[_T(
"Z")] = m_boatVariation.Z;
 
  754  v[_T(
"Zdot")] = m_boatVariation.Zdot;
 
  761void wmm_pi::SendCursorVariation() {
 
  763  v[_T(
"Decl")] = m_cursorVariation.Decl;
 
  764  v[_T(
"Decldot")] = m_cursorVariation.Decldot;
 
  765  v[_T(
"F")] = m_cursorVariation.F;
 
  766  v[_T(
"Fdot")] = m_cursorVariation.Fdot;
 
  767  v[_T(
"GV")] = m_cursorVariation.GV;
 
  768  v[_T(
"GVdot")] = m_cursorVariation.GVdot;
 
  769  v[_T(
"H")] = m_cursorVariation.H;
 
  770  v[_T(
"Hdot")] = m_cursorVariation.Hdot;
 
  771  v[_T(
"Incl")] = m_cursorVariation.Incl;
 
  772  v[_T(
"Incldot")] = m_cursorVariation.Incldot;
 
  773  v[_T(
"X")] = m_cursorVariation.X;
 
  774  v[_T(
"Xdot")] = m_cursorVariation.Xdot;
 
  775  v[_T(
"Y")] = m_cursorVariation.Y;
 
  776  v[_T(
"Ydot")] = m_cursorVariation.Ydot;
 
  777  v[_T(
"Z")] = m_cursorVariation.Z;
 
  778  v[_T(
"Zdot")] = m_cursorVariation.Zdot;
 
  785wxString wmm_pi::AngleToText(
double angle) {
 
  786  int deg = (int)fabs(angle);
 
  787  int min = (fabs(angle) - deg) * 60;
 
  789    return wxString::Format(_T(
"%u%c%u' W"), deg, 0x00B0, min);
 
  791    return wxString::Format(_T(
"%u%c%u' E"), deg, 0x00B0, min);
 
  794bool wmm_pi::LoadConfig(
void) {
 
  795  wxFileConfig *pConf = (wxFileConfig *)m_pconfig;
 
  798    pConf->SetPath(_T( 
"/Settings/WMM" ));
 
  799    pConf->Read(_T( 
"ViewType" ), &m_iViewType, 1);
 
  800    pConf->Read(_T( 
"ShowPlotOptions" ), &m_bShowPlotOptions, 1);
 
  801    pConf->Read(_T( 
"ShowAtCursor" ), &m_bShowAtCursor, 1);
 
  802    pConf->Read(_T( 
"ShowLiveIcon" ), &m_bShowLiveIcon, 1);
 
  803    pConf->Read(_T( 
"ShowIcon" ), &m_bShowIcon, 1);
 
  804    pConf->Read(_T( 
"Opacity" ), &m_iOpacity, 255);
 
  806    m_wmm_dialog_x = pConf->Read(_T ( 
"DialogPosX" ), 20L);
 
  807    m_wmm_dialog_y = pConf->Read(_T ( 
"DialogPosY" ), 20L);
 
  809    if ((m_wmm_dialog_x < 0) || (m_wmm_dialog_x > m_display_width))
 
  811    if ((m_wmm_dialog_y < 0) || (m_wmm_dialog_y > m_display_height))
 
  814    pConf->SetPath(_T( 
"/Settings/WMM/Plot" ));
 
  815    pConf->Read(_T( 
"Declination" ), &m_DeclinationMap.m_bEnabled, 1);
 
  816    pConf->Read(_T( 
"DeclinationSpacing" ), &m_DeclinationMap.m_Spacing, 10);
 
  817    pConf->Read(_T( 
"Inclination" ), &m_InclinationMap.m_bEnabled, 0);
 
  818    pConf->Read(_T( 
"InclinationSpacing" ), &m_InclinationMap.m_Spacing, 10);
 
  819    pConf->Read(_T( 
"FieldStrength" ), &m_FieldStrengthMap.m_bEnabled, 0);
 
  820    pConf->Read(_T( 
"FieldStrengthSpacing" ), &m_FieldStrengthMap.m_Spacing,
 
  823    pConf->Read(_T( 
"StepSize" ), &m_MapStep, 6);
 
  824    pConf->Read(_T( 
"PoleAccuracy" ), &m_MapPoleAccuracy, 2);
 
  825    m_DeclinationMap.ConfigureAccuracy(m_MapStep, m_MapPoleAccuracy);
 
  826    m_InclinationMap.ConfigureAccuracy(m_MapStep, m_MapPoleAccuracy);
 
  827    m_FieldStrengthMap.ConfigureAccuracy(m_MapStep, m_MapPoleAccuracy);
 
  829    m_MapDate = wxDateTime::Now(); 
 
  831    m_bCachedPlotOk = 
false;
 
  833    pConf->SetPath(_T ( 
"/Directories" ));
 
  834    wxString s = wxFileName::GetPathSeparator();
 
  836                   _T(
"wmm_pi") + s + _T(
"data") + s;
 
  844bool wmm_pi::SaveConfig(
void) {
 
  845  wxFileConfig *pConf = (wxFileConfig *)m_pconfig;
 
  848    pConf->SetPath(_T ( 
"/Settings/WMM" ));
 
  849    pConf->Write(_T ( 
"ViewType" ), m_iViewType);
 
  850    pConf->Write(_T ( 
"ShowPlotOptions" ), m_bShowPlotOptions);
 
  851    pConf->Write(_T ( 
"ShowAtCursor" ), m_bShowAtCursor);
 
  852    pConf->Write(_T ( 
"ShowLiveIcon" ), m_bShowLiveIcon);
 
  853    pConf->Write(_T ( 
"ShowIcon" ), m_bShowIcon);
 
  854    pConf->Write(_T ( 
"Opacity" ), m_iOpacity);
 
  856    pConf->Write(_T ( 
"DialogPosX" ), m_wmm_dialog_x);
 
  857    pConf->Write(_T ( 
"DialogPosY" ), m_wmm_dialog_y);
 
  859    pConf->SetPath(_T( 
"/Settings/WMM/Plot" ));
 
  860    pConf->Write(_T( 
"Declination" ), m_DeclinationMap.m_bEnabled);
 
  861    pConf->Write(_T( 
"DeclinationSpacing" ), m_DeclinationMap.m_Spacing);
 
  862    pConf->Write(_T( 
"Inclination" ), m_InclinationMap.m_bEnabled);
 
  863    pConf->Write(_T( 
"InclinationSpacing" ), m_InclinationMap.m_Spacing);
 
  864    pConf->Write(_T( 
"FieldStrength" ), m_FieldStrengthMap.m_bEnabled);
 
  865    pConf->Write(_T( 
"FieldStrengthSpacing" ), m_FieldStrengthMap.m_Spacing);
 
  866    pConf->Write(_T( 
"StepSize" ), m_MapStep);
 
  867    pConf->Write(_T( 
"PoleAccuracy" ), m_MapPoleAccuracy);
 
  869    pConf->SetPath(_T ( 
"/Directories" ));
 
  870    pConf->Write(_T ( 
"WMMDataLocation" ), m_wmm_dir);
 
  880                         wxPoint(m_wmm_dialog_x, m_wmm_dialog_y), wxDefaultSize,
 
  881                         wxDEFAULT_DIALOG_STYLE);
 
  884  dialog->m_rbViewType->SetSelection(m_iViewType);
 
  885  dialog->m_cbShowPlotOptions->SetValue(m_bShowPlotOptions);
 
  886  dialog->m_cbShowAtCursor->SetValue(m_bShowAtCursor);
 
  887  dialog->m_cbShowIcon->SetValue(m_bShowIcon);
 
  888  dialog->m_cbLiveIcon->SetValue(m_bShowLiveIcon);
 
  889  dialog->m_sOpacity->SetValue(m_iOpacity);
 
  891  if (dialog->ShowModal() == wxID_OK) {
 
  892    m_iViewType = dialog->m_rbViewType->GetSelection();
 
  893    m_bShowPlotOptions = dialog->m_cbShowPlotOptions->GetValue();
 
  894    m_bShowAtCursor = dialog->m_cbShowAtCursor->GetValue();
 
  895    m_bShowLiveIcon = dialog->m_cbLiveIcon->GetValue();
 
  896    m_bShowIcon = dialog->m_cbShowIcon->GetValue();
 
  897    m_iOpacity = dialog->m_sOpacity->GetValue();
 
 
  910  dialog->SetFont(*pFont);
 
  914  dialog->m_cbDeclination->SetValue(m_DeclinationMap.m_bEnabled);
 
  915  dialog->m_scDeclinationSpacing->SetValue(m_DeclinationMap.m_Spacing);
 
  916  dialog->m_cbInclination->SetValue(m_InclinationMap.m_bEnabled);
 
  917  dialog->m_scInclinationSpacing->SetValue(m_InclinationMap.m_Spacing);
 
  918  dialog->m_cbFieldStrength->SetValue(m_FieldStrengthMap.m_bEnabled);
 
  919  dialog->m_scFieldStrengthSpacing->SetValue(m_FieldStrengthMap.m_Spacing);
 
  921  dialog->m_sStep->SetValue(m_MapStep);
 
  922  dialog->m_sPoleAccuracy->SetValue(m_MapPoleAccuracy);
 
  924  if (dialog->ShowModal() == wxID_OK) {
 
  925    m_DeclinationMap.m_bEnabled = dialog->m_cbDeclination->GetValue();
 
  926    m_DeclinationMap.m_Spacing = dialog->m_scDeclinationSpacing->GetValue();
 
  927    m_InclinationMap.m_bEnabled = dialog->m_cbInclination->GetValue();
 
  928    m_InclinationMap.m_Spacing = dialog->m_scInclinationSpacing->GetValue();
 
  929    m_FieldStrengthMap.m_bEnabled = dialog->m_cbFieldStrength->GetValue();
 
  930    m_FieldStrengthMap.m_Spacing = dialog->m_scFieldStrengthSpacing->GetValue();
 
  932    m_MapStep = dialog->m_sStep->GetValue();
 
  933    m_MapPoleAccuracy = dialog->m_sPoleAccuracy->GetValue();
 
  934    m_DeclinationMap.ConfigureAccuracy(m_MapStep, m_MapPoleAccuracy);
 
  935    m_InclinationMap.ConfigureAccuracy(m_MapStep, m_MapPoleAccuracy);
 
  936    m_FieldStrengthMap.ConfigureAccuracy(m_MapStep, m_MapPoleAccuracy);
 
  938    m_bCachedPlotOk = 
false;
 
  939    if (m_pWmmDialog->m_cbEnablePlot->GetValue()) RecomputePlot();
 
 
Basic position fix information.
double Lat
Latitude in decimal degrees.
double Lon
Longitude in decimal degrees.
Contains view parameters and status information for a chart display viewport.
Base class for OpenCPN plugins.
void OnToolbarToolCallback(int id)
Handles toolbar tool clicks.
int GetAPIVersionMajor()
Returns the major version number of the plugin API that this plugin supports.
wxString GetCommonName()
Get the plugin's common (short) name.
void SetColorScheme(PI_ColorScheme cs)
Updates plugin color scheme.
int GetToolbarToolCount(void)
Returns the number of toolbar tools this plugin provides.
void SetPositionFix(PlugIn_Position_Fix &pfix)
Updates plugin with current position fix data at regular intervals.
bool DeInit(void)
Clean up plugin resources.
void ShowPreferencesDialog(wxWindow *parent)
Shows the plugin preferences dialog.
void SetCursorLatLon(double lat, double lon)
Receives cursor lat/lon position updates.
int Init(void)
Initialize the plugin and declare its capabilities.
wxString GetShortDescription()
Get a brief description of the plugin.
int GetPlugInVersionMinor()
Returns the minor version number of the plugin itself.
wxString GetLongDescription()
Get detailed plugin information.
wxBitmap * GetPlugInBitmap()
Get the plugin's icon bitmap.
int GetAPIVersionMinor()
Returns the minor version number of the plugin API that this plugin supports.
int GetPlugInVersionMajor()
Returns the major version number of the plugin itself.
bool RenderGLOverlay(wxGLContext *pcontext, PlugIn_ViewPort *vp)
Renders plugin overlay graphics in OpenGL mode for single canvas.
int Parse(const wxString &doc, wxJSONValue *val)
Parse the JSON document.
The JSON value class implementation.
double AsDouble() const
Return the stored value as a double.
int AsInt() const
Return the stored value as an integer.
The JSON document writer.
void Write(const wxJSONValue &value, wxString &str)
Write the JSONvalue object to a JSON text.
#define WANTS_NMEA_EVENTS
Receive decoded NMEA events with parsed data.
PI_ColorScheme
Color schemes for different lighting conditions.
#define WANTS_PREFERENCES
Plugin will add page(s) to global preferences dialog.
#define WANTS_CONFIG
Plugin requires persistent configuration storage.
#define WANTS_PLUGIN_MESSAGING
Enable message passing between plugins.
#define INSTALLS_TOOLBAR_TOOL
Plugin will add one or more toolbar buttons.
#define WANTS_CURSOR_LATLON
Receive updates when cursor moves over chart.
#define WANTS_TOOLBAR_CALLBACK
Receive notification when user left-clicks plugin's toolbar buttons.
#define WANTS_OVERLAY_CALLBACK
Receive callbacks to render custom overlay graphics on the chart.
void RemovePlugInTool(int tool_id)
Removes a tool from OpenCPN's toolbar.
wxWindow * GetOCPNCanvasWindow()
Gets OpenCPN's main canvas window.
wxFont * OCPNGetFont(wxString TextElement, int default_size)
Gets a font for UI elements.
wxFileConfig * GetOCPNConfigObject()
Gets OpenCPN's configuration object.
wxBitmap GetBitmapFromSVGFile(wxString filename, unsigned int width, unsigned int height)
Creates bitmap from SVG file.
int InsertPlugInTool(wxString label, wxBitmap *bitmap, wxBitmap *bmpRollover, wxItemKind kind, wxString shortHelp, wxString longHelp, wxObject *clientData, int position, int tool_sel, opencpn_plugin *pplugin)
Adds a tool to OpenCPN's toolbar.
void SetToolbarToolBitmaps(int item, wxBitmap *bitmap, wxBitmap *bmpRollover)
Updates toolbar tool bitmaps.
wxString * GetpSharedDataLocation()
Gets shared application data location.
void DimeWindow(wxWindow *win)
Applies system color scheme to window.
double GetOCPNGUIToolScaleFactor_PlugIn()
Gets current global GUI scaling factor.
void SetToolbarToolBitmapsSVG(int item, wxString SVGfile, wxString SVGfileRollover, wxString SVGfileToggled)
Updates SVG graphics for toolbar tool.
double OCPN_GetWinDIPScaleFactor()
Gets Windows-specific DPI scaling factor.
void SendPluginMessage(wxString message_id, wxString message_body)
Sends message to other plugins.
void RequestRefresh(wxWindow *win)
Requests window refresh.
bool AddLocaleCatalog(wxString catalog)
Adds a locale catalog for translations.