Commit 9396f137 authored by lm's avatar lm

Added opmapcontrol

parent 2021535f
#include "src/mapwidget/opmapwidget.h"
######################################################################
# Automatically generated by qmake (2.01a) Sa. Mrz 19 17:12:54 2011
######################################################################
DEPENDPATH += src/core src/internals src/mapwidget src/internals/projections
INCLUDEPATH += src/core src/internals src/internals/projections src/mapwidget
# Input
HEADERS += opmapcontrol.h \
src/core/accessmode.h \
src/core/alllayersoftype.h \
src/core/cache.h \
src/core/cacheitemqueue.h \
src/core/debugheader.h \
src/core/diagnostics.h \
src/core/geodecoderstatus.h \
src/core/kibertilecache.h \
src/core/languagetype.h \
src/core/maptype.h \
src/core/memorycache.h \
src/core/opmaps.h \
src/core/placemark.h \
src/core/point.h \
src/core/providerstrings.h \
src/core/pureimage.h \
src/core/pureimagecache.h \
src/core/rawtile.h \
src/core/size.h \
src/core/tilecachequeue.h \
src/core/urlfactory.h \
src/internals/copyrightstrings.h \
src/internals/core.h \
src/internals/debugheader.h \
src/internals/loadtask.h \
src/internals/mousewheelzoomtype.h \
src/internals/pointlatlng.h \
src/internals/pureprojection.h \
src/internals/rectangle.h \
src/internals/rectlatlng.h \
src/internals/sizelatlng.h \
src/internals/tile.h \
src/internals/tilematrix.h \
src/mapwidget/configuration.h \
src/mapwidget/gpsitem.h \
src/mapwidget/homeitem.h \
src/mapwidget/mapgraphicitem.h \
src/mapwidget/mapripform.h \
src/mapwidget/mapripper.h \
src/mapwidget/opmapwidget.h \
src/mapwidget/trailitem.h \
src/mapwidget/uavitem.h \
src/mapwidget/uavmapfollowtype.h \
src/mapwidget/uavtrailtype.h \
src/mapwidget/waypointitem.h \
src/internals/projections/lks94projection.h \
src/internals/projections/mercatorprojection.h \
src/internals/projections/mercatorprojectionyandex.h \
src/internals/projections/platecarreeprojection.h \
src/internals/projections/platecarreeprojectionpergo.h
FORMS += src/mapwidget/mapripform.ui
SOURCES += src/core/alllayersoftype.cpp \
src/core/cache.cpp \
src/core/cacheitemqueue.cpp \
src/core/diagnostics.cpp \
src/core/kibertilecache.cpp \
src/core/languagetype.cpp \
src/core/memorycache.cpp \
src/core/opmaps.cpp \
src/core/placemark.cpp \
src/core/point.cpp \
src/core/providerstrings.cpp \
src/core/pureimage.cpp \
src/core/pureimagecache.cpp \
src/core/rawtile.cpp \
src/core/size.cpp \
src/core/tilecachequeue.cpp \
src/core/urlfactory.cpp \
src/internals/core.cpp \
src/internals/loadtask.cpp \
src/internals/MouseWheelZoomType.cpp \
src/internals/pointlatlng.cpp \
src/internals/pureprojection.cpp \
src/internals/rectangle.cpp \
src/internals/rectlatlng.cpp \
src/internals/sizelatlng.cpp \
src/internals/tile.cpp \
src/internals/tilematrix.cpp \
src/mapwidget/configuration.cpp \
src/mapwidget/gpsitem.cpp \
src/mapwidget/homeitem.cpp \
src/mapwidget/mapgraphicitem.cpp \
src/mapwidget/mapripform.cpp \
src/mapwidget/mapripper.cpp \
src/mapwidget/opmapwidget.cpp \
src/mapwidget/trailitem.cpp \
src/mapwidget/uavitem.cpp \
src/mapwidget/waypointitem.cpp \
src/internals/projections/lks94projection.cpp \
src/internals/projections/mercatorprojection.cpp \
src/internals/projections/mercatorprojectionyandex.cpp \
src/internals/projections/platecarreeprojection.cpp \
src/internals/projections/platecarreeprojectionpergo.cpp
RESOURCES += src/mapwidget/mapresources.qrc
DESTDIR = ../build
QT += network
QT += sql
CONFIG += staticlib
TEMPLATE = lib
UI_DIR = uics
MOC_DIR = mocs
OBJECTS_DIR = objs
/**
******************************************************************************
*
* @file accessmode.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef ACCESSMODE_H
#define ACCESSMODE_H
#include "debugheader.h"
#include <QObject>
#include <QMetaObject>
#include <QMetaEnum>
#include <QStringList>
namespace core {
class AccessMode:public QObject
{
Q_OBJECT
Q_ENUMS(Types)
public:
enum Types
{
/// <summary>
/// access only server
/// </summary>
ServerOnly,
/// <summary>
/// access first server and caches localy
/// </summary>
ServerAndCache,
/// <summary>
/// access only cache
/// </summary>
CacheOnly
};
static QString StrByType(Types const& value)
{
QMetaObject metaObject = AccessMode().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
QString s=metaEnum.valueToKey(value);
return s;
}
static Types TypeByStr(QString const& value)
{
QMetaObject metaObject = AccessMode().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
Types s=(Types)metaEnum.keyToValue(value.toLatin1());
return s;
}
static QStringList TypesList()
{
QStringList ret;
QMetaObject metaObject = AccessMode().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
for(int x=0;x<metaEnum.keyCount();++x)
{
ret.append(metaEnum.key(x));
}
return ret;
}
};
}
#endif // ACCESSMODE_H
/**
******************************************************************************
*
* @file alllayersoftype.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "alllayersoftype.h"
namespace core {
AllLayersOfType::AllLayersOfType()
{
}
QVector<MapType::Types> AllLayersOfType::GetAllLayersOfType(const MapType::Types &type)
{
QVector<MapType::Types> types;
{
switch(type)
{
case MapType::GoogleHybrid:
{
types.append(MapType::GoogleSatellite);
types.append(MapType::GoogleLabels);
}
break;
case MapType::GoogleHybridChina:
{
types.append(MapType::GoogleSatelliteChina);
types.append(MapType::GoogleLabelsChina);
}
break;
case MapType::GoogleHybridKorea:
{
types.append(MapType::GoogleSatelliteKorea);
types.append(MapType::GoogleLabelsKorea);
}
break;
case MapType::YahooHybrid:
{
types.append(MapType::YahooSatellite);
types.append(MapType::YahooLabels);
}
break;
case MapType::ArcGIS_MapsLT_Map_Hybrid:
{
types.append(MapType::ArcGIS_MapsLT_OrtoFoto);
types.append(MapType::ArcGIS_MapsLT_Map_Labels);
}
break;
default:
{
types.append(type);
}
break;
}
}
return types;
}
}
/**
******************************************************************************
*
* @file alllayersoftype.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef ALLLAYERSOFTYPE_H
#define ALLLAYERSOFTYPE_H
#include "maptype.h"
#include <QList>
#include <QVector>
namespace core {
class AllLayersOfType
{
public:
AllLayersOfType();
QVector<MapType::Types> GetAllLayersOfType(const MapType::Types &type);
};
}
#endif // ALLLAYERSOFTYPE_H
/**
******************************************************************************
*
* @file cache.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "cache.h"
namespace core {
Cache* Cache::m_pInstance=0;
Cache* Cache::Instance()
{
if(!m_pInstance)
m_pInstance=new Cache;
return m_pInstance;
}
void Cache::setCacheLocation(const QString& value)
{
cache=value;
routeCache = cache + "RouteCache" + QDir::separator();
geoCache = cache + "GeocoderCache"+ QDir::separator();
placemarkCache = cache + "PlacemarkCache" + QDir::separator();
ImageCache.setGtileCache(value);
}
QString Cache::CacheLocation()
{
return cache;
}
Cache::Cache()
{
if(cache.isNull()|cache.isEmpty())
{
cache=QDir::currentPath()+QDir::separator()+"mapscache"+QDir::separator();
setCacheLocation(cache);
}
}
QString Cache::GetGeocoderFromCache(const QString &urlEnd)
{
#ifdef DEBUG_GetGeocoderFromCache
qDebug()<<"Entered GetGeocoderFromCache";
#endif
QString ret=QString::null;
QString filename=geoCache+QString(urlEnd)+".geo";
#ifdef DEBUG_GetGeocoderFromCache
qDebug()<<"GetGeocoderFromCache: Does file exist?:"<<filename;
#endif
QFileInfo File(filename);
if (File .exists())
{
#ifdef DEBUG_GetGeocoderFromCache
qDebug()<<"GetGeocoderFromCache:File exists!!";
#endif
QFile file(filename);
if (file.open(QIODevice::ReadOnly))
{
QTextStream stream(&file);
stream.setCodec("UTF-8");
stream>>ret;
}
}
#ifdef DEBUG_GetGeocoderFromCache
qDebug()<<"GetGeocoderFromCache:Returning:"<<ret;
#endif
return ret;
}
void Cache::CacheGeocoder(const QString &urlEnd, const QString &content)
{
QString ret=QString::null;
QString filename=geoCache+QString(urlEnd)+".geo";
#ifdef DEBUG_CACHE
qDebug()<<"CacheGeocoder: Filename:"<<filename;
#endif //DEBUG_CACHE
QFileInfo File(filename);;
QDir dir=File.absoluteDir();
QString path=dir.absolutePath();
#ifdef DEBUG_CACHE
qDebug()<<"CacheGeocoder: Path:"<<path;
#endif //DEBUG_CACHE
if(!dir.exists())
{
#ifdef DEBUG_CACHE
qDebug()<<"CacheGeocoder: Cache path doesn't exist, try to create";
#endif //DEBUG_CACHE
if(!dir.mkpath(path))
{
#ifdef DEBUG_CACHE
qDebug()<<"GetGeocoderFromCache: Could not create path";
#endif //DEBUG_CACHE
}
}
#ifdef DEBUG_CACHE
qDebug()<<"CacheGeocoder: OpenFile:"<<filename;
#endif //DEBUG_CACHE
QFile file(filename);
if (file.open(QIODevice::WriteOnly))
{
#ifdef DEBUG_CACHE
qDebug()<<"CacheGeocoder: File Opened!!!:"<<filename;
#endif //DEBUG_CACHE
QTextStream stream(&file);
stream.setCodec("UTF-8");
stream<<content;
}
}
QString Cache::GetPlacemarkFromCache(const QString &urlEnd)
{
#ifdef DEBUG_CACHE
qDebug()<<"Entered GetPlacemarkFromCache";
#endif //DEBUG_CACHE
QString ret=QString::null;
QString filename=placemarkCache+QString(urlEnd)+".plc";
#ifdef DEBUG_CACHE
qDebug()<<"GetPlacemarkFromCache: Does file exist?:"<<filename;
#endif //DEBUG_CACHE
QFileInfo File(filename);
if (File .exists())
{
#ifdef DEBUG_CACHE
qDebug()<<"GetPlacemarkFromCache:File exists!!";
#endif //DEBUG_CACHE
QFile file(filename);
if (file.open(QIODevice::ReadOnly))
{
QTextStream stream(&file);
stream.setCodec("UTF-8");
stream>>ret;
}
}
#ifdef DEBUG_CACHE
qDebug()<<"GetPlacemarkFromCache:Returning:"<<ret;
#endif //DEBUG_CACHE
return ret;
}
void Cache::CachePlacemark(const QString &urlEnd, const QString &content)
{
QString ret=QString::null;
QString filename=placemarkCache+QString(urlEnd)+".plc";
#ifdef DEBUG_CACHE
qDebug()<<"CachePlacemark: Filename:"<<filename;
#endif //DEBUG_CACHE
QFileInfo File(filename);;
QDir dir=File.absoluteDir();
QString path=dir.absolutePath();
#ifdef DEBUG_CACHE
qDebug()<<"CachePlacemark: Path:"<<path;
#endif //DEBUG_CACHE
if(!dir.exists())
{
#ifdef DEBUG_CACHE
qDebug()<<"CachePlacemark: Cache path doesn't exist, try to create";
#endif //DEBUG_CACHE
if(!dir.mkpath(path))
{
#ifdef DEBUG_CACHE
qDebug()<<"CachePlacemark: Could not create path";
#endif //DEBUG_CACHE
}
}
#ifdef DEBUG_CACHE
qDebug()<<"CachePlacemark: OpenFile:"<<filename;
#endif //DEBUG_CACHE
QFile file(filename);
if (file.open(QIODevice::WriteOnly))
{
#ifdef DEBUG_CACHE
qDebug()<<"CachePlacemark: File Opened!!!:"<<filename;
#endif //DEBUG_CACHE
QTextStream stream(&file);
stream.setCodec("UTF-8");
stream<<content;
}
}
}
/**
******************************************************************************
*
* @file cache.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CACHE_H
#define CACHE_H
#include "pureimagecache.h"
#include "debugheader.h"
namespace core {
class Cache
{
public:
static Cache* Instance();
PureImageCache ImageCache;
QString CacheLocation();
void setCacheLocation(const QString& value);
void CacheGeocoder(const QString &urlEnd,const QString &content);
QString GetGeocoderFromCache(const QString &urlEnd);
void CachePlacemark(const QString &urlEnd,const QString &content);
QString GetPlacemarkFromCache(const QString &urlEnd);
void CacheRoute(const QString &urlEnd,const QString &content);
QString GetRouteFromCache(const QString &urlEnd);
private:
Cache();
Cache(Cache const&){}
Cache& operator=(Cache const&){ return *this; }
static Cache* m_pInstance;
QString cache;
QString routeCache;
QString geoCache;
QString placemarkCache;
};
}
#endif // CACHE_H
/**
******************************************************************************
*
* @file cacheitemqueue.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "cacheitemqueue.h"
namespace core {
CacheItemQueue::CacheItemQueue(const MapType::Types &Type, const Point &Pos, const QByteArray &Img, const int &Zoom)
{
type=Type;
pos=Pos;
img=Img;
zoom=Zoom;
}
QByteArray CacheItemQueue::GetImg()
{
return img;
}
MapType::Types CacheItemQueue::GetMapType()
{
return type;
}
Point CacheItemQueue::GetPosition()
{
return pos;
}
void CacheItemQueue::SetImg(const QByteArray &value)
{
img=value;
}
void CacheItemQueue::SetMapType(const MapType::Types &value)
{
type=value;
}
void CacheItemQueue::SetPosition(const Point &value)
{
pos=value;
}
CacheItemQueue& CacheItemQueue::operator =(const CacheItemQueue &cSource)
{
img=cSource.img;
pos=cSource.pos;
type=cSource.type;
zoom=cSource.zoom;
return *this;
}
bool CacheItemQueue::operator ==(const CacheItemQueue &cSource)
{
bool b=(img==cSource.img)&& (pos==cSource.pos) && (type==cSource.type) && (zoom==cSource.zoom);
return b;
}
}
/**
******************************************************************************
*
* @file cacheitemqueue.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CACHEITEMQUEUE_H
#define CACHEITEMQUEUE_H
#include "maptype.h"
#include "point.h"
#include <QByteArray>
namespace core {
class CacheItemQueue
{
public:
CacheItemQueue(const MapType::Types &Type,const core::Point &Pos,const QByteArray &Img,const int &Zoom);
CacheItemQueue(){};
CacheItemQueue(const CacheItemQueue &cSource)
{
img=cSource.img;
pos=cSource.pos;
type=cSource.type;
zoom=cSource.zoom;
}
CacheItemQueue& operator= (const CacheItemQueue &cSource);
bool operator== (const CacheItemQueue &cSource);
void SetMapType(const MapType::Types &value);
void SetPosition(const core::Point &value);
void SetImg(const QByteArray &value);
MapType::Types GetMapType();
core::Point GetPosition();
QByteArray GetImg();
int GetZoom(){return zoom;};
void SetZoom(const int &value) {zoom=value;};
private:
MapType::Types type;
core::Point pos;
QByteArray img;
int zoom;
};
}
#endif // CACHEITEMQUEUE_H
include (../common.pri)
SOURCES += opmaps.cpp \
pureimagecache.cpp \
pureimage.cpp \
rawtile.cpp \
memorycache.cpp \
cache.cpp \
languagetype.cpp \
providerstrings.cpp \
cacheitemqueue.cpp \
tilecachequeue.cpp \
alllayersoftype.cpp \
urlfactory.cpp \
placemark.cpp \
point.cpp \
size.cpp \
kibertilecache.cpp \
diagnostics.cpp
HEADERS += opmaps.h \
size.h \
maptype.h \
pureimagecache.h \
pureimage.h \
rawtile.h \
memorycache.h \
cache.h \
accessmode.h \
languagetype.h \
providerstrings.h \
cacheitemqueue.h \
tilecachequeue.h \
alllayersoftype.h \
urlfactory.h \
geodecoderstatus.h \
placemark.h \
point.h \
kibertilecache.h \
debugheader.h \
diagnostics.h
#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
/**
******************************************************************************
*
* @file diagnostics.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "diagnostics.h"
diagnostics::diagnostics():networkerrors(0),emptytiles(0),timeouts(0),runningThreads(0),tilesFromMem(0),tilesFromNet(0),tilesFromDB(0)
{
}
/**
******************************************************************************
*
* @file diagnostics.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef DIAGNOSTICS_H
#define DIAGNOSTICS_H
#include <QString>
struct diagnostics
{
diagnostics();
int networkerrors;
int emptytiles;
int timeouts;
int runningThreads;
int tilesFromMem;
int tilesFromNet;
int tilesFromDB;
QString toString()
{
return QString("Network errors:%1\nEmpty Tiles:%2\nTimeOuts:%3\nRunningThreads:%4\nTilesFromMem:%5\nTilesFromNet:%6\nTilesFromDB:%7").arg(networkerrors).arg(emptytiles).arg(timeouts).arg(runningThreads).arg(tilesFromMem).arg(tilesFromNet).arg(tilesFromDB);
;
}
};
#endif // DIAGNOSTICS_H
/**
******************************************************************************
*
* @file geodecoderstatus.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef GEODECODERSTATUS_H
#define GEODECODERSTATUS_H
#include <QObject>
#include <QMetaObject>
#include <QMetaEnum>
#include <QStringList>
namespace core {
class GeoCoderStatusCode:public QObject
{
Q_OBJECT
Q_ENUMS(Types)
public:
enum Types
{
/// <summary>
/// unknow response
/// </summary>
Unknow = -1,
/// <summary>
/// No errors occurred; the address was successfully parsed and its geocode has been returned.
/// </summary>
G_GEO_SUCCESS=200,
/// <summary>
/// A directions request could not be successfully parsed.
/// For example, the request may have been rejected if it contained more than the maximum number of waypoints allowed.
/// </summary>
G_GEO_BAD_REQUEST=400,
/// <summary>
/// A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.
/// </summary>
G_GEO_SERVER_ERROR=500,
/// <summary>
/// The HTTP q parameter was either missing or had no value.
/// For geocoding requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.
/// </summary>
G_GEO_MISSING_QUERY=601,
/// <summary>
/// Synonym for G_GEO_MISSING_QUERY.
/// </summary>
G_GEO_MISSING_ADDRESS=601,
/// <summary>
/// No corresponding geographic location could be found for the specified address.
/// This may be due to the fact that the address is relatively new, or it may be incorrect.
/// </summary>
G_GEO_UNKNOWN_ADDRESS=602,
/// <summary>
/// The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.
/// </summary>
G_GEO_UNAVAILABLE_ADDRESS=603,
/// <summary>
/// The GDirections object could not compute directions between the points mentioned in the query.
/// This is usually because there is no route available between the two points, or because we do not have data for routing in that region.
/// </summary>
G_GEO_UNKNOWN_DIRECTIONS=604,
/// <summary>
/// The given key is either invalid or does not match the domain for which it was given.
/// </summary>
G_GEO_BAD_KEY=610,
/// <summary>
/// The given key has gone over the requests limit in the 24 hour period or has submitted too many requests in too short a period of time.
/// If you're sending multiple requests in parallel or in a tight loop, use a timer or pause in your code to make sure you don't send the requests too quickly.
/// </summary>
G_GEO_TOO_MANY_QUERIES=620
};
static QString StrByType(Types const& value)
{
QMetaObject metaObject = GeoCoderStatusCode().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
QString s=metaEnum.valueToKey(value);
return s;
}
static Types TypeByStr(QString const& value)
{
QMetaObject metaObject = GeoCoderStatusCode().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
Types s=(Types)metaEnum.keyToValue(value.toLatin1());
return s;
}
static QStringList TypesList()
{
QStringList ret;
QMetaObject metaObject = GeoCoderStatusCode().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
for(int x=0;x<metaEnum.keyCount();++x)
{
ret.append(metaEnum.key(x));
}
return ret;
}
};
}
#endif // GEODECODERSTATUS_H
/**
******************************************************************************
*
* @file kibertilecache.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "kibertilecache.h"
//TODO add readwrite lock
namespace core {
KiberTileCache::KiberTileCache()
{
memoryCacheSize = 0;
_MemoryCacheCapacity = 22;
}
void KiberTileCache::setMemoryCacheCapacity(const int &value)
{
kiberCacheLock.lockForWrite();
_MemoryCacheCapacity=value;
kiberCacheLock.unlock();
}
int KiberTileCache::MemoryCacheCapacity()
{
kiberCacheLock.lockForRead();
return _MemoryCacheCapacity;
kiberCacheLock.unlock();
}
void KiberTileCache::RemoveMemoryOverload()
{
while(MemoryCacheSize()>MemoryCacheCapacity())
{
if(cachequeue.count()>0 && list.count()>0)
{
#ifdef DEBUG_MEMORY_CACHE
qDebug()<<"Cleaning Memory cache="<<" started with "<<cachequeue.count()<<" tile "<<"ocupying "<<memoryCacheSize<<" bytes";
#endif
RawTile first=list.dequeue();
memoryCacheSize-=cachequeue.value(first).size();
cachequeue.remove(first);
}
}
#ifdef DEBUG_MEMORY_CACHE
qDebug()<<"Cleaning Memory cache="<<" ended with "<<cachequeue.count()<<" tile "<<"ocupying "<<memoryCacheSize<<" bytes";
#endif
}
}
/**
******************************************************************************
*
* @file kibertilecache.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef KIBERTILECACHE_H
#define KIBERTILECACHE_H
#include "rawtile.h"
#include <QMutex>
#include <QReadWriteLock>
#include <QQueue>
#include <QDebug>
#include "debugheader.h"
namespace core {
class KiberTileCache
{
public:
KiberTileCache();
void setMemoryCacheCapacity(const int &value);
int MemoryCacheCapacity();
double MemoryCacheSize(){return memoryCacheSize/1048576.0;}
void RemoveMemoryOverload();
QReadWriteLock kiberCacheLock;
QHash <RawTile,QByteArray> cachequeue;
QQueue <RawTile> list;
long memoryCacheSize;
private:
int _MemoryCacheCapacity;
};
}
#endif // KIBERTILECACHE_H
/**
******************************************************************************
*
* @file languagetype.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "languagetype.h"
namespace core {
LanguageType::LanguageType()
{
list
<<"ar"
<<"bg"
<<"bn"
<<"ca"
<<"cs"
<<"da"
<<"de"
<<"el"
<<"en"
<<"en-AU"
<<"en-GB"
<<"es"
<<"eu"
<<"fi"
<<"fil"
<<"fr"
<<"gl"
<<"gu"
<<"hi"
<<"hr"
<<"hu"
<<"id"
<<"it"
<<"iw"
<<"ja"
<<"kn"
<<"ko"
<<"lt"
<<"lv"
<<"ml"
<<"mr"
<<"nl"
<<"nn"
<<"no"
<<"or"
<<"pl"
<<"pt"
<<"pt-BR"
<<"pt-PT"
<<"rm"
<<"ro"
<<"ru"
<<"sk"
<<"sl"
<<"sr"
<<"sv"
<<"ta"
<<"te"
<<"th"
<<"tr"
<<"uk"
<<"vi"
<<"zh-CN"
<<"zh-TW";
}
QString LanguageType::toShortString(Types type)
{
return list[type];
}
LanguageType::~LanguageType()
{
list.clear();
}
}
/**
******************************************************************************
*
* @file languagetype.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef LANGUAGETYPE_H
#define LANGUAGETYPE_H
#include <QString>
#include <QMetaObject>
#include <QMetaEnum>
#include <QStringList>
namespace core {
class LanguageType:public QObject
{
Q_OBJECT
Q_ENUMS(Types)
public:
enum Types
{
Arabic,
Bulgarian,
Bengali,
Catalan,
Czech,
Danish,
German,
Greek,
English,
EnglishAustralian,
EnglishGreatBritain,
Spanish,
Basque,
Finnish,
Filipino,
French,
Galician,
Gujarati,
Hindi,
Croatian,
Hungarian,
Indonesian,
Italian,
Hebrew,
Japanese,
Kannada,
Korean,
Lithuanian,
Latvian,
Malayalam,
Marathi,
Dutch,
NorwegianNynorsk,
Norwegian,
Oriya,
Polish,
Portuguese,
PortugueseBrazil,
PortuguesePortugal,
Romansch,
Romanian,
Russian,
Slovak,
Slovenian,
Serbian,
Swedish,
Tamil,
Telugu,
Thai,
Turkish,
Ukrainian,
Vietnamese,
ChineseSimplified,
ChineseTraditional
};
static QString StrByType(Types const& value)
{
QMetaObject metaObject = LanguageType().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
QString s=metaEnum.valueToKey(value);
return s;
}
static Types TypeByStr(QString const& value)
{
QMetaObject metaObject = LanguageType().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
Types s=(Types)metaEnum.keyToValue(value.toLatin1());
return s;
}
static QStringList TypesList()
{
QStringList ret;
QMetaObject metaObject = LanguageType().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
for(int x=0;x<metaEnum.keyCount();++x)
{
ret.append(metaEnum.key(x));
}
return ret;
}
QString toShortString(Types type);
LanguageType();
~LanguageType();
private:
QStringList list;
};
}
#endif // LANGUAGETYPE_H
/**
******************************************************************************
*
* @file maptype.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MAPTYPE_H
#define MAPTYPE_H
#include <QMetaObject>
#include <QMetaEnum>
#include <QStringList>
namespace core {
class MapType:public QObject
{
Q_OBJECT
Q_ENUMS(Types)
public:
enum Types
{
GoogleMap=1,
GoogleSatellite=4,
GoogleLabels=8,
GoogleTerrain=16,
GoogleHybrid=20,
GoogleMapChina=22,
GoogleSatelliteChina=24,
GoogleLabelsChina=26,
GoogleTerrainChina=28,
GoogleHybridChina=29,
OpenStreetMap=32,
OpenStreetOsm=33,
OpenStreetMapSurfer=34,
OpenStreetMapSurferTerrain=35,
YahooMap=64,
YahooSatellite=128,
YahooLabels=256,
YahooHybrid=333,
BingMap=444,
BingSatellite=555,
BingHybrid=666,
ArcGIS_Map=777,
ArcGIS_Satellite=788,
ArcGIS_ShadedRelief=799,
ArcGIS_Terrain=811,
// use these numbers to clean up old stuff
//ArcGIS_MapsLT_Map_Old= 877,
//ArcGIS_MapsLT_OrtoFoto_Old = 888,
//ArcGIS_MapsLT_Map_Labels_Old = 890,
//ArcGIS_MapsLT_Map_Hybrid_Old = 899,
//ArcGIS_MapsLT_Map=977,
//ArcGIS_MapsLT_OrtoFoto=988,
//ArcGIS_MapsLT_Map_Labels=990,
//ArcGIS_MapsLT_Map_Hybrid=999,
//ArcGIS_MapsLT_Map=978,
//ArcGIS_MapsLT_OrtoFoto=989,
//ArcGIS_MapsLT_Map_Labels=991,
//ArcGIS_MapsLT_Map_Hybrid=998,
ArcGIS_MapsLT_Map=1000,
ArcGIS_MapsLT_OrtoFoto=1001,
ArcGIS_MapsLT_Map_Labels=1002,
ArcGIS_MapsLT_Map_Hybrid=1003,
PergoTurkeyMap = 2001,
SigPacSpainMap = 3001,
GoogleMapKorea=4001,
GoogleSatelliteKorea=4002,
GoogleLabelsKorea=4003,
GoogleHybridKorea=4005,
YandexMapRu = 5000
};
static QString StrByType(Types const& value)
{
QMetaObject metaObject = MapType().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
QString s=metaEnum.valueToKey(value);
return s;
}
static Types TypeByStr(QString const& value)
{
QMetaObject metaObject = MapType().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
Types s=(Types)metaEnum.keyToValue(value.toLatin1());
return s;
}
static QStringList TypesList()
{
QStringList ret;
QMetaObject metaObject = MapType().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
for(int x=0;x<metaEnum.keyCount();++x)
{
ret.append(metaEnum.key(x));
}
return ret;
}
};
}
#endif // MAPTYPE_H
/**
******************************************************************************
*
* @file memorycache.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "memorycache.h"
//TODO add readwrite lock
namespace core {
MemoryCache::MemoryCache()
{
}
QByteArray MemoryCache::GetTileFromMemoryCache(const RawTile &tile)
{
kiberCacheLock.lockForRead();
QByteArray pic;
pic=TilesInMemory.cachequeue.value(tile);
// TilesInMemory.find(key,&pic);
kiberCacheLock.unlock();
return pic;
}
void MemoryCache::AddTileToMemoryCache(const RawTile &tile, const QByteArray &pic)
{
kiberCacheLock.lockForWrite();
// QPixmapCache::Key key=TilesInMemory.insert(pic);
TilesInMemory.memoryCacheSize +=pic.size();
#ifdef DEBUG_MEMORY_CACHE
qDebug()<<"Current memory="<<TilesInMemory.memoryCacheSize<<" in "<<TilesInMemory.cachequeue.count()<<" tiles";
#endif
TilesInMemory.cachequeue.insert(tile,pic);
TilesInMemory.list.enqueue(tile);
kiberCacheLock.unlock();
}
}
/**
******************************************************************************
*
* @file memorycache.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MEMORYCACHE_H
#define MEMORYCACHE_H
#include "rawtile.h"
#include <QMutex>
#include <QReadWriteLock>
#include <QQueue>
#include "kibertilecache.h"
#include <QDebug>
#include "debugheader.h"
namespace core {
class MemoryCache
{
public:
MemoryCache();
KiberTileCache TilesInMemory;
QByteArray GetTileFromMemoryCache(const RawTile &tile);
void AddTileToMemoryCache(const RawTile &tile, const QByteArray &pic);
QReadWriteLock kiberCacheLock;
};
}
#endif // MEMORYCACHE_H
/**
******************************************************************************
*
* @file OPMaps.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "opmaps.h"
namespace core {
OPMaps* OPMaps::m_pInstance=0;
OPMaps* OPMaps::Instance()
{
if(!m_pInstance)
m_pInstance=new OPMaps;
return m_pInstance;
}
OPMaps::OPMaps():RetryLoadTile(2),useMemoryCache(true)
{
accessmode=AccessMode::ServerAndCache;
Language=LanguageType::PortuguesePortugal;
LanguageStr=LanguageType().toShortString(Language);
Cache::Instance();
}
OPMaps::~OPMaps()
{
TileDBcacheQueue.wait();
}
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()<<"Entered GetImageFrom";
#endif //DEBUG_GMAPS
QByteArray ret;
if(useMemoryCache)
{
#ifdef DEBUG_GMAPS
qDebug()<<"Try Tile from memory:Size="<<TilesInMemory.MemoryCacheSize();
#endif //DEBUG_GMAPS
ret=GetTileFromMemoryCache(RawTile(type,pos,zoom));
if(!ret.isEmpty())
{
errorvars.lock();
++diag.tilesFromMem;
errorvars.unlock();
}
}
if(ret.isEmpty())
{
#ifdef DEBUG_GMAPS
qDebug()<<"Tile not in memory";
#endif //DEBUG_GMAPS
if(accessmode != (AccessMode::ServerOnly))
{
#ifdef DEBUG_GMAPS
qDebug()<<"Try tile from DataBase";
#endif //DEBUG_GMAPS
ret=Cache::Instance()->ImageCache.GetImageFromCache(type,pos,zoom);
if(!ret.isEmpty())
{
errorvars.lock();
++diag.tilesFromDB;
errorvars.unlock();
#ifdef DEBUG_GMAPS
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)
{
QEventLoop q;
QNetworkReply *reply;
QNetworkRequest qheader;
QNetworkAccessManager network;
QTimer tT;
tT.setSingleShot(true);
connect(&network, SIGNAL(finished(QNetworkReply*)),
&q, SLOT(quit()));
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
network.setProxy(Proxy);
#ifdef DEBUG_GMAPS
qDebug()<<"Try Tile from the Internet";
#endif //DEBUG_GMAPS
#ifdef DEBUG_TIMINGS
qDebug()<<"opmaps before make image url"<<time.elapsed();
#endif
QString url=MakeImageUrl(type,pos,zoom,LanguageStr);
#ifdef DEBUG_TIMINGS
qDebug()<<"opmaps after make image url"<<time.elapsed();
#endif //url "http://vec02.maps.yandex.ru/tiles?l=map&v=2.10.2&x=7&y=5&z=3" string
//"http://map3.pergo.com.tr/tile/02/000/000/007/000/000/002.png"
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);
tT.start(Timeout);
q.exec();
if(!tT.isActive()){
errorvars.lock();
++diag.timeouts;
errorvars.unlock();
return ret;
}
tT.stop();
if( (reply->error()!=QNetworkReply::NoError))
{
errorvars.lock();
++diag.networkerrors;
errorvars.unlock();
reply->deleteLater();
return ret;
}
ret=reply->readAll();
reply->deleteLater();//TODO can't this be global??
if(ret.isEmpty())
{
#ifdef DEBUG_GMAPS
qDebug()<<"Invalid Tile";
#endif //DEBUG_GMAPS
errorvars.lock();
++diag.emptytiles;
errorvars.unlock();
return ret;
}
#ifdef DEBUG_GMAPS
qDebug()<<"Received Tile from the Internet";
#endif //DEBUG_GMAPS
errorvars.lock();
++diag.tilesFromNet;
errorvars.unlock();
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=new CacheItemQueue(type,pos,ret,zoom);
TileDBcacheQueue.EnqueueCacheTask(item);
}
}
}
#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");
}
diagnostics OPMaps::GetDiagnostics()
{
diagnostics i;
errorvars.lock();
i=diag;
errorvars.unlock();
return i;
}
}
/**
******************************************************************************
*
* @file OPMaps.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef OPMaps_H
#define OPMaps_H
#include "debugheader.h"
#include "memorycache.h"
#include "rawtile.h"
#include "cache.h"
#include "accessmode.h"
#include "languagetype.h"
#include "cacheitemqueue.h"
#include "tilecachequeue.h"
#include "pureimagecache.h"
#include "alllayersoftype.h"
#include "urlfactory.h"
#include "diagnostics.h"
//#include "point.h"
namespace core {
class OPMaps: public MemoryCache,public AllLayersOfType,public UrlFactory
{
public:
~OPMaps();
static OPMaps* Instance();
bool ImportFromGMDB(const QString &file);
bool ExportToGMDB(const QString &file);
/// <summary>
/// timeout for map connections
/// </summary>
QByteArray GetImageFrom(const MapType::Types &type,const core::Point &pos,const int &zoom);
bool UseMemoryCache(){return useMemoryCache;}//TODO
void setUseMemoryCache(const bool& value){useMemoryCache=value;}
void setLanguage(const LanguageType::Types& language){Language=language;}//TODO
LanguageType::Types GetLanguage(){return Language;}//TODO
AccessMode::Types GetAccessMode()const{return accessmode;}
void setAccessMode(const AccessMode::Types& mode){accessmode=mode;}
int RetryLoadTile;
diagnostics GetDiagnostics();
private:
bool useMemoryCache;
LanguageType::Types Language;
AccessMode::Types accessmode;
// PureImageCache ImageCacheLocal;//TODO Criar acesso Get Set
TileCacheQueue TileDBcacheQueue;
OPMaps();
OPMaps(OPMaps const&){}
OPMaps& operator=(OPMaps const&){ return *this; }
static OPMaps* m_pInstance;
diagnostics diag;
QMutex errorvars;
protected:
// MemoryCache TilesInMemory;
};
}
#endif // OPMaps_H
/**
******************************************************************************
*
* @file placemark.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "placemark.h"
/**
******************************************************************************
*
* @file placemark.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PLACEMARK_H
#define PLACEMARK_H
#include <QString>
namespace core {
class Placemark
{
public:
Placemark(const QString &address)
{
this->address = address;
}
QString Address(){return address;}
int Accuracy(){return accuracy;}
void SetAddress(const QString &adr){address=adr;}
void SetAccuracy(const int &value){accuracy=value;}
private:
QString address;
int accuracy;
protected:
};
}
#endif // PLACEMARK_H
/**
******************************************************************************
*
* @file point.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "point.h"
#include "size.h"
namespace core {
Point::Point(int dw)
{
this->x=(short)Point::LOWORD(dw);
this->y=(short)Point::HIWORD(dw);
empty=false;
}
Point::Point(Size sz)
{
this->x=sz.Width();
this->y=sz.Height();
empty=false;
}
Point::Point(int x, int y)
{
this->x=x;
this->y=y;
empty=false;
}
Point::Point():x(0),y(0),empty(true)
{}
uint qHash(Point const& point)
{
return point.x^point.y;
}
bool operator==(Point const &lhs,Point const &rhs)
{
return (lhs.x==rhs.x && lhs.y==rhs.y);
}
bool operator!=(Point const &lhs,Point const &rhs)
{
return !(lhs==rhs);
}
int Point::HIWORD(int n)
{
return (n >> 16) & 0xffff;
}
int Point::LOWORD(int n)
{
return n & 0xffff;
}
Point Point::Empty=Point();
}
/**
******************************************************************************
*
* @file point.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef OPOINT_H
#define OPOINT_H
#include <QString>
namespace core {
struct Size;
struct Point
{
friend uint qHash(Point const& point);
friend bool operator==(Point const& lhs,Point const& rhs);
friend bool operator!=(Point const& lhs,Point const& rhs);
public:
Point();
Point(int x,int y);
Point(Size sz);
Point(int dw);
bool IsEmpty(){return empty;}
int X()const{return this->x;}
int Y()const{return this->y;}
void SetX(const int &value){x=value;empty=false;}
void SetY(const int &value){y=value;empty=false;}
QString ToString()const{return "{"+QString::number(x)+","+QString::number(y)+"}";}
static Point Empty;
void Offset(const int &dx,const int &dy)
{
x += dx;
y += dy;
}
void Offset(Point p)
{
Offset(p.x, p.y);
}
static int HIWORD(int n);
static int LOWORD(int n);
private:
int x;
int y;
bool empty;
};
}
#endif // POINT_H
/**
******************************************************************************
*
* @file providerstrings.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "providerstrings.h"
namespace core {
const QString ProviderStrings::levelsForSigPacSpainMap[] = {"0", "1", "2", "3", "4",
"MTNSIGPAC",
"MTN2000", "MTN2000", "MTN2000", "MTN2000", "MTN2000",
"MTN200", "MTN200", "MTN200",
"MTN25", "MTN25",
"ORTOFOTOS","ORTOFOTOS","ORTOFOTOS","ORTOFOTOS"};
ProviderStrings::ProviderStrings()
{
// VersionGoogleMap = "m@132";
// VersionGoogleSatellite = "71";
// VersionGoogleLabels = "h@132";
// VersionGoogleTerrain = "t@125,r@132";
// Google version strings
VersionGoogleMap = "m@132";
VersionGoogleSatellite = "71";
VersionGoogleLabels = "h@132";
VersionGoogleTerrain = "t@125,r@132";
SecGoogleWord = "Galileo";
// Google (China) version strings
VersionGoogleMapChina = "m@132";
VersionGoogleSatelliteChina = "s@71";
VersionGoogleLabelsChina = "h@132";
VersionGoogleTerrainChina = "t@125,r@132";
// Google (Korea) version strings
VersionGoogleMapKorea = "kr1.12";
VersionGoogleSatelliteKorea = "66";
VersionGoogleLabelsKorea = "kr1t.12";
/// <summary>
/// Google Maps API generated using http://greatmaps.codeplex.com/
/// from http://code.google.com/intl/en-us/apis/maps/signup.html
/// </summary>
GoogleMapsAPIKey = "ABQIAAAAWaQgWiEBF3lW97ifKnAczhRAzBk5Igf8Z5n2W3hNnMT0j2TikxTLtVIGU7hCLLHMAuAMt-BO5UrEWA";
// Yahoo version strings
VersionYahooMap = "4.3";
VersionYahooSatellite = "1.9";
VersionYahooLabels = "4.3";
// BingMaps
VersionBingMaps = "563";
// YandexMap
VersionYandexMap = "2.16.0";
//VersionYandexSatellite = "1.19.0";
////////////////////
/// <summary>
/// Bing Maps Customer Identification, more info here
/// http://msdn.microsoft.com/en-us/library/bb924353.aspx
/// </summary>
BingMapsClientToken = "";
}
}
/**
******************************************************************************
*
* @file providerstrings.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PROVIDERSTRINGS_H
#define PROVIDERSTRINGS_H
#include <QString>
namespace core {
class ProviderStrings
{
public:
ProviderStrings();
static const QString levelsForSigPacSpainMap[];
QString GoogleMapsAPIKey;
// Google version strings
QString VersionGoogleMap;
QString VersionGoogleSatellite;
QString VersionGoogleLabels;
QString VersionGoogleTerrain;
QString SecGoogleWord;
// Google (China) version strings
QString VersionGoogleMapChina;
QString VersionGoogleSatelliteChina;
QString VersionGoogleLabelsChina;
QString VersionGoogleTerrainChina;
// Google (Korea) version strings
QString VersionGoogleMapKorea;
QString VersionGoogleSatelliteKorea;
QString VersionGoogleLabelsKorea;
/// <summary>
/// Google Maps API generated using http://greatmaps.codeplex.com/
/// from http://code.google.com/intl/en-us/apis/maps/signup.html
/// </summary>
// Yahoo version strings
QString VersionYahooMap;
QString VersionYahooSatellite;
QString VersionYahooLabels;
// BingMaps
QString VersionBingMaps;
// YandexMap
QString VersionYandexMap;
/// <summary>
/// Bing Maps Customer Identification, more info here
/// http://msdn.microsoft.com/en-us/library/bb924353.aspx
/// </summary>
QString BingMapsClientToken;
};
}
#endif // PROVIDERSTRINGS_H
/**
******************************************************************************
*
* @file pureimage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "pureimage.h"
namespace core {
PureImageProxy::PureImageProxy()
{
}
QPixmap PureImageProxy::FromStream(const QByteArray &array)
{
return QPixmap::fromImage(QImage::fromData(array));
}
bool PureImageProxy::Save(const QByteArray &array, QPixmap &pic)
{
pic=QPixmap::fromImage(QImage::fromData(array));
return true;
}
}
/**
******************************************************************************
*
* @file pureimage.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PUREIMAGE_H
#define PUREIMAGE_H
#include <QPixmap>
#include <QByteArray>
namespace core {
class PureImageProxy
{
public:
PureImageProxy();
static QPixmap FromStream(const QByteArray &array);
static bool Save(const QByteArray &array,QPixmap &pic);
};
}
#endif // PUREIMAGE_H
This diff is collapsed.
/**
******************************************************************************
*
* @file pureimagecache.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PUREIMAGECACHE_H
#define PUREIMAGECACHE_H
#include <QtSql/QSqlDatabase>
#include <QString>
#include <QDir>
#include <QDebug>
#include <QFileInfo>
#include <QtSql/QSqlQuery>
#include <QtSql/QSqlError>
#include <QBuffer>
#include "maptype.h"
#include "point.h"
#include <QVariant>
#include "pureimage.h"
#include <QList>
#include <QMutex>
namespace core {
class PureImageCache
{
public:
PureImageCache();
static bool CreateEmptyDB(const QString &file);
bool PutImageToCache(const QByteArray &tile,const MapType::Types &type,const core::Point &pos, const int &zoom);
QByteArray GetImageFromCache(MapType::Types type, core::Point pos, int zoom);
QString GtileCache();
void setGtileCache(const QString &value);
static bool ExportMapDataToDB(QString sourceFile, QString destFile);
void deleteOlderTiles(int const& days);
private:
QString gtilecache;
QMutex Mcounter;
static qlonglong ConnCounter;
};
}
#endif // PUREIMAGECACHE_H
/**
******************************************************************************
*
* @file rawtile.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "rawtile.h"
namespace core {
RawTile::RawTile(const MapType::Types &Type, const Point &Pos, const int &Zoom)
{
zoom=Zoom;
type=Type;
pos=Pos;
}
QString RawTile::ToString()
{
return QString("%1 at zoom %2, pos:%3,%4").arg(type).arg(zoom).arg(pos.X()).arg(pos.Y());
}
Point RawTile::Pos()
{
return pos;
}
MapType::Types RawTile::Type()
{
return type;
}
int RawTile::Zoom()
{
return zoom;
}
void RawTile::setType(const MapType::Types &value)
{
type=value;
}
void RawTile::setPos(const Point &value)
{
pos=value;
}
void RawTile::setZoom(const int &value)
{
zoom=value;
}
uint qHash(RawTile const& tile)
{
// RawTile tile=tilee;
quint64 tmp=(((quint64)(tile.zoom))<<54)+(((quint64)(tile.type))<<36)+(((quint64)(tile.pos.X()))<<18)+(((quint64)(tile.pos.Y())));
// quint64 tmp5=tmp+tmp2+tmp3+tmp4;
return ::qHash(tmp);
}
bool operator==(RawTile const &lhs,RawTile const &rhs)
{
return (lhs.pos==rhs.pos && lhs.zoom==rhs.zoom && lhs.type==rhs.type);
}
}
/**
******************************************************************************
*
* @file rawtile.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef RAWTILE_H
#define RAWTILE_H
#include "maptype.h"
#include "point.h"
#include <QString>
#include <QHash>
namespace core {
class RawTile
{
friend uint qHash(RawTile const& tile);
friend bool operator==(RawTile const& lhs,RawTile const& rhs);
public:
RawTile(const MapType::Types &Type,const core::Point &Pos,const int &Zoom);
QString ToString(void);
MapType::Types Type();
core::Point Pos();
int Zoom();
void setType(const MapType::Types &value);
void setPos(const core::Point &value);
void setZoom(const int &value);
private:
MapType::Types type;
core::Point pos;
int zoom;
};
}
#endif // RAWTILE_H
/**
******************************************************************************
*
* @file size.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "size.h"
namespace core {
Size::Size():width(0),height(0)
{}
}
/**
******************************************************************************
*
* @file size.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef SIZE_H
#define SIZE_H
#include "point.h"
#include <QString>
#include <QHash>
namespace core {
struct Size
{
Size();
Size(Point pt){width=pt.X(); height=pt.Y();};
Size(int Width,int Height){width=Width; height=Height;};
friend uint qHash(Size const& size);
// friend bool operator==(Size const& lhs,Size const& rhs);
Size operator-(const Size &sz1){return Size(width-sz1.width,height-sz1.height);}
Size operator+(const Size &sz1){return Size(sz1.width+width,sz1.height+height);}
int GetHashCode(){return width^height;}
uint qHash(Size const& /*rect*/){return width^height;}
QString ToString(){return "With="+QString::number(width)+" ,Height="+QString::number(height);}
int Width()const {return width;}
int Height()const {return height;}
void SetWidth(int const& value){width=value;}
void SetHeight(int const& value){height=value;}
private:
int width;
int height;
};
}
#endif // SIZE_H
/**
******************************************************************************
*
* @file tilecachequeue.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "tilecachequeue.h"
//#define DEBUG_TILECACHEQUEUE
namespace core {
TileCacheQueue::TileCacheQueue()
{
}
TileCacheQueue::~TileCacheQueue()
{
// QThread::wait(10000);
}
void TileCacheQueue::EnqueueCacheTask(CacheItemQueue *task)
{
#ifdef DEBUG_TILECACHEQUEUE
qDebug()<<"DB Do I EnqueueCacheTask"<<task->GetPosition().X()<<","<<task->GetPosition().Y();
#endif //DEBUG_TILECACHEQUEUE
if(!tileCacheQueue.contains(task))
{
#ifdef DEBUG_TILECACHEQUEUE
qDebug()<<"EnqueueCacheTask"<<task->GetPosition().X()<<","<<task->GetPosition().Y();
#endif //DEBUG_TILECACHEQUEUE
mutex.lock();
tileCacheQueue.enqueue(task);
mutex.unlock();
if(this->isRunning())
{
#ifdef DEBUG_TILECACHEQUEUE
qDebug()<<"Wake Thread";
#endif //DEBUG_TILECACHEQUEUE
//this->start(QThread::NormalPriority);
//waitmutex.lock();
waitc.wakeAll();
//waitmutex.unlock();
}
else
{
#ifdef DEBUG_TILECACHEQUEUE
qDebug()<<"Start Thread";
#endif //DEBUG_TILECACHEQUEUE
this->start(QThread::NormalPriority);
}
}
}
void TileCacheQueue::run()
{
#ifdef DEBUG_TILECACHEQUEUE
qDebug()<<"Cache Engine Start";
#endif //DEBUG_TILECACHEQUEUE
while(true)
{
CacheItemQueue *task;
#ifdef DEBUG_TILECACHEQUEUE
qDebug()<<"Cache";
#endif //DEBUG_TILECACHEQUEUE
if(tileCacheQueue.count()>0)
{
mutex.lock();
task=tileCacheQueue.dequeue();
mutex.unlock();
#ifdef DEBUG_TILECACHEQUEUE
qDebug()<<"Cache engine Put:"<<task->GetPosition().X()<<","<<task->GetPosition().Y();
#endif //DEBUG_TILECACHEQUEUE
Cache::Instance()->ImageCache.PutImageToCache(task->GetImg(),task->GetMapType(),task->GetPosition(),task->GetZoom());
usleep(44);
delete task;
}
else
{
qDebug()<<"Cache engine BEGIN WAIT";
waitmutex.lock();
int tout=4000;
if(!waitc.wait(&waitmutex,tout))
{
waitmutex.unlock();
#ifdef DEBUG_TILECACHEQUEUE
qDebug()<<"Cache Engine TimeOut";
#endif //DEBUG_TILECACHEQUEUE
mutex.lock();
if(tileCacheQueue.count()==0)
{
mutex.unlock();
break;
}
mutex.unlock();
}
qDebug()<<"Cache Engine DID NOT TimeOut";
waitmutex.unlock();
}
}
#ifdef DEBUG_TILECACHEQUEUE
qDebug()<<"Cache Engine Stopped";
#endif //DEBUG_TILECACHEQUEUE
}
}
/**
******************************************************************************
*
* @file tilecachequeue.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef TILECACHEQUEUE_H
#define TILECACHEQUEUE_H
#include <QQueue>
#include "cacheitemqueue.h"
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <QObject>
#include <QMutexLocker>
#include "pureimagecache.h"
#include "cache.h"
namespace core {
class TileCacheQueue:public QThread
{
Q_OBJECT
public:
TileCacheQueue();
~TileCacheQueue();
void EnqueueCacheTask(CacheItemQueue *task);
protected:
QQueue<CacheItemQueue*> tileCacheQueue;
private:
void run();
QMutex mutex;
QMutex waitmutex;
QWaitCondition waitc;
};
}
#endif // TILECACHEQUEUE_H
This diff is collapsed.
/**
******************************************************************************
*
* @file urlfactory.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef URLFACTORY_H
#define URLFACTORY_H
#include <QtNetwork/QNetworkProxy>
#include <QtNetwork/QNetworkAccessManager>
#include <QUrl>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QTimer>
#include <QCoreApplication>
#include "providerstrings.h"
#include "pureimagecache.h"
#include "../internals/pointlatlng.h"
#include "geodecoderstatus.h"
#include <QTime>
#include "cache.h"
#include "placemark.h"
#include <QTextCodec>
#include "cmath"
namespace core {
class UrlFactory: public QObject,public ProviderStrings
{
Q_OBJECT
public:
/// <summary>
/// Gets or sets the value of the User-agent HTTP header.
/// </summary>
QByteArray UserAgent;
QNetworkProxy Proxy;
UrlFactory();
~UrlFactory();
QString MakeImageUrl(const MapType::Types &type,const core::Point &pos,const int &zoom,const QString &language);
internals::PointLatLng GetLatLngFromGeodecoder(const QString &keywords,GeoCoderStatusCode::Types &status);
Placemark GetPlacemarkFromGeocoder(internals::PointLatLng location);
int Timeout;
private:
void GetSecGoogleWords(const core::Point &pos, QString &sec1, QString &sec2);
int GetServerNum(const core::Point &pos,const int &max) const;
void TryCorrectGoogleVersions();
bool isCorrectedGoogleVersions;
QString TileXYToQuadKey(const int &tileX,const int &tileY,const int &levelOfDetail) const;
bool CorrectGoogleVersions;
bool UseGeocoderCache; //TODO GetSet
bool UsePlacemarkCache;//TODO GetSet
static const double EarthRadiusKm;
double GetDistance(internals::PointLatLng p1,internals::PointLatLng p2);
protected:
static short timelapse;
QString LanguageStr;
bool IsCorrectGoogleVersions();
void setIsCorrectGoogleVersions(bool value);
QString MakeGeocoderUrl(QString keywords);
QString MakeReverseGeocoderUrl(internals::PointLatLng &pt,const QString &language);
internals::PointLatLng GetLatLngFromGeocoderUrl(const QString &url,const bool &useCache, GeoCoderStatusCode::Types &status);
Placemark GetPlacemarkFromReverseGeocoderUrl(const QString &url,const bool &useCache);
};
}
#endif // URLFACTORY_H
/**
******************************************************************************
*
* @file MouseWheelZoomType.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mousewheelzoomtype.h"
namespace internals {
}
/**
******************************************************************************
*
* @file copyrightstrings.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef COPYRIGHTSTRINGS_H
#define COPYRIGHTSTRINGS_H
#include <QString>
#include <QDateTime>
namespace internals {
static const QString googleCopyright = QString("%1 Google - Map data %1 Tele Atlas, Imagery %1 TerraMetrics").arg(QDate::currentDate().year());
static const QString openStreetMapCopyright = QString(" OpenStreetMap - Map data %1 OpenStreetMap").arg(QDate::currentDate().year());
static const QString yahooMapCopyright = QString(" Yahoo! Inc. - Map data & Imagery %1 NAVTEQ").arg(QDate::currentDate().year());
static const QString virtualEarthCopyright = QString("%1 Microsoft Corporation, %1 NAVTEQ, %1 Image courtesy of NASA").arg(QDate::currentDate().year());
static const QString arcGisCopyright = QString("%1 ESRI - Map data %1 ArcGIS").arg(QDate::currentDate().year());
}
#endif // COPYRIGHTSTRINGS_H
This diff is collapsed.
This diff is collapsed.
#ifndef DEBUGHEADER_H
#define DEBUGHEADER_H
//#define DEBUG_CORE
//#define DEBUG_TILE
//#define DEBUG_TILEMATRIX
#endif // DEBUGHEADER_H
include (../common.pri)
HEADERS += core.h \
mousewheelzoomtype.h \
rectangle.h \
tile.h \
tilematrix.h \
loadtask.h \
copyrightstrings.h \
pureprojection.h \
pointlatlng.h \
rectlatlng.h \
sizelatlng.h \
debugheader.h
SOURCES += core.cpp \
rectangle.cpp \
tile.cpp \
tilematrix.cpp \
pureprojection.cpp \
rectlatlng.cpp \
sizelatlng.cpp \
pointlatlng.cpp \
loadtask.cpp \
mousewheelzoomtype.cpp
HEADERS += ./projections/lks94projection.h \
./projections/mercatorprojection.h \
./projections/mercatorprojectionyandex.h \
./projections/platecarreeprojection.h \
./projections/platecarreeprojectionpergo.h
SOURCES += ./projections/lks94projection.cpp \
./projections/mercatorprojection.cpp \
./projections/mercatorprojectionyandex.cpp \
./projections/platecarreeprojection.cpp \
./projections/platecarreeprojectionpergo.cpp
LIBS += -L../build \
-lcore
/**
******************************************************************************
*
* @file loadtask.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "loadtask.h"
namespace internals {
bool operator==(LoadTask const& lhs,LoadTask const& rhs)
{
return ((lhs.Pos==rhs.Pos)&&(lhs.Zoom==rhs.Zoom));
}
}
/**
******************************************************************************
*
* @file loadtask.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* 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 3 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef LOADTASK_H
#define LOADTASK_H
#include <QString>
#include "../core/point.h"
using namespace core;
namespace internals
{
struct LoadTask
{
friend bool operator==(LoadTask const& lhs,LoadTask const& rhs);
public:
core::Point Pos;
int Zoom;
LoadTask(Point pos, int zoom)
{
Pos = pos;
Zoom = zoom;
}
LoadTask()
{
Pos=core::Point(-1,-1);
Zoom=-1;
}
bool HasValue()
{
return !(Zoom==-1);
}
QString ToString()const
{
return QString::number(Zoom) + " - " + Pos.ToString();
}
};
}
#endif // LOADTASK_H
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment