Aperture/mycanvas.cpp
2023-05-24 03:04:44 +03:00

129 lines
4.1 KiB
C++

#include "mycanvas.h"
#include <qpainter.h>
#include <qpen.h>
#include <qsize.h>
#include <qwidget.h>
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));
}
}
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);
}
void MyCanvas::drawState(ToPaintState state) {
this->state = state;
this->update();
}
void MyCanvas::paintEvent(QPaintEvent *event) {
QPainter painter(this);
painter.fillRect(event->rect(), QColor(255,255,255));
switch (this->state.type) {
case 1:
for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
int c = i % 4;
painter.setPen(QPen(QColor(63 * c, 255 - 63 * c, 163 * c)));
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);
}
case 2:
// IAmpIzls
this->ColorAxis(event, &painter, state.axisX/5, state.axisX);
for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
TIzl izls = radar.FIzlArray[i];
painter.setPen(QPen(QColor::fromHsvF(izls.Amplitude, 1, 1)));
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);
}
break;
case 3:
// FazIzls
this->ColorAxis(event, &painter, state.axisX/5, state.axisX);
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;
painter.setPen(QPen(QColor::fromHsvF(faz, 1,1)));
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);
}
break;
case 4:
// DN
this->ColorAxis(event, &painter, state.axisX/5, state.axisX);
for (int i = 0; i < this->FDNMass.size(); ++i) {
for (int j = 0; j < this->FDNMass[i].size(); ++j) {
TColPoint mass = FDNMass[i][j];
QPen pen = QPen(QColor(0,0,0));
painter.setPen(pen);
QPointF point = transposePoint(mass.x, mass.y, state.axisX, state.axisY);
painter.drawPoint(point);
}
}
break;
}
// chart()->addSeries(series1);
}
QPointF MyCanvas::transposePoint(double x, double y, double axisX, double axisY) {
double cwidth = static_cast<double>(width())/(axisX*2);
double cheight = static_cast<double>(height())/(axisY*2);
double zeroX = width()/2;
double zeroY = height()/2;
QPointF point(zeroX + (x * cwidth), zeroY + (y * cheight));
return point;
}
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));
}