diff --git a/src/global.h b/src/global.h index a84aa92..66f1684 100644 --- a/src/global.h +++ b/src/global.h @@ -3,6 +3,9 @@ #include #include +#include + +#include "filemanager.h" class Global:public QObject { @@ -31,6 +34,7 @@ public: DeviceConnectionStatus getDeviceConnectionStatus(){return _deviceConnectStatus;} #endif + QVector>> _curveDataVtr; signals: void sigModeModify(const Mode); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6aad32d..3e2ed32 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -35,7 +35,6 @@ MainWindow::MainWindow(QWidget *parent) permenentLabel->setText("Permanent show!"); ui->statusbar->addPermanentWidget(permenentLabel); // - connections(); // _expertmentSettingForm->setWindowFlags(_expertmentSettingForm->windowFlags()| Qt::Dialog); _specificHeatComparisonMethodForm->setWindowFlags(_specificHeatComparisonMethodForm->windowFlags()| Qt::Dialog); @@ -44,6 +43,11 @@ MainWindow::MainWindow(QWidget *parent) // _realTimeDataForm->show(); setActionEnable(true); + + _eventHandler = _centralWidget->getEvnetHandler(); + // + connections(); + } MainWindow::~MainWindow() @@ -100,6 +104,11 @@ void MainWindow::connections() connect(_centralWidget,&CentralWidget::sigRightDockWidgetHide, [&](){ _rightWidget->hide(); }); + + //SpecificHeatComparisonMethodForm + connect(_eventHandler,&EventHandler::sigSetCurve, + _specificHeatComparisonMethodForm, + &SpecificHeatComparisonMethodForm::slotSetCurve); } void MainWindow::setActionEnable(const bool flag) diff --git a/src/mainwindow.h b/src/mainwindow.h index 3d6ef05..cab2357 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -71,6 +71,7 @@ private: private: Ui::MainWindow *ui; CentralWidget *_centralWidget; + EventHandler *_eventHandler; LeftWidget*_leftWidget; QDockWidget* _rightWidget; ExperimentSettingForm *_expertmentSettingForm; diff --git a/src/ui/centralwidget.cpp b/src/ui/centralwidget.cpp index 62a8dc6..4e966b9 100644 --- a/src/ui/centralwidget.cpp +++ b/src/ui/centralwidget.cpp @@ -44,15 +44,14 @@ CentralWidget::CentralWidget(QWidget *parent) _eventHandler = new EventHandler(_customPlot, _line1, _line2, nullptr); _eventHandler->setEnable(true); - _customPlot->installEventFilter(_eventHandler); _customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); connect(_eventHandler,&EventHandler::sigSendLineXCoord, this,&CentralWidget::sigSendLineXCoord); -// connect(_customPlot, &QCustomPlot::selectionChangedByUser, -// this, &CentralWidget::slotSelectionChanged); + // connect(_customPlot, &QCustomPlot::selectionChangedByUser, + // this, &CentralWidget::slotSelectionChanged); setEventHandlerEnable(false); @@ -185,7 +184,11 @@ void CentralWidget::slotRecvAnalysisFileName(const QString &fileName) // _currentCurve->setPen(QPen(Qt::red)); // 设置线条颜色为红色 // _currentCurve->setBrush(QBrush(QColor(255, 0, 0, 20))); // 设置填充颜色并带有透明度 _currentCurve->setSelectable(QCP::stWhole); // 设置曲线可选 -// _currentCurve->setSelectable(QCP::stPlottable); // 设置曲线可选 + // _currentCurve->setSelectable(QCP::stPlottable); // 设置曲线可选 + + Global::instance()->_curveDataVtr.push_back( + qMakePair>( + _currentCurve,_dataVtr)); // 清除第一个图表上的数据 #if 0 @@ -228,11 +231,11 @@ void CentralWidget::slotSelectionChanged() } } - logde << "Current pen color:" << curve->pen().color().name().toStdString(); + logde << "Current pen color:" << curve->pen().color().name().toStdString(); } -// _customPlot->replot(); -// _customPlot->update(); + // _customPlot->replot(); + // _customPlot->update(); #if 0 for (QCPAbstractPlottable *plottable : _customPlot->plottable()) { diff --git a/src/ui/centralwidget.h b/src/ui/centralwidget.h index b54fa35..bfc1ff3 100644 --- a/src/ui/centralwidget.h +++ b/src/ui/centralwidget.h @@ -27,6 +27,8 @@ public: void setAnalysisMode(const AnalysisMode); void clearAllData(); + + EventHandler* getEvnetHandler(){return _eventHandler;} signals: void sigContextMenuShow(const QPoint); void sigSendLineXCoord(const int,const double); @@ -36,6 +38,7 @@ public slots: void slotRecvCommonData(const CommonData&); void slotRecvAnalysisFileName(const QString&); void slotSelectionChanged(); + //analysis setting void slotAnalysisSettingLineXPoint(const int index,const double); diff --git a/src/ui/eventhandler.cpp b/src/ui/eventhandler.cpp index 02291cb..d632507 100644 --- a/src/ui/eventhandler.cpp +++ b/src/ui/eventhandler.cpp @@ -1,5 +1,6 @@ #include "eventhandler.h" #include "logger.h" +#include "specificheatcomparisonmethodform.h" EventHandler::EventHandler(QCustomPlot *plot, QCPItemStraightLine *line1, @@ -193,17 +194,20 @@ void EventHandler::slotBaseLine() } curve->setPen(QPen(Qt::red)); _plot->replot(); + + emit sigSetCurve(SpecificHeatComparisonMethodForm::CurveType::BaseLine,curve); } void EventHandler::slotStandardSample() { - QCPCurve *curve = qobject_cast(_plot->selectedPlottables().front()); if(!curve){ return; } curve->setPen(QPen(Qt::darkGreen)); _plot->replot(); + + emit sigSetCurve(SpecificHeatComparisonMethodForm::CurveType::StandardSample,curve); } void EventHandler::slotSample() @@ -216,6 +220,8 @@ void EventHandler::slotSample() curve->setPen(QPen(Qt::black)); _plot->replot(); #endif + + emit sigSetCurve(SpecificHeatComparisonMethodForm::CurveType::Sample,curve); } void EventHandler::updateSelectedRegion() diff --git a/src/ui/eventhandler.h b/src/ui/eventhandler.h index bbe4cbf..2997e20 100644 --- a/src/ui/eventhandler.h +++ b/src/ui/eventhandler.h @@ -33,6 +33,7 @@ public: void setMode(const Mode mode){ _mode = mode;} signals: void sigSendLineXCoord(const int,const double); + void sigSetCurve(const int, QCPCurve*); protected: bool eventFilter(QObject *obj, QEvent *event) override; private slots: @@ -45,7 +46,6 @@ private: int findClosestIndex(const QVector &data, double target); void updateSelectedRegion(); bool isNearLine(QCPItemStraightLine *line, const QPoint &pos); - private: Mode _mode; bool _enableFlag; diff --git a/src/ui/specificheatcomparisonmethodform.cpp b/src/ui/specificheatcomparisonmethodform.cpp index bf909ad..f7e65b5 100644 --- a/src/ui/specificheatcomparisonmethodform.cpp +++ b/src/ui/specificheatcomparisonmethodform.cpp @@ -4,6 +4,9 @@ #include "specificheatcomparisonmethodform.h" #include "ui_specificheatcomparisonmethodform.h" +#include "logger.h" +#include "global.h" +#include "pointcalculate.h" SpecificHeatComparisonMethodForm::SpecificHeatComparisonMethodForm(QWidget *parent) : QWidget(parent), @@ -39,6 +42,19 @@ SpecificHeatComparisonMethodForm::SpecificHeatComparisonMethodForm(QWidget *pare ui->formLayoutDataFile->addRow("基线",baseLineLayout); ui->formLayoutDataFile->addRow("标样",standardSampleLayout); ui->formLayoutDataFile->addRow("样品",sampleLayout); + + // + _baseLineLineEdit->setEnabled(false); + _standardSampleLineEdit->setEnabled(false); + _sampleLineEdit->setEnabled(false); + + ui->LineEditCorrectionCoefficient->setText("1.000"); + ui->LineEditSampleWeight->setText("17.92"); + ui->LineEditStandardSampleWeight->setText("13.92"); + + _baseLineCurve = nullptr; + _standardSampleCurve = nullptr; + _sampleCurve = nullptr; } SpecificHeatComparisonMethodForm::~SpecificHeatComparisonMethodForm() @@ -46,9 +62,71 @@ SpecificHeatComparisonMethodForm::~SpecificHeatComparisonMethodForm() delete ui; } +void SpecificHeatComparisonMethodForm::slotSetCurve(const int type, QCPCurve *curve) +{ + logde<<"index:"<_curveDataVtr; + QVector *baseLineDataVtr = nullptr, + *standardSampleDataVtr = nullptr, + *sampleDataVtr = nullptr; + for (auto& pair : curveDataVtr) { + if(pair.first == _baseLineCurve){ + baseLineDataVtr = &(pair.second); + }else if(pair.first == _standardSampleCurve){ + standardSampleDataVtr = &(pair.second); + }else if(pair.first == _sampleCurve){ + sampleDataVtr = &(pair.second); + } + } + + if(!baseLineDataVtr || + !standardSampleDataVtr|| + !sampleDataVtr){ + logde<<"Base,standard,sample not selected."; + return; + } + + // + float targetTemperature = ui->LineEditTemperature->text().toFloat(); + + PointCalculate::setExperimentData(*baseLineDataVtr); + QPointF baseLinePoint = PointCalculate::getClosestPointByX(targetTemperature); + + PointCalculate::setExperimentData(*standardSampleDataVtr); + QPointF standardSamplePoint = PointCalculate::getClosestPointByX(targetTemperature); + + PointCalculate::setExperimentData(*sampleDataVtr); + QPointF samplePoint = PointCalculate::getClosestPointByX(targetTemperature); + + logde<<"baseLinePoint:"<LineEditStandardSampleWeight->text().toFloat(); + float sampleWeight = ui->LineEditSampleWeight->text().toFloat(); + +// double cpTarget = cp * } void SpecificHeatComparisonMethodForm::on_pushButtonQuit_clicked() @@ -56,7 +134,7 @@ void SpecificHeatComparisonMethodForm::on_pushButtonQuit_clicked() hide(); } -double calculateHeatCapacity(double theta) { +double SpecificHeatComparisonMethodForm::calculateHeatCapacity(double theta) { // 系数A_i const double A0 = 1.12705; const double A1 = 0.23260; @@ -76,8 +154,8 @@ double calculateHeatCapacity(double theta) { // 计算比热容 double Cp = A0 + A1 * x + A2 * std::pow(x, 2) + A3 * std::pow(x, 3) + A4 * std::pow(x, 4) + - A5 * std::pow(x, 5) + A6 * std::pow(x, 6) + A7 * std::pow(x, 7) + A8 * std::pow(x, 8) + - A9 * std::pow(x, 9) + A10 * std::pow(x, 10); + A5 * std::pow(x, 5) + A6 * std::pow(x, 6) + A7 * std::pow(x, 7) + A8 * std::pow(x, 8) + + A9 * std::pow(x, 9) + A10 * std::pow(x, 10); return Cp; } diff --git a/src/ui/specificheatcomparisonmethodform.h b/src/ui/specificheatcomparisonmethodform.h index dc3ff1e..81bcb5f 100644 --- a/src/ui/specificheatcomparisonmethodform.h +++ b/src/ui/specificheatcomparisonmethodform.h @@ -4,6 +4,7 @@ #include #include #include +#include namespace Ui { class SpecificHeatComparisonMethodForm; @@ -17,6 +18,13 @@ public: explicit SpecificHeatComparisonMethodForm(QWidget *parent = nullptr); ~SpecificHeatComparisonMethodForm(); + enum CurveType{ + BaseLine, + StandardSample, + Sample + }; +public slots: + void slotSetCurve(const int ,QCPCurve*); private slots: void on_pushButtonCalculate_clicked(); @@ -29,6 +37,8 @@ private: QLineEdit *_baseLineLineEdit,*_standardSampleLineEdit, *_sampleLineEdit; QLabel *_baseLineLabel,*_standardSampleLabel,*_sampleLabel; + + QCPCurve *_baseLineCurve,*_standardSampleCurve,*_sampleCurve; }; #endif // SPECIFICHEATCOMPARISONMETHODFORM_H diff --git a/src/ui/specificheatcomparisonmethodform.ui b/src/ui/specificheatcomparisonmethodform.ui index a634be3..c671333 100644 --- a/src/ui/specificheatcomparisonmethodform.ui +++ b/src/ui/specificheatcomparisonmethodform.ui @@ -46,7 +46,7 @@ - + @@ -56,7 +56,7 @@ - + @@ -113,7 +113,7 @@ - +