diff --git a/ground/src/experimental/OPMapWidget/core/accessmode.h b/ground/src/experimental/OPMapWidget/core/accessmode.h index cf309afe4..835401d91 100644 --- a/ground/src/experimental/OPMapWidget/core/accessmode.h +++ b/ground/src/experimental/OPMapWidget/core/accessmode.h @@ -28,7 +28,8 @@ #ifndef ACCESSMODE_H #define ACCESSMODE_H - +#include "debugheader.h" + namespace core { struct AccessMode { diff --git a/ground/src/experimental/OPMapWidget/core/cache.h b/ground/src/experimental/OPMapWidget/core/cache.h index 6b724a8b3..592a247cb 100644 --- a/ground/src/experimental/OPMapWidget/core/cache.h +++ b/ground/src/experimental/OPMapWidget/core/cache.h @@ -29,7 +29,7 @@ #define CACHE_H #include "pureimagecache.h" - +#include "debugheader.h" namespace core { class Cache diff --git a/ground/src/experimental/OPMapWidget/core/core.pro b/ground/src/experimental/OPMapWidget/core/core.pro index dbeacebfc..e1ff2d254 100644 --- a/ground/src/experimental/OPMapWidget/core/core.pro +++ b/ground/src/experimental/OPMapWidget/core/core.pro @@ -33,4 +33,5 @@ HEADERS += opmaps.h \ geodecoderstatus.h \ placemark.h \ point.h \ - kibertilecache.h + kibertilecache.h \ + debugheader.h diff --git a/ground/src/experimental/OPMapWidget/core/debugheader.h b/ground/src/experimental/OPMapWidget/core/debugheader.h new file mode 100644 index 000000000..0e1f73195 --- /dev/null +++ b/ground/src/experimental/OPMapWidget/core/debugheader.h @@ -0,0 +1,13 @@ +#ifndef DEBUGHEADER_H +#define DEBUGHEADER_H + +//#define DEBUG_MEMORY_CACHE +//#define DEBUG_CACHE +//#define DEBUG_GMAPS +//#define DEBUG_PUREIMAGECACHE +//#define DEBUG_TILECACHEQUEUE +//#define DEBUG_URLFACTORY +//#define DEBUG_MEMORY_CACHE +//#define DEBUG_GetGeocoderFromCache + +#endif // DEBUGHEADER_H diff --git a/ground/src/experimental/OPMapWidget/core/kibertilecache.cpp b/ground/src/experimental/OPMapWidget/core/kibertilecache.cpp index e9667ec3f..ec3e76e06 100644 --- a/ground/src/experimental/OPMapWidget/core/kibertilecache.cpp +++ b/ground/src/experimental/OPMapWidget/core/kibertilecache.cpp @@ -51,14 +51,20 @@ int KiberTileCache::MemoryCacheCapacity() void KiberTileCache::RemoveMemoryOverload() { - while(memoryCacheSize>MemoryCacheCapacity()) + while(MemoryCacheSize()>MemoryCacheCapacity()) { if(cachequeue.count()>0 && list.count()>0) { +#ifdef DEBUG_MEMORY_CACHE + qDebug()<<"Cleaning Memory cache="<<" started with "< #include "rawtile.h" #include #include #include - - +#include +#include "debugheader.h" namespace core { class KiberTileCache { @@ -52,9 +51,6 @@ public: private: int _MemoryCacheCapacity; - // QPixmapCache TilesInMemory; - - }; diff --git a/ground/src/experimental/OPMapWidget/core/memorycache.cpp b/ground/src/experimental/OPMapWidget/core/memorycache.cpp index d231a791f..21318cf6e 100644 --- a/ground/src/experimental/OPMapWidget/core/memorycache.cpp +++ b/ground/src/experimental/OPMapWidget/core/memorycache.cpp @@ -48,7 +48,10 @@ void MemoryCache::AddTileToMemoryCache(const RawTile &tile, const QByteArray &pi { kiberCacheLock.lockForWrite(); // QPixmapCache::Key key=TilesInMemory.insert(pic); - TilesInMemory.memoryCacheSize +=pic.count(); + TilesInMemory.memoryCacheSize +=pic.size(); +#ifdef DEBUG_MEMORY_CACHE + qDebug()<<"Current memory="< #include "rawtile.h" #include #include #include #include "kibertilecache.h" - +#include +#include "debugheader.h" namespace core { class MemoryCache { @@ -45,7 +45,6 @@ public: QByteArray GetTileFromMemoryCache(const RawTile &tile); void AddTileToMemoryCache(const RawTile &tile, const QByteArray &pic); QReadWriteLock kiberCacheLock; - }; diff --git a/ground/src/experimental/OPMapWidget/core/opmaps.cpp b/ground/src/experimental/OPMapWidget/core/opmaps.cpp index e2c1a3d26..1c9758857 100644 --- a/ground/src/experimental/OPMapWidget/core/opmaps.cpp +++ b/ground/src/experimental/OPMapWidget/core/opmaps.cpp @@ -27,220 +27,233 @@ */ #include "opmaps.h" - + namespace core { -OPMaps* OPMaps::m_pInstance=0; + OPMaps* OPMaps::m_pInstance=0; -OPMaps* OPMaps::Instance() -{ - if(!m_pInstance) - m_pInstance=new OPMaps; - return m_pInstance; -} -OPMaps::OPMaps():useMemoryCache(true),MaxZoom(19),RetryLoadTile(2) -{ - accessmode=AccessMode::ServerAndCache; - Language=LanguageType::PortuguesePortugal; - LanguageStr=LanguageType().toString(Language); - // Cache::Instance()->ImageCache=PureImageCache(); - -} - - -OPMaps::~OPMaps() -{ - //delete Proxy; -} - - - -QByteArray OPMaps::GetImageFrom(const MapType::Types &type,const Point &pos,const int &zoom) -{ -#ifdef DEBUG_GMAPS - qDebug()<<"Entered GetImageFrom"; -#endif //DEBUG_GMAPS - QByteArray ret; - - if(useMemoryCache) + OPMaps* OPMaps::Instance() { -#ifdef DEBUG_GMAPS - qDebug()<<"Try Tile from memory:Size="<ImageCache=PureImageCache(); } - if(ret.isEmpty()) + + + OPMaps::~OPMaps() { + //delete Proxy; + } + + + + QByteArray OPMaps::GetImageFrom(const MapType::Types &type,const Point &pos,const int &zoom) + { +#ifdef DEBUG_TIMINGS + QTime time; + time.restart(); +#endif #ifdef DEBUG_GMAPS - qDebug()<<"Tile not in memory"; + qDebug()<<"Entered GetImageFrom"; #endif //DEBUG_GMAPS - if(accessmode != (AccessMode::ServerOnly)) + QByteArray ret; + + if(useMemoryCache) { #ifdef DEBUG_GMAPS - qDebug()<<"Try tile from DataBase"; + qDebug()<<"Try Tile from memory:Size="<ImageCache.GetImageFromCache(type,pos,zoom); - if(!ret.isEmpty()) + ret=GetTileFromMemoryCache(RawTile(type,pos,zoom)); + + } + if(ret.isEmpty()) + { +#ifdef DEBUG_GMAPS + qDebug()<<"Tile not in memory"; +#endif //DEBUG_GMAPS + if(accessmode != (AccessMode::ServerOnly)) { #ifdef DEBUG_GMAPS - qDebug()<<"Tile found in Database"; + qDebug()<<"Try tile from DataBase"; #endif //DEBUG_GMAPS - if(useMemoryCache) + ret=Cache::Instance()->ImageCache.GetImageFromCache(type,pos,zoom); + if(!ret.isEmpty()) { #ifdef DEBUG_GMAPS - qDebug()<<"Add Tile to memory"; + qDebug()<<"Tile found in Database"; +#endif //DEBUG_GMAPS + if(useMemoryCache) + { +#ifdef DEBUG_GMAPS + qDebug()<<"Add Tile to memory"; +#endif //DEBUG_GMAPS + AddTileToMemoryCache(RawTile(type,pos,zoom),ret); + } + return ret; + } + } + if(accessmode!=AccessMode::CacheOnly) + { + QNetworkReply *reply; + QNetworkRequest qheader; + QNetworkAccessManager network; + network.setProxy(Proxy); +#ifdef DEBUG_GMAPS + qDebug()<<"Try Tile from the Internet"; +#endif //DEBUG_GMAPS +#ifdef DEBUG_TIMINGS + qDebug()<<"opmaps before make image url"<isFinished() | time.elapsed()>(6*Timeout)) ){QCoreApplication::processEvents(QEventLoop::AllEvents);} +#ifdef DEBUG_TIMINGS + qDebug()<<"Network time:"<error()<<" abort?"<<(time.elapsed()>Timeout*6); +#endif //DEBUG_GMAPS + if( (reply->error()!=QNetworkReply::NoError) | (time.elapsed()>Timeout*6)) + { +#ifdef DEBUG_GMAPS + qDebug()<<"Request timed out ";//<readAll(); + reply->deleteLater();//TODO can't this be global?? + if(ret.isEmpty()) + { +#ifdef DEBUG_GMAPS + qDebug()<<"Invalid Tile"; +#endif //DEBUG_GMAPS + return ret; + } +#ifdef DEBUG_GMAPS + qDebug()<<"Received Tile from the Internet"; +#endif //DEBUG_GMAPS + if (useMemoryCache) + { +#ifdef DEBUG_GMAPS + qDebug()<<"Add Tile to memory cache"; #endif //DEBUG_GMAPS AddTileToMemoryCache(RawTile(type,pos,zoom),ret); } - return ret; + if(accessmode!=AccessMode::ServerOnly) + { +#ifdef DEBUG_GMAPS + qDebug()<<"Add tile to DataBase"; +#endif //DEBUG_GMAPS + CacheItemQueue item(type,pos,ret,zoom); + TileDBcacheQueue.EnqueueCacheTask(item); + } + + } } - if(accessmode!=AccessMode::CacheOnly) - { - QNetworkReply *reply; - QNetworkRequest qheader; - QNetworkAccessManager network; - network.setProxy(Proxy); #ifdef DEBUG_GMAPS - qDebug()<<"Try Tile from the Internet"; + qDebug()<<"Entered GetImageFrom"; #endif //DEBUG_GMAPS - QString url=MakeImageUrl(type,pos,zoom,LanguageStr); - qheader.setUrl(QUrl(url)); - qheader.setRawHeader("User-Agent",UserAgent); - qheader.setRawHeader("Accept","*/*"); - switch(type) - { - case MapType::GoogleMap: - case MapType::GoogleSatellite: - case MapType::GoogleLabels: - case MapType::GoogleTerrain: - case MapType::GoogleHybrid: - { - qheader.setRawHeader("Referrer", "http://maps.google.com/"); - } - break; - - case MapType::GoogleMapChina: - case MapType::GoogleSatelliteChina: - case MapType::GoogleLabelsChina: - case MapType::GoogleTerrainChina: - case MapType::GoogleHybridChina: - { - qheader.setRawHeader("Referrer", "http://ditu.google.cn/"); - } - break; - - case MapType::BingHybrid: - case MapType::BingMap: - case MapType::BingSatellite: - { - qheader.setRawHeader("Referrer", "http://www.bing.com/maps/"); - } - break; - - case MapType::YahooHybrid: - case MapType::YahooLabels: - case MapType::YahooMap: - case MapType::YahooSatellite: - { - qheader.setRawHeader("Referrer", "http://maps.yahoo.com/"); - } - break; - - case MapType::ArcGIS_MapsLT_Map_Labels: - case MapType::ArcGIS_MapsLT_Map: - case MapType::ArcGIS_MapsLT_OrtoFoto: - case MapType::ArcGIS_MapsLT_Map_Hybrid: - { - qheader.setRawHeader("Referrer", "http://www.maps.lt/map_beta/"); - } - break; - - case MapType::OpenStreetMapSurfer: - case MapType::OpenStreetMapSurferTerrain: - { - qheader.setRawHeader("Referrer", "http://www.mapsurfer.net/"); - } - break; - - case MapType::OpenStreetMap: - case MapType::OpenStreetOsm: - { - qheader.setRawHeader("Referrer", "http://www.openstreetmap.org/"); - } - break; - - case MapType::YandexMapRu: - { - qheader.setRawHeader("Referrer", "http://maps.yandex.ru/"); - } - break; - default: - break; - } - reply=network.get(qheader); -#ifdef DEBUG_GMAPS - qDebug()<<"Starting get response ";//<isFinished() | time.elapsed()>(6*Timeout)) ){QCoreApplication::processEvents(QEventLoop::AllEvents);} -#ifdef DEBUG_GMAPS - qDebug()<<"Finished?"<error()<<" abort?"<<(time.elapsed()>Timeout*6); -#endif //DEBUG_GMAPS - if( (reply->error()!=QNetworkReply::NoError) | (time.elapsed()>Timeout*6)) - { -#ifdef DEBUG_GMAPS - qDebug()<<"Request timed out ";//<readAll(); - reply->deleteLater();//TODO can't this be global?? - if(ret.isEmpty()) - { -#ifdef DEBUG_GMAPS - qDebug()<<"Invalid Tile"; -#endif //DEBUG_GMAPS - return ret; - } -#ifdef DEBUG_GMAPS - qDebug()<<"Received Tile from the Internet"; -#endif //DEBUG_GMAPS - if (useMemoryCache) - { -#ifdef DEBUG_GMAPS - qDebug()<<"Add Tile to memory cache"; -#endif //DEBUG_GMAPS - AddTileToMemoryCache(RawTile(type,pos,zoom),ret); - } - if(accessmode!=AccessMode::ServerOnly) - { -#ifdef DEBUG_GMAPS - qDebug()<<"Add tile to DataBase"; -#endif //DEBUG_GMAPS - CacheItemQueue item(type,pos,ret,zoom); - TileDBcacheQueue.EnqueueCacheTask(item); - } - - - } + return ret; } -#ifdef DEBUG_GMAPS - qDebug()<<"Entered GetImageFrom"; -#endif //DEBUG_GMAPS - return ret; -} -bool OPMaps::ExportToGMDB(const QString &file) -{ - return Cache::Instance()->ImageCache.ExportMapDataToDB(Cache::Instance()->ImageCache.GtileCache()+QDir::separator()+"Data.qmdb",file); -} -bool OPMaps::ImportFromGMDB(const QString &file) -{ - return Cache::Instance()->ImageCache.ExportMapDataToDB(file,Cache::Instance()->ImageCache.GtileCache()+QDir::separator()+"Data.qmdb"); -} + bool OPMaps::ExportToGMDB(const QString &file) + { + return Cache::Instance()->ImageCache.ExportMapDataToDB(Cache::Instance()->ImageCache.GtileCache()+QDir::separator()+"Data.qmdb",file); + } + bool OPMaps::ImportFromGMDB(const QString &file) + { + return Cache::Instance()->ImageCache.ExportMapDataToDB(file,Cache::Instance()->ImageCache.GtileCache()+QDir::separator()+"Data.qmdb"); + } } diff --git a/ground/src/experimental/OPMapWidget/core/opmaps.h b/ground/src/experimental/OPMapWidget/core/opmaps.h index 19648f83a..46a6d4136 100644 --- a/ground/src/experimental/OPMapWidget/core/opmaps.h +++ b/ground/src/experimental/OPMapWidget/core/opmaps.h @@ -28,12 +28,8 @@ #ifndef OPMaps_H #define OPMaps_H -//#define DEBUG_CACHE -//#define DEBUG_GMAPS -//#define DEBUG_PUREIMAGECACHE -//#define DEBUG_TILECACHEQUEUE -//#define DEBUG_URLFACTORY +#include "debugheader.h" #include "memorycache.h" #include "rawtile.h" #include "cache.h" @@ -66,22 +62,17 @@ public: QByteArray GetImageFrom(const MapType::Types &type,const Point &pos,const int &zoom); bool UseMemoryCache();//TODO - void setUseMemoryCache(const bool& value);//TODO + void setUseMemoryCache(const bool& value){useMemoryCache=value;} void setLanguage(const LanguageType::Types& language);//TODO LanguageType::Types GetLanguage();//TODO - AccessMode GetAccessMode(); - void setAccessMode(const AccessMode& mode); + AccessMode::Types GetAccessMode()const{return accessmode;}; + void setAccessMode(const AccessMode::Types& mode){accessmode=mode;}; int MaxZoom; int RetryLoadTile; private: - - - - bool useMemoryCache; LanguageType::Types Language; AccessMode::Types accessmode; - // PureImageCache ImageCacheLocal;//TODO Criar acesso Get Set TileCacheQueue TileDBcacheQueue; OPMaps(); diff --git a/ground/src/experimental/OPMapWidget/core/point.h b/ground/src/experimental/OPMapWidget/core/point.h index 74d461565..3600d71f0 100644 --- a/ground/src/experimental/OPMapWidget/core/point.h +++ b/ground/src/experimental/OPMapWidget/core/point.h @@ -30,7 +30,6 @@ #include -//#include "size.h" namespace core { struct Size;