提交原始齿轮泵代码

This commit is contained in:
kite_lucs
2026-08-26 16:13:59 +08:00
commit afc8fcf2a4
1688 changed files with 316635 additions and 0 deletions
+576
View File
@@ -0,0 +1,576 @@
#include "sectionalwid.h"
#include "ui_sectionalwid.h"
#include <QLineEdit>
#include <QMessageBox>
#include <QSpinBox>
SectionalWid::SectionalWid(QWidget *parent) :
QWidget(parent),
ui(new Ui::SectionalWid)
{
ui->setupUi(this);
initUI();
connect(SectionalManager::instance(), &SectionalManager::sig_applySetting,
this, &SectionalWid::slt_applySetting);
connect(SectionalManager::instance(), &SectionalManager::sig_loadSettings2UI,
this, &SectionalWid::slt_loadSettings2UI);
connect(SectionalManager::instance(), &SectionalManager::sig_updateCntGroupDisp,
this, &SectionalWid::slt_updateCntGroupDisp);
}
SectionalWid::~SectionalWid()
{
delete ui;
}
void SectionalWid::bindSysPara(SysPara* sysPara)
{
this->sysPara = sysPara;
}
#ifdef COUNTER1_BY_GROUP /* 分段计米 */
void SectionalWid::rowWidgetCreate(int rowIndex)
{
for(int i=0;i<3;i++)
{
QSpinBox *spinBox = new QSpinBox();
spinBox->setButtonSymbols(QSpinBox::NoButtons);
spinBox->setMaximum(INT_MAX);
spinBox->setMinimum(i == 2 ? 1 : 0);
ui->tableWidget->setCellWidget(rowIndex,i,spinBox);
}
}
void SectionalWid::LoadCnt1GroupSettingsToUI()
{
ui->checkBoxGroupCnt1->setChecked(sysPara->para.cnt1ByGroupEnalbe);
on_checkBoxGroupCnt1_clicked(sysPara->para.cnt1ByGroupEnalbe);
ui->tableWidget->setRowCount(sysPara->para.Cnt1ByGroup.cnt1GroupCnt);
for(int i=0; i<sysPara->para.Cnt1ByGroup.cnt1GroupCnt; i++)
{
QSpinBox *spinBox = new QSpinBox();
spinBox->setRange(0, INT_MAX);
spinBox->setButtonSymbols(QSpinBox::NoButtons);
spinBox->setValue(sysPara->para.Cnt1ByGroup.cnt1GroupSettings[i].StartValue);
ui->tableWidget->setCellWidget(i,0,spinBox);
spinBox = new QSpinBox();
spinBox->setRange(0, INT_MAX);
spinBox->setButtonSymbols(QSpinBox::NoButtons);
spinBox->setValue(sysPara->para.Cnt1ByGroup.cnt1GroupSettings[i].EndValue);
ui->tableWidget->setCellWidget(i,1,spinBox);
spinBox = new QSpinBox();
spinBox->setRange(1, INT_MAX);
spinBox->setButtonSymbols(QSpinBox::NoButtons);
spinBox->setValue(sysPara->para.Cnt1ByGroup.cnt1GroupSettings[i].LoopTimes);
ui->tableWidget->setCellWidget(i,2,spinBox);
}
updateCnt1GroupsTblWgt();
}
void SectionalWid::on_Cnt3AddRowBtn_clicked()
{
int rowCnt=ui->tableWidget->rowCount();
if(rowCnt>=MAX_CNT1_GROUPS_NUM)
{
return;
}
ui->tableWidget->setRowCount(rowCnt+1);
rowWidgetCreate(rowCnt);
}
void SectionalWid::on_Cnt3InsertRowBtn_clicked()
{
int rowIndex=ui->tableWidget->currentRow();
int rowCnt=ui->tableWidget->rowCount();
if(rowIndex<0||rowCnt>=MAX_CNT1_GROUPS_NUM)
{
return;
}
ui->tableWidget->insertRow(rowIndex+1);
rowWidgetCreate(rowIndex+1);
}
void SectionalWid::on_cnt3RemoveAllRowsBtn_clicked()
{
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(this, tr("警告"),
tr("是否确认删除全部设置?"),
QMessageBox::Ok | QMessageBox::Cancel);
if (ret == QMessageBox::Ok){
int rowCnt=ui->tableWidget->rowCount();
for(int i=rowCnt-1;i>=0;i--)
{
ui->tableWidget->removeRow(i);
}
}
}
void SectionalWid::on_Cnt3RemoveRowBtn_clicked()
{
int rowIndex=ui->tableWidget->currentRow();
if(rowIndex<0)
{
return;
}
QMessageBox::StandardButton ret;
if(rowIndex==sysPara->status.cnt1GroupRunningIndex)
{
QMessageBox::warning(this, tr("错误"),
tr("正在打印第%1组设置,不可删除").arg(rowIndex+1),
QMessageBox::Ok);
return;
}
ret = QMessageBox::warning(this, tr("警告"),
tr("是否确认删除第%1组设置?").arg(rowIndex+1),
QMessageBox::Ok | QMessageBox::Cancel);
if (ret == QMessageBox::Ok){
ui->tableWidget->removeRow(rowIndex);
}
}
void SectionalWid::on_cnt3RemoveAllRowsBtn_3_clicked()
{
unsigned char temp = 1;
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(this, tr("警告"),
tr("是否确认清零计数器1的循环值已经打印次数?"),
QMessageBox::Ok | QMessageBox::Cancel);
if (ret == QMessageBox::Ok){
sysPara->devOp->fpgaWr(0xb12c,(unsigned char *)&temp,1);
temp = 0;
sysPara->devOp->fpgaWr(0xb12c,(unsigned char *)&temp,1);
}
}
void SectionalWid::on_checkBoxGroupCnt1_clicked(bool checked)
{
// 信号修改计数器的显示
ui->checkBoxGroupCnt_2->setChecked(checked);
SectionalManager::instance()->emitUpdateCntShow(checked);
}
void SectionalWid::updateCnt1GroupsTblWgt()
{
QPalette Palette;
QSpinBox *spinBox;
int rowCnt=ui->tableWidget->rowCount();
for(int i=0;i<rowCnt;i++)
{
for(int j=0;j<3;j++)
{
spinBox = (QSpinBox *)ui->tableWidget->cellWidget(i,j);
QLineEdit *lineEdit = spinBox->findChild<QLineEdit*>();
if (lineEdit) {
lineEdit->setAutoFillBackground(true);
QPalette palette = lineEdit->palette();
if(sysPara->para.cnt1ByGroupEnalbe && (i == sysPara->status.cnt1GroupRunningIndex))
{
palette.setColor(QPalette::Normal,QPalette::Base, Qt::green);
}
else
{
palette.setColor(QPalette::Normal,QPalette::Base, Qt::lightGray);
}
lineEdit->setPalette(palette);
}
else{
continue;
}
}
}
}
void SectionalWid::ApplyCnt1GroupSetting()
{
QSpinBox *spinBox = nullptr;
sysPara->para.cnt1ByGroupEnalbe = ui->checkBoxGroupCnt1->isChecked();
sysPara->para.Cnt1ByGroup.cnt1GroupCnt=ui->tableWidget->rowCount();
if(sysPara->para.cnt1ByGroupEnalbe && sysPara->para.Cnt1ByGroup.cnt1GroupCnt==0)
{
sysPara->para.cnt1ByGroupEnalbe=false;
ui->checkBoxGroupCnt1->setChecked(false);
on_checkBoxGroupCnt1_clicked(false);
}
for(int i=0; i<sysPara->para.Cnt1ByGroup.cnt1GroupCnt; i++)
{
spinBox = (QSpinBox *)ui->tableWidget->cellWidget(i,0);
sysPara->para.Cnt1ByGroup.cnt1GroupSettings[i].StartValue = spinBox->value();
spinBox = (QSpinBox *)ui->tableWidget->cellWidget(i,1);
sysPara->para.Cnt1ByGroup.cnt1GroupSettings[i].EndValue = spinBox->value();
spinBox = (QSpinBox *)ui->tableWidget->cellWidget(i,2);
sysPara->para.Cnt1ByGroup.cnt1GroupSettings[i].LoopTimes = spinBox->value();
}
sysPara->devOp->writeCnt1GroupSetting(1);
sysPara->saveParaToFile();
//改变当前执行的分段的背景颜色
updateCnt1GroupsTblWgt();
}
#endif
#ifdef COUNTER2_BY_GROUP /* 分段计米2 */
void SectionalWid::rowWidgetCreate2(int rowIndex)
{
for(int i=0;i<3;i++)
{
QSpinBox *spinBox = new QSpinBox();
spinBox->setButtonSymbols(QSpinBox::NoButtons);
spinBox->setMaximum(INT_MAX);
spinBox->setMinimum(i == 2 ? 1 : 0);
ui->tableWidget_2->setCellWidget(rowIndex,i,spinBox);
}
}
void SectionalWid::LoadCnt2GroupSettingsToUI()
{
ui->checkBoxGroupCnt_2->setChecked(sysPara->para.cnt2ByGroupEnalbe);
on_checkBoxGroupCnt_2_clicked(sysPara->para.cnt2ByGroupEnalbe);
//qDebug()<<"LoadCnt1GroupSettingsToUI:cnt1GroupCnt "<<sysPara->para.Cnt1ByGroup.cnt1GroupCnt;
ui->tableWidget_2->setRowCount(sysPara->para.Cnt2ByGroup.cnt2GroupCnt);
for(int i=0; i<sysPara->para.Cnt2ByGroup.cnt2GroupCnt; i++)
{
QSpinBox *spinBox = new QSpinBox();
spinBox->setButtonSymbols(QSpinBox::NoButtons);
spinBox->setValue(sysPara->para.Cnt2ByGroup.cnt2GroupSettings[i].StartValue);
spinBox->setRange(0, INT_MAX);
ui->tableWidget_2->setCellWidget(i,0,spinBox);
spinBox = new QSpinBox();
spinBox->setButtonSymbols(QSpinBox::NoButtons);
spinBox->setValue(sysPara->para.Cnt2ByGroup.cnt2GroupSettings[i].EndValue);
spinBox->setRange(0, INT_MAX);
ui->tableWidget_2->setCellWidget(i,1,spinBox);
spinBox = new QSpinBox();
spinBox->setButtonSymbols(QSpinBox::NoButtons);
spinBox->setValue(sysPara->para.Cnt2ByGroup.cnt2GroupSettings[i].LoopTimes);
spinBox->setRange(1, INT_MAX);
ui->tableWidget_2->setCellWidget(i,2,spinBox);
}
updateCnt2GroupsTblWgt();
}
void SectionalWid::on_checkBoxGroupCnt_2_clicked(bool checked)
{
// 信号修改计数器的显示
ui->checkBoxGroupCnt1->setChecked(checked);
SectionalManager::instance()->emitUpdateCntShow(checked);
}
void SectionalWid::updateCnt2GroupsTblWgt()
{
QPalette Palette;
int rowCnt=ui->tableWidget_2->rowCount();
for(int i=0;i<rowCnt;i++)
{
for(int j=0;j<3;j++)
{
auto spinBox = (QSpinBox *)ui->tableWidget_2->cellWidget(i,j);
QLineEdit *lineEdit = spinBox->findChild<QLineEdit*>();
if (lineEdit) {
lineEdit->setAutoFillBackground(true);
QPalette palette = lineEdit->palette();
if(sysPara->para.cnt2ByGroupEnalbe && (i == sysPara->status.cnt2GroupRunningIndex))
{
palette.setColor(QPalette::Normal,QPalette::Base, Qt::green);
}
else
{
palette.setColor(QPalette::Normal,QPalette::Base, Qt::lightGray);
}
lineEdit->setPalette(palette);
}
else{
continue;
}
}
}
}
void SectionalWid::ApplyCnt2GroupSetting()
{
QSpinBox *spinBox = nullptr;
sysPara->para.cnt2ByGroupEnalbe = ui->checkBoxGroupCnt_2->isChecked();
sysPara->para.Cnt2ByGroup.cnt2GroupCnt=ui->tableWidget_2->rowCount();
if(sysPara->para.cnt2ByGroupEnalbe && sysPara->para.Cnt2ByGroup.cnt2GroupCnt==0)
{
sysPara->para.cnt2ByGroupEnalbe=false;
ui->checkBoxGroupCnt_2->setChecked(false);
on_checkBoxGroupCnt_2_clicked(false);
}
for(int i=0; i<sysPara->para.Cnt2ByGroup.cnt2GroupCnt; i++)
{
spinBox = (QSpinBox *)ui->tableWidget_2->cellWidget(i,0);
sysPara->para.Cnt2ByGroup.cnt2GroupSettings[i].StartValue = spinBox->value();
spinBox = (QSpinBox *)ui->tableWidget_2->cellWidget(i,1);
sysPara->para.Cnt2ByGroup.cnt2GroupSettings[i].EndValue = spinBox->value();
spinBox = (QSpinBox *)ui->tableWidget_2->cellWidget(i,2);
sysPara->para.Cnt2ByGroup.cnt2GroupSettings[i].LoopTimes = spinBox->value();
}
sysPara->devOp->writeCnt2GroupSetting(1);
sysPara->saveParaToFile();
//改变当前执行的分段的背景颜色
updateCnt2GroupsTblWgt();
}
#endif
void SectionalWid::moveRow(int nFrom, int nTo, QTableWidget* table)
{
if (table == nullptr) return;
if( nFrom == nTo ) return;
if( nFrom < 0 || nTo < 0 ) return;
int StartValue,EndValue,LoopTimes;
int To_StartValue,To_EndValue,To_LoopTimes;
QSpinBox *spinBox = nullptr;
int nRowCount = table->rowCount();
if( nFrom >= nRowCount || nTo >= nRowCount ) return;
spinBox = (QSpinBox *)table->cellWidget(nFrom,0);
StartValue = spinBox->value();
spinBox = (QSpinBox *)table->cellWidget(nFrom,1);
EndValue = spinBox->value();
spinBox = (QSpinBox *)table->cellWidget(nFrom,2);
LoopTimes = spinBox->value();
spinBox = (QSpinBox *)table->cellWidget(nTo,0);
To_StartValue = spinBox->value();
spinBox = (QSpinBox *)table->cellWidget(nTo,1);
To_EndValue = spinBox->value();
spinBox = (QSpinBox *)table->cellWidget(nTo,2);
To_LoopTimes = spinBox->value();
spinBox = new QSpinBox();
spinBox->setButtonSymbols(QSpinBox::NoButtons);
spinBox->setValue(StartValue);
spinBox->setRange(0, INT_MAX);
table->setCellWidget(nTo,0,spinBox);
spinBox = new QSpinBox();
spinBox->setButtonSymbols(QSpinBox::NoButtons);
spinBox->setValue(EndValue);
spinBox->setRange(0, INT_MAX);
table->setCellWidget(nTo,1,spinBox);
spinBox = new QSpinBox();
spinBox->setButtonSymbols(QSpinBox::NoButtons);
spinBox->setValue(LoopTimes);
spinBox->setRange(1, INT_MAX);
table->setCellWidget(nTo,2,spinBox);
spinBox = new QSpinBox();
spinBox->setButtonSymbols(QSpinBox::NoButtons);
spinBox->setValue(To_StartValue);
spinBox->setRange(0, INT_MAX);
table->setCellWidget(nFrom,0,spinBox);
spinBox = new QSpinBox();
spinBox->setButtonSymbols(QSpinBox::NoButtons);
spinBox->setValue(To_EndValue);
spinBox->setRange(0, INT_MAX);
table->setCellWidget(nFrom,1,spinBox);
spinBox = new QSpinBox();
spinBox->setButtonSymbols(QSpinBox::NoButtons);
spinBox->setValue(To_LoopTimes);
spinBox->setRange(1, INT_MAX);
table->setCellWidget(nFrom,2,spinBox);
table->selectRow(nTo);
}
void SectionalWid::on_pushButtonUpRow_clicked()
{
moveRow(ui->tableWidget->currentRow(),
ui->tableWidget->currentRow() - 1,
ui->tableWidget);
}
void SectionalWid::on_pushButtonDownRow_clicked()
{
moveRow(ui->tableWidget->currentRow(),
ui->tableWidget->currentRow() + 1,
ui->tableWidget);
}
#ifdef COUNTER2_BY_GROUP /* 分段计米 */
void SectionalWid::on_Cnt3AddRowBtn_2_clicked()
{
int rowCnt=ui->tableWidget_2->rowCount();
if(rowCnt>=MAX_CNT1_GROUPS_NUM)
{
return;
}
ui->tableWidget_2->setRowCount(rowCnt+1);
rowWidgetCreate2(rowCnt);
}
void SectionalWid::on_Cnt3InsertRowBtn_2_clicked()
{
int rowIndex=ui->tableWidget_2->currentRow();
int rowCnt=ui->tableWidget_2->rowCount();
if(rowIndex<0||rowCnt>=MAX_CNT1_GROUPS_NUM)
{
//qDebug()<<"max counter1 groups num is "<<MAX_CNT1_GROUPS_NUM;
return;
}
ui->tableWidget_2->insertRow(rowIndex+1);
rowWidgetCreate2(rowIndex+1);
}
void SectionalWid::on_cnt3RemoveAllRowsBtn_2_clicked()
{
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(this, tr("警告"),
tr("是否确认删除全部设置?"),
QMessageBox::Ok | QMessageBox::Cancel);
if (ret == QMessageBox::Ok){
int rowCnt=ui->tableWidget_2->rowCount();
for(int i=rowCnt-1;i>=0;i--)
{
ui->tableWidget_2->removeRow(i);
}
}
}
void SectionalWid::on_Cnt3RemoveRowBtn_2_clicked()
{
int rowIndex=ui->tableWidget_2->currentRow();
if(rowIndex<0)
{
return;
}
QMessageBox::StandardButton ret;
if(rowIndex==sysPara->status.cnt2GroupRunningIndex)
{
QMessageBox::warning(this, tr("错误"),
tr("正在打印第%1组设置,不可删除").arg(rowIndex+1),
QMessageBox::Ok);
return;
}
ret = QMessageBox::warning(this, tr("警告"),
tr("是否确认删除第%1组设置?").arg(rowIndex+1),
QMessageBox::Ok | QMessageBox::Cancel);
if (ret == QMessageBox::Ok){
ui->tableWidget_2->removeRow(rowIndex);
}
}
void SectionalWid::on_cnt3RemoveAllRowsBtn_4_clicked()
{
unsigned char temp = 2;
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(this, tr("警告"),
tr("是否确认清零计数器2的循环值已经打印次数?"),
QMessageBox::Ok | QMessageBox::Cancel);
if (ret == QMessageBox::Ok){
sysPara->devOp->fpgaWr(0xb12c,(unsigned char *)&temp,1);
temp = 0;
sysPara->devOp->fpgaWr(0xb12c,(unsigned char *)&temp,1);
}
}
#endif
void SectionalWid::on_pushButtonUpRow_2_clicked()
{
moveRow(ui->tableWidget_2->currentRow(),
ui->tableWidget_2->currentRow() - 1,
ui->tableWidget_2);
}
void SectionalWid::on_pushButtonDownRow_2_clicked()
{
moveRow(ui->tableWidget_2->currentRow(),
ui->tableWidget_2->currentRow() + 1,
ui->tableWidget_2);
}
void SectionalWid::slt_applySetting()
{
#ifdef COUNTER1_BY_GROUP
ApplyCnt1GroupSetting();
#endif
#ifdef COUNTER2_BY_GROUP
ApplyCnt2GroupSetting();
#endif
}
void SectionalWid::slt_loadSettings2UI()
{
#ifdef COUNTER1_BY_GROUP
LoadCnt1GroupSettingsToUI();
#endif
#ifdef COUNTER2_BY_GROUP
LoadCnt2GroupSettingsToUI();
#endif
}
void SectionalWid::slt_updateCntGroupDisp(bool bChangeToNext)
{
if(bChangeToNext)//循环数走完
{
//改变当前执行的分段的背景颜色
#ifdef COUNTER1_BY_GROUP /* 分段计米 */
updateCnt1GroupsTblWgt();
#endif
#ifdef COUNTER2_BY_GROUP /* 分段计米2 */
updateCnt2GroupsTblWgt();
#endif
}
}
void SectionalWid::initUI()
{
#ifdef COUNTER1_BY_GROUP /* 分段计米 */
QStringList headerLabels = QStringList()<<QObject::tr("起始值")
<<QObject::tr("结束值")
<<QObject::tr("循环值");
ui->tableWidget->setHorizontalHeaderLabels(headerLabels);
ui->tableWidget->setFocusPolicy(Qt::NoFocus);
ui->tableWidget->horizontalHeader()->setHighlightSections(false);
ui->tableWidget->setColumnHidden(3,true);//第3列用来标志是否保存当前行
QHeaderView* vertivalHeader = ui->tableWidget->verticalHeader();
vertivalHeader->setFixedWidth(60);
ui->tableWidget->setColumnWidth(2,120);
#endif
#ifdef COUNTER2_BY_GROUP /* 分段计米2 */
QStringList headerLabels2 = QStringList()<<QObject::tr("起始值")
<<QObject::tr("结束值")
<<QObject::tr("循环值");
ui->tableWidget_2->setHorizontalHeaderLabels(headerLabels2);
ui->tableWidget_2->setFocusPolicy(Qt::NoFocus);
ui->tableWidget_2->horizontalHeader()->setHighlightSections(false);
ui->tableWidget_2->setColumnHidden(3,true);//第3列用来标志是否保存当前行
QHeaderView* vertivalHeader2 = ui->tableWidget_2->verticalHeader();
vertivalHeader2->setFixedWidth(60);
ui->tableWidget_2->setColumnWidth(2,120);
#endif
}