1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 16:08:39 -05:00

DOA2: Compass widget updates

This commit is contained in:
f4exb 2022-05-27 14:02:52 +02:00
parent 5557c5b67c
commit 4e373478e7
3 changed files with 150 additions and 137 deletions

View File

@ -30,6 +30,7 @@ DOA2Compass::DOA2Compass(QWidget *parent)
m_sizeMax = 600;
m_offset = 2;
m_size = m_sizeMin - 2*m_offset;
m_drawLegend = false;
setMinimumSize(m_sizeMin, m_sizeMin);
setMaximumSize(m_sizeMax, m_sizeMax);
@ -37,17 +38,15 @@ DOA2Compass::DOA2Compass(QWidget *parent)
setFocusPolicy(Qt::NoFocus);
m_yaw = 0.0;
m_alt = 0.0;
m_h = 0.0;
m_azPos = 0.0;
m_azNeg = 0.0;
m_azAnt = 0.0;
}
DOA2Compass::~DOA2Compass()
{
}
void DOA2Compass::canvasReplot_slot(void)
{
update();
@ -56,13 +55,14 @@ void DOA2Compass::canvasReplot_slot(void)
void DOA2Compass::resizeEvent(QResizeEvent *event)
{
m_size = qMin(width(),height()) - 2*m_offset;
QWidget::resizeEvent(event);
}
void DOA2Compass::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QBrush bgGround(QColor(48,172,220));
QBrush bgGround(palette().button().color());
QPen whitePen(Qt::white);
QPen blackPen(Qt::black);
@ -77,15 +77,12 @@ void DOA2Compass::paintEvent(QPaintEvent *)
greenPen.setWidth(2);
painter.setRenderHint(QPainter::Antialiasing);
painter.translate(width() / 2, height() / 2);
// draw background
{
painter.setPen(blackPen);
painter.setPen(whitePen);
painter.setBrush(bgGround);
painter.drawEllipse(-m_size/2, -m_size/2, m_size, m_size);
}
@ -100,60 +97,47 @@ void DOA2Compass::paintEvent(QPaintEvent *)
QString s;
blackPen.setWidth(1);
painter.setPen(blackPen);
painter.setPen(whitePen);
painter.setFont(font());
for(int i=0; i<nyawLines; i++) {
if( i == 0 ) {
s = "N";
painter.setPen(bluePen);
painter.setFont(QFont("", fontSize*1.3));
} else if ( i == 9 ) {
s = "W";
painter.setPen(blackPen);
painter.setFont(QFont("", fontSize*1.3));
s = "E";
} else if ( i == 18 ) {
s = "S";
painter.setPen(redPen);
painter.setFont(QFont("", fontSize*1.3));
} else if ( i == 27 ) {
s = "E";
painter.setPen(blackPen);
painter.setFont(QFont("", fontSize*1.3));
s = "W";
} else {
s = QString("%1").arg(i*rotAng);
painter.setPen(blackPen);
painter.setFont(QFont("", fontSize));
}
fx1 = 0;
fy1 = -m_size/2 + m_offset;
fx2 = 0;
if( i % 3 == 0 ) {
if (i % 3 == 0)
{
fy2 = fy1 + yawLineLeng;
painter.drawLine(QPointF(fx1, fy1), QPointF(fx2, fy2));
fy2 = fy1 + yawLineLeng+4;
painter.drawText(QRectF(-50, fy2, 100, fontSize+2),
Qt::AlignCenter, s);
} else {
painter.drawText(QRectF(-50, fy2, 100, fontSize+2), Qt::AlignCenter, s);
}
else
{
fy2 = fy1 + yawLineLeng/2;
painter.drawLine(QPointF(fx1, fy1), QPointF(fx2, fy2));
}
painter.rotate(-rotAng);
painter.rotate(rotAng);
}
}
// draw S/N arrow
// draw antennas arrow
{
int arrowWidth = m_size/5;
int arrowWidth = m_size/20;
double fx1, fy1, fx2, fy2, fx3, fy3;
fx1 = 0;
@ -163,9 +147,10 @@ void DOA2Compass::paintEvent(QPaintEvent *)
fx3 = arrowWidth/2;
fy3 = 0;
painter.setPen(Qt::NoPen);
painter.rotate(m_azAnt);
painter.setBrush(QBrush(Qt::blue));
painter.setPen(Qt::NoPen);
painter.setBrush(QBrush(Qt::white));
QPointF pointsN[3] = {
QPointF(fx1, fy1),
QPointF(fx2, fy2),
@ -173,7 +158,6 @@ void DOA2Compass::paintEvent(QPaintEvent *)
};
painter.drawPolygon(pointsN, 3);
fx1 = 0;
fy1 = m_size/2 - m_offset - m_size/25 - 15;
fx2 = -arrowWidth/2;
@ -181,31 +165,34 @@ void DOA2Compass::paintEvent(QPaintEvent *)
fx3 = arrowWidth/2;
fy3 = 0;
painter.setBrush(QBrush(Qt::red));
painter.setBrush(QBrush(palette().button().color().lighter(150)));
QPointF pointsS[3] = {
QPointF(fx1, fy1),
QPointF(fx2, fy2),
QPointF(fx3, fy3)
};
painter.drawPolygon(pointsS, 3);
painter.rotate(-m_azAnt);
}
// draw yaw marker
// draw azPos marker
{
int yawMarkerSize = m_size/12;
double fx1, fy1, fx2, fy2, fx3, fy3;
painter.rotate(-m_yaw);
painter.setBrush(QBrush(QColor(0xFF, 0x00, 0x00, 0xE0)));
int azMarkerSize = m_size/15;
double fx1, fy1, fx2, fy2, fx3, fy3, fyl;
fx1 = 0;
fy1 = -m_size/2 + m_offset;
fx2 = fx1 - yawMarkerSize/2;
fy2 = fy1 + yawMarkerSize;
fx3 = fx1 + yawMarkerSize/2;
fy3 = fy1 + yawMarkerSize;
fx2 = fx1 - azMarkerSize/2;
fy2 = fy1 + azMarkerSize;
fx3 = fx1 + azMarkerSize/2;
fy3 = fy1 + azMarkerSize;
fyl = -m_size/2; // -m_size/2 + m_offset + m_size/25 + 15;
painter.rotate(m_azPos);
painter.setPen(Qt::NoPen);
painter.setBrush(QBrush(QColor(0xFF, 0x60, 0x60, 0xA0)));
QPointF points[3] = {
QPointF(fx1, fy1),
QPointF(fx2, fy2),
@ -213,65 +200,63 @@ void DOA2Compass::paintEvent(QPaintEvent *)
};
painter.drawPolygon(points, 3);
painter.rotate(m_yaw);
painter.setPen(QColor(0xFF, 0x60, 0x60, 0xE0));
painter.drawLine(0, 0, 0, fyl);
painter.rotate(-m_azPos);
}
// draw altitude
// draw azNeg marker
{
int altFontSize = 13;
int fx, fy, w, h;
QString s;
char buf[200];
int yawMarkerSize = m_size/15;
double fx1, fy1, fx2, fy2, fx3, fy3, fyl;
w = 130;
h = 2*(altFontSize + 8);
fx1 = 0;
fy1 = -m_size/2 + m_offset;
fx2 = fx1 - yawMarkerSize/2;
fy2 = fy1 + yawMarkerSize;
fx3 = fx1 + yawMarkerSize/2;
fy3 = fy1 + yawMarkerSize;
fyl = -m_size/2;
painter.rotate(m_azNeg);
painter.setPen(Qt::NoPen);
painter.setBrush(QBrush(QColor(0x80, 0x80, 0xFF, 0xA0)));
QPointF points[3] = {
QPointF(fx1, fy1),
QPointF(fx2, fy2),
QPointF(fx3, fy3)
};
painter.drawPolygon(points, 3);
painter.setPen(QColor(0x80, 0x80, 0xFF, 0xE0));
painter.drawLine(0, 0, 0, fyl);
painter.rotate(-m_azNeg);
}
// draw legend
if (m_drawLegend)
{
int altFontSize = 8;
int fx, fy, w, h;
w = 10*altFontSize;
h = 3*(altFontSize + 8);
fx = -w/2;
fy = -h/2;
blackPen.setWidth(2);
painter.setPen(blackPen);
painter.setBrush(QBrush(Qt::white));
painter.setFont(QFont("", altFontSize));
painter.setPen(whitePen);
painter.setBrush(QBrush(Qt::black));
QFont f = font();
f.setPointSize(altFontSize);
painter.setFont(f);
painter.drawRoundedRect(fx, fy, w, h, 6, 6);
painter.setPen(bluePen);
sprintf(buf, "ALT: %6.1f m", m_alt);
s = buf;
painter.drawText(QRectF(fx, fy+2, w, h/2), Qt::AlignCenter, s);
sprintf(buf, "H: %6.1f m", m_h);
s = buf;
painter.drawText(QRectF(fx, fy+h/2, w, h/2), Qt::AlignCenter, s);
painter.drawText(QRectF(fx, fy+2, w, h/3), Qt::AlignCenter, QString("POS: %1%2").arg((int) m_azPos, 3, 10, QLatin1Char('0')).arg(QChar(0260)));
painter.drawText(QRectF(fx, fy+h/3, w, h/3), Qt::AlignCenter, QString("ANT: %1%2").arg((int) m_azAnt, 3, 10, QLatin1Char('0')).arg(QChar(0260)));
painter.drawText(QRectF(fx, fy+2*(h/3), w, h/3), Qt::AlignCenter, QString("NEG: %1%2").arg((int) m_azNeg, 3, 10, QLatin1Char('0')).arg(QChar(0260)));
}
}
void DOA2Compass::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {
case Qt::Key_Left:
m_yaw -= 1.0;
break;
case Qt::Key_Right:
m_yaw += 1.0;
break;
case Qt::Key_Down:
m_alt -= 1.0;
break;
case Qt::Key_Up:
m_alt += 1.0;
break;
case Qt::Key_W:
m_h += 1.0;
break;
case Qt::Key_S:
m_h -= 1.0;
break;
default:
QWidget::keyPressEvent(event);
break;
}
update();
}

