2025-06-27T15:34:56
This commit is contained in:
parent
ca1186c9b1
commit
330b4a3195
@ -1,6 +1,8 @@
|
||||
#include "lowesssmoother.h"
|
||||
#include <numeric>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace Lowess {
|
||||
|
||||
void validateConfig(const Config& config) {
|
||||
@ -54,10 +56,14 @@ std::vector<double> smooth(
|
||||
validateConfig(config);
|
||||
|
||||
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) {
|
||||
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();
|
||||
|
@ -72,7 +72,7 @@ QPointF PointCalculate::getPeakPoint(){
|
||||
|
||||
_peakPoint = uniquePeak;
|
||||
|
||||
logde<<"peakPoint:"<<_peakPoint.x()<<","<<_peakPoint.y();
|
||||
// logde<<"peakPoint:"<<_peakPoint.x()<<","<<_peakPoint.y();
|
||||
|
||||
return uniquePeak;
|
||||
}
|
||||
@ -181,21 +181,21 @@ QPointF PointCalculate::findClosestPointByX(float x) {
|
||||
|
||||
void PointCalculate::setRegionPointX(const float left, const float right)
|
||||
{
|
||||
logde<<"dataVtr size:"<<_dataVtr.size();
|
||||
logde<<"select point param left,right:"<<left<<","<<right;
|
||||
// logde<<"dataVtr size:"<<_dataVtr.size();
|
||||
// logde<<"select point param left,right:"<<left<<","<<right;
|
||||
|
||||
_leftSelectedPoint = getClosestPointByX(left);
|
||||
_rightSelectedPoint = getClosestPointByX(right);
|
||||
|
||||
_peakPoint = getPeakPoint();
|
||||
|
||||
logde<<"peak point:"<<_peakPoint.x()<<","<<_peakPoint.y();
|
||||
// logde<<"peak point:"<<_peakPoint.x()<<","<<_peakPoint.y();
|
||||
|
||||
//根据峰谷重置选择点。
|
||||
updateStartEndPoint();
|
||||
|
||||
logde<<"select point left:"<<_leftSelectedPoint.x()<<","<<_leftSelectedPoint.y();
|
||||
logde<<"select point right:"<<_rightSelectedPoint.x()<<","<<_rightSelectedPoint.y();
|
||||
// logde<<"select point left:"<<_leftSelectedPoint.x()<<","<<_leftSelectedPoint.y();
|
||||
// logde<<"select point right:"<<_rightSelectedPoint.x()<<","<<_rightSelectedPoint.y();
|
||||
}
|
||||
|
||||
QVector<QPointF> PointCalculate::getPeakPointGroup()
|
||||
@ -211,9 +211,14 @@ QVector<QPointF> PointCalculate::getPeakPointGroup()
|
||||
return pointVtr;
|
||||
}
|
||||
|
||||
float PointCalculate::calculateArea() {
|
||||
float PointCalculate::calculateArea(const double x1,const double x2) {
|
||||
//getPoint group
|
||||
QVector<QPointF> points = getPeakPointGroup();
|
||||
#if 1
|
||||
if(_axisMode == AxisMode::DoubleY){
|
||||
points = getPeakPointGroupByTime(x1,x2);
|
||||
}
|
||||
#endif
|
||||
logde<<"points size:"<<points.size();
|
||||
|
||||
//calculate Area
|
||||
@ -225,9 +230,20 @@ float PointCalculate::calculateArea() {
|
||||
}
|
||||
|
||||
//find a line.
|
||||
float k = (_leftSelectedPoint.y() - _rightSelectedPoint.y()) /
|
||||
(_leftSelectedPoint.x() - _rightSelectedPoint.x());
|
||||
float b = _leftSelectedPoint.y() - k * _leftSelectedPoint.x();
|
||||
QPointF leftSelectedPoint = _leftSelectedPoint;
|
||||
QPointF rightSelectedPoint = _rightSelectedPoint;
|
||||
|
||||
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) {
|
||||
#if 1
|
||||
@ -622,7 +638,7 @@ QVector<QPointF> PointCalculate::getNearbyPointGroupByX(const float targetX)
|
||||
if(tmpPointVtr.size() > conCount){
|
||||
targetPointVtr = QVector<QPointF>(tmpPointVtr.end() - conCount, tmpPointVtr.end());
|
||||
}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) {
|
||||
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;
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ QPair<float,float> getMinAndMaxOfDSC();
|
||||
QPair<float,float> getMinAndMaxOfAxis(const float min,const float max);
|
||||
|
||||
QVector<Global::ExperimentData> getDataInXRange(const float, const float);
|
||||
QVector<Global::ExperimentData> getDataInXRangeByTime(const float, const float);
|
||||
|
||||
QVector<QPointF> getPointVtrInXRange(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 getPeakPoint();
|
||||
QPointF getPeakPointByTime();
|
||||
QPair<float, float> getMaxMinValue();
|
||||
|
||||
QPair<QPointF,QPointF> getSelectedPoints();
|
||||
|
||||
// According to the value of plot x axis witch of temperature value.
|
||||
QPair<float, float> getTheMaximumAndMinimumValuesOfTime(
|
||||
const double min,const double max);
|
||||
@ -42,7 +47,7 @@ QPair<ExperimentData,ExperimentData> calculateStartAndEndData();
|
||||
|
||||
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);
|
||||
|
||||
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,
|
||||
const QPointF p3, const QPointF p4);
|
||||
QVector<QPointF> getPeakPointGroup();
|
||||
QVector<QPointF> getPeakPointGroupByTime(const double,const double);
|
||||
|
||||
std::vector<float> movingAverage(const std::vector<float>& data, int windowSize);
|
||||
QVector<QPointF> movingAveragePoint(const QVector<QPointF>& data, int windowSize);
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
ENABLED = true
|
||||
TO_FILE = true
|
||||
TO_STANDARD_OUTPUT = true
|
||||
FORMAT = "[%datetime] %msg"
|
||||
FORMAT = "[%datetime] [%func] %msg"
|
||||
FILENAME = "log-sdk/%datetime{%Y%M%d}.log"
|
||||
MILLISECONDS_WIDTH = 3
|
||||
PERFORMANCE_TRACKING = false
|
||||
|
25
src/main.cpp
25
src/main.cpp
@ -15,7 +15,7 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// system("chcp 65001");
|
||||
// system("chcp 65001");
|
||||
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
|
||||
QTextCodec::setCodecForLocale(codec);
|
||||
|
||||
@ -24,24 +24,8 @@ int main(int argc, char *argv[])
|
||||
//
|
||||
ConfigHandler::reader();
|
||||
|
||||
#if 0
|
||||
logde<<"config,instrument coefficient:"
|
||||
<<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
|
||||
|
||||
//
|
||||
// 启用高DPI支持
|
||||
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // 启用高DPI缩放
|
||||
QApplication a(argc, argv);
|
||||
|
||||
@ -54,12 +38,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
a.setWindowIcon(icon);
|
||||
|
||||
// a.setWindowIcon(QIcon(":/images/logo.png"));
|
||||
|
||||
#if 1
|
||||
MainWindow w;
|
||||
w.setWindowTitle("DSC Analysis Tool");
|
||||
// w.setWindowIcon(QIcon(":/images/logo.png"));
|
||||
w.setWindowIcon(icon);
|
||||
w.show();
|
||||
#endif
|
||||
|
@ -320,50 +320,8 @@ bool MainWindow::saveFile(const QString fileName,const Global::Mode mode,
|
||||
|
||||
void MainWindow::smoothness(const int level)
|
||||
{
|
||||
#if 0
|
||||
Global::_smoothnessFlag = true;
|
||||
|
||||
// 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
|
||||
logde<<"smoothness...";
|
||||
slotUpdateStatusbarMsg("数据平滑计算中...");
|
||||
|
||||
if(!Global::_curveExperimentDataVtr.empty()){
|
||||
// 当前数据为实验数据时,需要把所有的当前实验数据都进行平滑处理。
|
||||
@ -373,7 +331,8 @@ void MainWindow::smoothness(const int level)
|
||||
// 添加所有平滑后的curve.
|
||||
for(auto & item:Global::_curveExperimentDataVtr){
|
||||
item.smoothDataVtr = smoothnessDetail(level,item.dataVtr);
|
||||
item.curve = _centralWidget->addCurveData(item.smoothDataVtr,Global::ObjectNameExperiemnt);
|
||||
item.curve = _centralWidget->addCurveData(item.smoothDataVtr,
|
||||
Global::ObjectNameExperiemnt);
|
||||
}
|
||||
}else{
|
||||
// 当前数据为文件分析数据时,需要把当前文件下的所有数据都进行平滑处理。
|
||||
@ -412,12 +371,28 @@ QVector<Global::ExperimentData> MainWindow::smoothnessDetail(const int level,con
|
||||
y.push_back(ed.dsc);
|
||||
}
|
||||
|
||||
slotUpdateStatusbarMsg("数据平滑计算中...");
|
||||
|
||||
QVector<Global::ExperimentData> resultVtr;
|
||||
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);
|
||||
if(yest.empty()){
|
||||
slotUpdateStatusbarMsg("数据平滑完成.");
|
||||
return resultVtr;
|
||||
}
|
||||
|
||||
slotUpdateStatusbarMsg("数据平滑完成.");
|
||||
|
||||
logde<<"smooth end...";
|
||||
|
||||
// result data vector.
|
||||
QVector<Global::ExperimentData> resultVtr;
|
||||
|
||||
for(int i = 0; i < x.size();i++){
|
||||
Global::ExperimentData ed;
|
||||
@ -610,6 +585,8 @@ void MainWindow::on_actionPeakSynthesisAnalysis_triggered()
|
||||
|
||||
void MainWindow::on_actionClearAllData_triggered()
|
||||
{
|
||||
slotUpdateStatusbarMsg("");
|
||||
|
||||
_rightWidget->hide();
|
||||
_centralWidget->clearAllData();
|
||||
}
|
||||
|
@ -92,12 +92,6 @@
|
||||
<addaction name="menu_9"/>
|
||||
<addaction name="actionOriginalData"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_6">
|
||||
<property name="title">
|
||||
<string>语言</string>
|
||||
</property>
|
||||
<addaction name="actionLanguage"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_7">
|
||||
<property name="title">
|
||||
<string>帮助</string>
|
||||
@ -116,7 +110,6 @@
|
||||
<addaction name="menu_8"/>
|
||||
<addaction name="menu_4"/>
|
||||
<addaction name="menu_5"/>
|
||||
<addaction name="menu_6"/>
|
||||
<addaction name="menu_7"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
|
@ -140,6 +140,9 @@ void CentralWidget::deleteAllExperimentCurve()
|
||||
QCPCurve* CentralWidget::addCurveData(
|
||||
const QVector<ExperimentData> &dataVtr,const QString objectName)
|
||||
{
|
||||
logde<<"addCurveData...";
|
||||
logde<<"data vtr size:"<<dataVtr.size();
|
||||
|
||||
PointCalculate::setAnalysisData(dataVtr);
|
||||
|
||||
// Load data.
|
||||
@ -160,6 +163,7 @@ QCPCurve* CentralWidget::addCurveData(
|
||||
_currentCurve->setData(tVtr, xVtr, yVtr);
|
||||
_currentCurve->setSelectable(QCP::stWhole); // 设置曲线可选
|
||||
_currentCurve->setLineStyle(QCPCurve::lsLine); // 线性连接
|
||||
_currentCurve->setVisible(true);
|
||||
|
||||
_currentCurve->setObjectName(objectName);
|
||||
|
||||
@ -172,6 +176,7 @@ QCPCurve* CentralWidget::addCurveData(
|
||||
// Axis x is time value.
|
||||
minMaxXAxisPair = PointCalculate::getMinAndMaxOfRunTime();
|
||||
}
|
||||
#if 1
|
||||
QPair<float, float>newXAxisPair = PointCalculate::getMinAndMaxOfAxis(
|
||||
minMaxXAxisPair.first,minMaxXAxisPair.second);
|
||||
_customPlot->xAxis->setRange(newXAxisPair.first, newXAxisPair.second);
|
||||
@ -181,6 +186,7 @@ QCPCurve* CentralWidget::addCurveData(
|
||||
minMaxYAxisPair.first,minMaxYAxisPair.second);
|
||||
_customPlot->yAxis->setRange(newYAxisPair.first ,
|
||||
newYAxisPair.second);
|
||||
#endif
|
||||
|
||||
// Add analysis operation data.
|
||||
#if 0
|
||||
@ -194,6 +200,7 @@ QCPCurve* CentralWidget::addCurveData(
|
||||
|
||||
// Refresh ui.
|
||||
_customPlot->replot();
|
||||
_customPlot->update();
|
||||
|
||||
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)
|
||||
{
|
||||
#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 x2Ed = PointCalculate::getClosestDataByTemperature(x2);
|
||||
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(x2Ed.runTime);
|
||||
|
||||
yVtr.clear();
|
||||
yVtr.push_back(x1Ed.dsc);
|
||||
yVtr.push_back(x2Ed.dsc);
|
||||
}
|
||||
|
||||
QCPGraph *mainGraph = _customPlot->addGraph();
|
||||
@ -1178,6 +1177,9 @@ void CentralWidget::fillGraph(const double x1, const double x2,const QString obj
|
||||
//
|
||||
QVector<Global::ExperimentData> curveDataVtr =
|
||||
PointCalculate::getDataInXRange(x1,x2);
|
||||
if(_axisMode == AxisMode::DoubleY){
|
||||
curveDataVtr = PointCalculate::getDataInXRangeByTime(x1,x2);
|
||||
}
|
||||
|
||||
QCPGraph *fillGraph = _customPlot->addGraph();
|
||||
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->setChannelFillGraph(mainGraph);
|
||||
|
||||
//
|
||||
ItemManager::addTemporaryQCPGraph(mainGraph,objectName);
|
||||
ItemManager::addTemporaryQCPGraph(fillGraph,objectName);
|
||||
|
||||
@ -1370,7 +1373,6 @@ void CentralWidget::calculateAnalysisResult(
|
||||
const AnalysisMode mode,const double x1,const double x2,const QString objectName)
|
||||
{
|
||||
logde<<"calculateAnalysisResult...";
|
||||
|
||||
logde<<"x1,x2:"<<x1<<","<<x2;
|
||||
|
||||
switch (mode) {
|
||||
@ -1442,9 +1444,9 @@ void CentralWidget::calculateAnalysisResult(
|
||||
}
|
||||
case AnalysisMode::PeakSynthesisAnalysis:
|
||||
{
|
||||
logde<<"PeakSynthesisAnalysis...";
|
||||
|
||||
fillGraph(x1,x2,objectName);
|
||||
return;
|
||||
|
||||
PointCalculate::setRegionPointX(x1,x2);
|
||||
|
||||
@ -1455,19 +1457,10 @@ void CentralWidget::calculateAnalysisResult(
|
||||
}else{
|
||||
for(Global::CurveFileData& cfd:Global::_curveFileDataVtr){
|
||||
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
|
||||
|
||||
#if 0
|
||||
if(_currentCurve && _currentCurve == pti.curve){
|
||||
sampleWeight = cfd.ei.sampleWeight.toDouble();
|
||||
}
|
||||
#endif
|
||||
if(_currentCurve){
|
||||
if(_currentCurve == pti.curve){
|
||||
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;
|
||||
sampleWeight = 1;
|
||||
}
|
||||
logde<<"sample weight:"<<sampleWeight;
|
||||
|
||||
double enthalpyValue = PointCalculate::calculateArea() / sampleWeight;
|
||||
|
||||
double enthalpyValue = PointCalculate::calculateArea(x1,x2) / sampleWeight;
|
||||
logde<<"enthalpyValue:"<<enthalpyValue;
|
||||
|
||||
// peak
|
||||
QPointF peakPoint = PointCalculate::getPeakPoint();
|
||||
if(_axisMode == AxisMode::DoubleY){
|
||||
peakPoint = PointCalculate::getPeakPointByTime();
|
||||
}
|
||||
|
||||
// start point and end point
|
||||
QPair<QPointF, QPointF> startEndPointPair =
|
||||
@ -1494,20 +1490,13 @@ void CentralWidget::calculateAnalysisResult(
|
||||
|
||||
QString str;
|
||||
if(_axisMode == AxisMode::DoubleY){
|
||||
double peakPointTime = PointCalculate::obtainTimeValueBasedOnTemperatureValue(peakPoint.x());
|
||||
double startPointTime = PointCalculate::obtainTimeValueBasedOnTemperatureValue(startEndPointPair.first.x());
|
||||
double endPointTime = PointCalculate::obtainTimeValueBasedOnTemperatureValue(startEndPointPair.second.x());
|
||||
QPair<QPointF, QPointF> selectedPointsPair = PointCalculate::getSelectedPoints();
|
||||
|
||||
str = PointCalculate::textFormatPeakPointWithTime(
|
||||
str = PointCalculate::textFormatPeakPointWithTime(
|
||||
enthalpyValue,
|
||||
peakPointTime,
|
||||
startPointTime,
|
||||
endPointTime);
|
||||
|
||||
Global::ExperimentData peakPointEd =
|
||||
PointCalculate::getClosestDataByTemperature(peakPoint.x());
|
||||
|
||||
peakPoint = QPointF(peakPointEd.runTime,peakPointEd.dsc);
|
||||
peakPoint.x(),
|
||||
selectedPointsPair.first.x(),
|
||||
selectedPointsPair.second.x());
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@ -1723,12 +1713,6 @@ void CentralWidget::peakSynthesisSingleAxisY(const double x1, const double x2,co
|
||||
}else{
|
||||
for(Global::CurveFileData& cfd:Global::_curveFileDataVtr){
|
||||
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
|
||||
|
||||
#if 0
|
||||
if(_currentCurve && _currentCurve == pti.curve){
|
||||
sampleWeight = cfd.ei.sampleWeight.toDouble();
|
||||
}
|
||||
#endif
|
||||
if(_currentCurve){
|
||||
if(_currentCurve == pti.curve){
|
||||
sampleWeight = cfd.ei.sampleWeight.toDouble();
|
||||
@ -1746,8 +1730,7 @@ void CentralWidget::peakSynthesisSingleAxisY(const double x1, const double x2,co
|
||||
sampleWeight = 1;
|
||||
}
|
||||
|
||||
double enthalpyValue = PointCalculate::calculateArea() / sampleWeight;
|
||||
|
||||
double enthalpyValue = PointCalculate::calculateArea(x1,x2) / sampleWeight;
|
||||
logde<<"enthalpyValue:"<<enthalpyValue;
|
||||
|
||||
// peak
|
||||
@ -1801,9 +1784,12 @@ void CentralWidget::peakSynthesisSingleAxisY(const double x1, const double x2,co
|
||||
drawText(peakPoint,str,objectName);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void CentralWidget::clearAllData()
|
||||
{
|
||||
_customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
|
||||
|
||||
Global::_mode = Global::Mode::Analysis;
|
||||
clearData(ClearDataMode::All);
|
||||
}
|
||||
|
@ -124,8 +124,10 @@ private:
|
||||
|
||||
void setAxisMode(Global::AxisMode mode);
|
||||
|
||||
#if 0
|
||||
void peakSynthesisDoubleAxisY(const double,const double,const QString objectName);
|
||||
void peakSynthesisSingleAxisY(const double,const double,const QString objectName);
|
||||
#endif
|
||||
private:
|
||||
AnalysisOperationRecorder::AnalysisMode _analysisMode;
|
||||
LocalCustomPlot *_customPlot;
|
||||
|
@ -46,6 +46,8 @@ void PrintPreviewForm::setPixmap(const QPixmap &pixmap)
|
||||
|
||||
void PrintPreviewForm::slotPaintRequested(QPrinter *printer)
|
||||
{
|
||||
const int ConTextHeight = 100;
|
||||
|
||||
printer->setOrientation(QPrinter::Landscape);
|
||||
QPainter painter(printer);
|
||||
|
||||
@ -64,35 +66,31 @@ void PrintPreviewForm::slotPaintRequested(QPrinter *printer)
|
||||
QRect pageRect = printer->pageRect();
|
||||
qDebug()<<"rect:"<<pageRect;
|
||||
|
||||
// painter.drawText(pageRect.width()/2 - 50, 100, "Page 1"); // 居中显示
|
||||
|
||||
#if 1
|
||||
// 绘制矩形框
|
||||
QRect frameRect(50, 50, pageRect.width() - 100, pageRect.height() - 100);
|
||||
QPen pen(Qt::black, 1); // 设置笔的宽度和颜色
|
||||
painter.setPen(pen);
|
||||
painter.drawRect(frameRect);
|
||||
|
||||
// 在框中绘制文字
|
||||
// painter.drawText(frameRect, Qt::AlignCenter, "Hello, World!");
|
||||
#endif
|
||||
|
||||
// Draw image.
|
||||
QRect imageRect = frameRect;
|
||||
imageRect.setHeight(imageRect.height() - 200);
|
||||
// QPixmap pixmap(":/curve.png"); // 确保这个路径是正确的
|
||||
imageRect.setHeight(imageRect.height() - ConTextHeight * 7);
|
||||
|
||||
if (!_pixmap.isNull()) {
|
||||
#if 0
|
||||
QRect pixmapRect = pixmap.rect();
|
||||
pixmapRect.moveCenter(pageRect.center());
|
||||
#endif
|
||||
painter.drawPixmap(imageRect, _pixmap);
|
||||
QPixmap resizedPixmap =
|
||||
_pixmap.scaled(imageRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
painter.drawPixmap(imageRect, resizedPixmap);
|
||||
}else{
|
||||
qDebug()<<" file not exist";
|
||||
logde<<"piamap is null.";
|
||||
return;
|
||||
}
|
||||
// File info.
|
||||
QRect fileInfoRect(frameRect.x(),frameRect.y() + imageRect.height(),
|
||||
frameRect.width(),30);
|
||||
// file info
|
||||
QRect fileInfoRect(frameRect.x(),
|
||||
frameRect.y() + imageRect.height(),
|
||||
frameRect.width(),
|
||||
ConTextHeight);
|
||||
painter.drawRect(fileInfoRect);
|
||||
|
||||
QString fileName = Global::getFileName(Global::_curveFileDataVtr.first().filePath);
|
||||
@ -102,11 +100,23 @@ void PrintPreviewForm::slotPaintRequested(QPrinter *printer)
|
||||
|
||||
// Experiment info.
|
||||
// Only print the first experiment data.
|
||||
QRect experimentRect(frameRect.x(),fileInfoRect.y() + fileInfoRect.height(),
|
||||
400,frameRect.height() - imageRect.height() - fileInfoRect.height());
|
||||
#if 0
|
||||
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);
|
||||
|
||||
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"
|
||||
" 样品重量:%2 mg\n"
|
||||
@ -117,11 +127,13 @@ void PrintPreviewForm::slotPaintRequested(QPrinter *printer)
|
||||
.arg(exInfo.sampleWeight)
|
||||
.arg(exInfo.date)
|
||||
.arg(exInfo.experimentor);
|
||||
painter.drawText(experimentRect, Qt::AlignLeft|Qt::AlignVCenter, experimentInfoStr);
|
||||
painter.drawText(experimentRect, Qt::AlignLeft|Qt::AlignTop, experimentInfoStr);
|
||||
|
||||
// Phase info.
|
||||
QRect phaseInfoRect(experimentRect.x() + experimentRect.width(),experimentRect.y(),
|
||||
frameRect.width() - experimentRect.width(),experimentRect.height());
|
||||
QRect phaseInfoRect(experimentRect.x() + experimentRect.width()
|
||||
,experimentRect.y(),
|
||||
frameRect.width() - experimentRect.width(),
|
||||
experimentRect.height());
|
||||
|
||||
QVector<Global::PhaseTotalInfo>& 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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user