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 "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};
177
179 ChartTableEntry() { Clear(); }
180 ChartTableEntry(ChartBase &theChart, wxString &utf8Path);
182
183 bool IsEqualTo(const ChartTableEntry &cte) const;
184 bool IsEarlierThan(const ChartTableEntry &cte) const;
185 bool Read(const ChartDatabase *pDb, wxInputStream &is);
186 bool Write(const ChartDatabase *pDb, wxOutputStream &os);
187 void Clear();
188 void Disable();
189 void ReEnable();
190
191 void SetValid(bool valid) { bValid = valid; }
192 time_t GetFileTime() const { return file_date; }
193 time_t GetChartEditionDate() const { return edition_date; }
194
195 int GetnPlyEntries() const { return nPlyEntries; }
196 float *GetpPlyTable() const { return pPlyTable; }
197
198 int GetnAuxPlyEntries() const { return nAuxPlyEntries; }
199 float *GetpAuxPlyTableEntry(int index) const { return pAuxPlyTable[index]; }
200 int GetAuxCntTableEntry(int index) const { return pAuxCntTable[index]; }
201
202 int GetnNoCovrPlyEntries() const { return nNoCovrPlyEntries; }
203 float *GetpNoCovrPlyTableEntry(int index) const {
204 return pNoCovrPlyTable[index];
205 }
206 int GetNoCovrCntTableEntry(int index) const { return pNoCovrCntTable[index]; }
207
208 const LLBBox &GetBBox() const { return m_bbox; }
209
210 char *GetpFullPath() const { return pFullPath; }
211 float GetLonMax() const { return LonMax; }
212 float GetLonMin() const { return LonMin; }
213 float GetLatMax() const { return LatMax; }
214 float GetLatMin() const { return LatMin; }
215 int GetScale() const { return Scale; }
216 int GetChartType() const { return ChartType; }
217 int GetChartFamily() const { return ChartFamily; }
218 int GetChartProjectionType() const { return ProjectionType; }
219 float GetChartSkew() const { return Skew; }
220
221 bool GetbValid() { return bValid; }
222 void SetEntryOffset(int n) { EntryOffset = n; }
223 const wxString *GetpFileName(void) const { return m_pfilename; }
224 wxString *GetpsFullPath(void) const { return m_psFullPath; }
225 wxString GetFullSystemPath() const { return m_fullSystemPath; }
226
227 const std::vector<int> &GetGroupArray(void) const { return m_GroupArray; }
228 void ClearGroupArray(void) { m_GroupArray.clear(); }
229 void AddIntToGroupArray(int val) { m_GroupArray.push_back(val); }
230 void SetAvailable(bool avail) { m_bavail = avail; }
231
232 std::vector<float> GetReducedPlyPoints();
233 std::vector<float> GetReducedAuxPlyPoints(int iTable);
234
235 LLRegion quilt_candidate_region;
236
237 void SetScale(int scale);
238 bool Scale_eq(int b) const { return abs(Scale - b) <= rounding; }
239 bool Scale_ge(int b) const { return Scale_eq(b) || Scale > b; }
240 bool Scale_gt(int b) const { return Scale > b && !Scale_eq(b); }
241
242private:
243 int EntryOffset;
244 int ChartType;
245 int ChartFamily;
246 float LatMax;
247 float LatMin;
248 float LonMax;
249 float LonMin;
250 char *pFullPath;
251 int rounding;
252 int Scale;
253 time_t edition_date;
254 time_t file_date;
255 float *pPlyTable;
256 int nPlyEntries;
257 int nAuxPlyEntries;
258 float **pAuxPlyTable;
259 int *pAuxCntTable;
260 float Skew;
261 int ProjectionType;
262 bool bValid;
263 int nNoCovrPlyEntries;
264 int *pNoCovrCntTable;
265 float **pNoCovrPlyTable;
266
267 std::vector<int> m_GroupArray;
268 wxString *m_pfilename; // a helper member, not on disk
269 wxString *m_psFullPath;
270 wxString m_fullSystemPath;
271
272 LLBBox m_bbox;
273 bool m_bavail;
274
275 std::vector<float> m_reducedPlyPoints;
276
277 std::vector<std::vector<float>> m_reducedAuxPlyPointsVector;
278};
279
280enum { BUILTIN_DESCRIPTOR = 0, PLUGIN_DESCRIPTOR };
281
283public:
285 virtual ~ChartClassDescriptor() {}
286
287 ChartClassDescriptor(wxString classn, wxString mask, int type)
288 : m_class_name(classn), m_search_mask(mask), m_descriptor_type(type){};
289
290 wxString m_class_name;
291 wxString m_search_mask;
292 int m_descriptor_type;
293};
294
296// Chart Database
298
299WX_DECLARE_OBJARRAY(ChartTableEntry, ChartTable);
300WX_DECLARE_OBJARRAY(ChartClassDescriptor, ArrayOfChartClassDescriptor);
301
303public:
305 virtual ~ChartDatabase(){};
306
307 bool Create(ArrayOfCDI &dir_array, wxGenericProgressDialog *pprog);
308 bool Update(ArrayOfCDI &dir_array, bool bForce,
309 wxGenericProgressDialog *pprog);
310
311 bool Read(const wxString &filePath);
312 bool Write(const wxString &filePath);
313
314 bool AddSingleChart(wxString &fullpath, bool b_force_full_search = true);
315 bool RemoveSingleChart(wxString &ChartFullPath);
316
317 const wxString &GetDBFileName() const { return m_DBFileName; }
318 ArrayOfCDI &GetChartDirArray() { return m_dir_array; }
319 wxArrayString &GetChartDirArrayString() { return m_chartDirs; }
320 void SetChartDirArray(ArrayOfCDI array) { m_dir_array = array; }
321 bool CompareChartDirArray(ArrayOfCDI &test_array);
322 wxString GetMagicNumberCached(wxString dir);
323
324 void UpdateChartClassDescriptorArray(void);
325
326 int GetChartTableEntries() const { return active_chartTable.size(); }
327 const ChartTableEntry &GetChartTableEntry(int index) const;
328 ChartTableEntry *GetpChartTableEntry(int index) const;
329 inline ChartTable &GetChartTable() { return active_chartTable; }
330
331 bool IsValid() const { return bValid; }
332 int DisableChart(wxString &PathToDisable);
333 bool GetCentroidOfLargestScaleChart(double *clat, double *clon,
334 ChartFamilyEnum family);
335 int GetDBChartType(int dbIndex);
336 int GetDBChartFamily(int dbIndex);
337 float GetDBChartSkew(int dbIndex);
338 int GetDBChartProj(int dbIndex);
339 int GetDBChartScale(int dbIndex);
340
341 bool GetDBBoundingBox(int dbindex, LLBBox &box);
342 const LLBBox &GetDBBoundingBox(int dbIndex);
343
344 int GetnAuxPlyEntries(int dbIndex);
345 int GetDBPlyPoint(int dbIndex, int plyindex, float *lat, float *lon);
346 int GetDBAuxPlyPoint(int dbIndex, int plyindex, int iAuxPly, float *lat,
347 float *lon);
348 int GetVersion() { return m_dbversion; }
349 wxString GetFullChartInfo(ChartBase *pc, int dbIndex, int *char_width,
350 int *line_count);
351 int FinddbIndex(wxString PathToFind);
352 wxString GetDBChartFileName(int dbIndex);
353 void ApplyGroupArray(ChartGroupArray *pGroupArray);
354 bool IsChartAvailable(int dbIndex);
355 ChartTable active_chartTable;
356 std::map<wxString, int> active_chartTable_pathindex;
357
358 std::vector<float> GetReducedPlyPoints(int dbIndex);
359 std::vector<float> GetReducedAuxPlyPoints(int dbIndex, int iTable);
360
361 bool IsBusy() { return m_b_busy; }
362
363protected:
364 virtual ChartBase *GetChart(const wxChar *theFilePath,
365 ChartClassDescriptor &chart_desc) const;
366 int AddChartDirectory(const wxString &theDir, bool bshow_prog);
367 void SetValid(bool valid) { bValid = valid; }
368 ChartTableEntry *CreateChartTableEntry(const wxString &filePath,
369 wxString &utf8Path,
370 ChartClassDescriptor &chart_desc);
371
372 ArrayOfChartClassDescriptor m_ChartClassDescriptorArray;
373 ArrayOfCDI m_dir_array;
374 bool m_b_busy;
375
376private:
377 bool IsChartDirUsed(const wxString &theDir);
378
379 int SearchDirAndAddCharts(wxString &dir_name_base,
380 ChartClassDescriptor &chart_desc,
381 wxGenericProgressDialog *pprog);
382
383 int TraverseDirAndAddCharts(ChartDirInfo &dir_info,
384 wxGenericProgressDialog *pprog,
385 wxString &dir_magic, bool bForce);
386 bool DetectDirChange(const wxString &dir_path, const wxString &prog_label,
387 const wxString &magic, wxString &new_magic,
388 wxGenericProgressDialog *pprog);
389
390 bool AddChart(wxString &chartfilename, ChartClassDescriptor &chart_desc,
391 wxGenericProgressDialog *pprog, int isearch,
392 bool bthis_dir_in_dB);
393
394 bool Check_CM93_Structure(wxString dir_name);
395
396 bool bValid;
397 wxArrayString m_chartDirs;
398 int m_dbversion;
399
401 m_ChartTableEntryDummy; // used for return value if database is not valid
402 wxString m_DBFileName;
403
404 int m_pdifile;
405 int m_pdnFile;
406
407 int m_nentries;
408
409 LLBBox m_dummy_bbox;
410};
411
412//-------------------------------------------------------------------------------------------
413// Chart Group Structure Definitions
414//-------------------------------------------------------------------------------------------
416class ChartGroup;
417
418WX_DEFINE_ARRAY_PTR(ChartGroup *, ChartGroupArray);
419
421 // ChartGroupElements need nothing special to delete since
422 // m_missing_name_array is a wxArrayString which manages
423 // memory for the strings cleanly without need for a .Clear.
424public:
425 wxString m_element_name;
426 wxArrayString m_missing_name_array;
427};
428
430public:
431 wxString m_group_name;
432 std::vector<ChartGroupElement> m_element_array;
433};
434
435#endif
Definition: Quilt.cpp:864