OpenCPN Partial API docs
Loading...
Searching...
No Matches
s57_load.cpp
1/***************************************************************************
2 * Copyright (C) 2010 - 2025 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
18#include <wx/app.h>
19
20#include "model/cmdline.h"
21#include "model/gui_vars.h"
22
23#include "chart_ctx_factory.h"
24#include "displays.h"
25#include "navutil.h"
26#include "ocpn_platform.h"
27#include "o_senc.h"
28#include "senc_manager.h"
29#include "s52plib.h"
30#include "s57registrar_mgr.h"
31
32void LoadS57() {
33 if (ps52plib) // already loaded?
34 return;
35
36 // Start a SENC Thread manager
38
39 // Set up a useable CPL library error handler for S57 stuff
40 // FIXME (dave) Verify after moving LoadS57
41 // CPLSetErrorHandler(MyCPLErrorHandler);
42
43 // Init the s57 chart object, specifying the location of the required csv
44 // files
45 g_csv_locn = g_Platform->GetSharedDataDir();
46 g_csv_locn.Append("s57data");
47
48 if (g_bportable) {
49 g_csv_locn = ".";
50 appendOSDirSlash(&g_csv_locn);
51 g_csv_locn.Append("s57data");
52 }
53
54 // If the config file contains an entry for SENC file prefix, use it.
55 // Otherwise, default to PrivateDataDir
56 if (g_SENCPrefix.IsEmpty()) {
57 g_SENCPrefix = g_Platform->GetPrivateDataDir();
58 appendOSDirSlash(&g_SENCPrefix);
59 g_SENCPrefix.Append("SENC");
60 }
61
62 if (g_bportable) {
63 wxFileName f(g_SENCPrefix);
64 if (f.MakeRelativeTo(g_Platform->GetPrivateDataDir()))
65 g_SENCPrefix = f.GetFullPath();
66 else
67 g_SENCPrefix = "SENC";
68 }
69
70 // If the config file contains an entry for PresentationLibraryData, use
71 // it. Otherwise, default to conditionally set spot under g_pcsv_locn
72 wxString plib_data;
73 bool b_force_legacy = false;
74
75 if (g_UserPresLibData.IsEmpty()) {
76 plib_data = g_csv_locn;
77 appendOSDirSlash(&plib_data);
78 plib_data.Append("S52RAZDS.RLE");
79 } else {
80 plib_data = g_UserPresLibData;
81 b_force_legacy = true;
82 }
83
84 ps52plib = new s52plib(plib_data, b_force_legacy);
85
86 // If the library load failed, try looking for the s57 data elsewhere
87
88 // First, look in UserDataDir
89 /* From wxWidgets documentation
90
91 wxStandardPaths::GetUserDataDir
92 wxString GetUserDataDir() const
93 Return the directory for the user-dependent application data files:
94 * Unix: ~/.appname
95 * Windows: C:\Documents and Settings\username\Application Data\appname
96 * Mac: ~/Library/Application Support/appname
97 */
98
99 if (!ps52plib->m_bOK) {
100 delete ps52plib;
101
102 wxStandardPaths &std_path = g_Platform->GetStdPaths();
103
104 wxString look_data_dir;
105 look_data_dir.Append(std_path.GetUserDataDir());
106 appendOSDirSlash(&look_data_dir);
107 wxString tentative_SData_Locn = look_data_dir;
108 look_data_dir.Append("s57data");
109
110 plib_data = look_data_dir;
111 appendOSDirSlash(&plib_data);
112 plib_data.Append("S52RAZDS.RLE");
113
114 wxLogMessage("Looking for s57data in " + look_data_dir);
115 ps52plib = new s52plib(plib_data);
116
117 if (ps52plib->m_bOK) {
118 g_csv_locn = look_data_dir;
120 }
121 }
122
123 // And if that doesn't work, look again in the original SData Location
124 // This will cover the case in which the .ini file entry is corrupted or
125 // moved
126
127 if (!ps52plib->m_bOK) {
128 delete ps52plib;
129
130 wxString look_data_dir;
131 look_data_dir = g_Platform->GetSharedDataDir();
132 look_data_dir.Append("s57data");
133
134 plib_data = look_data_dir;
135 appendOSDirSlash(&plib_data);
136 plib_data.Append("S52RAZDS.RLE");
137
138 wxLogMessage("Looking for s57data in " + look_data_dir);
139 ps52plib = new s52plib(plib_data);
140
141 if (ps52plib->m_bOK) g_csv_locn = look_data_dir;
142 }
143
144 if (ps52plib->m_bOK) {
145 wxLogMessage("Using s57data in " + g_csv_locn);
147 new s57RegistrarMgr(g_csv_locn, g_Platform->GetLogFilePtr());
148
149 // Preset some object class visibilites for "User Standard" disply
150 // category
151 // They may be overridden in LoadS57Config
152 for (unsigned int iPtr = 0; iPtr < ps52plib->pOBJLArray->GetCount();
153 iPtr++) {
154 OBJLElement *pOLE = (OBJLElement *)(ps52plib->pOBJLArray->Item(iPtr));
155 if (!strncmp(pOLE->OBJLName, "DEPARE", 6)) pOLE->nViz = 1;
156 if (!strncmp(pOLE->OBJLName, "LNDARE", 6)) pOLE->nViz = 1;
157 if (!strncmp(pOLE->OBJLName, "COALNE", 6)) pOLE->nViz = 1;
158 }
159
160 pConfig->LoadS57Config();
161 ps52plib->SetPLIBColorScheme(global_color_scheme, ChartCtxFactory());
162
163 if (wxTheApp->GetTopWindow()) {
164 ps52plib->SetDisplayWidth(g_monitor_info[g_current_monitor].width);
165 ps52plib->SetPPMM(g_BasePlatform->GetDisplayDPmm());
166 double dip_factor =
167 g_BasePlatform->GetDisplayDIPMult(wxTheApp->GetTopWindow());
168 ps52plib->SetDIPFactor(dip_factor);
169 ps52plib->SetContentScaleFactor(OCPN_GetDisplayContentScaleFactor());
170 }
171
172 // preset S52 PLIB scale factors
173 ps52plib->SetScaleFactorExp(
174 g_Platform->GetChartScaleFactorExp(g_ChartScaleFactor));
175 ps52plib->SetScaleFactorZoomMod(g_chart_zoom_modifier_vector);
176
177#ifdef ocpnUSE_GL
178
179 // Setup PLIB OpenGL options, if enabled
180 if (g_bopengl) {
181 if (GL_Caps) {
182 wxString renderer = wxString(GL_Caps->Renderer.c_str());
183 ps52plib->SetGLRendererString(renderer);
184 }
185
186 ps52plib->SetGLOptions(
187 glChartCanvas::s_b_useStencil, glChartCanvas::s_b_useStencilAP,
188 glChartCanvas::s_b_useScissorTest, glChartCanvas::s_b_useFBO,
189 g_b_EnableVBO, g_texture_rectangle_format, 1, 1);
190 }
191#endif
192
193 } else {
194 wxLogMessage(" S52PLIB Initialization failed, disabling Vector charts.");
195 delete ps52plib;
196 ps52plib = NULL;
197 }
198}
BasePlatform * g_BasePlatform
points to g_platform, handles brain-dead MS linker.
Wrapper for creating a ChartCtx based on global vars.
double GetDisplayDIPMult(wxWindow *win)
Get the display scaling factor for DPI-aware rendering.
wxString & GetPrivateDataDir()
Return dir path for opencpn.log, etc., respecting -c cli option.
Manager for S57 chart SENC creation threads.
Global variables reflecting command line options and arguments.
std::vector< OCPN_MonitorInfo > g_monitor_info
Information about the monitors connected to the system.
Definition displays.cpp:45
Display utilities.
size_t g_current_monitor
Current monitor displaying main application frame.
Definition gui_vars.cpp:75
Miscellaneous globals primarely used by gui layer, not persisted in configuration file.
MyConfig * pConfig
Global instance.
Definition navutil.cpp:118
Utility functions.
s57RegistrarMgr * m_pRegistrarMan
Global instance.
Definition o_senc.cpp:62
S57 SENC File Object.
OpenCPN Platform specific support utilities.
double OCPN_GetDisplayContentScaleFactor()
Gets content scaling factor for current display.
SENCThreadManager * g_SencThreadManager
Global instance.
S57 Chart Object.