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