2025-06-16T17:25:40

This commit is contained in:
yuntang 2025-06-16 17:25:41 +08:00
parent bc9a3249c3
commit ea533c0fff
23 changed files with 147 additions and 102 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -44,7 +44,8 @@ int XlsxHandler::readFile(const QString filePath, Global::CurveFileData &cfd)
_currentFilePath = filePath;
cfd.fileName = fileInfo.fileName();
// cfd.fileName = fileInfo.fileName();
cfd.filePath = filePath;
QXlsx::Document xlsx(filePath);
@ -254,10 +255,11 @@ void XlsxHandler::writeExperimentFile(const QString filePath)
QVector<Global::ExperimentData> edVtr =
Global::_curveExperimentDataVtr.at(i).dataVtr;
if(Global::_smoothnessFlag){
if(!Global::_curveExperimentDataVtr.at(i).smoothDataVtr.empty()){
edVtr = Global::_curveExperimentDataVtr.at(i).smoothDataVtr;
}
// phase data size.
dataSizeRow = row;
xlsx.write(row , 1, ConPhaseDataSize);
@ -289,7 +291,6 @@ void XlsxHandler::writeExperimentFile(const QString filePath)
logde<<"Save xlsx failed.";
return ;
}
}
void XlsxHandler:: xlsxFileAppendAnalysisOperation(const QString filePath)
@ -313,63 +314,6 @@ void XlsxHandler:: xlsxFileAppendAnalysisOperation(const QString filePath)
writeAnalysisOperationDetail(xlsx,row);
#if 0
QVector<AnalysisOperationRecorder::AnalysisOperation>& aoVtr =
AnalysisOperationRecorder::_analysisOperationVtr;
xlsx->write(row , 1, ConAnalysisOperationCount);
xlsx->write(row , 2, aoVtr.size());
row++;
for (AnaOpRecorderOperation& ao:aoVtr){
QString analysisOpName;
switch(ao.mode){
case AnalysisMode::NumericalLabel:
{
analysisOpName = AnalysisOperationRecorder::NumericalLabelStr;
break;
}
case AnalysisMode::StartPoint:
{
analysisOpName = AnalysisOperationRecorder::StartPointStr;
break;
}
case AnalysisMode::StopPoint:
{
analysisOpName = AnalysisOperationRecorder::StopPointStr;
break;
}
case AnalysisMode::PeakSynthesisAnalysis:
{
analysisOpName = AnalysisOperationRecorder::PeakSynthesisAnalysisStr;
break;
}
case AnalysisMode::GlassTransition:
{
analysisOpName = AnalysisOperationRecorder::GlassTransitionStr;
break;
}
case AnalysisMode::OnsetTemperaturePoint:
{
analysisOpName = AnalysisOperationRecorder::OnsetTemperaturePointStr;
break;
}
case AnalysisMode::EndsetTemperaturePoint:
{
analysisOpName = AnalysisOperationRecorder::EndsetTemperaturePointStr;
break;
}
default:break;
}
xlsx->write(row , 1, analysisOpName);
xlsx->write(row , 2, ao.x1);
xlsx->write(row , 3, ao.x2);
row++;
}
#endif
// save
#if 1
if (!xlsx->saveAs(filePath)) {
@ -430,9 +374,9 @@ void XlsxHandler::readAnalysisOperation(
for(int i = 0;i < size; i++){
AnaOpRecorderOperation ao;
ao.filePath = cfd.fileName;
ao.filePath = cfd.filePath;
logde<<"cfd fileName:"<<cfd.fileName.toStdString();
logde<<"cfd filePath:"<<cfd.filePath.toStdString();
QString modeStr = sheet->cellAt(startLineIndex, 1)->value().toString();
@ -662,8 +606,11 @@ void XlsxHandler::writeSmoothnessFile(const QString filePath)
// logde<<"Global::_curveExperimentDataVtr size:"
// <<Global::_curveExperimentDataVtr.size();
const QVector<Global::ExperimentData>& edVtr =
QVector<Global::ExperimentData> edVtr =
phaseVtr.at(i).dataVtr;
if(!phaseVtr.at(i).smoothDataVtr.empty()){
edVtr = phaseVtr.at(i).smoothDataVtr;
}
// phase data size.
dataSizeRow = row;
@ -698,24 +645,21 @@ void XlsxHandler::writeSmoothnessFile(const QString filePath)
}
}
void XlsxHandler::writeAnalysisiFile(const QString filePath)
void XlsxHandler::writeXlsxFile(const QString filePath)
{
QXlsx::Document* xlsx = openXlsxFile(_currentFilePath);
if(!xlsx){
logde<<"xlsx is nullptr." ;
if(Global::_curveFileDataVtr.empty()){
logde<<"curve file data vtr empty...";
return;
}
QXlsx::Worksheet *sheet = xlsx->currentWorksheet();
if(!sheet)
{
logde << "current sheet is empty.";
return;
QVector<Global::PhaseTotalInfo>& phaseVtr =
Global::_curveFileDataVtr.first().phaseTotalVtr;
if(phaseVtr.first().smoothDataVtr.empty()){
logde<<"xlsx file data smooth vtr is empty.";
xlsxFileAppendAnalysisOperation(filePath);
}else{
logde<<"xlsx file data smooth vtr is not empty.";
writeSmoothnessFile(filePath);
}
int index = sheet->dimension().lastRow();
logde<<"lastRow:"<<index;
int row = index + 1;
writeAnalysisOperationDetail(xlsx,row);
}

View File

@ -25,11 +25,12 @@ namespace XlsxHandler {
void readAnalysisOperation(QXlsx::Worksheet*,int& startLineIndex,Global::CurveFileData&);
void writeExperimentFile(const QString filePath);
void xlsxFileAppendAnalysisOperation(const QString filePath);
void writeAnalysisiFile(const QString filePath);
void writeAnalysisOperationDetail(QXlsx::Document*doc,const int row);
void writeXlsxFile(const QString filePath);
void writeSmoothnessFile(const QString filePath);
void xlsxFileAppendAnalysisOperation(const QString filePath);
void writeAnalysisOperationDetail(QXlsx::Document*doc,const int row);
extern QString _currentFilePath;

View File

@ -142,6 +142,16 @@ bool isZero(double value, double epsilon) {
return std::abs(value) < epsilon;
}
QString getFileName(const QString filePath)
{
QFileInfo fileInfo(filePath);
// 获取文件的后缀名并转换为小写,方便比较
QString fileSuffix = fileInfo.suffix().toLower();
return fileInfo.fileName();
}
}
#if 0

View File

@ -98,7 +98,8 @@ struct PhaseTotalInfo{
};
struct CurveFileData{
QString fileName;
// QString fileName;
QString filePath;
Global::ExperimentInfo ei;
QVector<Global::PhaseTotalInfo> phaseTotalVtr;
QVector<AnalysisOperationRecorder::AnalysisOperation> analysisOperationVtr;
@ -120,7 +121,7 @@ extern int _currentPhase;
extern ExperimentInfo _experimentInfo;
extern QVector<CurveExperimentData> _curveExperimentDataVtr;
extern CurveExperimentData* _currentCurveExperimentDataPtr;
extern bool _smoothnessFlag;
//extern bool _smoothnessFlag;
#if 0
// Smoothness data
@ -147,6 +148,7 @@ 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);
QString getFileName(const QString filePath);
};
#endif // GLOBAL_H

View File

@ -276,6 +276,9 @@ bool MainWindow::saveFile(const QString fileName,const Global::Mode mode)
// 分析模式下,但是文件数据为空,说明做完实验没有保存数据。
XlsxHandler::writeExperimentFile(filePath);
}else{
// 分析模式下,存在文件数据,将文件数据写入文件。
XlsxHandler::writeXlsxFile(filePath);
#if 0
// 分析模式下,直接保存从文件读取来的数据。
if(Global::_smoothnessFlag){
XlsxHandler::writeSmoothnessFile(filePath);
@ -283,6 +286,7 @@ bool MainWindow::saveFile(const QString fileName,const Global::Mode mode)
// 直接在xlsx文件的基础上添加分析数据。
XlsxHandler::xlsxFileAppendAnalysisOperation(filePath);
}
#endif
}
}else if(mode == Global::Mode::Experiment){
XlsxHandler::writeExperimentFile(filePath);
@ -293,12 +297,15 @@ 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)){
@ -333,6 +340,33 @@ void MainWindow::smoothness(const int level)
_centralWidget->addCurveData(smoothDataVtr,wholeObjectName);
*curvePtrPtr = _centralWidget->getCurrentCurve();
#endif
if(!Global::_curveExperimentDataVtr.empty()){
// 当前数据为实验数据时,需要把所有的当前实验数据都进行平滑处理。
// 删除所有objectName为experiment的curve.
_centralWidget->deleteCurveByObjectName(Global::ObjectNameExperiemnt);
// 添加所有平滑后的curve.
for(auto & item:Global::_curveExperimentDataVtr){
item.smoothDataVtr = smoothnessDetail(level,item.dataVtr);
item.curve = _centralWidget->addCurveData(item.smoothDataVtr,Global::ObjectNameExperiemnt);
}
}else{
// 当前数据为文件分析数据时,需要把当前文件下的所有数据都进行平滑处理。
QString selectedCurveObjectName = _centralWidget->getCurrentCurve()->objectName();
_centralWidget->deleteCurveByObjectName(selectedCurveObjectName);
for(Global::CurveFileData &cfd :Global::_curveFileDataVtr){
if(selectedCurveObjectName.contains(cfd.filePath)){
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
pti.smoothDataVtr = smoothnessDetail(level,pti.dataVtr);
pti.curve = _centralWidget->addCurveData(pti.smoothDataVtr,
cfd.filePath);
}
}
}
}
}
@ -704,8 +738,32 @@ void MainWindow::on_actionSmoothness10_triggered()
void MainWindow::on_actionOriginalData_triggered()
{
Global::_smoothnessFlag = false;
if(!Global::_curveExperimentDataVtr.empty()){
// 删除所有objectName为experiment的curve.
_centralWidget->deleteCurveByObjectName(Global::ObjectNameExperiemnt);
for(auto & item:Global::_curveExperimentDataVtr){
item.smoothDataVtr.clear();
item.curve = _centralWidget->addCurveData(item.dataVtr,Global::ObjectNameExperiemnt);
}
}else{
// 当前数据为文件分析数据时,需要把当前文件下的所有数据都进行平滑处理。
QString selectedCurveObjectName = _centralWidget->getCurrentCurve()->objectName();
_centralWidget->deleteCurveByObjectName(selectedCurveObjectName);
for(Global::CurveFileData &cfd :Global::_curveFileDataVtr){
if(selectedCurveObjectName.contains(cfd.filePath)){
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
pti.smoothDataVtr.clear();
pti.curve = _centralWidget->addCurveData(pti.dataVtr,
cfd.filePath);
}
}
}
}
#if 0
// process data.
QVector<Global::ExperimentData> targetDataVtr;
QString objectName;
@ -726,16 +784,17 @@ void MainWindow::on_actionOriginalData_triggered()
if(_centralWidget->isCurrentCurve(pti.curve)){
targetDataVtr = pti.dataVtr;
objectName = cfd.fileName;
objectName = cfd.filePath;
curvePtrPtr = &pti.curve;
}
}
}
}
//
_centralWidget->deleteCurrentCurve();
_centralWidget->deleteCurveByObjectName(_centralWidget->getCurrentCurve()->objectName());
_centralWidget->addCurveData(targetDataVtr,objectName);
*curvePtrPtr = _centralWidget->getCurrentCurve();
#endif
}

