1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
/******************************************************************************
*
* Project: OpenCPN
* Purpose: Chart Database Object
* Author: David Register
*
***************************************************************************
* Copyright (C) 2010 by David S. Register *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************
*
*
*
*/
#ifndef __CHARTDB_H__
#define __CHARTDB_H__
#include <wx/xml/xml.h>
#include "chartbase.h"
#include "chartdbs.h"
#define MAXSTACK 100
// ----------------------------------------------------------------------------
// Constants, etc.
// ----------------------------------------------------------------------------
typedef struct {
float y;
float x;
} MyFlPoint;
// ----------------------------------------------------------------------------
// Fwd Declarations
// ----------------------------------------------------------------------------
class ChartBase;
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
class ChartStack
{
public:
ChartStack() { nEntry = 0; CurrentStackEntry = 0; b_valid = false;}
bool b_valid;
int nEntry;
int CurrentStackEntry;
int GetCurrentEntrydbIndex(void);
void SetCurrentEntryFromdbIndex(int current_db_index);
int GetDBIndex(int stack_index);
void SetDBIndex(int stack_index, int db_index);
bool DoesStackContaindbIndex(int db_index);
void AddChart( int db_add );
private:
int DBIndex[MAXSTACK];
};
class CacheEntry
{
public:
wxString FullPath;
void *pChart;
int RecentTime;
int dbIndex;
bool b_in_use;
int n_lock;
};
// ----------------------------------------------------------------------------
// Chart Database
// ----------------------------------------------------------------------------
class ChartDB: public ChartDatabase
{
public:
ChartDB();
virtual ~ChartDB();
bool LoadBinary(const wxString & filename, ArrayOfCDI& dir_array_check);
bool SaveBinary(const wxString & filename) { return ChartDatabase::Write(filename); }
int BuildChartStack(ChartStack * cstk, float lat, float lon, int groupIndex);
int BuildChartStack(ChartStack * cstk, float lat, float lon, int db_add, int groupIndex );
bool EqualStacks(ChartStack *, ChartStack *);
bool CopyStack(ChartStack *pa, ChartStack *pb);
wxString GetFullPath(ChartStack *ps, int stackindex);
int GetStackChartScale(ChartStack *ps, int stackindex, char *buf, int nbuf);
int GetCSPlyPoint(ChartStack *ps, int stackindex, int plyindex, float *lat, float *lon);
ChartTypeEnum GetCSChartType(ChartStack *ps, int stackindex);
ChartFamilyEnum GetCSChartFamily(ChartStack *ps, int stackindex);
bool SearchForChartDir(const wxString &dir);
ChartBase *OpenStackChartConditional(ChartStack *ps, int start_index, bool bLargest, ChartTypeEnum New_Type, ChartFamilyEnum New_Family_Fallback);
wxArrayPtrVoid *GetChartCache(void) { return pChartCache; }
std::vector<int> GetCSArray(ChartStack *ps);
int GetStackEntry(ChartStack *ps, wxString fp);
bool IsChartInCache(int dbindex);
bool IsChartInCache(wxString path);
bool IsChartInGroup(const int db_index, const int group);
bool IsENCInGroup(const int group);
bool IsNonMBTileInGroup(const int group);
ChartBase *OpenChartFromStack(ChartStack *pStack, int StackEntry, ChartInitFlag iflag = FULL_INIT);
ChartBase *OpenChartFromDB(int index, ChartInitFlag init_flag);
ChartBase *OpenChartFromDBAndLock(int index, ChartInitFlag init_flag , bool lock = true);
ChartBase *OpenChartFromDBAndLock(wxString chart_path, ChartInitFlag init_flag);
ChartBase *OpenChartFromDB(wxString chart_path, ChartInitFlag init_flag);
void ApplyColorSchemeToCachedCharts(ColorScheme cs);
void PurgeCache();
void PurgeCachePlugins();
bool DeleteCacheChart(ChartBase *pChart);
void LockCache(bool bl){m_b_locked = bl;}
void LockCache(){m_b_locked = true;}
void UnLockCache(){m_b_locked = false;}
bool IsCacheLocked(){ return m_b_locked; }
wxXmlDocument GetXMLDescription(int dbIndex, bool b_getGeom);
bool LockCacheChart( int index );
bool IsChartLocked( int index );
void UnLockCacheChart( int index );
void UnLockAllCacheCharts();
void ClearCacheInUseFlags(void);
void PurgeCacheUnusedCharts( double factor );
bool IsBusy(){ return m_b_busy; }
bool CheckExclusiveTileGroup( int canvasIndex );
bool CheckAnyCanvasExclusiveTileGroup( );
protected:
virtual ChartBase *GetChart(const wxChar *theFilePath, ChartClassDescriptor &chart_desc) const;
private:
InitReturn CreateChartTableEntry(wxString full_name, ChartTableEntry *pEntry);
int SearchDirAndAddSENC(wxString& dir, bool bshow_prog, bool bupdate);
bool CreateS57SENCChartTableEntry(wxString full_name, ChartTableEntry *pEntry, Extent *pext);
bool CheckPositionWithinChart(int index, float lat, float lon);
ChartBase *OpenChartUsingCache(int dbindex, ChartInitFlag init_flag);
CacheEntry *FindOldestDeleteCandidate( bool blog );
void DeleteCacheEntry(int i, bool bDelTexture = false, const wxString &msg = wxEmptyString);
void DeleteCacheEntry(CacheEntry *pce, bool bDelTexture = false, const wxString &msg = wxEmptyString);
wxArrayPtrVoid *pChartCache;
int m_ticks;
bool m_b_locked;
bool m_b_busy;
wxCriticalSection m_critSect;
wxMutex m_cache_mutex;
int m_checkGroupIndex[2];
bool m_checkedTileOnly[2];
};
#endif
|