300 lines
6.0 KiB
C++
300 lines
6.0 KiB
C++
#include "groundobj.h"
|
|
|
|
groundObj::groundObj( )
|
|
|
|
{
|
|
x=y=type=0;
|
|
exist=true;
|
|
boegotov = false;
|
|
type = 0;
|
|
n_Ab = 0;
|
|
pic = QImage(":/new/pics/ground0.xpm");
|
|
|
|
priznakSektor = false;
|
|
angle1 = 0;
|
|
angle2 = 0;
|
|
alt_n = 0;
|
|
hMin=0;
|
|
hMax=8479;
|
|
|
|
initRockets(0,0);
|
|
}
|
|
void groundObj::initRockets(int _allR, int _activeR) {
|
|
allR = _allR; activeR = _activeR;
|
|
hasCU.clear();
|
|
for (int i=0; i<activeR; i++) hasCU<<-1;
|
|
}
|
|
|
|
void groundObj::setBoegotov(bool fl)
|
|
{
|
|
if (fl!=boegotov)
|
|
{
|
|
prepareGeometryChange();
|
|
boegotov = fl;
|
|
}
|
|
}
|
|
|
|
void groundObj::setPriznakSektor(bool fl)
|
|
{
|
|
if (fl!=priznakSektor)
|
|
{
|
|
prepareGeometryChange();
|
|
priznakSektor = fl;
|
|
|
|
}
|
|
}
|
|
|
|
void groundObj::setRockets(int r)
|
|
{
|
|
if (r!=allR)
|
|
{
|
|
allR = r;
|
|
|
|
}
|
|
}
|
|
|
|
int groundObj::addCU(int ud)
|
|
{
|
|
if (activeR>0)
|
|
{
|
|
if (hasCU.contains((int)ud))
|
|
{
|
|
return -1;
|
|
}
|
|
else
|
|
{
|
|
int t = 0;
|
|
t= hasCU.indexOf(((int) -1));
|
|
if (t<0)
|
|
{
|
|
qDebug("Error:: hasCU in grObj wrong Index");
|
|
}
|
|
else
|
|
{
|
|
hasCU[t] = ud;
|
|
activeR--;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
else
|
|
{
|
|
int t = hasCU.first();
|
|
|
|
hasCU.removeFirst();
|
|
hasCU.append(ud);
|
|
|
|
return t;
|
|
}
|
|
}
|
|
|
|
void groundObj::removeCU(int ud)
|
|
{
|
|
if (activeR<allR)
|
|
{
|
|
if (hasCU.indexOf(ud)!=-1)
|
|
{
|
|
hasCU.removeOne(ud);
|
|
hasCU.append(-1);
|
|
activeR++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void groundObj::setExist(bool fl)
|
|
{
|
|
if (fl!=exist)
|
|
{
|
|
prepareGeometryChange();
|
|
exist = fl;
|
|
}
|
|
}
|
|
|
|
QRectF groundObj::boundingRect() const
|
|
{
|
|
qreal d = 30;
|
|
return QRectF(-d/2+x,-d/2+y,d,d);
|
|
}
|
|
|
|
void groundObj::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
{
|
|
QPen pen;
|
|
QBrush br;
|
|
QPointF p0, ptemp;
|
|
QLineF lf;
|
|
QFont f;
|
|
QString s, s1;
|
|
|
|
if (exist)
|
|
{
|
|
p0 = QPointF(x,y);
|
|
|
|
p->setPen(Qt::green);
|
|
p->drawEllipse(p0, 0.5, 0.5);
|
|
|
|
|
|
if (type==1 || type == 12) // type == 1 is TOR, type == 12 is Shilks
|
|
{
|
|
if (priznakSektor)
|
|
{
|
|
br = p->brush();
|
|
br.setStyle(Qt::NoBrush);
|
|
p->setBrush(br);
|
|
pen = p->pen();
|
|
pen.setColor(Qt::red);
|
|
pen.setStyle(Qt::DashLine);
|
|
p->setPen(pen);
|
|
|
|
const qreal elRadius = (type==12) ? 25 : 160;
|
|
p->drawEllipse(p0, elRadius, elRadius);
|
|
|
|
pen.setColor(Qt::cyan);
|
|
if (boegotov) pen.setStyle(Qt::SolidLine);
|
|
else pen.setStyle(Qt::DashLine);
|
|
p->setPen(pen);
|
|
|
|
qreal a1 = (90-angle1); if (a1<0) a1+=360;
|
|
qreal a2 = (90-angle2); if (a2<0) a2+=360;
|
|
p->drawPie(QRectF(p0-QPointF(320,320), QSize(640,640)), a2*16, (angle2-angle1)*16);
|
|
|
|
pen.setStyle(Qt::SolidLine);
|
|
pen.setColor(Qt::darkGreen);
|
|
pen.setWidthF(3);
|
|
p->setPen(pen);
|
|
p->drawArc(QRectF(p0-QPointF(280,280), QSize(560,560)), a2*16, (angle2-angle1)*16);
|
|
p->drawArc(QRectF(p0-QPointF(120,120), QSize(240,240)), a2*16, (angle2-angle1)*16);
|
|
|
|
p->setPen(Qt::white);
|
|
f = p->font();
|
|
f.setPointSize(10);
|
|
f.setItalic(true);
|
|
p->setFont(f);
|
|
|
|
ptemp = p0+QPointF(320,0);
|
|
lf = QLineF(p0, ptemp); lf.setAngle(a1);
|
|
|
|
s = QString::number(n_Ab);
|
|
if (alt_n==1) s.append("H");
|
|
if (alt_n==2) s.append("B");
|
|
if (alt_n==3)
|
|
{
|
|
qreal hmi = hMin/1000;
|
|
s.append(" ");
|
|
s.append(QString::number(hmi, 'f', 1 ));
|
|
}
|
|
|
|
|
|
p->drawText(QRectF(lf.p2(), QSizeF(45, 15)), s);
|
|
lf = QLineF(p0, ptemp); lf.setAngle(a2);
|
|
if (alt_n==3)
|
|
{
|
|
s = QString::number(n_Ab);
|
|
s.append(" ");
|
|
qreal hma = hMax/1000;
|
|
s.append(QString::number(hma, 'f', 1 ));
|
|
}
|
|
|
|
p->drawText(QRectF(lf.p2(), QSizeF(45, 15)), s);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
p->setBrush(Qt::NoBrush);
|
|
p->setPen(Qt::NoPen);
|
|
p->drawPoint(0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
void groundObj::setSektor(qreal a1, qreal a2)
|
|
{
|
|
while (a1>a2) { a2+=360; }
|
|
|
|
if ((a1!=angle1)||(a2!=angle2)|| (!priznakSektor))
|
|
{
|
|
prepareGeometryChange();
|
|
priznakSektor = true;
|
|
angle1 = a1;
|
|
angle2 = a2;
|
|
}
|
|
}
|
|
|
|
void groundObj::clearSektor()
|
|
{
|
|
if (priznakSektor || angle1 || angle2)
|
|
{
|
|
prepareGeometryChange();
|
|
priznakSektor = false;
|
|
angle1 = angle2 = 0;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
void groundObj::setType(int t)
|
|
{
|
|
if (type!=t)
|
|
{
|
|
prepareGeometryChange();
|
|
type=t;
|
|
|
|
if (t==0)
|
|
{
|
|
pic = QImage(":/new/pics/ground0.xpm");
|
|
}
|
|
if (t==1)
|
|
{
|
|
pic = QImage(":/new/pics/tor2.xpm");
|
|
initRockets(8, 4);
|
|
}
|
|
if (t==12) {
|
|
pic = QImage(":/new/pics/sh.xpm");
|
|
initRockets(4, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
void groundObj::setPos(QPointF p)
|
|
{
|
|
QPointF lp(x, y);
|
|
if (lp!=p)
|
|
{
|
|
prepareGeometryChange();
|
|
x = p.x();
|
|
y = p.y();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void groundObj::setPos(qreal x, qreal y)
|
|
{
|
|
setPos(QPointF(x, y));
|
|
}
|
|
|
|
void groundObj::mousePressEvent(QGraphicsSceneMouseEvent *e)
|
|
{
|
|
|
|
}
|
|
|
|
void groundObj::setOgrH(int al)
|
|
{
|
|
prepareGeometryChange();
|
|
alt_n = al;
|
|
}
|
|
|
|
void groundObj::setOgrH(int al, qreal min, qreal max)
|
|
{
|
|
|
|
hMin = min;
|
|
hMax = max;
|
|
setOgrH(al);
|
|
}
|