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