34#include "wx/tokenzr.h"
35#include <wx/textfile.h>
38#include "OCPNPlatform.h"
46#include "model/cutil.h"
47#include "model/georef.h"
49#include "ocpn_pixel.h"
52#include "model/wx28compat.h"
54#include "gdal/cpl_csv.h"
59#include "pluginmanager.h"
64#include <wx/msw/msvcrt.h>
68#include "glChartCanvas.h"
75#define strncasecmp(x, y, z) _strnicmp(x, y, z)
78extern bool g_b_EnableVBO;
84S57Obj::S57Obj() { Init(); }
94 for (
unsigned int iv = 0; iv < attVal->GetCount(); iv++) {
95 S57attVal *vv = attVal->Item(iv);
106 bool b_useVBO = g_b_EnableVBO && !auxParm1;
108 PolyTriGroup *ppg_vbo = pPolyTessGeo->Get_PolyTriGroup_head();
109 if (b_useVBO && ppg_vbo && auxParm0 > 0 && ppg_vbo->single_buffer) {
110 glDeleteBuffers(1, (GLuint *)&auxParm0);
116 if (FText)
delete FText;
118 if (geoPt) free(geoPt);
119 if (geoPtz) free(geoPtz);
120 if (geoPtMulti) free(geoPtMulti);
122 if (m_lsindex_array) free(m_lsindex_array);
125 line_segment_element *element = m_ls_list;
127 line_segment_element *next = element->next;
155 bIsAssociable =
false;
157 m_lsindex_array = NULL;
158 m_n_edge_max_points = 0;
160 m_ls_list_legacy = 0;
163 bBBObj_valid =
false;
180S57Obj::S57Obj(
const char *featureName) {
183 attVal =
new wxArrayOfS57attVal();
185 strncpy(FeatureName, featureName, 6);
188 if (!strncmp(FeatureName,
"DEPARE", 6) || !strncmp(FeatureName,
"DRGARE", 6))
189 bIsAssociable =
true;
192bool S57Obj::AddIntegerAttribute(
const char *acronym,
int val) {
193 S57attVal *pattValTmp =
new S57attVal;
195 int *pAVI = (
int *)malloc(
sizeof(
int));
198 pattValTmp->valType = OGR_INT;
199 pattValTmp->value = pAVI;
201 att_array = (
char *)realloc(att_array, 6 * (n_attr + 1));
202 strncpy(att_array + (6 *
sizeof(
char) * n_attr), acronym, 6);
205 attVal->Add(pattValTmp);
207 if (!strncmp(acronym,
"SCAMIN", 6)) Scamin = val;
212bool S57Obj::AddIntegerListAttribute(
const char *acronym,
int *pval,
217bool S57Obj::AddDoubleAttribute(
const char *acronym,
double val) {
218 S57attVal *pattValTmp =
new S57attVal;
220 double *pAVI = (
double *)malloc(
sizeof(
double));
223 pattValTmp->valType = OGR_REAL;
224 pattValTmp->value = pAVI;
226 att_array = (
char *)realloc(att_array, 6 * (n_attr + 1));
227 strncpy(att_array + (6 *
sizeof(
char) * n_attr), acronym, 6);
230 attVal->Add(pattValTmp);
235bool S57Obj::AddDoubleListAttribute(
const char *acronym,
double *pval,
240bool S57Obj::AddStringAttribute(
const char *acronym,
char *val) {
241 S57attVal *pattValTmp =
new S57attVal;
243 char *pAVS = (
char *)malloc(strlen(val) + 1);
246 pattValTmp->valType = OGR_STR;
247 pattValTmp->value = pAVS;
249 att_array = (
char *)realloc(att_array, 6 * (n_attr + 1));
250 strncpy(att_array + (6 *
sizeof(
char) * n_attr), acronym, 6);
253 attVal->Add(pattValTmp);
258bool S57Obj::SetPointGeometry(
double lat,
double lon,
double ref_lat,
260 Primitive_type = GEO_POINT;
266 double bound = 1. / 60.;
267 BBObj.Set(m_lat - bound, m_lon - bound, m_lat + bound, m_lon + bound);
268 bBBObj_valid =
false;
271 double easting, northing;
272 toSM(lat, lon, ref_lat, ref_lon, &easting, &northing);
282bool S57Obj::SetLineGeometry(LineGeometryDescriptor *pGeo, GeoPrim_t geoType,
283 double ref_lat,
double ref_lon) {
284 Primitive_type = geoType;
287 BBObj.Set(pGeo->extent_s_lat, pGeo->extent_w_lon, pGeo->extent_n_lat,
292 double e1, e2, n1, n2;
293 toSM(pGeo->extent_n_lat, pGeo->extent_e_lon, ref_lat, ref_lon, &e1, &n1);
294 toSM(pGeo->extent_s_lat, pGeo->extent_w_lon, ref_lat, ref_lon, &e2, &n2);
301 fromSM(x, y, ref_lat, ref_lon, &yll, &xll);
306 m_n_lsindex = pGeo->indexCount;
307 m_lsindex_array = pGeo->indexTable;
309 m_n_edge_max_points =
315bool S57Obj::SetAreaGeometry(PolyTessGeo *ppg,
double ref_lat,
double ref_lon) {
316 Primitive_type = GEO_AREA;
320 BBObj.Set(ppg->Get_ymin(), ppg->Get_xmin(), ppg->Get_ymax(), ppg->Get_xmax());
324 double e1, e2, n1, n2;
325 toSM(ppg->Get_ymax(), ppg->Get_xmax(), ref_lat, ref_lon, &e1, &n1);
326 toSM(ppg->Get_ymin(), ppg->Get_xmin(), ref_lat, ref_lon, &e2, &n2);
333 fromSM(x, y, ref_lat, ref_lon, &yll, &xll);
340bool S57Obj::SetMultipointGeometry(MultipointGeometryDescriptor *pGeo,
341 double ref_lat,
double ref_lon) {
342 Primitive_type = GEO_POINT;
344 npt = pGeo->pointCount;
346 geoPtz = (
double *)malloc(npt * 3 *
sizeof(
double));
347 geoPtMulti = (
double *)malloc(npt * 2 *
sizeof(
double));
349 double *pdd = geoPtz;
350 double *pdl = geoPtMulti;
352 float *pfs = (
float *)(pGeo->pointTable);
353 for (
int ip = 0; ip < npt; ip++) {
354 float easting, northing;
357 float depth = *pfs++;
365 fromSM(easting, northing, ref_lat, ref_lon, &yll, &xll);
372 BBObj.Set(pGeo->extent_s_lat, pGeo->extent_w_lon, pGeo->extent_n_lat,
379int S57Obj::GetAttributeIndex(
const char *AttrSeek) {
380 char *patl = att_array;
382 for (
int i = 0; i < n_attr; i++) {
383 if (!strncmp(patl, AttrSeek, 6)) {
394wxString S57Obj::GetAttrValueAsString(
const char *AttrName) {
397 int idx = GetAttributeIndex(AttrName);
402 S57attVal *v = attVal->Item(idx);
404 switch (v->valType) {
406 char *val = (
char *)(v->value);
407 str.Append(wxString(val, wxConvUTF8));
411 double dval = *(
double *)(v->value);
412 str.Printf(_T(
"%g"), dval);
416 int ival = *((
int *)v->value);
417 str.Printf(_T(
"%d"), ival);
421 str.Printf(_T(
"Unknown attribute type"));