dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
gpsitem.cpp
Go to the documentation of this file.
1 
13 /*
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, see <http://www.gnu.org/licenses/>
26 */
27 
28 #include "tlmapwidget.h"
29 #include "waypointitem.h"
30 #include "gpsitem.h"
31 
32 namespace mapcontrol
33 {
34  GPSItem::GPSItem(MapGraphicItem *map, TLMapWidget *parent, QString uavPic) :
35  mapwidget(parent),
36  showtrail(true),
37  showtrailline(true),
38  trailtime(5),
39  traildistance(50),
40  autosetreached(true),
41  autosetdistance(100)
42  {
43  this->map = map;
44  altitude = 0;
45  pic.load(uavPic);
46  // Don't scale but trust the image we are given
47  // pic=pic.scaled(50,33,Qt::IgnoreAspectRatio);
48  localposition=map->FromLatLngToLocal(mapwidget->CurrentPosition());
49  this->setPos(localposition.X(),localposition.Y());
50  this->setZValue(4);
51  trail=new QGraphicsItemGroup(this);
52  trail->setParentItem(map);
53  trailLine=new QGraphicsItemGroup(this);
54  trailLine->setParentItem(map);
55  this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true);
56  mapfollowtype=UAVMapFollowType::None;
57  trailtype=UAVTrailType::ByDistance;
58  timer.start();
59  connect(map,SIGNAL(childRefreshPosition()),this,SLOT(RefreshPos()));
60  connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal)));
61  }
62  GPSItem::~GPSItem()
63  {
64 
65  }
66 
67  void GPSItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
68  {
69  Q_UNUSED(option);
70  Q_UNUSED(widget);
71  painter->drawPixmap(-pic.width()/2,-pic.height()/2,pic);
72  }
73  QRectF GPSItem::boundingRect()const
74  {
75  return QRectF(-pic.width()/2,-pic.height()/2,pic.width(),pic.height());
76  }
77  void GPSItem::SetUAVPos(const internals::PointLatLng &position, const int &altitude)
78  {
79  if(coord.IsEmpty())
80  lastcoord=coord;
81  if(coord!=position)
82  {
83 
84  if(trailtype==UAVTrailType::ByTimeElapsed)
85  {
86  if(timer.elapsed()>trailtime*1000)
87  {
88  TrailItem * ob=new TrailItem(position,altitude,Qt::green,map);
89  trail->addToGroup(ob);
90  connect(this,SIGNAL(setChildPosition()),ob,SLOT(setPosSLOT()));
91  if(!lasttrailline.IsEmpty())
92  {
93  TrailLineItem * obj=new TrailLineItem(lasttrailline,position,Qt::red,map);
94  trailLine->addToGroup(obj);
95  connect(this,SIGNAL(setChildLine()),obj,SLOT(setLineSlot()));
96  }
97  lasttrailline=position;
98  timer.restart();
99  }
100 
101  }
102  else if(trailtype==UAVTrailType::ByDistance)
103  {
104  if(qAbs(internals::PureProjection::DistanceBetweenLatLng(lastcoord,position)*1000)>traildistance)
105  {
106  TrailItem * ob=new TrailItem(position,altitude,Qt::green,map);
107  trail->addToGroup(ob);
108  connect(this,SIGNAL(setChildPosition()),ob,SLOT(setPosSLOT()));
109  if(!lasttrailline.IsEmpty())
110  {
111  TrailLineItem * obj=new TrailLineItem(lasttrailline,position,Qt::red,map);
112  trailLine->addToGroup(obj);
113  connect(this,SIGNAL(setChildLine()),obj,SLOT(setLineSlot()));
114  }
115  lasttrailline=position;
116  lastcoord=position;
117  }
118  }
119  coord=position;
120  this->altitude=altitude;
121  RefreshPos();
122  }
123  }
124 
129  void GPSItem::SetUAVHeading(const qreal &value)
130  {
131  if(mapfollowtype==UAVMapFollowType::CenterAndRotateMap)
132  {
133  mapwidget->SetRotate(-value);
134  }
135  else {
136  if (this->rotation() != value)
137  this->setRotation(value);
138  }
139  }
140 
141 
142  int GPSItem::type()const
143  {
144  return Type;
145  }
146 
147 
149  {
150  localposition=map->FromLatLngToLocal(coord);
151  this->setPos(localposition.X(),localposition.Y());
152  emit setChildPosition();
153  emit setChildLine();
154 
155  }
156 
157  void GPSItem::setOpacitySlot(qreal opacity)
158  {
159  setOpacity(opacity);
160  }
161  void GPSItem::SetTrailType(const UAVTrailType::Types &value)
162  {
163  trailtype=value;
164  if(trailtype==UAVTrailType::ByTimeElapsed)
165  timer.restart();
166  }
167  void GPSItem::SetShowTrail(const bool &value)
168  {
169  showtrail=value;
170  trail->setVisible(value);
171 
172  }
173  void GPSItem::SetShowTrailLine(const bool &value)
174  {
175  showtrailline=value;
176  trailLine->setVisible(value);
177  }
178  void GPSItem::DeleteTrail()const
179  {
180  foreach(QGraphicsItem* i,trail->childItems())
181  delete i;
182  foreach(QGraphicsItem* i,trailLine->childItems())
183  delete i;
184  }
185  double GPSItem::Distance3D(const internals::PointLatLng &coord, const int &altitude)
186  {
187  return sqrt(pow(internals::PureProjection::DistanceBetweenLatLng(this->coord, coord), 2) +
188  pow(this->altitude - altitude, 2));
189 
190  }
191  void GPSItem::SetUavPic(QString UAVPic)
192  {
193  pic.load(":/uavs/images/"+UAVPic);
194  }
195 }
A graphicsItem representing a WayPoint.
qint64 X() const
Definition: point.h:51
A graphicsItem representing a WayPoint.
The Map Widget, this is the part exposed to the user.
internals::PointLatLng coord
Definition: mappointitem.h:109
for i
Definition: OPPlots.m:140
void setOpacitySlot(qreal opacity)
Definition: gpsitem.cpp:157
void SetRotate(qreal const &value)
static double DistanceBetweenLatLng(PointLatLng const &p1, PointLatLng const &p2)
PureProjection::DistanceBetweenLatLng Returns 2D distance between two geodetic points.
qint64 Y() const
Definition: point.h:52