PunchHMI/sharedviews/debugviews/debugdialog.cpp
2024-02-06 14:58:57 +08:00

316 lines
8.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "debugdialog.h"
#include "ui_debugdialog.h"
DebugDialog::DebugDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::DebugDialog)
{
ui->setupUi(this);
setWindowFlags (Qt::Window | Qt::FramelessWindowHint);
setWindowModality(Qt::ApplicationModal);
setAttribute(Qt::WA_TranslucentBackground, true);//设置窗体背景透明
setFocusPolicy(Qt::NoFocus);
initControlStyle();
m_flag = 0;
m_funType = 0;
m_headParaFlag = 0;
m_mcParaFlag = 0;
m_id = 0;
m_val = 0;
memset(m_headParaValues.paraBuf, 0, sizeof(m_headParaValues.paraBuf));
memset(m_mcParaValues.buf, 0, sizeof(ParaStruct));
memset(m_wkParaValues.buf, 0, sizeof(ParaStruct));
}
DebugDialog::~DebugDialog()
{
delete ui;
}
void DebugDialog::initControlStyle()
{
SetControlStyle setControlStyle;
setControlStyle.setUiName(this->objectName());
//设置控件图标
//背景图
ui->frameBack->setStyleSheet(TRANSPARENTSTYLE);
this->setStyleSheet(LABELWHITESTYLE);
ui->frameBack->setStyleSheet(setControlStyle.getStyleSheet(this->objectName()));
ui->labelTitle->setStyleSheet(LABELWHITESTYLE);
ui->labelTitle->setFont(fontNormal_1);
ui->labelTitle->setAlignment(Qt::AlignLeft);
ui->labelTitle->setAlignment(Qt::AlignVCenter);
ui->buttonCancel->setWhiteBlueBottomStyle();
ui->buttonOk->setWhiteBlueBottomStyle();
}
void DebugDialog::resizeUI(int w, int h)
{
this->resize(w,h);
ui->frameBack->setGeometry(0,0,w,h);
}
void DebugDialog::resizeTittle(int x, int y, int w, int h)
{
ui->labelTitle->setGeometry(x,y,w,h);
}
void DebugDialog::resizeCancelBtn(int x, int y, int w, int h)
{
SetControlStyle setControlStyle;
setControlStyle.setUiName(this->objectName());
ui->buttonCancel->setGeometry(x,y,w,h);
ui->buttonCancel->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonCancel->objectName()+"_1"),12);
}
void DebugDialog::resizeOkBtn(int x, int y, int w, int h)
{
SetControlStyle setControlStyle;
setControlStyle.setUiName(this->objectName());
ui->buttonOk->setGeometry(x,y,w,h);
ui->buttonOk->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonOk->objectName()+"_1"),12);
}
void DebugDialog::setTitleStr(QString str)
{
ui->labelTitle->setText(str);
}
void DebugDialog::setFlag(int flag)
{
m_flag = flag;
}
void DebugDialog::excuteOrder(int def, int fun)
{
//def 对应的事件宏定义
//fun 动作
if(def < 0 || fun < 0)
{
return;
}
switch(fun)
{
case OUTCONTROL_ENABLE:
g_pMachine->motoServoCtrl(def, UP_OPEN_ON);
break;
case OUTCONTROL_DISABLE:
g_pMachine->motoServoCtrl(def, DOWN_CLOSE_OFF);
break;
case OUTCONTROL_JOGP://电机点动正转
g_pMachine->motoMove(def, MT_MOVE_DIR_POSI, 0);
break;
case OUTCONTROL_JOGN://电机点动反转
g_pMachine->motoMove(def, MT_MOVE_DIR_NEGA, 0);
break;
case OUTCONTROL_STOP://电机点动停止
g_pMachine->motoMove(def, MT_MOVE_DIR_STOP, 0);
break;
case OUTCONTROL_ZERO://电机归零
g_pMachine->motoToZero(def);
break;
case OUTCONTROL_UP://气缸上升,输出控制方式的电机正转
g_pMachine->outputCtrl(def, UP_OPEN_ON, 0);
break;
case OUTCONTROL_DOWN://气缸下降,输出控制方式的电机反转
g_pMachine->outputCtrl(def, DOWN_CLOSE_OFF, 0);
break;
case MANUALACTION_RUN://手动动作执行
g_pMachine->manualAction(def);
break;
case OUTCONTROL_OPEN://电磁阀开
g_pMachine->outputCtrl(def, UP_OPEN_ON, 0);
break;
case OUTCONTROL_CLOSE://电磁阀合
g_pMachine->outputCtrl(def, DOWN_CLOSE_OFF, 0);
break;
case OUTCONTROL_FOLLOWPOS://跟随位 缠绕压脚 跟随位
g_pMachine->outputCtrl(def, UP_OPEN_ON, 2);
break;
case OUTCONTROL_ZEROPOS://锯齿零位
g_pMachine->outputCtrl(def, DOWN_CLOSE_OFF, 0);
break;
case OUTCONTROL_TOUP://锯齿上位
g_pMachine->outputCtrl(def, DOWN_CLOSE_OFF, 2);
break;
case OUTCONTROL_CTRL1://锯齿摆动位1
g_pMachine->outputCtrl(def, UP_OPEN_ON, 0);
break;
case OUTCONTROL_CTRL2://锯齿摆动位2
g_pMachine->outputCtrl(def, UP_OPEN_ON, 2);
break;
case OUTCONTROL_STARTOIL://开始(如手动加油)
g_pMachine->manualOil(1);
break;
case OUTCONTROL_STOPOIL://停止(如手动加油)
g_pMachine->manualOil(0);
break;
}
}
void DebugDialog::on_buttonCancel_clicked()
{
if(m_flag == 1)//已经发送打开命令
{
if(g_pMachine != NULL)
{
g_pMachine->encoderVal(0);//显示M轴绝对值编码器值,1打开,0关闭
m_flag = -1;
}
}
this->close();
}
void DebugDialog::on_buttonOk_clicked()
{
if(m_funType == DEBUG_DIECUTTER||
m_funType == DEBUG_DIECUTTER)
{
saveHeadPara();
}
if(m_funType == DEBUG_TRIM||//主轴调试
m_funType == DEBUG_NEEDLESHUTTLE)//针梭调试
{
saveMcPara();//发送机器参数
}
}
//设置界面类型
void DebugDialog::setFunType(int sel)
{
m_funType = sel;
if(m_funType == DEBUG_DIECUTTER ||
m_funType == DEBUG_DIECUTTER )
{
g_pMachine->getHeadParasFromMachine(1);//获取机头板参数
}
if(m_funType == DEBUG_TRIM ||
m_funType == DEBUG_NEEDLESHUTTLE )
{
g_pMachine->getParasFromMachine();//获取参数
}
// if(m_funType == DEBUG_CUTHEAD ||
// m_funType == DEBUG_SPINDLE )
// {
// ui->buttonOk->hide();
// }
// else
// {
// ui->buttonOk->show();
// }
}
//收到下位机参数改变信号的槽
void DebugDialog::paraChange(int type, int id)
{
m_mcParaFlag = 0;//参数改变的标志
//点了主板的按钮后现在这个g_pMachine就是对应主板的
if (type == SEW_MCPARA_MACH)
{
if (id == 0)
{ //得到当前主板的参数
memcpy(&m_mcParaValues, &g_pMachine->getMcPara(), sizeof(ParaStruct));
m_mcParaFlag= 1;
emit siMcParaChange();
}
}
else if (type == SEW_MCPARA_WORK)
{
if (id == 0)
{
memcpy(&m_wkParaValues, &g_pMachine->getWkPara(), sizeof(ParaStruct));
// m_mcParaFlag = 1;
emit siWkParaChange();
}
}
}
//外围板参数改变的槽函数
void DebugDialog::EXBParaChange()
{
m_headParaFlag = 0;
if(g_pMachine->getHeadPara(0) != NULL)
{
memcpy(&m_headParaValues, g_pMachine->getHeadPara(0), sizeof(HeadInfo));
m_headParaFlag = 1;
emit siEXBParaChange();
}
}
//读取机头板参数
int DebugDialog::getHeadPara(int idx)
{
int value = 0;
value = m_headParaValues.paraBuf[idx];
return value;
}
//设置机头板参数
void DebugDialog::setHeadPara(int id,int val)
{
m_headParaValues.paraBuf[id] = val;
}
//发送机头板参数
void DebugDialog::saveHeadPara()
{
if(g_pMachine != NULL)
{
g_pMachine->setHeadBoardPara(&m_headParaValues);
}
}
//读取机器参数
int DebugDialog::getMcPara(int idx)
{
int mcValue = 0;
mcValue = m_mcParaValues.buf[idx];
return mcValue;
}
//设置机器参数
void DebugDialog::setMcPara(int id,int val)
{
//单个保存
// m_id = id;
// m_val = val;
m_mcParaValues.buf[id] = val;
}
//发送机器参数
void DebugDialog::saveMcPara()
{
if(g_pMachine != NULL)
{
//单个保存
//g_pMachine->setAMcPara(m_id+1, m_val);
g_pMachine->setMcPara(&m_mcParaValues);
}
}
//读取工作参数
int DebugDialog::getWkPara(int idx)
{
int wkValue = 0;
wkValue = m_wkParaValues.buf[idx];
return wkValue;
}
//设置工作参数
void DebugDialog::setWkPara(int id,int val)
{
//单个保存
// m_id = id;
// m_val = val;
m_wkParaValues.buf[id] = val;
}
//发送工作参数
void DebugDialog::saveWkPara()
{
if(g_pMachine != NULL)
{
//单个保存
//g_pMachine->setAMcPara(m_id+1, m_val);
g_pMachine->setWkPara(&m_wkParaValues);
}
}