00001
00002
00003
00004
00005
00006
00007 #include "tcasdisplay.h"
00008 #include <QPolygon>
00009 #include <math.h>
00010
00011 tcasDisplay::tcasDisplay( QWidget *parent)
00012 : QWidget( parent )
00013 {
00014 threatIndex = 0;
00015 setPalette( QPalette( QColor( 0, 0,0) ) );
00016 this->setAutoFillBackground(true);
00017 }
00018
00019 void tcasDisplay::paintEvent( QPaintEvent * )
00020 {
00021
00022 QPainter p( this );
00023
00024 std::list<threatListItem>::iterator threatIter;
00025 for (threatIter=tList.begin(); threatIter != tList.end(); threatIter++)
00026 {
00027 paintThreat( &p, threatIter );
00028 }
00029
00030 drawAircraftSymbol(&p);
00031 }
00032
00033
00034 QSizePolicy tcasDisplay::sizePolicy() const
00035 {
00036 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
00037 }
00038
00039 void tcasDisplay::paintThreat(QPainter *p, std::list<threatListItem>::iterator item)
00040 {
00041 QPolygon a;
00042
00043 p->setBrush(Qt::NoBrush);
00044 p->setPen(Qt::darkBlue);
00045 int hwidth = this->width()/2;
00046 int hheight = this->height()/2;
00047 int mradius = (int)( sqrt( pow( hwidth-item->xPos,2) + pow( hheight-item->yPos,2) ) );
00048 QRectF rectangle(hwidth - mradius+7, hheight - mradius+7, mradius*2-7, mradius*2-7);
00049 p->drawEllipse(rectangle);
00050
00051
00052 switch(item->type)
00053 {
00054 case threatOther:
00055 a.putPoints(0,4, item->xPos+8,item->yPos, item->xPos+16,item->yPos+8, item->xPos+8,item->yPos+16, item->xPos,item->yPos+8);
00056 p->setBrush(Qt::cyan);
00057 p->setPen(Qt::cyan);
00058 p->drawPolygon(a);
00059 p->translate( item->xPos, item->yPos );
00060 break;
00061 case threatProximate:
00062 a.putPoints(0,4, item->xPos+8,item->yPos, item->xPos+16,item->yPos+8, item->xPos+8,item->yPos+16, item->xPos,item->yPos+8);
00063 p->setBrush(Qt::NoBrush);
00064 p->setPen(QPen(Qt::cyan,2));
00065 p->drawPolygon(a);
00066 p->translate( item->xPos, item->yPos );
00067 break;
00068 case threatIntruding:
00069 p->setBrush(Qt::yellow);
00070 p->setPen(Qt::NoPen);
00071 p->translate( item->xPos, item->yPos );
00072 p->drawPie(0,0,16,16,0,5760);
00073 break;
00074 case threatReal :
00075 p->setBrush(Qt::red);
00076 p->setPen(Qt::NoPen);
00077 p->translate( item->xPos, item->yPos );
00078 p->drawRect( QRect(0, 0, 16, 16) );
00079 break;
00080
00081 }
00082
00083 drawArrow(p,25,0,item->dir, item->type);
00084 QString s = QString::number( item->relAlt );
00085 p->drawText( -5, 30, s );
00086
00087 p->translate(-item->xPos, -item->yPos);
00088
00089 }
00090
00091 void tcasDisplay::drawArrow(QPainter *p, int x, int y, trendDir dir, threatType type)
00092 {
00093 QPen arrowPen;
00094 arrowPen.setWidth(2);
00095 switch(type)
00096 {
00097 case threatOther:
00098 arrowPen.setColor(Qt::cyan);
00099 break;
00100 case threatProximate:
00101 arrowPen.setColor(Qt::cyan);
00102 break;
00103 case threatIntruding:
00104 arrowPen.setColor(Qt::yellow);
00105 break;
00106 case threatReal:
00107 arrowPen.setColor(Qt::red);
00108 break;
00109 default:
00110 arrowPen.setColor(Qt::white);
00111 break;
00112 }
00113 p->setPen( arrowPen );
00114 p->setBrush( Qt::NoBrush );
00115
00116 switch(dir)
00117 {
00118 case ascending:
00119 p->drawLine(x,y,x,y+14);
00120 p->drawLine(x,y,x-5,y+5);
00121 p->drawLine(x,y,x+5,y+5);
00122 break;
00123 case descending:
00124 p->drawLine(x,y,x,y+14);
00125 p->drawLine(x,y+14,x-5,y+9);
00126 p->drawLine(x,y+14,x+5,y+9);
00127 break;
00128 case none:
00129 break;
00130 default:
00131 break;
00132
00133 }
00134 }
00135
00136 void tcasDisplay::addThreat(threatType type, trendDir dir, int relAlt, int x, int y, unsigned long &key)
00137 {
00138 if (dir != none)
00139 {
00140 threatIndex++;
00141
00142 if (x == 0 && y == 0)
00143 {x = 275; y = 80;}
00144 threatListItem *ti = new threatListItem(type, dir, relAlt, threatIndex, x, y);
00145 tList.push_back(*ti);
00146 key = threatIndex;
00147 this->repaint();
00148 }
00149 else
00150 key=-1;
00151 }
00152
00153 void tcasDisplay::removeThreat(int idx)
00154 {
00155
00156 std::list<threatListItem>::iterator threatIter;
00157 for (threatIter=tList.begin(); threatIter != tList.end(); threatIter++)
00158 {
00159 if(threatIter->id == idx)
00160 tList.erase(threatIter);
00161 }
00162 this->repaint();
00163
00164 }
00165 void tcasDisplay::drawAircraftSymbol(QPainter *p)
00166 {
00167 int mwidth = this->width();
00168 int mheight = this->height();
00169 p->setPen( QPen(Qt::white,3) );
00170 p->translate(0,0);
00171
00172 p->drawLine(mwidth/2, mheight/2 + 15, mwidth/2, mheight/2 - 15);
00173
00174 p->drawLine(mwidth/2 - 3, mheight/2 + 10, mwidth/2 + 3, mheight/2 + 10);
00175
00176 p->drawLine(mwidth/2 - 10, mheight/2 - 5, mwidth/2 + 10, mheight/2 - 5);
00177 }
00178
00179