1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

OP-37 GCS/MapPlugin cleaning and bug hunting

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@704 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
zedamota 2010-06-02 20:22:31 +00:00 committed by zedamota
parent 59250845ea
commit f31cd81a8d
6 changed files with 597 additions and 577 deletions

View File

@ -27,29 +27,31 @@
*/ */
#include "core.h" #include "core.h"
#ifdef DEBUG_CORE
qlonglong internals::Core::debugcounter=0; qlonglong internals::Core::debugcounter=0;
#endif
using namespace projections; using namespace projections;
namespace internals { namespace internals {
Core::Core():currentPosition(0,0),currentPositionPixel(0,0),LastLocationInBounds(-1,-1),sizeOfMapArea(0,0) Core::Core():currentPosition(0,0),currentPositionPixel(0,0),LastLocationInBounds(-1,-1),sizeOfMapArea(0,0)
,minOfTiles(0,0),maxOfTiles(0,0),isDragging(false),started(false),MouseWheelZooming(false),TooltipTextPadding(10,10),zoom(0),loaderLimit(5) ,minOfTiles(0,0),maxOfTiles(0,0),isDragging(false),started(false),MouseWheelZooming(false),TooltipTextPadding(10,10),zoom(0),loaderLimit(5)
{ {
mousewheelzoomtype=MouseWheelZoomType::MousePositionAndCenter; mousewheelzoomtype=MouseWheelZoomType::MousePositionAndCenter;
SetProjection(new MercatorProjection()); SetProjection(new MercatorProjection());
this->setAutoDelete(false); this->setAutoDelete(false);
ProcessLoadTaskCallback.setMaxThreadCount(10);
renderOffset=Point(0,0); renderOffset=Point(0,0);
dragPoint=Point(0,0); dragPoint=Point(0,0);
CanDragMap=true; CanDragMap=true;
} }
void Core::run() void Core::run()
{ {
#ifdef DEBUG_CORE
qlonglong debug; qlonglong debug;
Mdebug.lock(); Mdebug.lock();
debug=++debugcounter; debug=++debugcounter;
Mdebug.unlock(); Mdebug.unlock();
#ifdef DEBUG_CORE
qDebug()<<"core:run"<<" ID="<<debug; qDebug()<<"core:run"<<" ID="<<debug;
#endif //DEBUG_CORE #endif //DEBUG_CORE
bool last = false; bool last = false;
@ -106,10 +108,12 @@ void Core::run()
} }
else // ok else // ok
{ {
#ifdef DEBUG_CORE
qDebug()<<"start getting image"<<" ID="<<debug; qDebug()<<"start getting image"<<" ID="<<debug;
#endif //DEBUG_CORE
img = OPMaps::Instance()->GetImageFrom(tl, task.Pos, task.Zoom); img = OPMaps::Instance()->GetImageFrom(tl, task.Pos, task.Zoom);
#ifdef DEBUG_CORE #ifdef DEBUG_CORE
qDebug()<<"Core::run:gotimage size:"<<img.count()<<" ID="<<debug; qDebug()<<"Core::run:gotimage size:"<<img.count()<<" ID="<<debug<<" time="<<t.elapsed();
#endif //DEBUG_CORE #endif //DEBUG_CORE
} }
@ -189,12 +193,14 @@ void Core::run()
} }
#ifdef DEBUG_CORE
qDebug()<<"loaderLimit release:"+loaderLimit.available()<<" ID="<<debug; qDebug()<<"loaderLimit release:"+loaderLimit.available()<<" ID="<<debug;
#endif
loaderLimit.release(); loaderLimit.release();
} }
} }
void Core::SetZoom(const int &value) void Core::SetZoom(const int &value)
{ {
if (zoom!=value && !isDragging) if (zoom!=value && !isDragging)
{ {
zoom=value; zoom=value;
@ -214,10 +220,10 @@ void Core::SetZoom(const int &value)
emit OnNeedInvalidation(); emit OnNeedInvalidation();
} }
} }
} }
void Core::SetCurrentPosition(const PointLatLng &value) void Core::SetCurrentPosition(const PointLatLng &value)
{ {
if(!IsDragging()) if(!IsDragging())
{ {
currentPosition = value; currentPosition = value;
@ -239,9 +245,9 @@ void Core::SetCurrentPosition(const PointLatLng &value)
emit OnCurrentPositionChanged(currentPosition); emit OnCurrentPositionChanged(currentPosition);
} }
} }
} }
void Core::SetMapType(const MapType::Types &value) void Core::SetMapType(const MapType::Types &value)
{ {
if(value != GetMapType()) if(value != GetMapType())
{ {
@ -318,9 +324,9 @@ void Core::SetMapType(const MapType::Types &value)
} }
} }
} }
void Core::StartSystem() void Core::StartSystem()
{ {
if(!started) if(!started)
{ {
started = true; started = true;
@ -328,17 +334,17 @@ void Core::StartSystem()
ReloadMap(); ReloadMap();
GoToCurrentPosition(); GoToCurrentPosition();
} }
} }
void Core::UpdateCenterTileXYLocation() void Core::UpdateCenterTileXYLocation()
{ {
PointLatLng center = FromLocalToLatLng(Width/2, Height/2); PointLatLng center = FromLocalToLatLng(Width/2, Height/2);
Point centerPixel = Projection()->FromLatLngToPixel(center, Zoom()); Point centerPixel = Projection()->FromLatLngToPixel(center, Zoom());
centerTileXYLocation = Projection()->FromPixelToTileXY(centerPixel); centerTileXYLocation = Projection()->FromPixelToTileXY(centerPixel);
} }
void Core::OnMapSizeChanged(int const& width, int const& height) void Core::OnMapSizeChanged(int const& width, int const& height)
{ {
Width = width; Width = width;
Height = height; Height = height;
@ -353,9 +359,9 @@ void Core::OnMapSizeChanged(int const& width, int const& height)
emit OnCurrentPositionChanged(currentPosition); emit OnCurrentPositionChanged(currentPosition);
} }
} }
void Core::OnMapClose() void Core::OnMapClose()
{ {
// if(waitOnEmptyTasks != null) // if(waitOnEmptyTasks != null)
// { // {
// try // try
@ -369,9 +375,9 @@ void Core::OnMapClose()
// } // }
CancelAsyncTasks(); CancelAsyncTasks();
} }
GeoCoderStatusCode::Types Core::SetCurrentPositionByKeywords(QString const& keys) GeoCoderStatusCode::Types Core::SetCurrentPositionByKeywords(QString const& keys)
{ {
GeoCoderStatusCode::Types status = GeoCoderStatusCode::Unknow; GeoCoderStatusCode::Types status = GeoCoderStatusCode::Unknow;
PointLatLng pos = OPMaps::Instance()->GetLatLngFromGeodecoder(keys, status); PointLatLng pos = OPMaps::Instance()->GetLatLngFromGeodecoder(keys, status);
if(pos.IsEmpty() && status == GeoCoderStatusCode::G_GEO_SUCCESS) if(pos.IsEmpty() && status == GeoCoderStatusCode::G_GEO_SUCCESS)
@ -380,29 +386,29 @@ GeoCoderStatusCode::Types Core::SetCurrentPositionByKeywords(QString const& keys
} }
return status; return status;
} }
RectLatLng Core::CurrentViewArea() RectLatLng Core::CurrentViewArea()
{ {
PointLatLng p = Projection()->FromPixelToLatLng(-renderOffset.X(), -renderOffset.Y(), Zoom()); PointLatLng p = Projection()->FromPixelToLatLng(-renderOffset.X(), -renderOffset.Y(), Zoom());
double rlng = Projection()->FromPixelToLatLng(-renderOffset.X() + Width, -renderOffset.Y(), Zoom()).Lng(); double rlng = Projection()->FromPixelToLatLng(-renderOffset.X() + Width, -renderOffset.Y(), Zoom()).Lng();
double blat = Projection()->FromPixelToLatLng(-renderOffset.X(), -renderOffset.Y() + Height, Zoom()).Lat(); double blat = Projection()->FromPixelToLatLng(-renderOffset.X(), -renderOffset.Y() + Height, Zoom()).Lat();
return RectLatLng::FromLTRB(p.Lng(), p.Lat(), rlng, blat); return RectLatLng::FromLTRB(p.Lng(), p.Lat(), rlng, blat);
} }
PointLatLng Core::FromLocalToLatLng(int const& x, int const& y) PointLatLng Core::FromLocalToLatLng(int const& x, int const& y)
{ {
return Projection()->FromPixelToLatLng(Point(x - renderOffset.X(), y - renderOffset.Y()), Zoom()); return Projection()->FromPixelToLatLng(Point(x - renderOffset.X(), y - renderOffset.Y()), Zoom());
} }
Point Core::FromLatLngToLocal(PointLatLng const& latlng) Point Core::FromLatLngToLocal(PointLatLng const& latlng)
{ {
Point pLocal = Projection()->FromLatLngToPixel(latlng, Zoom()); Point pLocal = Projection()->FromLatLngToPixel(latlng, Zoom());
pLocal.Offset(renderOffset); pLocal.Offset(renderOffset);
return pLocal; return pLocal;
} }
int Core::GetMaxZoomToFitRect(RectLatLng const& rect) int Core::GetMaxZoomToFitRect(RectLatLng const& rect)
{ {
int zoom = 0; int zoom = 0;
for(int i = 1; i <= OPMaps::Instance()->MaxZoom; i++) for(int i = 1; i <= OPMaps::Instance()->MaxZoom; i++)
@ -421,21 +427,21 @@ int Core::GetMaxZoomToFitRect(RectLatLng const& rect)
} }
return zoom; return zoom;
} }
void Core::BeginDrag(Point const& pt) void Core::BeginDrag(Point const& pt)
{ {
dragPoint.SetX(pt.X() - renderOffset.X()); dragPoint.SetX(pt.X() - renderOffset.X());
dragPoint.SetY(pt.Y() - renderOffset.Y()); dragPoint.SetY(pt.Y() - renderOffset.Y());
isDragging = true; isDragging = true;
} }
void Core::EndDrag() void Core::EndDrag()
{ {
isDragging = false; isDragging = false;
emit OnNeedInvalidation(); emit OnNeedInvalidation();
} }
void Core::ReloadMap() void Core::ReloadMap()
{ {
if(started) if(started)
{ {
#ifdef DEBUG_CORE #ifdef DEBUG_CORE
@ -452,9 +458,9 @@ void Core::ReloadMap()
emit OnNeedInvalidation(); emit OnNeedInvalidation();
} }
} }
void Core::GoToCurrentPosition() void Core::GoToCurrentPosition()
{ {
// reset stuff // reset stuff
renderOffset = Point::Empty; renderOffset = Point::Empty;
centerTileXYLocationLast = Point::Empty; centerTileXYLocationLast = Point::Empty;
@ -462,9 +468,9 @@ void Core::GoToCurrentPosition()
// goto location // goto location
Drag(Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2))); Drag(Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2)));
} }
void Core::GoToCurrentPositionOnZoom() void Core::GoToCurrentPositionOnZoom()
{ {
// reset stuff // reset stuff
renderOffset = Point::Empty; renderOffset = Point::Empty;
centerTileXYLocationLast = Point::Empty; centerTileXYLocationLast = Point::Empty;
@ -496,9 +502,9 @@ void Core::GoToCurrentPositionOnZoom()
} }
UpdateCenterTileXYLocation(); UpdateCenterTileXYLocation();
} }
void Core::DragOffset(Point const& offset) void Core::DragOffset(Point const& offset)
{ {
renderOffset.Offset(offset); renderOffset.Offset(offset);
UpdateCenterTileXYLocation(); UpdateCenterTileXYLocation();
@ -516,9 +522,9 @@ void Core::DragOffset(Point const& offset)
emit OnNeedInvalidation(); emit OnNeedInvalidation();
emit OnMapDrag(); emit OnMapDrag();
} }
void Core::Drag(Point const& pt) void Core::Drag(Point const& pt)
{ {
renderOffset.SetX(pt.X() - dragPoint.X()); renderOffset.SetX(pt.X() - dragPoint.X());
renderOffset.SetY(pt.Y() - dragPoint.Y()); renderOffset.SetY(pt.Y() - dragPoint.Y());
@ -541,9 +547,9 @@ void Core::Drag(Point const& pt)
emit OnMapDrag(); emit OnMapDrag();
} }
void Core::CancelAsyncTasks() void Core::CancelAsyncTasks()
{ {
if(started) if(started)
{ {
ProcessLoadTaskCallback.waitForDone(); ProcessLoadTaskCallback.waitForDone();
@ -554,9 +560,9 @@ void Core::CancelAsyncTasks()
MtileLoadQueue.unlock(); MtileLoadQueue.unlock();
// ProcessLoadTaskCallback.waitForDone(); // ProcessLoadTaskCallback.waitForDone();
} }
} }
void Core::UpdateBounds() void Core::UpdateBounds()
{ {
MtileDrawingList.lock(); MtileDrawingList.lock();
{ {
FindTilesAround(tileDrawingList); FindTilesAround(tileDrawingList);
@ -590,8 +596,8 @@ void Core::UpdateBounds()
} }
MtileDrawingList.unlock(); MtileDrawingList.unlock();
UpdateGroundResolution(); UpdateGroundResolution();
} }
void Core::FindTilesAround(QList<Point> &list) void Core::FindTilesAround(QList<Point> &list)
{ {
list.clear();; list.clear();;
for(int i = -sizeOfMapArea.Width(); i <= sizeOfMapArea.Width(); i++) for(int i = -sizeOfMapArea.Width(); i <= sizeOfMapArea.Width(); i++)
@ -624,8 +630,8 @@ void Core::FindTilesAround(QList<Point> &list)
} }
void Core::UpdateGroundResolution() void Core::UpdateGroundResolution()
{ {
double rez = Projection()->GetGroundResolution(Zoom(), CurrentPosition().Lat()); double rez = Projection()->GetGroundResolution(Zoom(), CurrentPosition().Lat());
pxRes100m = (int) (100.0 / rez); // 100 meters pxRes100m = (int) (100.0 / rez); // 100 meters
pxRes1000m = (int) (1000.0 / rez); // 1km pxRes1000m = (int) (1000.0 / rez); // 1km
@ -633,5 +639,5 @@ void Core::UpdateGroundResolution()
pxRes100km = (int) (100000.0 / rez); // 100km pxRes100km = (int) (100000.0 / rez); // 100km
pxRes1000km = (int) (1000000.0 / rez); // 1000km pxRes1000km = (int) (1000000.0 / rez); // 1000km
pxRes5000km = (int) (5000000.0 / rez); // 5000km pxRes5000km = (int) (5000000.0 / rez); // 5000km
} }
} }

