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#include <atomic>
32
33#include <wx/progdlg.h>
34#include <wx/thread.h>
35
36#include "model/ocpn_types.h"
37#include "bbox.h"
38#include "LLRegion.h"
39#include "chartdb_thread.h"
40
41class ChartGroupArray; // forward
42extern ChartGroupArray *g_pGroupArray;
43class ChartBase; // Circular if including chcanv.h in gui...
44
45// A small class used in an array to describe chart directories
47public:
48 wxString fullpath;
49 wxString magic_number;
50};
51
52WX_DECLARE_OBJARRAY(ChartDirInfo, ArrayOfCDI);
53WX_DECLARE_STRING_HASH_MAP(int, ChartCollisionsHashMap);
54
55#define ID_TIMER_UPDATE_PROGRESS 10337
56#define ID_TIMER_UPDATE_COMPLETE 10338
57
59
60static const int DB_VERSION_PREVIOUS = 17;
61static const int DB_VERSION_CURRENT = 18;
62
63class ChartDatabase;
64class ChartGroupArray;
65
67 int EntryOffset;
68 int ChartType;
69 int ChartFamily;
70 float LatMax;
71 float LatMin;
72 float LonMax;
73 float LonMin;
74
75 int Scale;
76 int edition_date;
77 int file_date;
78
79 int nPlyEntries;
80 int nAuxPlyEntries;
81
82 float skew;
83 int ProjectionType;
84 bool bValid;
85
86 int nNoCovrPlyEntries;
87};
88
90 int EntryOffset;
91 int ChartType;
92 float LatMax;
93 float LatMin;
94 float LonMax;
95 float LonMin;
96
97 int Scale;
98 int edition_date;
99 int file_date;
100
101 int nPlyEntries;
102 int nAuxPlyEntries;
103
104 float skew;
105 int ProjectionType;
106 bool bValid;
107
108 int nNoCovrPlyEntries;
109};
110
112 int EntryOffset;
113 int ChartType;
114 float LatMax;
115 float LatMin;
116 float LonMax;
117 float LonMin;
118
119 int Scale;
120 int edition_date;
121 int file_date;
122
123 int nPlyEntries;
124 int nAuxPlyEntries;
125
126 float skew;
127 int ProjectionType;
128 bool bValid;
129};
130
132 int EntryOffset;
133 int ChartType;
134 float LatMax;
135 float LatMin;
136 float LonMax;
137 float LonMin;
138
139 int Scale;
140 time_t edition_date;
141 time_t file_date;
142
143 int nPlyEntries;
144 int nAuxPlyEntries;
145
146 bool bValid;
147};
148
150 int EntryOffset;
151 int ChartType;
152 char ChartID[16];
153 float LatMax;
154 float LatMin;
155 float LonMax;
156 float LonMin;
157 char *pFullPath;
158 int Scale;
159 time_t edition_date;
160 float *pPlyTable;
161 int nPlyEntries;
162 int nAuxPlyEntries;
163 float **pAuxPlyTable;
164 int *pAuxCntTable;
165 bool bValid;
166};
167
170 ChartTableHeader(int dirEntries, int tableEntries)
171 : nTableEntries(tableEntries), nDirEntries(dirEntries) {}
172
173 void Read(wxInputStream &is);
174 void Write(wxOutputStream &os);
175 bool CheckValid();
176 int GetDirEntries() const { return nDirEntries; }
177 int GetTableEntries() const { return nTableEntries; }
178 char *GetDBVersionString() { return dbVersion; }
179
180private:
181 // NOTE: on-disk structure - cannot add, remove, or reorder!
182 char dbVersion[4];
183 int nTableEntries;
184 int nDirEntries;
185};
191 ChartTableEntry() { Clear(); }
192 ChartTableEntry(ChartBase &theChart, wxString &utf8Path);
194
195 bool IsEqualTo(const ChartTableEntry &cte) const;
196 bool IsEarlierThan(const ChartTableEntry &cte) const;
197 bool Read(const ChartDatabase *pDb, wxInputStream &is);
198 bool Write(const ChartDatabase *pDb, wxOutputStream &os);
199 void Clear();
200 void Disable();
201 void ReEnable();
202
203 void SetValid(bool valid) { bValid = valid; }
204 time_t GetFileTime() const { return file_date; }
205 time_t GetChartEditionDate() const { return edition_date; }
206
207 int GetnPlyEntries() const { return nPlyEntries; }
208 float *GetpPlyTable() const { return pPlyTable; }
209
210 int GetnAuxPlyEntries() const { return nAuxPlyEntries; }
211 float *GetpAuxPlyTableEntry(int index) const { return pAuxPlyTable[index]; }
212 int GetAuxCntTableEntry(int index) const { return pAuxCntTable[index]; }
213
214 int GetnNoCovrPlyEntries() const { return nNoCovrPlyEntries; }
215 float *GetpNoCovrPlyTableEntry(int index) const {
216 return pNoCovrPlyTable[index];
217 }
218 int GetNoCovrCntTableEntry(int index) const { return pNoCovrCntTable[index]; }
219
220 const LLBBox &GetBBox() const { return m_bbox; }
221
222 const char *GetpFullPath() const { return m_FullPath.c_str(); }
223 float GetLonMax() const { return LonMax; }
224 float GetLonMin() const { return LonMin; }
225 float GetLatMax() const { return LatMax; }
226 float GetLatMin() const { return LatMin; }
227 int GetScale() const { return Scale; }
228 int GetChartType() const { return ChartType; }
229 int GetChartFamily() const { return ChartFamily; }
230 int GetChartProjectionType() const { return ProjectionType; }
231 float GetChartSkew() const { return Skew; }
232
233 bool GetbValid() { return bValid; }
234 void SetEntryOffset(int n) { EntryOffset = n; }
235 const wxString *GetpFileName(void) const { return m_pfilename; }
236 wxString *GetpsFullPath(void) const { return m_psFullPath; }
237 wxString GetFullSystemPath() const { return m_fullSystemPath; }
238 const std::string &GetFullPath() const { return m_FullPath; }
239
240 const std::vector<int> &GetGroupArray(void) const { return m_GroupArray; }
241 void ClearGroupArray(void) { m_GroupArray.clear(); }
242 void AddIntToGroupArray(int val) { m_GroupArray.push_back(val); }
243 void SetAvailable(bool avail) { m_bavail = avail; }
244
245 std::vector<float> GetReducedPlyPoints();
246 std::vector<float> GetReducedAuxPlyPoints(int iTable);
247
248 LLRegion quilt_candidate_region;
249
250 void SetScale(int scale);
251 bool Scale_eq(int b) const { return abs(Scale - b) <= rounding; }
252 bool Scale_ge(int b) const { return Scale_eq(b) || Scale > b; }
253 bool Scale_gt(int b) const { return Scale > b && !Scale_eq(b); }
254 bool IsBasemap() const;
255
256private:
257 int EntryOffset;
258 int ChartType;
259 int ChartFamily;
260 float LatMax;
261 float LatMin;
262 float LonMax;
263 float LonMin;
264 int rounding;
265 int Scale;
266 time_t edition_date;
267 time_t file_date;
268 float *pPlyTable;
269 int nPlyEntries;
270 int nAuxPlyEntries;
271 float **pAuxPlyTable;
272 int *pAuxCntTable;
273 float Skew;
274 int ProjectionType;
275 bool bValid;
276 int nNoCovrPlyEntries;
277 int *pNoCovrCntTable;
278 float **pNoCovrPlyTable;
279
280 std::vector<int> m_GroupArray;
281 wxString *m_pfilename; // a helper member, not on disk
282 wxString *m_psFullPath;
283 wxString m_fullSystemPath;
284 std::string m_FullPath;
285
286 LLBBox m_bbox;
287 bool m_bavail;
288
289 std::vector<float> m_reducedPlyPoints;
290
291 std::vector<std::vector<float>> m_reducedAuxPlyPointsVector;
292};
293
295// Chart Database
297
298WX_DECLARE_OBJARRAY(ChartTableEntry, ChartTable);
299
300#define CTE_THREAD_MAX 1
301
306class ChartDatabase : public wxEvtHandler {
307public:
309 virtual ~ChartDatabase() {};
310
311 void OnEvtThread(OCPN_ChartTableEntryThreadEvent &event);
312 void OnAnyEvent(wxEvent &event);
313
319 bool Create(ArrayOfCDI &dir_array, wxGenericProgressDialog *pprog);
320
327 bool Update(ArrayOfCDI &dir_array, bool bForce,
328 wxGenericProgressDialog *pprog);
329 void FinalizeChartUpdate();
330
331 bool Read(const wxString &filePath);
332 bool Write(const wxString &filePath);
333
334 bool AddSingleChart(wxString &fullpath, bool b_force_full_search = true);
335 bool RemoveSingleChart(wxString &ChartFullPath);
336
337 const wxString &GetDBFileName() const { return m_DBFileName; }
338 ArrayOfCDI &GetChartDirArray() { return m_dir_array; }
339 wxArrayString &GetChartDirArrayString() { return m_chartDirs; }
340 void SetChartDirArray(ArrayOfCDI array) { m_dir_array = array; }
341 bool CompareChartDirArray(ArrayOfCDI &test_array);
342 wxString GetMagicNumberCached(wxString dir);
343
344 void UpdateChartClassDescriptorArray(void);
345 bool UpdateChartDatabaseInplace(ArrayOfCDI &DirArray, bool b_force,
346 wxGenericProgressDialog *_prog);
347
348 inline std::vector<std::shared_ptr<ChartTableEntry>> &GetChartTable() {
349 return active_chartTable;
350 }
351 int GetChartTableEntries() const { return active_chartTable.size(); }
352 ChartTableEntry &GetChartTableEntry(int index);
353
354 bool IsValid() const { return bValid; }
355 int DisableChart(wxString &PathToDisable);
356 bool GetCentroidOfLargestScaleChart(double *clat, double *clon,
357 ChartFamilyEnum family);
358 int GetDBChartType(int dbIndex);
359 int GetDBChartFamily(int dbIndex);
360 float GetDBChartSkew(int dbIndex);
361 int GetDBChartProj(int dbIndex);
362 int GetDBChartScale(int dbIndex);
363
364 bool GetDBBoundingBox(int dbindex, LLBBox &box);
365 const LLBBox &GetDBBoundingBox(int dbIndex);
366
367 int GetnAuxPlyEntries(int dbIndex);
368 int GetDBPlyPoint(int dbIndex, int plyindex, float *lat, float *lon);
369 int GetDBAuxPlyPoint(int dbIndex, int plyindex, int iAuxPly, float *lat,
370 float *lon);
371 int GetVersion() { return m_dbversion; }
372 wxString GetFullChartInfo(ChartBase *pc, int dbIndex, int *char_width,
373 int *line_count);
374 int FinddbIndex(wxString PathToFind);
375 wxString GetDBChartFileName(int dbIndex);
376 void ApplyGroupArray(ChartGroupArray *pGroupArray);
377 bool IsChartAvailable(int dbIndex);
378 std::map<wxString, int> active_chartTable_pathindex;
379
380 std::vector<float> GetReducedPlyPoints(int dbIndex);
381 std::vector<float> GetReducedAuxPlyPoints(int dbIndex, int iTable);
382
383 bool IsBusy() { return m_b_busy; }
384 void SetBusy(bool _busy) { m_b_busy = _busy; }
385 bool ScrubGroupArray();
386
387 ChartTableEntry *CreateChartTableEntry(const wxString &filePath,
388 wxString &utf8Path,
389 ChartClassDescriptor &chart_desc);
390
391 std::vector<std::shared_ptr<ChartTableEntry>> active_chartTable;
392 void OnDBSProgressUpdate(wxCommandEvent &evt);
393
394protected:
395 virtual ChartBase *GetChart(const wxChar *theFilePath,
396 ChartClassDescriptor &chart_desc) const;
397 int AddChartDirectory(const wxString &theDir, bool bshow_prog);
398 void SetValid(bool valid) { bValid = valid; }
399
400 std::vector<ChartClassDescriptor> m_ChartClassDescriptorArray;
401 ArrayOfCDI m_dir_array;
402 bool m_b_busy;
403
404private:
405 bool IsChartDirUsed(const wxString &theDir);
406
407 int SearchDirAndAddCharts(wxString &dir_name_base,
408 ChartClassDescriptor &chart_desc,
409 wxGenericProgressDialog *pprog);
410
411 int TraverseDirAndAddCharts(ChartDirInfo &dir_info,
412 wxGenericProgressDialog *pprog,
413 wxString &dir_magic, bool bForce);
414 bool DetectDirChange(const wxString &dir_path, const wxString &prog_label,
415 const wxString &magic, wxString &new_magic,
416 wxGenericProgressDialog *pprog);
417
418 bool AddChart(wxString &chartfilename, ChartClassDescriptor &chart_desc,
419 wxGenericProgressDialog *pprog, int isearch,
420 bool bthis_dir_in_dB);
421
422 bool Check_CM93_Structure(wxString dir_name);
423 void OnProgessTimer(wxTimerEvent &event);
424 void OnUpdateComplete(wxTimerEvent &event);
425
426 void ProcessThreadQueueEmpty();
427
428 bool bValid;
429 wxArrayString m_chartDirs;
430 int m_dbversion;
431
433 m_ChartTableEntryDummy; // used for return value if database is not valid
434
435 wxString m_DBFileName;
436
437 int m_pdifile;
438 int m_pdnFile;
439
440 int m_nentries;
441
442 LLBBox m_dummy_bbox;
443 std::atomic<int> m_jobsRemaining{0};
444 JobQueueCTE m_pool;
445 JobQueueCTE m_pool_deferred;
446
447 std::vector<std::shared_ptr<ChartTableEntryJobTicket>> m_ticket_vector;
448 std::vector<std::shared_ptr<ChartTableEntryJobTicket>>
449 m_deferred_ticket_vector;
450 ChartCollisionsHashMap m_full_collision_map;
451 int m_progcount;
452 int m_ticketcount;
453 wxGenericProgressDialog *m_pprog;
454 wxTimer m_progress_timer;
455 std::atomic<bool> m_progress_dirty{false};
456 int m_progress_value = 0;
457 wxString m_progress_message;
458 wxTimer m_update_competion_timer;
459
460 int m_progint;
461 int m_nFileProgressQuantum;
462 wxString m_gshhg_chart_loc;
463};
464
465//-------------------------------------------------------------------------------------------
466// Chart Group Structure Definitions
467//-------------------------------------------------------------------------------------------
469class ChartGroup;
470
471WX_DEFINE_ARRAY_PTR(ChartGroup *, ChartGroupArray);
472
480 // ChartGroupElements need nothing special to delete since
481 // m_missing_name_array is a wxArrayString which manages
482 // memory for the strings cleanly without need for a .Clear.
483public:
484 wxString m_element_name;
485 wxArrayString m_missing_name_array;
486};
487
500public:
501 wxString m_group_name;
502 std::vector<ChartGroupElement> m_element_array;
503};
504
505#endif
Define threaded chart database classes.
ChartGroupArray * g_pGroupArray
Global instance.
Definition chartdbs.cpp:61
Base class for all chart types.
Definition chartbase.h:126
Manages a database of charts, including reading, writing, and querying chart information.
Definition chartdbs.h:306
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:479
Represents a user-defined collection of logically related charts.
Definition chartdbs.h:499
Navigation data types.
Represents an entry in the chart table, containing information about a single chart.
Definition chartdbs.h:190