344 lines
7.7 KiB
C++
344 lines
7.7 KiB
C++
#include "ui/Panel/PolarPanel.h"
|
|
#include "ui/DockWidget.h"
|
|
#include "ui/DockTitleBar.h"
|
|
#include "common/SpdLogger.h"
|
|
#include <QHBoxLayout>
|
|
#include <QFileInfo>
|
|
#include <QMessageBox>
|
|
|
|
PolarPanel::PolarPanel(int index, const QString& filePath, QWidget* parent)
|
|
: DataPanel(index, FileEntryType::Polar, filePath, parent)
|
|
{
|
|
m_pChart = NULL;
|
|
m_pThetaAxis = NULL;
|
|
m_pRadiusAxis = NULL;
|
|
|
|
m_iThetaMax = 0;
|
|
m_iThetaMin = 0;
|
|
m_iRadiusMax = 0;
|
|
m_iRadiusMin = 0;
|
|
|
|
m_unitTheta = "";
|
|
m_unitRadius = "";
|
|
|
|
LOG_INFO("Created PolarPanel {} for file: {}", index, filePath.toStdString());
|
|
}
|
|
|
|
PolarPanel::PolarPanel(int index, std::shared_ptr<FileEntryPolar> fileEntry, QWidget* parent)
|
|
: DataPanel(index, fileEntry, parent)
|
|
{
|
|
m_pChart = NULL;
|
|
m_pThetaAxis = NULL;
|
|
m_pRadiusAxis = NULL;
|
|
|
|
m_iThetaMax = 0;
|
|
m_iThetaMin = 0;
|
|
m_iRadiusMax = 0;
|
|
m_iRadiusMin = 0;
|
|
|
|
m_unitTheta = "";
|
|
m_unitRadius = "";
|
|
|
|
if (fileEntry) {
|
|
LOG_INFO("Created PolarPanel {} for chart: {}", index, fileEntry->GetName().toStdString());
|
|
// Override the title with chart name
|
|
title_ = QString("Polar Panel %1 - %2").arg(index).arg(fileEntry->GetName());
|
|
}
|
|
else {
|
|
LOG_WARN("Created PolarPanel {} with null chart data", index);
|
|
}
|
|
}
|
|
|
|
PolarPanel::~PolarPanel()
|
|
{
|
|
LOG_INFO("Destroyed PolarPanel {}", GetIndex());
|
|
}
|
|
|
|
void PolarPanel::RefreshPanel()
|
|
{
|
|
// Implement curve-specific refresh logic here
|
|
DataPanel::RefreshPanel();
|
|
|
|
if (auto fileEntry = fileEntry_->AsPolar()) {
|
|
OnDataPanelUpdated(fileEntry);
|
|
}
|
|
|
|
LOG_INFO("Refreshed TablePanel {}", GetIndex());
|
|
}
|
|
|
|
void PolarPanel::InitUI()
|
|
{
|
|
m_pChart = new QPolarChart();
|
|
//mPolarChart->addSeries(mCurveData);
|
|
//m_pChart->legend()->hide();
|
|
m_pChart->layout()->setContentsMargins(0, 0, 0, 0);
|
|
m_pChart->setBackgroundRoundness(0);
|
|
m_pChart->setTheme(QChart::ChartThemeBlueIcy);
|
|
|
|
//×ø±êÖá
|
|
m_pThetaAxis = new QValueAxis();
|
|
m_pThetaAxis->setTickCount(13);
|
|
m_pThetaAxis->setLabelFormat("%d");
|
|
m_pThetaAxis->setRange(0, 360);
|
|
m_pChart->addAxis(m_pThetaAxis, QPolarChart::PolarOrientationAngular);
|
|
|
|
m_pRadiusAxis = new QValueAxis();
|
|
m_pRadiusAxis->setTickCount(6);
|
|
m_pRadiusAxis->setLabelFormat("%d");
|
|
m_pRadiusAxis->setRange(0, 30);
|
|
m_pChart->addAxis(m_pRadiusAxis, QPolarChart::PolarOrientationRadial);
|
|
|
|
QChartView *mChartView = new QChartView();
|
|
mChartView->setChart(m_pChart);
|
|
mChartView->setRenderHint(QPainter::Antialiasing);
|
|
|
|
QHBoxLayout* mainLayout = new QHBoxLayout(this);
|
|
mainLayout->setContentsMargins(0, 0, 0, 0);
|
|
mainLayout->addWidget(mChartView);
|
|
setLayout(mainLayout);
|
|
}
|
|
|
|
QString PolarPanel::GetTypeDisplayName() const
|
|
{
|
|
return "Polar";
|
|
}
|
|
|
|
void PolarPanel::OnDataPanelUpdated(FileEntryPolar* fileEntry)
|
|
{
|
|
QString strName = fileEntry->GetName();
|
|
updateTitle(strName);
|
|
|
|
FileEntryPolar::ChartProperties propChart = fileEntry->GetChartProperties();
|
|
updateTitleAxis(propChart.AngularTitle, propChart.RadialTitle);
|
|
updateMinMaxTheta(propChart.AngularMin, propChart.AngularMax, propChart.AngularCount, propChart.AngularUnit);
|
|
updateMinMaxRadius(propChart.RadialMin, propChart.RadialMax, propChart.RadialCount, propChart.RadialUnit);
|
|
|
|
QString strFile = fileEntry->GetPath() + "/" + fileEntry->GetFileName();
|
|
FileEntryPolar::LineProperties propCurves = fileEntry->GetLineProperties();
|
|
updateParseFile(strFile, propChart.timeParam, propCurves);
|
|
}
|
|
|
|
void PolarPanel::OnTimeChanged(double time)
|
|
{
|
|
if (m_data.size() > 0)
|
|
{
|
|
for (QMap<int, QLineSeries *>::Iterator itSeries = m_seriesIDMap.begin(); itSeries != m_seriesIDMap.end(); itSeries++)
|
|
{
|
|
QLineSeries * pSeries = itSeries.value();
|
|
if (pSeries)
|
|
{
|
|
pSeries->clear();
|
|
}
|
|
}
|
|
|
|
QMap< double, QMap<int, QPointF> >::const_iterator ite = m_data.lowerBound(time);
|
|
if (ite != m_data.end())
|
|
{
|
|
ite++;
|
|
}
|
|
|
|
for (QMap< double, QMap<int, QPointF> >::Iterator itA = m_data.begin(); itA != ite; itA++)
|
|
{
|
|
double dTime = itA.key();
|
|
QMap<int, QPointF> mapData = itA.value();
|
|
for (QMap<int, QPointF>::Iterator it = mapData.begin(); it != mapData.end(); it++)
|
|
{
|
|
int nIndex = it.key();
|
|
QPointF data = it.value();
|
|
|
|
QLineSeries * pSeries = m_seriesIDMap.value(nIndex);
|
|
if (pSeries)
|
|
{
|
|
pSeries->append(data);
|
|
}
|
|
}
|
|
}
|
|
|
|
m_pChart->update();
|
|
}
|
|
}
|
|
|
|
void PolarPanel::updateTitle(const QString & title)
|
|
{
|
|
if (nullptr != dockWidget_)
|
|
{
|
|
dockWidget_->setWindowTitle(title);
|
|
}
|
|
}
|
|
|
|
void PolarPanel::updateTitleAxis(const QString& thetaTitle, const QString& radiusTitle)
|
|
{
|
|
if (m_pThetaAxis)
|
|
{
|
|
if (!thetaTitle.isEmpty())
|
|
{
|
|
m_pThetaAxis->setTitleText(thetaTitle);
|
|
}
|
|
}
|
|
if (m_pRadiusAxis)
|
|
{
|
|
if (!radiusTitle.isEmpty())
|
|
{
|
|
m_pRadiusAxis->setTitleText(radiusTitle);
|
|
}
|
|
}
|
|
}
|
|
|
|
void PolarPanel::updateMinMaxTheta(float min, float max, int count, const QString& unit)
|
|
{
|
|
if (m_pThetaAxis)
|
|
{
|
|
if (max > min)
|
|
{
|
|
m_iThetaMax = max;
|
|
m_iThetaMin = min;
|
|
|
|
m_pThetaAxis->setRange(min, max);
|
|
}
|
|
|
|
if (count > 0)
|
|
{
|
|
m_pThetaAxis->setTickCount(count);
|
|
}
|
|
|
|
if (!unit.isEmpty())
|
|
{
|
|
m_pThetaAxis->setLabelFormat("%d" + unit);
|
|
|
|
m_unitTheta = unit;
|
|
}
|
|
}
|
|
}
|
|
|
|
void PolarPanel::updateMinMaxRadius(float min, float max, int count, const QString& unit)
|
|
{
|
|
if (m_pRadiusAxis)
|
|
{
|
|
if (max > min)
|
|
{
|
|
m_iRadiusMax = max;
|
|
m_iRadiusMin = min;
|
|
|
|
m_pRadiusAxis->setRange(min, max);
|
|
}
|
|
|
|
if (count > 0)
|
|
{
|
|
m_pRadiusAxis->setTickCount(count);
|
|
}
|
|
|
|
if (!unit.isEmpty())
|
|
{
|
|
m_pRadiusAxis->setLabelFormat("%d" + unit);
|
|
|
|
m_unitRadius = unit;
|
|
}
|
|
}
|
|
}
|
|
|
|
void PolarPanel::updateParseFile(const QString& strFile, int nT, FileEntryPolar::LineProperties listCurve)
|
|
{
|
|
if (strFile.isEmpty())
|
|
{
|
|
QMessageBox::information(nullptr, QStringLiteral("Error"), QStringLiteral("Please check file path"));
|
|
return;
|
|
}
|
|
|
|
m_seriesIDMap.clear();
|
|
|
|
QFile file(strFile);
|
|
if (file.open(QIODevice::ReadOnly))
|
|
{
|
|
bool bResetAxisTheta = false;
|
|
if (m_iThetaMax == m_iThetaMin)
|
|
{
|
|
bResetAxisTheta = true;
|
|
}
|
|
bool bResetAxisRadius = false;
|
|
if (m_iRadiusMax == m_iRadiusMin)
|
|
{
|
|
bResetAxisRadius = true;
|
|
}
|
|
|
|
float maxTheta = -10000000.0;
|
|
float minTheta = 10000000.0;
|
|
float maxRadius = -10000000.0;
|
|
float minRadius = 10000000.0;
|
|
|
|
while (!file.atEnd())
|
|
{
|
|
QString strLine = file.readLine().simplified();
|
|
if (!strLine.isEmpty())
|
|
{
|
|
QStringList listLine = strLine.split(" ");
|
|
double t = listLine.at(nT).toDouble();
|
|
|
|
QMap<int, QPointF> mapData;
|
|
for (int nI = 0; nI < listCurve.size(); nI++)
|
|
{
|
|
FileEntryPolar::LineProperty propCurve = listCurve.at(nI);
|
|
|
|
double Angular = listLine.at(propCurve.Angular).toDouble();
|
|
double Radial = listLine.at(propCurve.Radial).toDouble();
|
|
|
|
QPointF ptData = QPointF(Angular, Radial);
|
|
mapData.insert(nI, ptData);
|
|
|
|
if (bResetAxisTheta)
|
|
{
|
|
if (Angular < minTheta)
|
|
{
|
|
minTheta = Angular;
|
|
}
|
|
if (Angular > maxTheta)
|
|
{
|
|
maxTheta = Angular;
|
|
}
|
|
}
|
|
if (bResetAxisRadius)
|
|
{
|
|
if (Radial < minRadius)
|
|
{
|
|
minRadius = Radial;
|
|
}
|
|
if (Radial > maxRadius)
|
|
{
|
|
maxRadius = Radial;
|
|
}
|
|
}
|
|
}
|
|
m_data.insert(t, mapData);
|
|
}
|
|
}
|
|
|
|
if (bResetAxisTheta)
|
|
{
|
|
updateMinMaxTheta(minTheta * 0.9, maxTheta * 1.1, 0, m_unitTheta);
|
|
}
|
|
if (bResetAxisRadius)
|
|
{
|
|
updateMinMaxRadius(minRadius * 0.9, maxRadius * 1.1, 0, m_unitRadius);
|
|
}
|
|
|
|
for (int nI = 0; nI < listCurve.size(); nI++)
|
|
{
|
|
FileEntryPolar::LineProperty propCurve = listCurve.at(nI);
|
|
|
|
QLineSeries *pSeries = new QLineSeries(this);
|
|
pSeries->setName(propCurve.name);
|
|
pSeries->setColor(propCurve.color);
|
|
pSeries->setUseOpenGL(true);
|
|
m_pChart->addSeries(pSeries);
|
|
m_seriesIDMap.insert(nI, pSeries);
|
|
|
|
QPen pen(propCurve.color);
|
|
pen.setWidth(2);
|
|
pSeries->setPen(pen);
|
|
|
|
pSeries->attachAxis(m_pThetaAxis);
|
|
pSeries->attachAxis(m_pRadiusAxis);
|
|
}
|
|
|
|
file.close();
|
|
}
|
|
} |