OpenCPN Partial API docs
Loading...
Searching...
No Matches
chartdbs.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2010 by David S. Register *
3 * Copyright (C) 2010 by Mark A Sikes *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
25#ifndef __CHARTDBS_H__
26#define __CHARTDBS_H__
27
28#include <map>
29#include <memory>
30#include <vector>
31
32#include <wx/progdlg.h>
33
34#include "model/ocpn_types.h"
35#include "bbox.h"
36#include "LLRegion.h"
37
38class ChartGroupArray; // forward
39extern ChartGroupArray *g_pGroupArray;
41// A small class used in an array to describe chart directories
43public:
44 wxString fullpath;
45 wxString magic_number;
46};
47
48WX_DECLARE_OBJARRAY(ChartDirInfo, ArrayOfCDI);
49
51
52static const int DB_VERSION_PREVIOUS = 17;
53static const int DB_VERSION_CURRENT = 18;
54
55class ChartDatabase;
56class ChartGroupArray;
57
59 int EntryOffset;
60 int ChartType;
61 int ChartFamily;
62 float LatMax;
63 float LatMin;
64 float LonMax;
65 float LonMin;
66
67 int Scale;
68 int edition_date;
69 int file_date;
70
71 int nPlyEntries;
72 int nAuxPlyEntries;
73
74 float skew;
75 int ProjectionType;
76 bool bValid;
77
78 int nNoCovrPlyEntries;
79};
80
82 int EntryOffset;
83 int ChartType;
84 float LatMax;
85 float LatMin;
86 float LonMax;
87 float LonMin;
88
89 int Scale;
90 int edition_date;
91 int file_date;
92
93 int nPlyEntries;
94 int nAuxPlyEntries;
95
96 float skew;
97 int ProjectionType;
98 bool bValid;
99
100 int nNoCovrPlyEntries;
101};
102
104 int EntryOffset;
105 int ChartType;
106 float LatMax;
107 float LatMin;
108 float LonMax;
109 float LonMin;
110
111 int Scale;
112 int edition_date;
113 int file_date;
114
115 int nPlyEntries;
116 int nAuxPlyEntries;
117
118 float skew;
119 int ProjectionType;
120 bool bValid;
121};
122
124 int EntryOffset;
125 int ChartType;
126 float LatMax;
127 float LatMin;
128 float LonMax;
129 float LonMin;
130
131 int Scale;
132 time_t edition_date;
133 time_t file_date;
134
135 int nPlyEntries;
136 int nAuxPlyEntries;
137
138 bool bValid;
139};
140
142 int EntryOffset;
143 int ChartType;
144 char ChartID[16];
145 float LatMax;
146 float LatMin;
147 float LonMax;
148 float LonMin;
149 char *pFullPath;
150 int Scale;
151 time_t edition_date;
152 float *pPlyTable;
153 int nPlyEntries;
154 int nAuxPlyEntries;
155 float **pAuxPlyTable;
156 int *pAuxCntTable;
157 bool bValid;
158};
159
162 ChartTableHeader(int dirEntries, int tableEntries)
163 : nTableEntries(tableEntries), nDirEntries(dirEntries) {}
164
165 void Read(wxInputStream &is);
166 void Write(wxOutputStream &os);
167 bool CheckValid();
168 int GetDirEntries() const { return nDirEntries; }
169 int GetTableEntries() const { return nTableEntries; }
170 char *GetDBVersionString() { return dbVersion; }
171
172private:
173 // NOTE: on-disk structure - cannot add, remove, or reorder!
174 char dbVersion[4];
175 int nTableEntries;
176 int nDirEntries;
177};
183 ChartTableEntry() { Clear(); }
184 ChartTableEntry(ChartBase &theChart, wxString &utf8Path);
186
187 bool IsEqualTo(const ChartTableEntry &cte) const;
188 bool IsEarlierThan(const ChartTableEntry &cte) const;
189 bool Read(const ChartDatabase *pDb, wxInputStream &is);
190 bool Write(const ChartDatabase *pDb, wxOutputStream &os);
191 void Clear();
192 void Disable();
193 void ReEnable();
194
195 void SetValid(bool valid) { bValid = valid; }
196 time_t GetFileTime() const { return file_date; }
197 time_t GetChartEditionDate() const { return edition_date; }
198
199 int GetnPlyEntries() const { return nPlyEntries; }
200 float *GetpPlyTable() const { return pPlyTable; }
201
202 int GetnAuxPlyEntries() const { return nAuxPlyEntries; }
203 float *GetpAuxPlyTableEntry(int index) const { return pAuxPlyTable[index]; }
204 int GetAuxCntTableEntry(int index) const { return pAuxCntTable[index]; }
205
206 int GetnNoCovrPlyEntries() const { return nNoCovrPlyEntries; }
207 float *GetpNoCovrPlyTableEntry(int index) const {
208 return pNoCovrPlyTable[index];
209 }
210 int GetNoCovrCntTableEntry(int index) const { return pNoCovrCntTable[index]; }
211
212 const LLBBox &GetBBox() const { return m_bbox; }
213
214 char *GetpFullPath() const { return pFullPath; }
215 float GetLonMax() const { return LonMax; }
216 float GetLonMin() const { return LonMin; }
217 float GetLatMax() const { return LatMax; }
218 float GetLatMin() const { return LatMin; }
219 int GetScale() const { return Scale; }
220 int GetChartType() const { return ChartType; }
221 int GetChartFamily() const { return ChartFamily; }
222 int GetChartProjectionType() const { return ProjectionType; }
223 float GetChartSkew() const { return Skew; }
224
225 bool GetbValid() { return bValid; }
226 void SetEntryOffset(int n) { EntryOffset = n; }
227 const wxString *GetpFileName(void) const { return m_pfilename; }
228 wxString *GetpsFullPath(void) const { return m_psFullPath; }
229 wxString GetFullSystemPath() const { return m_fullSystemPath; }
230 const std::string &GetFullPath() const { return m_FullPath; }
231
232 const std::vector<int> &GetGroupArray(void) const { return m_GroupArray; }
233 void ClearGroupArray(void) { m_GroupArray.clear(); }
234 void AddIntToGroupArray(int val) { m_GroupArray.push_back(val); }
235 void SetAvailable(bool avail) { m_bavail = avail; }
236
237 std::vector<float> GetReducedPlyPoints();
238 std::vector<float> GetReducedAuxPlyPoints(int iTable);
239
240 LLRegion quilt_candidate_region;
241
242 void SetScale(int scale);
243 bool Scale_eq(int b) const { return abs(Scale - b) <= rounding; }
244 bool Scale_ge(int b) const { return Scale_eq(b) || Scale > b; }
245 bool Scale_gt(int b) const { return Scale > b && !Scale_eq(b); }
246
247private:
248 int EntryOffset;
249 int ChartType;
250 int ChartFamily;
251 float LatMax;
252 float LatMin;
253 float LonMax;
254 float LonMin;
255 char *pFullPath;
256 int rounding;
257 int Scale;
258 time_t edition_date;
259 time_t file_date;
260 float *pPlyTable;
261 int nPlyEntries;
262 int nAuxPlyEntries;
263 float **pAuxPlyTable;
264 int *pAuxCntTable;
265 float Skew;
266 int ProjectionType;
267 bool bValid;
268 int nNoCovrPlyEntries;
269 int *pNoCovrCntTable;
270 float **pNoCovrPlyTable;
271
272 std::vector<int> m_GroupArray;
273 wxString *m_pfilename; // a helper member, not on disk
274 wxString *m_psFullPath;
275 wxString m_fullSystemPath;
276 std::string m_FullPath;
277
278 LLBBox m_bbox;
279 bool m_bavail;
280
281 std::vector<float> m_reducedPlyPoints;
282
283 std::vector<std::vector<float>> m_reducedAuxPlyPointsVector;
284};
285
286enum { BUILTIN_DESCRIPTOR = 0, PLUGIN_DESCRIPTOR };
287
289public:
291 virtual ~ChartClassDescriptor() {}
292
293 ChartClassDescriptor(wxString classn, wxString mask, int type)
294 : m_class_name(classn), m_search_mask(mask), m_descriptor_type(type) {};
295
296 wxString m_class_name;
297 wxString m_search_mask;
298 int m_descriptor_type;
299};
300
302// Chart Database
304
305WX_DECLARE_OBJARRAY(ChartTableEntry, ChartTable);
306
312public:
314 virtual ~ChartDatabase() {};
315
321 bool Create(ArrayOfCDI &dir_array, wxGenericProgressDialog *pprog);
322
329 bool Update(ArrayOfCDI &dir_array, bool bForce,
330 wxGenericProgressDialog *pprog);
331
332 bool Read(const wxString &filePath);
333 bool Write(const wxString &filePath);
334
335 bool AddSingleChart(wxString &fullpath, bool b_force_full_search = true);
336 bool RemoveSingleChart(wxString &ChartFullPath);
337
338 const wxString &GetDBFileName() const { return m_DBFileName; }
339 ArrayOfCDI &GetChartDirArray() { return m_dir_array; }
340 wxArrayString &GetChartDirArrayString() { return m_chartDirs; }
341 void SetChartDirArray(ArrayOfCDI array) { m_dir_array = array; }
342 bool CompareChartDirArray(ArrayOfCDI &test_array);
343 wxString GetMagicNumberCached(wxString dir);
344
345 void UpdateChartClassDescriptorArray(void);
346
347 int GetChartTableEntries() const { return active_chartTable.size(); }
348 const ChartTableEntry &GetChartTableEntry(int index) const;
349 ChartTableEntry *GetpChartTableEntry(int index) const;
350 inline ChartTable &GetChartTable() { return active_chartTable; }
351
352 bool IsValid() const { return bValid; }
353 int DisableChart(wxString &PathToDisable);
354 bool GetCentroidOfLargestScaleChart(double *clat, double *clon,
355 ChartFamilyEnum family);
356 int GetDBChartType(int dbIndex);
357 int GetDBChartFamily(int dbIndex);
358 float GetDBChartSkew(int dbIndex);
359 int GetDBChartProj(int dbIndex);
360 int GetDBChartScale(int dbIndex);
361
362 bool GetDBBoundingBox(int dbindex, LLBBox &box);
363 const LLBBox &GetDBBoundingBox(int dbIndex);
364
365 int GetnAuxPlyEntries(int dbIndex);
366 int GetDBPlyPoint(int dbIndex, int plyindex, float *lat, float *lon);
367 int GetDBAuxPlyPoint(int dbIndex, int plyindex, int iAuxPly, float *lat,
368 float *lon);
369 int GetVersion() { return m_dbversion; }
370 wxString GetFullChartInfo(ChartBase *pc, int dbIndex, int *char_width,
371 int *line_count);
372 int FinddbIndex(wxString PathToFind);
373 wxString GetDBChartFileName(int dbIndex);
374 void ApplyGroupArray(ChartGroupArray *pGroupArray);
375 bool IsChartAvailable(int dbIndex);
376 ChartTable active_chartTable;
377 std::map<wxString, int> active_chartTable_pathindex;
378
379 std::vector<float> GetReducedPlyPoints(int dbIndex);
380 std::vector<float> GetReducedAuxPlyPoints(int dbIndex, int iTable);
381
382 bool IsBusy() { return m_b_busy; }
383
384protected:
385 virtual ChartBase *GetChart(const wxChar *theFilePath,
386 ChartClassDescriptor &chart_desc) const;
387 int AddChartDirectory(const wxString &theDir, bool bshow_prog);
388 void SetValid(bool valid) { bValid = valid; }
389 ChartTableEntry *CreateChartTableEntry(const wxString &filePath,
390 wxString &utf8Path,
391 ChartClassDescriptor &chart_desc);
392
393 std::vector<ChartClassDescriptor> m_ChartClassDescriptorArray;
394 ArrayOfCDI m_dir_array;
395 bool m_b_busy;
396
397private:
398 bool IsChartDirUsed(const wxString &theDir);
399
400 int SearchDirAndAddCharts(wxString &dir_name_base,
401 ChartClassDescriptor &chart_desc,
402 wxGenericProgressDialog *pprog);
403
404 int TraverseDirAndAddCharts(ChartDirInfo &dir_info,
405 wxGenericProgressDialog *pprog,
406 wxString &dir_magic, bool bForce);
407 bool DetectDirChange(const wxString &dir_path, const wxString &prog_label,
408 const wxString &magic, wxString &new_magic,
409 wxGenericProgressDialog *pprog);
410
411 bool AddChart(wxString &chartfilename, ChartClassDescriptor &chart_desc,
412 wxGenericProgressDialog *pprog, int isearch,
413 bool bthis_dir_in_dB);
414
415 bool Check_CM93_Structure(wxString dir_name);
416
417 bool bValid;
418 wxArrayString m_chartDirs;
419 int m_dbversion;
420
422 m_ChartTableEntryDummy; // used for return value if database is not valid
423 wxString m_DBFileName;
424
425 int m_pdifile;
426 int m_pdnFile;
427
428 int m_nentries;
429
430 LLBBox m_dummy_bbox;
431};
432
433//-------------------------------------------------------------------------------------------
434// Chart Group Structure Definitions
435//-------------------------------------------------------------------------------------------
437class ChartGroup;
438
439WX_DEFINE_ARRAY_PTR(ChartGroup *, ChartGroupArray);
440
448 // ChartGroupElements need nothing special to delete since
449 // m_missing_name_array is a wxArrayString which manages
450 // memory for the strings cleanly without need for a .Clear.
451public:
452 wxString m_element_name;
453 wxArrayString m_missing_name_array;
454};
455
468public:
469 wxString m_group_name;
470 std::vector<ChartGroupElement> m_element_array;
471};
472
473#endif
ChartGroupArray * g_pGroupArray
Global instance.
Definition chartdbs.cpp:54
Base class for all chart types.
Definition chartbase.h:125
Manages a database of charts, including reading, writing, and querying chart information.
Definition chartdbs.h:311
bool Create(ArrayOfCDI &dir_array, wxGenericProgressDialog *pprog)
Creates a new chart database from a list of directories.
bool Update(ArrayOfCDI &dir_array, bool bForce, wxGenericProgressDialog *pprog)
Updates the chart database.
Represents an individual component within a ChartGroup.
Definition chartdbs.h:447
Represents a user-defined collection of logically related charts.
Definition chartdbs.h:467
Represents an entry in the chart table, containing information about a single chart.
Definition chartdbs.h:182