34#include "wx/tokenzr.h"
35#include <wx/textfile.h>
38#include "OCPNPlatform.h"
49#include "ocpn_pixel.h"
52#include "wx28compat.h"
54#include "gdal/cpl_csv.h"
59#include "pluginmanager.h"
64#define _CRTDBG_MAP_ALLOC
67#define DEBUG_NEW new (_NORMAL_BLOCK, __FILE__, __LINE__)
72#include "glChartCanvas.h"
79#define strncasecmp(x, y, z) _strnicmp(x, y, z)
82extern bool g_b_EnableVBO;
89S57Obj::S57Obj() { Init(); }
99 for (
unsigned int iv = 0; iv < attVal->GetCount(); iv++) {
100 S57attVal *vv = attVal->Item(iv);
101 void *v2 = vv->value;
111 bool b_useVBO = g_b_EnableVBO && !auxParm1;
113 PolyTriGroup *ppg_vbo = pPolyTessGeo->Get_PolyTriGroup_head();
114 if (b_useVBO && ppg_vbo && auxParm0 > 0 && ppg_vbo->single_buffer) {
115 glDeleteBuffers(1, (GLuint *)&auxParm0);
121 if (FText)
delete FText;
123 if (geoPt) free(geoPt);
124 if (geoPtz) free(geoPtz);
125 if (geoPtMulti) free(geoPtMulti);
127 if (m_lsindex_array) free(m_lsindex_array);
130 line_segment_element *element = m_ls_list;
132 line_segment_element *next = element->next;
160 bIsAssociable =
false;
162 m_lsindex_array = NULL;
163 m_n_edge_max_points = 0;
165 m_ls_list_legacy = 0;
168 bBBObj_valid =
false;
185S57Obj::S57Obj(
const char *featureName) {
188 attVal =
new wxArrayOfS57attVal();
190 strncpy(FeatureName, featureName, 6);
193 if (!strncmp(FeatureName,
"DEPARE", 6) || !strncmp(FeatureName,
"DRGARE", 6))
194 bIsAssociable =
true;
197bool S57Obj::AddIntegerAttribute(
const char *acronym,
int val) {
198 S57attVal *pattValTmp =
new S57attVal;
200 int *pAVI = (
int *)malloc(
sizeof(
int));
203 pattValTmp->valType = OGR_INT;
204 pattValTmp->value = pAVI;
206 att_array = (
char *)realloc(att_array, 6 * (n_attr + 1));
207 strncpy(att_array + (6 *
sizeof(
char) * n_attr), acronym, 6);
210 attVal->Add(pattValTmp);
212 if (!strncmp(acronym,
"SCAMIN", 6)) Scamin = val;
217bool S57Obj::AddIntegerListAttribute(
const char *acronym,
int *pval,
222bool S57Obj::AddDoubleAttribute(
const char *acronym,
double val) {
223 S57attVal *pattValTmp =
new S57attVal;
225 double *pAVI = (
double *)malloc(
sizeof(
double));
228 pattValTmp->valType = OGR_REAL;
229 pattValTmp->value = pAVI;
231 att_array = (
char *)realloc(att_array, 6 * (n_attr + 1));
232 strncpy(att_array + (6 *
sizeof(
char) * n_attr), acronym, 6);
235 attVal->Add(pattValTmp);
240bool S57Obj::AddDoubleListAttribute(
const char *acronym,
double *pval,
245bool S57Obj::AddStringAttribute(
const char *acronym,
char *val) {
246 S57attVal *pattValTmp =
new S57attVal;
248 char *pAVS = (
char *)malloc(strlen(val) + 1);
251 pattValTmp->valType = OGR_STR;
252 pattValTmp->value = pAVS;
254 att_array = (
char *)realloc(att_array, 6 * (n_attr + 1));
255 strncpy(att_array + (6 *
sizeof(
char) * n_attr), acronym, 6);
258 attVal->Add(pattValTmp);
263bool S57Obj::SetPointGeometry(
double lat,
double lon,
double ref_lat,
265 Primitive_type = GEO_POINT;
271 double bound = 1. / 60.;
272 BBObj.Set(m_lat - bound, m_lon - bound, m_lat + bound, m_lon + bound);
273 bBBObj_valid =
false;
276 double easting, northing;
277 toSM(lat, lon, ref_lat, ref_lon, &easting, &northing);
287bool S57Obj::SetLineGeometry(LineGeometryDescriptor *pGeo, GeoPrim_t geoType,
288 double ref_lat,
double ref_lon) {
289 Primitive_type = geoType;
292 BBObj.Set(pGeo->extent_s_lat, pGeo->extent_w_lon, pGeo->extent_n_lat,
297 double e1, e2, n1, n2;
298 toSM(pGeo->extent_n_lat, pGeo->extent_e_lon, ref_lat, ref_lon, &e1, &n1);
299 toSM(pGeo->extent_s_lat, pGeo->extent_w_lon, ref_lat, ref_lon, &e2, &n2);
306 fromSM(x, y, ref_lat, ref_lon, &yll, &xll);
311 m_n_lsindex = pGeo->indexCount;
312 m_lsindex_array = pGeo->indexTable;
314 m_n_edge_max_points =
320bool S57Obj::SetAreaGeometry(PolyTessGeo *ppg,
double ref_lat,
double ref_lon) {
321 Primitive_type = GEO_AREA;
325 BBObj.Set(ppg->Get_ymin(), ppg->Get_xmin(), ppg->Get_ymax(), ppg->Get_xmax());
329 double e1, e2, n1, n2;
330 toSM(ppg->Get_ymax(), ppg->Get_xmax(), ref_lat, ref_lon, &e1, &n1);
331 toSM(ppg->Get_ymin(), ppg->Get_xmin(), ref_lat, ref_lon, &e2, &n2);
338 fromSM(x, y, ref_lat, ref_lon, &yll, &xll);
345bool S57Obj::SetMultipointGeometry(MultipointGeometryDescriptor *pGeo,
346 double ref_lat,
double ref_lon) {
347 Primitive_type = GEO_POINT;
349 npt = pGeo->pointCount;
351 geoPtz = (
double *)malloc(npt * 3 *
sizeof(
double));
352 geoPtMulti = (
double *)malloc(npt * 2 *
sizeof(
double));
354 double *pdd = geoPtz;
355 double *pdl = geoPtMulti;
357 float *pfs = (
float *)(pGeo->pointTable);
358 for (
int ip = 0; ip < npt; ip++) {
359 float easting, northing;
362 float depth = *pfs++;
370 fromSM(easting, northing, ref_lat, ref_lon, &yll, &xll);
377 BBObj.Set(pGeo->extent_s_lat, pGeo->extent_w_lon, pGeo->extent_n_lat,
384int S57Obj::GetAttributeIndex(
const char *AttrSeek) {
385 char *patl = att_array;
387 for (
int i = 0; i < n_attr; i++) {
388 if (!strncmp(patl, AttrSeek, 6)) {
399wxString S57Obj::GetAttrValueAsString(
const char *AttrName) {
402 int idx = GetAttributeIndex(AttrName);
407 S57attVal *v = attVal->Item(idx);
409 switch (v->valType) {
411 char *val = (
char *)(v->value);
412 str.Append(wxString(val, wxConvUTF8));
416 double dval = *(
double *)(v->value);
417 str.Printf(_T(
"%g"), dval);
421 int ival = *((
int *)v->value);
422 str.Printf(_T(
"%d"), ival);
426 str.Printf(_T(
"Unknown attribute type"));