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;
40class ChartBase; // Circular if including chcanv.h in gui...
41
42// A small class used in an array to describe chart directories
44public:
45 wxString fullpath;
46 wxString magic_number;
47};
48
49WX_DECLARE_OBJARRAY(ChartDirInfo, ArrayOfCDI);
50
52
53static const int DB_VERSION_PREVIOUS = 17;
54static const int DB_VERSION_CURRENT = 18;
55
56class ChartDatabase;
57class ChartGroupArray;
58
60 int EntryOffset;
61 int ChartType;
62 int ChartFamily;
63 float LatMax;
64 float LatMin;
65 float LonMax;
66 float LonMin;
67
68 int Scale;
69 int edition_date;
70 int file_date;
71
72 int nPlyEntries;
73 int nAuxPlyEntries;
74
75 float skew;
76 int ProjectionType;
77 bool bValid;
78
79 int nNoCovrPlyEntries;
80};
81
83 int EntryOffset;
84 int ChartType;
85 float LatMax;
86 float LatMin;
87 float LonMax;
88 float LonMin;
89
90 int Scale;
91 int edition_date;
92 int file_date;
93
94 int nPlyEntries;
95 int nAuxPlyEntries;
96
97 float skew;
98 int ProjectionType;
99 bool bValid;
100
101 int nNoCovrPlyEntries;
102};
103
105 int EntryOffset;
106 int ChartType;
107 float LatMax;
108 float LatMin;
109 float LonMax;
110 float LonMin;
111
112 int Scale;
113 int edition_date;
114 int file_date;
115
116 int nPlyEntries;
117 int nAuxPlyEntries;
118
119 float skew;
120 int ProjectionType;
121 bool bValid;
122};
123
125 int EntryOffset;
126 int ChartType;
127 float LatMax;
128 float LatMin;
129 float LonMax;
130 float LonMin;
131
132 int Scale;
133 time_t edition_date;
134 time_t file_date;
135
136 int nPlyEntries;
137 int nAuxPlyEntries;
138
139 bool bValid;
140};
141
143 int EntryOffset;
144 int ChartType;
145 char ChartID[16];
146 float LatMax;
147 float LatMin;
148 float LonMax;
149 float LonMin;
150 char *pFullPath;
151 int Scale;
152 time_t edition_date;
153 float *pPlyTable;
154 int nPlyEntries;
155 int nAuxPlyEntries;
156 float **pAuxPlyTable;
157 int *pAuxCntTable;
158 bool bValid;
159};
160
163 ChartTableHeader(int dirEntries, int tableEntries)
164 : nTableEntries(tableEntries), nDirEntries(dirEntries) {}
165
166 void Read(wxInputStream &is);
167 void Write(wxOutputStream &os);
168 bool CheckValid();
169 int GetDirEntries() const { return nDirEntries; }
170 int GetTableEntries() const { return nTableEntries; }
171 char *GetDBVersionString() { return dbVersion; }
172
173private:
174 // NOTE: on-disk structure - cannot add, remove, or reorder!
175 char dbVersion[4];
176 int nTableEntries;
177 int nDirEntries;
178};
184 ChartTableEntry() { Clear(); }
185 ChartTableEntry(ChartBase &theChart, wxString &utf8Path);
187
188 bool IsEqualTo(const ChartTableEntry &cte) const;
189 bool IsEarlierThan(const ChartTableEntry &cte) const;
190 bool Read(const ChartDatabase *pDb, wxInputStream &is);
191 bool Write(const ChartDatabase *pDb, wxOutputStream &os);
192 void Clear();
193 void Disable();
194 void ReEnable();
195
196 void SetValid(bool valid) { bValid = valid; }
197 time_t GetFileTime() const { return file_date; }
198 time_t GetChartEditionDate() const { return edition_date; }
199
200 int GetnPlyEntries() const { return nPlyEntries; }
201 float *GetpPlyTable() const { return pPlyTable; }
202
203 int GetnAuxPlyEntries() const { return nAuxPlyEntries; }
204 float *GetpAuxPlyTableEntry(int index) const { return pAuxPlyTable[index]; }
205 int GetAuxCntTableEntry(int index) const { return pAuxCntTable[index]; }
206
207 int GetnNoCovrPlyEntries() const { return nNoCovrPlyEntries; }
208 float *GetpNoCovrPlyTableEntry(int index) const {
209 return pNoCovrPlyTable[index];
210 }
211 int GetNoCovrCntTableEntry(int index) const { return pNoCovrCntTable[index]; }
212
213 const LLBBox &GetBBox() const { return m_bbox; }
214
215 char *GetpFullPath() const { return pFullPath; }
216 float GetLonMax() const { return LonMax; }
217 float GetLonMin() const { return LonMin; }
218 float GetLatMax() const { return LatMax; }
219 float GetLatMin() const { return LatMin; }
220 int GetScale() const { return Scale; }
221 int GetChartType() const { return ChartType; }
222 int GetChartFamily() const { return ChartFamily; }
223 int GetChartProjectionType() const { return ProjectionType; }
224 float GetChartSkew() const { return Skew; }
225
226 bool GetbValid() { return bValid; }
227 void SetEntryOffset(int n) { EntryOffset = n; }
228 const wxString *GetpFileName(void) const { return m_pfilename; }
229 wxString *GetpsFullPath(void) const { return m_psFullPath; }
230 wxString GetFullSystemPath() const { return m_fullSystemPath; }
231 const std::string &GetFullPath() const { return m_FullPath; }
232
233 const std::vector<int> &GetGroupArray(void) const { return m_GroupArray; }
234 void ClearGroupArray(void) { m_GroupArray.clear(); }
235 void AddIntToGroupArray(int val) { m_GroupArray.push_back(val); }
236 void SetAvailable(bool avail) { m_bavail = avail; }
237
238 std::vector<float> GetReducedPlyPoints();
239 std::vector<float> GetReducedAuxPlyPoints(int iTable);
240
241 LLRegion quilt_candidate_region;
242
243 void SetScale(int scale);
244 bool Scale_eq(int b) const { return abs(Scale - b) <= rounding; }
245 bool Scale_ge(int b) const { return Scale_eq(b) || Scale > b; }
246 bool Scale_gt(int b) const { return Scale > b && !Scale_eq(b); }
247
248private:
249 int EntryOffset;
250 int ChartType;
251 int ChartFamily;
252 float LatMax;
253 float LatMin;
254 float LonMax;
255 float LonMin;
256 char *pFullPath;
257 int rounding;
258 int Scale;
259 time_t edition_date;
260 time_t file_date;
261 float *pPlyTable;
262 int nPlyEntries;
263 int nAuxPlyEntries;
264 float **pAuxPlyTable;
265 int *pAuxCntTable;
266 float Skew;
267 int ProjectionType;
268 bool bValid;
269 int nNoCovrPlyEntries;
270 int *pNoCovrCntTable;
271 float **pNoCovrPlyTable;
272
273 std::vector<int> m_GroupArray;
274 wxString *m_pfilename; // a helper member, not on disk
275 wxString *m_psFullPath;
276 wxString m_fullSystemPath;
277 std::string m_FullPath;
278
279 LLBBox m_bbox;
280 bool m_bavail;
281
282 std::vector<float> m_reducedPlyPoints;
283
284 std::vector<std::vector<float>> m_reducedAuxPlyPointsVector;
285};
286
287enum { BUILTIN_DESCRIPTOR = 0, PLUGIN_DESCRIPTOR };
288
290public:
292 virtual ~ChartClassDescriptor() {}
293
294 ChartClassDescriptor(wxString classn, wxString mask, int type)
295 : m_class_name(classn), m_search_mask(mask), m_descriptor_type(type) {};
296
297 wxString m_class_name;
298 wxString m_search_mask;
299 int m_descriptor_type;
300};
301
303// Chart Database
305
306WX_DECLARE_OBJARRAY(ChartTableEntry, ChartTable);
307
313public:
315 virtual ~ChartDatabase() {};
316
322 bool Create(ArrayOfCDI &dir_array, wxGenericProgressDialog *pprog);
323
330 bool Update(ArrayOfCDI &dir_array, bool bForce,
331 wxGenericProgressDialog *pprog);
332
333 bool Read(const wxString &filePath);
334 bool Write(const wxString &filePath);
335
336 bool AddSingleChart(wxString &fullpath, bool b_force_full_search = true);
337 bool RemoveSingleChart(wxString &ChartFullPath);
338
339 const wxString &GetDBFileName() const { return m_DBFileName; }
340 ArrayOfCDI &GetChartDirArray() { return m_dir_array; }
341 wxArrayString &GetChartDirArrayString() { return m_chartDirs; }
342 void SetChartDirArray(ArrayOfCDI array) { m_dir_array = array; }
343 bool CompareChartDirArray(ArrayOfCDI &test_array);
344 wxString GetMagicNumberCached(wxString dir);
345
346 void UpdateChartClassDescriptorArray(void);
347
348 int GetChartTableEntries() const { return active_chartTable.size(); }
349 const ChartTableEntry &GetChartTableEntry(int index) const;
350 ChartTableEntry *GetpChartTableEntry(int index) const;
351 inline ChartTable &GetChartTable() { return active_chartTable; }
352
353 bool IsValid() const { return bValid; }
354 int DisableChart(wxString &PathToDisable);
355 bool GetCentroidOfLargestScaleChart(double *clat, double *clon,
356 ChartFamilyEnum family);
357 int GetDBChartType(int dbIndex);
358 int GetDBChartFamily(int dbIndex);
359 float GetDBChartSkew(int dbIndex);
360 int GetDBChartProj(int dbIndex);
361 int GetDBChartScale(int dbIndex);
362
363 bool GetDBBoundingBox(int dbindex, LLBBox &box);
364 const LLBBox &GetDBBoundingBox(int dbIndex);
365
366 int GetnAuxPlyEntries(int dbIndex);
367 int GetDBPlyPoint(int dbIndex, int plyindex, float *lat, float *lon);
368 int GetDBAuxPlyPoint(int dbIndex, int plyindex, int iAuxPly, float *lat,
369 float *lon);
370 int GetVersion() { return m_dbversion; }
371 wxString GetFullChartInfo(ChartBase *pc, int dbIndex, int *char_width,
372 int *line_count);
373 int FinddbIndex(wxString PathToFind);
374 wxString GetDBChartFileName(int dbIndex);
375 void ApplyGroupArray(ChartGroupArray *pGroupArray);
376 bool IsChartAvailable(int dbIndex);
377 ChartTable active_chartTable;
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
385protected:
386 virtual ChartBase *GetChart(const wxChar *theFilePath,
387 ChartClassDescriptor &chart_desc) const;
388 int AddChartDirectory(const wxString &theDir, bool bshow_prog);
389 void SetValid(bool valid) { bValid = valid; }
390 ChartTableEntry *CreateChartTableEntry(const wxString &filePath,
391 wxString &utf8Path,
392 ChartClassDescriptor &chart_desc);
393
394 std::vector<ChartClassDescriptor> m_ChartClassDescriptorArray;
395 ArrayOfCDI m_dir_array;
396 bool m_b_busy;
397
398private:
399 bool IsChartDirUsed(const wxString &theDir);
400
401 int SearchDirAndAddCharts(wxString &dir_name_base,
402 ChartClassDescriptor &chart_desc,
403 wxGenericProgressDialog *pprog);
404
405 int TraverseDirAndAddCharts(ChartDirInfo &dir_info,
406 wxGenericProgressDialog *pprog,
407 wxString &dir_magic, bool bForce);
408 bool DetectDirChange(const wxString &dir_path, const wxString &prog_label,
409 const wxString &magic, wxString &new_magic,
410 wxGenericProgressDialog *pprog);
411
412 bool AddChart(wxString &chartfilename, ChartClassDescriptor &chart_desc,
413 wxGenericProgressDialog *pprog, int isearch,
414 bool bthis_dir_in_dB);
415
416 bool Check_CM93_Structure(wxString dir_name);
417
418 bool bValid;
419 wxArrayString m_chartDirs;
420 int m_dbversion;
421
423 m_ChartTableEntryDummy; // used for return value if database is not valid
424 wxString m_DBFileName;
425
426 int m_pdifile;
427 int m_pdnFile;
428
429 int m_nentries;
430
431 LLBBox m_dummy_bbox;
432};
433
434//-------------------------------------------------------------------------------------------
435// Chart Group Structure Definitions
436//-------------------------------------------------------------------------------------------
438class ChartGroup;
439
440WX_DEFINE_ARRAY_PTR(ChartGroup *, ChartGroupArray);
441
449 // ChartGroupElements need nothing special to delete since
450 // m_missing_name_array is a wxArrayString which manages
451 // memory for the strings cleanly without need for a .Clear.
452public:
453 wxString m_element_name;
454 wxArrayString m_missing_name_array;
455};
456
469public:
470 wxString m_group_name;
471 std::vector<ChartGroupElement> m_element_array;
472};
473
474#endif
ChartGroupArray * g_pGroupArray
Global instance.
Definition chartdbs.cpp:56
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:312
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:448
Represents a user-defined collection of logically related charts.
Definition chartdbs.h:468
Navigation data types.
Represents an entry in the chart table, containing information about a single chart.
Definition chartdbs.h:183