OpenCPN Partial API docs
Loading...
Searching...
No Matches
grib_settings_dlg.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2015 by Sean D'Epagnier *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 ***************************************************************************/
17
24#include "pi_gl.h"
25
26#include "jsonwriter.h"
27
28#include "grib_pi.h"
29#include "folder.xpm"
30
31static const wxString units0_names[] = {_("Knots"), _("m/s"), _("mph"),
32 _("km/h"), _("Beaufort"), ""};
33static const wxString units1_names[] = {_("MilliBars"), _("mmHG"), _("inHG"),
34 ""};
35static const wxString units2_names[] = {_("Meters"), _("Feet"), ""};
36static const wxString units3_names[] = {_("Celsius"), _("Fahrenheit"), ""};
37static const wxString units4_names[] = {_("Millimeters"), _("Inches"), ""};
38static const wxString units5_names[] = {_("Percentage"), ""};
39static const wxString units6_names[] = {_("j/kg"), ""};
40static const wxString units7_names[] = {_("Knots"), _("m/s"), _("mph"),
41 _("km/h"), ""};
42static const wxString units8_names[] = {_("dBZ"), ""};
43static const wxString *unit_names[] = {
44 units0_names, units1_names, units2_names, units3_names, units4_names,
45 units5_names, units6_names, units7_names, units8_names};
46
47static const wxString name_from_index[] = {"Wind",
48 "WindGust",
49 "Pressure",
50 "Waves",
51 "Current",
52 "Rainfall",
53 "CloudCover",
54 "AirTemperature",
55 "SeaTemperature",
56 "CAPE",
57 "CompositeReflectivity",
58 "Altitude",
59 "RelativeHumidity"};
60static const wxString tname_from_index[] = {_("Wind"),
61 _("Wind Gust"),
62 _("Pressure"),
63 _("Waves"),
64 _("Current"),
65 _("Rainfall"),
66 _("Cloud Cover"),
67 _("Air Temperature"),
68 _("Sea Temperature"),
69 _("CAPE"),
70 "Composite Reflectivity",
71 _("Altitude(Geopotential)"),
72 _("Relative Humidity")};
73
74static const int unittype[GribOverlaySettings::SETTINGS_COUNT] = {
75 0, 0, 1, 2, 7, 4, 5, 3, 3, 6, 8, 2, 5};
76
77static const int minuttes_from_index[] = {2, 5, 10, 20, 30, 60,
78 90, 180, 360, 720, 1440};
79
80static const wxString altitude_from_index[3][5] = {
81 {"Std", "850", "700", "500", "300"},
82 {"Std", "637", "525", "375", "225"},
83 {"Std", "25.2", "20.7", "14.8", "8.9"}};
84
85#ifdef __ANDROID__
86
87QString qtStyleSheet =
88 "QScrollBar:horizontal {\
89border: 0px solid grey;\
90background-color: rgb(240, 240, 240);\
91height: 35px;\
92margin: 0px 1px 0 1px;\
93}\
94QScrollBar::handle:horizontal {\
95background-color: rgb(200, 200, 200);\
96min-width: 20px;\
97border-radius: 10px;\
98}\
99QScrollBar::add-line:horizontal {\
100border: 0px solid grey;\
101background: #32CC99;\
102width: 0px;\
103subcontrol-position: right;\
104subcontrol-origin: margin;\
105}\
106QScrollBar::sub-line:horizontal {\
107border: 0px solid grey;\
108background: #32CC99;\
109width: 0px;\
110subcontrol-position: left;\
111subcontrol-origin: margin;\
112}\
113QScrollBar:vertical {\
114border: 0px solid grey;\
115background-color: rgb(240, 240, 240);\
116width: 35px;\
117margin: 1px 0px 1px 0px;\
118}\
119QScrollBar::handle:vertical {\
120background-color: rgb(200, 200, 200);\
121min-height: 20px;\
122border-radius: 10px;\
123}\
124QScrollBar::add-line:vertical {\
125border: 0px solid grey;\
126background: #32CC99;\
127height: 0px;\
128subcontrol-position: top;\
129subcontrol-origin: margin;\
130}\
131QScrollBar::sub-line:vertical {\
132border: 0px solid grey;\
133background: #32CC99;\
134height: 0px;\
135subcontrol-position: bottom;\
136subcontrol-origin: margin;\
137}\
138QCheckBox {\
139spacing: 25px;\
140}\
141QCheckBox::indicator {\
142width: 30px;\
143height: 30px;\
144}\
145";
146
147#endif
148
149extern int m_DialogStyle;
150
151wxString GribOverlaySettings::GetAltitudeFromIndex(int index, int unit) {
152 return wxGetTranslation(altitude_from_index[unit][index]);
153}
154
155int GribOverlaySettings::GetMinFromIndex(int index) {
156 return minuttes_from_index[index];
157}
158
159wxString GribOverlaySettings::NameFromIndex(int index) {
160 return wxGetTranslation(tname_from_index[index]);
161}
162
163void GribOverlaySettings::Read() {
164 /* read settings here */
165 wxFileConfig *pConf = GetOCPNConfigObject();
166
167 if (!pConf) return;
168
169 pConf->SetPath("/PlugIns/GRIB");
170 // Overlay general parameter
171 pConf->Read("OverlayTransparency", &m_iOverlayTransparency, 220);
172 // Playback Options
173 pConf->Read("LoopMode", &m_bLoopMode, false);
174 pConf->Read("LoopStartPoint", &m_LoopStartPoint, 0);
175 pConf->Read("SlicesPerUpdate", &m_SlicesPerUpdate, 5);
176 pConf->Read("UpdatesPerSecond", &m_UpdatesPerSecond, 4);
177 pConf->Read("Interpolate", &m_bInterpolate, false);
178 // gui options
179 m_iCtrlandDataStyle = m_DialogStyle;
180 wxString s1, s2;
181 wxString const dflt = "XXXXXXXXX";
182 pConf->Read("CtrlBarCtrlVisibility1", &s1, dflt);
183 if (s1.Len() != dflt.Len()) s1 = dflt;
184 pConf->Read("CtrlBarCtrlVisibility2", &s2, dflt);
185 if (s2.Len() != dflt.Len()) s2 = dflt;
186 m_iCtrlBarCtrlVisible[0] = s1;
187 m_iCtrlBarCtrlVisible[1] = s2;
188 // data options
189 for (int i = 0; i < SETTINGS_COUNT; i++) {
190 wxString Name = name_from_index[i];
191
192 int units;
193 pConf->Read(Name + "Units", &units, 0);
194 int j;
195 for (j = 0; !unit_names[unittype[i]][j].empty(); j++);
196 Settings[i].m_Units =
197 (units < 0 || units > j - 1) ? (SettingsType)0 : (SettingsType)units;
198
199 pConf->Read(Name + "BarbedArrows", &Settings[i].m_bBarbedArrows, i == WIND);
200 pConf->Read(Name + "BarbedVisibility", &Settings[i].m_iBarbedVisibility,
201 i == WIND);
202 pConf->Read(Name + "BarbedColors", &Settings[i].m_iBarbedColour, 0);
203 pConf->Read(Name + "BarbedArrowFixedSpacing",
204 &Settings[i].m_bBarbArrFixSpac, false);
205 pConf->Read(Name + "BarbedArrowSpacing", &Settings[i].m_iBarbArrSpacing,
206 50);
207
208 pConf->Read(Name + "Display Isobars", &Settings[i].m_bIsoBars,
209 i == PRESSURE);
210 pConf->Read(Name + "Abbreviated Isobars Numbers",
211 &Settings[i].m_bAbbrIsoBarsNumbers, i == PRESSURE);
212
213 double defspacing[SETTINGS_COUNT] = {4, 4, 4, 0, 0, 0, 0, 2, 2, 100};
214 pConf->Read(Name + "IsoBarSpacing", &Settings[i].m_iIsoBarSpacing,
215 defspacing[i]);
216 pConf->Read(Name + "IsoBarVisibility", &Settings[i].m_iIsoBarVisibility,
217 i == PRESSURE);
218
219 pConf->Read(Name + "DirectionArrows", &Settings[i].m_bDirectionArrows,
220 i == CURRENT || i == WAVE);
221 double defform[SETTINGS_COUNT] = {0, 0, 0, 0, 1, 0, 0, 0, 0, 0};
222 pConf->Read(Name + "DirectionArrowForm", &Settings[i].m_iDirectionArrowForm,
223 defform[i]);
224 pConf->Read(Name + "DirectionArrowSize", &Settings[i].m_iDirectionArrowSize,
225 0);
226 pConf->Read(Name + "DirectionArrowFixedSpacing",
227 &Settings[i].m_bDirArrFixSpac, false);
228 pConf->Read(Name + "DirectionArrowSpacing", &Settings[i].m_iDirArrSpacing,
229 50);
230
231 pConf->Read(Name + "OverlayMap", &Settings[i].m_bOverlayMap,
232 i != WIND && i != PRESSURE);
233 int defcolor[SETTINGS_COUNT] = {1, 1, 0, 0, 6, 4, 5, 2, 3, 7};
234 pConf->Read(Name + "OverlayMapColors", &Settings[i].m_iOverlayMapColors,
235 defcolor[i]);
236
237 pConf->Read(Name + "Numbers", &Settings[i].m_bNumbers, false);
238 pConf->Read(Name + "NumbersFixedSpacing", &Settings[i].m_bNumFixSpac,
239 false);
240 pConf->Read(Name + "NumbersSpacing", &Settings[i].m_iNumbersSpacing, 50);
241
242 pConf->Read(Name + "Particles", &Settings[i].m_bParticles, false);
243 pConf->Read(Name + "ParticleDensity", &Settings[i].m_dParticleDensity, 1.0);
244 }
245}
246
247void GribOverlaySettings::Write() {
248 /* save settings here */
249 wxFileConfig *pConf = GetOCPNConfigObject();
250
251 if (!pConf) return;
252
253 pConf->SetPath("/PlugIns/GRIB");
254 // Overlay general parameter
255 pConf->Write("OverlayTransparency", m_iOverlayTransparency);
256 // playback options
257 pConf->Write("Interpolate", m_bInterpolate);
258 pConf->Write("LoopMode", m_bLoopMode);
259 pConf->Write("LoopStartPoint", m_LoopStartPoint);
260 pConf->Write("SlicesPerUpdate", m_SlicesPerUpdate);
261 pConf->Write("UpdatesPerSecond", m_UpdatesPerSecond);
262 // gui options
263 pConf->Write("GribCursorDataDisplayStyle", m_iCtrlandDataStyle);
264 wxString s1 = m_iCtrlBarCtrlVisible[0], s2 = m_iCtrlBarCtrlVisible[1];
265 pConf->Write("CtrlBarCtrlVisibility1", s1);
266 pConf->Write("CtrlBarCtrlVisibility2", s2);
267
268 for (int i = 0; i < SETTINGS_COUNT; i++) {
269 pConf->Write(name_from_index[i] + "Units", (int)Settings[i].m_Units);
270
271 if (i == WIND) {
272 SaveSettingGroups(pConf, i, B_ARROWS);
273 SaveSettingGroups(pConf, i, ISO_LINE_SHORT);
274 SaveSettingGroups(pConf, i, OVERLAY);
275 SaveSettingGroups(pConf, i, NUMBERS);
276 SaveSettingGroups(pConf, i, PARTICLES);
277 } else if (i == WIND_GUST || i == AIR_TEMPERATURE || i == SEA_TEMPERATURE ||
278 i == CAPE || i == COMP_REFL) {
279 SaveSettingGroups(pConf, i, ISO_LINE_SHORT);
280 SaveSettingGroups(pConf, i, OVERLAY);
281 SaveSettingGroups(pConf, i, NUMBERS);
282 } else if (i == PRESSURE) {
283 SaveSettingGroups(pConf, i, ISO_LINE_SHORT);
284 SaveSettingGroups(pConf, i, ISO_LINE_VISI);
285 SaveSettingGroups(pConf, i, NUMBERS);
286 } else if (i == WAVE || i == CURRENT) {
287 SaveSettingGroups(pConf, i, D_ARROWS);
288 SaveSettingGroups(pConf, i, OVERLAY);
289 SaveSettingGroups(pConf, i, NUMBERS);
290 SaveSettingGroups(pConf, i, PARTICLES);
291 } else if (i == PRECIPITATION || i == CLOUD) {
292 SaveSettingGroups(pConf, i, OVERLAY);
293 SaveSettingGroups(pConf, i, NUMBERS);
294 }
295 }
296}
297
298void GribOverlaySettings::SaveSettingGroups(wxFileConfig *pConf, int settings,
299 int group) {
300 wxString Name = name_from_index[settings];
301
302 switch (group) {
303 case B_ARROWS:
304 pConf->Write(Name + "BarbedArrows", Settings[settings].m_bBarbedArrows);
305 pConf->Write(Name + "BarbedVisibility",
306 Settings[settings].m_iBarbedVisibility);
307 pConf->Write(Name + "BarbedColors", Settings[settings].m_iBarbedColour);
308 pConf->Write(Name + "BarbedArrowFixedSpacing",
309 Settings[settings].m_bBarbArrFixSpac);
310 pConf->Write(Name + "BarbedArrowSpacing",
311 Settings[settings].m_iBarbArrSpacing);
312 break;
313 case ISO_LINE_SHORT:
314 pConf->Write(Name + "Display Isobars", Settings[settings].m_bIsoBars);
315 pConf->Write(Name + "Abbreviated Isobars Numbers",
316 Settings[settings].m_bAbbrIsoBarsNumbers);
317 pConf->Write(Name + "IsoBarSpacing", Settings[settings].m_iIsoBarSpacing);
318 break;
319 case ISO_LINE_VISI:
320 pConf->Write(Name + "IsoBarVisibility",
321 Settings[settings].m_iIsoBarVisibility);
322 break;
323 case D_ARROWS:
324 pConf->Write(Name + "DirectionArrows",
325 Settings[settings].m_bDirectionArrows);
326 pConf->Write(Name + "DirectionArrowForm",
327 Settings[settings].m_iDirectionArrowForm);
328 pConf->Write(Name + "DirectionArrowSize",
329 Settings[settings].m_iDirectionArrowSize);
330 pConf->Write(Name + "DirectionArrowFixedSpacing",
331 Settings[settings].m_bDirArrFixSpac);
332 pConf->Write(Name + "DirectionArrowSpacing",
333 Settings[settings].m_iDirArrSpacing);
334 break;
335 case OVERLAY:
336 pConf->Write(Name + "OverlayMap", Settings[settings].m_bOverlayMap);
337 pConf->Write(Name + "OverlayMapColors",
338 Settings[settings].m_iOverlayMapColors);
339 break;
340 case NUMBERS:
341 pConf->Write(Name + "Numbers", Settings[settings].m_bNumbers);
342 pConf->Write(Name + "NumbersFixedSpacing",
343 Settings[settings].m_bNumFixSpac);
344 pConf->Write(Name + "NumbersSpacing",
345 Settings[settings].m_iNumbersSpacing);
346 break;
347 case PARTICLES:
348 pConf->Write(Name + "Particles", Settings[settings].m_bParticles);
349 pConf->Write(Name + "ParticleDensity",
350 Settings[settings].m_dParticleDensity);
351 break;
352 default:
353 assert(false && "SaveSettinsGroup: Illegal group");
354 }
355}
356
357double GribOverlaySettings::CalibrationOffset(int settings) {
358 switch (unittype[settings]) {
359 case 3:
360 switch (
361 Settings[settings].m_Units) { /* only have offset for temperature */
362 case CELCIUS:
363 return -273.15;
364 case FAHRENHEIT:
365 return -273.15 + 32 * 5 / 9.0;
366 }
367 break;
368 }
369
370 return 0;
371}
372
373double GribOverlaySettings::CalibrationFactor(int settings, double input,
374 bool reverse) {
375 switch (unittype[settings]) {
376 case 7:
377 case 0:
378 switch (Settings[settings].m_Units) {
379 case KNOTS:
380 return 3.6 / 1.852;
381 case M_S:
382 return 1;
383 case MPH:
384 return 3.6 / 1.60934;
385 case KPH:
386 return 3.6;
387 case BFS:
388 return (reverse) ? GetbftomsFactor(input) : GetmstobfFactor(input);
389 }
390 break;
391 case 1:
392 switch (Settings[settings].m_Units) {
393 case MILLIBARS:
394 return 1 / 100.;
395 case MMHG:
396 return 1 / (100. * 1.333);
397 case INHG:
398 return 1 / (100. * 33.864);
399 }
400 break;
401 case 2:
402 switch (Settings[settings].m_Units) {
403 case METERS:
404 return 1;
405 case FEET:
406 return 3.28;
407 }
408 break;
409 case 3:
410 switch (Settings[settings].m_Units) {
411 case CELCIUS:
412 return 1;
413 case FAHRENHEIT:
414 return 9. / 5;
415 }
416 break;
417 case 4:
418 switch (Settings[settings].m_Units) {
419 case MILLIMETERS:
420 return 1;
421 case INCHES:
422 return 1. / 25.4;
423 }
424 break;
425 case 5:
426 case 6:
427 case 8:
428 return 1;
429 }
430
431 return 1;
432}
433
434/*
435Beaufort scale
436 force in knots in m/s in knots
437 0 < 1 <0.5 < 1
438 1 from 1 0.5 to 3
439 2 4 2.1 6
440 3 7 3.6 10
441 4 11 5.7 16
442 5 17 8.7 21
443 6 22 11.3 27
444 7 28 14.4 33
445 8 34 17.5 40
446 9 41 21.1 47
447 10 48 24.7 55
448 11 56 28.8 63
449 12 >= 64 >= 32.9 >= 64
450*/
451
452double GribOverlaySettings::GetmstobfFactor(double input) {
453 double val = fabs(input);
454 // find bf value ( m/s ) and return the corresponding factor
455 if (val < 0.5) return 0;
456 if (val < 2.1) return 1 / input;
457 if (val < 3.6) return 2 / input;
458 if (val < 5.7) return 3 / input;
459 if (val < 8.7) return 4 / input;
460 if (val < 11.3) return 5 / input;
461 if (val < 14.4) return 6 / input;
462 if (val < 17.5) return 7 / input;
463 if (val < 21.1) return 8 / input;
464 if (val < 24.7) return 9 / input;
465 if (val < 28.8) return 10 / input;
466 if (val < 32.9) return 11 / input;
467 return 12 / input;
468}
469
470double GribOverlaySettings::GetbftomsFactor(double input) {
471 // find the limit value in m/s in Beaufort scale and return the corresponding
472 // factor
473 switch ((int)input) {
474 case 1:
475 return input / 0.5;
476 case 2:
477 return input / 2.1;
478 case 3:
479 return input / 3.6;
480 case 4:
481 return input / 5.7;
482 case 5:
483 return input / 8.7;
484 case 6:
485 return input / 11.3;
486 case 7:
487 return input / 14.4;
488 case 8:
489 return input / 17.5;
490 case 9:
491 return input / 21.1;
492 case 10:
493 return input / 24.7;
494 case 11:
495 return input / 28.7;
496 case 12:
497 return input / 32.9;
498 }
499 return 1;
500}
501
502wxString GribOverlaySettings::GetUnitSymbol(int settings) {
503 switch (unittype[settings]) {
504 case 0:
505 switch (Settings[settings].m_Units) {
506 case KNOTS:
507 return "kts";
508 case M_S:
509 return "m/s";
510 case MPH:
511 return "mph";
512 case KPH:
513 return "km/h";
514 case BFS:
515 return "bf";
516 }
517 break;
518 case 1:
519 switch (Settings[settings].m_Units) {
520 case MILLIBARS:
521 return "hPa";
522 case MMHG:
523 return "mmHg";
524 case INHG:
525 return "inHg";
526 }
527 break;
528 case 2:
529 switch (Settings[settings].m_Units) {
530 case METERS:
531 return "m";
532 case FEET:
533 return "ft";
534 }
535 break;
536 case 3:
537 switch (Settings[settings].m_Units) {
538 case CELCIUS:
539 return "\u00B0C";
540 case FAHRENHEIT:
541 return "\u00B0F";
542 }
543 break;
544 case 4:
545 switch (Settings[settings].m_Units) {
546 case MILLIMETERS:
547 return "mm";
548 case INCHES:
549 return "in";
550 }
551 break;
552 case 5:
553 switch (Settings[settings].m_Units) {
554 case PERCENTAGE:
555 return "%";
556 }
557 break;
558 case 6:
559 switch (Settings[settings].m_Units) {
560 case JPKG:
561 return "j/kg";
562 }
563 break;
564 case 7:
565 switch (Settings[settings].m_Units) {
566 case KNOTS:
567 return "kts";
568 case M_S:
569 return "m/s";
570 case MPH:
571 return "mph";
572 case KPH:
573 return "km/h";
574 }
575 break;
576 case 8:
577 switch (Settings[settings].m_Units) {
578 case DBZ:
579 return "dBZ";
580 }
581 break;
582 }
583 return "";
584}
585
586double GribOverlaySettings::GetMin(int settings) {
587 double min = 0;
588 switch (settings) {
589 case PRESSURE:
590 min = 84000;
591 break; /* 100's of millibars */
592 case AIR_TEMPERATURE:
593 min = 273.15 - 40;
594 break; /* kelvin */
595 case SEA_TEMPERATURE:
596 min = 273.15 - 2;
597 break; /* kelvin */
598 }
599 return CalibrateValue(settings, min);
600}
601
602double GribOverlaySettings::GetMax(int settings) {
603 double max = 0;
604 switch (settings) {
605 case WIND:
606 max = 40;
607 break; /* m/s */
608 case WIND_GUST:
609 max = 40;
610 break; /* m/s */
611 case PRESSURE:
612 max = 112000;
613 break; /* 100s of millibars */
614 case WAVE:
615 max = 30;
616 break; /* meters */
617 case CURRENT:
618 max = 12;
619 break; /* m/s */
620 case PRECIPITATION:
621 max = 80;
622 break; /* mm */
623 case CLOUD:
624 max = 100;
625 break; /* percent */
626 case AIR_TEMPERATURE:
627 max = 273.15 + 50;
628 break; /* kelvin */
629 case SEA_TEMPERATURE:
630 max = 273.15 + 56;
631 break; /* kelvin */
632 case CAPE:
633 max = 3500;
634 break; /* j/kg */
635 case COMP_REFL:
636 max = 80;
637 break; /* dBZ */
638 }
639 return CalibrateValue(settings, max);
640}
641
642GribSettingsDialog::GribSettingsDialog(GRIBUICtrlBar &parent,
643 GribOverlaySettings &Settings,
644 int &lastdatatype, int fileIntervalIndex)
645 : GribSettingsDialogBase(&parent),
646 m_parent(parent),
647 m_extSettings(Settings),
648 m_lastdatatype(lastdatatype) {
649 m_Settings = m_extSettings;
650 // populate interval choice
651 m_sSlicesPerUpdate->Clear();
652 for (int i = 0; i < fileIntervalIndex + 1; i++) {
653 int mn = m_Settings.GetMinFromIndex(i);
654 m_sSlicesPerUpdate->Append(wxString::Format("%2d ", mn / 60) + _("h") +
655 wxString::Format(" %.2d ", mn % 60) + _("mn"));
656 }
657 // Set Bitmap
658 m_biAltitude->SetBitmap(parent.GetScaledBitmap(wxBitmap(altitude), "altitude",
659 parent.GetScaleFactor()));
660 m_biNow->SetBitmap(
661 parent.GetScaledBitmap(wxBitmap(now), "now", parent.GetScaleFactor()));
662 m_biZoomToCenter->SetBitmap(parent.GetScaledBitmap(wxBitmap(zoomto), "zoomto",
663 parent.GetScaleFactor()));
664 m_biShowCursorData->SetBitmap(parent.GetScaledBitmap(
665 parent.m_CDataIsShown ? wxBitmap(curdata) : wxBitmap(ncurdata),
666 parent.m_CDataIsShown ? "curdata" : "ncurdata", parent.GetScaleFactor()));
667 m_biPlay->SetBitmap(
668 parent.GetScaledBitmap(wxBitmap(play), "play", parent.GetScaleFactor()));
669 m_biTimeSlider->SetBitmap(parent.GetScaledBitmap(wxBitmap(slider), "slider",
670 parent.GetScaleFactor()));
671 m_biOpenFile->SetBitmap(parent.GetScaledBitmap(wxBitmap(openfile), "openfile",
672 parent.GetScaleFactor()));
673 m_biSettings->SetBitmap(parent.GetScaledBitmap(wxBitmap(setting), "setting",
674 parent.GetScaleFactor()));
675 m_biRequest->SetBitmap(parent.GetScaledBitmap(wxBitmap(request), "request",
676 parent.GetScaleFactor()));
677 // read bookpage
678 wxFileConfig *pConf = GetOCPNConfigObject();
679 if (pConf) {
680 pConf->SetPath("/Settings/GRIB");
681 pConf->Read("GribSettingsBookPageIndex", &m_SetBookpageIndex, 0);
682 }
683
684 m_cInterpolate->SetValue(m_Settings.m_bInterpolate);
685 m_cLoopMode->SetValue(m_Settings.m_bLoopMode);
686 m_cLoopStartPoint->SetSelection(m_Settings.m_LoopStartPoint);
687 m_sSlicesPerUpdate->SetSelection(m_Settings.m_SlicesPerUpdate);
688 m_sUpdatesPerSecond->SetValue(m_Settings.m_UpdatesPerSecond);
689 m_sTransparency->SetValue(
690 100. - ((float)m_Settings.m_iOverlayTransparency * 100. / 254.));
691 if (!m_cInterpolate->IsChecked()) { // eventually disable parameters
692 m_tSlicesPerUpdate->Disable();
693 m_sSlicesPerUpdate->Disable();
694 }
695 if (!m_cLoopMode->IsChecked()) {
696 m_staticText26->Disable();
697 m_cLoopStartPoint->Disable();
698 }
699
700 m_rbCurDataAttaWCap->SetValue(m_Settings.m_iCtrlandDataStyle == 0);
701 m_rbCurDataAttaWoCap->SetValue(m_Settings.m_iCtrlandDataStyle == 1);
702 m_rbCurDataIsolHoriz->SetValue(m_Settings.m_iCtrlandDataStyle == 2);
703 m_rbCurDataIsolVertic->SetValue(m_Settings.m_iCtrlandDataStyle == 3);
704
705 for (unsigned int i = 0; i < (m_Settings.m_iCtrlBarCtrlVisible[0].Len() * 2);
706 i += 2) {
707 ((wxCheckBox *)FindWindow(i + AC0))
708 ->SetValue(m_Settings.m_iCtrlBarCtrlVisible[0].GetChar(i / 2) == 'X');
709 ((wxCheckBox *)FindWindow(i + 1 + AC0))
710 ->SetValue(m_Settings.m_iCtrlBarCtrlVisible[1].GetChar(i / 2) == 'X');
711 }
712
713 m_cDataType->Clear();
714 for (int i = 0; i < GribOverlaySettings::SETTINGS_COUNT; i++)
715 m_cDataType->Append(wxGetTranslation(tname_from_index[i]));
716
717 m_cDataType->SetSelection(m_lastdatatype);
718 PopulateUnits(m_lastdatatype);
719 ReadDataTypeSettings(m_lastdatatype);
720 m_sButtonApply->SetLabel(_("Apply"));
721
722 DimeWindow(this); // apply global colours scheme
723
724#ifdef __ANDROID__
725 GetHandle()->setStyleSheet(qtStyleSheet);
726#endif
727
728 wxWindow::Fit();
729}
730
731void GribSettingsDialog::SaveLastPage() {
732 wxFileConfig *pConf = GetOCPNConfigObject();
733
734 if (pConf) {
735 pConf->SetPath("/Settings/GRIB");
736
737 pConf->Write("GribSettingsBookPageIndex", m_SetBookpageIndex);
738 }
739}
740
741void GribSettingsDialog::OnPageChange(wxNotebookEvent &event) {
742 m_SetBookpageIndex = event.GetSelection();
743 SetSettingsDialogSize();
744}
745
746void GribSettingsDialog::SetSettingsDialogSize() {
747#ifdef __ANDROID__
748 /*Sizing do not work with wxScolledWindow so we need to compute it
749 using fixed X/Y margin to try to center nicely the dialog in the screen*/
750 int wt, ht, w, h;
751 ::wxDisplaySize(&wt, &ht); // the screen size
752
753 int XMargin = 100, YMargin = 200; // set margins
754 w = wt - XMargin; // maximum scolled window size
755 h = ht - (m_sButton->GetSize().GetY() + YMargin);
756 wxSize scroll(0, 0);
757#else
758 /*Sizing do not work with wxScolledWindow so we need to compute it*/
759
760 wxWindow *frame = wxTheApp->GetTopWindow();
761
762 int w = frame->GetClientSize().x; // the display size
763 int h = frame->GetClientSize().y;
764 int dMargin = 80; // set a margin
765 w -= dMargin; // width available for the scrolled window
766 h -= (2 * m_sButton->GetSize().GetY()) +
767 dMargin; // height available for the scrolled window
768 // two times the button's height to handle pages tab's height
769#endif
770#ifdef __WXGTK__
771 SetMinSize(wxSize(10, 10));
772#endif
773
774 int display_width, display_height;
775 wxDisplaySize(&display_width, &display_height);
776
777 for (size_t i = 0; i < m_nSettingsBook->GetPageCount();
778 i++) { // compute and set scrolled windows size
779 wxScrolledWindow *sc = ((wxScrolledWindow *)m_nSettingsBook->GetPage(i));
780 sc->SetMinSize(wxSize(10, 10));
781 wxSize scr;
782#ifndef __WXGTK__
783 if ((int)i == m_SetBookpageIndex)
784#endif
785 {
786 switch (i) {
787 case 0:
788 scr = m_fgSetDataSizer->Fit(sc);
789 break;
790 case 1:
791 // set a reasonable speed slider's width
792 m_sUpdatesPerSecond->SetMinSize(
793 wxSize(m_cLoopStartPoint->GetSize().x, -1));
794 scr = m_fgSetPlaybackSizer->Fit(sc);
795 break;
796 case 2:
797 scr = m_fgSetGuiSizer->Fit(sc);
798 }
799 sc->SetMinSize(wxSize(wxMin(scr.x, w), wxMin(scr.y, h)));
800 sc->SetSize(wxSize(wxMin(scr.x, w), wxMin(scr.y, h)));
801
802 // Constrain size on small displays
803 if (display_height < 600) {
804 sc->SetSize(scr.x, h);
805 }
806
807#if defined __WXMSW__ || defined(__WXOSX__)
808 sc->Show();
809#endif
810 }
811 } // end compute
812
813#ifdef __ANDROID__
814 m_nSettingsBook->SetSize(wt, -1);
815#endif
816
817 Layout();
818 Fit();
819#ifdef __WXGTK__
820 wxSize sd = GetSize();
821 if (sd.y == GetClientSize().y) sd.y += 30;
822 SetSize(wxSize(sd.x, sd.y));
823 SetMinSize(wxSize(sd.x, sd.y));
824#endif
825 Refresh();
826}
827
828/* set settings to the dialog controls */
829void GribSettingsDialog::WriteSettings() {
830 m_Settings.m_bInterpolate = m_cInterpolate->GetValue();
831 m_Settings.m_bLoopMode = m_cLoopMode->GetValue();
832 m_Settings.m_LoopStartPoint = m_cLoopStartPoint->GetSelection();
833 m_Settings.m_SlicesPerUpdate = m_sSlicesPerUpdate->GetCurrentSelection();
834 m_Settings.m_UpdatesPerSecond = m_sUpdatesPerSecond->GetValue();
835
836 m_Settings.m_iCtrlandDataStyle =
837 m_rbCurDataAttaWCap->GetValue() ? ATTACHED_HAS_CAPTION
838 : m_rbCurDataAttaWoCap->GetValue() ? ATTACHED_NO_CAPTION
839 : m_rbCurDataIsolHoriz->GetValue() ? SEPARATED_HORIZONTAL
840 : SEPARATED_VERTICAL;
841
842 for (unsigned int i = 0; i < (m_Settings.m_iCtrlBarCtrlVisible[0].Len() * 2);
843 i += 2) {
844 m_Settings.m_iCtrlBarCtrlVisible[0].SetChar(
845 i / 2, ((wxCheckBox *)FindWindow(i + AC0))->GetValue() ? 'X' : '.');
846 m_Settings.m_iCtrlBarCtrlVisible[1].SetChar(
847 i / 2, ((wxCheckBox *)FindWindow(i + 1 + AC0))->GetValue() ? 'X' : '.');
848 }
849
850 SetDataTypeSettings(m_lastdatatype);
851
852 m_extSettings = m_Settings;
853 m_DialogStyle = m_Settings.m_iCtrlandDataStyle;
854}
855
856void GribSettingsDialog::SetDataTypeSettings(int settings) {
857 GribOverlaySettings::OverlayDataSettings &odc = m_Settings.Settings[settings];
858 odc.m_Units = m_cDataUnits->GetSelection();
859 odc.m_bBarbedArrows = m_cbBarbedArrows->GetValue();
860 odc.m_iBarbedVisibility = m_cBarbedVisibility->GetValue();
861 odc.m_iBarbedColour = m_cBarbedColours->GetSelection();
862 odc.m_bBarbArrFixSpac = m_cBarbArrFixSpac->GetValue();
863 odc.m_iBarbArrSpacing = m_sBarbArrSpacing->GetValue();
864 odc.m_bIsoBars = m_cbIsoBars->GetValue();
865 odc.m_bAbbrIsoBarsNumbers = m_cbAbbrIsoBarsNumbers->GetValue();
866 odc.m_iIsoBarVisibility = m_sIsoBarVisibility->GetValue();
867 odc.m_iIsoBarSpacing = m_sIsoBarSpacing->GetValue();
868 odc.m_bDirectionArrows = m_cbDirectionArrows->GetValue();
869 odc.m_iDirectionArrowForm = m_cDirectionArrowForm->GetSelection();
870 odc.m_iDirectionArrowSize = m_cDirectionArrowSize->GetSelection();
871 odc.m_bDirArrFixSpac = m_cDirArrFixSpac->GetValue();
872 odc.m_iDirArrSpacing = m_sDirArrSpacing->GetValue();
873 odc.m_bOverlayMap = m_cbOverlayMap->GetValue();
874 odc.m_iOverlayMapColors = m_cOverlayColors->GetSelection();
875 odc.m_bNumbers = m_cbNumbers->GetValue();
876 odc.m_bNumFixSpac = m_cNumFixSpac->GetValue();
877 odc.m_iNumbersSpacing = m_sNumbersSpacing->GetValue();
878 odc.m_bParticles = m_cbParticles->GetValue();
879 odc.m_dParticleDensity = 4.0 * exp(m_sParticleDensity->GetValue() - 7.0);
880}
881
882void GribSettingsDialog::ReadDataTypeSettings(int settings) {
883 GribOverlaySettings::OverlayDataSettings &odc = m_Settings.Settings[settings];
884
885 m_cDataUnits->SetSelection(odc.m_Units);
886 m_cbBarbedArrows->SetValue(odc.m_bBarbedArrows);
887 m_cBarbedVisibility->SetValue(odc.m_iBarbedVisibility);
888 m_cBarbedColours->SetSelection(odc.m_iBarbedColour);
889 m_cBarbArrFixSpac->SetValue(odc.m_bBarbArrFixSpac);
890 m_cBarbArrMinSpac->SetValue(!odc.m_bBarbArrFixSpac);
891 m_sBarbArrSpacing->SetValue(odc.m_iBarbArrSpacing);
892 m_cbIsoBars->SetValue(odc.m_bIsoBars);
893 m_cbAbbrIsoBarsNumbers->SetValue(odc.m_bAbbrIsoBarsNumbers);
894 m_sIsoBarVisibility->SetValue(odc.m_iIsoBarVisibility);
895 m_sIsoBarSpacing->SetValue(odc.m_iIsoBarSpacing);
896 m_cbDirectionArrows->SetValue(odc.m_bDirectionArrows);
897 m_cDirectionArrowForm->SetSelection(odc.m_iDirectionArrowForm);
898 m_cDirectionArrowSize->SetSelection(odc.m_iDirectionArrowSize);
899 m_cDirArrFixSpac->SetValue(odc.m_bDirArrFixSpac);
900 m_cDirArrMinSpac->SetValue(!odc.m_bDirArrFixSpac);
901 m_sDirArrSpacing->SetValue(odc.m_iDirArrSpacing);
902 m_cbOverlayMap->SetValue(odc.m_bOverlayMap);
903 m_cOverlayColors->SetSelection(odc.m_iOverlayMapColors);
904 m_cbNumbers->SetValue(odc.m_bNumbers);
905 m_cNumFixSpac->SetValue(odc.m_bNumFixSpac);
906 m_cNumMinSpac->SetValue(!odc.m_bNumFixSpac);
907 m_sNumbersSpacing->SetValue(odc.m_iNumbersSpacing);
908 m_cbParticles->SetValue(odc.m_bParticles);
909 m_sParticleDensity->SetValue(log(odc.m_dParticleDensity / 4.0) + 7);
910
911 ShowFittingSettings(settings);
912}
913
914void GribSettingsDialog::ShowFittingSettings(int settings) {
915 // Hide all Parameters
916 ShowSettings(B_ARROWS, false);
917 ShowSettings(ISO_LINE, false);
918 if (m_fIsoBarSpacing->GetItem(m_sIsoBarSpacing) != nullptr)
919 m_fIsoBarSpacing->Detach(m_sIsoBarSpacing);
920 if (m_fIsoBarVisibility->GetItem(m_sIsoBarSpacing) != nullptr)
921 m_fIsoBarVisibility->Detach(m_sIsoBarSpacing);
922 if (m_fIsoBarVisibility->GetItem(m_sIsoBarVisibility) != nullptr)
923 m_fIsoBarVisibility->Detach(m_sIsoBarVisibility);
924 ShowSettings(ISO_ABBR, false);
925 ShowSettings(D_ARROWS, false);
926 ShowSettings(OVERLAY, false);
927 ShowSettings(NUMBERS, false);
928 ShowSettings(PARTICLES, false);
929 this->Fit();
930 // Show only fitting parameters
931 switch (settings) {
932 case GribOverlaySettings::WIND:
933 ShowSettings(ISO_LINE_SHORT);
934 ShowSettings(ISO_LINE);
935 m_cbIsoBars->SetLabel(_("Display Isotachs"));
936 ShowSettings(B_ARROWS);
937 ShowSettings(OVERLAY);
938 ShowSettings(NUMBERS);
939 ShowSettings(PARTICLES);
940 break;
941 case GribOverlaySettings::WIND_GUST:
942 ShowSettings(ISO_LINE_SHORT);
943 ShowSettings(ISO_LINE);
944 m_cbIsoBars->SetLabel(_("Display Isotachs"));
945 ShowSettings(OVERLAY);
946 ShowSettings(NUMBERS);
947 break;
948 case GribOverlaySettings::PRESSURE:
949 ShowSettings(ISO_LINE_VISI);
950 ShowSettings(ISO_LINE);
951 m_cbIsoBars->SetLabel(_("Display Isobars"));
952 ShowSettings(ISO_ABBR);
953 ShowSettings(NUMBERS);
954 break;
955 case GribOverlaySettings::CURRENT:
956 ShowSettings(PARTICLES); // should we allow particles for waves?
957 case GribOverlaySettings::WAVE:
958 ShowSettings(D_ARROWS);
959 ShowSettings(OVERLAY);
960 ShowSettings(NUMBERS);
961 break;
962 case GribOverlaySettings::PRECIPITATION:
963 case GribOverlaySettings::CLOUD:
964 ShowSettings(OVERLAY);
965 ShowSettings(NUMBERS);
966 break;
967 case GribOverlaySettings::AIR_TEMPERATURE:
968 case GribOverlaySettings::SEA_TEMPERATURE:
969 ShowSettings(ISO_LINE_SHORT);
970 ShowSettings(ISO_LINE);
971 m_cbIsoBars->SetLabel(_("Display Isotherms"));
972 ShowSettings(OVERLAY);
973 ShowSettings(NUMBERS);
974 break;
975 case GribOverlaySettings::CAPE:
976 ShowSettings(ISO_LINE_SHORT);
977 ShowSettings(ISO_LINE);
978 m_cbIsoBars->SetLabel(_("Display Iso CAPE"));
979 ShowSettings(OVERLAY);
980 ShowSettings(NUMBERS);
981 break;
982 case GribOverlaySettings::COMP_REFL:
983 ShowSettings(ISO_LINE_SHORT);
984 ShowSettings(ISO_LINE);
985 m_cbIsoBars->SetLabel(_("Display Comp. Reflectivity"));
986 ShowSettings(OVERLAY);
987 ShowSettings(NUMBERS);
988 break;
989 }
990
991 wxString l = (m_lastdatatype == GribOverlaySettings::PRESSURE &&
992 m_cDataUnits->GetSelection() == GribOverlaySettings::INHG)
993 ? "(0.03 "
994 : "(";
995 m_tIsoBarSpacing->SetLabel(
996 wxString(_("Spacing"))
997 .Append(l)
998 .Append(m_Settings.GetUnitSymbol(m_lastdatatype))
999 .Append(")"));
1000}
1001
1002void GribSettingsDialog::ShowSettings(int params, bool show) {
1003 switch (params) {
1004 case B_ARROWS:
1005 m_cbBarbedArrows->Show(show);
1006 m_fgBarbedData1->ShowItems(show);
1007 m_fgBarbedData2->ShowItems(show);
1008 break;
1009 case ISO_LINE:
1010 m_cbIsoBars->Show(show);
1011 m_fIsoBarSpacing->ShowItems(show);
1012 m_fIsoBarVisibility->ShowItems(show);
1013 break;
1014 case ISO_ABBR:
1015 m_cbAbbrIsoBarsNumbers->Show(show);
1016 break;
1017 case ISO_LINE_VISI:
1018 m_fIsoBarSpacing->Add(m_sIsoBarSpacing, 0, 5, wxALL | wxEXPAND);
1019 m_fIsoBarVisibility->Add(m_sIsoBarVisibility, 0, 5,
1020 wxTOP | wxLEFT | wxEXPAND);
1021 // m_sIsoBarSpacing->SetMinSize(wxSize(70, -1));
1022 break;
1023 case ISO_LINE_SHORT:
1024 m_fIsoBarVisibility->Add(m_sIsoBarSpacing, 0, 5,
1025 wxTOP | wxLEFT | wxEXPAND);
1026 // m_sIsoBarSpacing->SetMinSize(wxSize(-1, -1));
1027 break;
1028 case D_ARROWS:
1029 m_cbDirectionArrows->Show(show);
1030 m_fgDirArrData1->ShowItems(show);
1031 m_fgDirArrData2->ShowItems(show);
1032 break;
1033 case OVERLAY:
1034 m_cbOverlayMap->Show(show);
1035 m_tOverlayColors->Show(show);
1036 m_cOverlayColors->Show(show);
1037 break;
1038 case NUMBERS:
1039 m_cbNumbers->Show(show);
1040 m_fgNumData1->ShowItems(show);
1041 m_sNumbersSpacing->Show(show);
1042 break;
1043 case PARTICLES:
1044 m_cbParticles->Show(show);
1045 m_ctParticles->Show(show);
1046 m_sParticleDensity->Show(show);
1047 break;
1048 }
1049}
1050
1051void GribSettingsDialog::PopulateUnits(int settings) {
1052 m_cDataUnits->Clear();
1053 for (int i = 0; !unit_names[unittype[m_lastdatatype]][i].empty(); i++)
1054 m_cDataUnits->Append(
1055 wxGetTranslation((unit_names[unittype[m_lastdatatype]][i])));
1056}
1057
1058void GribSettingsDialog::OnDataTypeChoice(wxCommandEvent &event) {
1059 SetDataTypeSettings(m_lastdatatype);
1060 m_lastdatatype = m_cDataType->GetSelection();
1061 PopulateUnits(m_lastdatatype);
1062 ReadDataTypeSettings(m_lastdatatype);
1063 SetSettingsDialogSize();
1064}
1065
1066void GribSettingsDialog::OnUnitChange(wxCommandEvent &event) {
1067 m_Settings.Settings[m_lastdatatype].m_Units = m_cDataUnits->GetSelection();
1068 wxString l = (m_lastdatatype == GribOverlaySettings::PRESSURE &&
1069 m_cDataUnits->GetSelection() == GribOverlaySettings::INHG)
1070 ? "(0.03 "
1071 : "(";
1072 m_tIsoBarSpacing->SetLabel(
1073 wxString(_("Spacing"))
1074 .Append(l)
1075 .Append(m_Settings.GetUnitSymbol(m_lastdatatype))
1076 .Append(")"));
1077 SetSettingsDialogSize();
1078}
1079
1080void GribSettingsDialog::OnTransparencyChange(wxScrollEvent &event) {
1081 m_Settings.m_iOverlayTransparency =
1082 254. - ((long)m_sTransparency->GetValue() * 254. / 100.);
1083 m_extSettings.m_iOverlayTransparency = m_Settings.m_iOverlayTransparency;
1084 m_parent.SetFactoryOptions();
1085}
1086
1087void GribSettingsDialog::OnCtrlandDataStyleChanged(wxCommandEvent &event) {
1088 wxString messages;
1089 if ((m_Settings.m_iCtrlandDataStyle == 0 && !m_rbCurDataAttaWCap->GetValue()))
1090 messages.Printf(_("You want to remove the dialog title/drag bar\n"));
1091 if ((m_Settings.m_iCtrlandDataStyle != 0 && m_rbCurDataAttaWCap->GetValue()))
1092 messages.Printf(_("You want to add a title/drag bar to the dialog\n"));
1093 if (!messages.IsEmpty()) {
1094 m_parent.pPlugIn->m_DialogStyleChanged = true;
1095 messages.Append(
1096 _("This change needs a complete reload.\nIt will be applied after "
1097 "closing and re-opening the plugin"));
1098 OCPNMessageBox_PlugIn(this, messages);
1099 }
1100}
1101
1102void GribSettingsDialog::OnApply(wxCommandEvent &event) {
1103 if (m_Settings.Settings[GribOverlaySettings::WIND].m_Units !=
1104 m_extSettings.Settings[GribOverlaySettings::WIND].m_Units &&
1105 (m_Settings.Settings[GribOverlaySettings::WIND].m_Units ==
1106 GribOverlaySettings::BFS ||
1107 m_extSettings.Settings[GribOverlaySettings::WIND].m_Units ==
1108 GribOverlaySettings::BFS))
1109 m_parent.m_old_DialogStyle =
1110 STARTING_STATE_STYLE; // must recompute dialogs size
1111
1112 WriteSettings();
1113 m_parent.SetFactoryOptions();
1114 m_parent.SetDialogsStyleSizePosition(true);
1115}
1116
1117void GribSettingsDialog::OnIntepolateChange(wxCommandEvent &event) {
1118 if (m_cInterpolate->IsChecked()) {
1120 this,
1121 _("You have chosen to authorize interpolation.\nDon't forget that data "
1122 "displayed will not be real but recomputed\nThis can decrease "
1123 "accuracy!"),
1124 _("Warning!"));
1125 m_tSlicesPerUpdate->Enable();
1126 m_sSlicesPerUpdate->Enable();
1127 } else { // hide no suiting parameters
1128 m_tSlicesPerUpdate->Disable();
1129 m_sSlicesPerUpdate->Disable();
1130 }
1131 if (m_cLoopMode->IsChecked()) {
1132 m_staticText26->Enable();
1133 m_cLoopStartPoint->Enable();
1134 } else {
1135 m_staticText26->Disable();
1136 m_cLoopStartPoint->Disable();
1137 }
1138 Refresh();
1139 // SetSettingsDialogSize();
1140}
1141
1142void GribSettingsDialog::OnSpacingModeChange(wxCommandEvent &event) {
1143 bool message = false;
1144 switch (event.GetId()) {
1145 case BARBFIXSPACING:
1146 m_cBarbArrMinSpac->SetValue(!m_cBarbArrFixSpac->IsChecked());
1147 if (m_cBarbArrFixSpac->IsChecked()) message = true;
1148 break;
1149 case BARBMINSPACING:
1150 m_cBarbArrFixSpac->SetValue(!m_cBarbArrMinSpac->IsChecked());
1151 break;
1152 case DIRFIXSPACING:
1153 m_cDirArrMinSpac->SetValue(!m_cDirArrFixSpac->IsChecked());
1154 if (m_cDirArrFixSpac->IsChecked()) message = true;
1155 break;
1156 case DIRMINSPACING:
1157 m_cDirArrFixSpac->SetValue(!m_cDirArrMinSpac->IsChecked());
1158 break;
1159 case NUMFIXSPACING:
1160 m_cNumMinSpac->SetValue(!m_cNumFixSpac->IsChecked());
1161 if (m_cNumFixSpac->IsChecked()) message = true;
1162 break;
1163 case NUMMINSPACING:
1164 m_cNumFixSpac->SetValue(!m_cNumMinSpac->IsChecked());
1165 }
1166
1167 if (message) {
1169 this,
1170 _("This option imply you authorize intrepolation\nDon't forget that "
1171 "data displayed will not be real but recomputed\nThis can decrease "
1172 "accuracy!"),
1173 _("Warning!"));
1174 }
1175}
1176
1177wxString GribOverlaySettings::SettingsToJSON(wxString json) {
1178 wxJSONValue v(json);
1179
1180 for (int i = 0; i < SETTINGS_COUNT; i++) {
1181 wxString units;
1182 units.Printf("%d", (int)Settings[i].m_Units);
1183 v[name_from_index[i] + "Units"] = units;
1184
1185 if (i == WIND) {
1186 UpdateJSONval(v, i, B_ARROWS);
1187 UpdateJSONval(v, i, ISO_LINE_SHORT);
1188 UpdateJSONval(v, i, OVERLAY);
1189 UpdateJSONval(v, i, NUMBERS);
1190 UpdateJSONval(v, i, PARTICLES);
1191 } else if (i == WIND_GUST || i == AIR_TEMPERATURE || i == SEA_TEMPERATURE ||
1192 i == CAPE || i == COMP_REFL) {
1193 UpdateJSONval(v, i, ISO_LINE_SHORT);
1194 UpdateJSONval(v, i, OVERLAY);
1195 UpdateJSONval(v, i, NUMBERS);
1196 } else if (i == PRESSURE) {
1197 UpdateJSONval(v, i, ISO_LINE_SHORT);
1198 UpdateJSONval(v, i, ISO_LINE_VISI);
1199 UpdateJSONval(v, i, NUMBERS);
1200 } else if (i == WAVE || i == CURRENT) {
1201 UpdateJSONval(v, i, D_ARROWS);
1202 UpdateJSONval(v, i, OVERLAY);
1203 UpdateJSONval(v, i, NUMBERS);
1204 UpdateJSONval(v, i, PARTICLES);
1205 } else if (i == PRECIPITATION || i == CLOUD) {
1206 UpdateJSONval(v, i, OVERLAY);
1207 UpdateJSONval(v, i, NUMBERS);
1208 }
1209 }
1210
1211 wxJSONWriter w;
1212 wxString out;
1213 w.Write(v, out);
1214 return out;
1215}
1216
1217bool GribOverlaySettings::UpdateJSONval(wxJSONValue &v, int settings,
1218 int group) {
1219 wxString Name = name_from_index[settings];
1220
1221 switch (group) {
1222 case B_ARROWS:
1223 v[Name + "BarbedArrows"] = Settings[settings].m_bBarbedArrows;
1224 v[Name + "BarbedVisibility"] = Settings[settings].m_iBarbedVisibility;
1225 v[Name + "BarbedColors"] = Settings[settings].m_iBarbedColour;
1226 v[Name + "BarbedArrowFixedSpacing"] =
1227 Settings[settings].m_bBarbArrFixSpac;
1228 v[Name + "BarbedArrowSpacing"] = Settings[settings].m_iBarbArrSpacing;
1229 break;
1230 case ISO_LINE_SHORT:
1231 v[Name + "DisplayIsobars"] = Settings[settings].m_bIsoBars;
1232 v[Name + "IsoBarSpacing"] = Settings[settings].m_iIsoBarSpacing;
1233 break;
1234 case ISO_ABBR:
1235 v[Name + "AbbrIsobarsNumbers"] = Settings[settings].m_bAbbrIsoBarsNumbers;
1236 break;
1237 case ISO_LINE_VISI:
1238 v[Name + "IsoBarVisibility"] = Settings[settings].m_iIsoBarVisibility;
1239 break;
1240 case D_ARROWS:
1241 v[Name + "DirectionArrows"] = Settings[settings].m_bDirectionArrows;
1242 v[Name + "DirectionArrowForm"] = Settings[settings].m_iDirectionArrowForm;
1243 v[Name + "DirectionArrowSize"] = Settings[settings].m_iDirectionArrowSize;
1244 v[Name + "DirectionArrowFixedSpacing"] =
1245 Settings[settings].m_bDirArrFixSpac;
1246 v[Name + "DirectionArrowSpacing"] = Settings[settings].m_iDirArrSpacing;
1247 break;
1248 case OVERLAY:
1249 v[Name + "OverlayMap"] = Settings[settings].m_bOverlayMap;
1250 v[Name + "OverlayMapColors"] = Settings[settings].m_iOverlayMapColors;
1251 break;
1252 case NUMBERS:
1253 v[Name + "Numbers"] = Settings[settings].m_bNumbers;
1254 v[Name + "NumbersFixedSpacing"] = Settings[settings].m_bNumFixSpac;
1255 v[Name + "NumbersSpacing"] = Settings[settings].m_iNumbersSpacing;
1256 break;
1257 case PARTICLES:
1258 v[Name + "Particles"] = Settings[settings].m_bParticles;
1259 v[Name + "ParticleDensity"] = Settings[settings].m_dParticleDensity;
1260 break;
1261 default:
1262 break;
1263 }
1264
1265 return true;
1266}
1267
1268bool GribOverlaySettings::JSONToSettings(wxString json) {
1269 wxJSONValue root;
1270 wxJSONReader reader;
1271
1272 // now read the JSON text and store it in the 'root' structure
1273 // check for errors before retreiving values...
1274 int numErrors = reader.Parse(json, &root);
1275 if (numErrors > 0) {
1276 return false;
1277 }
1278
1279 // Read all the JSON values, and populate the local settings
1280
1281 if (root["overlay_transparency"].IsString()) {
1282 wxString s = root["overlay_transparency"].AsString();
1283 long transparency = -1;
1284 s.ToLong(&transparency);
1285 transparency = wxMax(1, transparency);
1286 transparency = wxMin(100, transparency);
1287 m_iOverlayTransparency = transparency * (double)(254. / 100.);
1288 }
1289
1290 for (int i = 0; i < SETTINGS_COUNT; i++) {
1291 wxString Name = name_from_index[i];
1292 wxString s;
1293
1294 if (root[Name + "Units"].IsString()) {
1295 wxString ss = root[Name + "Units"].AsString();
1296 long units = -1;
1297 ss.ToLong(&units);
1298 for (int j = 0; !unit_names[unittype[i]][j].empty(); j++)
1299 Settings[i].m_Units = (units < 0 || units > j - 1)
1300 ? (SettingsType)0
1301 : (SettingsType)units;
1302 }
1303
1304 if (root[Name + "BarbedArrows"].IsBool())
1305 Settings[i].m_bBarbedArrows = root[Name + "BarbedArrows"].AsBool();
1306
1307 if (root[Name + "BarbedVisibility"].IsBool())
1308 Settings[i].m_iBarbedVisibility =
1309 root[Name + "BarbedVisibility"].AsBool();
1310
1311 if (root[Name + "BarbedColors"].IsString()) {
1312 wxString ss = root[Name + "BarbedColors"].AsString();
1313 long val = -1;
1314 ss.ToLong(&val);
1315 Settings[i].m_iBarbedColour = val;
1316 }
1317
1318 if (root[Name + "BarbedArrowFixedSpacing"].IsBool())
1319 Settings[i].m_bBarbArrFixSpac =
1320 root[Name + "BarbedArrowFixedSpacing"].AsBool();
1321
1322 if (root[Name + "BarbedArrowSpacing"].IsString()) {
1323 wxString ss = root[Name + "BarbedArrowSpacing"].AsString();
1324 long val = -1;
1325 ss.ToLong(&val);
1326 Settings[i].m_iBarbArrSpacing = val;
1327 }
1328
1329 if (root[Name + "DisplayIsobars"].IsBool())
1330 Settings[i].m_bIsoBars = root[Name + "DisplayIsobars"].AsBool();
1331
1332 if (root[Name + "IsoBarSpacing"].IsString()) {
1333 wxString ss = root[Name + "IsoBarSpacing"].AsString();
1334 long val = -1;
1335 ss.ToLong(&val);
1336 Settings[i].m_iIsoBarSpacing = val;
1337 }
1338
1339 if (root[Name + "AbbrIsobarsNumbers"].IsBool())
1340 Settings[i].m_bAbbrIsoBarsNumbers =
1341 root[Name + "AbbrIsobarsNumbers"].AsBool();
1342
1343 if (root[Name + "IsoBarVisibility"].IsBool())
1344 Settings[i].m_iIsoBarVisibility =
1345 root[Name + "IsoBarVisibility"].AsBool();
1346
1347 if (root[Name + "DirectionArrows"].IsBool())
1348 Settings[i].m_bDirectionArrows = root[Name + "DirectionArrows"].AsBool();
1349
1350 if (root[Name + "DirectionArrowForm"].IsString()) {
1351 wxString ss = root[Name + "DirectionArrowForm"].AsString();
1352 long val = -1;
1353 ss.ToLong(&val);
1354 Settings[i].m_iDirectionArrowForm = val;
1355 }
1356
1357 if (root[Name + "DirectionArrowSize"].IsString()) {
1358 wxString ss = root[Name + "DirectionArrowSize"].AsString();
1359 long val = -1;
1360 ss.ToLong(&val);
1361 Settings[i].m_iDirectionArrowSize = val;
1362 }
1363
1364 if (root[Name + "DirectionArrowFixedSpacing"].IsBool())
1365 Settings[i].m_bDirArrFixSpac =
1366 root[Name + "DirectionArrowFixedSpacing"].AsBool();
1367
1368 if (root[Name + "DirectionArrowSpacing"].IsString()) {
1369 wxString ss = root[Name + "DirectionArrowSpacing"].AsString();
1370 long val = -1;
1371 ss.ToLong(&val);
1372 Settings[i].m_iDirArrSpacing = val;
1373 }
1374
1375 if (root[Name + "OverlayMap"].IsBool())
1376 Settings[i].m_bOverlayMap = root[Name + "OverlayMap"].AsBool();
1377
1378 if (root[Name + "OverlayMapColors"].IsString()) {
1379 wxString ss = root[Name + "OverlayMapColors"].AsString();
1380 long val = -1;
1381 ss.ToLong(&val);
1382 Settings[i].m_iOverlayMapColors = val;
1383 }
1384
1385 if (root[Name + "Numbers"].IsBool())
1386 Settings[i].m_bNumbers = root[Name + "Numbers"].AsBool();
1387
1388 if (root[Name + "NumbersFixedSpacing"].IsBool())
1389 Settings[i].m_bNumFixSpac = root[Name + "NumbersFixedSpacing"].AsBool();
1390
1391 if (root[Name + "NumbersSpacing"].IsString()) {
1392 wxString ss = root[Name + "NumbersSpacing"].AsString();
1393 long val = -1;
1394 ss.ToLong(&val);
1395 Settings[i].m_iNumbersSpacing = val;
1396 }
1397
1398 if (root[Name + "Particles"].IsBool())
1399 Settings[i].m_bParticles = root[Name + "Particles"].AsBool();
1400
1401 if (root[Name + "ParticleDensity"].IsString()) {
1402 wxString ss = root[Name + "ParticleDensity"].AsString();
1403 double val = -1;
1404 ss.ToDouble(&val);
1405 Settings[i].m_dParticleDensity = val;
1406 }
1407 }
1408
1409 return true;
1410}
GribPi * pPlugIn
Plugin instance that owns this control bar.
Class GribSettingsDialogBase.
wxSpinCtrl * m_sBarbArrSpacing
Spacing between barbed arrows in fixed spacing mode.
wxCheckBox * m_cBarbArrFixSpac
Flag to determine barbed arrow layout mode.
The JSON parser.
Definition jsonreader.h:45
int Parse(const wxString &doc, wxJSONValue *val)
Parse the JSON document.
The JSON value class implementation.
Definition jsonval.h:79
wxString AsString() const
Return the stored value as a wxWidget's string.
Definition jsonval.cpp:875
bool AsBool() const
Return the stored value as a boolean.
Definition jsonval.cpp:812
The JSON document writer.
Definition jsonwriter.h:45
void Write(const wxJSONValue &value, wxString &str)
Write the JSONvalue object to a JSON text.
GRIB Weather Data Plugin for OpenCPN.
wxFileConfig * GetOCPNConfigObject()
Gets OpenCPN's configuration object.
void DimeWindow(wxWindow *win)
Applies system color scheme to window.
OpenGL Platform Abstraction Layer.
int OCPNMessageBox_PlugIn(wxWindow *parent, const wxString &message, const wxString &caption, int style, int x, int y)
Shows a message box dialog.