1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 16:38:37 -05:00
sdrangel/plugins/channelmimo/doa2/doa2compass.cpp

280 lines
8.2 KiB
C++
Raw Normal View History

2022-05-27 04:59:25 -04:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2022 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QtCore>
#include <QtGui>
#include <QDebug>
#include "doa2compass.h"
DOA2Compass::DOA2Compass(QWidget *parent)
: QWidget(parent)
{
connect(this, SIGNAL(canvasReplot(void)), this, SLOT(canvasReplot_slot(void)));
m_sizeMin = 200;
m_sizeMax = 600;
m_offset = 2;
m_size = m_sizeMin - 2*m_offset;
2022-05-27 08:02:52 -04:00
m_drawLegend = false;
2022-05-27 04:59:25 -04:00
setMinimumSize(m_sizeMin, m_sizeMin);
setMaximumSize(m_sizeMax, m_sizeMax);
resize(m_sizeMin, m_sizeMin);
setFocusPolicy(Qt::NoFocus);
2022-05-27 08:02:52 -04:00
m_azPos = 0.0;
m_azNeg = 0.0;
m_azAnt = 0.0;
2022-05-27 23:48:49 -04:00
m_blindAngle = 0.0;
m_blindColor = QColor(32, 32, 32);
2022-05-27 04:59:25 -04:00
}
DOA2Compass::~DOA2Compass()
{
}
void DOA2Compass::canvasReplot_slot(void)
{
update();
}
void DOA2Compass::resizeEvent(QResizeEvent *event)
{
m_size = qMin(width(),height()) - 2*m_offset;
2022-05-27 08:02:52 -04:00
QWidget::resizeEvent(event);
2022-05-27 04:59:25 -04:00
}
void DOA2Compass::paintEvent(QPaintEvent *)
{
QPainter painter(this);
2022-05-27 08:02:52 -04:00
QBrush bgGround(palette().button().color());
2022-05-27 04:59:25 -04:00
QPen whitePen(Qt::white);
QPen blackPen(Qt::black);
QPen redPen(Qt::red);
QPen bluePen(Qt::blue);
QPen greenPen(Qt::green);
QPen borderPen(palette().button().color().lighter(200));
2022-05-27 04:59:25 -04:00
whitePen.setWidth(1);
blackPen.setWidth(2);
redPen.setWidth(2);
bluePen.setWidth(2);
greenPen.setWidth(2);
painter.setRenderHint(QPainter::Antialiasing);
painter.translate(width() / 2, height() / 2);
// draw background
{
2022-05-27 08:02:52 -04:00
painter.setPen(whitePen);
2022-05-27 04:59:25 -04:00
painter.setBrush(bgGround);
painter.drawEllipse(-m_size/2, -m_size/2, m_size, m_size);
}
2022-05-27 23:48:49 -04:00
// draw blind angle
if (m_blindAngle != 0)
{
2022-05-28 14:15:07 -04:00
painter.setBrush(m_blindColor);
painter.setPen(m_blindAngleBorder ? borderPen : Qt::NoPen);
2022-05-27 23:48:49 -04:00
painter.rotate(m_azAnt - 90);
painter.drawPie(-m_size/2, -m_size/2, m_size, m_size, -m_blindAngle*16, m_blindAngle*32);
painter.rotate(180);
painter.drawPie(-m_size/2, -m_size/2, m_size, m_size, -m_blindAngle*16, m_blindAngle*32);
painter.rotate(-m_azAnt - 90);
painter.setBrush(Qt::NoBrush);
painter.setPen(whitePen);
painter.drawEllipse(-m_size/2, -m_size/2, m_size, m_size);
}
2022-05-27 04:59:25 -04:00
2022-05-27 17:31:43 -04:00
// draw compass lines
2022-05-27 04:59:25 -04:00
{
int nyawLines = 36;
float rotAng = 360.0 / nyawLines;
int yawLineLeng = m_size/25;
double fx1, fy1, fx2, fy2;
int fontSize = 8;
QString s;
blackPen.setWidth(1);
2022-05-27 08:02:52 -04:00
painter.setPen(whitePen);
painter.setFont(font());
2022-05-27 04:59:25 -04:00
for(int i=0; i<nyawLines; i++) {
if( i == 0 ) {
s = "N";
} else if ( i == 9 ) {
2022-05-27 08:02:52 -04:00
s = "E";
2022-05-27 04:59:25 -04:00
} else if ( i == 18 ) {
s = "S";
} else if ( i == 27 ) {
2022-05-27 08:02:52 -04:00
s = "W";
2022-05-27 04:59:25 -04:00
} else {
s = QString("%1").arg(i*rotAng);
}
fx1 = 0;
fy1 = -m_size/2 + m_offset;
fx2 = 0;
2022-05-27 08:02:52 -04:00
if (i % 3 == 0)
{
2022-05-27 04:59:25 -04:00
fy2 = fy1 + yawLineLeng;
painter.drawLine(QPointF(fx1, fy1), QPointF(fx2, fy2));
fy2 = fy1 + yawLineLeng+4;
2022-05-27 08:02:52 -04:00
painter.drawText(QRectF(-50, fy2, 100, fontSize+2), Qt::AlignCenter, s);
}
else
{
2022-05-27 04:59:25 -04:00
fy2 = fy1 + yawLineLeng/2;
painter.drawLine(QPointF(fx1, fy1), QPointF(fx2, fy2));
}
2022-05-27 08:02:52 -04:00
painter.rotate(rotAng);
2022-05-27 04:59:25 -04:00
}
}
2022-05-27 08:02:52 -04:00
// draw antennas arrow
2022-05-27 04:59:25 -04:00
{
2022-05-27 08:02:52 -04:00
int arrowWidth = m_size/20;
2022-05-27 04:59:25 -04:00
double fx1, fy1, fx2, fy2, fx3, fy3;
fx1 = 0;
fy1 = -m_size/2 + m_offset + m_size/25 + 15;
fx2 = -arrowWidth/2;
fy2 = 0;
fx3 = arrowWidth/2;
fy3 = 0;
2022-05-27 08:02:52 -04:00
painter.rotate(m_azAnt);
2022-05-27 04:59:25 -04:00
2022-05-27 08:02:52 -04:00
painter.setPen(Qt::NoPen);
2022-05-27 17:31:43 -04:00
painter.setBrush(QBrush(QColor(192, 192, 192)));
2022-05-27 04:59:25 -04:00
QPointF pointsN[3] = {
QPointF(fx1, fy1),
QPointF(fx2, fy2),
QPointF(fx3, fy3)
};
painter.drawPolygon(pointsN, 3);
fx1 = 0;
fy1 = m_size/2 - m_offset - m_size/25 - 15;
fx2 = -arrowWidth/2;
fy2 = 0;
fx3 = arrowWidth/2;
fy3 = 0;
2022-05-27 08:02:52 -04:00
painter.setBrush(QBrush(palette().button().color().lighter(150)));
2022-05-27 04:59:25 -04:00
QPointF pointsS[3] = {
QPointF(fx1, fy1),
QPointF(fx2, fy2),
QPointF(fx3, fy3)
};
painter.drawPolygon(pointsS, 3);
2022-05-27 08:02:52 -04:00
painter.rotate(-m_azAnt);
}
2022-05-27 04:59:25 -04:00
2022-05-27 08:02:52 -04:00
// draw azPos marker
2022-05-27 04:59:25 -04:00
{
2022-05-27 08:02:52 -04:00
int azMarkerSize = m_size/15;
double fx1, fy1, fx2, fy2, fx3, fy3, fyl;
fx1 = 0;
fy1 = -m_size/2 + m_offset;
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),
QPointF(fx3, fy3)
};
painter.drawPolygon(points, 3);
painter.setPen(QColor(0xFF, 0x60, 0x60, 0xE0));
painter.drawLine(0, 0, 0, fyl);
painter.rotate(-m_azPos);
}
2022-05-27 04:59:25 -04:00
2022-05-27 08:02:52 -04:00
// draw azNeg marker
{
int yawMarkerSize = m_size/15;
double fx1, fy1, fx2, fy2, fx3, fy3, fyl;
2022-05-27 04:59:25 -04:00
fx1 = 0;
fy1 = -m_size/2 + m_offset;
fx2 = fx1 - yawMarkerSize/2;
fy2 = fy1 + yawMarkerSize;
fx3 = fx1 + yawMarkerSize/2;
fy3 = fy1 + yawMarkerSize;
2022-05-27 08:02:52 -04:00
fyl = -m_size/2;
painter.rotate(m_azNeg);
2022-05-27 04:59:25 -04:00
2022-05-27 08:02:52 -04:00
painter.setPen(Qt::NoPen);
2022-05-27 23:48:49 -04:00
painter.setBrush(QBrush(QColor(0x80, 0xFF, 0x80, 0xA0)));
2022-05-27 04:59:25 -04:00
QPointF points[3] = {
QPointF(fx1, fy1),
QPointF(fx2, fy2),
QPointF(fx3, fy3)
};
painter.drawPolygon(points, 3);
2022-05-27 23:48:49 -04:00
painter.setPen(QColor(0x80, 0xFF, 0x80, 0xE0));
2022-05-27 08:02:52 -04:00
painter.drawLine(0, 0, 0, fyl);
painter.rotate(-m_azNeg);
2022-05-27 04:59:25 -04:00
}
2022-05-27 08:02:52 -04:00
// draw legend
if (m_drawLegend)
2022-05-27 04:59:25 -04:00
{
2022-05-27 08:02:52 -04:00
int altFontSize = 8;
int fx, fy, w, h;
2022-05-27 04:59:25 -04:00
2022-05-27 08:02:52 -04:00
w = 10*altFontSize;
h = 3*(altFontSize + 8);
2022-05-27 04:59:25 -04:00
fx = -w/2;
fy = -h/2;
2022-05-27 08:02:52 -04:00
painter.setPen(whitePen);
painter.setBrush(QBrush(Qt::black));
QFont f = font();
f.setPointSize(altFontSize);
painter.setFont(f);
2022-05-27 04:59:25 -04:00
painter.drawRoundedRect(fx, fy, w, h, 6, 6);
2022-05-27 08:02:52 -04:00
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)));
2022-05-27 04:59:25 -04:00
}
}