MRU1/airobj.cpp
2025-07-02 08:18:27 +03:00

225 lines
3.4 KiB
C++

#include "airobj.h"
airObj::airObj()
{
exist=false;
x=y=0;
h=100;
vx=vy = 10;
v0 = 14;
numer = uid = -1;
alt=0;
aType = gType = -1;
pic = QImage();
col = Qt::white;
lastTime = QTime();
for (int i=0; i<6;i++) CU[i]=0;
priznakAction = 0;
}
void airObj::deleteTarget()
{
prepareGeometryChange();
exist=false;
x=y=0;
h=100;
vx=vy = 10;
v0 = 14;
numer = uid = -1;
alt=0;
aType = gType = -1;
pic = QImage();
col = Qt::white;
lastTime = QTime();
for (int i=0; i<6;i++) CU[i]=0;
priznakAction = 0;
}
qreal airObj::kurs()
{
if ((vx==0)&&(vy==0)) return 0;
QLineF lf= QLineF(0,0,vx,vy);
return lf.angle();
}
bool airObj::haveCU()
{
int ret=0;
for (int i=0; i<6; i++) ret+=CU[i];
return (ret>0);
}
QRectF airObj::boundingRect() const
{
qreal d=100;
return QRectF(x-d, y-d, 2*d, 2*d);
}
void airObj::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QPen pen;
if (exist)
{
pen=p->pen();
pen.setWidth(3);
pen.setColor(col);
p->setPen(pen);
p->drawPoint(x, y);
pen.setWidth(2);
p->setPen(pen);
QLineF lf(x, y, x+2*vx, y+2*vy);
if (QPointF(vx, vy).manhattanLength()<10)
{
lf.setLength(10);
}
p->drawLine(lf);
}
}
void airObj::setExist(bool fl)
{
if (fl!=exist)
{
prepareGeometryChange();
exist = fl;
}
}
void airObj::setPic()
{
int d;
QString s;
if ((aType>0)&&(aType<16))
{
d=aType;
}
else
{
d=0;
}
s = ":/new/pics/type_En";
s.append(QString("%1").arg(d));
s.append(".xpm");
pic = QImage(s);
pic.setColor(0, col.rgb());
}
void airObj::setGType(int g)
{
if (g!=gType)
{
gType =g;
setColAsG();
}
}
void airObj::setPriznak(int pr)
{
if (pr!=priznakAction)
{
prepareGeometryChange();
priznakAction = pr;
switch (pr)
{
case 1:
priznakColor = Qt::green;
break;
case 2:
priznakColor = Qt::yellow;
break;
case 3:
priznakColor = Qt::red;
break;
default:
priznakColor = Qt::black;
break;
}
}
}
void airObj::setAType(int a)
{
if (a!=aType)
{
prepareGeometryChange();
aType = a;
setPic();
}
}
void airObj::setColAsG()
{
prepareGeometryChange();
switch (gType)
{
case 3:
col=QColor(Qt::magenta);
break;
case 2:
col=QColor(Qt::red);
break;
case 1:
col=QColor(Qt::green);
break;
default:
col=QColor(Qt::yellow);
}
setPic();
}
void airObj::setCoord(qreal cx, qreal cy, qreal ch)
{
x = cx; y= cy; h = ch;
prepareGeometryChange();
// oldLX = lX;
// oldLY = lY;
// lX=cy;
// lY=-cx;
if (h>120) alt = 3;
else if ((h>40)&&(h<=120)) alt=2;
else if ((h>10)&&(h<=40)) alt=1;
else alt = 0;
QString s = ":/new/pics/alt";
s.append(QString("%1").arg(alt));
if ((alt==0)&&(h<=2)) s.append("0");
s.append(".xpm");
picAlt = QImage(s);
picAlt.setColor(0, col.rgb());
}
void airObj::setCoord(qreal cx, qreal cy)
{
setCoord(cx, cy, h);
}
void airObj::setSpeed(qreal vx1, qreal vy1)
{
vx = vx1;
vy = vy1;
v0=sqrt(vx*vx+vy*vy);
}