1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-29 19:28:47 -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_sizeMax = 600;
m_offset = 2; m_offset = 2;
m_size = m_sizeMin - 2*m_offset; m_size = m_sizeMin - 2*m_offset;
m_drawLegend = false;
setMinimumSize(m_sizeMin, m_sizeMin); setMinimumSize(m_sizeMin, m_sizeMin);
setMaximumSize(m_sizeMax, m_sizeMax); setMaximumSize(m_sizeMax, m_sizeMax);
@ -37,17 +38,15 @@ DOA2Compass::DOA2Compass(QWidget *parent)
setFocusPolicy(Qt::NoFocus); setFocusPolicy(Qt::NoFocus);
m_yaw = 0.0; m_azPos = 0.0;
m_alt = 0.0; m_azNeg = 0.0;
m_h = 0.0; m_azAnt = 0.0;
} }
DOA2Compass::~DOA2Compass() DOA2Compass::~DOA2Compass()
{ {
} }
void DOA2Compass::canvasReplot_slot(void) void DOA2Compass::canvasReplot_slot(void)
{ {
update(); update();
@ -56,13 +55,14 @@ void DOA2Compass::canvasReplot_slot(void)
void DOA2Compass::resizeEvent(QResizeEvent *event) void DOA2Compass::resizeEvent(QResizeEvent *event)
{ {
m_size = qMin(width(),height()) - 2*m_offset; m_size = qMin(width(),height()) - 2*m_offset;
QWidget::resizeEvent(event);
} }
void DOA2Compass::paintEvent(QPaintEvent *) void DOA2Compass::paintEvent(QPaintEvent *)
{ {
QPainter painter(this); QPainter painter(this);
QBrush bgGround(QColor(48,172,220)); QBrush bgGround(palette().button().color());
QPen whitePen(Qt::white); QPen whitePen(Qt::white);
QPen blackPen(Qt::black); QPen blackPen(Qt::black);
@ -77,15 +77,12 @@ void DOA2Compass::paintEvent(QPaintEvent *)
greenPen.setWidth(2); greenPen.setWidth(2);
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::Antialiasing);
painter.translate(width() / 2, height() / 2); painter.translate(width() / 2, height() / 2);
// draw background // draw background
{ {
painter.setPen(blackPen); painter.setPen(whitePen);
painter.setBrush(bgGround); painter.setBrush(bgGround);
painter.drawEllipse(-m_size/2, -m_size/2, m_size, m_size); painter.drawEllipse(-m_size/2, -m_size/2, m_size, m_size);
} }
@ -100,60 +97,47 @@ void DOA2Compass::paintEvent(QPaintEvent *)
QString s; QString s;
blackPen.setWidth(1); blackPen.setWidth(1);
painter.setPen(blackPen); painter.setPen(whitePen);
painter.setFont(font());
for(int i=0; i<nyawLines; i++) { for(int i=0; i<nyawLines; i++) {
if( i == 0 ) { if( i == 0 ) {
s = "N"; s = "N";
painter.setPen(bluePen);
painter.setFont(QFont("", fontSize*1.3));
} else if ( i == 9 ) { } else if ( i == 9 ) {
s = "W"; s = "E";
painter.setPen(blackPen);
painter.setFont(QFont("", fontSize*1.3));
} else if ( i == 18 ) { } else if ( i == 18 ) {
s = "S"; s = "S";
painter.setPen(redPen);
painter.setFont(QFont("", fontSize*1.3));
} else if ( i == 27 ) { } else if ( i == 27 ) {
s = "E"; s = "W";
painter.setPen(blackPen);
painter.setFont(QFont("", fontSize*1.3));
} else { } else {
s = QString("%1").arg(i*rotAng); s = QString("%1").arg(i*rotAng);
painter.setPen(blackPen);
painter.setFont(QFont("", fontSize));
} }
fx1 = 0; fx1 = 0;
fy1 = -m_size/2 + m_offset; fy1 = -m_size/2 + m_offset;
fx2 = 0; fx2 = 0;
if( i % 3 == 0 ) { if (i % 3 == 0)
{
fy2 = fy1 + yawLineLeng; fy2 = fy1 + yawLineLeng;
painter.drawLine(QPointF(fx1, fy1), QPointF(fx2, fy2)); painter.drawLine(QPointF(fx1, fy1), QPointF(fx2, fy2));
fy2 = fy1 + yawLineLeng+4; fy2 = fy1 + yawLineLeng+4;
painter.drawText(QRectF(-50, fy2, 100, fontSize+2), painter.drawText(QRectF(-50, fy2, 100, fontSize+2), Qt::AlignCenter, s);
Qt::AlignCenter, s); }
} else { else
{
fy2 = fy1 + yawLineLeng/2; fy2 = fy1 + yawLineLeng/2;
painter.drawLine(QPointF(fx1, fy1), QPointF(fx2, fy2)); 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; double fx1, fy1, fx2, fy2, fx3, fy3;
fx1 = 0; fx1 = 0;
@ -163,9 +147,10 @@ void DOA2Compass::paintEvent(QPaintEvent *)
fx3 = arrowWidth/2; fx3 = arrowWidth/2;
fy3 = 0; 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 pointsN[3] = {
QPointF(fx1, fy1), QPointF(fx1, fy1),
QPointF(fx2, fy2), QPointF(fx2, fy2),
@ -173,7 +158,6 @@ void DOA2Compass::paintEvent(QPaintEvent *)
}; };
painter.drawPolygon(pointsN, 3); painter.drawPolygon(pointsN, 3);
fx1 = 0; fx1 = 0;
fy1 = m_size/2 - m_offset - m_size/25 - 15; fy1 = m_size/2 - m_offset - m_size/25 - 15;
fx2 = -arrowWidth/2; fx2 = -arrowWidth/2;
@ -181,31 +165,34 @@ void DOA2Compass::paintEvent(QPaintEvent *)
fx3 = arrowWidth/2; fx3 = arrowWidth/2;
fy3 = 0; fy3 = 0;
painter.setBrush(QBrush(Qt::red)); painter.setBrush(QBrush(palette().button().color().lighter(150)));
QPointF pointsS[3] = { QPointF pointsS[3] = {
QPointF(fx1, fy1), QPointF(fx1, fy1),
QPointF(fx2, fy2), QPointF(fx2, fy2),
QPointF(fx3, fy3) QPointF(fx3, fy3)
}; };
painter.drawPolygon(pointsS, 3); painter.drawPolygon(pointsS, 3);
painter.rotate(-m_azAnt);
} }
// draw azPos marker
// draw yaw marker
{ {
int yawMarkerSize = m_size/12; int azMarkerSize = m_size/15;
double fx1, fy1, fx2, fy2, fx3, fy3; double fx1, fy1, fx2, fy2, fx3, fy3, fyl;
painter.rotate(-m_yaw);
painter.setBrush(QBrush(QColor(0xFF, 0x00, 0x00, 0xE0)));
fx1 = 0; fx1 = 0;
fy1 = -m_size/2 + m_offset; fy1 = -m_size/2 + m_offset;
fx2 = fx1 - yawMarkerSize/2; fx2 = fx1 - azMarkerSize/2;
fy2 = fy1 + yawMarkerSize; fy2 = fy1 + azMarkerSize;
fx3 = fx1 + yawMarkerSize/2; fx3 = fx1 + azMarkerSize/2;
fy3 = fy1 + yawMarkerSize; 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 points[3] = {
QPointF(fx1, fy1), QPointF(fx1, fy1),
QPointF(fx2, fy2), QPointF(fx2, fy2),
@ -213,65 +200,63 @@ void DOA2Compass::paintEvent(QPaintEvent *)
}; };
painter.drawPolygon(points, 3); 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 yawMarkerSize = m_size/15;
int fx, fy, w, h; double fx1, fy1, fx2, fy2, fx3, fy3, fyl;
QString s;
char buf[200];
w = 130; fx1 = 0;
h = 2*(altFontSize + 8); 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; fx = -w/2;
fy = -h/2; fy = -h/2;
blackPen.setWidth(2); painter.setPen(whitePen);
painter.setPen(blackPen); painter.setBrush(QBrush(Qt::black));
painter.setBrush(QBrush(Qt::white)); QFont f = font();
painter.setFont(QFont("", altFontSize)); f.setPointSize(altFontSize);
painter.setFont(f);
painter.drawRoundedRect(fx, fy, w, h, 6, 6); painter.drawRoundedRect(fx, fy, w, h, 6, 6);
painter.setPen(bluePen); 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)));
sprintf(buf, "ALT: %6.1f m", m_alt); 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)));
s = buf; 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)));
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);
} }
} }
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) /// \brief Set all data (yaw, alt, height)
/// ///
/// \param y - yaw ( in degree) /// \param azPos - forward (positive angles side relative to antennas direction) azimuth (in degrees)
/// \param a - altitude ( in m) /// \param azNeg - reverse (negatve angles side relative to antennas direction) azimuth (in degrees)
/// \param h - height from ground (in m) /// \param azAnt - antennas azimuth from 1 (connected to stream 0) to 2 (connected to stream 1)
/// ///
void setData(double y, double a, double h) { void setData(double azPos, double azNeg, double azAnt) {
m_yaw = y; m_azPos = azPos;
m_alt = a; m_azNeg = azNeg;
m_h = h; m_azAnt = azAnt;
if( m_yaw < 0 ) m_yaw = 360 + m_yaw; if( m_azPos < 0 ) m_azPos = 360 + m_azPos;
if( m_yaw > 360 ) m_yaw = m_yaw - 360; 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(); emit canvasReplot();
} }
/// ///
/// \brief Set yaw angle (in degree) /// \brief Set forward azimoth (in degree)
/// \param val - yaw angle (in degree) /// \param val - forward azimoth (in degree)
/// ///
void setYaw(double val) { void setAzPos(double val)
m_yaw = val; {
if( m_yaw < 0 ) m_yaw = 360 + m_yaw; m_azPos = val;
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;
emit canvasReplot(); emit canvasReplot();
} }
/// ///
/// \brief Set altitude value /// \brief Set reverse azimoth (in degree)
/// \param val - altitude (in m) /// \param val - reverse azimoth (in degree)
/// ///
void setAlt(double val) { void setAzNeg(double val)
m_alt = val; {
m_azNeg = val;
if( m_azNeg < 0 ) m_azNeg = 360 + m_azNeg;
if( m_azNeg > 360 ) m_azNeg = m_azNeg - 360;
emit canvasReplot(); emit canvasReplot();
} }
/// ///
/// \brief Set height from ground /// \brief Set antennas azimoth (in degree)
/// \param val - height (in m) /// \param val - antennas azimoth (in degree)
/// ///
void setH(double val) { void setAzAnt(double val)
m_h = val; {
m_azAnt = val;
if( m_azAnt < 0 ) m_azAnt = 360 + m_azAnt;
if( m_azAnt > 360 ) m_azAnt = m_azAnt - 360;
emit canvasReplot(); emit canvasReplot();
} }
/// ///
/// \brief Get yaw angle /// \brief Draw legend in the center of the compass
/// \return yaw angle (in degree) /// \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 /// \brief Get forward azimuth
/// \return altitude (in m) /// \return forward azimuth (in degree)
/// ///
double getAlt() {return m_alt;} double getAzPos() const {return m_azPos; }
/// ///
/// \brief Get height from ground /// \brief Get reverse azimuth
/// \return height from ground (in m) /// \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: signals:
void canvasReplot(void); void canvasReplot(void);
@ -105,15 +128,15 @@ protected slots:
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event); void resizeEvent(QResizeEvent *event);
void keyPressEvent(QKeyEvent *event);
protected: protected:
int m_sizeMin, m_sizeMax; ///< widget min/max size (in pixel) int m_sizeMin, m_sizeMax; ///< widget min/max size (in pixel)
int m_size, m_offset; ///< widget size and offset size 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_azPos; ///< forward (+) azimuth (in degree)
double m_alt; ///< altitude (in m) double m_azNeg; ///< reverse (-) azimuth (in degree)
double m_h; ///< height from ground (in m) double m_azAnt; ///< antennas azimuth from 1 (connected to stream 0) to 2 (connected to stream 1)
}; };
#endif // INCLUDE_DOA2COMPASS_H #endif // INCLUDE_DOA2COMPASS_H

View File

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