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 const std::string &GetFullPath() const { return m_FullPath; }
230
231 const std::vector<int> &GetGroupArray(void) const { return m_GroupArray; }
232 void ClearGroupArray(void) { m_GroupArray.clear(); }
233 void AddIntToGroupArray(int val) { m_GroupArray.push_back(val); }
234 void SetAvailable(bool avail) { m_bavail = avail; }
235
236 std::vector<float> GetReducedPlyPoints();
237 std::vector<float> GetReducedAuxPlyPoints(int iTable);
238
239 LLRegion quilt_candidate_region;
240
241 void SetScale(int scale);
242 bool Scale_eq(int b) const { return abs(Scale - b) <= rounding; }
243 bool Scale_ge(int b) const { return Scale_eq(b) || Scale > b; }
244 bool Scale_gt(int b) const { return Scale > b && !Scale_eq(b); }
245
246private:
247 int EntryOffset;
248 int ChartType;
249 int ChartFamily;
250 float LatMax;
251 float LatMin;
252 float LonMax;
253 float LonMin;
254 char *pFullPath;
255 int rounding;
256 int Scale;
257 time_t edition_date;
258 time_t file_date;
259 float *pPlyTable;
260 int nPlyEntries;
261 int nAuxPlyEntries;
262 float **pAuxPlyTable;
263 int *pAuxCntTable;
264 float Skew;
265 int ProjectionType;
266 bool bValid;
267 int nNoCovrPlyEntries;
268 int *pNoCovrCntTable;
269 float **pNoCovrPlyTable;
270
271 std::vector<int> m_GroupArray;
272 wxString *m_pfilename; // a helper member, not on disk
273 wxString *m_psFullPath;
274 wxString m_fullSystemPath;
275 std::string m_FullPath;
276
277 LLBBox m_bbox;
278 bool m_bavail;
279
280 std::vector<float> m_reducedPlyPoints;
281
282 std::vector<std::vector<float>> m_reducedAuxPlyPointsVector;
283};
284
285enum { BUILTIN_DESCRIPTOR = 0, PLUGIN_DESCRIPTOR };
286
288public:
290 virtual ~ChartClassDescriptor() {}
291
292 ChartClassDescriptor(wxString classn, wxString mask, int type)
293 : m_class_name(classn), m_search_mask(mask), m_descriptor_type(type) {};
294
295 wxString m_class_name;
296 wxString m_search_mask;
297 int m_descriptor_type;
298};
299
301// Chart Database
303
304WX_DECLARE_OBJARRAY(ChartTableEntry, ChartTable);
305
311public:
313 virtual ~ChartDatabase() {};
314
320 bool Create(ArrayOfCDI &dir_array, wxGenericProgressDialog *pprog);
321
328 bool Update(ArrayOfCDI &dir_array, bool bForce,
329 wxGenericProgressDialog *pprog);
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
346 int GetChartTableEntries() const { return active_chartTable.size(); }
347 const ChartTableEntry &GetChartTableEntry(int index) const;
348 ChartTableEntry *GetpChartTableEntry(int index) const;
349 inline ChartTable &GetChartTable() { return active_chartTable; }
350
351 bool IsValid() const { return bValid; }
352 int DisableChart(wxString &PathToDisable);
353 bool GetCentroidOfLargestScaleChart(double *clat, double *clon,
354 ChartFamilyEnum family);
355 int GetDBChartType(int dbIndex);
356 int GetDBChartFamily(int dbIndex);
357 float GetDBChartSkew(int dbIndex);
358 int GetDBChartProj(int dbIndex);
359 int GetDBChartScale(int dbIndex);
360
361 bool GetDBBoundingBox(int dbindex, LLBBox &box);
362 const LLBBox &GetDBBoundingBox(int dbIndex);
363
364 int GetnAuxPlyEntries(int dbIndex);
365 int GetDBPlyPoint(int dbIndex, int plyindex, float *lat, float *lon);
366 int GetDBAuxPlyPoint(int dbIndex, int plyindex, int iAuxPly, float *lat,
367 float *lon);
368 int GetVersion() { return m_dbversion; }
369 wxString GetFullChartInfo(ChartBase *pc, int dbIndex, int *char_width,
370 int *line_count);
371 int FinddbIndex(wxString PathToFind);
372 wxString GetDBChartFileName(int dbIndex);
373 void ApplyGroupArray(ChartGroupArray *pGroupArray);
374 bool IsChartAvailable(int dbIndex);
375 ChartTable active_chartTable;
376 std::map<wxString, int> active_chartTable_pathindex;
377
378 std::vector<float> GetReducedPlyPoints(int dbIndex);
379 std::vector<float> GetReducedAuxPlyPoints(int dbIndex, int iTable);
380
381 bool IsBusy() { return m_b_busy; }
382
383protected:
384 virtual ChartBase *GetChart(const wxChar *theFilePath,
385 ChartClassDescriptor &chart_desc) const;
386 int AddChartDirectory(const wxString &theDir, bool bshow_prog);
387 void SetValid(bool valid) { bValid = valid; }
388 ChartTableEntry *CreateChartTableEntry(const wxString &filePath,
389 wxString &utf8Path,
390 ChartClassDescriptor &chart_desc);
391
392 std::vector<ChartClassDescriptor> m_ChartClassDescriptorArray;
393 ArrayOfCDI m_dir_array;
394 bool m_b_busy;
395
396private:
397 bool IsChartDirUsed(const wxString &theDir);
398
399 int SearchDirAndAddCharts(wxString &dir_name_base,
400 ChartClassDescriptor &chart_desc,
401 wxGenericProgressDialog *pprog);
402
403 int TraverseDirAndAddCharts(ChartDirInfo &dir_info,
404 wxGenericProgressDialog *pprog,
405 wxString &dir_magic, bool bForce);
406 bool DetectDirChange(const wxString &dir_path, const wxString &prog_label,
407 const wxString &magic, wxString &new_magic,
408 wxGenericProgressDialog *pprog);
409
410 bool AddChart(wxString &chartfilename, ChartClassDescriptor &chart_desc,
411 wxGenericProgressDialog *pprog, int isearch,
412 bool bthis_dir_in_dB);
413
414 bool Check_CM93_Structure(wxString dir_name);
415
416 bool bValid;
417 wxArrayString m_chartDirs;
418 int m_dbversion;
419
421 m_ChartTableEntryDummy; // used for return value if database is not valid
422 wxString m_DBFileName;
423
424 int m_pdifile;
425 int m_pdnFile;
426
427 int m_nentries;
428
429 LLBBox m_dummy_bbox;
430};
431
432//-------------------------------------------------------------------------------------------
433// Chart Group Structure Definitions
434//-------------------------------------------------------------------------------------------
436class ChartGroup;
437
438WX_DEFINE_ARRAY_PTR(ChartGroup *, ChartGroupArray);
439
447 // ChartGroupElements need nothing special to delete since
448 // m_missing_name_array is a wxArrayString which manages
449 // memory for the strings cleanly without need for a .Clear.
450public:
451 wxString m_element_name;
452 wxArrayString m_missing_name_array;
453};
454
467public:
468 wxString m_group_name;
469 std::vector<ChartGroupElement> m_element_array;
470};
471
472#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:310
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:446
Represents a user-defined collection of logically related charts.
Definition chartdbs.h:466
Represents an entry in the chart table, containing information about a single chart.
Definition chartdbs.h:181