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