View File

@ -124,12 +124,19 @@ bool CentralWidget::isCurrentCurve(QCPCurve *curve)
return _currentCurve == curve;
}
#if 0
void CentralWidget::deleteCurrentCurve()
{
slotDelCurve(_currentCurve);
}
void CentralWidget::addCurveData(
void CentralWidget::deleteAllExperimentCurve()
{
deleteCurve(Global::ObjectNameExperiemnt);
}
#endif
QCPCurve* CentralWidget::addCurveData(
const QVector<ExperimentData> &dataVtr,const QString objectName)
{
PointCalculate::setAnalysisData(dataVtr);
@ -186,6 +193,8 @@ void CentralWidget::addCurveData(
// Refresh ui.
_customPlot->replot();
return _currentCurve;
}
void CentralWidget::setAnalysisMode(const AnalysisMode mode)
@ -319,14 +328,21 @@ void CentralWidget::slotAnalysisSettingApply()
return;
}
QString selectedCurveObjectName = _currentCurve->objectName();
// Set curve data to PointCalculate.
if(Global::_curveFileDataVtr.empty()){
// Load experiment data.
logde<<"experiment vtr size:"<<Global::_curveExperimentDataVtr.size();
for(Global::CurveExperimentData& ced:Global::_curveExperimentDataVtr){
if(ced.curve == _currentCurve){
logde<<"load experiment data.";
PointCalculate::setAnalysisData(ced.dataVtr);
if(ced.smoothDataVtr.empty()){
PointCalculate::setAnalysisData(ced.dataVtr);
}else{
PointCalculate::setAnalysisData(ced.smoothDataVtr);
}
break;
}
}
@ -335,12 +351,17 @@ void CentralWidget::slotAnalysisSettingApply()
for(Global::CurveFileData& cfd:Global::_curveFileDataVtr){
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
if(pti.curve == _currentCurve){
PointCalculate::setAnalysisData(pti.dataVtr);
if(pti.smoothDataVtr.empty()){
PointCalculate::setAnalysisData(pti.dataVtr);
}else{
PointCalculate::setAnalysisData(pti.smoothDataVtr);
}
break;
}
}
}
}
#if 0
// Load smoothness data.
for(Global::CurveExperimentData& ced:Global::_curveSmoothnessDataVtr){
@ -446,7 +467,7 @@ void CentralWidget::slotDelCurve(QCPCurve *curve)
logde<<"deltel curve object name:"<<curve->objectName().toStdString();
deleteCurve(curve->objectName());
deleteCurveByObjectName(curve->objectName());
}
void CentralWidget::slotGetAxisInfo()
@ -579,7 +600,7 @@ void CentralWidget::uiLoadXlsxFileData()
_currentCurve->setSelectable(QCP::stWhole); // 设置曲线可选
_currentCurve->setLineStyle(QCPCurve::lsLine); // 线性连接
_currentCurve->setObjectName(cfd.fileName);
_currentCurve->setObjectName(cfd.filePath);
// Set axis range.
QPair<float, float> minMaxXAxisPair;
@ -607,7 +628,7 @@ void CentralWidget::uiLoadXlsxFileData()
if(cfd.analysisOperationVtr.size() > 0){
for(AnaOpRecorder::AnalysisOperation& ao
:cfd.analysisOperationVtr){
loadAnalysisData(ao.mode,ao.x1,ao.x2,cfd.fileName);
loadAnalysisData(ao.mode,ao.x1,ao.x2,cfd.filePath);
}
}
}
@ -1062,7 +1083,7 @@ void CentralWidget::clearData(const CentralWidget::ClearDataMode mode)
_currentCurve = nullptr;
Global::_smoothnessFlag = false;
// Global::_smoothnessFlag = false;
case ClearDataMode::JustUi:
//ui
clearAllUiData();
@ -1152,7 +1173,7 @@ void CentralWidget::clearAllUiData()
}
}
void CentralWidget::deleteCurve(const QString objectName)
void CentralWidget::deleteCurveByObjectName(const QString objectName)
{
for (int i = _analysisFilePathVtr.size() - 1; i >= 0; --i) {
if (_analysisFilePathVtr[i].startsWith(objectName)) {

View File

@ -41,8 +41,14 @@ public:
bool isCurrentCurve(QCPCurve* curve);
#if 0
void deleteCurrentCurve();
void addCurveData(const QVector<Global::ExperimentData> &,const QString objectName);
void deleteAllExperimentCurve();
#endif
void deleteCurveByObjectName(const QString);
QCPCurve* addCurveData(const QVector<Global::ExperimentData> &,const QString objectName);
QCPCurve * getCurrentCurve(){return _currentCurve;}
signals:
@ -106,7 +112,7 @@ private:
void clearData(const ClearDataMode);
void clearAllUiData();
void deleteCurve(const QString);
void loadAnalysisData(const AnalysisMode mode,const double x1,const double x2,const QString objectName);
@ -114,7 +120,7 @@ private:
private:
AnalysisOperationRecorder::AnalysisMode _analysisMode;
LocalCustomPlot *_customPlot;
QCPCurve * _currentCurve;
QCPCurve * _currentCurve;
EventHandler* _eventHandler;
QCPItemStraightLine *_line1,*_line2;
QVector<QCPItemStraightLine*> _lineVtr;

View File

@ -652,6 +652,7 @@ void ExperimentSettingForm::slotRecvPhaseInfo(const QByteArray &ba)
Phase *phase = (Phase *)(data + i * PHASE_BYTE_SIZE);
phaseVtr.push_back(*phase);
#endif
#if 0
u8* localData = data + i * PHASE_BYTE_SIZE;
int index = 0;

View File

@ -95,8 +95,9 @@ void PrintPreviewForm::slotPaintRequested(QPrinter *printer)
frameRect.width(),30);
painter.drawRect(fileInfoRect);
QString fileInfoStr = QString(" 设备:差式扫描量热仪 文件名:")
+ Global::_curveFileDataVtr.first().fileName;
QString fileName = Global::getFileName(Global::_curveFileDataVtr.first().filePath);
QString fileInfoStr = QString(" 设备:差式扫描量热仪 文件名:") + fileName;
painter.drawText(fileInfoRect, Qt::AlignLeft|Qt::AlignVCenter, fileInfoStr);
// Experiment info.

View File

@ -113,13 +113,13 @@ void SpecificHeatComparisonMethodForm::showEvent(QShowEvent *event)
for(auto& cfd:Global::_curveFileDataVtr){
for(auto& item:cfd.phaseTotalVtr){
if(item.curve == _baseLineCurve){
_baseLineLineEdit->setText(cfd.fileName);
_baseLineLineEdit->setText(cfd.filePath);
_baseLineDataVtr = &(item.dataVtr);
}else if(item.curve == _standardSampleCurve){
_standardSampleLineEdit->setText(cfd.fileName);
_standardSampleLineEdit->setText(cfd.filePath);
_standardSampleDataVtr = &(item.dataVtr);
}else if(item.curve == _sampleCurve){
_sampleLineEdit->setText(cfd.fileName);
_sampleLineEdit->setText(cfd.filePath);
_sampleDataVtr = &(item.dataVtr);
}
}