View File

@ -28,9 +28,7 @@
#ifndef CORE_H #ifndef CORE_H
#define CORE_H #define CORE_H
#define DEBUG_CORE #include "debugheader.h"
//#define DEBUG_TILE
//#define DEBUG_TILEMATRIX
#include "../internals/PointLatlng.h" #include "../internals/PointLatlng.h"
#include "mousewheelzoomtype.h" #include "mousewheelzoomtype.h"
@ -56,11 +54,16 @@
//#include <QObject> //#include <QObject>
namespace mapcontrol
{
class OPMapControl;
}
namespace internals { namespace internals {
class Core:public QObject,public QRunnable class Core:public QObject,public QRunnable
{ {
Q_OBJECT Q_OBJECT
friend class mapcontrol::OPMapControl;
public: public:
Core(); Core();
void run(); void run();
@ -179,12 +182,7 @@ public:
TileMatrix Matrix; TileMatrix Matrix;
Rectangle tileRect;
Point mouseDown;
bool CanDragMap;
Point mouseCurrent;
PointLatLng LastLocationInBounds;
Point mouseLastZoom;
signals: signals:
void OnCurrentPositionChanged(PointLatLng point); void OnCurrentPositionChanged(PointLatLng point);
void OnTileLoadComplete(); void OnTileLoadComplete();
@ -197,14 +195,19 @@ signals:
private: private:
static qlonglong debugcounter;
PointLatLng currentPosition; PointLatLng currentPosition;
Point currentPositionPixel; Point currentPositionPixel;
Point renderOffset; Point renderOffset;
Point centerTileXYLocation; Point centerTileXYLocation;
Point centerTileXYLocationLast; Point centerTileXYLocationLast;
Point dragPoint; Point dragPoint;
Rectangle tileRect;
Point mouseDown;
bool CanDragMap;
Point mouseCurrent;
PointLatLng LastLocationInBounds;
Point mouseLastZoom;
MouseWheelZoomType::Types mousewheelzoomtype; MouseWheelZoomType::Types mousewheelzoomtype;
@ -233,9 +236,10 @@ private:
QMutex Moverlays; QMutex Moverlays;
QMutex MtileDrawingList; QMutex MtileDrawingList;
#ifdef DEBUG_CORE
QMutex Mdebug; QMutex Mdebug;
static qlonglong debugcounter;
#endif
Size TooltipTextPadding; Size TooltipTextPadding;
MapType::Types mapType; MapType::Types mapType;

View File

@ -0,0 +1,8 @@
#ifndef DEBUGHEADER_H
#define DEBUGHEADER_H
//#define DEBUG_CORE
//#define DEBUG_TILE
//#define DEBUG_TILEMATRIX
#endif // DEBUGHEADER_H

View File

@ -9,7 +9,8 @@ HEADERS += core.h \
pureprojection.h \ pureprojection.h \
pointlatlng.h \ pointlatlng.h \
rectlatlng.h \ rectlatlng.h \
sizelatlng.h sizelatlng.h \
debugheader.h
SOURCES += core.cpp \ SOURCES += core.cpp \
rectangle.cpp \ rectangle.cpp \
tile.cpp \ tile.cpp \
@ -19,7 +20,7 @@ SOURCES += core.cpp \
sizelatlng.cpp \ sizelatlng.cpp \
pointlatlng.cpp \ pointlatlng.cpp \
loadtask.cpp \ loadtask.cpp \
MouseWheelZoomType.cpp mousewheelzoomtype.cpp
HEADERS += ./projections/lks94projection.h \ HEADERS += ./projections/lks94projection.h \
./projections/mercatorprojection.h \ ./projections/mercatorprojection.h \
./projections/mercatorprojectionyandex.h \ ./projections/mercatorprojectionyandex.h \

View File

@ -33,6 +33,7 @@
#include "../core/point.h" #include "../core/point.h"
#include <QMutex> #include <QMutex>
#include <QDebug> #include <QDebug>
#include "debugheader.h"
using namespace core; using namespace core;
namespace internals namespace internals
{ {

View File

@ -32,7 +32,7 @@
#include "tile.h" #include "tile.h"
#include <QList> #include <QList>
#include "../core/point.h" #include "../core/point.h"
#include "debugheader.h"
namespace internals { namespace internals {
class TileMatrix class TileMatrix
{ {