OpenCPN Partial API docs
Loading...
Searching...
No Matches
chartdb.h
1/******************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: Chart Database Object
5 * Author: David Register
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 *
27 *
28 */
29
30#ifndef __CHARTDB_H__
31#define __CHARTDB_H__
32
33#include <wx/xml/xml.h>
34
35#include "chartbase.h"
36#include "chartdbs.h"
37
38#define MAXSTACK 100
39
40// ----------------------------------------------------------------------------
41// Constants, etc.
42// ----------------------------------------------------------------------------
43
44typedef struct {
45 float y;
46 float x;
47} MyFlPoint;
48
49// ----------------------------------------------------------------------------
50// Fwd Declarations
51// ----------------------------------------------------------------------------
52class ChartBase;
53
54// ----------------------------------------------------------------------------
55// ----------------------------------------------------------------------------
56
58public:
59 ChartStack() {
60 nEntry = 0;
61 CurrentStackEntry = 0;
62 b_valid = false;
63 }
64
65 bool b_valid;
66 int nEntry;
67 int CurrentStackEntry;
68 int GetCurrentEntrydbIndex(void);
69 void SetCurrentEntryFromdbIndex(int current_db_index);
70 int GetDBIndex(int stack_index);
71 void SetDBIndex(int stack_index, int db_index);
72 bool DoesStackContaindbIndex(int db_index);
73 void AddChart(int db_add);
74
75private:
76 int DBIndex[MAXSTACK];
77};
78
80public:
81 wxString FullPath;
82 void *pChart;
83 int RecentTime;
84 int dbIndex;
85 bool b_in_use;
86 int n_lock;
87};
88
89// ----------------------------------------------------------------------------
90// Chart Database
91// ----------------------------------------------------------------------------
92
93class ChartDB : public ChartDatabase {
94public:
95 ChartDB();
96 virtual ~ChartDB();
97
98 bool LoadBinary(const wxString &filename, ArrayOfCDI &dir_array_check);
99 bool SaveBinary(const wxString &filename) {
100 return ChartDatabase::Write(filename);
101 }
102
103 int BuildChartStack(ChartStack *cstk, float lat, float lon, int groupIndex);
104 int BuildChartStack(ChartStack *cstk, float lat, float lon, int db_add,
105 int groupIndex);
106 bool EqualStacks(ChartStack *, ChartStack *);
107 bool CopyStack(ChartStack *pa, ChartStack *pb);
108 wxString GetFullPath(ChartStack *ps, int stackindex);
109 int GetStackChartScale(ChartStack *ps, int stackindex, char *buf, int nbuf);
110 int GetCSPlyPoint(ChartStack *ps, int stackindex, int plyindex, float *lat,
111 float *lon);
112 ChartTypeEnum GetCSChartType(ChartStack *ps, int stackindex);
113 ChartFamilyEnum GetCSChartFamily(ChartStack *ps, int stackindex);
114 bool SearchForChartDir(const wxString &dir);
115 ChartBase *OpenStackChartConditional(ChartStack *ps, int start_index,
116 bool bLargest, ChartTypeEnum New_Type,
117 ChartFamilyEnum New_Family_Fallback);
118
119 wxArrayPtrVoid *GetChartCache(void) { return pChartCache; }
120 std::vector<int> GetCSArray(ChartStack *ps);
121
122 int GetStackEntry(ChartStack *ps, wxString fp);
123 bool IsChartInCache(int dbindex);
124 bool IsChartInCache(wxString path);
125 bool IsChartInGroup(const int db_index, const int group);
126 bool IsENCInGroup(const int group);
127 bool IsNonMBTileInGroup(const int group);
128
129 ChartBase *OpenChartFromStack(ChartStack *pStack, int StackEntry,
130 ChartInitFlag iflag = FULL_INIT);
131 ChartBase *OpenChartFromDB(int index, ChartInitFlag init_flag);
132 ChartBase *OpenChartFromDBAndLock(int index, ChartInitFlag init_flag,
133 bool lock = true);
134 ChartBase *OpenChartFromDBAndLock(wxString chart_path,
135 ChartInitFlag init_flag);
136 ChartBase *OpenChartFromDB(wxString chart_path, ChartInitFlag init_flag);
137
138 void ApplyColorSchemeToCachedCharts(ColorScheme cs);
139 void PurgeCache();
140 void PurgeCachePlugins();
141 bool DeleteCacheChart(ChartBase *pChart);
142
143 void LockCache(bool bl) { m_b_locked = bl; }
144 void LockCache() { m_b_locked = true; }
145 void UnLockCache() { m_b_locked = false; }
146 bool IsCacheLocked() { return m_b_locked; }
147 wxXmlDocument GetXMLDescription(int dbIndex, bool b_getGeom);
148
149 bool LockCacheChart(int index);
150 bool IsChartLocked(int index);
151
152 void UnLockCacheChart(int index);
153 void UnLockAllCacheCharts();
154
155 void ClearCacheInUseFlags(void);
156 void PurgeCacheUnusedCharts(double factor);
157
158 bool IsBusy() { return m_b_busy; }
159 bool CheckExclusiveTileGroup(int canvasIndex);
160 bool CheckAnyCanvasExclusiveTileGroup();
161
162protected:
163 virtual ChartBase *GetChart(const wxChar *theFilePath,
164 ChartClassDescriptor &chart_desc) const;
165
166private:
167 InitReturn CreateChartTableEntry(wxString full_name, ChartTableEntry *pEntry);
168
169 int SearchDirAndAddSENC(wxString &dir, bool bshow_prog, bool bupdate);
170 bool CreateS57SENCChartTableEntry(wxString full_name, ChartTableEntry *pEntry,
171 Extent *pext);
172 bool CheckPositionWithinChart(int index, float lat, float lon);
173 ChartBase *OpenChartUsingCache(int dbindex, ChartInitFlag init_flag);
174 CacheEntry *FindOldestDeleteCandidate(bool blog);
175 void DeleteCacheEntry(int i, bool bDelTexture = false,
176 const wxString &msg = wxEmptyString);
177 void DeleteCacheEntry(CacheEntry *pce, bool bDelTexture = false,
178 const wxString &msg = wxEmptyString);
179
180 wxArrayPtrVoid *pChartCache;
181 int m_ticks;
182
183 bool m_b_locked;
184 bool m_b_busy;
185
186 wxCriticalSection m_critSect;
187 wxMutex m_cache_mutex;
188 int m_checkGroupIndex[2];
189 bool m_checkedTileOnly[2];
190};
191
192#endif