1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

OP37/GCS Enhancements to smooth zooming. Continue preliminary work on the UAV overlay.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@994 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
zedamota 2010-07-03 13:05:22 +00:00 committed by zedamota
parent 0dedcd888c
commit 6714d62e42
7 changed files with 229 additions and 40 deletions

View File

@ -80,20 +80,22 @@ namespace mapcontrol
w->RefreshPos();
}
}
void MapGraphicItem::ConstructLastImage()
void MapGraphicItem::ConstructLastImage(int const& zoomdiff)
{
QImage temp;
QSize size=boundingRect().size().toSize();
size.setWidth(size.width()*2);
size.setHeight(size.height()*2);
lastimage=QImage(size,
size.setWidth(size.width()*2*zoomdiff);
size.setHeight(size.height()*2*zoomdiff);
temp=QImage(size,
QImage::Format_ARGB32_Premultiplied);
lastimage.fill(0);
QPainter* imagePainter=new QPainter(&lastimage);
imagePainter->translate(-boundingRect().topLeft());
imagePainter->scale(2,2);
paintImage(imagePainter);
imagePainter->end();
lastimagepoint=Point(core->GetrenderOffset().X()*2,core->GetrenderOffset().Y()*2);
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)
{
@ -104,13 +106,13 @@ namespace mapcontrol
transform.scale(MapRenderTransform,MapRenderTransform);
painter->setWorldTransform(transform);
{
DrawMap2D(painter,true);
DrawMap2D(painter);
}
painter->resetTransform();
}
else
{
DrawMap2D(painter,true);
DrawMap2D(painter);
}
//painter->drawRect(maprect);
}
@ -123,15 +125,14 @@ namespace mapcontrol
transform.scale(MapRenderTransform,MapRenderTransform);
painter->setWorldTransform(transform);
{
DrawMap2D(painter,false);
DrawMap2D(painter);
}
painter->resetTransform();
}
else
{
DrawMap2D(painter,false);
DrawMap2D(painter);
}
// painter->drawRect(maprect);
}
void MapGraphicItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
@ -251,12 +252,10 @@ namespace mapcontrol
core->MouseWheelZooming = false;
}
}
void MapGraphicItem::DrawMap2D(QPainter *painter,bool ToImage)
void MapGraphicItem::DrawMap2D(QPainter *painter)
{
// qDebug()<<core->Matrix.count();
// painter.drawText(10,10,"TESTE");
//painter->drawImage(0,0,lastimage);
if(!ToImage && !lastimage.isNull())
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++)
@ -337,6 +336,8 @@ namespace mapcontrol
}
// painter->drawRect(core->GetrenderOffset().X()-lastimagepoint.X()-3,core->GetrenderOffset().Y()-lastimagepoint.Y()-3,lastimage.width(),lastimage.height());
}
core::Point MapGraphicItem::FromLatLngToLocal(internals::PointLatLng const& point)
{
core::Point ret = core->FromLatLngToLocal(point);
@ -409,8 +410,8 @@ namespace mapcontrol
}
void MapGraphicItem::SetZoomStep(int const& value)
{
if(value-core->Zoom()==1 && value<= MaxZoom())
ConstructLastImage();
if(value-core->Zoom()>0 && value<= MaxZoom())
ConstructLastImage(value-core->Zoom());
else
lastimage=QImage();
if(value > MaxZoom())

View File

@ -92,9 +92,10 @@ namespace mapcontrol
bool IsDragging()const{return core->IsDragging();}
QImage lastimage;
// QPainter* imagePainter;
core::Point lastimagepoint;
void paintImage(QPainter* painter);
void ConstructLastImage();
void ConstructLastImage(int const& zoomdiff);
protected:
void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
void mousePressEvent ( QGraphicsSceneMouseEvent * event );
@ -123,8 +124,7 @@ namespace mapcontrol
Configuration *config;
bool showTileGridLines;
qreal MapRenderTransform;
void DrawMap2D(QPainter *painter,bool ToImage);
void DrawMap2D(QPainter *painter);
/**
* @brief Maximum possible zoom
*

View File

@ -17,7 +17,9 @@ HEADERS += mapgraphicitem.h \
opmapwidget.h \
configuration.h \
waypointitem.h \
uavitem.h
uavitem.h \
uavmapfollowtype.h \
uavtrailtype.h
QT += opengl
QT += network
QT += sql

View File

@ -304,7 +304,7 @@ namespace mapcontrol
void SetShowCompass(bool const& value);
QImage X(){map->ConstructLastImage(); return map->lastimage;}
QImage X(){return map->lastimage;}
private:
internals::Core *core;

View File

@ -33,13 +33,16 @@
#include <QLabel>
#include "../internals/pointlatlng.h"
#include "mapgraphicitem.h"
#include "waypointitem.h"
#include <QObject>
#include "uavmapfollowtype.h"
#include "uavtrailtype.h"
namespace mapcontrol
{
/**
* @brief A QGraphicsItem representing a WayPoint
* @brief A QGraphicsItem representing the UAV
*
* @class WayPointItem waypointitem.h "waypointitem.h"
* @class UAVItem uavitem.h "mapwidget/uavitem.h"
*/
class UAVItem:public QObject,public QGraphicsItem
{
@ -48,9 +51,14 @@ class UAVItem:public QObject,public QGraphicsItem
public:
enum { Type = UserType + 2 };
private:
int trailtime;
int traildistance;
public slots:
signals:
void UAVReachedWayPoint(int const& waypointnumber,WayPointItem* waypoint);
void UAVLeftSafetyBouble(internals::PointLatLng const& position);
};
}
#endif // UAVITEM_H

View File

@ -0,0 +1,87 @@
/**
******************************************************************************
*
* @file uavmapfollowtype.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @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 <QObject>
#include <QMetaObject>
#include <QMetaEnum>
#include <QStringList>
namespace mapcontrol {
class UAVMapFollowType:public QObject
{
Q_OBJECT
Q_ENUMS(Types)
public:
enum Types
{
/// <summary>
/// only centers the map on the UAV
/// </summary>
CenterMap,
/// <summary>
/// centers and rotates map on the UAV
/// </summary>
CenterAndRotateMap,
/// <summary>
/// map is not connected to UAV position or heading
/// </summary>
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<metaEnum.keyCount();++x)
{
ret.append(metaEnum.key(x));
}
return ret;
}
};
}
#endif // UAVMAPFOLLOWTYPE_H

View File

@ -0,0 +1,91 @@
/**
******************************************************************************
*
* @file uavtrailtype.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief An enum representing the uav trailing 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 UAVTRAILTYPE_H
#define UAVTRAILTYPE_H
#include <QObject>
#include <QMetaObject>
#include <QMetaEnum>
#include <QStringList>
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;x<metaEnum.keyCount();++x)
{
ret.append(metaEnum.key(x));
}
return ret;
}
};
}
#endif // UAVTRAILTYPE_H