Aperture/mycanvas.cpp

130 lines
4.1 KiB
C++
Raw Normal View History

2023-05-16 14:58:12 +00:00
#include "mycanvas.h"
2023-05-17 23:08:48 +00:00
#include <qpainter.h>
#include <qpen.h>
#include <qsize.h>
#include <qwidget.h>
2023-05-24 00:04:44 +00:00
void MyCanvas::ColorAxis(QPaintEvent *event, QPainter *painter, double step, double max) {
double centerX = event->rect().width()/2;
double centerY = event->rect().height()/2;
painter->setPen(QPen(QColor(0,0,0)));
painter->drawLine(QLineF(centerX, 0, centerX, event->rect().height()));
painter->drawLine(QLineF(0, centerY, event->rect().width(), centerY));
for (double x = 0; x<max; x+=step) {
painter->drawText(transposePoint(x, 0, max, max),
QString::number(x, 'f', 2));
}
for (double x = 0; x>-max; x-=step) {
painter->drawText(transposePoint(x, 0, max, max),
QString::number(x, 'f', 2));
}
for (double y = 0; y<max; y+=step) {
painter->drawText(transposePoint(0, y, max, max),
QString::number(y, 'f', 2));
}
for (double y = 0; y>-max; y-=step) {
painter->drawText(transposePoint(0, y, max, max),
QString::number(y, 'f', 2));
}
}
2023-05-17 23:08:48 +00:00
MyCanvas::MyCanvas(QWidget *parent) : QWidget(parent) {
// chart()->setTitle("Фазовое распределение антенных решеток");
// chart()->legend()->hide();
// QValueAxis *qAxisX = new QValueAxis();
// QValueAxis *qAxisY = new QValueAxis();
// qAxisX->setRange(-1, 1);
// qAxisY->setRange(-1, 1);
// chart()->addAxis(qAxisX, Qt::AlignLeft);
// chart()->addAxis(qAxisY, Qt::AlignBottom);
2023-05-16 14:58:12 +00:00
}
void MyCanvas::drawState(ToPaintState state) {
2023-05-17 23:08:48 +00:00
this->state = state;
this->update();
}
2023-05-16 14:58:12 +00:00
2023-05-17 23:08:48 +00:00
void MyCanvas::paintEvent(QPaintEvent *event) {
QPainter painter(this);
2023-05-24 00:04:44 +00:00
painter.fillRect(event->rect(), QColor(255,255,255));
2023-05-16 14:58:12 +00:00
2023-05-17 23:08:48 +00:00
switch (this->state.type) {
case 1:
for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
2023-05-16 14:58:12 +00:00
2023-05-17 23:08:48 +00:00
int c = i % 4;
2023-05-24 00:04:44 +00:00
painter.setPen(QPen(QColor(63 * c, 255 - 63 * c, 163 * c)));
2023-05-16 14:58:12 +00:00
2023-05-17 23:08:48 +00:00
TIzl izls = radar.FIzlArray[i];
QRectF rect = this->transposeRect(izls.IzPos.Z - 0.0085, izls.IzPos.Y - 0.0115, izls.IzPos.Z + 0.0085, izls.IzPos.Y + 0.0115, state.axisX, state.axisY);
painter.drawRect(rect);
}
2023-05-16 14:58:12 +00:00
2023-05-17 23:08:48 +00:00
case 2:
// IAmpIzls
2023-05-24 00:04:44 +00:00
this->ColorAxis(event, &painter, state.axisX/5, state.axisX);
2023-05-17 23:08:48 +00:00
for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
2023-05-16 14:58:12 +00:00
2023-05-17 23:08:48 +00:00
TIzl izls = radar.FIzlArray[i];
2023-05-24 00:04:44 +00:00
painter.setPen(QPen(QColor::fromHsvF(izls.Amplitude, 1, 1)));
2023-05-16 14:58:12 +00:00
2023-05-17 23:08:48 +00:00
QRectF rect = this->transposeRect(izls.IzPos.Z - 0.008, izls.IzPos.Y - 0.011, izls.IzPos.Z + 0.008, izls.IzPos.Y + 0.011, state.axisX, state.axisY);
painter.drawRect(rect);
2023-05-16 14:58:12 +00:00
}
break;
2023-05-17 23:08:48 +00:00
case 3:
// FazIzls
2023-05-24 00:04:44 +00:00
this->ColorAxis(event, &painter, state.axisX/5, state.axisX);
2023-05-17 23:08:48 +00:00
for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
TIzl izls = radar.FIzlArray[i];
double faz = frac(izls.Fase*0.5/M_PI)*2/M_PI;
2023-05-24 00:04:44 +00:00
painter.setPen(QPen(QColor::fromHsvF(faz, 1,1)));
2023-05-17 23:08:48 +00:00
QRectF rect = this->transposeRect(
izls.IzPos.Z - 0.008, izls.IzPos.Y - 0.011, izls.IzPos.Z + 0.008, izls.IzPos.Y + 0.011,
state.axisX, state.axisY);
painter.drawRect(rect);
2023-05-16 14:58:12 +00:00
}
break;
2023-05-17 23:08:48 +00:00
case 4:
// DN
2023-05-24 00:04:44 +00:00
this->ColorAxis(event, &painter, state.axisX/5, state.axisX);
2023-05-17 23:08:48 +00:00
for (int i = 0; i < this->FDNMass.size(); ++i) {
for (int j = 0; j < this->FDNMass[i].size(); ++j) {
TColPoint mass = FDNMass[i][j];
2023-05-24 00:04:44 +00:00
QPen pen = QPen(QColor(0,0,0));
2023-05-17 23:08:48 +00:00
painter.setPen(pen);
QPointF point = transposePoint(mass.x, mass.y, state.axisX, state.axisY);
painter.drawPoint(point);
}
2023-05-16 14:58:12 +00:00
}
break;
2023-05-17 23:08:48 +00:00
}
// chart()->addSeries(series1);
}
2023-05-16 14:58:12 +00:00
2023-05-24 00:04:44 +00:00
2023-05-17 23:08:48 +00:00
QPointF MyCanvas::transposePoint(double x, double y, double axisX, double axisY) {
2023-05-24 00:04:44 +00:00
double cwidth = static_cast<double>(width())/(axisX*2);
double cheight = static_cast<double>(height())/(axisY*2);
2023-05-16 14:58:12 +00:00
2023-05-24 00:04:44 +00:00
double zeroX = width()/2;
double zeroY = height()/2;
2023-05-17 23:08:48 +00:00
2023-05-24 00:04:44 +00:00
QPointF point(zeroX + (x * cwidth), zeroY + (y * cheight));
return point;
2023-05-17 23:08:48 +00:00
}
2023-05-16 14:58:12 +00:00
2023-05-17 23:08:48 +00:00
QRectF MyCanvas::transposeRect(double x, double y, double x2, double y2, double axisX, double axisY) {
return QRectF(transposePoint(x, y, axisX, axisY), transposePoint(x2, y2, axisX, axisY));
2023-05-16 14:58:12 +00:00
}