View File

@ -31,70 +31,93 @@ public:
///
/// \brief Set all data (yaw, alt, height)
///
/// \param y - yaw ( in degree)
/// \param a - altitude ( in m)
/// \param h - height from ground (in m)
/// \param azPos - forward (positive angles side relative to antennas direction) azimuth (in degrees)
/// \param azNeg - reverse (negatve angles side relative to antennas direction) azimuth (in degrees)
/// \param azAnt - antennas azimuth from 1 (connected to stream 0) to 2 (connected to stream 1)
///
void setData(double y, double a, double h) {
m_yaw = y;
m_alt = a;
m_h = h;
void setData(double azPos, double azNeg, double azAnt) {
m_azPos = azPos;
m_azNeg = azNeg;
m_azAnt = azAnt;
if( m_yaw < 0 ) m_yaw = 360 + m_yaw;
if( m_yaw > 360 ) m_yaw = m_yaw - 360;
if( m_azPos < 0 ) m_azPos = 360 + m_azPos;
if( m_azPos > 360 ) m_azPos = m_azPos - 360;
if( m_azNeg < 0 ) m_azNeg = 360 + m_azNeg;
if( m_azNeg > 360 ) m_azNeg = m_azNeg - 360;
if( azAnt < 0 ) azAnt = 360 + azAnt;
if( azAnt > 360 ) azAnt = azAnt - 360;
emit canvasReplot();
}
///
/// \brief Set yaw angle (in degree)
/// \param val - yaw angle (in degree)
/// \brief Set forward azimoth (in degree)
/// \param val - forward azimoth (in degree)
///
void setYaw(double val) {
m_yaw = val;
if( m_yaw < 0 ) m_yaw = 360 + m_yaw;
if( m_yaw > 360 ) m_yaw = m_yaw - 360;
void setAzPos(double val)
{
m_azPos = val;
if( m_azPos < 0 ) m_azPos = 360 + m_azPos;
if( m_azPos > 360 ) m_azPos = m_azPos - 360;
emit canvasReplot();
}
///
/// \brief Set altitude value
/// \param val - altitude (in m)
/// \brief Set reverse azimoth (in degree)
/// \param val - reverse azimoth (in degree)
///
void setAlt(double val) {
m_alt = val;
void setAzNeg(double val)
{
m_azNeg = val;
if( m_azNeg < 0 ) m_azNeg = 360 + m_azNeg;
if( m_azNeg > 360 ) m_azNeg = m_azNeg - 360;
emit canvasReplot();
}
///
/// \brief Set height from ground
/// \param val - height (in m)
/// \brief Set antennas azimoth (in degree)
/// \param val - antennas azimoth (in degree)
///
void setH(double val) {
m_h = val;
void setAzAnt(double val)
{
m_azAnt = val;
if( m_azAnt < 0 ) m_azAnt = 360 + m_azAnt;
if( m_azAnt > 360 ) m_azAnt = m_azAnt - 360;
emit canvasReplot();
}
///
/// \brief Get yaw angle
/// \return yaw angle (in degree)
/// \brief Draw legend in the center of the compass
/// \param drawLegend - true to draw legend else false
///
double getYaw() {return m_yaw;}
void drawLegend(bool drawLegend)
{
m_drawLegend = drawLegend;
emit canvasReplot();
}
///
/// \brief Get altitude value
/// \return altitude (in m)
/// \brief Get forward azimuth
/// \return forward azimuth (in degree)
///
double getAlt() {return m_alt;}
double getAzPos() const {return m_azPos; }
///
/// \brief Get height from ground
/// \return height from ground (in m)
/// \brief Get reverse azimuth
/// \return reverse azimuth (in degree)
///
double getH() {return m_h;}
double getAzNeg() const {return m_azNeg; }
///
/// \brief Get antennas azimuth
/// \return antennas azimuth (in degree)
///
double getAzAnt() const {return m_azAnt; }
signals:
void canvasReplot(void);
@ -105,15 +128,15 @@ protected slots:
protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
void keyPressEvent(QKeyEvent *event);
protected:
int m_sizeMin, m_sizeMax; ///< widget min/max size (in pixel)
int m_size, m_offset; ///< widget size and offset size
bool m_drawLegend; ///< draw legend in the center
double m_yaw; ///< yaw angle (in degree)
double m_alt; ///< altitude (in m)
double m_h; ///< height from ground (in m)
double m_azPos; ///< forward (+) azimuth (in degree)
double m_azNeg; ///< reverse (-) azimuth (in degree)
double m_azAnt; ///< antennas azimuth from 1 (connected to stream 0) to 2 (connected to stream 1)
};
#endif // INCLUDE_DOA2COMPASS_H

View File

@ -151,6 +151,11 @@ DOA2GUI::DOA2GUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, MIMOChannel *ch
makeUIConnections();
displayRateAndShift();
applySettings(true);
// Test
ui->compass->setAzNeg(85);
ui->compass->setAzPos(315);
ui->compass->setAzAnt(20);
}
DOA2GUI::~DOA2GUI()