diff --git a/lib/opmapcontrol/opmapcontrol.h b/lib/opmapcontrol/opmapcontrol.h new file mode 100644 index 0000000000000000000000000000000000000000..4add132fde1d938efb7b8a2854b4b9ea263722d3 --- /dev/null +++ b/lib/opmapcontrol/opmapcontrol.h @@ -0,0 +1 @@ +#include "src/mapwidget/opmapwidget.h" diff --git a/lib/opmapcontrol/opmapcontrol.pri b/lib/opmapcontrol/opmapcontrol.pri new file mode 100644 index 0000000000000000000000000000000000000000..685899169e29392a5e7c93ff084f72f564a4dc38 --- /dev/null +++ b/lib/opmapcontrol/opmapcontrol.pri @@ -0,0 +1,103 @@ +###################################################################### +# 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 diff --git a/lib/opmapcontrol/src/common.pri b/lib/opmapcontrol/src/common.pri new file mode 100644 index 0000000000000000000000000000000000000000..fa9b16603f16b8df35f7369edef0885e1c5d9bb9 --- /dev/null +++ b/lib/opmapcontrol/src/common.pri @@ -0,0 +1,8 @@ +DESTDIR = ../build +QT += network +QT += sql +CONFIG += staticlib +TEMPLATE = lib +UI_DIR = uics +MOC_DIR = mocs +OBJECTS_DIR = objs diff --git a/lib/opmapcontrol/src/core/accessmode.h b/lib/opmapcontrol/src/core/accessmode.h new file mode 100644 index 0000000000000000000000000000000000000000..d152936f2851ff7623170f8735716f4673bbf643 --- /dev/null +++ b/lib/opmapcontrol/src/core/accessmode.h @@ -0,0 +1,86 @@ +/** +****************************************************************************** +* +* @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 +#include +#include +#include +namespace core { + class AccessMode:public QObject + { + Q_OBJECT + Q_ENUMS(Types) + public: + enum Types + { + /// + /// access only server + /// + ServerOnly, + + /// + /// access first server and caches localy + /// + ServerAndCache, + + /// + /// access only cache + /// + 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 AllLayersOfType::GetAllLayersOfType(const MapType::Types &type) + { + QVector 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; + + } +} diff --git a/lib/opmapcontrol/src/core/alllayersoftype.h b/lib/opmapcontrol/src/core/alllayersoftype.h new file mode 100644 index 0000000000000000000000000000000000000000..94f7442b5e30d606d07cc6391111f7d9fb5c4646 --- /dev/null +++ b/lib/opmapcontrol/src/core/alllayersoftype.h @@ -0,0 +1,43 @@ +/** +****************************************************************************** +* +* @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 +#include + +namespace core { + class AllLayersOfType + { + public: + AllLayersOfType(); + QVector GetAllLayersOfType(const MapType::Types &type); + }; + +} +#endif // ALLLAYERSOFTYPE_H diff --git a/lib/opmapcontrol/src/core/cache.cpp b/lib/opmapcontrol/src/core/cache.cpp new file mode 100644 index 0000000000000000000000000000000000000000..302ef802f64138a41794628404b4a4c1ced2b0ba --- /dev/null +++ b/lib/opmapcontrol/src/core/cache.cpp @@ -0,0 +1,196 @@ +/** +****************************************************************************** +* +* @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?:"<>ret; + } + } +#ifdef DEBUG_GetGeocoderFromCache + qDebug()<<"GetGeocoderFromCache:Returning:"<>ret; + } + } +#ifdef DEBUG_CACHE + qDebug()<<"GetPlacemarkFromCache:Returning:"< + + + +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 diff --git a/lib/opmapcontrol/src/core/core.pro b/lib/opmapcontrol/src/core/core.pro new file mode 100644 index 0000000000000000000000000000000000000000..9c355e3ca4985cad7ca6d85f25a5b03fb8e38083 --- /dev/null +++ b/lib/opmapcontrol/src/core/core.pro @@ -0,0 +1,40 @@ +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 diff --git a/lib/opmapcontrol/src/core/debugheader.h b/lib/opmapcontrol/src/core/debugheader.h new file mode 100644 index 0000000000000000000000000000000000000000..0e1f73195afeb7a4d949be837805c5c08704a74a --- /dev/null +++ b/lib/opmapcontrol/src/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/lib/opmapcontrol/src/core/diagnostics.cpp b/lib/opmapcontrol/src/core/diagnostics.cpp new file mode 100644 index 0000000000000000000000000000000000000000..33bbbcc586127f71e11571c52e95c8ece8424e54 --- /dev/null +++ b/lib/opmapcontrol/src/core/diagnostics.cpp @@ -0,0 +1,31 @@ +/** +****************************************************************************** +* +* @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) +{ +} diff --git a/lib/opmapcontrol/src/core/diagnostics.h b/lib/opmapcontrol/src/core/diagnostics.h new file mode 100644 index 0000000000000000000000000000000000000000..113faef19d65fd534ca21c01dd3c598a73006ce0 --- /dev/null +++ b/lib/opmapcontrol/src/core/diagnostics.h @@ -0,0 +1,47 @@ +/** +****************************************************************************** +* +* @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 +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 diff --git a/lib/opmapcontrol/src/core/geodecoderstatus.h b/lib/opmapcontrol/src/core/geodecoderstatus.h new file mode 100644 index 0000000000000000000000000000000000000000..58b653dee433ff513f4a26e39b90bfe41a1f4902 --- /dev/null +++ b/lib/opmapcontrol/src/core/geodecoderstatus.h @@ -0,0 +1,131 @@ +/** +****************************************************************************** +* +* @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 +#include +#include +#include +namespace core { + class GeoCoderStatusCode:public QObject + { + Q_OBJECT + Q_ENUMS(Types) + public: + enum Types + { + /// + /// unknow response + /// + Unknow = -1, + + /// + /// No errors occurred; the address was successfully parsed and its geocode has been returned. + /// + G_GEO_SUCCESS=200, + + /// + /// 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. + /// + G_GEO_BAD_REQUEST=400, + + /// + /// A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known. + /// + G_GEO_SERVER_ERROR=500, + + /// + /// 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. + /// + G_GEO_MISSING_QUERY=601, + + /// + /// Synonym for G_GEO_MISSING_QUERY. + /// + G_GEO_MISSING_ADDRESS=601, + + /// + /// 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. + /// + G_GEO_UNKNOWN_ADDRESS=602, + + /// + /// The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons. + /// + G_GEO_UNAVAILABLE_ADDRESS=603, + + /// + /// 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. + /// + G_GEO_UNKNOWN_DIRECTIONS=604, + + /// + /// The given key is either invalid or does not match the domain for which it was given. + /// + G_GEO_BAD_KEY=610, + + /// + /// 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. + /// + 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;xMemoryCacheCapacity()) + { + if(cachequeue.count()>0 && list.count()>0) + { +#ifdef DEBUG_MEMORY_CACHE + qDebug()<<"Cleaning Memory cache="<<" started with "< +#include +#include +#include +#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 cachequeue; + QQueue list; + long memoryCacheSize; + private: + int _MemoryCacheCapacity; + + }; + + + +} +#endif // KIBERTILECACHE_H diff --git a/lib/opmapcontrol/src/core/languagetype.cpp b/lib/opmapcontrol/src/core/languagetype.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2c4ee2a7c88ef62d1af0c0af7ac8e18ff825566e --- /dev/null +++ b/lib/opmapcontrol/src/core/languagetype.cpp @@ -0,0 +1,100 @@ +/** +****************************************************************************** +* +* @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(); + } + +} diff --git a/lib/opmapcontrol/src/core/languagetype.h b/lib/opmapcontrol/src/core/languagetype.h new file mode 100644 index 0000000000000000000000000000000000000000..4b8411e452d11fec4d51a984d89f96360d4dbf7d --- /dev/null +++ b/lib/opmapcontrol/src/core/languagetype.h @@ -0,0 +1,133 @@ +/** +****************************************************************************** +* +* @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 +#include +#include +#include + + +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 +#include +#include + +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 +#include +#include +#include "kibertilecache.h" +#include +#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 diff --git a/lib/opmapcontrol/src/core/opmaps.cpp b/lib/opmapcontrol/src/core/opmaps.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b2db6747d6298cd05bdb84ac1d45088e3d4f825f --- /dev/null +++ b/lib/opmapcontrol/src/core/opmaps.cpp @@ -0,0 +1,286 @@ +/** +****************************************************************************** +* +* @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="<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"<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; + } +} + diff --git a/lib/opmapcontrol/src/core/opmaps.h b/lib/opmapcontrol/src/core/opmaps.h new file mode 100644 index 0000000000000000000000000000000000000000..f94f3fa06fb707fde6e2ed6a9c68836db435d8bf --- /dev/null +++ b/lib/opmapcontrol/src/core/opmaps.h @@ -0,0 +1,94 @@ +/** +****************************************************************************** +* +* @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); + /// + /// timeout for map connections + /// + + + 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 diff --git a/lib/opmapcontrol/src/core/placemark.cpp b/lib/opmapcontrol/src/core/placemark.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1f8971aae3c8655bb0ea38711614db925953ef54 --- /dev/null +++ b/lib/opmapcontrol/src/core/placemark.cpp @@ -0,0 +1,28 @@ +/** +****************************************************************************** +* +* @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" + diff --git a/lib/opmapcontrol/src/core/placemark.h b/lib/opmapcontrol/src/core/placemark.h new file mode 100644 index 0000000000000000000000000000000000000000..3f338b3f5673ed838b18d2495c85c2b2cae00b22 --- /dev/null +++ b/lib/opmapcontrol/src/core/placemark.h @@ -0,0 +1,54 @@ +/** +****************************************************************************** +* +* @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 + + +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 diff --git a/lib/opmapcontrol/src/core/point.cpp b/lib/opmapcontrol/src/core/point.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a8f43ed0ea500dcac251f47e49fc5fcd9227de71 --- /dev/null +++ b/lib/opmapcontrol/src/core/point.cpp @@ -0,0 +1,74 @@ +/** +****************************************************************************** +* +* @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(); + +} diff --git a/lib/opmapcontrol/src/core/point.h b/lib/opmapcontrol/src/core/point.h new file mode 100644 index 0000000000000000000000000000000000000000..83d1f079ebb78a6041dd28e1786433ca798431e7 --- /dev/null +++ b/lib/opmapcontrol/src/core/point.h @@ -0,0 +1,72 @@ +/** +****************************************************************************** +* +* @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 + +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 diff --git a/lib/opmapcontrol/src/core/providerstrings.cpp b/lib/opmapcontrol/src/core/providerstrings.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8d1f63e30a3b4a8ecfd6876b6f61149c47a0245b --- /dev/null +++ b/lib/opmapcontrol/src/core/providerstrings.cpp @@ -0,0 +1,88 @@ +/** +****************************************************************************** +* +* @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"; + + /// + /// Google Maps API generated using http://greatmaps.codeplex.com/ + /// from http://code.google.com/intl/en-us/apis/maps/signup.html + /// + 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"; + //////////////////// + + /// + /// Bing Maps Customer Identification, more info here + /// http://msdn.microsoft.com/en-us/library/bb924353.aspx + /// + BingMapsClientToken = ""; + + } +} diff --git a/lib/opmapcontrol/src/core/providerstrings.h b/lib/opmapcontrol/src/core/providerstrings.h new file mode 100644 index 0000000000000000000000000000000000000000..8759057b4124aac0f28cb8a4f31734331cd7cc6b --- /dev/null +++ b/lib/opmapcontrol/src/core/providerstrings.h @@ -0,0 +1,85 @@ +/** +****************************************************************************** +* +* @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 + + +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; + + /// + /// Google Maps API generated using http://greatmaps.codeplex.com/ + /// from http://code.google.com/intl/en-us/apis/maps/signup.html + /// + + + // Yahoo version strings + QString VersionYahooMap; + QString VersionYahooSatellite; + QString VersionYahooLabels; + + // BingMaps + QString VersionBingMaps; + + // YandexMap + QString VersionYandexMap; + + + + /// + /// Bing Maps Customer Identification, more info here + /// http://msdn.microsoft.com/en-us/library/bb924353.aspx + /// + QString BingMapsClientToken; + }; + +} +#endif // PROVIDERSTRINGS_H diff --git a/lib/opmapcontrol/src/core/pureimage.cpp b/lib/opmapcontrol/src/core/pureimage.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e938db04d44d119f10a3c5a8dcf77b6ae0528482 --- /dev/null +++ b/lib/opmapcontrol/src/core/pureimage.cpp @@ -0,0 +1,46 @@ +/** +****************************************************************************** +* +* @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; +} +} diff --git a/lib/opmapcontrol/src/core/pureimage.h b/lib/opmapcontrol/src/core/pureimage.h new file mode 100644 index 0000000000000000000000000000000000000000..76e1b552ffdac25d24af09fa8799d17f0737a784 --- /dev/null +++ b/lib/opmapcontrol/src/core/pureimage.h @@ -0,0 +1,44 @@ +/** +****************************************************************************** +* +* @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 +#include + + +namespace core { + class PureImageProxy + { + public: + PureImageProxy(); + static QPixmap FromStream(const QByteArray &array); + static bool Save(const QByteArray &array,QPixmap &pic); + }; + +} +#endif // PUREIMAGE_H diff --git a/lib/opmapcontrol/src/core/pureimagecache.cpp b/lib/opmapcontrol/src/core/pureimagecache.cpp new file mode 100644 index 0000000000000000000000000000000000000000..99690a94dcd6d68e805308215b820fdae9afb603 --- /dev/null +++ b/lib/opmapcontrol/src/core/pureimagecache.cpp @@ -0,0 +1,360 @@ +/** +****************************************************************************** +* +* @file pureimagecache.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 "pureimagecache.h" +#include + +//#define DEBUG_PUREIMAGECACHE +namespace core { + qlonglong PureImageCache::ConnCounter=0; + + PureImageCache::PureImageCache() + { + gtilecache=QDir::currentPath()+QDir::separator()+"mapscache"+QDir::separator(); + QDir d; + if(!d.exists(gtilecache)) + { + d.mkdir(gtilecache); +#ifdef DEBUG_PUREIMAGECACHE + qDebug()<<"Create Cache directory"; +#endif //DEBUG_PUREIMAGECACHE + } + { + QString db=gtilecache+"Data.qmdb"; + if(!QFileInfo(db).exists()) + { +#ifdef DEBUG_PUREIMAGECACHE + qDebug()<<"Try to create EmptyDB"; +#endif //DEBUG_PUREIMAGECACHE + CreateEmptyDB(db); + } + } + } + + void PureImageCache::setGtileCache(const QString &value) + { + gtilecache=value; + QDir d; + if(!d.exists(gtilecache)) + { + d.mkdir(gtilecache); +#ifdef DEBUG_PUREIMAGECACHE + qDebug()<<"Create Cache directory"; +#endif //DEBUG_PUREIMAGECACHE + } + { + QString db=gtilecache+"Data.qmdb"; + if(!QFileInfo(db).exists()) + { +#ifdef DEBUG_PUREIMAGECACHE + qDebug()<<"Try to create EmptyDB"; +#endif //DEBUG_PUREIMAGECACHE + CreateEmptyDB(db); + } + } + } + QString PureImageCache::GtileCache() + { + return gtilecache; + } + + + bool PureImageCache::CreateEmptyDB(const QString &file) + { +#ifdef DEBUG_PUREIMAGECACHE + qDebug()<<"Create database at!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:"< add; + bool ret=true; + QString dir=gtilecache; + { + QString db=dir+"Data.qmdb"; + ret=QFileInfo(db).exists(); + if(ret) + { + QSqlDatabase cn; + Mcounter.lock(); + qlonglong id=++ConnCounter; + Mcounter.unlock(); + cn = QSqlDatabase::addDatabase("QSQLITE",QString::number(id)); + cn.setDatabaseName(db); + cn.setConnectOptions("QSQLITE_ENABLE_SHARED_CACHE"); + if(cn.open()) + { + { + QSqlQuery query(cn); + query.exec(QString("SELECT id, X, Y, Zoom, Type, Date FROM Tiles")); + while(query.next()) + { + if(QDateTime::fromString(query.value(5).toString()).daysTo(QDateTime::currentDateTime())>days) + add.append(query.value(0).toLongLong()); + } + foreach(long i,add) + { + query.exec(QString("DELETE FROM Tiles WHERE id = %1;").arg(i)); + } + } + + cn.close(); + } + QSqlDatabase::removeDatabase(QString::number(id)); + } + } + } + // PureImageCache::ExportMapDataToDB("C:/Users/Xapo/Documents/mapcontrol/debug/mapscache/data.qmdb","C:/Users/Xapo/Documents/mapcontrol/debug/mapscache/data2.qmdb"); + bool PureImageCache::ExportMapDataToDB(QString sourceFile, QString destFile) + { + bool ret=true; + QList add; + if(!QFileInfo(destFile).exists()) + { +#ifdef DEBUG_PUREIMAGECACHE + qDebug()<<"Try to create EmptyDB"; +#endif //DEBUG_PUREIMAGECACHE + ret=CreateEmptyDB(destFile); + } + if(!ret) return false; + QSqlDatabase ca = QSqlDatabase::addDatabase("QSQLITE","ca"); + ca.setDatabaseName(sourceFile); + + if(ca.open()) + { + QSqlDatabase cb = QSqlDatabase::addDatabase("QSQLITE","cb"); + cb.setDatabaseName(destFile); + if(cb.open()) + { + QSqlQuery queryb(cb); + queryb.exec(QString("ATTACH DATABASE \"%1\" AS Source").arg(sourceFile)); + QSqlQuery querya(ca); + querya.exec("SELECT id, X, Y, Zoom, Type, Date FROM Tiles"); + while(querya.next()) + { + long id=querya.value(0).toLongLong(); + queryb.exec(QString("SELECT id FROM Tiles WHERE X=%1 AND Y=%2 AND Zoom=%3 AND Type=%4;").arg(querya.value(1).toLongLong()).arg(querya.value(2).toLongLong()).arg(querya.value(3).toLongLong()).arg(querya.value(4).toLongLong())); + if(!queryb.next()) + { + add.append(id); + } + + } + long f; + foreach(f,add) + { + queryb.exec(QString("INSERT INTO Tiles(X, Y, Zoom, Type, Date) SELECT X, Y, Zoom, Type, Date FROM Source.Tiles WHERE id=%1").arg(f)); + queryb.exec(QString("INSERT INTO TilesData(id, Tile) Values((SELECT last_insert_rowid()), (SELECT Tile FROM Source.TilesData WHERE id=%1))").arg(f)); + } + add.clear(); + ca.close(); + cb.close(); + + } + else return false; + } + else return false; + QSqlDatabase::removeDatabase("ca"); + QSqlDatabase::removeDatabase("cb"); + return true; + + } + +} diff --git a/lib/opmapcontrol/src/core/pureimagecache.h b/lib/opmapcontrol/src/core/pureimagecache.h new file mode 100644 index 0000000000000000000000000000000000000000..fdc120e3d1e453ffd06e31673d7e663f467e4d62 --- /dev/null +++ b/lib/opmapcontrol/src/core/pureimagecache.h @@ -0,0 +1,66 @@ +/** +****************************************************************************** +* +* @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 +#include +#include +#include +#include +#include +#include +#include +#include "maptype.h" +#include "point.h" +#include +#include "pureimage.h" +#include +#include + +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 diff --git a/lib/opmapcontrol/src/core/rawtile.cpp b/lib/opmapcontrol/src/core/rawtile.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f357ae50faf67622aefb4f11a4efc61e4b6175e7 --- /dev/null +++ b/lib/opmapcontrol/src/core/rawtile.cpp @@ -0,0 +1,76 @@ +/** +****************************************************************************** +* +* @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); +} +} diff --git a/lib/opmapcontrol/src/core/rawtile.h b/lib/opmapcontrol/src/core/rawtile.h new file mode 100644 index 0000000000000000000000000000000000000000..7b3901f6f699e580e58826daf6384bcb69096448 --- /dev/null +++ b/lib/opmapcontrol/src/core/rawtile.h @@ -0,0 +1,56 @@ +/** +****************************************************************************** +* +* @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 +#include + +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 diff --git a/lib/opmapcontrol/src/core/size.cpp b/lib/opmapcontrol/src/core/size.cpp new file mode 100644 index 0000000000000000000000000000000000000000..65a26fac217334ed621ad619e8854632c166b125 --- /dev/null +++ b/lib/opmapcontrol/src/core/size.cpp @@ -0,0 +1,33 @@ +/** +****************************************************************************** +* +* @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) +{} +} diff --git a/lib/opmapcontrol/src/core/size.h b/lib/opmapcontrol/src/core/size.h new file mode 100644 index 0000000000000000000000000000000000000000..da340b9a63c0c3c0f0c02388fc7f3d5d1d172965 --- /dev/null +++ b/lib/opmapcontrol/src/core/size.h @@ -0,0 +1,58 @@ +/** +****************************************************************************** +* +* @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 +#include + +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 diff --git a/lib/opmapcontrol/src/core/tilecachequeue.cpp b/lib/opmapcontrol/src/core/tilecachequeue.cpp new file mode 100644 index 0000000000000000000000000000000000000000..166e66a2911963a0b2848b0639c9255dc8019baf --- /dev/null +++ b/lib/opmapcontrol/src/core/tilecachequeue.cpp @@ -0,0 +1,128 @@ +/** +****************************************************************************** +* +* @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"<GetPosition().X()<<","<GetPosition().Y(); +#endif //DEBUG_TILECACHEQUEUE + if(!tileCacheQueue.contains(task)) + { +#ifdef DEBUG_TILECACHEQUEUE + qDebug()<<"EnqueueCacheTask"<GetPosition().X()<<","<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:"<GetPosition().X()<<","<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 +} + + +} diff --git a/lib/opmapcontrol/src/core/tilecachequeue.h b/lib/opmapcontrol/src/core/tilecachequeue.h new file mode 100644 index 0000000000000000000000000000000000000000..a0bf2b7e013f0ed93efc4e4c6c0822e55914b06c --- /dev/null +++ b/lib/opmapcontrol/src/core/tilecachequeue.h @@ -0,0 +1,59 @@ +/** +****************************************************************************** +* +* @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 +#include "cacheitemqueue.h" +#include +#include +#include +#include +#include +#include "pureimagecache.h" +#include "cache.h" + + +namespace core { + class TileCacheQueue:public QThread + { + Q_OBJECT + public: + TileCacheQueue(); + ~TileCacheQueue(); + void EnqueueCacheTask(CacheItemQueue *task); + + protected: + QQueue tileCacheQueue; + private: + void run(); + QMutex mutex; + QMutex waitmutex; + QWaitCondition waitc; + }; +} +#endif // TILECACHEQUEUE_H diff --git a/lib/opmapcontrol/src/core/urlfactory.cpp b/lib/opmapcontrol/src/core/urlfactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..77a971e4f5db6d684c0db94aee18b2b558229c53 --- /dev/null +++ b/lib/opmapcontrol/src/core/urlfactory.cpp @@ -0,0 +1,694 @@ +/** +****************************************************************************** +* +* @file urlfactory.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 "urlfactory.h" +#include + +namespace core { + + const double UrlFactory::EarthRadiusKm = 6378.137; // WGS-84 + + UrlFactory::UrlFactory() + { + /// + /// timeout for map connections + /// + + Proxy.setType(QNetworkProxy::NoProxy); + + /// + /// Gets or sets the value of the User-agent HTTP header. + /// + UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7"; + + Timeout = 5 * 1000; + CorrectGoogleVersions=true; + isCorrectedGoogleVersions = false; + UseGeocoderCache=true; + UsePlacemarkCache=true; + } + UrlFactory::~UrlFactory() + { + } + QString UrlFactory::TileXYToQuadKey(const int &tileX,const int &tileY,const int &levelOfDetail) const + { + QString quadKey; + for(int i = levelOfDetail; i > 0; i--) + { + char digit = '0'; + int mask = 1 << (i - 1); + if((tileX & mask) != 0) + { + digit++; + } + if((tileY & mask) != 0) + { + digit++; + digit++; + } + quadKey.append(digit); + } + return quadKey; + } + int UrlFactory::GetServerNum(const Point &pos,const int &max) const + { + return (pos.X() + 2 * pos.Y()) % max; + } + void UrlFactory::setIsCorrectGoogleVersions(bool value) + { + isCorrectedGoogleVersions=value; + + } + + bool UrlFactory::IsCorrectGoogleVersions() + { + return isCorrectedGoogleVersions; + } + + void UrlFactory::TryCorrectGoogleVersions() + { + if(CorrectGoogleVersions && !IsCorrectGoogleVersions()) + { + QNetworkReply *reply; + QNetworkRequest qheader; + QNetworkAccessManager network; + QEventLoop q; + 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_URLFACTORY + qDebug()<<"Correct GoogleVersion"; +#endif //DEBUG_URLFACTORY + setIsCorrectGoogleVersions(true); + QString url = "http://maps.google.com"; + + qheader.setUrl(QUrl(url)); + qheader.setRawHeader("User-Agent",UserAgent); + reply=network.get(qheader); + tT.start(Timeout); + q.exec(); + if(!tT.isActive()) + return; + tT.stop(); + if( (reply->error()!=QNetworkReply::NoError)) + { +#ifdef DEBUG_URLFACTORY + qDebug()<<"Try corrected version withou abort or error:"<errorString(); +#endif //DEBUG_URLFACTORY + return; + } + QString html=QString(reply->readAll()); + QRegExp reg("\"*http://mt0.google.com/vt/lyrs=m@(\\d*)",Qt::CaseInsensitive); + if(reg.indexIn(html)!=-1) + { + QStringList gc=reg.capturedTexts(); + VersionGoogleMap = QString("m@%1").arg(gc[1]); + VersionGoogleMapChina = VersionGoogleMap; +#ifdef DEBUG_URLFACTORY + qDebug()<<"TryCorrectGoogleVersions, VersionGoogleMap: "<deleteLater(); + + } + + } + + QString UrlFactory::MakeImageUrl(const MapType::Types &type,const Point &pos,const int &zoom,const QString &language) + { +#ifdef DEBUG_URLFACTORY + qDebug()<<"Entered MakeImageUrl"; +#endif //DEBUG_URLFACTORY + switch(type) + { + case MapType::GoogleMap: + { + QString server = "mt"; + QString request = "vt"; + QString sec1 = ""; // after &x=... + QString sec2 = ""; // after &zoom=... + GetSecGoogleWords(pos, sec1, sec2); + TryCorrectGoogleVersions(); + + return QString("http://%1%2.google.com/%3/lyrs=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleMap).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2); + } + break; + case MapType::GoogleSatellite: + { + QString server = "khm"; + QString request = "kh"; + QString sec1 = ""; // after &x=... + QString sec2 = ""; // after &zoom=... + GetSecGoogleWords(pos, sec1, sec2); + TryCorrectGoogleVersions(); + return QString("http://%1%2.google.com/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleSatellite).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2); + } + break; + case MapType::GoogleLabels: + { + QString server = "mt"; + QString request = "vt"; + QString sec1 = ""; // after &x=... + QString sec2 = ""; // after &zoom=... + GetSecGoogleWords(pos, sec1, sec2); + TryCorrectGoogleVersions(); + + return QString("http://%1%2.google.com/%3/lyrs=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleLabels).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2); + } + break; + case MapType::GoogleTerrain: + { + QString server = "mt"; + QString request = "vt"; + QString sec1 = ""; // after &x=... + QString sec2 = ""; // after &zoom=... + GetSecGoogleWords(pos, sec1, sec2); + TryCorrectGoogleVersions(); + return QString("http://%1%2.google.com/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleTerrain).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2); + } + break; + case MapType::GoogleMapChina: + { + QString server = "mt"; + QString request = "vt"; + QString sec1 = ""; // after &x=... + QString sec2 = ""; // after &zoom=... + GetSecGoogleWords(pos, sec1, sec2); + TryCorrectGoogleVersions(); + // http://mt0.google.cn/vt/v=w2.101&hl=zh-CN&gl=cn&x=12&y=6&z=4&s=Ga + + return QString("http://%1%2.google.cn/%3/lyrs=%4&hl=%5&gl=cn&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleMapChina).arg("zh-CN").arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2); + } + break; + case MapType::GoogleSatelliteChina: + { + QString server = "mt"; + QString request = "vt"; + QString sec1 = ""; // after &x=... + QString sec2 = ""; // after &zoom=... + GetSecGoogleWords(pos, sec1, sec2); + // TryCorrectGoogleVersions(); + // http://khm0.google.cn/kh/v=46&x=12&y=6&z=4&s=Ga + + return QString("http://%1%2.google.cn/%3/lyrs=%4&gl=cn&x=%5%6&y=%7&z=%8&s=%9").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleSatelliteChina).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2); + } + break; + case MapType::GoogleLabelsChina: + { + QString server = "mt"; + QString request = "vt"; + QString sec1 = ""; // after &x=... + QString sec2 = ""; // after &zoom=... + GetSecGoogleWords(pos, sec1, sec2); + TryCorrectGoogleVersions(); + // http://mt0.google.cn/vt/v=w2t.110&hl=zh-CN&gl=cn&x=12&y=6&z=4&s=Ga + + return QString("http://%1%2.google.cn/%3/imgtp=png32&lyrs=%4&hl=%5&gl=cn&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleLabelsChina).arg("zh-CN").arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2); + } + break; + case MapType::GoogleTerrainChina: + { + QString server = "mt"; + QString request = "vt"; + QString sec1 = ""; // after &x=... + QString sec2 = ""; // after &zoom=... + GetSecGoogleWords(pos, sec1, sec2); + TryCorrectGoogleVersions(); + // http://mt0.google.cn/vt/v=w2p.110&hl=zh-CN&gl=cn&x=12&y=6&z=4&s=Ga + + return QString("http://%1%2.google.com/%3/lyrs=%4&hl=%5&gl=cn&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleTerrainChina).arg("zh-CN").arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2); + } + break; + case MapType::GoogleMapKorea: + { + QString server = "mt"; + QString request = "mt"; + QString sec1 = ""; // after &x=... + QString sec2 = ""; // after &zoom=... + GetSecGoogleWords(pos, sec1, sec2); + + //http://mt3.gmaptiles.co.kr/mt/v=kr1.11&hl=lt&x=109&y=49&z=7&s= + + QString ret = QString("http://%1%2.gmaptiles.co.kr/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleMapKorea).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2); + return ret; + } + break; + case MapType::GoogleSatelliteKorea: + { + QString server = "khm"; + QString request = "kh"; + QString sec1 = ""; // after &x=... + QString sec2 = ""; // after &zoom=... + GetSecGoogleWords(pos, sec1, sec2); + + // http://khm1.google.co.kr/kh/v=54&x=109&y=49&z=7&s= + + return QString("http://%1%2.google.co.kr/%3/v=%4&x=%5%6&y=%7&z=%8&s=%9").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleSatelliteKorea).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2); + } + break; + case MapType::GoogleLabelsKorea: + { + QString server = "mt"; + QString request = "mt"; + QString sec1 = ""; // after &x=... + QString sec2 = ""; // after &zoom=... + GetSecGoogleWords(pos, sec1, sec2); + + // http://mt1.gmaptiles.co.kr/mt/v=kr1t.11&hl=lt&x=109&y=50&z=7&s=G + + return QString("http://%1%2.gmaptiles.co.kr/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleLabelsKorea).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2); + } + break; + case MapType::YahooMap: + { + return QString("http://maps%1.yimg.com/hx/tl?v=%2&.intl=%3&x=%4&y=%5&z=%6&r=1").arg(((GetServerNum(pos, 2)) + 1)).arg(VersionYahooMap).arg(language).arg(pos.X()).arg((((1 << zoom) >> 1) - 1 - pos.Y())).arg((zoom + 1)); + } + + case MapType::YahooSatellite: + { + return QString("http://maps%1.yimg.com/ae/ximg?v=%2&t=a&s=256&.intl=%3&x=%4&y=%5&z=%6&r=1").arg("3").arg(VersionYahooSatellite).arg(language).arg(pos.X()).arg(((1 << zoom) >> 1) - 1 - pos.Y()).arg(zoom + 1); + } + break; + case MapType::YahooLabels: + { + return QString("http://maps%1.yimg.com/hx/tl?v=%2&t=h&.intl=%3&x=%4&y=%5&z=%6&r=1").arg("1").arg(VersionYahooLabels).arg(language).arg(pos.X()).arg(((1 << zoom) >> 1) - 1 - pos.Y()).arg(zoom + 1); + } + break; + case MapType::OpenStreetMap: + { + char letter= "abc"[GetServerNum(pos, 3)]; + return QString("http://%1.tile.openstreetmap.org/%2/%3/%4.png").arg(letter).arg(zoom).arg(pos.X()).arg(pos.Y()); + } + break; + case MapType::OpenStreetOsm: + { + char letter = "abc"[GetServerNum(pos, 3)]; + return QString("http://%1.tah.openstreetmap.org/Tiles/tile/%2/%3/%4.png").arg(letter).arg(zoom).arg(pos.X()).arg(pos.Y()); + } + break; + case MapType::OpenStreetMapSurfer: + { + // http://tiles1.mapsurfer.net/tms_r.ashx?x=37378&y=20826&z=16 + + return QString("http://tiles1.mapsurfer.net/tms_r.ashx?x=%1&y=%2&z=%3").arg(pos.X()).arg(pos.Y()).arg(zoom); + } + break; + case MapType::OpenStreetMapSurferTerrain: + { + // http://tiles2.mapsurfer.net/tms_t.ashx?x=9346&y=5209&z=14 + + return QString("http://tiles2.mapsurfer.net/tms_t.ashx?x=%1&y=%2&z=%3").arg(pos.X()).arg(pos.Y()).arg(zoom); + } + break; + case MapType::BingMap: + { + QString key = TileXYToQuadKey(pos.X(), pos.Y(), zoom); + return QString("http://ecn.t%1.tiles.virtualearth.net/tiles/r%2.png?g=%3&mkt=%4%5").arg(GetServerNum(pos, 4)).arg(key).arg(VersionBingMaps).arg(language).arg(!(BingMapsClientToken.isNull()|BingMapsClientToken.isEmpty()) ? "&token=" + BingMapsClientToken : QString("")); + } + break; + case MapType::BingSatellite: + { + QString key = TileXYToQuadKey(pos.X(), pos.Y(), zoom); + return QString("http://ecn.t%1.tiles.virtualearth.net/tiles/a%2.jpeg?g=%3&mkt=%4%5").arg(GetServerNum(pos, 4)).arg(key).arg(VersionBingMaps).arg(language).arg(!(BingMapsClientToken.isNull()|BingMapsClientToken.isEmpty()) ? "&token=" + BingMapsClientToken : QString("")); + } + break; + case MapType::BingHybrid: + { + QString key = TileXYToQuadKey(pos.X(), pos.Y(), zoom); + return QString("http://ecn.t%1.tiles.virtualearth.net/tiles/h%2.jpeg?g=%3&mkt=%4%5").arg(GetServerNum(pos, 4)).arg(key).arg(VersionBingMaps).arg(language).arg(!(BingMapsClientToken.isNull()|BingMapsClientToken.isEmpty()) ? "&token=" + BingMapsClientToken : QString("")); + } + + case MapType::ArcGIS_Map: + { + // http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer/tile/0/0/0.jpg + + return QString("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer/tile/%1/%2/%3").arg(zoom).arg(pos.Y()).arg(pos.X()); + } + break; + case MapType::ArcGIS_Satellite: + { + // http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer/tile/1/0/1.jpg + + return QString("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer/tile/%1/%2/%3").arg(zoom).arg(pos.Y()).arg(pos.X()); + } + break; + case MapType::ArcGIS_ShadedRelief: + { + // http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_ShadedRelief_World_2D/MapServer/tile/1/0/1.jpg + + return QString("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_ShadedRelief_World_2D/MapServer/tile/%1/%2/%3").arg(zoom).arg(pos.Y()).arg(pos.X()); + } + break; + case MapType::ArcGIS_Terrain: + { + // http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer/tile/4/3/15 + + return QString("http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer/tile/%1/%2/%3").arg(zoom).arg(pos.Y()).arg(pos.X()); + } + break; + case MapType::ArcGIS_MapsLT_OrtoFoto: + { + // http://www.maps.lt/ortofoto/mapslt_ortofoto_vector_512/map/_alllayers/L02/R0000001b/C00000028.jpg + // http://arcgis.maps.lt/ArcGIS/rest/services/mapslt_ortofoto/MapServer/tile/0/9/13 + // return string.Format("http://www.maps.lt/ortofoto/mapslt_ortofoto_vector_512/map/_alllayers/L{0:00}/R{1:x8}/C{2:x8}.jpg", zoom, pos.Y(), pos.X()); + // http://dc1.maps.lt/cache/mapslt_ortofoto_512/map/_alllayers/L03/R0000001c/C00000029.jpg + // return string.Format("http://arcgis.maps.lt/ArcGIS/rest/services/mapslt_ortofoto/MapServer/tile/{0}/{1}/{2}", zoom, pos.Y(), pos.X()); + // http://dc1.maps.lt/cache/mapslt_ortofoto_512/map/_alllayers/L03/R0000001d/C0000002a.jpg + //TODO verificar + return QString("http://dc1.maps.lt/cache/mapslt_ortofoto/map/_alllayers/L%1/R%2/C%3.jpg").arg(zoom,2,10,(QChar)'0').arg(pos.Y(),8,16,(QChar)'0').arg(pos.X(),8,16,(QChar)'0'); + } + break; + case MapType::ArcGIS_MapsLT_Map: + { + // http://www.maps.lt/ortofoto/mapslt_ortofoto_vector_512/map/_alllayers/L02/R0000001b/C00000028.jpg + // http://arcgis.maps.lt/ArcGIS/rest/services/mapslt_ortofoto/MapServer/tile/0/9/13 + // return string.Format("http://www.maps.lt/ortofoto/mapslt_ortofoto_vector_512/map/_alllayers/L{0:00}/R{1:x8}/C{2:x8}.jpg", zoom, pos.Y(), pos.X()); + // http://arcgis.maps.lt/ArcGIS/rest/services/mapslt/MapServer/tile/7/1162/1684.png + // http://dc1.maps.lt/cache/mapslt_512/map/_alllayers/L03/R0000001b/C00000029.png + //TODO verificar + // http://dc1.maps.lt/cache/mapslt/map/_alllayers/L02/R0000001c/C00000029.png + return QString("http://dc1.maps.lt/cache/mapslt/map/_alllayers/L%1/R%2/C%3.png").arg(zoom,2,10,(QChar)'0').arg(pos.Y(),8,16,(QChar)'0').arg(pos.X(),8,16,(QChar)'0'); + } + break; + case MapType::ArcGIS_MapsLT_Map_Labels: + { + //http://arcgis.maps.lt/ArcGIS/rest/services/mapslt_ortofoto_overlay/MapServer/tile/0/9/13 + //return string.Format("http://arcgis.maps.lt/ArcGIS/rest/services/mapslt_ortofoto_overlay/MapServer/tile/{0}/{1}/{2}", zoom, pos.Y(), pos.X()); + //http://dc1.maps.lt/cache/mapslt_ortofoto_overlay_512/map/_alllayers/L03/R0000001d/C00000029.png + //TODO verificar + return QString("http://dc1.maps.lt/cache/mapslt_ortofoto_overlay/map/_alllayers/L%1/R%2/C%3.png").arg(zoom,2,10,(QChar)'0').arg(pos.Y(),8,16,(QChar)'0').arg(pos.X(),8,16,(QChar)'0'); + } + break; + case MapType::PergoTurkeyMap: + { + // http://{domain}/{layerName}/{zoomLevel}/{first3LetterOfTileX}/{second3LetterOfTileX}/{third3LetterOfTileX}/{first3LetterOfTileY}/{second3LetterOfTileY}/{third3LetterOfTileXY}.png + + // http://map3.pergo.com.tr/tile/00/000/000/001/000/000/000.png + // That means: Zoom Level: 0 TileX: 1 TileY: 0 + + // http://domain/tile/14/000/019/371/000/011/825.png + // That means: Zoom Level: 14 TileX: 19371 TileY:11825 + + // string x = pos.X().ToString("000000000").Insert(3, "/").Insert(7, "/"); // - 000/000/001 + // string y = pos.Y().ToString("000000000").Insert(3, "/").Insert(7, "/"); // - 000/000/000 + QString x=QString("%1").arg(QString::number(pos.X()),9,(QChar)'0'); + x.insert(3,"/").insert(7,"/"); + QString y=QString("%1").arg(QString::number(pos.Y()),9,(QChar)'0'); + y.insert(3,"/").insert(7,"/"); + //"http://map03.pergo.com.tr/tile/2/000/000/003/000/000/002.png" + return QString("http://map%1.pergo.com.tr/tile/%2/%3/%4.png").arg(GetServerNum(pos, 4)).arg(zoom,2,10,(QChar)'0').arg(x).arg(y); + } + break; + case MapType::SigPacSpainMap: + { + return QString("http://sigpac.mapa.es/kmlserver/raster/%1@3785/%2.%3.%4.img").arg(levelsForSigPacSpainMap[zoom]).arg(zoom).arg(pos.X()).arg((2 << (zoom - 1)) - pos.Y() - 1); + } + break; + + case MapType::YandexMapRu: + { + QString server = "vec"; + + //http://vec01.maps.yandex.ru/tiles?l=map&v=2.10.2&x=1494&y=650&z=11 + + return QString("http://%1").arg(server)+QString("0%2.maps.yandex.ru/tiles?l=map&v=%3&x=%4&y=%5&z=%6").arg(GetServerNum(pos, 4)+1).arg(VersionYandexMap).arg(pos.X()).arg(pos.Y()).arg(zoom); + } + break; + default: + break; + } + + return QString::null; + } + void UrlFactory::GetSecGoogleWords(const Point &pos, QString &sec1, QString &sec2) + { + sec1 = ""; // after &x=... + sec2 = ""; // after &zoom=... + int seclen = ((pos.X() * 3) + pos.Y()) % 8; + sec2 = SecGoogleWord.left(seclen); + if(pos.Y() >= 10000 && pos.Y() < 100000) + { + sec1 = "&s="; + } + } + QString UrlFactory::MakeGeocoderUrl(QString keywords) + { + QString key = keywords.replace(' ', '+'); + return QString("http://maps.google.com/maps/geo?q=%1&output=csv&key=%2").arg(key).arg(GoogleMapsAPIKey); + } + QString UrlFactory::MakeReverseGeocoderUrl(internals::PointLatLng &pt,const QString &language) + { + + return QString("http://maps.google.com/maps/geo?hl=%1&ll=%2,%3&output=csv&key=%4").arg(language).arg(QString::number(pt.Lat())).arg(QString::number(pt.Lng())).arg(GoogleMapsAPIKey); + + } + internals::PointLatLng UrlFactory::GetLatLngFromGeodecoder(const QString &keywords, GeoCoderStatusCode::Types &status) + { + return GetLatLngFromGeocoderUrl(MakeGeocoderUrl(keywords),UseGeocoderCache,status); + } + internals::PointLatLng UrlFactory::GetLatLngFromGeocoderUrl(const QString &url, const bool &useCache, GeoCoderStatusCode::Types &status) + { +#ifdef DEBUG_URLFACTORY + qDebug()<<"Entered GetLatLngFromGeocoderUrl:"; +#endif //DEBUG_URLFACTORY + status = GeoCoderStatusCode::Unknow; + internals::PointLatLng ret(0,0); + QString urlEnd = url.mid(url.indexOf("geo?q=")+6); + urlEnd.replace( QRegExp( + "[^" + "A-Z,a-z,0-9," + "\\^,\\&,\\',\\@," + "\\{,\\},\\[,\\]," + "\\,,\\$,\\=,\\!," + "\\-,\\#,\\(,\\)," + "\\%,\\.,\\+,\\~,\\_" + "]"), "_" ); + + QString geo = useCache ? Cache::Instance()->GetGeocoderFromCache(urlEnd) : ""; + + if(geo.isNull()|geo.isEmpty()) + { +#ifdef DEBUG_URLFACTORY + qDebug()<<"GetLatLngFromGeocoderUrl:Not in cache going internet"; +#endif //DEBUG_URLFACTORY + QNetworkReply *reply; + QNetworkRequest qheader; + QNetworkAccessManager network; + network.setProxy(Proxy); + qheader.setUrl(QUrl(url)); + qheader.setRawHeader("User-Agent",UserAgent); + reply=network.get(qheader); +#ifdef DEBUG_URLFACTORY + qDebug()<<"GetLatLngFromGeocoderUrl:URL="<isFinished()) || (time.elapsed()>(6*Timeout))) ){QCoreApplication::processEvents(QEventLoop::AllEvents);} +#ifdef DEBUG_URLFACTORY + qDebug()<<"Finished?"<error()<<" abort?"<<(time.elapsed()>Timeout*6); +#endif //DEBUG_URLFACTORY + if( (reply->error()!=QNetworkReply::NoError) | (time.elapsed()>Timeout*6)) + { +#ifdef DEBUG_URLFACTORY + qDebug()<<"GetLatLngFromGeocoderUrl::Network error"; +#endif //DEBUG_URLFACTORY + return internals::PointLatLng(0,0); + } + { +#ifdef DEBUG_URLFACTORY + qDebug()<<"GetLatLngFromGeocoderUrl:Reply ok"; +#endif //DEBUG_URLFACTORY + geo=reply->readAll(); + + + // cache geocoding + if(useCache && geo.startsWith("200")) + { + Cache::Instance()->CacheGeocoder(urlEnd, geo); + } + } + reply->deleteLater(); + } + + + // parse values + // true : 200,4,56.1451640,22.0681787 + // false: 602,0,0,0 + { + QStringList values = geo.split(','); + if(values.count() == 4) + { + status = (GeoCoderStatusCode::Types) QString(values[0]).toInt(); + if(status == GeoCoderStatusCode::G_GEO_SUCCESS) + { + double lat = QString(values[2]).toDouble(); + double lng = QString(values[3]).toDouble(); + + ret = internals::PointLatLng(lat, lng); +#ifdef DEBUG_URLFACTORY + qDebug()<<"Lat="<GetPlacemarkFromCache(urlEnd) : ""; + + if(reverse.isNull()|reverse.isEmpty()) + { +#ifdef DEBUG_URLFACTORY + qDebug()<<"GetLatLngFromGeocoderUrl:Not in cache going internet"; +#endif //DEBUG_URLFACTORY + QNetworkReply *reply; + QNetworkRequest qheader; + QNetworkAccessManager network; + network.setProxy(Proxy); + qheader.setUrl(QUrl(url)); + qheader.setRawHeader("User-Agent",UserAgent); + reply=network.get(qheader); +#ifdef DEBUG_URLFACTORY + qDebug()<<"GetLatLngFromGeocoderUrl:URL="<isFinished()) || (time.elapsed()>(6*Timeout))) ){QCoreApplication::processEvents(QEventLoop::AllEvents);} +#ifdef DEBUG_URLFACTORY + qDebug()<<"Finished?"<error()<<" abort?"<<(time.elapsed()>Timeout*6); +#endif //DEBUG_URLFACTORY + if( (reply->error()!=QNetworkReply::NoError) | (time.elapsed()>Timeout*6)) + { +#ifdef DEBUG_URLFACTORY + qDebug()<<"GetLatLngFromGeocoderUrl::Network error"; +#endif //DEBUG_URLFACTORY + return ret; + } + { +#ifdef DEBUG_URLFACTORY + qDebug()<<"GetLatLngFromGeocoderUrl:Reply ok"; +#endif //DEBUG_URLFACTORY + QByteArray a=(reply->readAll()); + QTextCodec *codec = QTextCodec::codecForName("UTF-8"); + reverse = codec->toUnicode(a); +#ifdef DEBUG_URLFACTORY + qDebug()<CachePlacemark(urlEnd, reverse); + } + } + reply->deleteLater(); + } + + + // parse values + // true : 200,4,56.1451640,22.0681787 + // false: 602,0,0,0 + if(reverse.startsWith("200")) + { + QString acc = reverse.left(reverse.indexOf('\"')); + ret = Placemark(reverse.remove(reverse.indexOf('\"'))); + ret.SetAccuracy ((int) (( (QString) acc.split(',')[1]).toInt()) ); + + } + return ret; + } + double UrlFactory::GetDistance(internals::PointLatLng p1, internals::PointLatLng p2) + { + double dLat1InRad = p1.Lat() * (M_PI / 180); + double dLong1InRad = p1.Lng() * (M_PI / 180); + double dLat2InRad = p2.Lat() * (M_PI / 180); + double dLong2InRad = p2.Lng() * (M_PI / 180); + double dLongitude = dLong2InRad - dLong1InRad; + double dLatitude = dLat2InRad - dLat1InRad; + double a = pow(sin(dLatitude / 2), 2) + cos(dLat1InRad) * cos(dLat2InRad) * pow(sin(dLongitude / 2), 2); + double c = 2 * atan2(sqrt(a), sqrt(1 - a)); + double dDistance = EarthRadiusKm * c; + return dDistance; + } +} diff --git a/lib/opmapcontrol/src/core/urlfactory.h b/lib/opmapcontrol/src/core/urlfactory.h new file mode 100644 index 0000000000000000000000000000000000000000..e886a5410e4e6f50dd370b8e369c0ca73f234173 --- /dev/null +++ b/lib/opmapcontrol/src/core/urlfactory.h @@ -0,0 +1,87 @@ +/** +****************************************************************************** +* +* @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 +#include +#include +#include +#include +#include +#include +#include "providerstrings.h" +#include "pureimagecache.h" +#include "../internals/pointlatlng.h" +#include "geodecoderstatus.h" +#include +#include "cache.h" +#include "placemark.h" +#include +#include "cmath" + +namespace core { + class UrlFactory: public QObject,public ProviderStrings + { + Q_OBJECT + public: + /// + /// Gets or sets the value of the User-agent HTTP header. + /// + 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 diff --git a/lib/opmapcontrol/src/internals/MouseWheelZoomType.cpp b/lib/opmapcontrol/src/internals/MouseWheelZoomType.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d36691145036a897efd512477215a5c8170870f3 --- /dev/null +++ b/lib/opmapcontrol/src/internals/MouseWheelZoomType.cpp @@ -0,0 +1,32 @@ +/** +****************************************************************************** +* +* @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 { + +} diff --git a/lib/opmapcontrol/src/internals/copyrightstrings.h b/lib/opmapcontrol/src/internals/copyrightstrings.h new file mode 100644 index 0000000000000000000000000000000000000000..6115297d6882cf5155e66a7df6c791f1611b06f6 --- /dev/null +++ b/lib/opmapcontrol/src/internals/copyrightstrings.h @@ -0,0 +1,41 @@ +/** +****************************************************************************** +* +* @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 +#include + +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 diff --git a/lib/opmapcontrol/src/internals/core.cpp b/lib/opmapcontrol/src/internals/core.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8a3fafc05942bde0565e7669e765c6b60c0c771d --- /dev/null +++ b/lib/opmapcontrol/src/internals/core.cpp @@ -0,0 +1,695 @@ +/** +****************************************************************************** +* +* @file core.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 "core.h" + +#ifdef DEBUG_CORE +qlonglong internals::Core::debugcounter=0; +#endif + +using namespace projections; + +namespace internals { + Core::Core():MouseWheelZooming(false),currentPosition(0,0),currentPositionPixel(0,0),LastLocationInBounds(-1,-1),sizeOfMapArea(0,0) + ,minOfTiles(0,0),maxOfTiles(0,0),zoom(0),isDragging(false),TooltipTextPadding(10,10),loaderLimit(5),maxzoom(21),started(false),runningThreads(0) + { + mousewheelzoomtype=MouseWheelZoomType::MousePositionAndCenter; + SetProjection(new MercatorProjection()); + this->setAutoDelete(false); + ProcessLoadTaskCallback.setMaxThreadCount(10); + renderOffset=Point(0,0); + dragPoint=Point(0,0); + CanDragMap=true; + tilesToload=0; + OPMaps::Instance(); + } + Core::~Core() + { + ProcessLoadTaskCallback.waitForDone(); + } + + void Core::run() + { + MrunningThreads.lock(); + ++runningThreads; + MrunningThreads.unlock(); +#ifdef DEBUG_CORE + qlonglong debug; + Mdebug.lock(); + debug=++debugcounter; + Mdebug.unlock(); + qDebug()<<"core:run"<<" ID="< 0) + { + task = tileLoadQueue.dequeue(); + { + + last = (tileLoadQueue.count() == 0); +#ifdef DEBUG_CORE + qDebug()<<"TileLoadQueue: " << tileLoadQueue.count()<<" Point:"<GetPos().ToString()<<" now has "<Overlays.count()<<" overlays"<<" ID="<RetryLoadTile > 0) + { +#ifdef DEBUG_CORE + qDebug()<<"ProcessLoadTask: " << task.ToString()<< " -> empty tile, retry " << retry<<" ID="<RetryLoadTile); + } + + if(t->Overlays.count() > 0) + { + Matrix.SetTileAt(task.Pos,t); + emit OnNeedInvalidation(); + +#ifdef DEBUG_CORE + qDebug()<<"Core::run add tile "<GetPos().ToString()<<" to matrix index "<Overlays.count()<<" ID="<kiberCacheLock.lockForWrite(); + OPMaps::Instance()->TilesInMemory.RemoveMemoryOverload(); + OPMaps::Instance()->kiberCacheLock.unlock(); + + MtileDrawingList.lock(); + { + Matrix.ClearPointsNotIn(tileDrawingList); + } + MtileDrawingList.unlock(); + + + emit OnTileLoadComplete(); + + + emit OnNeedInvalidation(); + + } + } + + + + } +#ifdef DEBUG_CORE + qDebug()<<"loaderLimit release:"+loaderLimit.available()<<" ID="<GetDiagnostics(); + diag.runningThreads=runningThreads; + MrunningThreads.unlock(); + return diag; + } + + void Core::SetZoom(const int &value) + { + if (!isDragging) + { + zoom=value; + minOfTiles=Projection()->GetTileMatrixMinXY(value); + maxOfTiles=Projection()->GetTileMatrixMaxXY(value); + currentPositionPixel=Projection()->FromLatLngToPixel(currentPosition,value); + if(started) + { + MtileLoadQueue.lock(); + tileLoadQueue.clear(); + MtileLoadQueue.unlock(); + MtileToload.lock(); + tilesToload=0; + MtileToload.unlock(); + Matrix.Clear(); + GoToCurrentPositionOnZoom(); + UpdateBounds(); + emit OnMapDrag(); + emit OnMapZoomChanged(); + emit OnNeedInvalidation(); + } + } + } + + void Core::SetCurrentPosition(const PointLatLng &value) + { + if(!IsDragging()) + { + currentPosition = value; + SetCurrentPositionGPixel(Projection()->FromLatLngToPixel(value, Zoom())); + + if(started) + { + GoToCurrentPosition(); + emit OnCurrentPositionChanged(currentPosition); + } + } + else + { + currentPosition = value; + SetCurrentPositionGPixel(Projection()->FromLatLngToPixel(value, Zoom())); + + if(started) + { + emit OnCurrentPositionChanged(currentPosition); + } + } + } + void Core::SetMapType(const MapType::Types &value) + { + + if(value != GetMapType()) + { + mapType = value; + + switch(value) + { + + + case MapType::ArcGIS_Map: + case MapType::ArcGIS_Satellite: + case MapType::ArcGIS_ShadedRelief: + case MapType::ArcGIS_Terrain: + { + if(Projection()->Type()!="PlateCarreeProjection") + { + SetProjection(new PlateCarreeProjection()); + maxzoom=13; + } + } + break; + + case MapType::ArcGIS_MapsLT_Map_Hybrid: + case MapType::ArcGIS_MapsLT_Map_Labels: + case MapType::ArcGIS_MapsLT_Map: + case MapType::ArcGIS_MapsLT_OrtoFoto: + { + if(Projection()->Type()!="LKS94Projection") + { + SetProjection(new LKS94Projection()); + maxzoom=11; + } + } + break; + + case MapType::PergoTurkeyMap: + { + if(Projection()->Type()!="PlateCarreeProjectionPergo") + { + SetProjection(new PlateCarreeProjectionPergo()); + maxzoom=17; + } + } + break; + + case MapType::YandexMapRu: + { + if(Projection()->Type()!="MercatorProjectionYandex") + { + SetProjection(new MercatorProjectionYandex()); + maxzoom=13; + } + } + break; + + default: + { + if(Projection()->Type()!="MercatorProjection") + { + SetProjection(new MercatorProjection()); + maxzoom=21; + } + } + break; + } + + minOfTiles = Projection()->GetTileMatrixMinXY(Zoom()); + maxOfTiles = Projection()->GetTileMatrixMaxXY(Zoom()); + SetCurrentPositionGPixel(Projection()->FromLatLngToPixel(CurrentPosition(), Zoom())); + + if(started) + { + CancelAsyncTasks(); + OnMapSizeChanged(Width, Height); + GoToCurrentPosition(); + ReloadMap(); + GoToCurrentPosition(); + emit OnMapTypeChanged(value); + + } + } + + } + void Core::StartSystem() + { + if(!started) + { + started = true; + + ReloadMap(); + GoToCurrentPosition(); + } + } + + void Core::UpdateCenterTileXYLocation() + { + PointLatLng center = FromLocalToLatLng(Width/2, Height/2); + Point centerPixel = Projection()->FromLatLngToPixel(center, Zoom()); + centerTileXYLocation = Projection()->FromPixelToTileXY(centerPixel); + } + + void Core::OnMapSizeChanged(int const& width, int const& height) + { + Width = width; + Height = height; + + sizeOfMapArea.SetWidth(1 + (Width/Projection()->TileSize().Width())/2); + sizeOfMapArea.SetHeight(1 + (Height/Projection()->TileSize().Height())/2); + + UpdateCenterTileXYLocation(); + + if(started) + { + UpdateBounds(); + + emit OnCurrentPositionChanged(currentPosition); + } + } + void Core::OnMapClose() + { + // if(waitOnEmptyTasks != null) + // { + // try + // { + // waitOnEmptyTasks.Set(); + // waitOnEmptyTasks.Close(); + // } + // catch + // { + // } + // } + + CancelAsyncTasks(); + } + GeoCoderStatusCode::Types Core::SetCurrentPositionByKeywords(QString const& keys) + { + GeoCoderStatusCode::Types status = GeoCoderStatusCode::Unknow; + PointLatLng pos = OPMaps::Instance()->GetLatLngFromGeodecoder(keys, status); + if(!pos.IsEmpty() && (status == GeoCoderStatusCode::G_GEO_SUCCESS)) + { + SetCurrentPosition(pos); + } + + return status; + } + RectLatLng Core::CurrentViewArea() + { + PointLatLng p = Projection()->FromPixelToLatLng(-renderOffset.X(), -renderOffset.Y(), Zoom()); + double rlng = Projection()->FromPixelToLatLng(-renderOffset.X() + Width, -renderOffset.Y(), Zoom()).Lng(); + double blat = Projection()->FromPixelToLatLng(-renderOffset.X(), -renderOffset.Y() + Height, Zoom()).Lat(); + return RectLatLng::FromLTRB(p.Lng(), p.Lat(), rlng, blat); + + } + PointLatLng Core::FromLocalToLatLng(int const& x, int const& y) + { + return Projection()->FromPixelToLatLng(Point(x - renderOffset.X(), y - renderOffset.Y()), Zoom()); + } + + + Point Core::FromLatLngToLocal(PointLatLng const& latlng) + { + Point pLocal = Projection()->FromLatLngToPixel(latlng, Zoom()); + pLocal.Offset(renderOffset); + return pLocal; + } + int Core::GetMaxZoomToFitRect(RectLatLng const& rect) + { + int zoom = 0; + + for(int i = 1; i <= MaxZoom(); i++) + { + Point p1 = Projection()->FromLatLngToPixel(rect.LocationTopLeft(), i); + Point p2 = Projection()->FromLatLngToPixel(rect.Bottom(), rect.Right(), i); + + if(((p2.X() - p1.X()) <= Width+10) && (p2.Y() - p1.Y()) <= Height+10) + { + zoom = i; + } + else + { + break; + } + } + + return zoom; + } + void Core::BeginDrag(Point const& pt) + { + dragPoint.SetX(pt.X() - renderOffset.X()); + dragPoint.SetY(pt.Y() - renderOffset.Y()); + isDragging = true; + } + void Core::EndDrag() + { + isDragging = false; + emit OnNeedInvalidation(); + + } + void Core::ReloadMap() + { + if(started) + { +#ifdef DEBUG_CORE + qDebug()<<"------------------"; +#endif //DEBUG_CORE + + MtileLoadQueue.lock(); + { + tileLoadQueue.clear(); + } + MtileLoadQueue.unlock(); + MtileToload.lock(); + tilesToload=0; + MtileToload.unlock(); + Matrix.Clear(); + + emit OnNeedInvalidation(); + + } + } + void Core::GoToCurrentPosition() + { + // reset stuff + renderOffset = Point::Empty; + centerTileXYLocationLast = Point::Empty; + dragPoint = Point::Empty; + + // goto location + Drag(Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2))); + } + void Core::GoToCurrentPositionOnZoom() + { + // reset stuff + renderOffset = Point::Empty; + centerTileXYLocationLast = Point::Empty; + dragPoint = Point::Empty; + + // goto location and centering + if(MouseWheelZooming) + { + if(mousewheelzoomtype != MouseWheelZoomType::MousePositionWithoutCenter) + { + Point pt = Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2)); + renderOffset.SetX(pt.X() - dragPoint.X()); + renderOffset.SetY(pt.Y() - dragPoint.Y()); + } + else // without centering + { + renderOffset.SetX(-GetcurrentPositionGPixel().X() - dragPoint.X()); + renderOffset.SetY(-GetcurrentPositionGPixel().Y() - dragPoint.Y()); + renderOffset.Offset(mouseLastZoom); + } + } + else // use current map center + { + mouseLastZoom = Point::Empty; + + Point pt = Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2)); + renderOffset.SetX(pt.X() - dragPoint.X()); + renderOffset.SetY(pt.Y() - dragPoint.Y()); + } + + UpdateCenterTileXYLocation(); + } + void Core::DragOffset(Point const& offset) + { + renderOffset.Offset(offset); + + UpdateCenterTileXYLocation(); + + if(centerTileXYLocation != centerTileXYLocationLast) + { + centerTileXYLocationLast = centerTileXYLocation; + UpdateBounds(); + } + + { + LastLocationInBounds = CurrentPosition(); + SetCurrentPosition (FromLocalToLatLng((int) Width/2, (int) Height/2)); + } + + emit OnNeedInvalidation(); + emit OnMapDrag(); + } + void Core::Drag(Point const& pt) + { + renderOffset.SetX(pt.X() - dragPoint.X()); + renderOffset.SetY(pt.Y() - dragPoint.Y()); + + UpdateCenterTileXYLocation(); + + if(centerTileXYLocation != centerTileXYLocationLast) + { + centerTileXYLocationLast = centerTileXYLocation; + UpdateBounds(); + } + + if(IsDragging()) + { + LastLocationInBounds = CurrentPosition(); + SetCurrentPosition(FromLocalToLatLng((int) Width/2, (int) Height/2)); + } + + emit OnNeedInvalidation(); + + + emit OnMapDrag(); + + } + void Core::CancelAsyncTasks() + { + if(started) + { + ProcessLoadTaskCallback.waitForDone(); + MtileLoadQueue.lock(); + { + tileLoadQueue.clear(); + //tilesToload=0; + } + MtileLoadQueue.unlock(); + MtileToload.lock(); + tilesToload=0; + MtileToload.unlock(); + // ProcessLoadTaskCallback.waitForDone(); + } + } + void Core::UpdateBounds() + { + MtileDrawingList.lock(); + { + FindTilesAround(tileDrawingList); + +#ifdef DEBUG_CORE + qDebug()<<"OnTileLoadStart: " << tileDrawingList.count() << " tiles to load at zoom " << Zoom() << ", time: " << QDateTime::currentDateTime().date(); +#endif //DEBUG_CORE + + emit OnTileLoadStart(); + + + foreach(Point p,tileDrawingList) + { + LoadTask task = LoadTask(p, Zoom()); + { + MtileLoadQueue.lock(); + { + if(!tileLoadQueue.contains(task)) + { + MtileToload.lock(); + ++tilesToload; + MtileToload.unlock(); + tileLoadQueue.enqueue(task); +#ifdef DEBUG_CORE + qDebug()<<"Core::UpdateBounds new Task"< &list) + { + list.clear();; + for(int i = -sizeOfMapArea.Width(); i <= sizeOfMapArea.Width(); i++) + { + for(int j = -sizeOfMapArea.Height(); j <= sizeOfMapArea.Height(); j++) + { + Point p = centerTileXYLocation; + p.SetX(p.X() + i); + p.SetY(p.Y() + j); + + //if(p.X < minOfTiles.Width) + //{ + // p.X += (maxOfTiles.Width + 1); + //} + + //if(p.X > maxOfTiles.Width) + //{ + // p.X -= (maxOfTiles.Width + 1); + //} + + if(p.X() >= minOfTiles.Width() && p.Y() >= minOfTiles.Height() && p.X() <= maxOfTiles.Width() && p.Y() <= maxOfTiles.Height()) + { + if(!list.contains(p)) + { + list.append(p); + } + } + } + } + + + } + void Core::UpdateGroundResolution() + { + double rez = Projection()->GetGroundResolution(Zoom(), CurrentPosition().Lat()); + pxRes100m = (int) (100.0 / rez); // 100 meters + pxRes1000m = (int) (1000.0 / rez); // 1km + pxRes10km = (int) (10000.0 / rez); // 10km + pxRes100km = (int) (100000.0 / rez); // 100km + pxRes1000km = (int) (1000000.0 / rez); // 1000km + pxRes5000km = (int) (5000000.0 / rez); // 5000km + } +} diff --git a/lib/opmapcontrol/src/internals/core.h b/lib/opmapcontrol/src/internals/core.h new file mode 100644 index 0000000000000000000000000000000000000000..73c652de57d9435975772eb59a018a1bbb7c4b85 --- /dev/null +++ b/lib/opmapcontrol/src/internals/core.h @@ -0,0 +1,283 @@ +/** +****************************************************************************** +* +* @file core.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 CORE_H +#define CORE_H + +#include "debugheader.h" + +#include "../internals/pointlatlng.h" +#include "mousewheelzoomtype.h" +#include "../core/size.h" +#include "../core/point.h" + +#include "../core/maptype.h" +#include "rectangle.h" +#include "QThreadPool" +#include "tilematrix.h" +#include +#include "loadtask.h" +#include "copyrightstrings.h" +#include "rectlatlng.h" +#include "../internals/projections/lks94projection.h" +#include "../internals/projections/mercatorprojection.h" +#include "../internals/projections/mercatorprojectionyandex.h" +#include "../internals/projections/platecarreeprojection.h" +#include "../internals/projections/platecarreeprojectionpergo.h" +#include "../core/geodecoderstatus.h" +#include "../core/opmaps.h" +#include "../core/diagnostics.h" + +#include +#include +#include + +#include + +namespace mapcontrol +{ + class OPMapControl; + class MapGraphicItem; +} + +namespace internals { + + class Core:public QObject,public QRunnable + { + Q_OBJECT + + friend class mapcontrol::OPMapControl; + friend class mapcontrol::MapGraphicItem; + public: + Core(); + ~Core(); + void run(); + PointLatLng CurrentPosition()const{return currentPosition;} + + void SetCurrentPosition(const PointLatLng &value); + + core::Point GetcurrentPositionGPixel(){return currentPositionPixel;} + void SetcurrentPositionGPixel(const core::Point &value){currentPositionPixel=value;} + + core::Point GetrenderOffset(){return renderOffset;} + void SetrenderOffset(const core::Point &value){renderOffset=value;} + + core::Point GetcenterTileXYLocation(){return centerTileXYLocation;} + void SetcenterTileXYLocation(const core::Point &value){centerTileXYLocation=value;} + + core::Point GetcenterTileXYLocationLast(){return centerTileXYLocationLast;} + void SetcenterTileXYLocationLast(const core::Point &value){centerTileXYLocationLast=value;} + + core::Point GetdragPoint(){return dragPoint;} + void SetdragPoint(const core::Point &value){dragPoint=value;} + + core::Point GetmouseDown(){return mouseDown;} + void SetmouseDown(const core::Point &value){mouseDown=value;} + + core::Point GetmouseCurrent(){return mouseCurrent;} + void SetmouseCurrent(const core::Point &value){mouseCurrent=value;} + + core::Point GetmouseLastZoom(){return mouseLastZoom;} + void SetmouseLastZoom(const core::Point &value){mouseLastZoom=value;} + + MouseWheelZoomType::Types GetMouseWheelZoomType(){return mousewheelzoomtype;} + void SetMouseWheelZoomType(const MouseWheelZoomType::Types &value){mousewheelzoomtype=value;} + + PointLatLng GetLastLocationInBounds(){return LastLocationInBounds;} + void SetLastLocationInBounds(const PointLatLng &value){LastLocationInBounds=value;} + + Size GetsizeOfMapArea(){return sizeOfMapArea;} + void SetsizeOfMapArea(const Size &value){sizeOfMapArea=value;} + + Size GetminOfTiles(){return minOfTiles;} + void SetminOfTiles(const Size &value){minOfTiles=value;} + + Size GetmaxOfTiles(){return maxOfTiles;} + void SetmaxOfTiles(const Size &value){maxOfTiles=value;} + + Rectangle GettileRect(){return tileRect;} + void SettileRect(const Rectangle &value){tileRect=value;} + + core::Point GettilePoint(){return tilePoint;} + void SettilePoint(const core::Point &value){tilePoint=value;} + + Rectangle GetCurrentRegion(){return CurrentRegion;} + void SetCurrentRegion(const Rectangle &value){CurrentRegion=value;} + + QList tileDrawingList; + + PureProjection* Projection() + { + return projection; + } + void SetProjection(PureProjection* value) + { + projection=value; + tileRect=Rectangle(core::Point(0,0),value->TileSize()); + } + bool IsDragging()const{return isDragging;} + + int Zoom()const{return zoom;} + void SetZoom(int const& value); + + int MaxZoom()const{return maxzoom;} + + void UpdateBounds(); + + MapType::Types GetMapType(){return mapType;} + void SetMapType(MapType::Types const& value); + + void StartSystem(); + + void UpdateCenterTileXYLocation(); + + void OnMapSizeChanged(int const& width, int const& height);//TODO had as slot + + void OnMapClose();//TODO had as slot + + GeoCoderStatusCode::Types SetCurrentPositionByKeywords(QString const& keys); + + RectLatLng CurrentViewArea(); + + PointLatLng FromLocalToLatLng(int const& x, int const& y); + + Point FromLatLngToLocal(PointLatLng const& latlng); + + int GetMaxZoomToFitRect(RectLatLng const& rect); + + void BeginDrag(core::Point const& pt); + + void EndDrag(); + + void ReloadMap(); + + void GoToCurrentPosition(); + + bool MouseWheelZooming; + + void DragOffset(core::Point const& offset); + + void Drag(core::Point const& pt); + + void CancelAsyncTasks(); + + void FindTilesAround(QList &list); + + void UpdateGroundResolution(); + + TileMatrix Matrix; + + bool isStarted(){return started;} + + diagnostics GetDiagnostics(); + signals: + void OnCurrentPositionChanged(internals::PointLatLng point); + void OnTileLoadComplete(); + void OnTilesStillToLoad(int number); + void OnTileLoadStart(); + void OnMapDrag(); + void OnMapZoomChanged(); + void OnMapTypeChanged(MapType::Types type); + void OnEmptyTileError(int zoom, core::Point pos); + void OnNeedInvalidation(); + + private: + + + PointLatLng currentPosition; + core::Point currentPositionPixel; + core::Point renderOffset; + core::Point centerTileXYLocation; + core::Point centerTileXYLocationLast; + core::Point dragPoint; + Rectangle tileRect; + core::Point mouseDown; + bool CanDragMap; + core::Point mouseCurrent; + PointLatLng LastLocationInBounds; + core::Point mouseLastZoom; + + MouseWheelZoomType::Types mousewheelzoomtype; + + + Size sizeOfMapArea; + Size minOfTiles; + Size maxOfTiles; + + core::Point tilePoint; + + Rectangle CurrentRegion; + + QQueue tileLoadQueue; + + int zoom; + + PureProjection* projection; + + bool isDragging; + + QMutex MtileLoadQueue; + + QMutex Moverlays; + + QMutex MtileDrawingList; +#ifdef DEBUG_CORE + QMutex Mdebug; + static qlonglong debugcounter; +#endif + Size TooltipTextPadding; + + MapType::Types mapType; + + QSemaphore loaderLimit; + + QThreadPool ProcessLoadTaskCallback; + QMutex MtileToload; + int tilesToload; + + int maxzoom; + QMutex MrunningThreads; + int runningThreads; + diagnostics diag; + + protected: + bool started; + + int Width; + int Height; + int pxRes100m; // 100 meters + int pxRes1000m; // 1km + int pxRes10km; // 10km + int pxRes100km; // 100km + int pxRes1000km; // 1000km + int pxRes5000km; // 5000km + void SetCurrentPositionGPixel(core::Point const& value){currentPositionPixel = value;} + void GoToCurrentPositionOnZoom(); + + }; + +} +#endif // CORE_H diff --git a/lib/opmapcontrol/src/internals/debugheader.h b/lib/opmapcontrol/src/internals/debugheader.h new file mode 100644 index 0000000000000000000000000000000000000000..8e5bdba43fcf9b7268f83955973d6f6b3dc80d16 --- /dev/null +++ b/lib/opmapcontrol/src/internals/debugheader.h @@ -0,0 +1,8 @@ +#ifndef DEBUGHEADER_H +#define DEBUGHEADER_H + +//#define DEBUG_CORE +//#define DEBUG_TILE +//#define DEBUG_TILEMATRIX + +#endif // DEBUGHEADER_H diff --git a/lib/opmapcontrol/src/internals/internals.pro b/lib/opmapcontrol/src/internals/internals.pro new file mode 100644 index 0000000000000000000000000000000000000000..21ce6b4b6927d2fc385628ed03acb4e2e45bdb54 --- /dev/null +++ b/lib/opmapcontrol/src/internals/internals.pro @@ -0,0 +1,35 @@ +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 diff --git a/lib/opmapcontrol/src/internals/loadtask.cpp b/lib/opmapcontrol/src/internals/loadtask.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0deb23025b24f39f854193a2860decfeac165ac2 --- /dev/null +++ b/lib/opmapcontrol/src/internals/loadtask.cpp @@ -0,0 +1,35 @@ +/** +****************************************************************************** +* +* @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)); +} +} diff --git a/lib/opmapcontrol/src/internals/loadtask.h b/lib/opmapcontrol/src/internals/loadtask.h new file mode 100644 index 0000000000000000000000000000000000000000..df38337b0a4349d2435cf5e70f6d5cc65c8d9359 --- /dev/null +++ b/lib/opmapcontrol/src/internals/loadtask.h @@ -0,0 +1,65 @@ +/** +****************************************************************************** +* +* @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 +#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 diff --git a/lib/opmapcontrol/src/internals/mousewheelzoomtype.h b/lib/opmapcontrol/src/internals/mousewheelzoomtype.h new file mode 100644 index 0000000000000000000000000000000000000000..218815c3697eaa9b1f9bb5c0154231703466c800 --- /dev/null +++ b/lib/opmapcontrol/src/internals/mousewheelzoomtype.h @@ -0,0 +1,89 @@ +/** +****************************************************************************** +* +* @file mousewheelzoomtype.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 MOUSEWHEELZOOMTYPE_H +#define MOUSEWHEELZOOMTYPE_H +#include +#include +#include +#include +#include +namespace internals { + class MouseWheelZoomType:public QObject + { + Q_OBJECT + Q_ENUMS(Types) + public: + enum Types + { + /// + /// zooms map to current mouse position and makes it map center + /// + MousePositionAndCenter, + + /// + /// zooms to current mouse position, but doesn't make it map center, + /// google/bing style ;} + /// + MousePositionWithoutCenter, + + /// + /// zooms map to current view center + /// + ViewCenter + }; + static QString StrByType(Types const& value) + { + QMetaObject metaObject = MouseWheelZoomType().staticMetaObject; + QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types")); + QString s=metaEnum.valueToKey(value); + return s; + } + static Types TypeByStr(QString const& value) + { + QMetaObject metaObject = MouseWheelZoomType().staticMetaObject; + QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types")); + Types s=(Types)metaEnum.keyToValue(value.toLatin1()); + return s; + } + static QStringList TypesList() + { + QStringList ret; + QMetaObject metaObject = MouseWheelZoomType().staticMetaObject; + QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types")); + for(int x=0;x +#include +#include "sizelatlng.h" + +namespace internals { +struct PointLatLng +{ + //friend uint qHash(PointLatLng const& point); + friend bool operator==(PointLatLng const& lhs,PointLatLng const& rhs); + friend bool operator!=(PointLatLng const& left, PointLatLng const& right); + friend PointLatLng operator+(PointLatLng pt, SizeLatLng sz); + friend PointLatLng operator-(PointLatLng pt, SizeLatLng sz); + + //TODO Sizelatlng friend PointLatLng operator+(PointLatLng pt, SizeLatLng sz); + + private: + double lat; + double lng; + bool empty; + public: + PointLatLng(); + + + static PointLatLng Empty; + + PointLatLng(const double &lat,const double &lng) + { + this->lat = lat; + this->lng = lng; + empty=false; + } + + bool IsEmpty() + { + return empty; + } + + double Lat()const + { + return this->lat; + } + + void SetLat(const double &value) + { + this->lat = value; + empty=false; + } + + + double Lng()const + { + return this->lng; + } + void SetLng(const double &value) + { + this->lng = value; + empty=false; + } + + + + + + static PointLatLng Add(PointLatLng const& pt, SizeLatLng const& sz) + { + return PointLatLng(pt.Lat() - sz.HeightLat(), pt.Lng() + sz.WidthLng()); + } + + static PointLatLng Subtract(PointLatLng const& pt, SizeLatLng const& sz) + { + return PointLatLng(pt.Lat() + sz.HeightLat(), pt.Lng() - sz.WidthLng()); + } + + + void Offset(PointLatLng const& pos) + { + this->Offset(pos.Lat(), pos.Lng()); + } + + void Offset(double const& lat, double const& lng) + { + this->lng += lng; + this->lat -= lat; + } + + + QString ToString()const + { + return QString("{Lat=%1, Lng=%2}").arg(this->lat).arg(this->lng); + } + +//// static PointLatLng() +//// { +//// Empty = new PointLatLng(); +//// } + }; + + +// +} +#endif // POINTLATLNG_H diff --git a/lib/opmapcontrol/src/internals/projections/lks94projection.cpp b/lib/opmapcontrol/src/internals/projections/lks94projection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f476ba2f17d1d0ecd089efaa7e26236b0983a614 --- /dev/null +++ b/lib/opmapcontrol/src/internals/projections/lks94projection.cpp @@ -0,0 +1,788 @@ +/** +****************************************************************************** +* +* @file lks94projection.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 "lks94projection.h" + + + +namespace projections { +LKS94Projection::LKS94Projection():MinLatitude (53.33 ), MaxLatitude (56.55 ), MinLongitude (20.22 ), +MaxLongitude (27.11 ), orignX (5122000 ), orignY (10000100 ),tileSize(256, 256) +{ +} + +Size LKS94Projection::TileSize() const +{ + return tileSize; +} +double LKS94Projection::Axis() const +{ + return 6378137; +} +double LKS94Projection::Flattening() const +{ + + return (1.0 / 298.257222101); + +} + +Point LKS94Projection::FromLatLngToPixel(double lat, double lng, int const& zoom) +{ + Point ret; + + lat = Clip(lat, MinLatitude, MaxLatitude); + lng = Clip(lng, MinLongitude, MaxLongitude); + QVector lks(3); + lks[0]=lng; + lks[1]=lat; + lks = DTM10(lks); + lks = MTD10(lks); + lks = DTM00(lks); + + double res = GetTileMatrixResolution(zoom); + + ret.SetX((int) floor((lks[0] + orignX) / res)); + ret.SetY((int) floor((orignY - lks[1]) / res)); + + return ret; +} + +internals::PointLatLng LKS94Projection::FromPixelToLatLng(int const& x, int const& y, int const& zoom) +{ + internals::PointLatLng ret;// = internals::PointLatLng::Empty; + + double res = GetTileMatrixResolution(zoom); + + QVector lks(2); + lks[0]=(x * res) - orignX; + lks[1]=-(y * res) + orignY; + lks = MTD11(lks); + lks = DTM10(lks); + lks = MTD10(lks); + ret.SetLat(Clip(lks[1], MinLatitude, MaxLatitude)); + ret.SetLng(Clip(lks[0], MinLongitude, MaxLongitude)); + return ret; +} + +QVector LKS94Projection::DTM10(const QVector & lonlat) +{ + double es; // Eccentricity squared : (a^2 - b^2)/a^2 + double semiMajor = 6378137.0; // major axis + double semiMinor = 6356752.3142451793; // minor axis + double ab; // Semi_major / semi_minor + double ba; // Semi_minor / semi_major + double ses; // Second eccentricity squared : (a^2 - b^2)/b^2 + + es = 1.0 - (semiMinor * semiMinor) / (semiMajor * semiMajor); //e^2 + ses = (pow(semiMajor, 2) - pow(semiMinor, 2)) / pow(semiMinor, 2); + ba = semiMinor / semiMajor; + ab = semiMajor / semiMinor; + + // ... + + double lon = DegreesToRadians(lonlat[0]); + double lat = DegreesToRadians(lonlat[1]); + double h = lonlat.count() < 3 ? 0 : std::isnan(lonlat[2]) ? 0 : lonlat[2];//TODO NAN + double v = semiMajor / sqrt(1 - es * pow(sin(lat), 2)); + double x = (v + h) * cos(lat) * cos(lon); + double y = (v + h) * cos(lat) * sin(lon); + double z = ((1 - es) * v + h) * sin(lat); + QVector ret(3); + ret[0]=x; + ret[1]=y; + ret[2]=z; + return ret; +} +QVector LKS94Projection::MTD10(QVector & pnt) +{ + QVector ret(3); + const double COS_67P5 = 0.38268343236508977; // cosine of 67.5 degrees + const double AD_C = 1.0026000; // Toms region 1 constant + + double es; // Eccentricity squared : (a^2 - b^2)/a^2 + double semiMajor = 6378137.0; // major axis + double semiMinor = 6356752.3141403561; // minor axis + double ab; // Semi_major / semi_minor + double ba; // Semi_minor / semi_major + double ses; // Second eccentricity squared : (a^2 - b^2)/b^2 + + es = 1.0 - (semiMinor * semiMinor) / (semiMajor * semiMajor); //e^2 + ses = (pow(semiMajor, 2) - pow(semiMinor, 2)) / pow(semiMinor, 2); + ba = semiMinor / semiMajor; + ab = semiMajor / semiMinor; + + // ... + + bool AtPole = false; // is location in polar region + double Z = pnt.count() < 3 ? 0 : std::isnan(pnt[2]) ? 0 : pnt[2];//TODO NaN + + double lon = 0; + double lat = 0; + double Height = 0; + if(pnt[0] != 0.0) + { + lon = atan2(pnt[1], pnt[0]); + } + else + { + if(pnt[1] > 0) + { + lon = M_PI / 2; + } + else + if(pnt[1] < 0) + { + lon = -M_PI * 0.5; + } + else + { + AtPole = true; + lon = 0.0; + if(Z > 0.0) // north pole + { + lat = M_PI * 0.5; + } + else + if(Z < 0.0) // south pole + { + lat = -M_PI * 0.5; + } + else // center of earth + { + ret[0]=RadiansToDegrees(lon); + ret[1]=RadiansToDegrees(M_PI * 0.5); + ret[2]=-semiMinor; + return ret; + } + } + } + double W2 = pnt[0] * pnt[0] + pnt[1] * pnt[1]; // Square of distance from Z axis + double W = sqrt(W2); // distance from Z axis + double T0 = Z * AD_C; // initial estimate of vertical component + double S0 = sqrt(T0 * T0 + W2); // initial estimate of horizontal component + double Sin_B0 = T0 / S0; // sin(B0), B0 is estimate of Bowring aux variable + double Cos_B0 = W / S0; // cos(B0) + double Sin3_B0 = pow(Sin_B0, 3); + double T1 = Z + semiMinor * ses * Sin3_B0; // corrected estimate of vertical component + double Sum = W - semiMajor * es * Cos_B0 * Cos_B0 * Cos_B0; // numerator of cos(phi1) + double S1 = sqrt(T1 * T1 + Sum * Sum); // corrected estimate of horizontal component + double Sin_p1 = T1 / S1; // sin(phi1), phi1 is estimated latitude + double Cos_p1 = Sum / S1; // cos(phi1) + double Rn = semiMajor / sqrt(1.0 - es * Sin_p1 * Sin_p1); // Earth radius at location + if(Cos_p1 >= COS_67P5) + { + Height = W / Cos_p1 - Rn; + } + else + if(Cos_p1 <= -COS_67P5) + { + Height = W / -Cos_p1 - Rn; + } + else + { + Height = Z / Sin_p1 + Rn * (es - 1.0); + } + + if(!AtPole) + { + lat = atan(Sin_p1 / Cos_p1); + } + ret[0]=RadiansToDegrees(lon); + ret[1]=RadiansToDegrees(lat); + ret[2]=Height; + return ret; +} +QVector LKS94Projection::DTM00(QVector & lonlat) +{ + double scaleFactor = 0.9998; // scale factor + double centralMeridian = 0.41887902047863912; // Center qlonglongitude (projection center) */ + double latOrigin = 0.0; // center latitude + double falseNorthing = 0.0; // y offset in meters + double falseEasting = 500000.0; // x offset in meters + double semiMajor = 6378137.0; // major axis + double semiMinor = 6356752.3141403561; // minor axis + double metersPerUnit = 1.0; + + double e0, e1, e2, e3; // eccentricity constants + double e, es, esp; // eccentricity constants + double ml0; // small value m + + es = 1.0 - pow(semiMinor / semiMajor, 2); + e = sqrt(es); + e0 = e0fn(es); + e1 = e1fn(es); + e2 = e2fn(es); + e3 = e3fn(es); + ml0 = semiMajor * mlfn(e0, e1, e2, e3, latOrigin); + esp = es / (1.0 - es); + + // ... + + double lon = DegreesToRadians(lonlat[0]); + double lat = DegreesToRadians(lonlat[1]); + + double delta_lon = 0.0; // Delta qlonglongitude (Given qlonglongitude - center) + double sin_phi, cos_phi; // sin and cos value + double al, als; // temporary values + double c, t, tq; // temporary values + double con, n, ml; // cone constant, small m + + delta_lon = LKS94Projection::AdjustLongitude(lon - centralMeridian); + LKS94Projection::SinCos(lat, sin_phi, cos_phi); + + al = cos_phi * delta_lon; + als = pow(al, 2); + c = pow(cos_phi, 2); + tq = tan(lat); + t = pow(tq, 2); + con = 1.0 - es * pow(sin_phi, 2); + n = semiMajor / sqrt(con); + ml = semiMajor * mlfn(e0, e1, e2, e3, lat); + + double x = scaleFactor * n * al * (1.0 + als / 6.0 * (1.0 - t + c + als / 20.0 * + (5.0 - 18.0 * t + pow(t, 2) + 72.0 * c - 58.0 * esp))) + falseEasting; + + double y = scaleFactor * (ml - ml0 + n * tq * (als * (0.5 + als / 24.0 * + (5.0 - t + 9.0 * c + 4.0 * pow(c, 2) + als / 30.0 * (61.0 - 58.0 * t + + pow(t, 2) + 600.0 * c - 330.0 * esp))))) + falseNorthing; + + if(lonlat.count() < 3) + { + QVector ret(2); + ret[0]= x / metersPerUnit; + ret[1]= y / metersPerUnit; + return ret; + } + else + { + QVector ret(3); + ret[0]= x / metersPerUnit; + ret[1]= y / metersPerUnit; + ret[2]=lonlat[2]; + return ret; + } +} + +QVector LKS94Projection::DTM01(QVector & lonlat) +{ + double es; // Eccentricity squared : (a^2 - b^2)/a^2 + double semiMajor = 6378137.0; // major axis + double semiMinor = 6356752.3141403561; // minor axis + double ab; // Semi_major / semi_minor + double ba; // Semi_minor / semi_major + double ses; // Second eccentricity squared : (a^2 - b^2)/b^2 + + es = 1.0 - (semiMinor * semiMinor) / (semiMajor * semiMajor); + ses = (pow(semiMajor, 2) -pow(semiMinor, 2)) / pow(semiMinor, 2); + ba = semiMinor / semiMajor; + ab = semiMajor / semiMinor; + + // ... + + double lon = DegreesToRadians(lonlat[0]); + double lat = DegreesToRadians(lonlat[1]); + double h = lonlat.count() < 3 ? 0 : std::isnan(lonlat[2]) ? 0 : lonlat[2];//TODO NaN + double v = semiMajor / sqrt(1 - es * pow(sin(lat), 2)); + double x = (v + h) * cos(lat) * cos(lon); + double y = (v + h) * cos(lat) * sin(lon); + double z = ((1 - es) * v + h) * sin(lat); + QVector ret(3); + ret[0]=x; + ret[1]=y; + ret[2]=z; + return ret; +} +QVector LKS94Projection::MTD01(QVector & pnt) +{ + const double COS_67P5 = 0.38268343236508977; // cosine of 67.5 degrees + const double AD_C = 1.0026000; // Toms region 1 constant + + double es; // Eccentricity squared : (a^2 - b^2)/a^2 + double semiMajor = 6378137.0; // major axis + double semiMinor = 6356752.3142451793; // minor axis + double ab; // Semi_major / semi_minor + double ba; // Semi_minor / semi_major + double ses; // Second eccentricity squared : (a^2 - b^2)/b^2 + + es = 1.0 - (semiMinor * semiMinor) / (semiMajor * semiMajor); + ses = (pow(semiMajor, 2) - pow(semiMinor, 2)) / pow(semiMinor, 2); + ba = semiMinor / semiMajor; + ab = semiMajor / semiMinor; + + // ... + + bool At_Pole = false; // is location in polar region + double Z = pnt.count() < 3 ? 0 : std::isnan(pnt[2]) ? 0 : pnt[2];//TODO NaN + + double lon = 0; + double lat = 0; + double Height = 0; + if(pnt[0] != 0.0) + { + lon = atan2(pnt[1], pnt[0]); + } + else + { + if(pnt[1] > 0) + { + lon = M_PI / 2; + } + else + if(pnt[1] < 0) + { + lon = -M_PI * 0.5; + } + else + { + At_Pole = true; + lon = 0.0; + if(Z > 0.0) // north pole + { + lat = M_PI * 0.5; + } + else + if(Z < 0.0) // south pole + { + lat = -M_PI * 0.5; + } + else // center of earth + { + QVector ret(3); + ret[0]=RadiansToDegrees(lon); + ret[1]=RadiansToDegrees(M_PI * 0.5); + ret[2]=-semiMinor; + return ret; + } + } + } + + double W2 = pnt[0] * pnt[0] + pnt[1] * pnt[1]; // Square of distance from Z axis + double W = sqrt(W2); // distance from Z axis + double T0 = Z * AD_C; // initial estimate of vertical component + double S0 = sqrt(T0 * T0 + W2); //initial estimate of horizontal component + double Sin_B0 = T0 / S0; // sin(B0), B0 is estimate of Bowring aux variable + double Cos_B0 = W / S0; // cos(B0) + double Sin3_B0 = pow(Sin_B0, 3); + double T1 = Z + semiMinor * ses * Sin3_B0; //corrected estimate of vertical component + double Sum = W - semiMajor * es * Cos_B0 * Cos_B0 * Cos_B0; // numerator of cos(phi1) + double S1 = sqrt(T1 * T1 + Sum * Sum); // corrected estimate of horizontal component + double Sin_p1 = T1 / S1; // sin(phi1), phi1 is estimated latitude + double Cos_p1 = Sum / S1; // cos(phi1) + double Rn = semiMajor / sqrt(1.0 - es * Sin_p1 * Sin_p1); // Earth radius at location + + if(Cos_p1 >= COS_67P5) + { + Height = W / Cos_p1 - Rn; + } + else + if(Cos_p1 <= -COS_67P5) + { + Height = W / -Cos_p1 - Rn; + } + else + { + Height = Z / Sin_p1 + Rn * (es - 1.0); + } + + if(!At_Pole) + { + lat = atan(Sin_p1 / Cos_p1); + } + QVector ret(3); + ret[0]=RadiansToDegrees(lon); + ret[1]=RadiansToDegrees(lat); + ret[2]=Height; + return ret; +} +QVector LKS94Projection::MTD11(QVector & p) +{ + double scaleFactor = 0.9998; // scale factor + double centralMeridian = 0.41887902047863912; // Center qlonglongitude (projection center) + double latOrigin = 0.0; // center latitude + double falseNorthing = 0.0; // y offset in meters + double falseEasting = 500000.0; // x offset in meters + double semiMajor = 6378137.0; // major axis + double semiMinor = 6356752.3141403561; // minor axis + double metersPerUnit = 1.0; + + double e0, e1, e2, e3; // eccentricity constants + double e, es, esp; // eccentricity constants + double ml0; // small value m + + es =(semiMinor * semiMinor) / (semiMajor * semiMajor); + es=1.0-es; + e = sqrt(es); + e0 = e0fn(es); + e1 = e1fn(es); + e2 = e2fn(es); + e3 = e3fn(es); + ml0 = semiMajor * mlfn(e0, e1, e2, e3, latOrigin); + esp = es / (1.0 - es); + + // ... + + double con, phi; + double delta_phi; + qlonglong i; + double sin_phi, cos_phi, tan_phi; + double c, cs, t, ts, n, r, d, ds; + qlonglong max_iter = 6; + + double x = p[0] * metersPerUnit - falseEasting; + double y = p[1] * metersPerUnit - falseNorthing; + + con = (ml0 + y / scaleFactor) / semiMajor; + phi = con; + for(i = 0; ; i++) + { + delta_phi = ((con + e1 * sin(2.0 * phi) - e2 * sin(4.0 * phi) + e3 * sin(6.0 * phi)) / e0) - phi; + phi += delta_phi; + if(fabs(delta_phi) <= EPSLoN) + break; + + if(i >= max_iter) + throw "Latitude failed to converge"; + } + + if(fabs(phi) < HALF_PI) + { + SinCos(phi, sin_phi, cos_phi); + tan_phi = tan(phi); + c = esp * pow(cos_phi, 2); + cs = pow(c, 2); + t = pow(tan_phi, 2); + ts = pow(t, 2); + con = 1.0 - es * pow(sin_phi, 2); + n = semiMajor / sqrt(con); + r = n * (1.0 - es) / con; + d = x / (n * scaleFactor); + ds = pow(d, 2); + + double lat = phi - (n * tan_phi * ds / r) * (0.5 - ds / 24.0 * (5.0 + 3.0 * t + + 10.0 * c - 4.0 * cs - 9.0 * esp - ds / 30.0 * (61.0 + 90.0 * t + + 298.0 * c + 45.0 * ts - 252.0 * esp - 3.0 * cs))); + + double lon = AdjustLongitude(centralMeridian + (d * (1.0 - ds / 6.0 * (1.0 + 2.0 * t + + c - ds / 20.0 * (5.0 - 2.0 * c + 28.0 * t - 3.0 * cs + 8.0 * esp + + 24.0 * ts))) / cos_phi)); + + if(p.count() < 3) + { + QVector ret(2); + ret[0]= RadiansToDegrees(lon); + ret[1]= RadiansToDegrees(lat); + return ret; + } + else + { + QVector ret(3); + ret[0]= RadiansToDegrees(lon); + ret[1]= RadiansToDegrees(lat); + ret[2]=p[2]; + return ret; + //return new double[] { RadiansToDegrees(lon), RadiansToDegrees(lat), p[2] }; + } + } + else + { + if(p.count() < 3) + { + QVector ret(2); + ret[0]= RadiansToDegrees(HALF_PI * Sign(y)); + ret[1]= RadiansToDegrees(centralMeridian); + return ret; + } + + else + { + QVector ret(3); + ret[0]= RadiansToDegrees(HALF_PI * Sign(y)); + ret[1]= RadiansToDegrees(centralMeridian); + ret[2]=p[2]; + return ret; + } + + } +} + +double LKS94Projection::Clip(double const& n, double const& minValue, double const& maxValue) +{ + return qMin(qMax(n, minValue), maxValue); +} +double LKS94Projection::GetTileMatrixResolution(int const& zoom) +{ + double ret = 0; + + switch(zoom) + { + case 0: + { + ret = 1587.50317500635; + } + break; + + case 1: + { + ret = 793.751587503175; + } + break; + + case 2: + { + ret = 529.167725002117; + } + break; + + case 3: + { + ret = 264.583862501058; + } + break; + + case 4: + { + ret = 132.291931250529; + } + break; + + case 5: + { + ret = 52.9167725002117; + } + break; + + case 6: + { + ret = 26.4583862501058; + } + break; + + case 7: + { + ret = 13.2291931250529; + } + break; + + case 8: + { + ret = 6.61459656252646; + } + break; + + case 9: + { + ret = 2.64583862501058; + } + break; + + case 10: + { + ret = 1.32291931250529; + } + break; + + case 11: + { + ret = 0.529167725002117; + } + break; + + } + + return ret; +} +double LKS94Projection::GetGroundResolution(int const& zoom, double const& latitude) +{ + Q_UNUSED(zoom); + Q_UNUSED(latitude); + return GetTileMatrixResolution(zoom); +} +Size LKS94Projection::GetTileMatrixMinXY(int const& zoom) +{ + Size ret; + + switch(zoom) + { + + case 0: + { + ret = Size(12, 8); + } + break; + + case 1: + { + ret = Size(24, 17); + } + break; + + case 2: + { + ret = Size(37, 25); + } + break; + + case 3: + { + ret = Size(74, 51); + } + break; + + case 4: + { + ret = Size(149, 103); + } + break; + + case 5: + { + ret = Size(374, 259); + } + break; + + case 6: + { + ret = Size(749, 519); + } + break; + + case 7: + { + ret = Size(1594, 1100); + } + break; + + case 8: + { + ret = Size(3188, 2201); + } + break; + + case 9: + { + ret = Size(7971, 5502); + } + break; + + case 10: + { + ret = Size(15943, 11005); + } + break; + + case 11: + { + ret = Size(39858, 27514); + } + break; + } + + return ret; +} + +Size LKS94Projection::GetTileMatrixMaxXY(int const& zoom) +{ + Size ret; + + switch(zoom) + { + case 0: + { + ret = Size(14, 10); + } + break; + + case 1: + { + ret = Size(30, 20); + } + break; + + case 2: + { + ret = Size(45, 31); + } + break; + + case 3: + { + ret = Size(90, 62); + } + break; + + case 4: + { + ret = Size(181, 125); + } + break; + + case 5: + { + ret = Size(454, 311); + } + break; + + case 6: + { + ret = Size(903, 623); + } + break; + + case 7: + { + ret = Size(1718, 1193); + } + break; + + case 8: + { + ret = Size(3437, 2386); + } + break; + + case 9: + { + ret = Size(8594, 5966); + } + break; + + case 10: + { + ret = Size(17189, 11932); + } + break; + + case 11: + { + ret = Size(42972, 29831); + } + break; + } + + return ret; +} + +} diff --git a/lib/opmapcontrol/src/internals/projections/lks94projection.h b/lib/opmapcontrol/src/internals/projections/lks94projection.h new file mode 100644 index 0000000000000000000000000000000000000000..4eee20aaa84f6b897042bd15267325a59f580d60 --- /dev/null +++ b/lib/opmapcontrol/src/internals/projections/lks94projection.h @@ -0,0 +1,72 @@ +/** +****************************************************************************** +* +* @file lks94projection.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 LKS94PROJECTION_H +#define LKS94PROJECTION_H +#include +#include "cmath" +#include "../pureprojection.h" + + +namespace projections { +class LKS94Projection:public internals::PureProjection +{ +public: + LKS94Projection(); + double GetTileMatrixResolution(int const& zoom); + virtual QString Type(){return "LKS94Projection";} + virtual Size TileSize() const; + virtual double Axis() const; + virtual double Flattening() const; + virtual core::Point FromLatLngToPixel(double lat, double lng, int const& zoom); + virtual internals::PointLatLng FromPixelToLatLng(int const& x, int const& y, int const& zoom); + virtual double GetGroundResolution(int const& zoom, double const& latitude); + virtual Size GetTileMatrixMinXY(int const& zoom); + virtual Size GetTileMatrixMaxXY(int const& zoom); + +private: + const double MinLatitude; + const double MaxLatitude; + const double MinLongitude; + const double MaxLongitude; + const double orignX; + const double orignY; + Size tileSize; + QVector DTM10(const QVector & lonlat); + QVector MTD10(QVector & pnt); + QVector DTM00(QVector & lonlat); + QVector DTM01(QVector & lonlat); + QVector MTD01(QVector & pnt); + QVector MTD11(QVector & p); + double Clip(double const& n, double const& minValue, double const& maxValue); +}; + +} +#endif // LKS94PROJECTION_H + + + + diff --git a/lib/opmapcontrol/src/internals/projections/mercatorprojection.cpp b/lib/opmapcontrol/src/internals/projections/mercatorprojection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..30b94d2e4d69e402536e14473d18187ef355697b --- /dev/null +++ b/lib/opmapcontrol/src/internals/projections/mercatorprojection.cpp @@ -0,0 +1,98 @@ +/** +****************************************************************************** +* +* @file mercatorprojection.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 "mercatorprojection.h" + + +namespace projections { +MercatorProjection::MercatorProjection():MinLatitude(-85.05112878), MaxLatitude(85.05112878),MinLongitude(-177), +MaxLongitude(177), tileSize(256, 256) +{ +} +Point MercatorProjection::FromLatLngToPixel(double lat, double lng, const int &zoom) +{ + Point ret;// = Point.Empty; + + lat = Clip(lat, MinLatitude, MaxLatitude); + lng = Clip(lng, MinLongitude, MaxLongitude); + + double x = (lng + 180) / 360; + double sinLatitude = sin(lat * M_PI / 180); + double y = 0.5 - log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * M_PI); + + Size s = GetTileMatrixSizePixel(zoom); + int mapSizeX = s.Width(); + int mapSizeY = s.Height(); + + ret.SetX((int) Clip(x * mapSizeX + 0.5, 0, mapSizeX - 1)); + ret.SetY((int) Clip(y * mapSizeY + 0.5, 0, mapSizeY - 1)); + + return ret; +} +internals::PointLatLng MercatorProjection::FromPixelToLatLng(const int &x, const int &y, const int &zoom) +{ + internals::PointLatLng ret;// = internals::PointLatLng.Empty; + + Size s = GetTileMatrixSizePixel(zoom); + double mapSizeX = s.Width(); + double mapSizeY = s.Height(); + + double xx = (Clip(x, 0, mapSizeX - 1) / mapSizeX) - 0.5; + double yy = 0.5 - (Clip(y, 0, mapSizeY - 1) / mapSizeY); + + ret.SetLat(90 - 360 * atan(exp(-yy * 2 * M_PI)) / M_PI); + ret.SetLng(360 * xx); + + return ret; +} +double MercatorProjection::Clip(const double &n, const double &minValue, const double &maxValue) const +{ + return qMin(qMax(n, minValue), maxValue); +} +Size MercatorProjection::TileSize() const +{ + return tileSize; +} +double MercatorProjection::Axis() const +{ + return 6378137; +} +double MercatorProjection::Flattening() const +{ + return (1.0 / 298.257223563); +} +Size MercatorProjection::GetTileMatrixMaxXY(const int &zoom) +{ + Q_UNUSED(zoom); + int xy = (1 << zoom); + return Size(xy - 1, xy - 1); +} +Size MercatorProjection::GetTileMatrixMinXY(const int &zoom) +{ + Q_UNUSED(zoom); + return Size(0, 0); +} +} diff --git a/lib/opmapcontrol/src/internals/projections/mercatorprojection.h b/lib/opmapcontrol/src/internals/projections/mercatorprojection.h new file mode 100644 index 0000000000000000000000000000000000000000..1c55f5638072e6c69e53b6b35520c9e34668ca90 --- /dev/null +++ b/lib/opmapcontrol/src/internals/projections/mercatorprojection.h @@ -0,0 +1,55 @@ +/** +****************************************************************************** +* +* @file mercatorprojection.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 MERCATORPROJECTION_H +#define MERCATORPROJECTION_H +#include "../pureprojection.h" + + +namespace projections { + class MercatorProjection:public internals::PureProjection +{ +public: + MercatorProjection(); + virtual QString Type(){return "MercatorProjection";} + virtual Size TileSize() const; + virtual double Axis() const; + virtual double Flattening()const; + virtual core::Point FromLatLngToPixel(double lat, double lng, int const& zoom); + virtual internals::PointLatLng FromPixelToLatLng(const int &x,const int &y,const int &zoom); + virtual Size GetTileMatrixMinXY(const int &zoom); + virtual Size GetTileMatrixMaxXY(const int &zoom); +private: + const double MinLatitude; + const double MaxLatitude; + const double MinLongitude; + const double MaxLongitude; + double Clip(double const& n, double const& minValue, double const& maxValue)const; + Size tileSize; +}; + +} +#endif // MERCATORPROJECTION_H diff --git a/lib/opmapcontrol/src/internals/projections/mercatorprojectionyandex.cpp b/lib/opmapcontrol/src/internals/projections/mercatorprojectionyandex.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0a695308dfdd6decd40af08429b13ab7c9d83edf --- /dev/null +++ b/lib/opmapcontrol/src/internals/projections/mercatorprojectionyandex.cpp @@ -0,0 +1,112 @@ +/** +****************************************************************************** +* +* @file mercatorprojectionyandex.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 "mercatorprojectionyandex.h" + + + +namespace projections { +MercatorProjectionYandex::MercatorProjectionYandex():MinLatitude(-85.05112878), MaxLatitude(85.05112878),MinLongitude(-177), +MaxLongitude(177), RAD_DEG(180 / M_PI),DEG_RAD(M_PI / 180),MathPiDiv4(M_PI / 4),tileSize(256, 256) +{ +} +Point MercatorProjectionYandex::FromLatLngToPixel(double lat, double lng, const int &zoom) +{ + lat = Clip(lat, MinLatitude, MaxLatitude); + lng = Clip(lng, MinLongitude, MaxLongitude); + + double rLon = lng * DEG_RAD; // Math.PI / 180; + double rLat = lat * DEG_RAD; // Math.PI / 180; + + double a = 6378137; + double k = 0.0818191908426; + + double z = tan(MathPiDiv4 + rLat / 2) / pow((tan(MathPiDiv4 + asin(k * sin(rLat)) / 2)), k); + double z1 = pow(2, 23 - zoom); + + double DX = ((20037508.342789 + a * rLon) * 53.5865938 / z1); + double DY = ((20037508.342789 - a * log(z)) * 53.5865938 / z1); + + Point ret;// = Point.Empty; + ret.SetX((int) DX); + ret.SetY((int) DY); + + return ret; + +} +internals::PointLatLng MercatorProjectionYandex::FromPixelToLatLng(const int &x, const int &y, const int &zoom) +{ + Size s = GetTileMatrixSizePixel(zoom); + + //double mapSizeX = s.Width(); + //double mapSizeY = s.Height(); + + double a = 6378137; + double c1 = 0.00335655146887969; + double c2 = 0.00000657187271079536; + double c3 = 0.00000001764564338702; + double c4 = 0.00000000005328478445; + double z1 = (23 - zoom); + double mercX = (x * pow(2, z1)) / 53.5865938 - 20037508.342789; + double mercY = 20037508.342789 - (y *pow(2, z1)) / 53.5865938; + + double g = M_PI /2 - 2 *atan(1 / exp(mercY /a)); + double z = g + c1 * sin(2 * g) + c2 * sin(4 * g) + c3 * sin(6 * g) + c4 * sin(8 * g); + + internals::PointLatLng ret;// = internals::PointLatLng.Empty; + ret.SetLat(z * RAD_DEG); + ret.SetLng (mercX / a * RAD_DEG); + + return ret; +} +double MercatorProjectionYandex::Clip(const double &n, const double &minValue, const double &maxValue) const +{ + return qMin(qMax(n, minValue), maxValue); +} +Size MercatorProjectionYandex::TileSize() const +{ + return tileSize; +} +double MercatorProjectionYandex::Axis() const +{ + return 6356752.3142; +} +double MercatorProjectionYandex::Flattening() const +{ + return (1.0 / 298.257223563); +} +Size MercatorProjectionYandex::GetTileMatrixMaxXY(const int &zoom) +{ + int xy = (1 << zoom); + return Size(xy - 1, xy - 1); +} + +Size MercatorProjectionYandex::GetTileMatrixMinXY(const int &zoom) +{ + Q_UNUSED(zoom); + return Size(0, 0); +} +} diff --git a/lib/opmapcontrol/src/internals/projections/mercatorprojectionyandex.h b/lib/opmapcontrol/src/internals/projections/mercatorprojectionyandex.h new file mode 100644 index 0000000000000000000000000000000000000000..949f83f1f113c5aa051b3237680a8a6aaa4db445 --- /dev/null +++ b/lib/opmapcontrol/src/internals/projections/mercatorprojectionyandex.h @@ -0,0 +1,59 @@ +/** +****************************************************************************** +* +* @file mercatorprojectionyandex.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 MERCATORPROJECTIONYANDEX_H +#define MERCATORPROJECTIONYANDEX_H + +#include "../pureprojection.h" + + +namespace projections { + class MercatorProjectionYandex:public internals::PureProjection +{ +public: + MercatorProjectionYandex(); + virtual QString Type(){return "MercatorProjectionYandex";} + virtual Size TileSize() const; + virtual double Axis() const; + virtual double Flattening()const; + virtual core::Point FromLatLngToPixel(double lat, double lng, int const& zoom); + virtual internals::PointLatLng FromPixelToLatLng(const int &x,const int &y,const int &zoom); + virtual Size GetTileMatrixMinXY(const int &zoom); + virtual Size GetTileMatrixMaxXY(const int &zoom); +private: + const double MinLatitude; + const double MaxLatitude; + const double MinLongitude; + const double MaxLongitude; + const double RAD_DEG; + const double DEG_RAD; + const double MathPiDiv4; + double Clip(double const& n, double const& minValue, double const& maxValue)const; + Size tileSize; +}; + +} +#endif // MERCATORPROJECTIONYANDEX_H diff --git a/lib/opmapcontrol/src/internals/projections/platecarreeprojection.cpp b/lib/opmapcontrol/src/internals/projections/platecarreeprojection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..be3989d920e83f73d507c6c806b586a7d962eded --- /dev/null +++ b/lib/opmapcontrol/src/internals/projections/platecarreeprojection.cpp @@ -0,0 +1,96 @@ +/** +****************************************************************************** +* +* @file platecarreeprojection.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 "platecarreeprojection.h" + + + +namespace projections { +PlateCarreeProjection::PlateCarreeProjection():MinLatitude(-85.05112878), MaxLatitude(85.05112878),MinLongitude(-180), +MaxLongitude(180), tileSize(512, 512) +{ +} +Point PlateCarreeProjection::FromLatLngToPixel(double lat, double lng, const int &zoom) +{ + Point ret;// = Point.Empty; + + lat = Clip(lat, MinLatitude, MaxLatitude); + lng = Clip(lng, MinLongitude, MaxLongitude); + + Size s = GetTileMatrixSizePixel(zoom); + double mapSizeX = s.Width(); + //double mapSizeY = s.Height(); + + double scale = 360.0 / mapSizeX; + + ret.SetY((int) ((90.0 - lat) / scale)); + ret.SetX((int) ((lng + 180.0) / scale)); + + return ret; + +} +internals::PointLatLng PlateCarreeProjection::FromPixelToLatLng(const int &x, const int &y, const int &zoom) +{ + internals::PointLatLng ret;// = internals::PointLatLng.Empty; + + Size s = GetTileMatrixSizePixel(zoom); + double mapSizeX = s.Width(); + //double mapSizeY = s.Height(); + + double scale = 360.0 / mapSizeX; + + ret.SetLat(90 - (y * scale)); + ret.SetLng((x * scale) - 180); + + return ret; +} +double PlateCarreeProjection::Clip(const double &n, const double &minValue, const double &maxValue) const +{ + return qMin(qMax(n, minValue), maxValue); +} +Size PlateCarreeProjection::TileSize() const +{ + return tileSize; +} +double PlateCarreeProjection::Axis() const +{ + return 6378137; +} +double PlateCarreeProjection::Flattening() const +{ + return (1.0 / 298.257223563); +} +Size PlateCarreeProjection::GetTileMatrixMaxXY(const int &zoom) +{ + int y = (int) pow(2, zoom); + return Size((2*y) - 1, y - 1); +} + +Size PlateCarreeProjection::GetTileMatrixMinXY(const int &zoom) +{ + return Size(0, 0); +} +} diff --git a/lib/opmapcontrol/src/internals/projections/platecarreeprojection.h b/lib/opmapcontrol/src/internals/projections/platecarreeprojection.h new file mode 100644 index 0000000000000000000000000000000000000000..c57285a2fcf1e29c3e15b40dc2f409f4f9f9d487 --- /dev/null +++ b/lib/opmapcontrol/src/internals/projections/platecarreeprojection.h @@ -0,0 +1,56 @@ +/** +****************************************************************************** +* +* @file platecarreeprojection.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 PLATECARREEPROJECTION_H +#define PLATECARREEPROJECTION_H + +#include "../pureprojection.h" + + +namespace projections { +class PlateCarreeProjection:public internals::PureProjection +{ +public: + PlateCarreeProjection(); + virtual QString Type(){return "PlateCarreeProjection";} + virtual Size TileSize() const; + virtual double Axis() const; + virtual double Flattening()const; + virtual core::Point FromLatLngToPixel(double lat, double lng, int const& zoom); + virtual internals::PointLatLng FromPixelToLatLng(const int &x,const int &y,const int &zoom); + virtual Size GetTileMatrixMinXY(const int &zoom); + virtual Size GetTileMatrixMaxXY(const int &zoom); +private: + const double MinLatitude; + const double MaxLatitude; + const double MinLongitude; + const double MaxLongitude; + + double Clip(double const& n, double const& minValue, double const& maxValue)const; + Size tileSize; +}; +} +#endif // PLATECARREEPROJECTION_H diff --git a/lib/opmapcontrol/src/internals/projections/platecarreeprojectionpergo.cpp b/lib/opmapcontrol/src/internals/projections/platecarreeprojectionpergo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c9ad01d1f379d131ec5d9521141199b4f06ff399 --- /dev/null +++ b/lib/opmapcontrol/src/internals/projections/platecarreeprojectionpergo.cpp @@ -0,0 +1,95 @@ +/** +****************************************************************************** +* +* @file platecarreeprojectionpergo.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 "platecarreeprojectionpergo.h" + + +namespace projections { +PlateCarreeProjectionPergo::PlateCarreeProjectionPergo():MinLatitude(-85.05112878), MaxLatitude(85.05112878),MinLongitude(-180), +MaxLongitude(180), tileSize(256, 256) +{ +} +Point PlateCarreeProjectionPergo::FromLatLngToPixel(double lat, double lng, const int &zoom) +{ + Point ret;// = Point.Empty; + + lat = Clip(lat, MinLatitude, MaxLatitude); + lng = Clip(lng, MinLongitude, MaxLongitude); + + Size s = GetTileMatrixSizePixel(zoom); + double mapSizeX = s.Width(); + //double mapSizeY = s.Height(); + + double scale = 360.0 / mapSizeX; + + ret.SetY((int) ((90.0 - lat) / scale)); + ret.SetX((int) ((lng + 180.0) / scale)); + + return ret; +} +internals::PointLatLng PlateCarreeProjectionPergo::FromPixelToLatLng(const int &x, const int &y, const int &zoom) +{ + internals::PointLatLng ret;// = internals::PointLatLng.Empty; + + Size s = GetTileMatrixSizePixel(zoom); + double mapSizeX = s.Width(); + //double mapSizeY = s.Height(); + + double scale = 360.0 / mapSizeX; + + ret.SetLat(90 - (y * scale)); + ret.SetLng((x * scale) - 180); + + return ret; +} + +double PlateCarreeProjectionPergo::Clip(const double &n, const double &minValue, const double &maxValue) const +{ + return qMin(qMax(n, minValue), maxValue); +} +Size PlateCarreeProjectionPergo::TileSize() const +{ + return tileSize; +} +double PlateCarreeProjectionPergo::Axis() const +{ + return 6378137; +} +double PlateCarreeProjectionPergo::Flattening() const +{ + return (1.0 / 298.257223563); +} +Size PlateCarreeProjectionPergo::GetTileMatrixMaxXY(const int &zoom) +{ + int y = (int) pow(2, zoom); + return Size((2*y) - 1, y - 1); +} + +Size PlateCarreeProjectionPergo::GetTileMatrixMinXY(const int &zoom) +{ + return Size(0, 0); +} +} diff --git a/lib/opmapcontrol/src/internals/projections/platecarreeprojectionpergo.h b/lib/opmapcontrol/src/internals/projections/platecarreeprojectionpergo.h new file mode 100644 index 0000000000000000000000000000000000000000..f0ca29fdff788b99d743a7bd26476990bffd9194 --- /dev/null +++ b/lib/opmapcontrol/src/internals/projections/platecarreeprojectionpergo.h @@ -0,0 +1,56 @@ +/** +****************************************************************************** +* +* @file platecarreeprojectionpergo.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 PLATECARREEPROJECTIONPERGO_H +#define PLATECARREEPROJECTIONPERGO_H + +#include "../pureprojection.h" + + +namespace projections { +class PlateCarreeProjectionPergo:public internals::PureProjection +{ +public: + PlateCarreeProjectionPergo(); + virtual QString Type(){return "PlateCarreeProjectionPergo";} + virtual Size TileSize() const; + virtual double Axis() const; + virtual double Flattening()const; + virtual core::Point FromLatLngToPixel(double lat, double lng, int const& zoom); + virtual internals::PointLatLng FromPixelToLatLng(const int &x,const int &y,const int &zoom); + virtual Size GetTileMatrixMinXY(const int &zoom); + virtual Size GetTileMatrixMaxXY(const int &zoom); +private: + const double MinLatitude; + const double MaxLatitude; + const double MinLongitude; + const double MaxLongitude; + + double Clip(double const& n, double const& minValue, double const& maxValue)const; + Size tileSize; +}; +} +#endif // PLATECARREEPROJECTIONPERGO_H diff --git a/lib/opmapcontrol/src/internals/pureprojection.cpp b/lib/opmapcontrol/src/internals/pureprojection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..432defd06577bd6f7ca6cadadee5df12af8af7e8 --- /dev/null +++ b/lib/opmapcontrol/src/internals/pureprojection.cpp @@ -0,0 +1,232 @@ +/** +****************************************************************************** +* +* @file pureprojection.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 "pureprojection.h" + + + + + + +namespace internals { + +const double PureProjection::PI = M_PI; +const double PureProjection::HALF_PI = (M_PI * 0.5); +const double PureProjection::TWO_PI= (M_PI * 2.0); +const double PureProjection::EPSLoN= 1.0e-10; +const double PureProjection::MAX_VAL= 4; +const double PureProjection::MAXLONG= 2147483647; +const double PureProjection::DBLLONG= 4.61168601e18; +const double PureProjection::R2D=180/M_PI; +const double PureProjection::D2R=M_PI/180; + +Point PureProjection::FromLatLngToPixel(const PointLatLng &p,const int &zoom) + { + return FromLatLngToPixel(p.Lat(), p.Lng(), zoom); + } + + + PointLatLng PureProjection::FromPixelToLatLng(const Point &p,const int &zoom) + { + return FromPixelToLatLng(p.X(), p.Y(), zoom); + } + + Point PureProjection::FromPixelToTileXY(const Point &p) + { + return Point((int) (p.X() / TileSize().Width()), (int) (p.Y() / TileSize().Height())); + } + + Point PureProjection::FromTileXYToPixel(const Point &p) + { + return Point((p.X() * TileSize().Width()), (p.Y() * TileSize().Height())); + } + + Size PureProjection::GetTileMatrixSizeXY(const int &zoom) + { + Size sMin = GetTileMatrixMinXY(zoom); + Size sMax = GetTileMatrixMaxXY(zoom); + + return Size(sMax.Width() - sMin.Width() + 1, sMax.Height() - sMin.Height() + 1); + } + int PureProjection::GetTileMatrixItemCount(const int &zoom) + { + Size s = GetTileMatrixSizeXY(zoom); + return (s.Width() * s.Height()); + } + Size PureProjection::GetTileMatrixSizePixel(const int &zoom) + { + Size s = GetTileMatrixSizeXY(zoom); + return Size(s.Width() * TileSize().Width(), s.Height() * TileSize().Height()); + } + QList PureProjection::GetAreaTileList(const RectLatLng &rect,const int &zoom,const int &padding) + { + QList ret; + + Point topLeft = FromPixelToTileXY(FromLatLngToPixel(rect.LocationTopLeft(), zoom)); + Point rightBottom = FromPixelToTileXY(FromLatLngToPixel(rect.Bottom(), rect.Right(), zoom)); + + for(int x = (topLeft.X() - padding); x <= (rightBottom.X() + padding); x++) + { + for(int y = (topLeft.Y() - padding); y <= (rightBottom.Y() + padding); y++) + { + Point p = Point(x, y); + if(!ret.contains(p) && p.X() >= 0 && p.Y() >= 0) + { + ret.append(p); + } + } + } + //ret.TrimExcess(); + + return ret; + } + double PureProjection::GetGroundResolution(const int &zoom,const double &latitude) + { + return (cos(latitude * (PI / 180)) * 2 * PI * Axis()) / GetTileMatrixSizePixel(zoom).Width(); + } + + double PureProjection::Sign(const double &x) + { + if(x < 0.0) + return (-1); + else + return (1); + } + + double PureProjection::AdjustLongitude(double x) + { + qlonglong count = 0; + while(true) + { + if(qAbs(x) <= PI) + break; + else + if(((qlonglong) qAbs(x / PI)) < 2) + x = x - (Sign(x) * TWO_PI); + + else + if(((qlonglong) qAbs(x / TWO_PI)) < MAXLONG) + { + x = x - (((qlonglong) (x / TWO_PI)) * TWO_PI); + } + else + if(((qlonglong) qAbs(x / (MAXLONG * TWO_PI))) < MAXLONG) + { + x = x - (((qlonglong) (x / (MAXLONG * TWO_PI))) * (TWO_PI * MAXLONG)); + } + else + if(((qlonglong) qAbs(x / (DBLLONG * TWO_PI))) < MAXLONG) + { + x = x - (((qlonglong) (x / (DBLLONG * TWO_PI))) * (TWO_PI * DBLLONG)); + } + else + x = x - (Sign(x) * TWO_PI); + count++; + if(count > MAX_VAL) + break; + } + return (x); + } + + void PureProjection::SinCos(const double &val, double &si, double &co) + { + si = sin(val); + co = cos(val); + } + + double PureProjection::e0fn(const double &x) + { + return (1.0 - 0.25 * x * (1.0 + x / 16.0 * (3.0 + 1.25 * x))); + } + + double PureProjection::e1fn(const double &x) + { + return (0.375 * x * (1.0 + 0.25 * x * (1.0 + 0.46875 * x))); + } + + double PureProjection::e2fn(const double &x) + { + return (0.05859375 * x * x * (1.0 + 0.75 * x)); + } + + double PureProjection::e3fn(const double &x) + { + return (x * x * x * (35.0 / 3072.0)); + } + + double PureProjection::mlfn(const double &e0,const double &e1,const double &e2,const double &e3,const double &phi) + { + return (e0 * phi - e1 * sin(2.0 * phi) + e2 * sin(4.0 * phi) - e3 * sin(6.0 * phi)); + } + + qlonglong PureProjection::GetUTMzone(const double &lon) + { + return ((qlonglong) (((lon + 180.0) / 6.0) + 1.0)); + } + + + void PureProjection::FromGeodeticToCartesian(double Lat,double Lng,double Height, double &X, double &Y, double &Z) + { + Lat = (PI / 180) * Lat; + Lng = (PI / 180) * Lng; + + double B = Axis() * (1.0 - Flattening()); + double ee = 1.0 - (B / Axis()) * (B / Axis()); + double N = (Axis() / sqrt(1.0 - ee * sin(Lat) * sin(Lat))); + + X = (N + Height) * cos(Lat) * cos(Lng); + Y = (N + Height) * cos(Lat) * sin(Lng); + Z = (N * (B / Axis()) * (B / Axis()) + Height) * sin(Lat); + } + void PureProjection::FromCartesianTGeodetic(const double &X,const double &Y,const double &Z, double &Lat, double &Lng) + { + double E = Flattening() * (2.0 - Flattening()); + Lng = atan2(Y, X); + + double P = sqrt(X * X + Y * Y); + double Theta = atan2(Z, (P * (1.0 - Flattening()))); + double st = sin(Theta); + double ct = cos(Theta); + Lat = atan2(Z + E / (1.0 - Flattening()) * Axis() * st * st * st, P - E * Axis() * ct * ct * ct); + + Lat /= (PI / 180); + Lng /= (PI / 180); + } + double PureProjection::DistanceBetweenLatLng(PointLatLng const& p1,PointLatLng const& p2) + { + double R = 6371; // km + double lat1=p1.Lat(); + double lat2=p2.Lat(); + double lon1=p1.Lng(); + double lon2=p2.Lng(); + double dLat = (lat2-lat1)* (PI / 180); + double dLon = (lon2-lon1)* (PI / 180); + double a = sin(dLat/2) * sin(dLat/2) + cos(lat1* (PI / 180)) * cos(lat2* (PI / 180)) * sin(dLon/2) * sin(dLon/2); + double c = 2 * atan2(sqrt(a), sqrt(1-a)); + double d = R * c; + return d; + } +} diff --git a/lib/opmapcontrol/src/internals/pureprojection.h b/lib/opmapcontrol/src/internals/pureprojection.h new file mode 100644 index 0000000000000000000000000000000000000000..4ab806a62e7bba2dd92a3473784724d87a9027d2 --- /dev/null +++ b/lib/opmapcontrol/src/internals/pureprojection.h @@ -0,0 +1,111 @@ +/** +****************************************************************************** +* +* @file pureprojection.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 PUREPROJECTION_H +#define PUREPROJECTION_H + +#include "../core/size.h" +#include "../core/point.h" +#include "../internals/pointlatlng.h" +#include "pointlatlng.h" +#include "cmath" +#include "rectlatlng.h" + +using namespace core; + +namespace internals +{ + +class PureProjection +{ + + +public: + virtual Size TileSize()const=0; + + virtual double Axis()const=0; + + virtual double Flattening()const=0; + + virtual core::Point FromLatLngToPixel(double lat, double lng, int const& zoom)=0; + + virtual PointLatLng FromPixelToLatLng(const int &x,const int &y,const int &zoom)=0; + + virtual QString Type(){return "PureProjection";} + core::Point FromLatLngToPixel(const PointLatLng &p,const int &zoom); + + PointLatLng FromPixelToLatLng(const Point &p,const int &zoom); + virtual core::Point FromPixelToTileXY(const core::Point &p); + virtual core::Point FromTileXYToPixel(const core::Point &p); + virtual Size GetTileMatrixMinXY(const int &zoom)=0; + virtual Size GetTileMatrixMaxXY(const int &zoom)=0; + virtual Size GetTileMatrixSizeXY(const int &zoom); + int GetTileMatrixItemCount(const int &zoom); + virtual Size GetTileMatrixSizePixel(const int &zoom); + QList GetAreaTileList(const RectLatLng &rect,const int &zoom,const int &padding); + virtual double GetGroundResolution(const int &zoom,const double &latitude); + + double DegreesToRadians(const double °)const + { + return (D2R * deg); + } + + double RadiansToDegrees(const double &rad)const + { + return (R2D * rad); + } + void FromGeodeticToCartesian(double Lat,double Lng,double Height, double &X, double &Y, double &Z); + void FromCartesianTGeodetic(const double &X,const double &Y,const double &Z, double &Lat, double &Lng); + static double DistanceBetweenLatLng(PointLatLng const& p1,PointLatLng const& p2); + +protected: + + static const double PI; + static const double HALF_PI; + static const double TWO_PI; + static const double EPSLoN; + static const double MAX_VAL; + static const double MAXLONG; + static const double DBLLONG; + static const double R2D; + static const double D2R; + + static double Sign(const double &x); + + static double AdjustLongitude(double x); + static void SinCos(const double &val, double &sin, double &cos); + static double e0fn(const double &x); + static double e1fn(const double &x); + static double e2fn(const double &x); + static double e3fn(const double &x); + static double mlfn(const double &e0,const double &e1,const double &e2,const double &e3,const double &phi); + static qlonglong GetUTMzone(const double &lon); + +}; +} + + +#endif // PUREPROJECTION_H diff --git a/lib/opmapcontrol/src/internals/rectangle.cpp b/lib/opmapcontrol/src/internals/rectangle.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f513b22717de2218634d06a7b76f749bd559e7bc --- /dev/null +++ b/lib/opmapcontrol/src/internals/rectangle.cpp @@ -0,0 +1,79 @@ +/** +****************************************************************************** +* +* @file rectangle.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 "rectangle.h" + +namespace internals { +Rectangle Rectangle::Empty=Rectangle(); +Rectangle Rectangle::FromLTRB(int left, int top, int right, int bottom) + { + return Rectangle(left, + top, + right - left, + bottom - top); + } +Rectangle Rectangle::Inflate(Rectangle rect, int x, int y) + { + Rectangle r = rect; + r.Inflate(x, y); + return r; + } +Rectangle Rectangle::Intersect(Rectangle a, Rectangle b) + { + int x1 = std::max(a.X(), b.X()); + int x2 = std::min(a.X() + a.Width(), b.X() + b.Width()); + int y1 = std::max(a.Y(), b.Y()); + int y2 = std::min(a.Y() + a.Height(), b.Y() + b.Height()); + + if(x2 >= x1 + && y2 >= y1) + { + + return Rectangle(x1, y1, x2 - x1, y2 - y1); + } + return Rectangle::Empty; + } +Rectangle Rectangle::Union(const Rectangle &a,const Rectangle &b) + { + int x1 = std::min(a.x, b.x); + int x2 = std::max(a.x + a.width, b.x + b.width); + int y1 = std::min(a.y, b.y); + int y2 = std::max(a.y + a.height, b.y + b.height); + + return Rectangle(x1, y1, x2 - x1, y2 - y1); + } +bool operator==(Rectangle const& lhs,Rectangle const& rhs) +{ + return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width && lhs.height == rhs.height); +} +uint qHash(Rectangle const& rect) + { + return (int) ((quint32) rect.x ^ + (((quint32) rect.y << 13) | ((quint32) rect.y >> 19)) ^ + (((quint32) rect.width << 26) | ((quint32) rect.width >> 6)) ^ + (((quint32) rect.height << 7) | ((quint32) rect.height >> 25))); + } +} diff --git a/lib/opmapcontrol/src/internals/rectangle.h b/lib/opmapcontrol/src/internals/rectangle.h new file mode 100644 index 0000000000000000000000000000000000000000..78919c1af0fc441fd98e5dde36c8d46cdcf5849a --- /dev/null +++ b/lib/opmapcontrol/src/internals/rectangle.h @@ -0,0 +1,158 @@ +/** +****************************************************************************** +* +* @file rectangle.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 RECTANGLE_H +#define RECTANGLE_H +//#include +#include "../core/size.h" +#include "math.h" +using namespace core; +namespace internals +{ +struct Rectangle +{ + + friend uint qHash(Rectangle const& rect); + friend bool operator==(Rectangle const& lhs,Rectangle const& rhs); +public: + static Rectangle Empty; + static Rectangle FromLTRB(int left, int top, int right, int bottom); + Rectangle(){x=0; y=0; width=0; height=0; }; + Rectangle(int x, int y, int width, int height) + { + this->x = x; + this->y = y; + this->width = width; + this->height = height; + } + Rectangle(core::Point location, core::Size size) + { + this->x = location.X(); + this->y = location.Y(); + this->width = size.Width(); + this->height = size.Height(); + } + core::Point GetLocation() { + return core::Point(x, y); + } + void SetLocation(const core::Point &value) + { + x = value.X(); + y = value.Y(); + } + int X(){return x;} + int Y(){return y;} + void SetX(const int &value){x=value;} + void SetY(const int &value){y=value;} + int Width(){return width;} + void SetWidth(const int &value){width=value;} + int Height(){return height;} + void SetHeight(const int &value){height=value;} + int Left(){return x;} + int Top(){return y;} + int Right(){return x+width;} + int Bottom(){return y+height;} + bool IsEmpty(){return (height==0 && width==0 && x==0 && y==0);} + bool operator==(const Rectangle &cSource) + { + return (cSource.x == x && cSource.y == y && cSource.width == width && cSource.height == height); + } + + + bool operator!=(const Rectangle &cSource){return !(*this==cSource);} + bool Contains(const int &x,const int &y) + { + return this->x<=x && xx+this->width && this->y<=y && yy+this->height; + } + bool Contains(const core::Point &pt) + { + return Contains(pt.X(),pt.Y()); + } + bool Contains(const Rectangle &rect) + { + return (this->x <= rect.x) && + ((rect.x + rect.width) <= (this->x + this->width)) && + (this->y <= rect.y) && + ((rect.y + rect.height) <= (this->y + this->height)); + } + + + void Inflate(const int &width,const int &height) + { + this->x -= width; + this->y -= height; + this->width += 2*width; + this->height += 2*height; + } + void Inflate(Size &size) + { + + Inflate(size.Width(), size.Height()); + } + static Rectangle Inflate(Rectangle rect, int x, int y); + + void Intersect(const Rectangle &rect) + { + Rectangle result = Rectangle::Intersect(rect, *this); + + this->x = result.X(); + this->y = result.Y(); + this->width = result.Width(); + this->height = result.Height(); + } + static Rectangle Intersect(Rectangle a, Rectangle b); + bool IntersectsWith(const Rectangle &rect) + { + return (rect.x < this->x + this->width) && + (this->x < (rect.x + rect.width)) && + (rect.y < this->y + this->height) && + (this->y < rect.y + rect.height); + } + static Rectangle Union(const Rectangle &a,const Rectangle &b); + void Offset(const core::Point &pos) + { + Offset(pos.X(), pos.Y()); + } + + void Offset(const int &x,const int &y) + { + this->x += x; + this->y += y; + } + QString ToString() + { + return "{X=" + QString::number(x) + ",Y=" + QString::number(y) + + ",Width=" + QString::number(width) + + ",Height=" +QString::number(height) +"}"; + } +private: + int x; + int y; + int width; + int height; +}; +} +#endif // RECTANGLE_H diff --git a/lib/opmapcontrol/src/internals/rectlatlng.cpp b/lib/opmapcontrol/src/internals/rectlatlng.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2d98772622282e1ab46756b1722434cc29de701a --- /dev/null +++ b/lib/opmapcontrol/src/internals/rectlatlng.cpp @@ -0,0 +1,48 @@ +/** +****************************************************************************** +* +* @file rectlatlng.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 "rectlatlng.h" + + + +namespace internals { +RectLatLng RectLatLng::Empty=RectLatLng(); +uint qHash(RectLatLng const& rect) +{ + return (int) (((((uint) rect.Lng()) ^ ((((uint) rect.Lat()) << 13) | (((uint) rect.Lat()) >> 0x13))) ^ ((((uint) rect.WidthLng()) << 0x1a) | (((uint) rect.WidthLng()) >> 6))) ^ ((((uint) rect.HeightLat()) << 7) | (((uint) rect.HeightLat()) >> 0x19))); +} + +bool operator==(RectLatLng const& left,RectLatLng const& right) +{ + return ((((left.Lng() == right.Lng()) && (left.Lat() == right.Lat())) && (left.WidthLng() == right.WidthLng())) && (left.HeightLat() == right.HeightLat())); +} + +bool operator!=(RectLatLng const& left,RectLatLng const& right) +{ + return !(left == right); +} + +} diff --git a/lib/opmapcontrol/src/internals/rectlatlng.h b/lib/opmapcontrol/src/internals/rectlatlng.h new file mode 100644 index 0000000000000000000000000000000000000000..bbc86bac1df14f8860943cfd8b9b8aa9e0a2ccce --- /dev/null +++ b/lib/opmapcontrol/src/internals/rectlatlng.h @@ -0,0 +1,264 @@ +/** +****************************************************************************** +* +* @file rectlatlng.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 RECTLATLNG_H +#define RECTLATLNG_H + +//#include "pointlatlng.h" +#include "../internals/pointlatlng.h" +#include "math.h" +#include +#include "sizelatlng.h" + +namespace internals { +struct RectLatLng +{ +public: + static RectLatLng Empty; + friend uint qHash(RectLatLng const& rect); + friend bool operator==(RectLatLng const& left,RectLatLng const& right); + friend bool operator!=(RectLatLng const& left,RectLatLng const& right); + RectLatLng(double const& lat, double const& lng, double const& widthLng, double const& heightLat) + { + this->lng = lng; + this->lat = lat; + this->widthLng = widthLng; + this->heightLat = heightLat; + isempty=false; + } + RectLatLng(PointLatLng const& location, SizeLatLng const& size) + { + this->lng = location.Lng(); + this->lat = location.Lat(); + this->widthLng = size.WidthLng(); + this->heightLat = size.HeightLat(); + isempty=false; + } + RectLatLng() + { + this->lng = 0; + this->lat = 0; + this->widthLng = 0; + this->heightLat = 0; + isempty=true; + } + + static RectLatLng FromLTRB(double const& lng, double const& lat, double const& rightLng, double const& bottomLat) + { + return RectLatLng(lat, lng, rightLng - lng, lat - bottomLat); + } + PointLatLng LocationTopLeft()const + { + return PointLatLng(this->lat, this->lng); + } + void SetLocationTopLeft(PointLatLng const& value) + { + this->lng = value.Lng(); + this->lat = value.Lat(); + isempty=false; + } + PointLatLng LocationRightBottom() + { + + PointLatLng ret = PointLatLng(this->lat, this->lng); + ret.Offset(HeightLat(), WidthLng()); + return ret; + } + SizeLatLng Size() + { + return SizeLatLng(this->HeightLat(), this->WidthLng()); + } + void SetSize(SizeLatLng const& value) + { + this->widthLng = value.WidthLng(); + this->heightLat = value.HeightLat(); + isempty=false; + } + double Lng()const + { + return this->lng; + } + void SetLng(double const& value) + { + this->lng = value; + isempty=false; + } + + + double Lat()const + { + return this->lat; + } + void SetLat(double const& value) + { + this->lat = value; + isempty=false; + } + + double WidthLng()const + { + return this->widthLng; + } + void SetWidthLng(double const& value) + { + this->widthLng = value; + isempty=false; + } + double HeightLat()const + { + return this->heightLat; + } + void SetHeightLat(double const& value) + { + this->heightLat = value; + isempty=false; + } + double Left()const + { + return this->Lng(); + } + + double Top()const + { + return this->Lat(); + } + + double Right()const + { + return (this->Lng() + this->WidthLng()); + } + + double Bottom()const + { + return (this->Lat() - this->HeightLat()); + } + bool IsEmpty()const + { + return isempty; + } + bool Contains(double const& lat, double const& lng) + { + return ((((this->Lng() <= lng) && (lng < (this->Lng() + this->WidthLng()))) && (this->Lat() >= lat)) && (lat > (this->Lat() - this->HeightLat()))); + } + + bool Contains(PointLatLng const& pt) + { + return this->Contains(pt.Lat(), pt.Lng()); + } + + bool Contains(RectLatLng const& rect) + { + return ((((this->Lng() <= rect.Lng()) && ((rect.Lng() + rect.WidthLng()) <= (this->Lng() + this->WidthLng()))) && (this->Lat() >= rect.Lat())) && ((rect.Lat() - rect.HeightLat()) >= (this->Lat() - this->HeightLat()))); + } + void Inflate(double const& lat, double const& lng) + { + this->lng -= lng; + this->lat += lat; + this->widthLng += (double)2 * lng; + this->heightLat +=(double)2 * lat; + } + + void Inflate(SizeLatLng const& size) + { + this->Inflate(size.HeightLat(), size.WidthLng()); + } + + static RectLatLng Inflate(RectLatLng const& rect, double const& lat, double const& lng) + { + RectLatLng ef = rect; + ef.Inflate(lat, lng); + return ef; + } + + void Intersect(RectLatLng const& rect) + { + RectLatLng ef = Intersect(rect, *this); + this->lng = ef.Lng(); + this->lat = ef.Lat(); + this->widthLng = ef.WidthLng(); + this->heightLat = ef.HeightLat(); + } + static RectLatLng Intersect(RectLatLng const& a, RectLatLng const& b) + { + double lng = std::max(a.Lng(), b.Lng()); + double num2 = std::min((double) (a.Lng() + a.WidthLng()), (double) (b.Lng() + b.WidthLng())); + + double lat = std::max(a.Lat(), b.Lat()); + double num4 = std::min((double) (a.Lat() + a.HeightLat()), (double) (b.Lat() + b.HeightLat())); + + if((num2 >= lng) && (num4 >= lat)) + { + return RectLatLng(lng, lat, num2 - lng, num4 - lat); + } + return Empty; + } + bool IntersectsWith(RectLatLng const& rect) + { + return ((((rect.Lng() < (this->Lng() + this->WidthLng())) && (this->Lng() < (rect.Lng() + rect.WidthLng()))) && (rect.Lat() < (this->Lat() + this->HeightLat()))) && (this->Lat() < (rect.Lat() + rect.HeightLat()))); + } + + static RectLatLng Union(RectLatLng const& a, RectLatLng const& b) + { + double lng = std::min(a.Lng(), b.Lng()); + double num2 = std::max((double) (a.Lng() + a.WidthLng()), (double) (b.Lng() + b.WidthLng())); + double lat = std::min(a.Lat(), b.Lat()); + double num4 = std::max((double) (a.Lat() + a.HeightLat()), (double) (b.Lat() + b.HeightLat())); + return RectLatLng(lng, lat, num2 - lng, num4 - lat); + } + void Offset(PointLatLng const& pos) + { + this->Offset(pos.Lat(), pos.Lng()); + } + + void Offset(double const& lat, double const& lng) + { + this->lng += lng; + this->lat -= lat; + } + + QString ToString() const + { + return ("{Lat=" + QString::number(this->Lat()) + ",Lng=" + QString::number(this->Lng()) + ",WidthLng=" + QString::number(this->WidthLng()) + ",HeightLat=" + QString::number(this->HeightLat()) + "}"); + } + +private: + double lng; + double lat; + double widthLng; + double heightLat; + bool isempty; +}; + +} +#endif // RECTLATLNG_H + + + +// static RectLatLng() +// { +// Empty = new RectLatLng(); +// } +// } diff --git a/lib/opmapcontrol/src/internals/sizelatlng.cpp b/lib/opmapcontrol/src/internals/sizelatlng.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9222c37045bf59518fac22002e2f97d8e7384dd9 --- /dev/null +++ b/lib/opmapcontrol/src/internals/sizelatlng.cpp @@ -0,0 +1,60 @@ +/** +****************************************************************************** +* +* @file sizelatlng.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 "sizelatlng.h" +#include "pointlatlng.h" + +namespace internals { +SizeLatLng::SizeLatLng():heightLat(0),widthLng(0) +{ + +} +SizeLatLng::SizeLatLng(PointLatLng const& pt) +{ + this->heightLat = pt.Lat(); + this->widthLng = pt.Lng(); +} +SizeLatLng operator+(SizeLatLng const& sz1, SizeLatLng const& sz2) +{ + return SizeLatLng::Add(sz1, sz2); +} + +SizeLatLng operator-(SizeLatLng const& sz1, SizeLatLng const& sz2) +{ + return SizeLatLng::Subtract(sz1, sz2); +} + +bool operator==(SizeLatLng const& sz1, SizeLatLng const& sz2) +{ + return ((sz1.WidthLng() == sz2.WidthLng()) && (sz1.HeightLat() == sz2.HeightLat())); +} + +bool operator!=(SizeLatLng const& sz1, SizeLatLng const& sz2) +{ + return !(sz1 == sz2); +} +SizeLatLng SizeLatLng::Empty=SizeLatLng(); +} diff --git a/lib/opmapcontrol/src/internals/sizelatlng.h b/lib/opmapcontrol/src/internals/sizelatlng.h new file mode 100644 index 0000000000000000000000000000000000000000..4ee5388cc99152dadd68a4d873ce79c6ecd5cf35 --- /dev/null +++ b/lib/opmapcontrol/src/internals/sizelatlng.h @@ -0,0 +1,136 @@ +/** +****************************************************************************** +* +* @file sizelatlng.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 SIZELATLNG_H +#define SIZELATLNG_H + + +#include + + +namespace internals { +struct PointLatLng; +struct SizeLatLng +{ +public: + SizeLatLng(); + static SizeLatLng Empty; + + SizeLatLng(SizeLatLng const& size) + { + this->widthLng = size.widthLng; + this->heightLat = size.heightLat; + } + + SizeLatLng(PointLatLng const& pt); + + + SizeLatLng(double const& heightLat, double const& widthLng) + { + this->heightLat = heightLat; + this->widthLng = widthLng; + } + + friend SizeLatLng operator+(SizeLatLng const& sz1, SizeLatLng const& sz2); + friend SizeLatLng operator-(SizeLatLng const& sz1, SizeLatLng const& sz2); + friend bool operator==(SizeLatLng const& sz1, SizeLatLng const& sz2); + friend bool operator!=(SizeLatLng const& sz1, SizeLatLng const& sz2); + + +// static explicit operator PointLatLng(SizeLatLng size) +// { +// return new PointLatLng(size.HeightLat(), size.WidthLng()); +// } + + + bool IsEmpty()const + { + return ((this->widthLng == 0) && (this->heightLat == 0)); + } + + double WidthLng()const + { + return this->widthLng; + } + void SetWidthLng(double const& value) + { + this->widthLng = value; + } + + + double HeightLat()const + { + return this->heightLat; + } + void SetHeightLat(double const& value) + { + this->heightLat = value; + } + + static SizeLatLng Add(SizeLatLng const& sz1, SizeLatLng const& sz2) + { + return SizeLatLng(sz1.HeightLat() + sz2.HeightLat(), sz1.WidthLng() + sz2.WidthLng()); + } + + static SizeLatLng Subtract(SizeLatLng const& sz1, SizeLatLng const& sz2) + { + return SizeLatLng(sz1.HeightLat() - sz2.HeightLat(), sz1.WidthLng() - sz2.WidthLng()); + } + +// override bool Equals(object obj) +// { +// if(!(obj is SizeLatLng)) +// { +// return false; +// } +// SizeLatLng ef = (SizeLatLng) obj; +// return (((ef.WidthLng == this->WidthLng) && (ef.HeightLat == this->HeightLat)) && ef.GetType().Equals(base.GetType())); +// } + +// override int GetHashCode() +// { +// return base.GetHashCode(); +// } + +// PointLatLng ToPointLatLng() +// { +// return (PointLatLng) this; +// } + + QString ToString() + { + return ("{WidthLng=" + QString::number(this->widthLng) + ", HeightLng=" + QString::number(this->heightLat) + "}"); + } + + +private: + double heightLat; + double widthLng; +}; + +} +#endif // SIZELATLNG_H + diff --git a/lib/opmapcontrol/src/internals/tile.cpp b/lib/opmapcontrol/src/internals/tile.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5d8289e71601ad572afa5e86ebad1f366db6a82c --- /dev/null +++ b/lib/opmapcontrol/src/internals/tile.cpp @@ -0,0 +1,60 @@ +/** +****************************************************************************** +* +* @file tile.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 "tile.h" + + +namespace internals { +Tile::Tile(int zoom, Point pos) +{ + this->zoom=zoom; + this->pos=pos; +} +void Tile::Clear() +{ +#ifdef DEBUG_TILE + qDebug()<<"Tile:Clear Overlays"; +#endif //DEBUG_TILE + mutex.lock(); + foreach(QByteArray img, Overlays) + { + img.~QByteArray(); + } + Overlays.clear(); + mutex.unlock(); +} +Tile::Tile():zoom(0),pos(0,0) +{ + +} +Tile& Tile::operator =(const Tile &cSource) +{ + this->zoom=cSource.zoom; + this->pos=cSource.pos; + return *this; +} + +} diff --git a/lib/opmapcontrol/src/internals/tile.h b/lib/opmapcontrol/src/internals/tile.h new file mode 100644 index 0000000000000000000000000000000000000000..6b1ae2023e77efb34b37c0cf1774e813fce49db3 --- /dev/null +++ b/lib/opmapcontrol/src/internals/tile.h @@ -0,0 +1,67 @@ +/** +****************************************************************************** +* +* @file tile.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 TILE_H +#define TILE_H + +#include "QList" +#include +#include "../core/point.h" +#include +#include +#include "debugheader.h" +using namespace core; +namespace internals +{ +class Tile +{ +public: + Tile(int zoom,core::Point pos); + Tile(); + void Clear(); + int GetZoom(){return zoom;} + core::Point GetPos(){return pos;} + void SetZoom(const int &value){zoom=value;} + void SetPos(const core::Point &value){pos=value;} + Tile& operator= (const Tile &cSource); + Tile(const Tile &cSource) + { + this->zoom=cSource.zoom; + this->pos=cSource.pos; + } + bool HasValue(){return !(zoom==0);} + QList Overlays; +protected: + + QMutex mutex; +private: + int zoom; + core::Point pos; + + +}; +} +#endif // TILE_H diff --git a/lib/opmapcontrol/src/internals/tilematrix.cpp b/lib/opmapcontrol/src/internals/tilematrix.cpp new file mode 100644 index 0000000000000000000000000000000000000000..658d3be95b18779893c74183454cc1babadd9f65 --- /dev/null +++ b/lib/opmapcontrol/src/internals/tilematrix.cpp @@ -0,0 +1,148 @@ +/** +****************************************************************************** +* +* @file tilematrix.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 "tilematrix.h" + + +namespace internals { +TileMatrix::TileMatrix() +{ +} +void TileMatrix::Clear() +{ + mutex.lock(); + foreach(Tile* t,matrix.values()) + { + delete t; + t=0; + } + matrix.clear(); + mutex.unlock(); +} +//void TileMatrix::RebuildToUpperZoom() +//{ +// mutex.lock(); +// QList newtiles; +// foreach(Tile* t,matrix.values()) +// { +// Point point=Point(t->GetPos().X()*2,t->GetPos().Y()*2); +// Tile* tile1=new Tile(t->GetZoom()+1,point); +// Tile* tile2=new Tile(t->GetZoom()+1,Point(point.X()+1,point.Y()+0)); +// Tile* tile3=new Tile(t->GetZoom()+1,Point(point.X()+0,point.Y()+1)); +// Tile* tile4=new Tile(t->GetZoom()+1,Point(point.X()+1,point.Y()+1)); +// +// foreach(QByteArray arr, t->Overlays) +// { +// QImage ima=QImage::fromData(arr); +// QImage ima1=ima.copy(0,0,ima.width()/2,ima.height()/2); +// QImage ima2=ima.copy(ima.width()/2,0,ima.width()/2,ima.height()/2); +// QImage ima3=ima.copy(0,ima.height()/2,ima.width()/2,ima.height()/2); +// QImage ima4=ima.copy(ima.width()/2,ima.height()/2,ima.width()/2,ima.height()/2); +// QByteArray ba; +// QBuffer buf(&ba); +// ima1.scaled(QSize(ima.width(),ima.height())).save(&buf,"PNG"); +// tile1->Overlays.append(ba); +// QByteArray ba1; +// QBuffer buf1(&ba1); +// ima2.scaled(QSize(ima.width(),ima.height())).save(&buf1,"PNG"); +// tile2->Overlays.append(ba1); +// QByteArray ba2; +// QBuffer buf2(&ba2); +// ima3.scaled(QSize(ima.width(),ima.height())).save(&buf2,"PNG"); +// tile3->Overlays.append(ba2); +// QByteArray ba3; +// QBuffer buf3(&ba3); +// ima4.scaled(QSize(ima.width(),ima.height())).save(&buf3,"PNG"); +// tile4->Overlays.append(ba3); +// newtiles.append(tile1); +// newtiles.append(tile2); +// newtiles.append(tile3); +// newtiles.append(tile4); +// } +// } +// foreach(Tile* t,matrix.values()) +// { +// delete t; +// t=0; +// } +// matrix.clear(); +// foreach(Tile* t,newtiles) +// { +// matrix.insert(t->GetPos(),t); +// } +// +// mutex.unlock(); +//} + +void TileMatrix::ClearPointsNotIn(QListlist) +{ + removals.clear(); + mutex.lock(); + foreach(Point p, matrix.keys()) + { + if(!list.contains(p)) + { + removals.append(p); + } + } + mutex.unlock(); + foreach(Point p,removals) + { + Tile* t=TileAt(p); + if(t!=0) + { + mutex.lock(); + delete t; + t=0; + matrix.remove(p); + mutex.unlock(); + } + + } + removals.clear(); +} +Tile* TileMatrix::TileAt(const Point &p) +{ + +#ifdef DEBUG_TILEMATRIX + qDebug()<<"TileMatrix:TileAt:"< +#include "tile.h" +#include +#include "../core/point.h" +#include "debugheader.h" +#include +namespace internals { +class TileMatrix +{ +public: + TileMatrix(); + void Clear(); + void ClearPointsNotIn(QList list); + Tile* TileAt(const core::Point &p); + void SetTileAt(const core::Point &p,Tile* tile); + int count()const{return matrix.count();} + // void RebuildToUpperZoom(); +protected: + QHash matrix; + QList removals; + QMutex mutex; +}; + +} +#endif // TILEMATRIX_H diff --git a/lib/opmapcontrol/src/mapwidget/configuration.cpp b/lib/opmapcontrol/src/mapwidget/configuration.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2dd1b95b4add0433aaefd05918ebcb80bdf565a5 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/configuration.cpp @@ -0,0 +1,60 @@ +/** +****************************************************************************** +* +* @file configuration.cpp +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief A class that centralizes most of the mapcontrol configurations +* @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 "configuration.h" +namespace mapcontrol +{ +Configuration::Configuration() +{ + EmptytileBrush = Qt::cyan; + MissingDataFont =QFont ("Times",10,QFont::Bold); + EmptyTileText = "We are sorry, but we don't\nhave imagery at this zoom\nlevel for this region."; + EmptyTileBorders = QPen(Qt::white); + ScalePen = QPen(Qt::blue); + SelectionPen = QPen(Qt::blue); + DragButton = Qt::LeftButton; +} +void Configuration::SetAccessMode(core::AccessMode::Types const& type) +{ + core::OPMaps::Instance()->setAccessMode(type); +} +core::AccessMode::Types Configuration::AccessMode() +{ + return core::OPMaps::Instance()->GetAccessMode(); +} +void Configuration::SetLanguage(core::LanguageType::Types const& type) +{ + core::OPMaps::Instance()->setLanguage(type); +} +core::LanguageType::Types Configuration::Language() +{ + return core::OPMaps::Instance()->GetLanguage(); +} +void Configuration::SetUseMemoryCache(bool const& value) +{ + core::OPMaps::Instance()->setUseMemoryCache(value); +} +} diff --git a/lib/opmapcontrol/src/mapwidget/configuration.h b/lib/opmapcontrol/src/mapwidget/configuration.h new file mode 100644 index 0000000000000000000000000000000000000000..46dd0d03c3f4aafc7216ece18eb047675a560ef0 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/configuration.h @@ -0,0 +1,186 @@ +/** +****************************************************************************** +* +* @file configuration.h +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief A class that centralizes most of the mapcontrol configurations +* @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 CONFIGURATION_H +#define CONFIGURATION_H + +#include +#include +#include +#include +#include "../core/opmaps.h" +#include "../core/accessmode.h" +#include "../core/cache.h" +namespace mapcontrol +{ + +/** +* @brief A class that centralizes most of the mapcontrol configurations +* +* @class Configuration configuration.h "configuration.h" +*/ +class Configuration +{ +public: + Configuration(); + /** + * @brief Used to draw empty map tiles + * + * @var EmptytileBrush + */ + QBrush EmptytileBrush; + /** + * @brief Used for empty tiles text + * + * @var EmptyTileText + */ + QString EmptyTileText; + /** + * @brief Used to draw empty tile borders + * + * @var EmptyTileBorders + */ + QPen EmptyTileBorders; + /** + * @brief Used to Draw the maps scale + * + * @var ScalePen + */ + QPen ScalePen; + /** + * @brief Used to draw selection box + * + * @var SelectionPen + */ + QPen SelectionPen; + /** + * @brief + * + * @var MissingDataFont + */ + QFont MissingDataFont; + + /** + * @brief Button used for dragging + * + * @var DragButton + */ + Qt::MouseButton DragButton; + + /** + * @brief Sets the access mode for the map (cache only, server and cache...) + * + * @param type access mode + */ + void SetAccessMode(core::AccessMode::Types const& type); + /** + * @brief Returns the access mode for the map (cache only, server and cache...) + * + * @return core::AccessMode::Types access mode for the map + */ + core::AccessMode::Types AccessMode(); + + /** + * @brief Sets the language used for geocaching + * + * @param type The language to be used + */ + void SetLanguage(core::LanguageType::Types const& type); + /** + * @brief Returns the language used for geocaching + * + * @return core::LanguageType::Types + */ + core::LanguageType::Types Language(); + + /** + * @brief Used to allow disallow use of memory caching + * + * @param value + * @return + */ + void SetUseMemoryCache(bool const& value); + /** + * @brief Return if memory caching is in use + * + * @return + */ + bool UseMemoryCache(){return core::OPMaps::Instance()->UseMemoryCache();} + + /** + * @brief Returns the currently used memory for tiles + * + * @return + */ + double TileMemoryUsed()const{return core::OPMaps::Instance()->TilesInMemory.MemoryCacheSize();} + + /** + * @brief Sets the size of the memory for tiles + * + * @param value size in Mb to use for tiles + * @return + */ + void SetTileMemorySize(int const& value){core::OPMaps::Instance()->TilesInMemory.setMemoryCacheCapacity(value);} + + /** + * @brief Sets the location for the SQLite Database used for caching and the geocoding cache files + * + * @param dir The path location for the cache file-IMPORTANT Must end with closing slash "/" + */ + void SetCacheLocation(QString const& dir) + { + core::Cache::Instance()->setCacheLocation(dir); + + } + + /** + * @brief Deletes tiles in DataBase older than "days" days + * + * @param days + * @return + */ + void DeleteTilesOlderThan(int const& days){core::Cache::Instance()->ImageCache.deleteOlderTiles(days);} + + /** + * @brief Exports tiles from one DB to another. Only new tiles are added. + * + * @param sourceDB the source DB + * @param destDB the destination DB. If it doesnt exhist it will be created. + * @return + */ + void ExportMapDataToDB(QString const& sourceDB, QString const& destDB)const{core::PureImageCache::ExportMapDataToDB(sourceDB,destDB);} + /** + * @brief Returns the location for the SQLite Database used for caching and the geocoding cache files + * + * @return + */ + QString CacheLocation(){return core::Cache::Instance()->CacheLocation();} + + +}; +} +#endif // CONFIGURATION_H diff --git a/lib/opmapcontrol/src/mapwidget/gpsitem.cpp b/lib/opmapcontrol/src/mapwidget/gpsitem.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9e247c08a8acdd6fe33c065f0e0777a9c1472eab --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/gpsitem.cpp @@ -0,0 +1,199 @@ +/** +****************************************************************************** +* +* @file gpsitem.cpp +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief A graphicsItem representing a UAV +* @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 "../internals/pureprojection.h" +#include "gpsitem.h" +namespace mapcontrol +{ + GPSItem::GPSItem(MapGraphicItem* map,OPMapWidget* parent):map(map),mapwidget(parent),showtrail(true),trailtime(5),traildistance(50),autosetreached(true) + ,autosetdistance(100) + { + pic.load(QString::fromUtf8(":/markers/images/mapquad.png")); + // Don't scale but trust the image we are given + // pic=pic.scaled(50,33,Qt::IgnoreAspectRatio); + localposition=map->FromLatLngToLocal(mapwidget->CurrentPosition()); + this->setPos(localposition.X(),localposition.Y()); + this->setZValue(4); + trail=new QGraphicsItemGroup(); + trail->setParentItem(map); + + + this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); + mapfollowtype=UAVMapFollowType::None; + trailtype=UAVTrailType::ByDistance; + timer.start(); + + // rect=QRectF(0,0,renderer.defaultSize().width()*0.05,renderer.defaultSize().height()*0.05); + + } + GPSItem::~GPSItem() + { + delete trail; + } + + void GPSItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + { + Q_UNUSED(option); + Q_UNUSED(widget); + // painter->rotate(-90); + painter->drawPixmap(-pic.width()/2,-pic.height()/2,pic); + // painter->drawRect(QRectF(-pic.width()/2,-pic.height()/2,pic.width()-1,pic.height()-1)); + } + QRectF GPSItem::boundingRect()const + { + return QRectF(-pic.width()/2,-pic.height()/2,pic.width(),pic.height()); + } + void GPSItem::SetUAVPos(const internals::PointLatLng &position, const int &altitude) + { + if(coord.IsEmpty()) + lastcoord=coord; + if(coord!=position) + { + + if(trailtype==UAVTrailType::ByTimeElapsed) + { + if(timer.elapsed()>trailtime*1000) + { + trail->addToGroup(new TrailItem(position,altitude,Qt::green,this)); + timer.restart(); + } + + } + else if(trailtype==UAVTrailType::ByDistance) + { + if(qAbs(internals::PureProjection::DistanceBetweenLatLng(lastcoord,position)*1000)>traildistance) + { + trail->addToGroup(new TrailItem(position,altitude,Qt::green,this)); + lastcoord=position; + } + } + coord=position; + this->altitude=altitude; + RefreshPos(); + /*if(mapfollowtype==UAVMapFollowType::CenterAndRotateMap||mapfollowtype==UAVMapFollowType::CenterMap) + { + mapwidget->SetCurrentPosition(coord); + }*/ + this->update(); + /*if(autosetreached) + { + foreach(QGraphicsItem* i,map->childItems()) + { + WayPointItem* wp=qgraphicsitem_cast(i); + if(wp) + { + if(Distance3D(wp->Coord(),wp->Altitude())SetReached(true); + emit UAVReachedWayPoint(wp->Number(),wp); + } + } + } + } + if(mapwidget->Home!=0) + { + //verify if the UAV is inside the safety bouble + if(Distance3D(mapwidget->Home->Coord(),mapwidget->Home->Altitude())>mapwidget->Home->SafeArea()) + { + if(mapwidget->Home->safe!=false) + { + mapwidget->Home->safe=false; + mapwidget->Home->update(); + emit UAVLeftSafetyBouble(this->coord); + } + } + else + { + if(mapwidget->Home->safe!=true) + { + mapwidget->Home->safe=true; + mapwidget->Home->update(); + } + } + + }*/ + } + } + + /** + * Rotate the UAV Icon on the map, or rotate the map + * depending on the display mode + */ + void GPSItem::SetUAVHeading(const qreal &value) + { + if(mapfollowtype==UAVMapFollowType::CenterAndRotateMap) + { + mapwidget->SetRotate(-value); + } + else { + if (this->rotation() != value) + this->setRotation(value); + } + } + + + int GPSItem::type()const + { + return Type; + } + + + void GPSItem::RefreshPos() + { + localposition=map->FromLatLngToLocal(coord); + this->setPos(localposition.X(),localposition.Y()); + foreach(QGraphicsItem* i,trail->childItems()) + { + TrailItem* w=qgraphicsitem_cast(i); + if(w) + w->setPos(map->FromLatLngToLocal(w->coord).X(),map->FromLatLngToLocal(w->coord).Y()); + //this->update(); + } + + } + void GPSItem::SetTrailType(const UAVTrailType::Types &value) + { + trailtype=value; + if(trailtype==UAVTrailType::ByTimeElapsed) + timer.restart(); + } + void GPSItem::SetShowTrail(const bool &value) + { + showtrail=value; + trail->setVisible(value); + } + void GPSItem::DeleteTrail()const + { + foreach(QGraphicsItem* i,trail->childItems()) + delete i; + } + double GPSItem::Distance3D(const internals::PointLatLng &coord, const int &altitude) + { + return sqrt(pow(internals::PureProjection::DistanceBetweenLatLng(this->coord,coord)*1000,2)+ + pow(this->altitude-altitude,2)); + + } +} diff --git a/lib/opmapcontrol/src/mapwidget/gpsitem.h b/lib/opmapcontrol/src/mapwidget/gpsitem.h new file mode 100644 index 0000000000000000000000000000000000000000..2c3439fc5281a66d86277e50090bac4904b1ce82 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/gpsitem.h @@ -0,0 +1,209 @@ +/** +****************************************************************************** +* +* @file gpsitem.h +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief A graphicsItem representing a WayPoint +* @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 GPSITEM_H +#define GPSITEM_H + +#include +#include +#include +#include "../internals/pointlatlng.h" +#include "mapgraphicitem.h" +#include "waypointitem.h" +#include +#include "uavmapfollowtype.h" +#include "uavtrailtype.h" +#include +#include "opmapwidget.h" +#include "trailitem.h" +namespace mapcontrol +{ + class WayPointItem; + class OPMapWidget; + /** +* @brief A QGraphicsItem representing the UAV +* +* @class UAVItem gpsitem.h "mapwidget/gpsitem.h" +*/ + class GPSItem:public QObject,public QGraphicsItem + { + Q_OBJECT + Q_INTERFACES(QGraphicsItem) + public: + enum { Type = UserType + 2 }; + GPSItem(MapGraphicItem* map,OPMapWidget* parent); + ~GPSItem(); + /** + * @brief Sets the UAV position + * + * @param position LatLng point + * @param altitude altitude in meters + */ + void SetUAVPos(internals::PointLatLng const& position,int const& altitude); + /** + * @brief Sets the UAV heading + * + * @param value heading angle (north=0deg) + */ + void SetUAVHeading(qreal const& value); + /** + * @brief Returns the UAV position + * + * @return internals::PointLatLng + */ + internals::PointLatLng UAVPos()const{return coord;} + /** + * @brief Sets the Map follow type + * + * @param value can be "none"(map doesnt follow UAV), "CenterMap"(map moves to keep UAV centered) or "CenterAndRotateMap"(map moves and rotates to keep UAV centered and straight) + */ + void SetMapFollowType(UAVMapFollowType::Types const& value){mapfollowtype=value;} + /** + * @brief Sets the trail type + * + * @param value can be "NoTrail"(no trail is plotted), "ByTimeElapsed"(a trail point is plotted each TrailTime()) or ByDistance(a trail point is plotted if the distance between the UAV and the last trail point is bigger than TrailDistance()) + */ + void SetTrailType(UAVTrailType::Types const& value); + /** + * @brief Returns the map follow method used + * + * @return UAVMapFollowType::Types + */ + UAVMapFollowType::Types GetMapFollowType()const{return mapfollowtype;} + /** + * @brief Returns the UAV trail type. It can be plotted by time elapsed or distance + * + * @return UAVTrailType::Types + */ + UAVTrailType::Types GetTrailType()const{return trailtype;} + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget); + void RefreshPos(); + QRectF boundingRect() const; + /** + * @brief Sets the trail time to be used if TrailType is ByTimeElapsed + * + * @param seconds the UAV trail time elapsed value. If the trail type is time elapsed + * a trail point will be plotted each "value returned" seconds. + */ + void SetTrailTime(int const& seconds){trailtime=seconds;} + /** + * @brief Returns the UAV trail time elapsed value. If the trail type is time elapsed + * a trail point will be plotted each "value returned" seconds. + * + * @return int + */ + int TrailTime()const{return trailtime;} + /** + * @brief Sets the trail distance to be used if TrailType is ByDistance + * + * @param distance the UAV trail plot distance. + * If the trail type is ByDistance a trail dot is plotted if + * the distance between the current UAV position and the last trail point + * is bigger than the returned value + */ + void SetTrailDistance(int const& distance){traildistance=distance;} + /** + * @brief Returns the UAV trail plot distance. + * If the trail type is distance diference a trail dot is plotted if + * the distance between the current UAV position and the last trail point + * is bigger than the returned value + * + * @return int + */ + int TrailDistance()const{return traildistance;} + /** + * @brief Returns true if UAV trail is shown + * + * @return bool + */ + bool ShowTrail()const{return showtrail;} + /** + * @brief Used to define if the UAV displays a trail + * + * @param value + */ + void SetShowTrail(bool const& value); + /** + * @brief Deletes all the trail points + */ + void DeleteTrail()const; + /** + * @brief Returns true if the UAV automaticaly sets WP reached value (changing its color) + * + * @return bool + */ + bool AutoSetReached()const{return autosetreached;} + /** + * @brief Defines if the UAV can set the WP's "reached" value automaticaly. + * + * @param value + */ + void SetAutoSetReached(bool const& value){autosetreached=value;} + /** + * @brief Returns the 3D distance in meters necessary for the UAV to set WP's to "reached" + * + * @return double + */ + double AutoSetDistance()const{return autosetdistance;} + /** + * @brief Sets the the 3D distance in meters necessary for the UAV to set WP's to "reached" + * + * @param value + */ + void SetAutoSetDistance(double const& value){autosetdistance=value;} + + int type() const; + private: + MapGraphicItem* map; + + int altitude; + UAVMapFollowType::Types mapfollowtype; + UAVTrailType::Types trailtype; + internals::PointLatLng coord; + internals::PointLatLng lastcoord; + QPixmap pic; + core::Point localposition; + OPMapWidget* mapwidget; + QGraphicsItemGroup* trail; + QTime timer; + bool showtrail; + int trailtime; + int traildistance; + bool autosetreached; + double Distance3D(internals::PointLatLng const& coord, int const& altitude); + double autosetdistance; + // QRectF rect; + + public slots: + + signals: + void UAVReachedWayPoint(int const& waypointnumber,WayPointItem* waypoint); + void UAVLeftSafetyBouble(internals::PointLatLng const& position); + }; +} +#endif // GPSITEM_H diff --git a/lib/opmapcontrol/src/mapwidget/homeitem.cpp b/lib/opmapcontrol/src/mapwidget/homeitem.cpp new file mode 100644 index 0000000000000000000000000000000000000000..815aa86f3dca7cb53e12a6595ed4d0790c08b2f8 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/homeitem.cpp @@ -0,0 +1,80 @@ +/** +****************************************************************************** +* +* @file homeitem.cpp +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief A graphicsItem representing a trail point +* @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 "homeitem.h" +namespace mapcontrol +{ + HomeItem::HomeItem(MapGraphicItem* map,OPMapWidget* parent):safe(true),map(map),mapwidget(parent),showsafearea(true),safearea(1000),altitude(0) + { + pic.load(QString::fromUtf8(":/markers/images/home2.svg")); + pic=pic.scaled(30,30,Qt::IgnoreAspectRatio); + this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); + localposition=map->FromLatLngToLocal(mapwidget->CurrentPosition()); + this->setPos(localposition.X(),localposition.Y()); + this->setZValue(4); + coord=internals::PointLatLng(50,50); + } + + void HomeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + { + Q_UNUSED(option); + Q_UNUSED(widget); + painter->drawPixmap(-pic.width()/2,-pic.height()/2,pic); + if(showsafearea) + { + if(safe) + painter->setPen(Qt::green); + else + painter->setPen(Qt::red); + painter->drawEllipse(QPointF(0,0),localsafearea,localsafearea); + // painter->drawRect(QRectF(-localsafearea,-localsafearea,localsafearea*2,localsafearea*2)); + } + + } + QRectF HomeItem::boundingRect()const + { + if(!showsafearea) + return QRectF(-pic.width()/2,-pic.height()/2,pic.width(),pic.height()); + else + return QRectF(-localsafearea,-localsafearea,localsafearea*2,localsafearea*2); + } + + + int HomeItem::type()const + { + return Type; + } + void HomeItem::RefreshPos() + { + prepareGeometryChange(); + localposition=map->FromLatLngToLocal(coord); + this->setPos(localposition.X(),localposition.Y()); + if(showsafearea) + localsafearea=safearea/map->Projection()->GetGroundResolution(map->ZoomTotal(),coord.Lat()); + + } + +} diff --git a/lib/opmapcontrol/src/mapwidget/homeitem.h b/lib/opmapcontrol/src/mapwidget/homeitem.h new file mode 100644 index 0000000000000000000000000000000000000000..3c03396ee526510cc4ba2d6e63e1be0f88c15880 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/homeitem.h @@ -0,0 +1,77 @@ +/** +****************************************************************************** +* +* @file homeitem.h +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief A graphicsItem representing a WayPoint +* @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 HOMEITEM_H +#define HOMEITEM_H + +#include +#include +#include +#include "../internals/pointlatlng.h" +#include +#include "opmapwidget.h" +namespace mapcontrol +{ + + class HomeItem:public QObject,public QGraphicsItem + { + Q_OBJECT + Q_INTERFACES(QGraphicsItem) + public: + enum { Type = UserType + 4 }; + HomeItem(MapGraphicItem* map,OPMapWidget* parent); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget); + QRectF boundingRect() const; + int type() const; + void RefreshPos(); + bool ShowSafeArea()const{return showsafearea;} + void SetShowSafeArea(bool const& value){showsafearea=value;} + int SafeArea()const{return safearea;} + void SetSafeArea(int const& value){safearea=value;} + bool safe; + void SetCoord(internals::PointLatLng const& value){coord=value;} + internals::PointLatLng Coord()const{return coord;} + void SetAltitude(int const& value){altitude=value;} + int Altitude()const{return altitude;} + private: + MapGraphicItem* map; + OPMapWidget* mapwidget; + QPixmap pic; + core::Point localposition; + internals::PointLatLng coord; + bool showsafearea; + int safearea; + int localsafearea; + int altitude; + + public slots: + + signals: + + }; +} +#endif // HOMEITEM_H diff --git a/lib/opmapcontrol/src/mapwidget/images/EasystarBlue.png b/lib/opmapcontrol/src/mapwidget/images/EasystarBlue.png new file mode 100644 index 0000000000000000000000000000000000000000..4e44eaed96650f7970eddc009bb53146be3e50a3 Binary files /dev/null and b/lib/opmapcontrol/src/mapwidget/images/EasystarBlue.png differ diff --git a/lib/opmapcontrol/src/mapwidget/images/airplane.png b/lib/opmapcontrol/src/mapwidget/images/airplane.png new file mode 100644 index 0000000000000000000000000000000000000000..81c73a7c4c64b6cd051923f31a1f552ea262d79d Binary files /dev/null and b/lib/opmapcontrol/src/mapwidget/images/airplane.png differ diff --git a/lib/opmapcontrol/src/mapwidget/images/airplane.svg b/lib/opmapcontrol/src/mapwidget/images/airplane.svg new file mode 100644 index 0000000000000000000000000000000000000000..da6977bec18bfc51aa7f8e8a7ce769c130571d93 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/images/airplane.svg @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + diff --git a/lib/opmapcontrol/src/mapwidget/images/airplanepip.png b/lib/opmapcontrol/src/mapwidget/images/airplanepip.png new file mode 100644 index 0000000000000000000000000000000000000000..d9b2279fc6e0e54a2e98d0b18349f5731f1afbdb Binary files /dev/null and b/lib/opmapcontrol/src/mapwidget/images/airplanepip.png differ diff --git a/lib/opmapcontrol/src/mapwidget/images/bigMarkerGreen.png b/lib/opmapcontrol/src/mapwidget/images/bigMarkerGreen.png new file mode 100644 index 0000000000000000000000000000000000000000..4aed804959cd7450939446ca75515003033a8543 Binary files /dev/null and b/lib/opmapcontrol/src/mapwidget/images/bigMarkerGreen.png differ diff --git a/lib/opmapcontrol/src/mapwidget/images/compas.svg b/lib/opmapcontrol/src/mapwidget/images/compas.svg new file mode 100644 index 0000000000000000000000000000000000000000..086b865a1d4831cd5a04f6c9847fb3dd3bd53254 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/images/compas.svg @@ -0,0 +1,248 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/opmapcontrol/src/mapwidget/images/home.png b/lib/opmapcontrol/src/mapwidget/images/home.png new file mode 100644 index 0000000000000000000000000000000000000000..817a9476a89a071bd2e0f053d00e6c1d06a56a3b Binary files /dev/null and b/lib/opmapcontrol/src/mapwidget/images/home.png differ diff --git a/lib/opmapcontrol/src/mapwidget/images/home.svg b/lib/opmapcontrol/src/mapwidget/images/home.svg new file mode 100644 index 0000000000000000000000000000000000000000..63fa6a97e811d0f4ed28919590747d66b3ccb7ae --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/images/home.svg @@ -0,0 +1,126 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/lib/opmapcontrol/src/mapwidget/images/home2.svg b/lib/opmapcontrol/src/mapwidget/images/home2.svg new file mode 100644 index 0000000000000000000000000000000000000000..4eef55159fb2aea7b4c501a19cd4ed4826c0e78d --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/images/home2.svg @@ -0,0 +1,80 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/lib/opmapcontrol/src/mapwidget/images/mapquad.png b/lib/opmapcontrol/src/mapwidget/images/mapquad.png new file mode 100644 index 0000000000000000000000000000000000000000..8f968a277295e44cce698127fd1a4dd36d57976e Binary files /dev/null and b/lib/opmapcontrol/src/mapwidget/images/mapquad.png differ diff --git a/lib/opmapcontrol/src/mapwidget/images/marker.png b/lib/opmapcontrol/src/mapwidget/images/marker.png new file mode 100644 index 0000000000000000000000000000000000000000..d3770dd74a3a88cfbc6c870530c0283bec7fdf5c Binary files /dev/null and b/lib/opmapcontrol/src/mapwidget/images/marker.png differ diff --git a/lib/opmapcontrol/src/mapwidget/mapgraphicitem.cpp b/lib/opmapcontrol/src/mapwidget/mapgraphicitem.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1a51d425c9c55f9f0bf68481c5de7452fccf5e05 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/mapgraphicitem.cpp @@ -0,0 +1,583 @@ +/** +****************************************************************************** +* +* @file mapgraphicitem.cpp +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief The main graphicsItem used on the widget, contains the map and map logic +* @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 "uavitem.h" +#include "gpsitem.h" +#include "homeitem.h" +#include "mapgraphicitem.h" + +namespace mapcontrol +{ + MapGraphicItem::MapGraphicItem(internals::Core *core, Configuration *configuration):core(core),config(configuration),MapRenderTransform(1), maxZoom(17),minZoom(2),zoomReal(0),isSelected(false),rotation(0),zoomDigi(0) + { + + showTileGridLines=false; + isMouseOverMarker=false; + maprect=QRectF(0,0,1022,680); + core->SetCurrentRegion(internals::Rectangle(0, 0, maprect.width(), maprect.height())); + core->SetMapType(MapType::GoogleHybrid); + this->SetZoom(2); + connect(core,SIGNAL(OnNeedInvalidation()),this,SLOT(Core_OnNeedInvalidation())); + connect(core,SIGNAL(OnMapDrag()),this,SLOT(ChildPosRefresh())); + connect(core,SIGNAL(OnMapZoomChanged()),this,SLOT(ChildPosRefresh())); + //resize(); + } + void MapGraphicItem::start() + { + core->StartSystem(); + } + + void MapGraphicItem::resize(const QRectF &rect) + { + Q_UNUSED(rect); + { + this->prepareGeometryChange(); + maprect=boundingBox(scene()->sceneRect(),rotation); + this->setTransform(QTransform().translate(-(maprect.width()-scene()->width())/2,-(maprect.height()-scene()->height())/2)); + this->setTransformOriginPoint(maprect.center().x(),maprect.center().y()); + this->setRotation(rotation); + } + + core->OnMapSizeChanged(maprect.width(),maprect.height()); + core->SetCurrentRegion(internals::Rectangle(0, 0, maprect.width(), maprect.height())); + if(isVisible()) + { + core->GoToCurrentPosition(); + } + } + + QRectF MapGraphicItem::boundingRect() const + { + const int Margin = 1; + return maprect.adjusted(-Margin, -Margin, +Margin, +Margin); + } + void MapGraphicItem::Core_OnNeedInvalidation() + { + this->update(); + foreach(QGraphicsItem* i,this->childItems()) + { + WayPointItem* w=qgraphicsitem_cast(i); + if(w) + w->RefreshPos(); + UAVItem* ww=qgraphicsitem_cast(i); + if(ww) + ww->RefreshPos(); + HomeItem* www=qgraphicsitem_cast(i); + if(www) + www->RefreshPos(); + GPSItem* wwww=qgraphicsitem_cast(i); + if(wwww) + wwww->RefreshPos(); + } + } + void MapGraphicItem::ChildPosRefresh() + { + foreach(QGraphicsItem* i,this->childItems()) + { + WayPointItem* w=qgraphicsitem_cast(i); + if(w) + w->RefreshPos(); + UAVItem* ww=qgraphicsitem_cast(i); + if(ww) + ww->RefreshPos(); + HomeItem* www=qgraphicsitem_cast(i); + if(www) + www->RefreshPos(); + GPSItem* wwww=qgraphicsitem_cast(i); + if(wwww) + wwww->RefreshPos(); + } + } + void MapGraphicItem::ConstructLastImage(int const& zoomdiff) + { + QImage temp; + QSize size=boundingRect().size().toSize(); + size.setWidth(size.width()*2*zoomdiff); + size.setHeight(size.height()*2*zoomdiff); + temp=QImage(size, + QImage::Format_ARGB32_Premultiplied); + temp.fill(0); + QPainter imagePainter(&temp); + imagePainter.translate(-boundingRect().topLeft()); + imagePainter.scale(2*zoomdiff,2*zoomdiff); + paintImage(&imagePainter); + imagePainter.end(); + lastimagepoint=Point(core->GetrenderOffset().X()*2*zoomdiff,core->GetrenderOffset().Y()*2*zoomdiff); + lastimage=temp; + } + void MapGraphicItem::paintImage(QPainter *painter) + { + + if(MapRenderTransform!=1) + { + QTransform transform; + transform.translate(-((boundingRect().width()*MapRenderTransform)-(boundingRect().width()))/2,-((boundingRect().height()*MapRenderTransform)-(boundingRect().height()))/2); + transform.scale(MapRenderTransform,MapRenderTransform); + painter->setWorldTransform(transform); + { + DrawMap2D(painter); + } + painter->resetTransform(); + } + else + { + DrawMap2D(painter); + } + //painter->drawRect(maprect); + } + void MapGraphicItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + { + Q_UNUSED(option); + Q_UNUSED(widget); + + if(MapRenderTransform!=1) + { + QTransform transform; + transform.translate(-((boundingRect().width()*MapRenderTransform)-(boundingRect().width()))/2,-((boundingRect().height()*MapRenderTransform)-(boundingRect().height()))/2); + transform.scale(MapRenderTransform,MapRenderTransform); + + painter->setWorldTransform(transform); + painter->setRenderHint(QPainter::SmoothPixmapTransform,true); + painter->setRenderHint(QPainter::HighQualityAntialiasing,true); + + { + DrawMap2D(painter); + } + painter->resetTransform(); + } + else + { + DrawMap2D(painter); + } + } + void MapGraphicItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) + { + if(core->IsDragging()) + { + if(MapRenderTransform!=1) + { + qreal dx= (event->pos().x()-core->mouseDown.X())/(MapRenderTransform); + qreal dy= (event->pos().y()-core->mouseDown.Y())/(MapRenderTransform); + qreal nx=core->mouseDown.X()+dx; + qreal ny=core->mouseDown.Y()+dy; + core->mouseCurrent.SetX(nx); + core->mouseCurrent.SetY(ny); + } + else + { + core->mouseCurrent.SetX(event->pos().x()); + core->mouseCurrent.SetY(event->pos().y()); + } + { + core->Drag(core->mouseCurrent); + } + + } + else if(isSelected && !selectionStart.IsEmpty() && (event->modifiers() == Qt::AltModifier || event->modifiers() == Qt::ShiftModifier)) + { + selectionEnd = FromLocalToLatLng(event->pos().x(), event->pos().y()); + { + internals::PointLatLng p1 = selectionStart; + internals::PointLatLng p2 = selectionEnd; + + double x1 = qMin(p1.Lng(), p2.Lng()); + double y1 = qMax(p1.Lat(), p2.Lat()); + double x2 = qMax(p1.Lng(), p2.Lng()); + double y2 = qMin(p1.Lat(), p2.Lat()); + + SetSelectedArea(internals::RectLatLng(y1, x1, x2 - x1, y1 - y2)); + } + } + QGraphicsItem::mouseMoveEvent(event); + } + void MapGraphicItem::mousePressEvent(QGraphicsSceneMouseEvent *event) + { + + + + if(!IsMouseOverMarker()) + { + if(event->button() == config->DragButton && CanDragMap()&& !((event->modifiers()==Qt::AltModifier)||(event->modifiers()==Qt::ShiftModifier))) + { + core->mouseDown.SetX(event->pos().x()); + core->mouseDown.SetY(event->pos().y()); + + + this->setCursor(Qt::SizeAllCursor); + + core->BeginDrag(core->mouseDown); + this->update(); + + } + else if(!isSelected && ((event->modifiers()==Qt::AltModifier)||(event->modifiers()==Qt::ShiftModifier))) + { + isSelected = true; + SetSelectedArea (internals::RectLatLng::Empty); + selectionEnd = internals::PointLatLng::Empty; + selectionStart = FromLocalToLatLng(event->pos().x(), event->pos().y()); + } + } + + } + void MapGraphicItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) + { + if(isSelected) + { + isSelected = false; + } + + if(core->IsDragging()) + { + core->EndDrag(); + + this->setCursor(Qt::ArrowCursor); + if(!BoundsOfMap.IsEmpty() && !BoundsOfMap.Contains(core->CurrentPosition())) + { + if(!core->LastLocationInBounds.IsEmpty()) + { + core->SetCurrentPosition(core->LastLocationInBounds); + } + } + } + else + { + if(!selectionEnd.IsEmpty() && !selectionStart.IsEmpty()) + { + if(!selectedArea.IsEmpty() && event->modifiers() == Qt::ShiftModifier) + { + SetZoomToFitRect(SelectedArea()); + } + } + + } + } + bool MapGraphicItem::SetZoomToFitRect(internals::RectLatLng const& rect) + { + int maxZoom = core->GetMaxZoomToFitRect(rect); + if(maxZoom > 0) + { + internals::PointLatLng center=internals::PointLatLng(rect.Lat()-(rect.HeightLat()/2), rect.Lng()+(rect.WidthLng()/2)); + core->SetCurrentPosition(center); + + if(maxZoom > MaxZoom()) + { + maxZoom = MaxZoom(); + } + + if((int) Zoom() != maxZoom) + { + SetZoom(maxZoom); + } + + return true; + } + return false; + } + + void MapGraphicItem::wheelEvent(QGraphicsSceneWheelEvent *event) + { + + if(!IsMouseOverMarker() && !IsDragging()) + { + if(core->GetmouseLastZoom().X() != event->pos().x() && core->mouseLastZoom.Y() != event->pos().y()) + { + if(GetMouseWheelZoomType() == internals::MouseWheelZoomType::MousePositionAndCenter) + { + core->SetCurrentPosition(FromLocalToLatLng(event->pos().x(), event->pos().y())); + } + else if(GetMouseWheelZoomType() == internals::MouseWheelZoomType::ViewCenter) + { + core->SetCurrentPosition(FromLocalToLatLng((int) maprect.width()/2, (int) maprect.height()/2)); + } + else if(GetMouseWheelZoomType() == internals::MouseWheelZoomType::MousePositionWithoutCenter) + { + core->SetCurrentPosition(FromLocalToLatLng(event->pos().x(), event->pos().y())); + + } + + core->mouseLastZoom.SetX((event->pos().x())); + core->mouseLastZoom.SetY((event->pos().y())); + } + + // set mouse position to map center + if(GetMouseWheelZoomType() != internals::MouseWheelZoomType::MousePositionWithoutCenter) + { + { + // System.Drawing.Point p = PointToScreen(new System.Drawing.Point(Width/2, Height/2)); + // Stuff.SetCursorPos((int) p.X, (int) p.Y); + } + } + + core->MouseWheelZooming = true; + + if(event->delta() > 0) + { + SetZoom(ZoomTotal()+1); + } + else if(event->delta() < 0) + { + SetZoom(ZoomTotal()-1); + } + + core->MouseWheelZooming = false; + } + } + void MapGraphicItem::DrawMap2D(QPainter *painter) + { + if(!lastimage.isNull()) + painter->drawImage(core->GetrenderOffset().X()-lastimagepoint.X(),core->GetrenderOffset().Y()-lastimagepoint.Y(),lastimage); + + for(int i = -core->GetsizeOfMapArea().Width(); i <= core->GetsizeOfMapArea().Width(); i++) + { + for(int j = -core->GetsizeOfMapArea().Height(); j <= core->GetsizeOfMapArea().Height(); j++) + { + core->SettilePoint (core->GetcenterTileXYLocation()); + core->SettilePoint(Point(core->GettilePoint().X()+ i,core->GettilePoint().Y()+j)); + { + internals::Tile* t = core->Matrix.TileAt(core->GettilePoint()); + if(true) + { + core->tileRect.SetX(core->GettilePoint().X()*core->tileRect.Width()); + core->tileRect.SetY(core->GettilePoint().Y()*core->tileRect.Height()); + core->tileRect.Offset(core->GetrenderOffset()); + if(core->GetCurrentRegion().IntersectsWith(core->tileRect)) + { + bool found = false; + + // render tile + //lock(t.Overlays) + if(t!=0) + { + foreach(QByteArray img,t->Overlays) + { + if(img.count()!=0) + { + if(!found) + found = true; + { + painter->drawPixmap(core->tileRect.X(),core->tileRect.Y(), core->tileRect.Width(), core->tileRect.Height(),PureImageProxy::FromStream(img)); + // qDebug()<<"tile:"<tileRect.X()<tileRect.Y(); + } + } + } + } + + if(showTileGridLines) + { + painter->setPen(config->EmptyTileBorders); + painter->drawRect(core->tileRect.X(), core->tileRect.Y(), core->tileRect.Width(), core->tileRect.Height()); + { + painter->setFont(config->MissingDataFont); + painter->setPen(Qt::red); + painter->drawText(QRectF(core->tileRect.X(), core->tileRect.Y(), core->tileRect.Width(), core->tileRect.Height()),Qt::AlignCenter,(core->GettilePoint() == core->GetcenterTileXYLocation()? "CENTER: " :"TILE: ")+core->GettilePoint().ToString()); + //qDebug()<<"ShowTileGridLine:"<GettilePoint().ToString()<<"=="<GetcenterTileXYLocation().ToString(); + } + } + + // add text if tile is missing + if(false) + { + + painter->fillRect(QRectF(core->tileRect.X(), core->tileRect.Y(), core->tileRect.Width(), core->tileRect.Height()),config->EmptytileBrush); + painter->setFont(config->MissingDataFont); + painter->drawText(QRectF(core->tileRect.X(), core->tileRect.Y(), core->tileRect.Width(), core->tileRect.Height()),config->EmptyTileText); + + + + painter->setPen(config->EmptyTileBorders); + painter->drawRect(core->tileRect.X(), core->tileRect.Y(), core->tileRect.Width(), core->tileRect.Height()); + + // raise error + + } + if(!SelectedArea().IsEmpty()) + { + core::Point p1 = FromLatLngToLocal(SelectedArea().LocationTopLeft()); + core::Point p2 = FromLatLngToLocal(SelectedArea().LocationRightBottom()); + int x1 = p1.X(); + int y1 = p1.Y(); + int x2 = p2.X(); + int y2 = p2.Y(); + painter->setPen(Qt::black); + painter->setBrush(QBrush(QColor(50,50,100,20))); + painter->drawRect(x1,y1,x2-x1,y2-y1); + } + } + } + } + } + } + // painter->drawRect(core->GetrenderOffset().X()-lastimagepoint.X()-3,core->GetrenderOffset().Y()-lastimagepoint.Y()-3,lastimage.width(),lastimage.height()); +// painter->setPen(Qt::red); +// painter->drawLine(-10,-10,10,10); +// painter->drawLine(10,10,-10,-10); +// painter->drawRect(boundingRect().adjusted(100,100,-100,-100)); + } + + + core::Point MapGraphicItem::FromLatLngToLocal(internals::PointLatLng const& point) + { + core::Point ret = core->FromLatLngToLocal(point); + if(MapRenderTransform!=1) + { + ret.SetX((int) (ret.X() * MapRenderTransform)); + ret.SetY((int) (ret.Y() * MapRenderTransform)); + ret.SetX(ret.X()-((boundingRect().width()*MapRenderTransform)-(boundingRect().width()))/2); + ret.SetY(ret.Y()-((boundingRect().height()*MapRenderTransform)-(boundingRect().height()))/2); + + + } + return ret; + } + internals::PointLatLng MapGraphicItem::FromLocalToLatLng(int x, int y) + { + if(MapRenderTransform!=1) + { + x=x+((boundingRect().width()*MapRenderTransform)-(boundingRect().width()))/2; + y=y+((boundingRect().height()*MapRenderTransform)-(boundingRect().height()))/2; + + x = (int) (x / MapRenderTransform); + y = (int) (y / MapRenderTransform); + } + return core->FromLocalToLatLng(x, y); + } + + double MapGraphicItem::Zoom() + { + return zoomReal; + } + double MapGraphicItem::ZoomDigi() + { + return zoomDigi; + } + double MapGraphicItem::ZoomTotal() + { + return zoomDigi+zoomReal; + } + + void MapGraphicItem::SetZoom(double const& value) + { + if(ZoomTotal() != value) + { + if(value > MaxZoom()) + { + zoomReal = MaxZoom(); + zoomDigi =value-MaxZoom(); + } + else + if(value < MinZoom()) + { + zoomDigi=0; + zoomReal = MinZoom(); + } + else + { + zoomDigi=0; + zoomReal = value; + } + double integer; + double remainder = modf (value , &integer); + if(zoomDigi!=0||remainder != 0) + { + float scaleValue = zoomDigi+remainder + 1; + { + MapRenderTransform = scaleValue; + // qDebug()<<"scale="<MaxZoom()) + integer=MaxZoom(); + SetZoomStep((qint32)(integer)); + // core->GoToCurrentPositionOnZoom(); + this->update(); + + } + else + { + + MapRenderTransform = 1; + + SetZoomStep ((qint32)(value)); + zoomReal = ZoomStep(); + this->update(); + } + } + } + int MapGraphicItem::ZoomStep()const + { + return core->Zoom(); + } + void MapGraphicItem::SetZoomStep(int const& value) + { + if(value-core->Zoom()>0 && value<= MaxZoom()) + ConstructLastImage(value-core->Zoom()); + else if(value!=MaxZoom()) + lastimage=QImage(); + if(value > MaxZoom()) + { + core->SetZoom(MaxZoom()); + emit zoomChanged(MaxZoom()+ZoomDigi(),Zoom(),ZoomDigi()); + } + else if(value < MinZoom()) + { + core->SetZoom(MinZoom()); + emit zoomChanged(MinZoom()+ZoomDigi(),Zoom(),ZoomDigi()); + } + else + { + core->SetZoom(value); + emit zoomChanged(value+ZoomDigi(),Zoom(),ZoomDigi());; + } + + } + + void MapGraphicItem::Offset(int const& x, int const& y) + { + core->DragOffset(Point(x, y)); + } + void MapGraphicItem::mapRotate(qreal angle) + { + if (rotation != angle) { + rotation=angle; + resize(scene()->sceneRect()); + } + } + QRectF MapGraphicItem::boundingBox(const QRectF &rect, const qreal &angle) + { + QRectF ret(rect); + float c=cos(angle*2*M_PI/360); + float s=sin(angle*2*M_PI/360); + ret.setHeight(rect.height()*fabs(c)+rect.width()*fabs(s)); + ret.setWidth(rect.width()*fabs(c)+rect.height()*fabs(s)); + return ret; + } + QSize MapGraphicItem::sizeHint()const + { + core::Size size=core->projection->GetTileMatrixMaxXY(MinZoom()); + core::Size tilesize=core->projection->TileSize(); + QSize rsize((size.Width()+1)*tilesize.Width(),(size.Height()+1)*tilesize.Height()); + return rsize; + } +} diff --git a/lib/opmapcontrol/src/mapwidget/mapgraphicitem.h b/lib/opmapcontrol/src/mapwidget/mapgraphicitem.h new file mode 100644 index 0000000000000000000000000000000000000000..cf8ffeb963a1ee5b48c99875bc05107c4e88a149 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/mapgraphicitem.h @@ -0,0 +1,210 @@ +/** +****************************************************************************** +* +* @file mapgraphicitem.h +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief The main graphicsItem used on the widget, contains the map and map logic +* @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 MAPGRAPHICITEM_H +#define MAPGRAPHICITEM_H + +#include +#include "../internals/core.h" +//#include "../internals/point.h" +#include "../core/diagnostics.h" +#include "configuration.h" +#include +#include +#include +#include +#include +#include +#include "waypointitem.h" +//#include "uavitem.h" +namespace mapcontrol +{ + class OPMapWidget; + /** + * @brief The main graphicsItem used on the widget, contains the map and map logic + * + * @class MapGraphicItem mapgraphicitem.h "mapgraphicitem.h" + */ + class MapGraphicItem:public QObject,public QGraphicsItem + { + friend class mapcontrol::OPMapWidget; + Q_OBJECT + Q_INTERFACES(QGraphicsItem) + public: + + + /** + * @brief Contructer + * + * @param core + * @param configuration the configuration to be used + * @return + */ + MapGraphicItem(internals::Core *core,Configuration *configuration); + QRectF boundingRect() const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget); + + QSize sizeHint()const; + /** + * @brief Convertes LatLong coordinates to local item coordinates + * + * @param point LatLong point to be converted + * @return core::Point Local item point + */ + core::Point FromLatLngToLocal(internals::PointLatLng const& point); + /** + * @brief Converts from local item coordinates to LatLong point + * + * @param x x local coordinate + * @param y y local coordinate + * @return internals::PointLatLng LatLng coordinate + */ + internals::PointLatLng FromLocalToLatLng(int x, int y); + /** + * @brief Returns true if map is being dragged + * + * @return + */ + bool IsDragging()const{return core->IsDragging();} + + QImage lastimage; +// QPainter* imagePainter; + core::Point lastimagepoint; + void paintImage(QPainter* painter); + void ConstructLastImage(int const& zoomdiff); + internals::PureProjection* Projection()const{return core->Projection();} + double Zoom(); + double ZoomDigi(); + double ZoomTotal(); + + protected: + void mouseMoveEvent ( QGraphicsSceneMouseEvent * event ); + void mousePressEvent ( QGraphicsSceneMouseEvent * event ); + void wheelEvent ( QGraphicsSceneWheelEvent * event ); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + bool IsMouseOverMarker()const{return isMouseOverMarker;} + + /** + * @brief Returns current map zoom + * + * @return int Current map zoom + */ + int ZoomStep()const; + /** + * @brief Sets map zoom + * + * @param value zoom value + */ + void SetZoomStep(int const& value); + + + private: + bool SetZoomToFitRect(internals::RectLatLng const& rect); + internals::Core *core; + Configuration *config; + bool showTileGridLines; + qreal MapRenderTransform; + void DrawMap2D(QPainter *painter); + /** + * @brief Maximum possible zoom + * + * @var maxZoom + */ + int maxZoom; + /** + * @brief Minimum possible zoom + * + * @var minZoom + */ + int minZoom; + internals::RectLatLng selectedArea; + internals::PointLatLng selectionStart; + internals::PointLatLng selectionEnd; + double zoomReal; + double zoomDigi; + QRectF maprect; + bool isSelected; + bool isMouseOverMarker; + void SetIsMouseOverMarker(bool const& value){isMouseOverMarker = value;} + + qreal rotation; + /** + * @brief Creates a rectangle that represents the "view" of the cuurent map, to compensate + * rotation + * + * @param rect original rectangle + * @param angle angle of rotation + * @return QRectF + */ + QRectF boundingBox(QRectF const& rect, qreal const& angle); + /** + * @brief Returns the maximum allowed zoom + * + * @return int + */ + int MaxZoom()const{return core->MaxZoom();} + /** + * @brief Returns the minimum allowed zoom + * + * @return int + */ + int MinZoom()const{return minZoom;} + internals::MouseWheelZoomType::Types GetMouseWheelZoomType(){return core->GetMouseWheelZoomType();} + void SetSelectedArea(internals::RectLatLng const& value){selectedArea = value;this->update();} + internals::RectLatLng SelectedArea()const{return selectedArea;} + internals::RectLatLng BoundsOfMap; + void Offset(int const& x, int const& y); + bool CanDragMap()const{return core->CanDragMap;} + void SetCanDragMap(bool const& value){core->CanDragMap = value;} + + void SetZoom(double const& value); + void mapRotate ( qreal angle ); + void start(); + void ReloadMap(){core->ReloadMap();} + GeoCoderStatusCode::Types SetCurrentPositionByKeywords(QString const& keys){return core->SetCurrentPositionByKeywords(keys);} + MapType::Types GetMapType(){return core->GetMapType();} + void SetMapType(MapType::Types const& value){core->SetMapType(value);} + private slots: + void Core_OnNeedInvalidation(); + void ChildPosRefresh(); + public slots: + /** + * @brief To be called when the scene size changes + * + * @param rect + */ + void resize ( QRectF const &rect=QRectF() ); + signals: + /** + * @brief Fired when the current zoom is changed + * + * @param zoom + */ + void zoomChanged(double zoomtotal,double zoomreal,double zoomdigi); + }; +} +#endif // MAPGRAPHICITEM_H diff --git a/lib/opmapcontrol/src/mapwidget/mapresources.qrc b/lib/opmapcontrol/src/mapwidget/mapresources.qrc new file mode 100644 index 0000000000000000000000000000000000000000..bdb546587cec7896aeef14bc21e4b1a26394695b --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/mapresources.qrc @@ -0,0 +1,14 @@ + + + images/bigMarkerGreen.png + images/marker.png + images/compas.svg + images/airplane.svg + images/home.png + images/home.svg + images/home2.svg + images/airplanepip.png + images/EasystarBlue.png + images/mapquad.png + + diff --git a/lib/opmapcontrol/src/mapwidget/mapripform.cpp b/lib/opmapcontrol/src/mapwidget/mapripform.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bbd1725a1aedb5d9bf5fb55a677257302151de5e --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/mapripform.cpp @@ -0,0 +1,53 @@ +/** +****************************************************************************** +* +* @file mapripform.cpp +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief Form to be used with the MapRipper class +* @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 "mapripform.h" +#include "ui_mapripform.h" + +MapRipForm::MapRipForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::MapRipForm) +{ + ui->setupUi(this); +} + +MapRipForm::~MapRipForm() +{ + delete ui; +} +void MapRipForm::SetPercentage(const int &perc) +{ + ui->progressBar->setValue(perc); +} +void MapRipForm::SetProvider(const QString &prov,const int &zoom) +{ + ui->mainlabel->setText(QString("Currently ripping from:%1 at Zoom level %2").arg(prov).arg(zoom)); +} +void MapRipForm::SetNumberOfTiles(const int &total, const int &actual) +{ + ui->statuslabel->setText(QString("Downloading tile %1 of %2").arg(actual).arg(total)); +} diff --git a/lib/opmapcontrol/src/mapwidget/mapripform.h b/lib/opmapcontrol/src/mapwidget/mapripform.h new file mode 100644 index 0000000000000000000000000000000000000000..b1ff3637f42b170a2976507226a65f9d754f3278 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/mapripform.h @@ -0,0 +1,51 @@ +/** +****************************************************************************** +* +* @file mapripform.h +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief Form to be used with the MapRipper class +* @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 MAPRIPFORM_H +#define MAPRIPFORM_H + +#include + +namespace Ui { + class MapRipForm; +} + +class MapRipForm : public QWidget +{ + Q_OBJECT + +public: + explicit MapRipForm(QWidget *parent = 0); + ~MapRipForm(); +public slots: + void SetPercentage(int const& perc); + void SetProvider(QString const& prov,int const& zoom); + void SetNumberOfTiles(int const& total,int const& actual); +private: + Ui::MapRipForm *ui; +}; + +#endif // MAPRIPFORM_H diff --git a/lib/opmapcontrol/src/mapwidget/mapripform.ui b/lib/opmapcontrol/src/mapwidget/mapripform.ui new file mode 100644 index 0000000000000000000000000000000000000000..8100f8651c2fa0a19a69e476d919c5b25dc0614e --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/mapripform.ui @@ -0,0 +1,71 @@ + + + MapRipForm + + + + 0 + 0 + 392 + 133 + + + + MapRipper + + + + + 20 + 60 + 371 + 23 + + + + 0 + + + + + + 30 + 10 + 321 + 16 + + + + Currently ripping from: + + + + + + 30 + 40 + 341 + 16 + + + + Downloading tile + + + + + + 280 + 100 + 75 + 23 + + + + Cancel + + + + + + diff --git a/lib/opmapcontrol/src/mapwidget/mapripper.cpp b/lib/opmapcontrol/src/mapwidget/mapripper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..00a2053cdf9b209a5b156eda045f9d87d4955837 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/mapripper.cpp @@ -0,0 +1,122 @@ +/** +****************************************************************************** +* +* @file mapripper.cpp +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief A class that allows ripping of a selection of the map +* @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 "mapripper.h" +namespace mapcontrol +{ + + MapRipper::MapRipper(internals::Core * core, const internals::RectLatLng & rect):sleep(100),cancel(false),progressForm(0),core(core) + { + if(!rect.IsEmpty()) + { + type=core->GetMapType(); + progressForm=new MapRipForm; + area=rect; + zoom=core->Zoom(); + maxzoom=core->MaxZoom(); + points=core->Projection()->GetAreaTileList(area,zoom,0); + this->start(); + progressForm->show(); + connect(this,SIGNAL(percentageChanged(int)),progressForm,SLOT(SetPercentage(int))); + connect(this,SIGNAL(numberOfTilesChanged(int,int)),progressForm,SLOT(SetNumberOfTiles(int,int))); + connect(this,SIGNAL(providerChanged(QString,int)),progressForm,SLOT(SetProvider(QString,int))); + connect(this,SIGNAL(finished()),this,SLOT(finish())); + emit numberOfTilesChanged(0,0); + } + } + void MapRipper::finish() + { + if(zoomProjection()->GetAreaTileList(area,zoom,0); + this->start(); + } + else + { + progressForm->close(); + delete progressForm; + this->deleteLater(); + } + } + } + + + void MapRipper::run() + { + int countOk = 0; + bool goodtile=false; + // Stuff.Shuffle(ref list); + QVector types = OPMaps::Instance()->GetAllLayersOfType(type); + int all=points.count(); + for(int i = 0; i < all; i++) + { + emit numberOfTilesChanged(all,i+1); + if(cancel) + break; + + core::Point p = points[i]; + { + //qDebug()<<"offline fetching:"<GetImageFrom(type, p, zoom); + if(img.length()!=0) + { + goodtile=true; + img=NULL; + } + else + goodtile=false; + } + if(goodtile) + { + countOk++; + } + else + { + i--; + QThread::msleep(1000); + continue; + } + } + emit percentageChanged((int) ((i+1)*100/all));//, i+1); + // worker.ReportProgress((int) ((i+1)*100/all), i+1); + + QThread::msleep(sleep); + } + } +} diff --git a/lib/opmapcontrol/src/mapwidget/mapripper.h b/lib/opmapcontrol/src/mapwidget/mapripper.h new file mode 100644 index 0000000000000000000000000000000000000000..6b2087a1241d52e6a57a6546ef909c1d2c8ed1fa --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/mapripper.h @@ -0,0 +1,64 @@ +/** +****************************************************************************** +* +* @file mapripper.h +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief A class that allows ripping of a selection of the map +* @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 MAPRIPPER_H +#define MAPRIPPER_H + +#include +#include "../internals/core.h" +#include "mapripform.h" +#include +#include +namespace mapcontrol +{ + class MapRipper:public QThread + { + Q_OBJECT + public: + MapRipper(internals::Core *,internals::RectLatLng const&); + void run(); + private: + QList points; + int zoom; + core::MapType::Types type; + int sleep; + internals::RectLatLng area; + bool cancel; + MapRipForm * progressForm; + int maxzoom; + internals::Core * core; + + signals: + void percentageChanged(int const& perc); + void numberOfTilesChanged(int const& total,int const& actual); + void providerChanged(QString const& prov,int const& zoom); + + + public slots: + void finish(); + }; +} +#endif // MAPRIPPER_H diff --git a/lib/opmapcontrol/src/mapwidget/mapwidget.pro b/lib/opmapcontrol/src/mapwidget/mapwidget.pro new file mode 100644 index 0000000000000000000000000000000000000000..7b824ec6fab6505538a22b1624d0deef6d03d105 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/mapwidget.pro @@ -0,0 +1,44 @@ +TEMPLATE = lib +TARGET = opmapwidget +DEFINES += OPMAPWIDGET_LIBRARY +include(../../../../openpilotgcslibrary.pri) + +# DESTDIR = ../build +SOURCES += mapgraphicitem.cpp \ + opmapwidget.cpp \ + configuration.cpp \ + waypointitem.cpp \ + uavitem.cpp \ + gpsitem.cpp \ + trailitem.cpp \ + homeitem.cpp \ + mapripform.cpp \ + mapripper.cpp +LIBS += -L../build \ + -lcore \ + -linternals \ + -lcore + +POST_TARGETDEPS += ../build/libcore.a +POST_TARGETDEPS += ../build/libinternals.a + +HEADERS += mapgraphicitem.h \ + opmapwidget.h \ + configuration.h \ + waypointitem.h \ + uavitem.h \ + gpsitem.h \ + uavmapfollowtype.h \ + uavtrailtype.h \ + trailitem.h \ + homeitem.h \ + mapripform.h \ + mapripper.h +QT += opengl +QT += network +QT += sql +QT += svg +RESOURCES += mapresources.qrc + +FORMS += \ + mapripform.ui diff --git a/lib/opmapcontrol/src/mapwidget/opmapwidget.cpp b/lib/opmapcontrol/src/mapwidget/opmapwidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..64599a082093bbb08957106525926fabe19a1958 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/opmapwidget.cpp @@ -0,0 +1,347 @@ +/** +****************************************************************************** +* +* @file opmapwidget.cpp +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief The Map Widget, this is the part exposed to the user +* @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 "opmapwidget.h" +#include +#include +#include "waypointitem.h" + +namespace mapcontrol +{ + + OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config):QGraphicsView(parent),configuration(config),UAV(0),GPS(0),Home(0),followmouse(true),compass(0),showuav(false),showhome(false),showDiag(false),diagGraphItem(0),diagTimer(0) + { + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + core=new internals::Core; + map=new MapGraphicItem(core,config); + mscene.addItem(map); + this->setScene(&mscene); + this->adjustSize(); + connect(map,SIGNAL(zoomChanged(double,double,double)),this,SIGNAL(zoomChanged(double,double,double))); + connect(map->core,SIGNAL(OnCurrentPositionChanged(internals::PointLatLng)),this,SIGNAL(OnCurrentPositionChanged(internals::PointLatLng))); + connect(map->core,SIGNAL(OnEmptyTileError(int,core::Point)),this,SIGNAL(OnEmptyTileError(int,core::Point))); + connect(map->core,SIGNAL(OnMapDrag()),this,SIGNAL(OnMapDrag())); + connect(map->core,SIGNAL(OnMapTypeChanged(MapType::Types)),this,SIGNAL(OnMapTypeChanged(MapType::Types))); + connect(map->core,SIGNAL(OnMapZoomChanged()),this,SIGNAL(OnMapZoomChanged())); + connect(map->core,SIGNAL(OnTileLoadComplete()),this,SIGNAL(OnTileLoadComplete())); + connect(map->core,SIGNAL(OnTileLoadStart()),this,SIGNAL(OnTileLoadStart())); + connect(map->core,SIGNAL(OnTilesStillToLoad(int)),this,SIGNAL(OnTilesStillToLoad(int))); + SetShowDiagnostics(showDiag); + this->setMouseTracking(followmouse); + SetShowCompass(true); + + } + void OPMapWidget::SetShowDiagnostics(bool const& value) + { + showDiag=value; + if(!showDiag) + { + if(diagGraphItem!=0) + { + delete diagGraphItem; + diagGraphItem=0; + } + if(diagTimer!=0) + { + delete diagTimer; + diagTimer=0; + } + } + else + { + diagTimer=new QTimer(); + connect(diagTimer,SIGNAL(timeout()),this,SLOT(diagRefresh())); + diagTimer->start(500); + } + + } + void OPMapWidget::SetShowUAV(const bool &value) + { + if(value && UAV==0) + { + UAV=new UAVItem(map,this); + UAV->setParentItem(map); + connect(this,SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)),UAV,SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng))); + connect(this,SIGNAL(UAVReachedWayPoint(int,WayPointItem*)),UAV,SIGNAL(UAVReachedWayPoint(int,WayPointItem*))); + } + else if(!value) + { + if(UAV!=0) + { + delete UAV; + UAV=0; + } + + } + if(value && GPS==0) + { + GPS=new GPSItem(map,this); + GPS->setParentItem(map); + } + else if(!value) + { + if(GPS!=0) + { + delete GPS; + GPS=0; + } + + } + } + void OPMapWidget::SetShowHome(const bool &value) + { + if(value && Home==0) + { + Home=new HomeItem(map,this); + Home->setParentItem(map); + } + else if(!value) + { + if(Home!=0) + { + delete Home; + Home=0; + } + + } + } + + void OPMapWidget::resizeEvent(QResizeEvent *event) + { + if (scene()) + scene()->setSceneRect( + QRect(QPoint(0, 0), event->size())); + QGraphicsView::resizeEvent(event); + if(compass) + compass->setScale(0.1+0.05*(qreal)(event->size().width())/1000*(qreal)(event->size().height())/600); + + } + QSize OPMapWidget::sizeHint() const + { + return map->sizeHint(); + } + void OPMapWidget::showEvent(QShowEvent *event) + { + connect(&mscene,SIGNAL(sceneRectChanged(QRectF)),map,SLOT(resize(QRectF))); + map->start(); + QGraphicsView::showEvent(event); + } + OPMapWidget::~OPMapWidget() + { + delete UAV; + delete Home; + delete map; + delete core; + delete configuration; + foreach(QGraphicsItem* i,this->items()) + { + delete i; + } + } + void OPMapWidget::closeEvent(QCloseEvent *event) + { + core->OnMapClose(); + event->accept(); + } + void OPMapWidget::SetUseOpenGL(const bool &value) + { + useOpenGL=value; + if (useOpenGL) + setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); + else + setupViewport(new QWidget()); + update(); + } + internals::PointLatLng OPMapWidget::currentMousePosition() + { + return currentmouseposition; + } + + void OPMapWidget::mouseMoveEvent(QMouseEvent *event) + { + QGraphicsView::mouseMoveEvent(event); + QPointF p=event->posF(); + p=map->mapFromParent(p); + currentmouseposition=map->FromLocalToLatLng(p.x(),p.y()); + } + ////////////////WAYPOINT//////////////////////// + WayPointItem* OPMapWidget::WPCreate() + { + WayPointItem* item=new WayPointItem(this->CurrentPosition(),0,map); + ConnectWP(item); + item->setParentItem(map); + return item; + } + void OPMapWidget::WPCreate(WayPointItem* item) + { + ConnectWP(item); + item->setParentItem(map); + } + WayPointItem* OPMapWidget::WPCreate(internals::PointLatLng const& coord,int const& altitude) + { + WayPointItem* item=new WayPointItem(coord,altitude,map); + ConnectWP(item); + item->setParentItem(map); + return item; + } + WayPointItem* OPMapWidget::WPCreate(internals::PointLatLng const& coord,int const& altitude, QString const& description) + { + WayPointItem* item=new WayPointItem(coord,altitude,description,map); + ConnectWP(item); + item->setParentItem(map); + return item; + } + WayPointItem* OPMapWidget::WPInsert(const int &position) + { + WayPointItem* item=new WayPointItem(this->CurrentPosition(),0,map); + item->SetNumber(position); + ConnectWP(item); + item->setParentItem(map); + emit WPInserted(position,item); + return item; + } + void OPMapWidget::WPInsert(WayPointItem* item,const int &position) + { + item->SetNumber(position); + ConnectWP(item); + item->setParentItem(map); + emit WPInserted(position,item); + + } + WayPointItem* OPMapWidget::WPInsert(internals::PointLatLng const& coord,int const& altitude,const int &position) + { + WayPointItem* item=new WayPointItem(coord,altitude,map); + item->SetNumber(position); + ConnectWP(item); + item->setParentItem(map); + emit WPInserted(position,item); + return item; + } + WayPointItem* OPMapWidget::WPInsert(internals::PointLatLng const& coord,int const& altitude, QString const& description,const int &position) + { + WayPointItem* item=new WayPointItem(coord,altitude,description,map); + item->SetNumber(position); + ConnectWP(item); + item->setParentItem(map); + emit WPInserted(position,item); + return item; + } + void OPMapWidget::WPDelete(WayPointItem *item) + { + emit WPDeleted(item->Number()); + delete item; + } + void OPMapWidget::WPDeleteAll() + { + foreach(QGraphicsItem* i,map->childItems()) + { + WayPointItem* w=qgraphicsitem_cast(i); + if(w) + delete w; + } + } + QList OPMapWidget::WPSelected() + { + QList list; + foreach(QGraphicsItem* i,mscene.selectedItems()) + { + WayPointItem* w=qgraphicsitem_cast(i); + if(w) + list.append(w); + } + return list; + } + void OPMapWidget::WPRenumber(WayPointItem *item, const int &newnumber) + { + item->SetNumber(newnumber); + } + + void OPMapWidget::ConnectWP(WayPointItem *item) + { + connect(item,SIGNAL(WPNumberChanged(int,int,WayPointItem*)),this,SIGNAL(WPNumberChanged(int,int,WayPointItem*))); + connect(item,SIGNAL(WPValuesChanged(WayPointItem*)),this,SIGNAL(WPValuesChanged(WayPointItem*))); + connect(this,SIGNAL(WPInserted(int,WayPointItem*)),item,SLOT(WPInserted(int,WayPointItem*))); + connect(this,SIGNAL(WPNumberChanged(int,int,WayPointItem*)),item,SLOT(WPRenumbered(int,int,WayPointItem*))); + connect(this,SIGNAL(WPDeleted(int)),item,SLOT(WPDeleted(int))); + } + void OPMapWidget::diagRefresh() + { + if(showDiag) + { + if(diagGraphItem==0) + { + diagGraphItem=new QGraphicsTextItem(); + mscene.addItem(diagGraphItem); + diagGraphItem->setPos(10,100); + diagGraphItem->setZValue(3); + diagGraphItem->setFlag(QGraphicsItem::ItemIsMovable,true); + diagGraphItem->setDefaultTextColor(Qt::yellow); + } + diagGraphItem->setPlainText(core->GetDiagnostics().toString()); + } + else + if(diagGraphItem!=0) + { + delete diagGraphItem; + diagGraphItem=0; + } + } + + ////////////////////////////////////////////// + void OPMapWidget::SetShowCompass(const bool &value) + { + if(value && !compass) + { + compass=new QGraphicsSvgItem(QString::fromUtf8(":/markers/images/compas.svg")); + compass->setScale(0.1+0.05*(qreal)(this->size().width())/1000*(qreal)(this->size().height())/600); + // compass->setTransformOriginPoint(compass->boundingRect().width(),compass->boundingRect().height()); + compass->setFlag(QGraphicsItem::ItemIsMovable,true); + mscene.addItem(compass); + compass->setTransformOriginPoint(compass->boundingRect().width()/2,compass->boundingRect().height()/2); + compass->setPos(55-compass->boundingRect().width()/2,55-compass->boundingRect().height()/2); + compass->setZValue(3); + compass->setOpacity(0.7); + + } + if(!value && compass) + { + delete compass; + compass=0; + } + } + void OPMapWidget::SetRotate(qreal const& value) + { + map->mapRotate(value); + if(compass && (compass->rotation() != value)) { + compass->setRotation(value); + } + } + void OPMapWidget::RipMap() + { + new MapRipper(core,map->SelectedArea()); + } +} diff --git a/lib/opmapcontrol/src/mapwidget/opmapwidget.h b/lib/opmapcontrol/src/mapwidget/opmapwidget.h new file mode 100644 index 0000000000000000000000000000000000000000..e080bfc30df27e8860b269bcbc33ab592d5f1e55 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/opmapwidget.h @@ -0,0 +1,479 @@ +/** +****************************************************************************** +* +* @file opmapwidget.h +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief The Map Widget, this is the part exposed to the user +* @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 OPMAPWIDGET_H +#define OPMAPWIDGET_H + +#include "../mapwidget/mapgraphicitem.h" +#include "../core/geodecoderstatus.h" +#include "../core/maptype.h" +#include "../core/languagetype.h" +#include "../core/diagnostics.h" +#include "configuration.h" +#include +#include +#include "waypointitem.h" +#include "QtSvg/QGraphicsSvgItem" +#include "uavitem.h" +#include "gpsitem.h" +#include "homeitem.h" +#include "mapripper.h" +namespace mapcontrol +{ + class UAVItem; + class GPSItem; + class HomeItem; + /** + * @brief Collection of static functions to help dealing with various enums used + * Contains functions for enumToString conversio, StringToEnum, QStringList of enum values... + * + * @class Helper opmapwidget.h "opmapwidget.h" + */ + class Helper + { + public: + /** + * @brief Converts from String to Type + * + * @param value String to convert + * @return + */ + static MapType::Types MapTypeFromString(QString const& value){return MapType::TypeByStr(value);} + /** + * @brief Converts from Type to String + */ + static QString StrFromMapType(MapType::Types const& value){return MapType::StrByType(value);} + /** + * @brief Returns QStringList with string representing all the enum values + */ + static QStringList MapTypes(){return MapType::TypesList();} + + /** + * @brief Converts from String to Type + */ + static GeoCoderStatusCode::Types GeoCoderStatusCodeFromString(QString const& value){return GeoCoderStatusCode::TypeByStr(value);} + /** + * @brief Converts from Type to String + */ + static QString StrFromGeoCoderStatusCode(GeoCoderStatusCode::Types const& value){return GeoCoderStatusCode::StrByType(value);} + /** + * @brief Returns QStringList with string representing all the enum values + */ + static QStringList GeoCoderTypes(){return GeoCoderStatusCode::TypesList();} + + /** + * @brief Converts from String to Type + */ + static internals::MouseWheelZoomType::Types MouseWheelZoomTypeFromString(QString const& value){return internals::MouseWheelZoomType::TypeByStr(value);} + /** + * @brief Converts from Type to String + */ + static QString StrFromMouseWheelZoomType(internals::MouseWheelZoomType::Types const& value){return internals::MouseWheelZoomType::StrByType(value);} + /** + * @brief Returns QStringList with string representing all the enum values + */ + static QStringList MouseWheelZoomTypes(){return internals::MouseWheelZoomType::TypesList();} + /** + * @brief Converts from String to Type + */ + static core::LanguageType::Types LanguageTypeFromString(QString const& value){return core::LanguageType::TypeByStr(value);} + /** + * @brief Converts from Type to String + */ + static QString StrFromLanguageType(core::LanguageType::Types const& value){return core::LanguageType::StrByType(value);} + /** + * @brief Returns QStringList with string representing all the enum values + */ + static QStringList LanguageTypes(){return core::LanguageType::TypesList();} + /** + * @brief Converts from String to Type + */ + static core::AccessMode::Types AccessModeFromString(QString const& value){return core::AccessMode::TypeByStr(value);} + /** + * @brief Converts from Type to String + */ + static QString StrFromAccessMode(core::AccessMode::Types const& value){return core::AccessMode::StrByType(value);} + /** + * @brief Returns QStringList with string representing all the enum values + */ + static QStringList AccessModeTypes(){return core::AccessMode::TypesList();} + + /** + * @brief Converts from String to Type + */ + static UAVMapFollowType::Types UAVMapFollowFromString(QString const& value){return UAVMapFollowType::TypeByStr(value);} + /** + * @brief Converts from Type to String + */ + static QString StrFromUAVMapFollow(UAVMapFollowType::Types const& value){return UAVMapFollowType::StrByType(value);} + /** + * @brief Returns QStringList with string representing all the enum values + */ + static QStringList UAVMapFollowTypes(){return UAVMapFollowType::TypesList();} + /** + * @brief Converts from String to Type + */ + static UAVTrailType::Types UAVTrailTypeFromString(QString const& value){return UAVTrailType::TypeByStr(value);} + /** + * @brief Converts from Type to String + */ + static QString StrFromUAVTrailType(UAVTrailType::Types const& value){return UAVTrailType::StrByType(value);} + /** + * @brief Returns QStringList with string representing all the enum values + */ + static QStringList UAVTrailTypes(){return UAVTrailType::TypesList();} + }; + + class OPMapWidget:public QGraphicsView + { + Q_OBJECT + + // Q_PROPERTY(int MaxZoom READ MaxZoom WRITE SetMaxZoom) + Q_PROPERTY(int MinZoom READ MinZoom WRITE SetMinZoom) + Q_PROPERTY(bool ShowTileGridLines READ ShowTileGridLines WRITE SetShowTileGridLines) + Q_PROPERTY(double Zoom READ ZoomTotal WRITE SetZoom) + Q_PROPERTY(qreal Rotate READ Rotate WRITE SetRotate) + Q_ENUMS(internals::MouseWheelZoomType::Types) + Q_ENUMS(internals::GeoCoderStatusCode::Types) + + public: + QSize sizeHint() const; + /** + * @brief Constructor + * + * @param parent parent widget + * @param config pointer to configuration classed to be used + * @return + */ + OPMapWidget(QWidget *parent=0,Configuration *config=new Configuration); + ~OPMapWidget(); + + /** + * @brief Returns true if map is showing gridlines + * + * @return bool + */ + bool ShowTileGridLines()const {return map->showTileGridLines;} + + /** + * @brief Defines if map is to show gridlines + * + * @param value + * @return + */ + void SetShowTileGridLines(bool const& value){map->showTileGridLines=value;map->update();} + + /** + * @brief Returns the maximum zoom for the map + * + */ + int MaxZoom()const{return map->MaxZoom();} + + // void SetMaxZoom(int const& value){map->maxZoom = value;} + + /** + * @brief + * + */ + int MinZoom()const{return map->minZoom;} + /** + * @brief + * + * @param value + */ + void SetMinZoom(int const& value){map->minZoom = value;} + + internals::MouseWheelZoomType::Types GetMouseWheelZoomType(){return map->core->GetMouseWheelZoomType();} + void SetMouseWheelZoomType(internals::MouseWheelZoomType::Types const& value){map->core->SetMouseWheelZoomType(value);} + // void SetMouseWheelZoomTypeByStr(const QString &value){map->core->SetMouseWheelZoomType(internals::MouseWheelZoomType::TypeByStr(value));} + // QString GetMouseWheelZoomTypeStr(){return map->GetMouseWheelZoomTypeStr();} + + internals::RectLatLng SelectedArea()const{return map->selectedArea;} + void SetSelectedArea(internals::RectLatLng const& value){ map->selectedArea = value;this->update();} + + bool CanDragMap()const{return map->CanDragMap();} + void SetCanDragMap(bool const& value){map->SetCanDragMap(value);} + + internals::PointLatLng CurrentPosition()const{return map->core->CurrentPosition();} + void SetCurrentPosition(internals::PointLatLng const& value){map->core->SetCurrentPosition(value);} + + double ZoomReal(){return map->Zoom();} + double ZoomDigi(){return map->ZoomDigi();} + double ZoomTotal(){return map->ZoomTotal();} + void SetZoom(double const& value){map->SetZoom(value);} + + qreal Rotate(){return map->rotation;} + void SetRotate(qreal const& value); + + void ReloadMap(){map->ReloadMap(); map->resize();} + + GeoCoderStatusCode::Types SetCurrentPositionByKeywords(QString const& keys){return map->SetCurrentPositionByKeywords(keys);} + + bool UseOpenGL(){return useOpenGL;} + void SetUseOpenGL(bool const& value); + + MapType::Types GetMapType(){return map->core->GetMapType();} + void SetMapType(MapType::Types const& value){map->lastimage=QImage(); map->core->SetMapType(value);} + + bool isStarted(){return map->core->isStarted();} + + Configuration* configuration; + + internals::PointLatLng currentMousePosition(); + + void SetFollowMouse(bool const& value){followmouse=value;this->setMouseTracking(followmouse);} + bool FollowMouse(){return followmouse;} + + internals::PointLatLng GetFromLocalToLatLng(QPointF p) {return map->FromLocalToLatLng(p.x(),p.y());} + + /** + * @brief Creates a new WayPoint on the center of the map + * + * @return WayPointItem a pointer to the WayPoint created + */ + WayPointItem* WPCreate(); + /** + * @brief Creates a new WayPoint + * + * @param item the WayPoint to create + */ + void WPCreate(WayPointItem* item); + /** + * @brief Creates a new WayPoint + * + * @param coord the coordinates in LatLng of the WayPoint + * @param altitude the Altitude of the WayPoint + * @return WayPointItem a pointer to the WayPoint created + */ + WayPointItem* WPCreate(internals::PointLatLng const& coord,int const& altitude); + /** + * @brief Creates a new WayPoint + * + * @param coord the coordinates in LatLng of the WayPoint + * @param altitude the Altitude of the WayPoint + * @param description the description of the WayPoint + * @return WayPointItem a pointer to the WayPoint created + */ + WayPointItem* WPCreate(internals::PointLatLng const& coord,int const& altitude, QString const& description); + /** + * @brief Inserts a new WayPoint on the specified position + * + * @param position index of the WayPoint + * @return WayPointItem a pointer to the WayPoint created + */ + WayPointItem* WPInsert(int const& position); + /** + * @brief Inserts a new WayPoint on the specified position + * + * @param item the WayPoint to Insert + * @param position index of the WayPoint + */ + void WPInsert(WayPointItem* item,int const& position); + /** + * @brief Inserts a new WayPoint on the specified position + * + * @param coord the coordinates in LatLng of the WayPoint + * @param altitude the Altitude of the WayPoint + * @param position index of the WayPoint + * @return WayPointItem a pointer to the WayPoint Inserted + */ + WayPointItem* WPInsert(internals::PointLatLng const& coord,int const& altitude,int const& position); + /** + * @brief Inserts a new WayPoint on the specified position + * + * @param coord the coordinates in LatLng of the WayPoint + * @param altitude the Altitude of the WayPoint + * @param description the description of the WayPoint + * @param position index of the WayPoint + * @return WayPointItem a pointer to the WayPoint Inserted + */ + WayPointItem* WPInsert(internals::PointLatLng const& coord,int const& altitude, QString const& description,int const& position); + + /** + * @brief Deletes the WayPoint + * + * @param item the WayPoint to delete + */ + void WPDelete(WayPointItem* item); + /** + * @brief deletes all WayPoints + * + */ + void WPDeleteAll(); + /** + * @brief Returns the currently selected WayPoints + * + * @return @return QList + */ + QList WPSelected(); + + /** + * @brief Renumbers the WayPoint and all others as needed + * + * @param item the WayPoint to renumber + * @param newnumber the WayPoint's new number + */ + void WPRenumber(WayPointItem* item,int const& newnumber); + + void SetShowCompass(bool const& value); + + UAVItem* UAV; + GPSItem* GPS; + HomeItem* Home; + void SetShowUAV(bool const& value); + bool ShowUAV()const{return showuav;} + void SetShowHome(bool const& value); + bool ShowHome()const{return showhome;} + void SetShowDiagnostics(bool const& value); + private: + internals::Core *core; + MapGraphicItem *map; + QGraphicsScene mscene; + bool useOpenGL; + GeoCoderStatusCode x; + MapType y; + core::AccessMode xx; + internals::PointLatLng currentmouseposition; + bool followmouse; + void ConnectWP(WayPointItem* item); + QGraphicsSvgItem *compass; + bool showuav; + bool showhome; + QTimer * diagTimer; + QGraphicsTextItem * diagGraphItem; + bool showDiag; + private slots: + void diagRefresh(); + // WayPointItem* item;//apagar + protected: + void resizeEvent(QResizeEvent *event); + void showEvent ( QShowEvent * event ); + void closeEvent(QCloseEvent *event); + void mouseMoveEvent ( QMouseEvent * event ); + // private slots: + signals: + void zoomChanged(double zoomt,double zoom, double zoomd); + /** + * @brief fires when one of the WayPoints numbers changes (not fired if due to a auto-renumbering) + * + * @param oldnumber WayPoint old number + * @param newnumber WayPoint new number + * @param waypoint a pointer to the WayPoint that was renumbered + */ + void WPNumberChanged(int const& oldnumber,int const& newnumber,WayPointItem* waypoint); + /** + * @brief Fired when the description, altitude or coordinates of a WayPoint changed + * + * @param waypoint a pointer to the WayPoint + */ + void WPValuesChanged(WayPointItem* waypoint); + /** + * @brief Fires when a new WayPoint is inserted + * + * @param number new WayPoint number + * @param waypoint WayPoint inserted + */ + void WPReached(WayPointItem* waypoint); + /** + * @brief Fires when a new WayPoint is inserted + * + * @param number new WayPoint number + * @param waypoint WayPoint inserted + */ + void WPInserted(int const& number,WayPointItem* waypoint); + /** + * @brief Fires When a WayPoint is deleted + * + * @param number number of the deleted WayPoint + */ + void WPDeleted(int const& number); + /** + * @brief Fires When a WayPoint is Reached + * + * @param number number of the Reached WayPoint + */ + void UAVReachedWayPoint(int const& waypointnumber,WayPointItem* waypoint); + /** + * @brief Fires When the UAV lives the safety bouble + * + * @param position the position of the UAV + */ + void UAVLeftSafetyBouble(internals::PointLatLng const& position); + + /** + * @brief Fires when map position changes + * + * @param point the point in LatLng of the new center of the map + */ + void OnCurrentPositionChanged(internals::PointLatLng point); + /** + * @brief Fires when there are no more tiles to load + * + */ + void OnTileLoadComplete(); + /** + * @brief Fires when tiles loading begins + * + */ + void OnTileLoadStart(); + /** + * @brief Fires when the map is dragged + * + */ + void OnMapDrag(); + /** + * @brief Fires when map zoom changes + * + */ + void OnMapZoomChanged(); + /** + * @brief Fires when map type changes + * + * @param type The maps new type + */ + void OnMapTypeChanged(MapType::Types type); + /** + * @brief Fires when an error ocurred while loading a tile + * + * @param zoom tile zoom + * @param pos tile position + */ + void OnEmptyTileError(int zoom, core::Point pos); + /** + * @brief Fires when the number of tiles in the load queue changes + * + * @param number the number of tiles still in the queue + */ + void OnTilesStillToLoad(int number); + public slots: + /** + * @brief Ripps the current selection to the DB + */ + void RipMap(); + + }; +} +#endif // OPMAPWIDGET_H diff --git a/lib/opmapcontrol/src/mapwidget/trailitem.cpp b/lib/opmapcontrol/src/mapwidget/trailitem.cpp new file mode 100644 index 0000000000000000000000000000000000000000..41e50c29bf8367292813d7372fd21190aef10fd1 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/trailitem.cpp @@ -0,0 +1,57 @@ +/** +****************************************************************************** +* +* @file trailitem.cpp +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief A graphicsItem representing a trail point +* @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 "trailitem.h" +#include +namespace mapcontrol +{ + TrailItem::TrailItem(internals::PointLatLng const& coord,int const& altitude, QBrush color, QGraphicsItem* parent):QGraphicsItem(parent),coord(coord) + { + m_brush=color; + QDateTime time=QDateTime::currentDateTime(); + QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6); + setToolTip(QString(tr("Position:")+"%1\n"+tr("Altitude:")+"%2\n"+tr("Time:")+"%3").arg(coord_str).arg(QString::number(altitude)).arg(time.toString())); + } + + void TrailItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + { + // painter->drawRect(QRectF(-3,-3,6,6)); + painter->setBrush(m_brush); + painter->drawEllipse(-2,-2,4,4); + } + QRectF TrailItem::boundingRect()const + { + return QRectF(-2,-2,4,4); + } + + + int TrailItem::type()const + { + return Type; + } + + +} diff --git a/lib/opmapcontrol/src/mapwidget/trailitem.h b/lib/opmapcontrol/src/mapwidget/trailitem.h new file mode 100644 index 0000000000000000000000000000000000000000..4af8282d5485102ade296054b2157bb96f858858 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/trailitem.h @@ -0,0 +1,63 @@ +/** +****************************************************************************** +* +* @file trailitem.h +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief A graphicsItem representing a WayPoint +* @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 TRAILITEM_H +#define TRAILITEM_H + +#include +#include +#include +#include "../internals/pointlatlng.h" +#include + +namespace mapcontrol +{ + + class TrailItem:public QObject,public QGraphicsItem + { + Q_OBJECT + Q_INTERFACES(QGraphicsItem) + public: + enum { Type = UserType + 3 }; + TrailItem(internals::PointLatLng const& coord,int const& altitude, QBrush color, QGraphicsItem* parent); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget); + QRectF boundingRect() const; + int type() const; + internals::PointLatLng coord; + private: + QBrush m_brush; + + + public slots: + + signals: + + }; +} +#endif // TRAILITEM_H + + diff --git a/lib/opmapcontrol/src/mapwidget/uavitem.cpp b/lib/opmapcontrol/src/mapwidget/uavitem.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5499d55f38f97a637f1228bd4be667a1ded67082 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/uavitem.cpp @@ -0,0 +1,199 @@ +/** +****************************************************************************** +* +* @file uavitem.cpp +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief A graphicsItem representing a UAV +* @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 "../internals/pureprojection.h" +#include "uavitem.h" +namespace mapcontrol +{ + UAVItem::UAVItem(MapGraphicItem* map,OPMapWidget* parent):map(map),mapwidget(parent),showtrail(true),trailtime(5),traildistance(50),autosetreached(true) + ,autosetdistance(100) + { + pic.load(QString::fromUtf8(":/markers/images/mapquad.png")); + // Don't scale but trust the image we are given + // pic=pic.scaled(50,33,Qt::IgnoreAspectRatio); + localposition=map->FromLatLngToLocal(mapwidget->CurrentPosition()); + this->setPos(localposition.X(),localposition.Y()); + this->setZValue(4); + trail=new QGraphicsItemGroup(); + trail->setParentItem(map); + + + this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); + mapfollowtype=UAVMapFollowType::None; + trailtype=UAVTrailType::ByDistance; + timer.start(); + + // rect=QRectF(0,0,renderer.defaultSize().width()*0.05,renderer.defaultSize().height()*0.05); + + } + UAVItem::~UAVItem() + { + delete trail; + } + + void UAVItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + { + Q_UNUSED(option); + Q_UNUSED(widget); + // painter->rotate(-90); + painter->drawPixmap(-pic.width()/2,-pic.height()/2,pic); + // painter->drawRect(QRectF(-pic.width()/2,-pic.height()/2,pic.width()-1,pic.height()-1)); + } + QRectF UAVItem::boundingRect()const + { + return QRectF(-pic.width()/2,-pic.height()/2,pic.width(),pic.height()); + } + void UAVItem::SetUAVPos(const internals::PointLatLng &position, const int &altitude) + { + if(coord.IsEmpty()) + lastcoord=coord; + if(coord!=position) + { + + if(trailtype==UAVTrailType::ByTimeElapsed) + { + if(timer.elapsed()>trailtime*1000) + { + trail->addToGroup(new TrailItem(position,altitude,Qt::red,this)); + timer.restart(); + } + + } + else if(trailtype==UAVTrailType::ByDistance) + { + if(qAbs(internals::PureProjection::DistanceBetweenLatLng(lastcoord,position)*1000)>traildistance) + { + trail->addToGroup(new TrailItem(position,altitude,Qt::red,this)); + lastcoord=position; + } + } + coord=position; + this->altitude=altitude; + RefreshPos(); + if(mapfollowtype==UAVMapFollowType::CenterAndRotateMap||mapfollowtype==UAVMapFollowType::CenterMap) + { + mapwidget->SetCurrentPosition(coord); + } + this->update(); + if(autosetreached) + { + foreach(QGraphicsItem* i,map->childItems()) + { + WayPointItem* wp=qgraphicsitem_cast(i); + if(wp) + { + if(Distance3D(wp->Coord(),wp->Altitude())SetReached(true); + emit UAVReachedWayPoint(wp->Number(),wp); + } + } + } + } + if(mapwidget->Home!=0) + { + //verify if the UAV is inside the safety bouble + if(Distance3D(mapwidget->Home->Coord(),mapwidget->Home->Altitude())>mapwidget->Home->SafeArea()) + { + if(mapwidget->Home->safe!=false) + { + mapwidget->Home->safe=false; + mapwidget->Home->update(); + emit UAVLeftSafetyBouble(this->coord); + } + } + else + { + if(mapwidget->Home->safe!=true) + { + mapwidget->Home->safe=true; + mapwidget->Home->update(); + } + } + + } + } + } + + /** + * Rotate the UAV Icon on the map, or rotate the map + * depending on the display mode + */ + void UAVItem::SetUAVHeading(const qreal &value) + { + if(mapfollowtype==UAVMapFollowType::CenterAndRotateMap) + { + mapwidget->SetRotate(-value); + } + else { + if (this->rotation() != value) + this->setRotation(value); + } + } + + + int UAVItem::type()const + { + return Type; + } + + + void UAVItem::RefreshPos() + { + localposition=map->FromLatLngToLocal(coord); + this->setPos(localposition.X(),localposition.Y()); + foreach(QGraphicsItem* i,trail->childItems()) + { + TrailItem* w=qgraphicsitem_cast(i); + if(w) + w->setPos(map->FromLatLngToLocal(w->coord).X(),map->FromLatLngToLocal(w->coord).Y()); + //this->update(); + } + + } + void UAVItem::SetTrailType(const UAVTrailType::Types &value) + { + trailtype=value; + if(trailtype==UAVTrailType::ByTimeElapsed) + timer.restart(); + } + void UAVItem::SetShowTrail(const bool &value) + { + showtrail=value; + trail->setVisible(value); + } + void UAVItem::DeleteTrail()const + { + foreach(QGraphicsItem* i,trail->childItems()) + delete i; + } + double UAVItem::Distance3D(const internals::PointLatLng &coord, const int &altitude) + { + return sqrt(pow(internals::PureProjection::DistanceBetweenLatLng(this->coord,coord)*1000,2)+ + pow(this->altitude-altitude,2)); + + } +} diff --git a/lib/opmapcontrol/src/mapwidget/uavitem.h b/lib/opmapcontrol/src/mapwidget/uavitem.h new file mode 100644 index 0000000000000000000000000000000000000000..7250b900d209df895250cc9f9cbab2b170114f1b --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/uavitem.h @@ -0,0 +1,209 @@ +/** +****************************************************************************** +* +* @file uavitem.h +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief A graphicsItem representing a WayPoint +* @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 UAVITEM_H +#define UAVITEM_H + +#include +#include +#include +#include "../internals/pointlatlng.h" +#include "mapgraphicitem.h" +#include "waypointitem.h" +#include +#include "uavmapfollowtype.h" +#include "uavtrailtype.h" +#include +#include "opmapwidget.h" +#include "trailitem.h" +namespace mapcontrol +{ + class WayPointItem; + class OPMapWidget; + /** +* @brief A QGraphicsItem representing the UAV +* +* @class UAVItem uavitem.h "mapwidget/uavitem.h" +*/ + class UAVItem:public QObject,public QGraphicsItem + { + Q_OBJECT + Q_INTERFACES(QGraphicsItem) + public: + enum { Type = UserType + 2 }; + UAVItem(MapGraphicItem* map,OPMapWidget* parent); + ~UAVItem(); + /** + * @brief Sets the UAV position + * + * @param position LatLng point + * @param altitude altitude in meters + */ + void SetUAVPos(internals::PointLatLng const& position,int const& altitude); + /** + * @brief Sets the UAV heading + * + * @param value heading angle (north=0deg) + */ + void SetUAVHeading(qreal const& value); + /** + * @brief Returns the UAV position + * + * @return internals::PointLatLng + */ + internals::PointLatLng UAVPos()const{return coord;} + /** + * @brief Sets the Map follow type + * + * @param value can be "none"(map doesnt follow UAV), "CenterMap"(map moves to keep UAV centered) or "CenterAndRotateMap"(map moves and rotates to keep UAV centered and straight) + */ + void SetMapFollowType(UAVMapFollowType::Types const& value){mapfollowtype=value;} + /** + * @brief Sets the trail type + * + * @param value can be "NoTrail"(no trail is plotted), "ByTimeElapsed"(a trail point is plotted each TrailTime()) or ByDistance(a trail point is plotted if the distance between the UAV and the last trail point is bigger than TrailDistance()) + */ + void SetTrailType(UAVTrailType::Types const& value); + /** + * @brief Returns the map follow method used + * + * @return UAVMapFollowType::Types + */ + UAVMapFollowType::Types GetMapFollowType()const{return mapfollowtype;} + /** + * @brief Returns the UAV trail type. It can be plotted by time elapsed or distance + * + * @return UAVTrailType::Types + */ + UAVTrailType::Types GetTrailType()const{return trailtype;} + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget); + void RefreshPos(); + QRectF boundingRect() const; + /** + * @brief Sets the trail time to be used if TrailType is ByTimeElapsed + * + * @param seconds the UAV trail time elapsed value. If the trail type is time elapsed + * a trail point will be plotted each "value returned" seconds. + */ + void SetTrailTime(int const& seconds){trailtime=seconds;} + /** + * @brief Returns the UAV trail time elapsed value. If the trail type is time elapsed + * a trail point will be plotted each "value returned" seconds. + * + * @return int + */ + int TrailTime()const{return trailtime;} + /** + * @brief Sets the trail distance to be used if TrailType is ByDistance + * + * @param distance the UAV trail plot distance. + * If the trail type is ByDistance a trail dot is plotted if + * the distance between the current UAV position and the last trail point + * is bigger than the returned value + */ + void SetTrailDistance(int const& distance){traildistance=distance;} + /** + * @brief Returns the UAV trail plot distance. + * If the trail type is distance diference a trail dot is plotted if + * the distance between the current UAV position and the last trail point + * is bigger than the returned value + * + * @return int + */ + int TrailDistance()const{return traildistance;} + /** + * @brief Returns true if UAV trail is shown + * + * @return bool + */ + bool ShowTrail()const{return showtrail;} + /** + * @brief Used to define if the UAV displays a trail + * + * @param value + */ + void SetShowTrail(bool const& value); + /** + * @brief Deletes all the trail points + */ + void DeleteTrail()const; + /** + * @brief Returns true if the UAV automaticaly sets WP reached value (changing its color) + * + * @return bool + */ + bool AutoSetReached()const{return autosetreached;} + /** + * @brief Defines if the UAV can set the WP's "reached" value automaticaly. + * + * @param value + */ + void SetAutoSetReached(bool const& value){autosetreached=value;} + /** + * @brief Returns the 3D distance in meters necessary for the UAV to set WP's to "reached" + * + * @return double + */ + double AutoSetDistance()const{return autosetdistance;} + /** + * @brief Sets the the 3D distance in meters necessary for the UAV to set WP's to "reached" + * + * @param value + */ + void SetAutoSetDistance(double const& value){autosetdistance=value;} + + int type() const; + private: + MapGraphicItem* map; + + int altitude; + UAVMapFollowType::Types mapfollowtype; + UAVTrailType::Types trailtype; + internals::PointLatLng coord; + internals::PointLatLng lastcoord; + QPixmap pic; + core::Point localposition; + OPMapWidget* mapwidget; + QGraphicsItemGroup* trail; + QTime timer; + bool showtrail; + int trailtime; + int traildistance; + bool autosetreached; + double Distance3D(internals::PointLatLng const& coord, int const& altitude); + double autosetdistance; + // QRectF rect; + + public slots: + + signals: + void UAVReachedWayPoint(int const& waypointnumber,WayPointItem* waypoint); + void UAVLeftSafetyBouble(internals::PointLatLng const& position); + }; +} +#endif // UAVITEM_H diff --git a/lib/opmapcontrol/src/mapwidget/uavmapfollowtype.h b/lib/opmapcontrol/src/mapwidget/uavmapfollowtype.h new file mode 100644 index 0000000000000000000000000000000000000000..a2321a4c3152ca73ce6b109674e21dd5f774403e --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/uavmapfollowtype.h @@ -0,0 +1,86 @@ +/** +****************************************************************************** +* +* @file uavmapfollowtype.h +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief An enum representing the various map follow modes +* @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 UAVMAPFOLLOWTYPE_H +#define UAVMAPFOLLOWTYPE_H +#include +#include +#include +#include +namespace mapcontrol { + class UAVMapFollowType:public QObject + { + Q_OBJECT + Q_ENUMS(Types) + public: + enum Types + { + /// + /// only centers the map on the UAV + /// + CenterMap, + + /// + /// centers and rotates map on the UAV + /// + CenterAndRotateMap, + + /// + /// map is not connected to UAV position or heading + /// + None + }; + static QString StrByType(Types const& value) + { + QMetaObject metaObject = UAVMapFollowType().staticMetaObject; + QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types")); + QString s=metaEnum.valueToKey(value); + return s; + } + static Types TypeByStr(QString const& value) + { + QMetaObject metaObject = UAVMapFollowType().staticMetaObject; + QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types")); + Types s=(Types)metaEnum.keyToValue(value.toLatin1()); + return s; + } + static QStringList TypesList() + { + QStringList ret; + QMetaObject metaObject = UAVMapFollowType().staticMetaObject; + QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types")); + for(int x=0;x +#include +#include +#include +namespace mapcontrol { + class UAVTrailType:public QObject + { + Q_OBJECT + Q_ENUMS(Types) + public: + enum Types + { + /** + * @brief UAV does not plot a trail + * + * @var NoTrail + */ + NoTrail, + /** + * @brief UAV plots a trail point every 'x' seconds + * + * @var ByTimeElapsed + */ + ByTimeElapsed, + /** + * @brief UAV plots a trail point every 'x' meters (ground distance) + * + * @var ByDistance + */ + ByDistance + }; + static QString StrByType(Types const& value) + { + QMetaObject metaObject = UAVTrailType().staticMetaObject; + QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types")); + QString s=metaEnum.valueToKey(value); + return s; + } + static Types TypeByStr(QString const& value) + { + QMetaObject metaObject = UAVTrailType().staticMetaObject; + QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types")); + Types s=(Types)metaEnum.keyToValue(value.toLatin1()); + return s; + } + static QStringList TypesList() + { + QStringList ret; + QMetaObject metaObject = UAVTrailType().staticMetaObject; + QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types")); + for(int x=0;xsetFlag(QGraphicsItem::ItemIsMovable,true); + this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); + this->setFlag(QGraphicsItem::ItemIsSelectable,true); + // transf.translate(picture.width()/2,picture.height()); + // this->setTransform(transf); + SetShowNumber(shownumber); + RefreshToolTip(); + RefreshPos(); + } + WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitude, const QString &description, MapGraphicItem *map):coord(coord),reached(false),description(description),shownumber(true),isDragging(false),altitude(altitude),map(map) + { + text=0; + numberI=0; + picture.load(QString::fromUtf8(":/markers/images/marker.png")); + number=WayPointItem::snumber; + ++WayPointItem::snumber; + this->setFlag(QGraphicsItem::ItemIsMovable,true); + this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); + this->setFlag(QGraphicsItem::ItemIsSelectable,true); + //transf.translate(picture.width()/2,picture.height()); + // this->setTransform(transf); + SetShowNumber(shownumber); + RefreshToolTip(); + RefreshPos(); + } + + QRectF WayPointItem::boundingRect() const + { + return QRectF(-picture.width()/2,-picture.height(),picture.width(),picture.height()); + } + void WayPointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + { + Q_UNUSED(option); + Q_UNUSED(widget); + painter->drawPixmap(-picture.width()/2,-picture.height(),picture); + if(this->isSelected()) + painter->drawRect(QRectF(-picture.width()/2,-picture.height(),picture.width()-1,picture.height()-1)); + } + void WayPointItem::mousePressEvent(QGraphicsSceneMouseEvent *event) + { + if(event->button()==Qt::LeftButton) + { + text=new QGraphicsSimpleTextItem(this); + textBG=new QGraphicsRectItem(this); + +// textBG->setBrush(Qt::white); +// textBG->setOpacity(0.5); + + textBG->setBrush(QColor(255, 255, 255, 128)); + + text->setPen(QPen(Qt::red)); + text->setPos(10,-picture.height()); + textBG->setPos(10,-picture.height()); + text->setZValue(3); + RefreshToolTip(); + isDragging=true; + } + QGraphicsItem::mousePressEvent(event); + } + void WayPointItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) + { + if(event->button()==Qt::LeftButton) + { + delete text; + delete textBG; + coord=map->FromLocalToLatLng(this->pos().x(),this->pos().y()); + isDragging=false; + RefreshToolTip(); + + emit WPValuesChanged(this); + } + QGraphicsItem::mouseReleaseEvent(event); + } + void WayPointItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) + { + + if(isDragging) + { + coord=map->FromLocalToLatLng(this->pos().x(),this->pos().y()); + QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6); + text->setText(coord_str); + textBG->setRect(text->boundingRect()); + + emit WPValuesChanged(this); + } + QGraphicsItem::mouseMoveEvent(event); + } + void WayPointItem::SetAltitude(const int &value) + { + altitude=value; + RefreshToolTip(); + + emit WPValuesChanged(this); + this->update(); + } + void WayPointItem::SetCoord(const internals::PointLatLng &value) + { + coord=value; + emit WPValuesChanged(this); + RefreshPos(); + RefreshToolTip(); + this->update(); + } + void WayPointItem::SetDescription(const QString &value) + { + description=value; + RefreshToolTip(); + emit WPValuesChanged(this); + this->update(); + } + void WayPointItem::SetNumber(const int &value) + { + emit WPNumberChanged(number,value,this); + number=value; + RefreshToolTip(); + numberI->setText(QString::number(number)); + numberIBG->setRect(numberI->boundingRect().adjusted(-2,0,1,0)); + this->update(); + } + void WayPointItem::SetReached(const bool &value) + { + reached=value; + emit WPValuesChanged(this); + if(value) + picture.load(QString::fromUtf8(":/markers/images/bigMarkerGreen.png")); + else + picture.load(QString::fromUtf8(":/markers/images/marker.png")); + this->update(); + + } + void WayPointItem::SetShowNumber(const bool &value) + { + shownumber=value; + if((numberI==0) && value) + { + numberI=new QGraphicsSimpleTextItem(this); + numberIBG=new QGraphicsRectItem(this); + numberIBG->setBrush(Qt::white); + numberIBG->setOpacity(0.5); + numberI->setZValue(3); + numberI->setPen(QPen(Qt::blue)); + numberI->setPos(0,-13-picture.height()); + numberIBG->setPos(0,-13-picture.height()); + numberI->setText(QString::number(number)); + numberIBG->setRect(numberI->boundingRect().adjusted(-2,0,1,0)); + } + else if (!value && numberI) + { + delete numberI; + delete numberIBG; + } + this->update(); + } + void WayPointItem::WPDeleted(const int &onumber) + { + if(number>onumber) --number; + numberI->setText(QString::number(number)); + numberIBG->setRect(numberI->boundingRect().adjusted(-2,0,1,0)); + RefreshToolTip(); + this->update(); + } + void WayPointItem::WPInserted(const int &onumber, WayPointItem *waypoint) + { + if(waypoint!=this) + { + if(onumber<=number) ++number; + numberI->setText(QString::number(number)); + RefreshToolTip(); + this->update(); + } + } + void WayPointItem::WPRenumbered(const int &oldnumber, const int &newnumber, WayPointItem *waypoint) + { + if (waypoint!=this) + { + if(((oldnumber>number) && (newnumber<=number))) + { + ++number; + numberI->setText(QString::number(number)); + numberIBG->setRect(numberI->boundingRect().adjusted(-2,0,1,0)); + RefreshToolTip(); + } + else if (((oldnumbernumber))) + { + --number; + numberI->setText(QString::number(number)); + numberIBG->setRect(numberI->boundingRect().adjusted(-2,0,1,0)); + RefreshToolTip(); + } + else if (newnumber==number) + { + ++number; + numberI->setText(QString::number(number)); + RefreshToolTip(); + } + this->update(); + } + } + int WayPointItem::type() const + { + // Enable the use of qgraphicsitem_cast with this item. + return Type; + } + + WayPointItem::~WayPointItem() + { + --WayPointItem::snumber; + } + void WayPointItem::RefreshPos() + { + core::Point point=map->FromLatLngToLocal(coord); + this->setPos(point.X(),point.Y()); + } + void WayPointItem::RefreshToolTip() + { + QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6); + setToolTip(QString("WayPoint Number:%1\nDescription:%2\nCoordinate:%4\nAltitude:%5").arg(QString::number(WayPointItem::number)).arg(description).arg(coord_str).arg(QString::number(altitude))); + } + + int WayPointItem::snumber=0; +} diff --git a/lib/opmapcontrol/src/mapwidget/waypointitem.h b/lib/opmapcontrol/src/mapwidget/waypointitem.h new file mode 100644 index 0000000000000000000000000000000000000000..b9bee5ce53a14d4fde0e6dc8e0a4638e1f0a9ed8 --- /dev/null +++ b/lib/opmapcontrol/src/mapwidget/waypointitem.h @@ -0,0 +1,210 @@ +/** +****************************************************************************** +* +* @file waypointitem.h +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @brief A graphicsItem representing a WayPoint +* @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 WAYPOINTITEM_H +#define WAYPOINTITEM_H + +#include +#include +#include +#include "../internals/pointlatlng.h" +#include "mapgraphicitem.h" +#include +namespace mapcontrol +{ +/** +* @brief A QGraphicsItem representing a WayPoint +* +* @class WayPointItem waypointitem.h "waypointitem.h" +*/ +class WayPointItem:public QObject,public QGraphicsItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsItem) +public: + enum { Type = UserType + 1 }; + /** + * @brief Constructer + * + * @param coord coordinates in LatLng of the Waypoint + * @param altitude altitude of the WayPoint + * @param map pointer to map to use + * @return + */ + WayPointItem(internals::PointLatLng const& coord,int const& altitude,MapGraphicItem* map); + /** + * @brief Constructer + * + * @param coord coordinates in LatLng of the WayPoint + * @param altitude altitude of the WayPoint + * @param description description fo the WayPoint + * @param map pointer to map to use + * @return + */ + WayPointItem(internals::PointLatLng const& coord,int const& altitude,QString const& description,MapGraphicItem* map); + /** + * @brief Returns the WayPoint description + * + * @return QString + */ + QString Description(){return description;} + /** + * @brief Sets the WayPoint description + * + * @param value + */ + void SetDescription(QString const& value); + /** + * @brief Returns true if WayPoint is Reached + * + * @return bool + */ + bool Reached(){return reached;} + /** + * @brief Sets if WayPoint is Reached + * + * @param value + */ + void SetReached(bool const& value); + /** + * @brief Returns the WayPoint number + * + */ + int Number(){return number;} + /** + * @brief Sets WayPoint number + * + * @param value + */ + void SetNumber(int const& value); + /** + * @brief Returns WayPoint LatLng coordinate + * + */ + internals::PointLatLng Coord(){return coord;} + /** + * @brief Sets WayPoint LatLng coordinate + * + * @param value + */ + void SetCoord(internals::PointLatLng const& value); + /** + * @brief Used if WayPoint number is to be drawn on screen + * + */ + bool ShowNumber(){return shownumber;} + /** + * @brief Used to set if WayPoint number is to be drawn on screen + * + * @param value + */ + void SetShowNumber(bool const& value); + /** + * @brief Returns the WayPoint altitude + * + * @return int + */ + int Altitude(){return altitude;} + /** + * @brief Sets the WayPoint Altitude + * + * @param value + */ + void SetAltitude(int const& value); + int type() const; + QRectF boundingRect() const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget); + void RefreshPos(); + void RefreshToolTip(); + QPixmap picture; +~WayPointItem(); + + static int snumber; +protected: + void mouseMoveEvent ( QGraphicsSceneMouseEvent * event ); + void mousePressEvent ( QGraphicsSceneMouseEvent * event ); + void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + + +private: + internals::PointLatLng coord;//coordinates of this WayPoint + bool reached; + QString description; + bool shownumber; + bool isDragging; + int altitude; + MapGraphicItem* map; + int number; + + + QGraphicsSimpleTextItem* text; + QGraphicsRectItem* textBG; + QGraphicsSimpleTextItem* numberI; + QGraphicsRectItem* numberIBG; + QTransform transf; + +public slots: + /** + * @brief Called when a WayPoint is deleted + * + * @param number number of the WayPoint that was deleted + */ + void WPDeleted(int const& number); + /** + * @brief Called when a WayPoint is renumbered + * + * @param oldnumber the old WayPoint number + * @param newnumber the new WayPoint number + * @param waypoint a pointer to the WayPoint renumbered + */ + void WPRenumbered(int const& oldnumber,int const& newnumber,WayPointItem* waypoint); + /** + * @brief Called when a WayPoint is inserted + * + * @param number the number of the WayPoint + * @param waypoint a pointer to the WayPoint inserted + */ + void WPInserted(int const& number,WayPointItem* waypoint); +signals: + /** + * @brief fires when this WayPoint number changes (not fired if due to a auto-renumbering) + * + * @param oldnumber this WayPoint old number + * @param newnumber this WayPoint new number + * @param waypoint a pointer to this WayPoint + */ + void WPNumberChanged(int const& oldnumber,int const& newnumber,WayPointItem* waypoint); + /** + * @brief Fired when the description, altitude or coordinates change + * + * @param waypoint a pointer to this WayPoint + */ + void WPValuesChanged(WayPointItem* waypoint); + +}; +} +#endif // WAYPOINTITEM_H diff --git a/lib/opmapcontrol/src/src.pro b/lib/opmapcontrol/src/src.pro new file mode 100644 index 0000000000000000000000000000000000000000..b676d74dc2b5f8e4966518a142f14f48a2fc1790 --- /dev/null +++ b/lib/opmapcontrol/src/src.pro @@ -0,0 +1,6 @@ +TEMPLATE = subdirs +CONFIG += ordered +SUBDIRS = core +SUBDIRS += internals +SUBDIRS += mapwidget +#SUBDIRS +=finaltest diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 19cc41a7e23adc4eba58f202b204464c20f888bc..c6b0e7837923984145604168916719b8b72a3e49 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -26,6 +26,7 @@ include(lib/QMapControl/QMapControl.pri) include(lib/nmea/nmea.pri) +#include(lib/opmapcontrol/opmapcontrol.pri) # message("Including bundled QMapControl version as FALLBACK. This is fine on Linux and MacOS, but not the best choice in Windows") QT += network \ @@ -105,9 +106,12 @@ include(src/lib/qwt/qwt.pri) DEPENDPATH += . \ lib/QMapControl \ lib/QMapControl/src \ + lib/opmapcontrol \ + lib/opmapcontrol/src \ plugins INCLUDEPATH += . \ lib/QMapControl \ + lib/opmapcontrol \ $$BASEDIR/../mavlink/include # ../mavlink/include \ diff --git a/src/ui/MAVLinkSettingsWidget.ui b/src/ui/MAVLinkSettingsWidget.ui index 33ad6b9b729c1f6d992059c3fe6bb345363dd7ee..f551a90b241e8a704bd0c4f2ca82879d8af7b361 100644 --- a/src/ui/MAVLinkSettingsWidget.ui +++ b/src/ui/MAVLinkSettingsWidget.ui @@ -338,7 +338,7 @@ - droneos.com:14555 + mavlink.droneos.com:14555