2025-06-27T15:34:56

This commit is contained in:
yuntang 2025-06-27 15:34:58 +08:00
parent ca1186c9b1
commit 330b4a3195
10 changed files with 224 additions and 158 deletions

View File

@ -1,6 +1,8 @@
#include "lowesssmoother.h" #include "lowesssmoother.h"
#include <numeric> #include <numeric>
#include "logger.h"
namespace Lowess { namespace Lowess {
void validateConfig(const Config& config) { void validateConfig(const Config& config) {
@ -54,10 +56,14 @@ std::vector<double> smooth(
validateConfig(config); validateConfig(config);
if (x.size() != y.size()) { if (x.size() != y.size()) {
throw std::invalid_argument("x and y must have the same size"); // throw std::invalid_argument("x and y must have the same size");
logde<<"x and y must have the same size.";
return std::vector<double>();
} }
if (x.size() < 2) { if (x.size() < 2) {
throw std::invalid_argument("At least 2 data points required"); // throw std::invalid_argument("At least 2 data points required");
logde<<"At least 2 data points required.";
return std::vector<double>();
} }
size_t n = x.size(); size_t n = x.size();

View File

@ -72,7 +72,7 @@ QPointF PointCalculate::getPeakPoint(){
_peakPoint = uniquePeak; _peakPoint = uniquePeak;
logde<<"peakPoint:"<<_peakPoint.x()<<","<<_peakPoint.y(); // logde<<"peakPoint:"<<_peakPoint.x()<<","<<_peakPoint.y();
return uniquePeak; return uniquePeak;
} }
@ -181,21 +181,21 @@ QPointF PointCalculate::findClosestPointByX(float x) {
void PointCalculate::setRegionPointX(const float left, const float right) void PointCalculate::setRegionPointX(const float left, const float right)
{ {
logde<<"dataVtr size:"<<_dataVtr.size(); // logde<<"dataVtr size:"<<_dataVtr.size();
logde<<"select point param left,right:"<<left<<","<<right; // logde<<"select point param left,right:"<<left<<","<<right;
_leftSelectedPoint = getClosestPointByX(left); _leftSelectedPoint = getClosestPointByX(left);
_rightSelectedPoint = getClosestPointByX(right); _rightSelectedPoint = getClosestPointByX(right);
_peakPoint = getPeakPoint(); _peakPoint = getPeakPoint();
logde<<"peak point:"<<_peakPoint.x()<<","<<_peakPoint.y(); // logde<<"peak point:"<<_peakPoint.x()<<","<<_peakPoint.y();
//根据峰谷重置选择点。 //根据峰谷重置选择点。
updateStartEndPoint(); updateStartEndPoint();
logde<<"select point left:"<<_leftSelectedPoint.x()<<","<<_leftSelectedPoint.y(); // logde<<"select point left:"<<_leftSelectedPoint.x()<<","<<_leftSelectedPoint.y();
logde<<"select point right:"<<_rightSelectedPoint.x()<<","<<_rightSelectedPoint.y(); // logde<<"select point right:"<<_rightSelectedPoint.x()<<","<<_rightSelectedPoint.y();
} }
QVector<QPointF> PointCalculate::getPeakPointGroup() QVector<QPointF> PointCalculate::getPeakPointGroup()
@ -211,9 +211,14 @@ QVector<QPointF> PointCalculate::getPeakPointGroup()
return pointVtr; return pointVtr;
} }
float PointCalculate::calculateArea() { float PointCalculate::calculateArea(const double x1,const double x2) {
//getPoint group //getPoint group
QVector<QPointF> points = getPeakPointGroup(); QVector<QPointF> points = getPeakPointGroup();
#if 1
if(_axisMode == AxisMode::DoubleY){
points = getPeakPointGroupByTime(x1,x2);
}
#endif
logde<<"points size:"<<points.size(); logde<<"points size:"<<points.size();
//calculate Area //calculate Area
@ -225,9 +230,20 @@ float PointCalculate::calculateArea() {
} }
//find a line. //find a line.
float k = (_leftSelectedPoint.y() - _rightSelectedPoint.y()) / QPointF leftSelectedPoint = _leftSelectedPoint;
(_leftSelectedPoint.x() - _rightSelectedPoint.x()); QPointF rightSelectedPoint = _rightSelectedPoint;
float b = _leftSelectedPoint.y() - k * _leftSelectedPoint.x();
if(_axisMode == AxisMode::DoubleY){
ExperimentData leftEd = getClosestDataByTime(_leftSelectedPoint.x());
ExperimentData rightEd = getClosestDataByTime(_rightSelectedPoint.x());
leftSelectedPoint = QPointF(leftEd.sampleTemp,leftEd.dsc);
rightSelectedPoint = QPointF(rightEd.sampleTemp,rightEd.dsc);
}
float k = (leftSelectedPoint.y() - rightSelectedPoint.y()) /
(leftSelectedPoint.x() - rightSelectedPoint.x());
float b = leftSelectedPoint.y() - k * leftSelectedPoint.x();
for (size_t i = 0; i < n - 1; ++i) { for (size_t i = 0; i < n - 1; ++i) {
#if 1 #if 1
@ -622,7 +638,7 @@ QVector<QPointF> PointCalculate::getNearbyPointGroupByX(const float targetX)
if(tmpPointVtr.size() > conCount){ if(tmpPointVtr.size() > conCount){
targetPointVtr = QVector<QPointF>(tmpPointVtr.end() - conCount, tmpPointVtr.end()); targetPointVtr = QVector<QPointF>(tmpPointVtr.end() - conCount, tmpPointVtr.end());
}else{ }else{
targetPointVtr = tmpPointVtr; targetPointVtr = tmpPointVtr;
} }
} }
} }
@ -1151,3 +1167,89 @@ std::pair<bool, Global::ExperimentData> PointCalculate::calculateMedianOIT(){
double PointCalculate::calculateDistance(const QPointF& p1, const QPointF& p2) { double PointCalculate::calculateDistance(const QPointF& p1, const QPointF& p2) {
return std::sqrt(std::pow(p2.x() - p1.x(), 2) + std::pow(p2.y() - p1.y(), 2)); return std::sqrt(std::pow(p2.x() - p1.x(), 2) + std::pow(p2.y() - p1.y(), 2));
} }
QVector<Global::ExperimentData> PointCalculate::getDataInXRangeByTime(const float x1, const float x2)
{
QVector<Global::ExperimentData> targetVtr;
for(const Global::ExperimentData &ed : _dataVtr) {
if(x1 < ed.runTime && ed.runTime < x2){
targetVtr.push_back(ed);
}else if (ed.runTime > x2){
break;
}
}
return targetVtr;
}
QVector<QPointF> PointCalculate::getPeakPointGroupByTime(const double x1, const double x2)
{
// modify select point.
ExperimentData edX1 = getClosestDataByTime(x1);
ExperimentData edX2 = getClosestDataByTime(x2);
_leftSelectedPoint = QPointF(edX1.runTime,edX1.dsc);
_rightSelectedPoint = QPointF(edX2.runTime,edX2.dsc);
// 焓值计算还得用样品温度作为x值。
QVector<QPointF> pointVtr;
for(Global::ExperimentData& ed:_dataVtr) {
if(ed.sampleTemp >= edX1.sampleTemp &&
ed.sampleTemp <= edX2.sampleTemp){
pointVtr.push_back(QPointF(ed.sampleTemp,ed.dsc));
}
}
return pointVtr;
}
QPair<QPointF, QPointF> PointCalculate::getSelectedPoints()
{
return qMakePair<QPointF,QPointF>(_leftSelectedPoint,_rightSelectedPoint);
}
QPointF PointCalculate::getPeakPointByTime()
{
int n = _dataVtr.size();
if (n < 3) {
return QPointF(); // 至少需要三个点才能找到波峰
}
QPointF uniquePeak;
float maxDiff = -std::numeric_limits<float>::infinity();
for (int i = 0; i < n; ++i) {
const float currentX = _dataVtr.at(i).runTime;
const float currentY = _dataVtr.at(i).dsc;
if (currentX < _leftSelectedPoint.x()) {
continue;
}
if (currentX > _rightSelectedPoint.x()) {
break;
}
// 计算当前点与左选择点 y 值的差值
float diffLeft = std::abs(currentY - _leftSelectedPoint.y());
// 计算当前点与右选择点 y 值的差值
float diffRight = std::abs(currentY - _rightSelectedPoint.y());
// 取两个差值中的较大值
float currentDiff = std::max(diffLeft, diffRight);
if (currentDiff > maxDiff) {
maxDiff = currentDiff;
uniquePeak = QPointF(currentX, currentY);
}
}
_peakPoint = uniquePeak;
// logde<<"peakPoint:"<<_peakPoint.x()<<","<<_peakPoint.y();
return uniquePeak;
}

View File

@ -19,6 +19,8 @@ QPair<float,float> getMinAndMaxOfDSC();
QPair<float,float> getMinAndMaxOfAxis(const float min,const float max); QPair<float,float> getMinAndMaxOfAxis(const float min,const float max);
QVector<Global::ExperimentData> getDataInXRange(const float, const float); QVector<Global::ExperimentData> getDataInXRange(const float, const float);
QVector<Global::ExperimentData> getDataInXRangeByTime(const float, const float);
QVector<QPointF> getPointVtrInXRange(const float, const float); QVector<QPointF> getPointVtrInXRange(const float, const float);
void setRegionPointX(const float,const float); void setRegionPointX(const float,const float);
@ -31,8 +33,11 @@ QVector<QPointF> getNearbyPointGroupByX(const float);
QPointF getClosestPointByY(const double left,const double right,const double valueY); QPointF getClosestPointByY(const double left,const double right,const double valueY);
QPointF getPeakPoint(); QPointF getPeakPoint();
QPointF getPeakPointByTime();
QPair<float, float> getMaxMinValue(); QPair<float, float> getMaxMinValue();
QPair<QPointF,QPointF> getSelectedPoints();
// According to the value of plot x axis witch of temperature value. // According to the value of plot x axis witch of temperature value.
QPair<float, float> getTheMaximumAndMinimumValuesOfTime( QPair<float, float> getTheMaximumAndMinimumValuesOfTime(
const double min,const double max); const double min,const double max);
@ -42,7 +47,7 @@ QPair<ExperimentData,ExperimentData> calculateStartAndEndData();
QPair<QPointF,QPointF> calculateOITStartAndEndDataByTime(const double x1,const double x2); QPair<QPointF,QPointF> calculateOITStartAndEndDataByTime(const double x1,const double x2);
float calculateArea(); float calculateArea(const double x1,const double x2);
double obtainTimeValueBasedOnTemperatureValue(const double sampleTemp); double obtainTimeValueBasedOnTemperatureValue(const double sampleTemp);
ExperimentData findOnSetDataByTemperature(const double x1,const double x2); ExperimentData findOnSetDataByTemperature(const double x1,const double x2);
@ -102,6 +107,8 @@ QPair<Global::ExperimentData,Global::ExperimentData> calculateMaxDiffDataByTime(
QPointF calculateIntersection(const QPointF p1,const QPointF p2, QPointF calculateIntersection(const QPointF p1,const QPointF p2,
const QPointF p3, const QPointF p4); const QPointF p3, const QPointF p4);
QVector<QPointF> getPeakPointGroup(); QVector<QPointF> getPeakPointGroup();
QVector<QPointF> getPeakPointGroupByTime(const double,const double);
std::vector<float> movingAverage(const std::vector<float>& data, int windowSize); std::vector<float> movingAverage(const std::vector<float>& data, int windowSize);
QVector<QPointF> movingAveragePoint(const QVector<QPointF>& data, int windowSize); QVector<QPointF> movingAveragePoint(const QVector<QPointF>& data, int windowSize);

View File

@ -2,7 +2,7 @@
ENABLED = true ENABLED = true
TO_FILE = true TO_FILE = true
TO_STANDARD_OUTPUT = true TO_STANDARD_OUTPUT = true
FORMAT = "[%datetime] %msg" FORMAT = "[%datetime] [%func] %msg"
FILENAME = "log-sdk/%datetime{%Y%M%d}.log" FILENAME = "log-sdk/%datetime{%Y%M%d}.log"
MILLISECONDS_WIDTH = 3 MILLISECONDS_WIDTH = 3
PERFORMANCE_TRACKING = false PERFORMANCE_TRACKING = false

View File

@ -15,7 +15,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
// system("chcp 65001"); // system("chcp 65001");
QTextCodec *codec = QTextCodec::codecForName("UTF-8"); QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForLocale(codec); QTextCodec::setCodecForLocale(codec);
@ -24,24 +24,8 @@ int main(int argc, char *argv[])
// //
ConfigHandler::reader(); ConfigHandler::reader();
#if 0 // 启用高DPI支持
logde<<"config,instrument coefficient:" QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
<<ConfigHandler::_configMap.value(ConInstrumentCoefficientStr).toFloat();
logde<<"config,default coefficient:"
<<ConfigHandler::ConDefaultMap.value(ConInstrumentCoefficientStr).toFloat();
#endif
#if 0
ConfigHandler::_configMap[ConInstrumentCoefficientStr] = 2.001f;
ConfigHandler::writer(false);
ConfigHandler::reader();
logde<<"config,instrument coefficient:"
<<ConfigHandler::_configMap[ConInstrumentCoefficientStr].toFloat();
#endif
//
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // 启用高DPI缩放 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // 启用高DPI缩放
QApplication a(argc, argv); QApplication a(argc, argv);
@ -54,12 +38,9 @@ int main(int argc, char *argv[])
a.setWindowIcon(icon); a.setWindowIcon(icon);
// a.setWindowIcon(QIcon(":/images/logo.png"));
#if 1 #if 1
MainWindow w; MainWindow w;
w.setWindowTitle("DSC Analysis Tool"); w.setWindowTitle("DSC Analysis Tool");
// w.setWindowIcon(QIcon(":/images/logo.png"));
w.setWindowIcon(icon); w.setWindowIcon(icon);
w.show(); w.show();
#endif #endif

View File

@ -320,50 +320,8 @@ bool MainWindow::saveFile(const QString fileName,const Global::Mode mode,
void MainWindow::smoothness(const int level) void MainWindow::smoothness(const int level)
{ {
#if 0 logde<<"smoothness...";
Global::_smoothnessFlag = true; slotUpdateStatusbarMsg("数据平滑计算中...");
// process data.
QVector<Global::ExperimentData> smoothDataVtr;
QString objectName;
QCPCurve ** curvePtrPtr;
// 当前数据为实验数据时,需要把所有的当前实验数据都尽心平滑处理。
if(!Global::_curveExperimentDataVtr.empty()){
for(auto & item:Global::_curveExperimentDataVtr){
if(_centralWidget->isCurrentCurve(item.curve)){
smoothDataVtr = smoothnessDetail(level,item.dataVtr);
item.smoothDataVtr = smoothDataVtr;
objectName = Global::ObjectNameExperiemnt;
curvePtrPtr = &item.curve;
}
}
}else{
for(Global::CurveFileData &cfd :Global::_curveFileDataVtr){
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
if(_centralWidget->isCurrentCurve(pti.curve)){
smoothDataVtr = smoothnessDetail(level,pti.dataVtr);
pti.smoothDataVtr = smoothDataVtr;
objectName = cfd.fileName;
curvePtrPtr = &pti.curve;
}
}
}
}
//
_centralWidget->deleteCurrentCurve();
//
QString wholeObjectName = Global::ObjectNameSmooth + Global::Separator + objectName;
_centralWidget->addCurveData(smoothDataVtr,wholeObjectName);
*curvePtrPtr = _centralWidget->getCurrentCurve();
#endif
if(!Global::_curveExperimentDataVtr.empty()){ if(!Global::_curveExperimentDataVtr.empty()){
// 当前数据为实验数据时,需要把所有的当前实验数据都进行平滑处理。 // 当前数据为实验数据时,需要把所有的当前实验数据都进行平滑处理。
@ -373,7 +331,8 @@ void MainWindow::smoothness(const int level)
// 添加所有平滑后的curve. // 添加所有平滑后的curve.
for(auto & item:Global::_curveExperimentDataVtr){ for(auto & item:Global::_curveExperimentDataVtr){
item.smoothDataVtr = smoothnessDetail(level,item.dataVtr); item.smoothDataVtr = smoothnessDetail(level,item.dataVtr);
item.curve = _centralWidget->addCurveData(item.smoothDataVtr,Global::ObjectNameExperiemnt); item.curve = _centralWidget->addCurveData(item.smoothDataVtr,
Global::ObjectNameExperiemnt);
} }
}else{ }else{
// 当前数据为文件分析数据时,需要把当前文件下的所有数据都进行平滑处理。 // 当前数据为文件分析数据时,需要把当前文件下的所有数据都进行平滑处理。
@ -412,12 +371,28 @@ QVector<Global::ExperimentData> MainWindow::smoothnessDetail(const int level,con
y.push_back(ed.dsc); y.push_back(ed.dsc);
} }
slotUpdateStatusbarMsg("数据平滑计算中...");
QVector<Global::ExperimentData> resultVtr;
logde<<"smooth start..."; logde<<"smooth start...";
logde<<"x,y size:"<<x.size()<<","<<y.size();
ui->statusbar->showMessage("数据平滑计算中...");
ui->statusbar->showMessage("数据平滑计算中...");
ui->statusbar->showMessage("数据平滑计算中...");
ui->statusbar->showMessage("数据平滑计算中...");
std::vector<double> yest = Lowess::smooth(x, y, config); std::vector<double> yest = Lowess::smooth(x, y, config);
if(yest.empty()){
slotUpdateStatusbarMsg("数据平滑完成.");
return resultVtr;
}
slotUpdateStatusbarMsg("数据平滑完成.");
logde<<"smooth end..."; logde<<"smooth end...";
// result data vector. // result data vector.
QVector<Global::ExperimentData> resultVtr;
for(int i = 0; i < x.size();i++){ for(int i = 0; i < x.size();i++){
Global::ExperimentData ed; Global::ExperimentData ed;
@ -610,6 +585,8 @@ void MainWindow::on_actionPeakSynthesisAnalysis_triggered()
void MainWindow::on_actionClearAllData_triggered() void MainWindow::on_actionClearAllData_triggered()
{ {
slotUpdateStatusbarMsg("");
_rightWidget->hide(); _rightWidget->hide();
_centralWidget->clearAllData(); _centralWidget->clearAllData();
} }

View File

@ -92,12 +92,6 @@
<addaction name="menu_9"/> <addaction name="menu_9"/>
<addaction name="actionOriginalData"/> <addaction name="actionOriginalData"/>
</widget> </widget>
<widget class="QMenu" name="menu_6">
<property name="title">
<string>语言</string>
</property>
<addaction name="actionLanguage"/>
</widget>
<widget class="QMenu" name="menu_7"> <widget class="QMenu" name="menu_7">
<property name="title"> <property name="title">
<string>帮助</string> <string>帮助</string>
@ -116,7 +110,6 @@
<addaction name="menu_8"/> <addaction name="menu_8"/>
<addaction name="menu_4"/> <addaction name="menu_4"/>
<addaction name="menu_5"/> <addaction name="menu_5"/>
<addaction name="menu_6"/>
<addaction name="menu_7"/> <addaction name="menu_7"/>
</widget> </widget>
<widget class="QStatusBar" name="statusbar"/> <widget class="QStatusBar" name="statusbar"/>

View File

@ -140,6 +140,9 @@ void CentralWidget::deleteAllExperimentCurve()
QCPCurve* CentralWidget::addCurveData( QCPCurve* CentralWidget::addCurveData(
const QVector<ExperimentData> &dataVtr,const QString objectName) const QVector<ExperimentData> &dataVtr,const QString objectName)
{ {
logde<<"addCurveData...";
logde<<"data vtr size:"<<dataVtr.size();
PointCalculate::setAnalysisData(dataVtr); PointCalculate::setAnalysisData(dataVtr);
// Load data. // Load data.
@ -160,6 +163,7 @@ QCPCurve* CentralWidget::addCurveData(
_currentCurve->setData(tVtr, xVtr, yVtr); _currentCurve->setData(tVtr, xVtr, yVtr);
_currentCurve->setSelectable(QCP::stWhole); // 设置曲线可选 _currentCurve->setSelectable(QCP::stWhole); // 设置曲线可选
_currentCurve->setLineStyle(QCPCurve::lsLine); // 线性连接 _currentCurve->setLineStyle(QCPCurve::lsLine); // 线性连接
_currentCurve->setVisible(true);
_currentCurve->setObjectName(objectName); _currentCurve->setObjectName(objectName);
@ -172,6 +176,7 @@ QCPCurve* CentralWidget::addCurveData(
// Axis x is time value. // Axis x is time value.
minMaxXAxisPair = PointCalculate::getMinAndMaxOfRunTime(); minMaxXAxisPair = PointCalculate::getMinAndMaxOfRunTime();
} }
#if 1
QPair<float, float>newXAxisPair = PointCalculate::getMinAndMaxOfAxis( QPair<float, float>newXAxisPair = PointCalculate::getMinAndMaxOfAxis(
minMaxXAxisPair.first,minMaxXAxisPair.second); minMaxXAxisPair.first,minMaxXAxisPair.second);
_customPlot->xAxis->setRange(newXAxisPair.first, newXAxisPair.second); _customPlot->xAxis->setRange(newXAxisPair.first, newXAxisPair.second);
@ -181,6 +186,7 @@ QCPCurve* CentralWidget::addCurveData(
minMaxYAxisPair.first,minMaxYAxisPair.second); minMaxYAxisPair.first,minMaxYAxisPair.second);
_customPlot->yAxis->setRange(newYAxisPair.first , _customPlot->yAxis->setRange(newYAxisPair.first ,
newYAxisPair.second); newYAxisPair.second);
#endif
// Add analysis operation data. // Add analysis operation data.
#if 0 #if 0
@ -194,6 +200,7 @@ QCPCurve* CentralWidget::addCurveData(
// Refresh ui. // Refresh ui.
_customPlot->replot(); _customPlot->replot();
_customPlot->update();
return _currentCurve; return _currentCurve;
} }
@ -1140,18 +1147,6 @@ void CentralWidget::drawText(const QPointF point, const QString text,const QStri
void CentralWidget::fillGraph(const double x1, const double x2,const QString objectName) void CentralWidget::fillGraph(const double x1, const double x2,const QString objectName)
{ {
#if 0
double y1 = PointCalculate::getClosestPointByX(x1).y();
double y2 = PointCalculate::getClosestPointByX(x2).y();
QVector<double> xVtr,yVtr;
xVtr.push_back(x1);
xVtr.push_back(x2);
yVtr.push_back(y1);
yVtr.push_back(y2);
#endif
Global::ExperimentData x1Ed = PointCalculate::getClosestDataByTemperature(x1); Global::ExperimentData x1Ed = PointCalculate::getClosestDataByTemperature(x1);
Global::ExperimentData x2Ed = PointCalculate::getClosestDataByTemperature(x2); Global::ExperimentData x2Ed = PointCalculate::getClosestDataByTemperature(x2);
QVector<double> xVtr,yVtr; QVector<double> xVtr,yVtr;
@ -1169,6 +1164,10 @@ void CentralWidget::fillGraph(const double x1, const double x2,const QString obj
xVtr.push_back(x1Ed.runTime); xVtr.push_back(x1Ed.runTime);
xVtr.push_back(x2Ed.runTime); xVtr.push_back(x2Ed.runTime);
yVtr.clear();
yVtr.push_back(x1Ed.dsc);
yVtr.push_back(x2Ed.dsc);
} }
QCPGraph *mainGraph = _customPlot->addGraph(); QCPGraph *mainGraph = _customPlot->addGraph();
@ -1178,6 +1177,9 @@ void CentralWidget::fillGraph(const double x1, const double x2,const QString obj
// //
QVector<Global::ExperimentData> curveDataVtr = QVector<Global::ExperimentData> curveDataVtr =
PointCalculate::getDataInXRange(x1,x2); PointCalculate::getDataInXRange(x1,x2);
if(_axisMode == AxisMode::DoubleY){
curveDataVtr = PointCalculate::getDataInXRangeByTime(x1,x2);
}
QCPGraph *fillGraph = _customPlot->addGraph(); QCPGraph *fillGraph = _customPlot->addGraph();
QVector<double> fillX, fillY; QVector<double> fillX, fillY;
@ -1197,6 +1199,7 @@ void CentralWidget::fillGraph(const double x1, const double x2,const QString obj
fillGraph->setBrush(QBrush(Qt::green, Qt::SolidPattern)); fillGraph->setBrush(QBrush(Qt::green, Qt::SolidPattern));
fillGraph->setChannelFillGraph(mainGraph); fillGraph->setChannelFillGraph(mainGraph);
//
ItemManager::addTemporaryQCPGraph(mainGraph,objectName); ItemManager::addTemporaryQCPGraph(mainGraph,objectName);
ItemManager::addTemporaryQCPGraph(fillGraph,objectName); ItemManager::addTemporaryQCPGraph(fillGraph,objectName);
@ -1370,7 +1373,6 @@ void CentralWidget::calculateAnalysisResult(
const AnalysisMode mode,const double x1,const double x2,const QString objectName) const AnalysisMode mode,const double x1,const double x2,const QString objectName)
{ {
logde<<"calculateAnalysisResult..."; logde<<"calculateAnalysisResult...";
logde<<"x1,x2:"<<x1<<","<<x2; logde<<"x1,x2:"<<x1<<","<<x2;
switch (mode) { switch (mode) {
@ -1442,9 +1444,9 @@ void CentralWidget::calculateAnalysisResult(
} }
case AnalysisMode::PeakSynthesisAnalysis: case AnalysisMode::PeakSynthesisAnalysis:
{ {
logde<<"PeakSynthesisAnalysis...";
fillGraph(x1,x2,objectName); fillGraph(x1,x2,objectName);
return;
PointCalculate::setRegionPointX(x1,x2); PointCalculate::setRegionPointX(x1,x2);
@ -1455,19 +1457,10 @@ void CentralWidget::calculateAnalysisResult(
}else{ }else{
for(Global::CurveFileData& cfd:Global::_curveFileDataVtr){ for(Global::CurveFileData& cfd:Global::_curveFileDataVtr){
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){ for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
#if 0
if(_currentCurve && _currentCurve == pti.curve){
sampleWeight = cfd.ei.sampleWeight.toDouble();
}
#endif
if(_currentCurve){ if(_currentCurve){
if(_currentCurve == pti.curve){ if(_currentCurve == pti.curve){
sampleWeight = cfd.ei.sampleWeight.toDouble(); sampleWeight = cfd.ei.sampleWeight.toDouble();
}else{
} }
}else{
// logde<<"current curve nullptr.";
} }
} }
} }
@ -1477,13 +1470,16 @@ void CentralWidget::calculateAnalysisResult(
logde<<"sample weight set value 1,"<<sampleWeight; logde<<"sample weight set value 1,"<<sampleWeight;
sampleWeight = 1; sampleWeight = 1;
} }
logde<<"sample weight:"<<sampleWeight;
double enthalpyValue = PointCalculate::calculateArea() / sampleWeight; double enthalpyValue = PointCalculate::calculateArea(x1,x2) / sampleWeight;
logde<<"enthalpyValue:"<<enthalpyValue; logde<<"enthalpyValue:"<<enthalpyValue;
// peak // peak
QPointF peakPoint = PointCalculate::getPeakPoint(); QPointF peakPoint = PointCalculate::getPeakPoint();
if(_axisMode == AxisMode::DoubleY){
peakPoint = PointCalculate::getPeakPointByTime();
}
// start point and end point // start point and end point
QPair<QPointF, QPointF> startEndPointPair = QPair<QPointF, QPointF> startEndPointPair =
@ -1494,20 +1490,13 @@ void CentralWidget::calculateAnalysisResult(
QString str; QString str;
if(_axisMode == AxisMode::DoubleY){ if(_axisMode == AxisMode::DoubleY){
double peakPointTime = PointCalculate::obtainTimeValueBasedOnTemperatureValue(peakPoint.x()); QPair<QPointF, QPointF> selectedPointsPair = PointCalculate::getSelectedPoints();
double startPointTime = PointCalculate::obtainTimeValueBasedOnTemperatureValue(startEndPointPair.first.x());
double endPointTime = PointCalculate::obtainTimeValueBasedOnTemperatureValue(startEndPointPair.second.x());
str = PointCalculate::textFormatPeakPointWithTime( str = PointCalculate::textFormatPeakPointWithTime(
enthalpyValue, enthalpyValue,
peakPointTime, peakPoint.x(),
startPointTime, selectedPointsPair.first.x(),
endPointTime); selectedPointsPair.second.x());
Global::ExperimentData peakPointEd =
PointCalculate::getClosestDataByTemperature(peakPoint.x());
peakPoint = QPointF(peakPointEd.runTime,peakPointEd.dsc);
drawText(peakPoint,str,objectName); drawText(peakPoint,str,objectName);
} }
@ -1705,6 +1694,7 @@ void CentralWidget::setAxisMode(AxisMode mode)
} }
} }
#if 0
void CentralWidget::peakSynthesisDoubleAxisY(const double, const double,const QString objectName) void CentralWidget::peakSynthesisDoubleAxisY(const double, const double,const QString objectName)
{ {
@ -1723,12 +1713,6 @@ void CentralWidget::peakSynthesisSingleAxisY(const double x1, const double x2,co
}else{ }else{
for(Global::CurveFileData& cfd:Global::_curveFileDataVtr){ for(Global::CurveFileData& cfd:Global::_curveFileDataVtr){
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){ for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
#if 0
if(_currentCurve && _currentCurve == pti.curve){
sampleWeight = cfd.ei.sampleWeight.toDouble();
}
#endif
if(_currentCurve){ if(_currentCurve){
if(_currentCurve == pti.curve){ if(_currentCurve == pti.curve){
sampleWeight = cfd.ei.sampleWeight.toDouble(); sampleWeight = cfd.ei.sampleWeight.toDouble();
@ -1746,8 +1730,7 @@ void CentralWidget::peakSynthesisSingleAxisY(const double x1, const double x2,co
sampleWeight = 1; sampleWeight = 1;
} }
double enthalpyValue = PointCalculate::calculateArea() / sampleWeight; double enthalpyValue = PointCalculate::calculateArea(x1,x2) / sampleWeight;
logde<<"enthalpyValue:"<<enthalpyValue; logde<<"enthalpyValue:"<<enthalpyValue;
// peak // peak
@ -1801,9 +1784,12 @@ void CentralWidget::peakSynthesisSingleAxisY(const double x1, const double x2,co
drawText(peakPoint,str,objectName); drawText(peakPoint,str,objectName);
} }
} }
#endif
void CentralWidget::clearAllData() void CentralWidget::clearAllData()
{ {
_customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
Global::_mode = Global::Mode::Analysis; Global::_mode = Global::Mode::Analysis;
clearData(ClearDataMode::All); clearData(ClearDataMode::All);
} }

View File

@ -124,8 +124,10 @@ private:
void setAxisMode(Global::AxisMode mode); void setAxisMode(Global::AxisMode mode);
#if 0
void peakSynthesisDoubleAxisY(const double,const double,const QString objectName); void peakSynthesisDoubleAxisY(const double,const double,const QString objectName);
void peakSynthesisSingleAxisY(const double,const double,const QString objectName); void peakSynthesisSingleAxisY(const double,const double,const QString objectName);
#endif
private: private:
AnalysisOperationRecorder::AnalysisMode _analysisMode; AnalysisOperationRecorder::AnalysisMode _analysisMode;
LocalCustomPlot *_customPlot; LocalCustomPlot *_customPlot;

View File

@ -46,6 +46,8 @@ void PrintPreviewForm::setPixmap(const QPixmap &pixmap)
void PrintPreviewForm::slotPaintRequested(QPrinter *printer) void PrintPreviewForm::slotPaintRequested(QPrinter *printer)
{ {
const int ConTextHeight = 100;
printer->setOrientation(QPrinter::Landscape); printer->setOrientation(QPrinter::Landscape);
QPainter painter(printer); QPainter painter(printer);
@ -64,35 +66,31 @@ void PrintPreviewForm::slotPaintRequested(QPrinter *printer)
QRect pageRect = printer->pageRect(); QRect pageRect = printer->pageRect();
qDebug()<<"rect:"<<pageRect; qDebug()<<"rect:"<<pageRect;
// painter.drawText(pageRect.width()/2 - 50, 100, "Page 1"); // 居中显示
#if 1 #if 1
// 绘制矩形框 // 绘制矩形框
QRect frameRect(50, 50, pageRect.width() - 100, pageRect.height() - 100); QRect frameRect(50, 50, pageRect.width() - 100, pageRect.height() - 100);
QPen pen(Qt::black, 1); // 设置笔的宽度和颜色 QPen pen(Qt::black, 1); // 设置笔的宽度和颜色
painter.setPen(pen); painter.setPen(pen);
painter.drawRect(frameRect); painter.drawRect(frameRect);
// 在框中绘制文字
// painter.drawText(frameRect, Qt::AlignCenter, "Hello, World!");
#endif #endif
// Draw image. // Draw image.
QRect imageRect = frameRect; QRect imageRect = frameRect;
imageRect.setHeight(imageRect.height() - 200); imageRect.setHeight(imageRect.height() - ConTextHeight * 7);
// QPixmap pixmap(":/curve.png"); // 确保这个路径是正确的
if (!_pixmap.isNull()) { if (!_pixmap.isNull()) {
#if 0 QPixmap resizedPixmap =
QRect pixmapRect = pixmap.rect(); _pixmap.scaled(imageRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
pixmapRect.moveCenter(pageRect.center()); painter.drawPixmap(imageRect, resizedPixmap);
#endif
painter.drawPixmap(imageRect, _pixmap);
}else{ }else{
qDebug()<<" file not exist"; logde<<"piamap is null.";
return;
} }
// File info. // file info
QRect fileInfoRect(frameRect.x(),frameRect.y() + imageRect.height(), QRect fileInfoRect(frameRect.x(),
frameRect.width(),30); frameRect.y() + imageRect.height(),
frameRect.width(),
ConTextHeight);
painter.drawRect(fileInfoRect); painter.drawRect(fileInfoRect);
QString fileName = Global::getFileName(Global::_curveFileDataVtr.first().filePath); QString fileName = Global::getFileName(Global::_curveFileDataVtr.first().filePath);
@ -102,11 +100,23 @@ void PrintPreviewForm::slotPaintRequested(QPrinter *printer)
// Experiment info. // Experiment info.
// Only print the first experiment data. // Only print the first experiment data.
QRect experimentRect(frameRect.x(),fileInfoRect.y() + fileInfoRect.height(), #if 0
400,frameRect.height() - imageRect.height() - fileInfoRect.height()); QRect experimentRect(frameRect.x(),
fileInfoRect.y() + fileInfoRect.height(),
1000,
frameRect.height() - imageRect.height() - fileInfoRect.height());
#endif
QRect experimentRect(frameRect.x(),
fileInfoRect.y() + fileInfoRect.height(),
2000,
ConTextHeight * 6);
painter.drawRect(experimentRect); painter.drawRect(experimentRect);
Global::ExperimentInfo & exInfo = Global::_curveFileDataVtr.first().ei; Global::ExperimentInfo exInfo = Global::_curveFileDataVtr.first().ei;
if(Global::_curveFileDataVtr.empty()){
exInfo = Global::_experimentInfo;
}
QString experimentInfoStr = QString(" 样品名称:%1 \n" QString experimentInfoStr = QString(" 样品名称:%1 \n"
" 样品重量:%2 mg\n" " 样品重量:%2 mg\n"
@ -117,11 +127,13 @@ void PrintPreviewForm::slotPaintRequested(QPrinter *printer)
.arg(exInfo.sampleWeight) .arg(exInfo.sampleWeight)
.arg(exInfo.date) .arg(exInfo.date)
.arg(exInfo.experimentor); .arg(exInfo.experimentor);
painter.drawText(experimentRect, Qt::AlignLeft|Qt::AlignVCenter, experimentInfoStr); painter.drawText(experimentRect, Qt::AlignLeft|Qt::AlignTop, experimentInfoStr);
// Phase info. // Phase info.
QRect phaseInfoRect(experimentRect.x() + experimentRect.width(),experimentRect.y(), QRect phaseInfoRect(experimentRect.x() + experimentRect.width()
frameRect.width() - experimentRect.width(),experimentRect.height()); ,experimentRect.y(),
frameRect.width() - experimentRect.width(),
experimentRect.height());
QVector<Global::PhaseTotalInfo>& phaseTotalVtr QVector<Global::PhaseTotalInfo>& phaseTotalVtr
= Global::_curveFileDataVtr.first().phaseTotalVtr; = Global::_curveFileDataVtr.first().phaseTotalVtr;
@ -168,7 +180,7 @@ void PrintPreviewForm::slotPaintRequested(QPrinter *printer)
} }
painter.drawText(phaseInfoRect, Qt::AlignLeft|Qt::AlignVCenter, phaseInfoStr); painter.drawText(phaseInfoRect, Qt::AlignLeft|Qt::AlignTop, phaseInfoStr);
} }