diff --git a/experiment_data/analysis_state/~$ana-5-new.xlsx b/experiment_data/analysis_state/~$ana-5-new.xlsx new file mode 100644 index 0000000..d4a5841 Binary files /dev/null and b/experiment_data/analysis_state/~$ana-5-new.xlsx differ diff --git a/experiment_data/analysis_state/~$ana-6-new.xlsx b/experiment_data/analysis_state/~$ana-6-new.xlsx new file mode 100644 index 0000000..d4a5841 Binary files /dev/null and b/experiment_data/analysis_state/~$ana-6-new.xlsx differ diff --git a/src/AnalysisTool.pro b/src/AnalysisTool.pro index a24145c..fef68b7 100644 --- a/src/AnalysisTool.pro +++ b/src/AnalysisTool.pro @@ -3,7 +3,7 @@ QT += core gui serialport printsupport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 -CONFIG += console +#CONFIG += console CONFIG+=precompile_header PRECOMPILED_HEADER=stable.h diff --git a/src/data/pointcalculate.cpp b/src/data/pointcalculate.cpp index f817221..29b3a31 100644 --- a/src/data/pointcalculate.cpp +++ b/src/data/pointcalculate.cpp @@ -284,6 +284,7 @@ QPair PointCalculate::calculateStartAndEndPoint() { QPair leftMaxDiffPointPair = PointCalculate::calculateMaxDiffPointLeft(); QPair rightMaxDiffPointPair = PointCalculate::calculateMaxDiffPointRight(); + #if 0 logde<<"b1:"< _dataVtr.last().sampleTemp){ + return resultData; + } +#endif + + float minDiff = std::numeric_limits::max(); + + for(Global::ExperimentData &ed:_dataVtr){ + float diff = std::abs(ed.sampleTemp - temp); + if (diff < minDiff) { + minDiff = diff; + resultData = ed; + } + } + + return resultData; +} QString PointCalculate::textFormatNumbericalLabel(const QPointF point) { @@ -466,7 +494,8 @@ QString PointCalculate::textFormatGlassTranstion(const float t1,const float tg,c return QString("T1:%1℃\n" "Tg:%2℃\n" "T2:%3℃" - ).arg(QString::number(t1, 'f', 3)) + ) + .arg(QString::number(t1, 'f', 3)) .arg(QString::number(tg, 'f', 3)) .arg(QString::number(t2, 'f', 3)); } @@ -715,6 +744,16 @@ QPair PointCalculate::getMinAndMaxOfSampleTemp() return qMakePair(sampleTempMin,sampleTempMax); } +QPair PointCalculate::calculateStartAndEndData() +{ + QPair leftAndRightPair = calculateStartAndEndPoint(); + + ExperimentData leftEd = getClosestDataByTemperature(leftAndRightPair.first.x()); + ExperimentData rightEd = getClosestDataByTemperature(leftAndRightPair.second.x()); + + return qMakePair (leftEd,rightEd); +} + QPair PointCalculate::getMinAndMaxOfRunTime() { float runTimeMax = std::numeric_limits::min(); @@ -749,4 +788,35 @@ QPair PointCalculate::getMinAndMaxOfDSC() return qMakePair(dscMin,dscMax); } +QString PointCalculate::textFormatNumbericalLabelWithTime(const QPointF point) +{ + return QString("数值:\n" + "%1 min,%2" + ).arg(QString::number(point.x(), 'f', 3)) + .arg(QString::number(point.y(), 'f', 3)); +} +QString PointCalculate::textFormatStartPointWithTime(const QPointF point) +{ + return QString("外推起始点:\n" + "%1 min" + ).arg(QString::number(point.x(), 'f', 3)); +} + +QString PointCalculate::textFormatEndPointWithTime(const QPointF point) +{ + return QString("外推终止点:\n" + "%1 min" + ).arg(QString::number(point.x(), 'f', 3)); +} + +QString PointCalculate::textFormatGlassTranstionWithTime(const float t1, const float tg, const float t2) +{ + return QString("T1:%1 min\n" + "Tg:%2 min\n" + "T2:%3 min" + ) + .arg(QString::number(t1, 'f', 3)) + .arg(QString::number(tg, 'f', 3)) + .arg(QString::number(t2, 'f', 3)); +} diff --git a/src/data/pointcalculate.h b/src/data/pointcalculate.h index afb1608..ab880d7 100644 --- a/src/data/pointcalculate.h +++ b/src/data/pointcalculate.h @@ -7,6 +7,8 @@ #include "global.h" namespace PointCalculate{ +using namespace Global; + void setAnalysisData(const QVector&); //QPair getStartAndEndPoint(); @@ -21,6 +23,7 @@ QVector getPointVtrInXRange(const float, const float); void setRegionPointX(const float,const float); +ExperimentData getClosestDataByTemperature(const float); QPointF getClosestPointByX(const float); QVector getNearbyPointGroupByX(const float); @@ -33,6 +36,8 @@ QPair getTheMaximumAndMinimumValuesOfTime( const double min,const double max); QPair calculateStartAndEndPoint(); +QPair calculateStartAndEndData(); + float calculateArea(); double obtainTimeValueBasedOnTemperatureValue(const double sampleTemp); @@ -45,10 +50,18 @@ QString textFormatPeakPointWithTime(const float enthalpyValue, const float peakValue, const float startPoint, const float endPoint); + QString textFormatNumbericalLabel(const QPointF); +QString textFormatNumbericalLabelWithTime(const QPointF); + QString textFormatStartPoint(const QPointF); +QString textFormatStartPointWithTime(const QPointF); + QString textFormatEndPoint(const QPointF); +QString textFormatEndPointWithTime(const QPointF); + QString textFormatGlassTranstion(const float t1,const float tg,const float t2); +QString textFormatGlassTranstionWithTime(const float t1,const float tg,const float t2); // glass transition QPair getCurveInflectionPointTangent(const float,const float); diff --git a/src/data/xlsxhandler.cpp b/src/data/xlsxhandler.cpp index 621d0ac..3a6e02a 100644 --- a/src/data/xlsxhandler.cpp +++ b/src/data/xlsxhandler.cpp @@ -79,13 +79,11 @@ int XlsxHandler::readFile(const QString filePath, Global::CurveFileData &cfd) phaseTotalVtr.push_back(phaseTotal); // print - logde<<"index:"<cellAt(startLineIndex, 2)->value().toDouble(); data.sampleTemp = workSheet->cellAt(startLineIndex, 3)->value().toDouble(); data.dsc = workSheet->cellAt(startLineIndex, 4)->value().toDouble(); + data.constantTempTime = workSheet->cellAt(startLineIndex, 5)->value().toDouble(); - phaseTotal.dataVtr.push_back(data); + if(data.runTime != 0){ + phaseTotal.dataVtr.push_back(data); + } startLineIndex++; } diff --git a/src/global.cpp b/src/global.cpp index 3c52e52..4c681b3 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -130,6 +130,10 @@ void clearExperimentData() _currentPhase = -1; } +bool isZero(double value, double epsilon) { + return std::abs(value) < epsilon; +} + } #if 0 diff --git a/src/global.h b/src/global.h index 59c6fcc..4721f19 100644 --- a/src/global.h +++ b/src/global.h @@ -115,7 +115,7 @@ extern bool _displayTimeValue; QString converDoubleToStr(const double); void quadraticLeastSquaresFit(double x[], double y[], int n, double coeff[]); double findNegativeStartPoint(double m, double b, double start, double end); - +bool isZero(double value, double epsilon = 1e-9); }; #endif // GLOBAL_H diff --git a/src/ui/centralwidget.cpp b/src/ui/centralwidget.cpp index 0a2eeb9..256e196 100644 --- a/src/ui/centralwidget.cpp +++ b/src/ui/centralwidget.cpp @@ -104,75 +104,19 @@ CentralWidget::~CentralWidget() void CentralWidget::switchAxisMode() { - if(Global::_mode != Global::Mode::Analysis){ return; } if(_axisMode == AxisMode::SingleY){ _axisMode = AxisMode::DoubleY; - - clearData(ClearDataMode::All); - -#if 0 - _customPlot->yAxis2->setVisible(true); - _customPlot->yAxis2->setLabel("Time/min"); - - for(Global::CurveFileData& cfd:Global::_curveFileDataVtr){ - for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){ - - QVector dataVtr; - QVector tVtr,xVtr, yVtr; - int index = 0; - for (Global::ExperimentData &ed : pti.dataVtr) - { - tVtr.push_back(index++); - xVtr.push_back(ed.sampleTemp); - yVtr.push_back(ed.runTime); - } - - double yMin = yVtr.first(); - double yMax = yVtr.last(); - double tick = (yMax - yMin) / 4; - - double axisMin = yMin - tick; - double axisMax = yMax + tick; - _customPlot->yAxis2->setRange(axisMin,axisMax); - - QCPCurve* curve = new QCPCurve(_customPlot->xAxis, _customPlot->yAxis2); - curve->setData(tVtr, xVtr, yVtr); - curve->setPen(QPen(QColor(Qt::red))); - curve->setObjectName(Global::CurveOfTimeTypeObjectName); - - // logde<<"plottableCount count:"<<_customPlot->plottableCount(); - } - } -#endif }else{ - logde<<"_axisMode == AxisMode::DoubleY ..."; - _axisMode = AxisMode::SingleY; - - clearData(ClearDataMode::All); - -#if 0 - _customPlot->yAxis2->setVisible(false); - - _customPlot->xAxis->setLabel(AxisTemperature); - - for (int i = _customPlot->plottableCount() - 1; i >= 0; --i) { - QCPAbstractPlottable* plottable = _customPlot->plottable(i); - if (auto curve = dynamic_cast(plottable)) { - if(curve && curve->objectName() == Global::CurveOfTimeTypeObjectName){ - _customPlot->removePlottable(curve); - } - } - } -#endif } - uiLoadXlsxFileData(); + clearData(ClearDataMode::JustUi); + uiLoadXlsxFileData(); } void CentralWidget::setAnalysisMode(const AnalysisMode mode) @@ -571,7 +515,6 @@ void CentralWidget::uiLoadXlsxFileData() PointCalculate::setAnalysisData(pti.dataVtr); - // Load data. QVector dataVtr; QVector tVtr,xVtr, yVtr; @@ -808,6 +751,21 @@ void CentralWidget::glassTransitionHandle(const double x1,const double x2,const QString str = PointCalculate::textFormatGlassTranstion(intersection1.x(), averagePoint.x(), intersection2.x()); + if(_axisMode == AxisMode::DoubleY){ + Global::ExperimentData intersection1Ed = + PointCalculate::getClosestDataByTemperature(intersection1.x()); + Global::ExperimentData averageEd = + PointCalculate::getClosestDataByTemperature(averagePoint.x()); + Global::ExperimentData intersection2Ed = + PointCalculate::getClosestDataByTemperature(intersection2.x()); + + averagePoint = QPointF(averageEd.runTime,averageEd.dsc); + + str = PointCalculate::textFormatGlassTranstionWithTime( + intersection1Ed.runTime, + averageEd.runTime, + intersection2Ed.runTime); + } drawText(averagePoint,str); @@ -988,6 +946,7 @@ 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(); @@ -997,11 +956,29 @@ void CentralWidget::fillGraph(const double x1, const double x2,const QString obj yVtr.push_back(y1); yVtr.push_back(y2); +#endif + + Global::ExperimentData x1Ed = PointCalculate::getClosestDataByTemperature(x1); + Global::ExperimentData x2Ed = PointCalculate::getClosestDataByTemperature(x2); + QVector xVtr,yVtr; + xVtr.push_back(x1Ed.sampleTemp); + xVtr.push_back(x2Ed.sampleTemp); + + yVtr.push_back(x1Ed.dsc); + yVtr.push_back(x2Ed.dsc); + + if(_axisMode == AxisMode::DoubleY){ + xVtr.clear(); + + xVtr.push_back(x1Ed.runTime); + xVtr.push_back(x2Ed.runTime); + } QCPGraph *mainGraph = _customPlot->addGraph(); mainGraph->setData(xVtr, yVtr); mainGraph->setPen(QPen(Qt::red, 1)); + // QVector curveDataVtr = PointCalculate::getDataInXRange(x1,x2); @@ -1010,7 +987,11 @@ void CentralWidget::fillGraph(const double x1, const double x2,const QString obj for(int i = 0;i < curveDataVtr.size();i++){ Global::ExperimentData &ed = curveDataVtr[i]; - fillX<setVisible(false); _currentCurve = nullptr; - + case ClearDataMode::JustUi: //ui - // Clear the data of graph. - for (int i = _customPlot->plottableCount() - 1; i >= 0; --i) { - QCPAbstractPlottable* plottable = _customPlot->plottable(i); - if (auto curve = dynamic_cast(plottable)) { - _customPlot->removePlottable(curve); - - ItemManager::removeItem(curve); - } - } - - // Clear graph on plot. - for (int i = _customPlot->graphCount() - 1; i >= 0; --i) { - QCPGraph *graph = _customPlot->graph(i); - _customPlot->removeGraph(graph); - - ItemManager::removeItem(graph); - } - - // Delete items. - QList itemsToKeep; - itemsToKeep << _line1 << _line2; - - for (int i = _customPlot->itemCount() - 1; i >= 0; --i) { - QCPAbstractItem *item = _customPlot->item(i); - if (!itemsToKeep.contains(item)) { - _customPlot->removeItem(item); - - ItemManager::removeItem(item); - } - } - // - AnalysisOperationRecorder::_analysisOperationVtr.clear(); - - }else if(mode == ClearDataMode::Undo){ + clearAllUiData(); + break; + case ClearDataMode::Undo: + { // Clear the data of graph. for (int i = _customPlot->plottableCount() - 1; i >= 0; --i) { QCPAbstractPlottable* plottable = _customPlot->plottable(i); @@ -1130,11 +1069,48 @@ void CentralWidget::clearData(const CentralWidget::ClearDataMode mode) // AnalysisOperationRecorder::removeTheLastAnalysisOperation(); + } + break; + default:break; } _customPlot->replot(); } +void CentralWidget::clearAllUiData() +{ + // Clear the data of graph. + for (int i = _customPlot->plottableCount() - 1; i >= 0; --i) { + QCPAbstractPlottable* plottable = _customPlot->plottable(i); + if (auto curve = dynamic_cast(plottable)) { + _customPlot->removePlottable(curve); + + ItemManager::removeItem(curve); + } + } + + // Clear graph on plot. + for (int i = _customPlot->graphCount() - 1; i >= 0; --i) { + QCPGraph *graph = _customPlot->graph(i); + _customPlot->removeGraph(graph); + + ItemManager::removeItem(graph); + } + + // Delete items. + QList itemsToKeep; + itemsToKeep << _line1 << _line2; + + for (int i = _customPlot->itemCount() - 1; i >= 0; --i) { + QCPAbstractItem *item = _customPlot->item(i); + if (!itemsToKeep.contains(item)) { + _customPlot->removeItem(item); + + ItemManager::removeItem(item); + } + } +} + void CentralWidget::deleteCurve(const QString objectName) { for (int i = _analysisFilePathVtr.size() - 1; i >= 0; --i) { @@ -1195,16 +1171,21 @@ void CentralWidget::loadAnalysisData( switch (mode) { case AnalysisMode::NumericalLabel: { - QPointF selectPoint = PointCalculate::getClosestPointByX(x1); + // QPointF selectPoint = PointCalculate::getClosestPointByX(x1); - // logde<<"lin1 x:"<parent(), "warnning", "曲线选择错误."); return; } + QPointF selectPoint(ed.sampleTemp,ed.dsc); QString str = PointCalculate::textFormatNumbericalLabel(selectPoint); + if(_axisMode == AxisMode::DoubleY){ + selectPoint.setX(ed.runTime); + str = PointCalculate::textFormatNumbericalLabelWithTime(selectPoint); + } drawText(selectPoint,str,objectName); @@ -1214,19 +1195,32 @@ void CentralWidget::loadAnalysisData( case AnalysisMode::StopPoint:{ PointCalculate::setRegionPointX(x1,x2); - QPair startEndPointPair = - PointCalculate::calculateStartAndEndPoint(); + // QPair startEndPointPair = + // PointCalculate::calculateStartAndEndPoint(); + + QPair + startEndDataPair = PointCalculate::calculateStartAndEndData(); + // QPointF point; QString str; - AnaOpRecorder::AnalysisOperation ao; if(mode == AnalysisMode::StartPoint){ - point = startEndPointPair.first; - str = PointCalculate::textFormatStartPoint(point); + if(_axisMode == AxisMode::SingleY){ + point = QPointF(startEndDataPair.first.sampleTemp,startEndDataPair.first.dsc); + str = PointCalculate::textFormatStartPoint(point); + }else{ + point = QPointF(startEndDataPair.first.runTime,startEndDataPair.first.dsc); + str = PointCalculate::textFormatStartPointWithTime(point); + } }else{ - point = startEndPointPair.second; - str = PointCalculate::textFormatEndPoint(point); + if(_axisMode == AxisMode::SingleY){ + point = QPointF(startEndDataPair.second.sampleTemp,startEndDataPair.second.dsc); + str = PointCalculate::textFormatEndPoint(point); + }else{ + point = QPointF(startEndDataPair.second.runTime,startEndDataPair.second.dsc); + str = PointCalculate::textFormatEndPointWithTime(point); + } } drawText(point,str,objectName); @@ -1241,7 +1235,7 @@ void CentralWidget::loadAnalysisData( PointCalculate::setRegionPointX(x1,x2); //enthalpy - double sampleWeight = 0.0f; + double sampleWeight = 1.0f; for(Global::CurveFileData& cfd:Global::_curveFileDataVtr){ for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){ @@ -1281,7 +1275,25 @@ void CentralWidget::loadAnalysisData( <toPixmap(); } - void CentralWidget::slotAxisModify(const float temp) { _customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); diff --git a/src/ui/centralwidget.h b/src/ui/centralwidget.h index 2e91dd0..5a9baed 100644 --- a/src/ui/centralwidget.h +++ b/src/ui/centralwidget.h @@ -99,6 +99,8 @@ private: JustUi }; void clearData(const ClearDataMode); + void clearAllUiData(); + void deleteCurve(const QString); void loadAnalysisData(const AnalysisMode mode,const double x1,const double x2,const QString objectName);