37 double UAVItem::groundspeed_mps_filt = 0;
39 UAVItem::UAVItem(MapGraphicItem *map, TLMapWidget *parent, QString uavPic) :
52 this->setFlag(QGraphicsItem::ItemIsMovable,
false);
53 this->setFlag(QGraphicsItem::ItemIsSelectable,
false);
54 localposition=map->FromLatLngToLocal(mapwidget->CurrentPosition());
55 this->setPos(localposition.X(),localposition.Y());
57 trail=
new QGraphicsItemGroup(
this);
58 trail->setParentItem(map);
59 trailLine=
new QGraphicsItemGroup(
this);
60 trailLine->setParentItem(map);
61 this->setFlag(QGraphicsItem::ItemIgnoresTransformations,
true);
62 setCacheMode(QGraphicsItem::ItemCoordinateCache);
63 mapfollowtype=UAVMapFollowType::None;
64 trailtype=UAVTrailType::ByDistance;
67 double pixels2meters = map->Projection()->GetGroundResolution(map->ZoomTotal(),coord.Lat());
68 meters2pixels=1.0 / pixels2meters;
69 setCacheMode(QGraphicsItem::DeviceCoordinateCache);
70 connect(map,SIGNAL(childRefreshPosition()),
this,SLOT(RefreshPos()));
71 connect(map,SIGNAL(childSetOpacity(qreal)),
this,SLOT(setOpacitySlot(qreal)));
72 connect(map,SIGNAL(zoomChanged(
double,
double,
double)),
this,SLOT(zoomChangedSlot()));
79 void UAVItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
85 painter->drawPixmap(-pic.width()/2,-pic.height()/2,pic);
95 painter->setRenderHint(QPainter::Antialiasing,
true);
98 QColor myColor(Qt::red);
100 myPen.setColor(myColor);
101 painter->setPen(myPen);
102 painter->drawPolygon(arrowHead);
103 painter->setPen(myPen);
104 painter->drawLine(arrowShaft);
107 myPen.setColor(Qt::magenta);
108 painter->setPen(myPen);
110 if (trendSpanAngle > 0){
111 QRectF rect(0, -trendRadius, trendRadius*2, trendRadius*2);
112 painter->drawArc(rect, 180*16, -trendSpanAngle*16);
115 QRectF rect(-2*trendRadius, -trendRadius, trendRadius*2, trendRadius*2);
116 painter->drawArc(rect, 0*16, -trendSpanAngle*16);
120 if(groundspeed_mps_filt > 0){
123 myPen.setColor(QColor(0, 0, 0, 100));
124 painter->setPen(myPen);
125 painter->drawEllipse(QPointF(0,0),precalcRings,precalcRings);
127 myPen.setColor(QColor(0, 0, 0, 110));
128 painter->setPen(myPen);
129 painter->drawEllipse(QPointF(0,0),precalcRings*2,precalcRings*2);
131 myPen.setColor(QColor(0, 0, 0, 120));
132 painter->setPen(myPen);
133 painter->drawEllipse(QPointF(0,0),precalcRings*4,precalcRings*4);
136 qreal rot=this->rotation();
137 painter->rotate(-1*rot);
140 myPen.setColor(Qt::white);
141 painter->setBrush(Qt::white);
142 painter->setPen(myPen);
143 painter->drawPath(textPath);
146 void UAVItem::updateTextOverlay()
155 QFont borderfont(
"Arial", 14, QFont::Normal,
false );
158 int textAnchorX = 20;
159 int textAnchorY = 20;
161 QString uavoInfoStrLine1, uavoInfoStrLine2;
162 QString uavoInfoStrLine3, uavoInfoStrLine4;
163 QString uavoInfoStrLine5;
165 uavoInfoStrLine2.append(QString(
"Groundspeed: %1 kph").arg(groundspeed_kph, 0,
'f',1));
166 uavoInfoStrLine3.append(QString(
"Lat-Lon: %1, %2").arg(
coord.
Lat(), 0,
'f',7).arg(
coord.
Lng(), 0,
'f',7));
167 uavoInfoStrLine4.append(QString(
"North-East: %1 m, %2 m").arg(NED[0], 0,
'f',1).arg(NED[1], 0,
'f',1));
168 uavoInfoStrLine5.append(QString(
"Altitude: %1 m").arg(-NED[2], 0,
'f',1));
169 temp.addText(textAnchorX, textAnchorY+16*0, borderfont, uavoInfoStrLine1);
170 temp.addText(textAnchorX, textAnchorY+16*1, borderfont, uavoInfoStrLine2);
171 temp.addText(textAnchorX, textAnchorY+16*2, borderfont, uavoInfoStrLine3);
172 temp.addText(textAnchorX, textAnchorY+16*3, borderfont, uavoInfoStrLine4);
173 temp.addText(textAnchorX, textAnchorY+16*4, borderfont, uavoInfoStrLine5);
176 if(groundspeed_mps > 0){
178 temp.addText(-(groundspeed_mps_filt*ringTime*1*meters2pixels+10), 0, borderfont, QString(
"%1 s").arg(ringTime,0,
'f',0));
179 temp.addText(-(groundspeed_mps_filt*ringTime*2*meters2pixels+10), 0, borderfont, QString(
"%1 s").arg(ringTime*2,0,
'f',0));
180 temp.addText(-(groundspeed_mps_filt*ringTime*4*meters2pixels+10), 0, borderfont, QString(
"%1 s").arg(ringTime*4,0,
'f',0));
182 if(groundspeed_mps_filt*ringTime*4*meters2pixels > 200){
183 if(groundspeed_mps_filt*ringTime*2*meters2pixels > 200){
184 if(groundspeed_mps_filt*ringTime*1*meters2pixels > 200){
185 temp.addText(groundspeed_mps_filt*ringTime*1*meters2pixels-8, 0, borderfont, QString(
"%1 s").arg(ringTime,0,
'f',0));
187 temp.addText(groundspeed_mps_filt*ringTime*2*meters2pixels-8, 0, borderfont, QString(
"%1 s").arg(ringTime*2,0,
'f',0));
189 temp.addText(groundspeed_mps_filt*ringTime*4*meters2pixels-8, 0, borderfont, QString(
"%1 s").arg(ringTime*4,0,
'f',0));
195 QRectF UAVItem::boundingRect()
const
198 if (boundingRectSize < 220){
200 return QRectF(-boundingRectSize,-80,boundingRectSize+220,180);
203 return QRectF(-boundingRectSize,-boundingRectSize,2*boundingRectSize,2*boundingRectSize);
207 return QRectF(-pic.width()/2,-pic.height()/2,pic.width(),pic.height());
211 void UAVItem::SetNED(
double NED[3]){
212 this->NED[0] = NED[0];
213 this->NED[1] = NED[1];
214 this->NED[2] = NED[2];
217 void UAVItem::SetYawRate(
double yawRate_dps){
218 this->yawRate_dps=yawRate_dps;
220 if (fabs(this->yawRate_dps) < 5
e-1){
221 this->yawRate_dps=5
e-1;
225 trendSpanAngle = this->yawRate_dps * 5;
228 trendRadius=fabs(groundspeed_mps/(this->yawRate_dps*M_PI/180))*meters2pixels;
231 void UAVItem::SetCAS(
double CAS_mps){
232 this->CAS_mps=CAS_mps;
235 void UAVItem::SetGroundspeed(
double vNED[3],
int m_maxUpdateRate_ms){
236 this->vNED[0] = vNED[0];
237 this->vNED[1] = vNED[1];
238 this->vNED[2] = vNED[2];
239 groundspeed_kph=sqrt(vNED[0]*vNED[0] + vNED[1]*vNED[1] + vNED[2]*vNED[2])*3.6;
240 groundspeed_mps=groundspeed_kph/3.6;
242 static bool firstGroundspeed=
true;
243 if (firstGroundspeed){
244 groundspeed_mps_filt=groundspeed_kph/3.6;
245 firstGroundspeed=
false;
248 int riseTime_ms=1000;
249 double alpha= m_maxUpdateRate_ms/(double)(m_maxUpdateRate_ms+riseTime_ms);
250 groundspeed_mps_filt= alpha*groundspeed_mps_filt + (1-alpha)*(groundspeed_kph/3.6);
252 ringTime=10*pow(2,17-map->ZoomTotal());
253 precalcRings=groundspeed_mps_filt*ringTime*meters2pixels;
254 boundingRectSize=groundspeed_mps_filt*ringTime*4*meters2pixels+20;
255 prepareGeometryChange();
266 if(trailtype==UAVTrailType::ByTimeElapsed)
268 if(timer.elapsed()>trailtime*1000)
270 TrailItem * ob=
new TrailItem(position,altitude,Qt::green,map);
271 trail->addToGroup(ob);
275 TrailLineItem * obj=
new TrailLineItem(lasttrailline,position,Qt::red,map);
276 trailLine->addToGroup(obj);
277 connect(
this,SIGNAL(
setChildLine()),obj,SLOT(setLineSlot()));
279 lasttrailline=position;
284 else if(trailtype==UAVTrailType::ByDistance)
288 TrailItem * ob=
new TrailItem(position,altitude,Qt::green,map);
289 trail->addToGroup(ob);
293 TrailLineItem * obj=
new TrailLineItem(lasttrailline,position,Qt::red,map);
294 trailLine->addToGroup(obj);
295 connect(
this,SIGNAL(
setChildLine()),obj,SLOT(setLineSlot()));
297 lasttrailline=position;
304 if(mapfollowtype==UAVMapFollowType::CenterAndRotateMap||mapfollowtype==UAVMapFollowType::CenterMap)
310 foreach(QGraphicsItem*
i,map->childItems())
312 WayPointItem* wp=qgraphicsitem_cast<WayPointItem*>(
i);
317 wp->SetReached(
true);
323 if(mapwidget->
Home!=
nullptr)
328 if(mapwidget->
Home->safe!=
false)
330 mapwidget->
Home->safe=
false;
331 mapwidget->
Home->update();
337 if(mapwidget->
Home->safe!=
true)
339 mapwidget->
Home->safe=
true;
340 mapwidget->
Home->update();
352 void UAVItem::SetUAVHeading(
const qreal &value)
354 if(mapfollowtype==UAVMapFollowType::CenterAndRotateMap)
359 if (this->rotation() != value)
360 this->setRotation(value);
365 int UAVItem::type()
const
373 localposition=map->FromLatLngToLocal(
coord);
374 this->setPos(localposition.
X(),localposition.
Y());
382 this->setOpacity(opacity);
387 double pixels2meters = map->Projection()->GetGroundResolution(map->ZoomTotal(),
coord.
Lat());
388 meters2pixels=1.0 / pixels2meters;
389 boundingRectSize=groundspeed_mps_filt*ringTime*4*meters2pixels+20;
390 prepareGeometryChange();
394 void UAVItem::SetTrailType(
const UAVTrailType::Types &value)
397 if(trailtype==UAVTrailType::ByTimeElapsed)
400 void UAVItem::SetShowTrail(
const bool &value)
403 trail->setVisible(value);
405 void UAVItem::SetShowTrailLine(
const bool &value)
408 trailLine->setVisible(value);
411 void UAVItem::DeleteTrail()
const
413 foreach(QGraphicsItem* i,trail->childItems())
415 foreach(QGraphicsItem* i,trailLine->childItems())
419 void UAVItem::SetUavPic(QString UAVPic)
421 pic.load(
":/uavs/images/"+UAVPic);
424 void UAVItem::SetShowUAVInfo(
bool const& value)
427 showJustChanged=
true;
431 void UAVItem::generateArrowhead(){
432 qreal arrowSize = 10;
435 arrowShaft=QLineF(0,0,1.0,1.0);
438 arrowShaft.setP1(QPointF(0,0));
441 arrowShaft.setLength(60.0);
442 arrowShaft.setAngle(90.0);
445 double angle = ::acos(arrowShaft.dx() / arrowShaft.length());
446 if (arrowShaft.dy() <= 0)
447 angle = (M_PI * 2) - angle;
449 QPointF arrowP1 = arrowShaft.pointAt(1) + QPointF(sin(angle + M_PI / 3) * arrowSize,
450 cos(angle + M_PI / 3) * arrowSize);
451 QPointF arrowP2 = arrowShaft.pointAt(1) + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize,
452 cos(angle + M_PI - M_PI / 3) * arrowSize);
456 arrowHead << arrowShaft.pointAt(1) << arrowP1 << arrowP2;
A graphicsItem representing a WayPoint.
axis equal end function NED
A graphicsItem representing a WayPoint.