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 char *GetpFullPath() const { return pFullPath; }
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 char *pFullPath;
265 int rounding;
266 int Scale;
267 time_t edition_date;
268 time_t file_date;
269 float *pPlyTable;
270 int nPlyEntries;
271 int nAuxPlyEntries;
272 float **pAuxPlyTable;
273 int *pAuxCntTable;
274 float Skew;
275 int ProjectionType;
276 bool bValid;
277 int nNoCovrPlyEntries;
278 int *pNoCovrCntTable;
279 float **pNoCovrPlyTable;
280
281 std::vector<int> m_GroupArray;
282 wxString *m_pfilename; // a helper member, not on disk
283 wxString *m_psFullPath;
284 wxString m_fullSystemPath;
285 std::string m_FullPath;
286
287 LLBBox m_bbox;
288 bool m_bavail;
289
290 std::vector<float> m_reducedPlyPoints;
291
292 std::vector<std::vector<float>> m_reducedAuxPlyPointsVector;
293};
294
296// Chart Database
298
299WX_DECLARE_OBJARRAY(ChartTableEntry, ChartTable);
300
301#define CTE_THREAD_MAX 1
302
307class ChartDatabase : public wxEvtHandler {
308public:
310 virtual ~ChartDatabase() {};
311
312 void OnEvtThread(OCPN_ChartTableEntryThreadEvent &event);
313 void OnAnyEvent(wxEvent &event);
314
320 bool Create(ArrayOfCDI &dir_array, wxGenericProgressDialog *pprog);
321
328 bool Update(ArrayOfCDI &dir_array, bool bForce,
329 wxGenericProgressDialog *pprog);
330 void FinalizeChartUpdate();
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 bool UpdateChartDatabaseInplace(ArrayOfCDI &DirArray, bool b_force,
347 wxGenericProgressDialog *_prog);
348
349 inline std::vector<std::shared_ptr<ChartTableEntry>> &GetChartTable() {
350 return active_chartTable;
351 }
352 int GetChartTableEntries() const { return active_chartTable.size(); }
353 ChartTableEntry &GetChartTableEntry(int index);
354
355 bool IsValid() const { return bValid; }
356 int DisableChart(wxString &PathToDisable);
357 bool GetCentroidOfLargestScaleChart(double *clat, double *clon,
358 ChartFamilyEnum family);
359 int GetDBChartType(int dbIndex);
360 int GetDBChartFamily(int dbIndex);
361 float GetDBChartSkew(int dbIndex);
362 int GetDBChartProj(int dbIndex);
363 int GetDBChartScale(int dbIndex);
364
365 bool GetDBBoundingBox(int dbindex, LLBBox &box);
366 const LLBBox &GetDBBoundingBox(int dbIndex);
367
368 int GetnAuxPlyEntries(int dbIndex);
369 int GetDBPlyPoint(int dbIndex, int plyindex, float *lat, float *lon);
370 int GetDBAuxPlyPoint(int dbIndex, int plyindex, int iAuxPly, float *lat,
371 float *lon);
372 int GetVersion() { return m_dbversion; }
373 wxString GetFullChartInfo(ChartBase *pc, int dbIndex, int *char_width,
374 int *line_count);
375 int FinddbIndex(wxString PathToFind);
376 wxString GetDBChartFileName(int dbIndex);
377 void ApplyGroupArray(ChartGroupArray *pGroupArray);
378 bool IsChartAvailable(int dbIndex);
379 std::map<wxString, int> active_chartTable_pathindex;
380
381 std::vector<float> GetReducedPlyPoints(int dbIndex);
382 std::vector<float> GetReducedAuxPlyPoints(int dbIndex, int iTable);
383
384 bool IsBusy() { return m_b_busy; }
385 void SetBusy(bool _busy) { m_b_busy = _busy; }
386 bool ScrubGroupArray();
387
388 ChartTableEntry *CreateChartTableEntry(const wxString &filePath,
389 wxString &utf8Path,
390 ChartClassDescriptor &chart_desc);
391
392 std::vector<std::shared_ptr<ChartTableEntry>> active_chartTable;
393 void OnDBSProgressUpdate(wxCommandEvent &evt);
394
395protected:
396 virtual ChartBase *GetChart(const wxChar *theFilePath,
397 ChartClassDescriptor &chart_desc) const;
398 int AddChartDirectory(const wxString &theDir, bool bshow_prog);
399 void SetValid(bool valid) { bValid = valid; }
400
401 std::vector<ChartClassDescriptor> m_ChartClassDescriptorArray;
402 ArrayOfCDI m_dir_array;
403 bool m_b_busy;
404
405private:
406 bool IsChartDirUsed(const wxString &theDir);
407
408 int SearchDirAndAddCharts(wxString &dir_name_base,
409 ChartClassDescriptor &chart_desc,
410 wxGenericProgressDialog *pprog);
411
412 int TraverseDirAndAddCharts(ChartDirInfo &dir_info,
413 wxGenericProgressDialog *pprog,
414 wxString &dir_magic, bool bForce);
415 bool DetectDirChange(const wxString &dir_path, const wxString &prog_label,
416 const wxString &magic, wxString &new_magic,
417 wxGenericProgressDialog *pprog);
418
419 bool AddChart(wxString &chartfilename, ChartClassDescriptor &chart_desc,
420 wxGenericProgressDialog *pprog, int isearch,
421 bool bthis_dir_in_dB);
422
423 bool Check_CM93_Structure(wxString dir_name);
424 void OnProgessTimer(wxTimerEvent &event);
425 void OnUpdateComplete(wxTimerEvent &event);
426
427 void ProcessThreadQueueEmpty();
428
429 bool bValid;
430 wxArrayString m_chartDirs;
431 int m_dbversion;
432
434 m_ChartTableEntryDummy; // used for return value if database is not valid
435
436 wxString m_DBFileName;
437
438 int m_pdifile;
439 int m_pdnFile;
440
441 int m_nentries;
442
443 LLBBox m_dummy_bbox;
444 std::atomic<int> m_jobsRemaining{0};
445 JobQueueCTE m_pool;
446 JobQueueCTE m_pool_deferred;
447
448 std::vector<std::shared_ptr<ChartTableEntryJobTicket>> m_ticket_vector;
449 std::vector<std::shared_ptr<ChartTableEntryJobTicket>>
450 m_deferred_ticket_vector;
451 ChartCollisionsHashMap m_full_collision_map;
452 int m_progcount;
453 int m_ticketcount;
454 wxGenericProgressDialog *m_pprog;
455 wxTimer m_progress_timer;
456 std::atomic<bool> m_progress_dirty{false};
457 int m_progress_value = 0;
458 wxString m_progress_message;
459 wxTimer m_update_competion_timer;
460
461 int m_progint;
462 int m_nFileProgressQuantum;
463 wxString m_gshhg_chart_loc;
464};
465
466//-------------------------------------------------------------------------------------------
467// Chart Group Structure Definitions
468//-------------------------------------------------------------------------------------------
470class ChartGroup;
471
472WX_DEFINE_ARRAY_PTR(ChartGroup *, ChartGroupArray);
473
481 // ChartGroupElements need nothing special to delete since
482 // m_missing_name_array is a wxArrayString which manages
483 // memory for the strings cleanly without need for a .Clear.
484public:
485 wxString m_element_name;
486 wxArrayString m_missing_name_array;
487};
488
501public:
502 wxString m_group_name;
503 std::vector<ChartGroupElement> m_element_array;
504};
505
506#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:307
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:480
Represents a user-defined collection of logically related charts.
Definition chartdbs.h:500
Navigation data types.
Represents an entry in the chart table, containing information about a single chart.
Definition chartdbs.h:190