OpenCPN Partial API docs
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 
37 class wxGenericProgressDialog;
38 class ChartBase;
39 
40 // A small class used in an array to describe chart directories
41 class ChartDirInfo {
42 public:
43  wxString fullpath;
44  wxString magic_number;
45 };
46 
47 WX_DECLARE_OBJARRAY(ChartDirInfo, ArrayOfCDI);
48 
50 
51 static const int DB_VERSION_PREVIOUS = 17;
52 static const int DB_VERSION_CURRENT = 18;
53 
54 class ChartDatabase;
55 class 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 
160  ChartTableHeader() {}
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 
171 private:
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);
181  ~ChartTableEntry();
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 
242 private:
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 
280 enum { BUILTIN_DESCRIPTOR = 0, PLUGIN_DESCRIPTOR };
281 
283 public:
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 
299 WX_DECLARE_OBJARRAY(ChartTableEntry, ChartTable);
300 
302 public:
303  ChartDatabase();
304  virtual ~ChartDatabase(){};
305 
306  bool Create(ArrayOfCDI &dir_array, wxGenericProgressDialog *pprog);
307  bool Update(ArrayOfCDI &dir_array, bool bForce,
308  wxGenericProgressDialog *pprog);
309 
310  bool Read(const wxString &filePath);
311  bool Write(const wxString &filePath);
312 
313  bool AddSingleChart(wxString &fullpath, bool b_force_full_search = true);
314  bool RemoveSingleChart(wxString &ChartFullPath);
315 
316  const wxString &GetDBFileName() const { return m_DBFileName; }
317  ArrayOfCDI &GetChartDirArray() { return m_dir_array; }
318  wxArrayString &GetChartDirArrayString() { return m_chartDirs; }
319  void SetChartDirArray(ArrayOfCDI array) { m_dir_array = array; }
320  bool CompareChartDirArray(ArrayOfCDI &test_array);
321  wxString GetMagicNumberCached(wxString dir);
322 
323  void UpdateChartClassDescriptorArray(void);
324 
325  int GetChartTableEntries() const { return active_chartTable.size(); }
326  const ChartTableEntry &GetChartTableEntry(int index) const;
327  ChartTableEntry *GetpChartTableEntry(int index) const;
328  inline ChartTable &GetChartTable() { return active_chartTable; }
329 
330  bool IsValid() const { return bValid; }
331  int DisableChart(wxString &PathToDisable);
332  bool GetCentroidOfLargestScaleChart(double *clat, double *clon,
333  ChartFamilyEnum family);
334  int GetDBChartType(int dbIndex);
335  int GetDBChartFamily(int dbIndex);
336  float GetDBChartSkew(int dbIndex);
337  int GetDBChartProj(int dbIndex);
338  int GetDBChartScale(int dbIndex);
339 
340  bool GetDBBoundingBox(int dbindex, LLBBox &box);
341  const LLBBox &GetDBBoundingBox(int dbIndex);
342 
343  int GetnAuxPlyEntries(int dbIndex);
344  int GetDBPlyPoint(int dbIndex, int plyindex, float *lat, float *lon);
345  int GetDBAuxPlyPoint(int dbIndex, int plyindex, int iAuxPly, float *lat,
346  float *lon);
347  int GetVersion() { return m_dbversion; }
348  wxString GetFullChartInfo(ChartBase *pc, int dbIndex, int *char_width,
349  int *line_count);
350  int FinddbIndex(wxString PathToFind);
351  wxString GetDBChartFileName(int dbIndex);
352  void ApplyGroupArray(ChartGroupArray *pGroupArray);
353  bool IsChartAvailable(int dbIndex);
354  ChartTable active_chartTable;
355  std::map<wxString, int> active_chartTable_pathindex;
356 
357  std::vector<float> GetReducedPlyPoints(int dbIndex);
358  std::vector<float> GetReducedAuxPlyPoints(int dbIndex, int iTable);
359 
360  bool IsBusy() { return m_b_busy; }
361 
362 protected:
363  virtual ChartBase *GetChart(const wxChar *theFilePath,
364  ChartClassDescriptor &chart_desc) const;
365  int AddChartDirectory(const wxString &theDir, bool bshow_prog);
366  void SetValid(bool valid) { bValid = valid; }
367  ChartTableEntry *CreateChartTableEntry(const wxString &filePath,
368  wxString &utf8Path,
369  ChartClassDescriptor &chart_desc);
370 
371  std::vector<ChartClassDescriptor> m_ChartClassDescriptorArray;
372  ArrayOfCDI m_dir_array;
373  bool m_b_busy;
374 
375 private:
376  bool IsChartDirUsed(const wxString &theDir);
377 
378  int SearchDirAndAddCharts(wxString &dir_name_base,
379  ChartClassDescriptor &chart_desc,
380  wxGenericProgressDialog *pprog);
381 
382  int TraverseDirAndAddCharts(ChartDirInfo &dir_info,
383  wxGenericProgressDialog *pprog,
384  wxString &dir_magic, bool bForce);
385  bool DetectDirChange(const wxString &dir_path, const wxString &prog_label,
386  const wxString &magic, wxString &new_magic,
387  wxGenericProgressDialog *pprog);
388 
389  bool AddChart(wxString &chartfilename, ChartClassDescriptor &chart_desc,
390  wxGenericProgressDialog *pprog, int isearch,
391  bool bthis_dir_in_dB);
392 
393  bool Check_CM93_Structure(wxString dir_name);
394 
395  bool bValid;
396  wxArrayString m_chartDirs;
397  int m_dbversion;
398 
400  m_ChartTableEntryDummy; // used for return value if database is not valid
401  wxString m_DBFileName;
402 
403  int m_pdifile;
404  int m_pdnFile;
405 
406  int m_nentries;
407 
408  LLBBox m_dummy_bbox;
409 };
410 
411 //-------------------------------------------------------------------------------------------
412 // Chart Group Structure Definitions
413 //-------------------------------------------------------------------------------------------
414 class ChartGroupElement;
415 class ChartGroup;
416 
417 WX_DEFINE_ARRAY_PTR(ChartGroup *, ChartGroupArray);
418 
420  // ChartGroupElements need nothing special to delete since
421  // m_missing_name_array is a wxArrayString which manages
422  // memory for the strings cleanly without need for a .Clear.
423 public:
424  wxString m_element_name;
425  wxArrayString m_missing_name_array;
426 };
427 
428 class ChartGroup {
429 public:
430  wxString m_group_name;
431  std::vector<ChartGroupElement> m_element_array;
432 };
433 
434 #endif
Definition: Quilt.cpp:867