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[] = {"Wind",
47 "WindGust",
48 "Pressure",
49 "Waves",
50 "Current",
51 "Rainfall",
52 "CloudCover",
53 "AirTemperature",
54 "SeaTemperature",
55 "CAPE",
56 "CompositeReflectivity",
57 "Altitude",
58 "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 "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 {"Std", "850", "700", "500", "300"},
81 {"Std", "637", "525", "375", "225"},
82 {"Std", "25.2", "20.7", "14.8", "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 "kts";
513 case M_S:
514 return "m/s";
515 case MPH:
516 return "mph";
517 case KPH:
518 return "km/h";
519 case BFS:
520 return "bf";
521 }
522 break;
523 case 1:
524 switch (Settings[settings].m_Units) {
525 case MILLIBARS:
526 return "hPa";
527 case MMHG:
528 return "mmHg";
529 case INHG:
530 return "inHg";
531 }
532 break;
533 case 2:
534 switch (Settings[settings].m_Units) {
535 case METERS:
536 return "m";
537 case FEET:
538 return "ft";
539 }
540 break;
541 case 3:
542 switch (Settings[settings].m_Units) {
543 case CELCIUS:
544 return "\u00B0C";
545 case FAHRENHEIT:
546 return "\u00B0F";
547 }
548 break;
549 case 4:
550 switch (Settings[settings].m_Units) {
551 case MILLIMETERS:
552 return "mm";
553 case INCHES:
554 return "in";
555 }
556 break;
557 case 5:
558 switch (Settings[settings].m_Units) {
559 case PERCENTAGE:
560 return "%";
561 }
562 break;
563 case 6:
564 switch (Settings[settings].m_Units) {
565 case JPKG:
566 return "j/kg";
567 }
568 break;
569 case 7:
570 switch (Settings[settings].m_Units) {
571 case KNOTS:
572 return "kts";
573 case M_S:
574 return "m/s";
575 case MPH:
576 return "mph";
577 case KPH:
578 return "km/h";
579 }
580 break;
581 case 8:
582 switch (Settings[settings].m_Units) {
583 case DBZ:
584 return "dBZ";
585 }
586 break;
587 }
588 return "";
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("%2d ", mn / 60) + _("h") +
660 wxString::Format(" %.2d ", mn % 60) + _("mn"));
661 }
662 // Set Bitmap
663 m_biAltitude->SetBitmap(parent.GetScaledBitmap(wxBitmap(altitude), "altitude",
664 parent.GetScaleFactor()));
665 m_biNow->SetBitmap(
666 parent.GetScaledBitmap(wxBitmap(now), "now", parent.GetScaleFactor()));
667 m_biZoomToCenter->SetBitmap(parent.GetScaledBitmap(wxBitmap(zoomto), "zoomto",
668 parent.GetScaleFactor()));
669 m_biShowCursorData->SetBitmap(parent.GetScaledBitmap(
670 parent.m_CDataIsShown ? wxBitmap(curdata) : wxBitmap(ncurdata),
671 parent.m_CDataIsShown ? "curdata" : "ncurdata", parent.GetScaleFactor()));
672 m_biPlay->SetBitmap(
673 parent.GetScaledBitmap(wxBitmap(play), "play", parent.GetScaleFactor()));
674 m_biTimeSlider->SetBitmap(parent.GetScaledBitmap(wxBitmap(slider), "slider",
675 parent.GetScaleFactor()));
676 m_biOpenFile->SetBitmap(parent.GetScaledBitmap(wxBitmap(openfile), "openfile",
677 parent.GetScaleFactor()));
678 m_biSettings->SetBitmap(parent.GetScaledBitmap(wxBitmap(setting), "setting",
679 parent.GetScaleFactor()));
680 m_biRequest->SetBitmap(parent.GetScaledBitmap(wxBitmap(request), "request",
681 parent.GetScaleFactor()));
682 // read bookpage
683 wxFileConfig *pConf = GetOCPNConfigObject();
684 if (pConf) {
685 pConf->SetPath(_T ( "/Settings/GRIB" ));
686 pConf->Read(_T ( "GribSettingsBookPageIndex" ), &m_SetBookpageIndex, 0);
687 }
688
689 m_cInterpolate->SetValue(m_Settings.m_bInterpolate);
690 m_cLoopMode->SetValue(m_Settings.m_bLoopMode);
691 m_cLoopStartPoint->SetSelection(m_Settings.m_LoopStartPoint);
692 m_sSlicesPerUpdate->SetSelection(m_Settings.m_SlicesPerUpdate);
693 m_sUpdatesPerSecond->SetValue(m_Settings.m_UpdatesPerSecond);
694 m_sTransparency->SetValue(
695 100. - ((float)m_Settings.m_iOverlayTransparency * 100. / 254.));
696 if (!m_cInterpolate->IsChecked()) { // eventually disable parameters
697 m_tSlicesPerUpdate->Disable();
698 m_sSlicesPerUpdate->Disable();
699 }
700 if (!m_cLoopMode->IsChecked()) {
701 m_staticText26->Disable();
702 m_cLoopStartPoint->Disable();
703 }
704
705 m_rbCurDataAttaWCap->SetValue(m_Settings.m_iCtrlandDataStyle == 0);
706 m_rbCurDataAttaWoCap->SetValue(m_Settings.m_iCtrlandDataStyle == 1);
707 m_rbCurDataIsolHoriz->SetValue(m_Settings.m_iCtrlandDataStyle == 2);
708 m_rbCurDataIsolVertic->SetValue(m_Settings.m_iCtrlandDataStyle == 3);
709
710 for (unsigned int i = 0; i < (m_Settings.m_iCtrlBarCtrlVisible[0].Len() * 2);
711 i += 2) {
712 ((wxCheckBox *)FindWindow(i + AC0))
713 ->SetValue(m_Settings.m_iCtrlBarCtrlVisible[0].GetChar(i / 2) ==
714 _T('X'));
715 ((wxCheckBox *)FindWindow(i + 1 + AC0))
716 ->SetValue(m_Settings.m_iCtrlBarCtrlVisible[1].GetChar(i / 2) ==
717 _T('X'));
718 }
719
720 m_cDataType->Clear();
721 for (int i = 0; i < GribOverlaySettings::SETTINGS_COUNT; i++)
722 m_cDataType->Append(wxGetTranslation(tname_from_index[i]));
723
724 m_cDataType->SetSelection(m_lastdatatype);
725 PopulateUnits(m_lastdatatype);
726 ReadDataTypeSettings(m_lastdatatype);
727 m_sButtonApply->SetLabel(_("Apply"));
728
729 DimeWindow(this); // apply global colours scheme
730
731#ifdef __OCPN__ANDROID__
732 GetHandle()->setStyleSheet(qtStyleSheet);
733#endif
734
735 Fit();
736}
737
738void GribSettingsDialog::SaveLastPage() {
739 wxFileConfig *pConf = GetOCPNConfigObject();
740
741 if (pConf) {
742 pConf->SetPath(_T ( "/Settings/GRIB" ));
743
744 pConf->Write(_T ( "GribSettingsBookPageIndex" ), m_SetBookpageIndex);
745 }
746}
747
748void GribSettingsDialog::OnPageChange(wxNotebookEvent &event) {
749 m_SetBookpageIndex = event.GetSelection();
750 SetSettingsDialogSize();
751}
752
753void GribSettingsDialog::SetSettingsDialogSize() {
754#ifdef __OCPN__ANDROID__
755 /*Sizing do not work with wxScolledWindow so we need to compute it
756 using fixed X/Y margin to try to center nicely the dialog in the screen*/
757 int wt, ht, w, h;
758 ::wxDisplaySize(&wt, &ht); // the screen size
759
760 int XMargin = 100, YMargin = 200; // set margins
761 w = wt - XMargin; // maximum scolled window size
762 h = ht - (m_sButton->GetSize().GetY() + YMargin);
763 wxSize scroll(0, 0);
764#else
765 /*Sizing do not work with wxScolledWindow so we need to compute it*/
766
767 wxWindow *frame = wxTheApp->GetTopWindow();
768
769 int w = frame->GetClientSize().x; // the display size
770 int h = frame->GetClientSize().y;
771 int dMargin = 80; // set a margin
772 w -= dMargin; // width available for the scrolled window
773 h -= (2 * m_sButton->GetSize().GetY()) +
774 dMargin; // height available for the scrolled window
775 // two times the button's height to handle pages tab's height
776#endif
777#ifdef __WXGTK__
778 SetMinSize(wxSize(10, 10));
779#endif
780
781 int display_width, display_height;
782 wxDisplaySize(&display_width, &display_height);
783
784 for (size_t i = 0; i < m_nSettingsBook->GetPageCount();
785 i++) { // compute and set scrolled windows size
786 wxScrolledWindow *sc = ((wxScrolledWindow *)m_nSettingsBook->GetPage(i));
787 sc->SetMinSize(wxSize(10, 10));
788 wxSize scr;
789#ifndef __WXGTK__
790 if ((int)i == m_SetBookpageIndex)
791#endif
792 {
793 switch (i) {
794 case 0:
795 scr = m_fgSetDataSizer->Fit(sc);
796 break;
797 case 1:
798 // set a reasonable speed slider's width
799 m_sUpdatesPerSecond->SetMinSize(
800 wxSize(m_cLoopStartPoint->GetSize().x, -1));
801 scr = m_fgSetPlaybackSizer->Fit(sc);
802 break;
803 case 2:
804 scr = m_fgSetGuiSizer->Fit(sc);
805 }
806 sc->SetMinSize(wxSize(wxMin(scr.x, w), wxMin(scr.y, h)));
807 sc->SetSize(wxSize(wxMin(scr.x, w), wxMin(scr.y, h)));
808
809 // Constrain size on small displays
810 if (display_height < 600) {
811 sc->SetSize(scr.x, h);
812 }
813
814#if defined __WXMSW__ || defined(__WXOSX__)
815 sc->Show();
816#endif
817 }
818 } // end compute
819
820#ifdef __OCPN__ANDROID__
821 m_nSettingsBook->SetSize(wt, -1);
822#endif
823
824 Layout();
825 Fit();
826#ifdef __WXGTK__
827 wxSize sd = GetSize();
828 if (sd.y == GetClientSize().y) sd.y += 30;
829 SetSize(wxSize(sd.x, sd.y));
830 SetMinSize(wxSize(sd.x, sd.y));
831#endif
832 Refresh();
833}
834
835/* set settings to the dialog controls */
836void GribSettingsDialog::WriteSettings() {
837 m_Settings.m_bInterpolate = m_cInterpolate->GetValue();
838 m_Settings.m_bLoopMode = m_cLoopMode->GetValue();
839 m_Settings.m_LoopStartPoint = m_cLoopStartPoint->GetSelection();
840 m_Settings.m_SlicesPerUpdate = m_sSlicesPerUpdate->GetCurrentSelection();
841 m_Settings.m_UpdatesPerSecond = m_sUpdatesPerSecond->GetValue();
842
843 m_Settings.m_iCtrlandDataStyle =
844 m_rbCurDataAttaWCap->GetValue() ? ATTACHED_HAS_CAPTION
845 : m_rbCurDataAttaWoCap->GetValue() ? ATTACHED_NO_CAPTION
846 : m_rbCurDataIsolHoriz->GetValue() ? SEPARATED_HORIZONTAL
847 : SEPARATED_VERTICAL;
848
849 for (unsigned int i = 0; i < (m_Settings.m_iCtrlBarCtrlVisible[0].Len() * 2);
850 i += 2) {
851 m_Settings.m_iCtrlBarCtrlVisible[0].SetChar(
852 i / 2,
853 ((wxCheckBox *)FindWindow(i + AC0))->GetValue() ? _T('X') : _T('.'));
854 m_Settings.m_iCtrlBarCtrlVisible[1].SetChar(
855 i / 2, ((wxCheckBox *)FindWindow(i + 1 + AC0))->GetValue() ? _T('X')
856 : _T('.'));
857 }
858
859 SetDataTypeSettings(m_lastdatatype);
860
861 m_extSettings = m_Settings;
862 m_DialogStyle = m_Settings.m_iCtrlandDataStyle;
863}
864
865void GribSettingsDialog::SetDataTypeSettings(int settings) {
866 GribOverlaySettings::OverlayDataSettings &odc = m_Settings.Settings[settings];
867 odc.m_Units = m_cDataUnits->GetSelection();
868 odc.m_bBarbedArrows = m_cbBarbedArrows->GetValue();
869 odc.m_iBarbedVisibility = m_cBarbedVisibility->GetValue();
870 odc.m_iBarbedColour = m_cBarbedColours->GetSelection();
871 odc.m_bBarbArrFixSpac = m_cBarbArrFixSpac->GetValue();
872 odc.m_iBarbArrSpacing = m_sBarbArrSpacing->GetValue();
873 odc.m_bIsoBars = m_cbIsoBars->GetValue();
874 odc.m_bAbbrIsoBarsNumbers = m_cbAbbrIsoBarsNumbers->GetValue();
875 odc.m_iIsoBarVisibility = m_sIsoBarVisibility->GetValue();
876 odc.m_iIsoBarSpacing = m_sIsoBarSpacing->GetValue();
877 odc.m_bDirectionArrows = m_cbDirectionArrows->GetValue();
878 odc.m_iDirectionArrowForm = m_cDirectionArrowForm->GetSelection();
879 odc.m_iDirectionArrowSize = m_cDirectionArrowSize->GetSelection();
880 odc.m_bDirArrFixSpac = m_cDirArrFixSpac->GetValue();
881 odc.m_iDirArrSpacing = m_sDirArrSpacing->GetValue();
882 odc.m_bOverlayMap = m_cbOverlayMap->GetValue();
883 odc.m_iOverlayMapColors = m_cOverlayColors->GetSelection();
884 odc.m_bNumbers = m_cbNumbers->GetValue();
885 odc.m_bNumFixSpac = m_cNumFixSpac->GetValue();
886 odc.m_iNumbersSpacing = m_sNumbersSpacing->GetValue();
887 odc.m_bParticles = m_cbParticles->GetValue();
888 odc.m_dParticleDensity = 4.0 * exp(m_sParticleDensity->GetValue() - 7.0);
889}
890
891void GribSettingsDialog::ReadDataTypeSettings(int settings) {
892 GribOverlaySettings::OverlayDataSettings &odc = m_Settings.Settings[settings];
893
894 m_cDataUnits->SetSelection(odc.m_Units);
895 m_cbBarbedArrows->SetValue(odc.m_bBarbedArrows);
896 m_cBarbedVisibility->SetValue(odc.m_iBarbedVisibility);
897 m_cBarbedColours->SetSelection(odc.m_iBarbedColour);
898 m_cBarbArrFixSpac->SetValue(odc.m_bBarbArrFixSpac);
899 m_cBarbArrMinSpac->SetValue(!odc.m_bBarbArrFixSpac);
900 m_sBarbArrSpacing->SetValue(odc.m_iBarbArrSpacing);
901 m_cbIsoBars->SetValue(odc.m_bIsoBars);
902 m_cbAbbrIsoBarsNumbers->SetValue(odc.m_bAbbrIsoBarsNumbers);
903 m_sIsoBarVisibility->SetValue(odc.m_iIsoBarVisibility);
904 m_sIsoBarSpacing->SetValue(odc.m_iIsoBarSpacing);
905 m_cbDirectionArrows->SetValue(odc.m_bDirectionArrows);
906 m_cDirectionArrowForm->SetSelection(odc.m_iDirectionArrowForm);
907 m_cDirectionArrowSize->SetSelection(odc.m_iDirectionArrowSize);
908 m_cDirArrFixSpac->SetValue(odc.m_bDirArrFixSpac);
909 m_cDirArrMinSpac->SetValue(!odc.m_bDirArrFixSpac);
910 m_sDirArrSpacing->SetValue(odc.m_iDirArrSpacing);
911 m_cbOverlayMap->SetValue(odc.m_bOverlayMap);
912 m_cOverlayColors->SetSelection(odc.m_iOverlayMapColors);
913 m_cbNumbers->SetValue(odc.m_bNumbers);
914 m_cNumFixSpac->SetValue(odc.m_bNumFixSpac);
915 m_cNumMinSpac->SetValue(!odc.m_bNumFixSpac);
916 m_sNumbersSpacing->SetValue(odc.m_iNumbersSpacing);
917 m_cbParticles->SetValue(odc.m_bParticles);
918 m_sParticleDensity->SetValue(log(odc.m_dParticleDensity / 4.0) + 7);
919
920 ShowFittingSettings(settings);
921}
922
923void GribSettingsDialog::ShowFittingSettings(int settings) {
924 // Hide all Parameters
925 ShowSettings(B_ARROWS, false);
926 ShowSettings(ISO_LINE, false);
927 if (m_fIsoBarSpacing->GetItem(m_sIsoBarSpacing) != nullptr)
928 m_fIsoBarSpacing->Detach(m_sIsoBarSpacing);
929 if (m_fIsoBarVisibility->GetItem(m_sIsoBarSpacing) != nullptr)
930 m_fIsoBarVisibility->Detach(m_sIsoBarSpacing);
931 if (m_fIsoBarVisibility->GetItem(m_sIsoBarVisibility) != nullptr)
932 m_fIsoBarVisibility->Detach(m_sIsoBarVisibility);
933 ShowSettings(ISO_ABBR, false);
934 ShowSettings(D_ARROWS, false);
935 ShowSettings(OVERLAY, false);
936 ShowSettings(NUMBERS, false);
937 ShowSettings(PARTICLES, false);
938 this->Fit();
939 // Show only fitting parameters
940 switch (settings) {
941 case GribOverlaySettings::WIND:
942 ShowSettings(ISO_LINE_SHORT);
943 ShowSettings(ISO_LINE);
944 m_cbIsoBars->SetLabel(_("Display Isotachs"));
945 ShowSettings(B_ARROWS);
946 ShowSettings(OVERLAY);
947 ShowSettings(NUMBERS);
948 ShowSettings(PARTICLES);
949 break;
950 case GribOverlaySettings::WIND_GUST:
951 ShowSettings(ISO_LINE_SHORT);
952 ShowSettings(ISO_LINE);
953 m_cbIsoBars->SetLabel(_("Display Isotachs"));
954 ShowSettings(OVERLAY);
955 ShowSettings(NUMBERS);
956 break;
957 case GribOverlaySettings::PRESSURE:
958 ShowSettings(ISO_LINE_VISI);
959 ShowSettings(ISO_LINE);
960 m_cbIsoBars->SetLabel(_("Display Isobars"));
961 ShowSettings(ISO_ABBR);
962 ShowSettings(NUMBERS);
963 break;
964 case GribOverlaySettings::CURRENT:
965 ShowSettings(PARTICLES); // should we allow particles for waves?
966 case GribOverlaySettings::WAVE:
967 ShowSettings(D_ARROWS);
968 ShowSettings(OVERLAY);
969 ShowSettings(NUMBERS);
970 break;
971 case GribOverlaySettings::PRECIPITATION:
972 case GribOverlaySettings::CLOUD:
973 ShowSettings(OVERLAY);
974 ShowSettings(NUMBERS);
975 break;
976 case GribOverlaySettings::AIR_TEMPERATURE:
977 case GribOverlaySettings::SEA_TEMPERATURE:
978 ShowSettings(ISO_LINE_SHORT);
979 ShowSettings(ISO_LINE);
980 m_cbIsoBars->SetLabel(_("Display Isotherms"));
981 ShowSettings(OVERLAY);
982 ShowSettings(NUMBERS);
983 break;
984 case GribOverlaySettings::CAPE:
985 ShowSettings(ISO_LINE_SHORT);
986 ShowSettings(ISO_LINE);
987 m_cbIsoBars->SetLabel(_("Display Iso CAPE"));
988 ShowSettings(OVERLAY);
989 ShowSettings(NUMBERS);
990 break;
991 case GribOverlaySettings::COMP_REFL:
992 ShowSettings(ISO_LINE_SHORT);
993 ShowSettings(ISO_LINE);
994 m_cbIsoBars->SetLabel(_("Display Comp. Reflectivity"));
995 ShowSettings(OVERLAY);
996 ShowSettings(NUMBERS);
997 break;
998 }
999
1000 wxString l = (m_lastdatatype == GribOverlaySettings::PRESSURE &&
1001 m_cDataUnits->GetSelection() == GribOverlaySettings::INHG)
1002 ? "(0.03 "
1003 : "(";
1004 m_tIsoBarSpacing->SetLabel(
1005 wxString(_("Spacing"))
1006 .Append(l)
1007 .Append(m_Settings.GetUnitSymbol(m_lastdatatype))
1008 .Append(")"));
1009}
1010
1011void GribSettingsDialog::ShowSettings(int params, bool show) {
1012 switch (params) {
1013 case B_ARROWS:
1014 m_cbBarbedArrows->Show(show);
1015 m_fgBarbedData1->ShowItems(show);
1016 m_fgBarbedData2->ShowItems(show);
1017 break;
1018 case ISO_LINE:
1019 m_cbIsoBars->Show(show);
1020 m_fIsoBarSpacing->ShowItems(show);
1021 m_fIsoBarVisibility->ShowItems(show);
1022 break;
1023 case ISO_ABBR:
1024 m_cbAbbrIsoBarsNumbers->Show(show);
1025 break;
1026 case ISO_LINE_VISI:
1027 m_fIsoBarSpacing->Add(m_sIsoBarSpacing, 0, 5, wxALL | wxEXPAND);
1028 m_fIsoBarVisibility->Add(m_sIsoBarVisibility, 0, 5,
1029 wxTOP | wxLEFT | wxEXPAND);
1030 // m_sIsoBarSpacing->SetMinSize(wxSize(70, -1));
1031 break;
1032 case ISO_LINE_SHORT:
1033 m_fIsoBarVisibility->Add(m_sIsoBarSpacing, 0, 5,
1034 wxTOP | wxLEFT | wxEXPAND);
1035 // m_sIsoBarSpacing->SetMinSize(wxSize(-1, -1));
1036 break;
1037 case D_ARROWS:
1038 m_cbDirectionArrows->Show(show);
1039 m_fgDirArrData1->ShowItems(show);
1040 m_fgDirArrData2->ShowItems(show);
1041 break;
1042 case OVERLAY:
1043 m_cbOverlayMap->Show(show);
1044 m_tOverlayColors->Show(show);
1045 m_cOverlayColors->Show(show);
1046 break;
1047 case NUMBERS:
1048 m_cbNumbers->Show(show);
1049 m_fgNumData1->ShowItems(show);
1050 m_sNumbersSpacing->Show(show);
1051 break;
1052 case PARTICLES:
1053 m_cbParticles->Show(show);
1054 m_ctParticles->Show(show);
1055 m_sParticleDensity->Show(show);
1056 break;
1057 }
1058}
1059
1060void GribSettingsDialog::PopulateUnits(int settings) {
1061 m_cDataUnits->Clear();
1062 for (int i = 0; !unit_names[unittype[m_lastdatatype]][i].empty(); i++)
1063 m_cDataUnits->Append(
1064 wxGetTranslation((unit_names[unittype[m_lastdatatype]][i])));
1065}
1066
1067void GribSettingsDialog::OnDataTypeChoice(wxCommandEvent &event) {
1068 SetDataTypeSettings(m_lastdatatype);
1069 m_lastdatatype = m_cDataType->GetSelection();
1070 PopulateUnits(m_lastdatatype);
1071 ReadDataTypeSettings(m_lastdatatype);
1072 SetSettingsDialogSize();
1073}
1074
1075void GribSettingsDialog::OnUnitChange(wxCommandEvent &event) {
1076 m_Settings.Settings[m_lastdatatype].m_Units = m_cDataUnits->GetSelection();
1077 wxString l = (m_lastdatatype == GribOverlaySettings::PRESSURE &&
1078 m_cDataUnits->GetSelection() == GribOverlaySettings::INHG)
1079 ? "(0.03 "
1080 : "(";
1081 m_tIsoBarSpacing->SetLabel(
1082 wxString(_("Spacing"))
1083 .Append(l)
1084 .Append(m_Settings.GetUnitSymbol(m_lastdatatype))
1085 .Append(")"));
1086 SetSettingsDialogSize();
1087}
1088
1089void GribSettingsDialog::OnTransparencyChange(wxScrollEvent &event) {
1090 m_Settings.m_iOverlayTransparency =
1091 254. - ((long)m_sTransparency->GetValue() * 254. / 100.);
1092 m_extSettings.m_iOverlayTransparency = m_Settings.m_iOverlayTransparency;
1093 m_parent.SetFactoryOptions();
1094}
1095
1096void GribSettingsDialog::OnCtrlandDataStyleChanged(wxCommandEvent &event) {
1097 wxString messages;
1098 if ((m_Settings.m_iCtrlandDataStyle == 0 && !m_rbCurDataAttaWCap->GetValue()))
1099 messages.Printf(_("You want to remove the dialog title/drag bar\n"));
1100 if ((m_Settings.m_iCtrlandDataStyle != 0 && m_rbCurDataAttaWCap->GetValue()))
1101 messages.Printf(_("You want to add a title/drag bar to the dialog\n"));
1102 if (!messages.IsEmpty()) {
1103 m_parent.pPlugIn->m_DialogStyleChanged = true;
1104 messages.Append(
1105 _("This change needs a complete reload.\nIt will be applied after "
1106 "closing and re-opening the plugin"));
1107 OCPNMessageBox_PlugIn(this, messages);
1108 }
1109}
1110
1111void GribSettingsDialog::OnApply(wxCommandEvent &event) {
1112 if (m_Settings.Settings[GribOverlaySettings::WIND].m_Units !=
1113 m_extSettings.Settings[GribOverlaySettings::WIND].m_Units &&
1114 (m_Settings.Settings[GribOverlaySettings::WIND].m_Units ==
1115 GribOverlaySettings::BFS ||
1116 m_extSettings.Settings[GribOverlaySettings::WIND].m_Units ==
1117 GribOverlaySettings::BFS))
1118 m_parent.m_old_DialogStyle =
1119 STARTING_STATE_STYLE; // must recompute dialogs size
1120
1121 WriteSettings();
1122 m_parent.SetFactoryOptions();
1123 m_parent.SetDialogsStyleSizePosition(true);
1124}
1125
1126void GribSettingsDialog::OnIntepolateChange(wxCommandEvent &event) {
1127 if (m_cInterpolate->IsChecked()) {
1129 this,
1130 _("You have chosen to authorize interpolation.\nDon't forget that data "
1131 "displayed will not be real but recomputed\nThis can decrease "
1132 "accuracy!"),
1133 _("Warning!"));
1134 m_tSlicesPerUpdate->Enable();
1135 m_sSlicesPerUpdate->Enable();
1136 } else { // hide no suiting parameters
1137 m_tSlicesPerUpdate->Disable();
1138 m_sSlicesPerUpdate->Disable();
1139 }
1140 if (m_cLoopMode->IsChecked()) {
1141 m_staticText26->Enable();
1142 m_cLoopStartPoint->Enable();
1143 } else {
1144 m_staticText26->Disable();
1145 m_cLoopStartPoint->Disable();
1146 }
1147 Refresh();
1148 // SetSettingsDialogSize();
1149}
1150
1151void GribSettingsDialog::OnSpacingModeChange(wxCommandEvent &event) {
1152 bool message = false;
1153 switch (event.GetId()) {
1154 case BARBFIXSPACING:
1155 m_cBarbArrMinSpac->SetValue(!m_cBarbArrFixSpac->IsChecked());
1156 if (m_cBarbArrFixSpac->IsChecked()) message = true;
1157 break;
1158 case BARBMINSPACING:
1159 m_cBarbArrFixSpac->SetValue(!m_cBarbArrMinSpac->IsChecked());
1160 break;
1161 case DIRFIXSPACING:
1162 m_cDirArrMinSpac->SetValue(!m_cDirArrFixSpac->IsChecked());
1163 if (m_cDirArrFixSpac->IsChecked()) message = true;
1164 break;
1165 case DIRMINSPACING:
1166 m_cDirArrFixSpac->SetValue(!m_cDirArrMinSpac->IsChecked());
1167 break;
1168 case NUMFIXSPACING:
1169 m_cNumMinSpac->SetValue(!m_cNumFixSpac->IsChecked());
1170 if (m_cNumFixSpac->IsChecked()) message = true;
1171 break;
1172 case NUMMINSPACING:
1173 m_cNumFixSpac->SetValue(!m_cNumMinSpac->IsChecked());
1174 }
1175
1176 if (message) {
1178 this,
1179 _("This option imply you authorize intrepolation\nDon't forget that "
1180 "data displayed will not be real but recomputed\nThis can decrease "
1181 "accuracy!"),
1182 _("Warning!"));
1183 }
1184}
1185
1186wxString GribOverlaySettings::SettingsToJSON(wxString json) {
1187 wxJSONValue v(json);
1188
1189 for (int i = 0; i < SETTINGS_COUNT; i++) {
1190 wxString units;
1191 units.Printf("%d", (int)Settings[i].m_Units);
1192 v[name_from_index[i] + _T ( "Units" )] = units;
1193
1194 if (i == WIND) {
1195 UpdateJSONval(v, i, B_ARROWS);
1196 UpdateJSONval(v, i, ISO_LINE_SHORT);
1197 UpdateJSONval(v, i, OVERLAY);
1198 UpdateJSONval(v, i, NUMBERS);
1199 UpdateJSONval(v, i, PARTICLES);
1200 } else if (i == WIND_GUST || i == AIR_TEMPERATURE || i == SEA_TEMPERATURE ||
1201 i == CAPE || i == COMP_REFL) {
1202 UpdateJSONval(v, i, ISO_LINE_SHORT);
1203 UpdateJSONval(v, i, OVERLAY);
1204 UpdateJSONval(v, i, NUMBERS);
1205 } else if (i == PRESSURE) {
1206 UpdateJSONval(v, i, ISO_LINE_SHORT);
1207 UpdateJSONval(v, i, ISO_LINE_VISI);
1208 UpdateJSONval(v, i, NUMBERS);
1209 } else if (i == WAVE || i == CURRENT) {
1210 UpdateJSONval(v, i, D_ARROWS);
1211 UpdateJSONval(v, i, OVERLAY);
1212 UpdateJSONval(v, i, NUMBERS);
1213 UpdateJSONval(v, i, PARTICLES);
1214 } else if (i == PRECIPITATION || i == CLOUD) {
1215 UpdateJSONval(v, i, OVERLAY);
1216 UpdateJSONval(v, i, NUMBERS);
1217 }
1218 }
1219
1220 wxJSONWriter w;
1221 wxString out;
1222 w.Write(v, out);
1223 return out;
1224}
1225
1226bool GribOverlaySettings::UpdateJSONval(wxJSONValue &v, int settings,
1227 int group) {
1228 wxString Name = name_from_index[settings];
1229
1230 switch (group) {
1231 case B_ARROWS:
1232 v[Name + _T ( "BarbedArrows" )] = Settings[settings].m_bBarbedArrows;
1233 v[Name + _T ( "BarbedVisibility" )] =
1234 Settings[settings].m_iBarbedVisibility;
1235 v[Name + _T ( "BarbedColors" )] = Settings[settings].m_iBarbedColour;
1236 v[Name + _T ( "BarbedArrowFixedSpacing" )] =
1237 Settings[settings].m_bBarbArrFixSpac;
1238 v[Name + _T ( "BarbedArrowSpacing" )] =
1239 Settings[settings].m_iBarbArrSpacing;
1240 break;
1241 case ISO_LINE_SHORT:
1242 v[Name + _T ( "DisplayIsobars" )] = Settings[settings].m_bIsoBars;
1243 v[Name + _T ( "IsoBarSpacing" )] = Settings[settings].m_iIsoBarSpacing;
1244 break;
1245 case ISO_ABBR:
1246 v[Name + _T ( "AbbrIsobarsNumbers" )] =
1247 Settings[settings].m_bAbbrIsoBarsNumbers;
1248 break;
1249 case ISO_LINE_VISI:
1250 v[Name + _T ( "IsoBarVisibility" )] =
1251 Settings[settings].m_iIsoBarVisibility;
1252 break;
1253 case D_ARROWS:
1254 v[Name + _T ( "DirectionArrows" )] =
1255 Settings[settings].m_bDirectionArrows;
1256 v[Name + _T ( "DirectionArrowForm" )] =
1257 Settings[settings].m_iDirectionArrowForm;
1258 v[Name + _T ( "DirectionArrowSize" )] =
1259 Settings[settings].m_iDirectionArrowSize;
1260 v[Name + _T ( "DirectionArrowFixedSpacing" )] =
1261 Settings[settings].m_bDirArrFixSpac;
1262 v[Name + _T ( "DirectionArrowSpacing" )] =
1263 Settings[settings].m_iDirArrSpacing;
1264 break;
1265 case OVERLAY:
1266 v[Name + _T ( "OverlayMap" )] = Settings[settings].m_bOverlayMap;
1267 v[Name + _T ( "OverlayMapColors" )] =
1268 Settings[settings].m_iOverlayMapColors;
1269 break;
1270 case NUMBERS:
1271 v[Name + _T ( "Numbers" )] = Settings[settings].m_bNumbers;
1272 v[Name + _T ( "NumbersFixedSpacing" )] = Settings[settings].m_bNumFixSpac;
1273 v[Name + _T ( "NumbersSpacing" )] = Settings[settings].m_iNumbersSpacing;
1274 break;
1275 case PARTICLES:
1276 v[Name + _T ( "Particles" )] = Settings[settings].m_bParticles;
1277 v[Name + _T ( "ParticleDensity" )] =
1278 Settings[settings].m_dParticleDensity;
1279 break;
1280 default:
1281 break;
1282 }
1283
1284 return true;
1285}
1286
1287bool GribOverlaySettings::JSONToSettings(wxString json) {
1288 wxJSONValue root;
1289 wxJSONReader reader;
1290
1291 // now read the JSON text and store it in the 'root' structure
1292 // check for errors before retreiving values...
1293 int numErrors = reader.Parse(json, &root);
1294 if (numErrors > 0) {
1295 return false;
1296 }
1297
1298 // Read all the JSON values, and populate the local settings
1299
1300 if (root[_T ( "overlay_transparency" )].IsString()) {
1301 wxString s = root[_T ( "overlay_transparency" )].AsString();
1302 long transparency = -1;
1303 s.ToLong(&transparency);
1304 transparency = wxMax(1, transparency);
1305 transparency = wxMin(100, transparency);
1306 m_iOverlayTransparency = transparency * (double)(254. / 100.);
1307 }
1308
1309 for (int i = 0; i < SETTINGS_COUNT; i++) {
1310 wxString Name = name_from_index[i];
1311 wxString s;
1312
1313 if (root[Name + _T ( "Units" )].IsString()) {
1314 wxString s = root[Name + _T ( "Units" )].AsString();
1315 long units = -1;
1316 s.ToLong(&units);
1317 for (int j = 0; !unit_names[unittype[i]][j].empty(); j++)
1318 Settings[i].m_Units = (units < 0 || units > j - 1)
1319 ? (SettingsType)0
1320 : (SettingsType)units;
1321 }
1322
1323 if (root[Name + _T ( "BarbedArrows" )].IsBool())
1324 Settings[i].m_bBarbedArrows = root[Name + _T ( "BarbedArrows" )].AsBool();
1325
1326 if (root[Name + _T ( "BarbedVisibility" )].IsBool())
1327 Settings[i].m_iBarbedVisibility =
1328 root[Name + _T ( "BarbedVisibility" )].AsBool();
1329
1330 if (root[Name + _T ( "BarbedColors" )].IsString()) {
1331 wxString s = root[Name + _T ( "BarbedColors" )].AsString();
1332 long val = -1;
1333 s.ToLong(&val);
1334 Settings[i].m_iBarbedColour = val;
1335 }
1336
1337 if (root[Name + _T ( "BarbedArrowFixedSpacing" )].IsBool())
1338 Settings[i].m_bBarbArrFixSpac =
1339 root[Name + _T ( "BarbedArrowFixedSpacing" )].AsBool();
1340
1341 if (root[Name + _T ( "BarbedArrowSpacing" )].IsString()) {
1342 wxString s = root[Name + _T ( "BarbedArrowSpacing" )].AsString();
1343 long val = -1;
1344 s.ToLong(&val);
1345 Settings[i].m_iBarbArrSpacing = val;
1346 }
1347
1348 if (root[Name + _T ( "DisplayIsobars" )].IsBool())
1349 Settings[i].m_bIsoBars = root[Name + _T ( "DisplayIsobars" )].AsBool();
1350
1351 if (root[Name + _T ( "IsoBarSpacing" )].IsString()) {
1352 wxString s = root[Name + _T ( "IsoBarSpacing" )].AsString();
1353 long val = -1;
1354 s.ToLong(&val);
1355 Settings[i].m_iIsoBarSpacing = val;
1356 }
1357
1358 if (root[Name + _T ( "AbbrIsobarsNumbers" )].IsBool())
1359 Settings[i].m_bAbbrIsoBarsNumbers =
1360 root[Name + _T ( "AbbrIsobarsNumbers" )].AsBool();
1361
1362 if (root[Name + _T ( "IsoBarVisibility" )].IsBool())
1363 Settings[i].m_iIsoBarVisibility =
1364 root[Name + _T ( "IsoBarVisibility" )].AsBool();
1365
1366 if (root[Name + _T ( "DirectionArrows" )].IsBool())
1367 Settings[i].m_bDirectionArrows =
1368 root[Name + _T ( "DirectionArrows" )].AsBool();
1369
1370 if (root[Name + _T ( "DirectionArrowForm" )].IsString()) {
1371 wxString s = root[Name + _T ( "DirectionArrowForm" )].AsString();
1372 long val = -1;
1373 s.ToLong(&val);
1374 Settings[i].m_iDirectionArrowForm = val;
1375 }
1376
1377 if (root[Name + _T ( "DirectionArrowSize" )].IsString()) {
1378 wxString s = root[Name + _T ( "DirectionArrowSize" )].AsString();
1379 long val = -1;
1380 s.ToLong(&val);
1381 Settings[i].m_iDirectionArrowSize = val;
1382 }
1383
1384 if (root[Name + _T ( "DirectionArrowFixedSpacing" )].IsBool())
1385 Settings[i].m_bDirArrFixSpac =
1386 root[Name + _T ( "DirectionArrowFixedSpacing" )].AsBool();
1387
1388 if (root[Name + _T ( "DirectionArrowSpacing" )].IsString()) {
1389 wxString s = root[Name + _T ( "DirectionArrowSpacing" )].AsString();
1390 long val = -1;
1391 s.ToLong(&val);
1392 Settings[i].m_iDirArrSpacing = val;
1393 }
1394
1395 if (root[Name + _T ( "OverlayMap" )].IsBool())
1396 Settings[i].m_bOverlayMap = root[Name + _T ( "OverlayMap" )].AsBool();
1397
1398 if (root[Name + _T ( "OverlayMapColors" )].IsString()) {
1399 wxString s = root[Name + _T ( "OverlayMapColors" )].AsString();
1400 long val = -1;
1401 s.ToLong(&val);
1402 Settings[i].m_iOverlayMapColors = val;
1403 }
1404
1405 if (root[Name + _T ( "Numbers" )].IsBool())
1406 Settings[i].m_bNumbers = root[Name + _T ( "Numbers" )].AsBool();
1407
1408 if (root[Name + _T ( "NumbersFixedSpacing" )].IsBool())
1409 Settings[i].m_bNumFixSpac =
1410 root[Name + _T ( "NumbersFixedSpacing" )].AsBool();
1411
1412 if (root[Name + _T ( "NumbersSpacing" )].IsString()) {
1413 wxString s = root[Name + _T ( "NumbersSpacing" )].AsString();
1414 long val = -1;
1415 s.ToLong(&val);
1416 Settings[i].m_iNumbersSpacing = val;
1417 }
1418
1419 if (root[Name + _T ( "Particles" )].IsBool())
1420 Settings[i].m_bParticles = root[Name + _T ( "Particles" )].AsBool();
1421
1422 if (root[Name + _T ( "ParticleDensity" )].IsString()) {
1423 wxString s = root[Name + _T ( "ParticleDensity" )].AsString();
1424 double val = -1;
1425 s.ToDouble(&val);
1426 Settings[i].m_dParticleDensity = val;
1427 }
1428 }
1429
1430 return true;
1431}
grib_pi * 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: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.
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.