384 lines
15 KiB
C++
384 lines
15 KiB
C++
#include"dd_motor_test.h"
|
||
#include "deviceinfo.h"
|
||
#include "rs_settings.h"
|
||
#include "deviceproxy.h"
|
||
#include <QDebug>
|
||
|
||
|
||
dd_motor_test_widget::dd_motor_test_widget(QWidget *parent):
|
||
QFrame(parent),
|
||
ui(new Ui::dd_motor_test_widget)
|
||
{
|
||
ui->setupUi(this);
|
||
// 获取文本光标(不是鼠标光标)
|
||
init();
|
||
}
|
||
|
||
|
||
dd_motor_test_widget::~dd_motor_test_widget()
|
||
{
|
||
delete ui;
|
||
}
|
||
|
||
void dd_motor_test_widget::init()
|
||
{
|
||
limit_state[0] = NORMAL;
|
||
limit_state[1] = NORMAL;
|
||
limit_state[2] = NORMAL;
|
||
enable_state = 0;
|
||
loadSet();
|
||
updateEnablePBStyleSheet(0);
|
||
// 使能状态变化信号和槽连接
|
||
connect(DEV,SIGNAL(DDEnableStateSGL(int)),this,SLOT(updateEnablePBStyleSheet(int)));
|
||
|
||
|
||
// 限位状态变化信号和槽连接
|
||
connect(DEV,SIGNAL(DDLimitStateSGL(int ,LIMIT_STATE)),this,SLOT(updatePBStyleSheet(int ,LIMIT_STATE)));
|
||
|
||
return;
|
||
}
|
||
void dd_motor_test_widget::loadSet()
|
||
{
|
||
RS_SETTINGS->beginGroup("device/DDMotor");
|
||
double dsbStepDDt = RS_SETTINGS->readNumDEntry("/step");
|
||
double dsbVelDD = RS_SETTINGS->readNumDEntry("/Vel");
|
||
int index_moter = RS_SETTINGS->readNumEntry("/motor");
|
||
int index_mode = RS_SETTINGS->readNumEntry("/mode");
|
||
RS_SETTINGS->endGroup();
|
||
ui->dsbStepDD->setValue(dsbStepDDt);
|
||
ui->dsbVelDD->setValue(dsbVelDD);
|
||
ui->cmbMotor->setCurrentIndex(index_moter);
|
||
ui->cmbMoveMode->setCurrentIndex(index_mode);
|
||
|
||
RS_SETTINGS->beginGroup("device/LaserMark");
|
||
double dsbZ0Offset = RS_SETTINGS->readNumDEntry("/Z0Offset");
|
||
double dsbZ2Offset = RS_SETTINGS->readNumDEntry("/Z2Offset");
|
||
RS_SETTINGS->endGroup();
|
||
ui->dsbZ0Offset->setValue(dsbZ0Offset);
|
||
ui->dsbZ2Offset->setValue(dsbZ2Offset);
|
||
|
||
return;
|
||
}
|
||
void dd_motor_test_widget::on_cmbMoveMode_currentIndexChanged(int index)
|
||
{
|
||
if (index == 2)
|
||
{
|
||
ui->dsbStepDD->setMinimum(-50);
|
||
}
|
||
else
|
||
{
|
||
ui->dsbStepDD->setMinimum(0);
|
||
}
|
||
|
||
RS_SETTINGS->beginGroup("device/DDMotor");
|
||
RS_SETTINGS->writeEntry("/mode", index);
|
||
RS_SETTINGS->endGroup();
|
||
}
|
||
|
||
void dd_motor_test_widget::on_dsbStepDD_valueChanged(double value)
|
||
{
|
||
//if (ui->cmbMoveMode->currentIndex() != 0)
|
||
{
|
||
RS_SETTINGS->beginGroup("device/DDMotor");
|
||
RS_SETTINGS->writeEntry("/step", value);
|
||
RS_SETTINGS->endGroup();
|
||
if (ui->cmbMoveMode->currentIndex() == 1)
|
||
DEVICE_INFO->printDeviceSystemInfo(QString("相对运动定位值改变为:%1mm").arg(value));
|
||
else if (ui->cmbMoveMode->currentIndex() == 2)
|
||
DEVICE_INFO->printDeviceSystemInfo(QString("绝对运动定位值改变为:%1mm").arg(value));
|
||
}
|
||
}
|
||
|
||
void dd_motor_test_widget::on_pbVelM10_clicked()
|
||
{
|
||
ui->dsbVelDD->setValue(ui->dsbVelDD->value()*10);
|
||
}
|
||
|
||
void dd_motor_test_widget::on_pbVelD10_clicked()
|
||
{
|
||
ui->dsbVelDD->setValue(ui->dsbVelDD->value()/10);
|
||
}
|
||
|
||
void dd_motor_test_widget::on_dsbVelDD_valueChanged(double value)
|
||
{
|
||
|
||
{
|
||
RS_SETTINGS->beginGroup("device/DDMotor");
|
||
RS_SETTINGS->writeEntry("/Vel", value);
|
||
RS_SETTINGS->endGroup();
|
||
DEVICE_INFO->printDeviceSystemInfo(QString("速度改变完成,当前速度为:%1mm/s").arg(value));
|
||
}
|
||
}
|
||
void dd_motor_test_widget::updateEnablePBStyleSheet(int state)
|
||
{
|
||
bool flag = false;
|
||
flag = state & (1 << ui->cmbMotor->currentIndex());
|
||
enable_state = state;
|
||
|
||
if(flag)
|
||
{
|
||
ui->pbEnable->setStyleSheet(QString::fromUtf8("QPushButton {\n"
|
||
" color: #333;\n"
|
||
" border: 2px solid #555;\n"
|
||
" border-radius: 20px;\n"
|
||
" border-style: outset; \n"
|
||
" background: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.772727 rgba(0, 178, 0, 255), stop:1 rgba(255, 255, 255, 255));\n"
|
||
" padding: 5px;\n"
|
||
" color: rgb(255, 255, 255);\n"
|
||
" }\n"
|
||
"\n"
|
||
"QPushButton:hover {\n"
|
||
" \n"
|
||
" background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.392045 rgba(0, 160, 0, 255), stop:1 rgba(255, 255, 255, 255));\n"
|
||
" \n"
|
||
" }"));
|
||
}
|
||
else
|
||
{
|
||
ui->pbEnable->setStyleSheet(QString::fromUtf8("QPushButton {\n"
|
||
" color: #333;\n"
|
||
" border: 2px solid #555;\n"
|
||
" border-radius: 20px;\n"
|
||
" border-style: outset;\n"
|
||
" background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.693182 rgba(159, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));\n"
|
||
" padding: 5px;\n"
|
||
" color: rgb(255, 255, 255);\n"
|
||
" }\n"
|
||
"\n"
|
||
"QPushButton:hover {\n"
|
||
" background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.573864 rgba(195, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));\n"
|
||
" }"));
|
||
}
|
||
|
||
}
|
||
void dd_motor_test_widget::updatePBStyleSheet(int motor,LIMIT_STATE state)
|
||
{
|
||
if ((motor >= 0) && (motor <= 2))
|
||
{
|
||
limit_state[motor] = state;
|
||
}
|
||
if (ui->cmbMotor->currentIndex() != motor)
|
||
return;
|
||
switch (state)
|
||
{
|
||
case LEFT_LIMIT:
|
||
ui->pbMoveN->setStyleSheet(QString::fromUtf8("QPushButton {\n"
|
||
"color: #333;\n"
|
||
"border: 1px solid #555;\n"
|
||
"border-radius: 2px;\n"
|
||
"border-style: outset;\n"
|
||
"background-color: rgb(197, 25, 9);\n"
|
||
"padding: 5px;\n"
|
||
"}\n"
|
||
"QPushButton:hover {\n"
|
||
"background-color: rgb(255, 10, 2);\n"
|
||
"}"));
|
||
break;
|
||
case RIGHT_LIMIT:
|
||
ui->pbMoveP->setStyleSheet(QString::fromUtf8("QPushButton {\n"
|
||
"color: #333;\n"
|
||
"border: 1px solid #555;\n"
|
||
"border-radius: 2px;\n"
|
||
"border-style: outset;\n"
|
||
"background-color: rgb(197, 25, 9);\n"
|
||
"padding: 5px;\n"
|
||
"}\n"
|
||
"QPushButton:hover {\n"
|
||
"background-color: rgb(255, 10, 2);\n"
|
||
"}"));
|
||
break;
|
||
case LEFT_SLIMIT:
|
||
ui->pbMoveN->setStyleSheet(QString::fromUtf8("QPushButton {\n"
|
||
"color: #333;\n"
|
||
"border: 1px solid #555;\n"
|
||
"border-radius: 2px;\n"
|
||
"border-style: outset;\n"
|
||
"background-color: rgb(255, 235, 12);\n"
|
||
"padding: 5px;\n"
|
||
"}\n"
|
||
"QPushButton:hover {\n"
|
||
"background-color: rgb(255, 255, 127);\n"
|
||
"}\n"));
|
||
break;
|
||
case RIGHT_SLIMIT:
|
||
ui->pbMoveP->setStyleSheet(QString::fromUtf8("QPushButton {\n"
|
||
"color: #333;\n"
|
||
"border: 1px solid #555;\n"
|
||
"border-radius: 2px;\n"
|
||
"border-style: outset;\n"
|
||
"background-color: rgb(255, 235, 12);\n"
|
||
"padding: 5px;\n"
|
||
"}\n"
|
||
"QPushButton:hover {\n"
|
||
"background-color: rgb(255, 255, 127);\n"
|
||
"}\n"));
|
||
break;
|
||
case NORMAL:
|
||
ui->pbMoveP->setStyleSheet(QString::fromUtf8("QPushButton {\n"
|
||
"color: #333;\n"
|
||
"border: 1px solid #555;\n"
|
||
"border-radius: 2px;\n"
|
||
"border-style: outset;\n"
|
||
"background-color: rgb(0, 160, 0);\n"
|
||
"padding: 5px;\n"
|
||
"}\n"
|
||
"QPushButton:hover {\n"
|
||
"background-color: rgb(0, 180, 0);\n"
|
||
"}\n"));
|
||
|
||
ui->pbMoveN->setStyleSheet(QString::fromUtf8("QPushButton {\n"
|
||
"color: #333;\n"
|
||
"border: 1px solid #555;\n"
|
||
"border-radius: 2px;\n"
|
||
"border-style: outset;\n"
|
||
"background-color: rgb(0, 160, 0);\n"
|
||
"padding: 5px;\n"
|
||
"}\n"
|
||
"QPushButton:hover {\n"
|
||
"background-color: rgb(0, 180, 0);\n"
|
||
"}\n"));
|
||
break;
|
||
}
|
||
|
||
}
|
||
|
||
void dd_motor_test_widget::on_cmbMotor_currentIndexChanged(int index)
|
||
{
|
||
RS_SETTINGS->beginGroup("device/DDMotor");
|
||
RS_SETTINGS->writeEntry("/motor", index);
|
||
RS_SETTINGS->endGroup();
|
||
|
||
updateEnablePBStyleSheet(enable_state);
|
||
updatePBStyleSheet(index,limit_state[index]);
|
||
}
|
||
|
||
void dd_motor_test_widget::on_pbMoveP_pressed()
|
||
{
|
||
if(ui->cmbMoveMode->currentIndex() == 0)
|
||
{
|
||
connect(ui->pbMoveP,SIGNAL(released()),this,SLOT(pbMovePReleasedHandl()));
|
||
if(ui->cmbMotor->currentIndex() == 0)
|
||
{
|
||
DEV->DAxisCMoveP();
|
||
}
|
||
if(ui->cmbMotor->currentIndex() == 1)
|
||
{
|
||
DEV->Z0AxisCMoveP();
|
||
}
|
||
if(ui->cmbMotor->currentIndex() == 2)
|
||
{
|
||
DEV->Z2AxisCMoveP();
|
||
}
|
||
}
|
||
else if(ui->cmbMoveMode->currentIndex() == 1)
|
||
{
|
||
if(ui->cmbMotor->currentIndex() == 0)
|
||
{
|
||
DEV->DAxisSMoveP();
|
||
}
|
||
if(ui->cmbMotor->currentIndex() == 1)
|
||
{
|
||
DEV->Z0AxisSMoveP();
|
||
}
|
||
if(ui->cmbMotor->currentIndex() == 2)
|
||
{
|
||
DEV->Z2AxisSMoveP();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
DEV->ABSMove_DZ0Z2();
|
||
}
|
||
}
|
||
|
||
void dd_motor_test_widget::pbMovePReleasedHandl()
|
||
{
|
||
disconnect(ui->pbMoveP,SIGNAL(released()),this,SLOT(pbMovePReleasedHandl()));
|
||
if(ui->cmbMotor->currentIndex() == 0)
|
||
DEV->DAxisCMovePEnd();
|
||
if(ui->cmbMotor->currentIndex() == 1)
|
||
DEV->Z0AxisCMovePEnd();
|
||
if(ui->cmbMotor->currentIndex() == 2)
|
||
DEV->Z2AxisCMovePEnd();
|
||
|
||
}
|
||
|
||
void dd_motor_test_widget::on_pbMoveN_pressed()
|
||
{
|
||
if(ui->cmbMoveMode->currentIndex() == 0)
|
||
{
|
||
connect(ui->pbMoveN,SIGNAL(released()),this,SLOT(pbMoveNReleasedHandl()));
|
||
if(ui->cmbMotor->currentIndex() == 0)
|
||
{
|
||
DEV->DAxisCMoveN();
|
||
}
|
||
if(ui->cmbMotor->currentIndex() == 1)
|
||
{
|
||
DEV->Z0AxisCMoveN();
|
||
}
|
||
if(ui->cmbMotor->currentIndex() == 2)
|
||
{
|
||
DEV->Z2AxisCMoveN();
|
||
}
|
||
}
|
||
else if(ui->cmbMoveMode->currentIndex() == 1)
|
||
{
|
||
if(ui->cmbMotor->currentIndex() == 0)
|
||
{
|
||
DEV->DAxisSMoveN();
|
||
}
|
||
if(ui->cmbMotor->currentIndex() == 1)
|
||
{
|
||
DEV->Z0AxisSMoveN();
|
||
}
|
||
if(ui->cmbMotor->currentIndex() == 2)
|
||
{
|
||
DEV->Z2AxisSMoveN();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
DEV->ABSMove_DZ0Z2();
|
||
}
|
||
}
|
||
|
||
void dd_motor_test_widget::pbMoveNReleasedHandl()
|
||
{
|
||
disconnect(ui->pbMoveN,SIGNAL(released()),this,SLOT(pbMoveNReleasedHandl()));
|
||
if(ui->cmbMotor->currentIndex() == 0)
|
||
DEV->DAxisCMoveNEnd();
|
||
if(ui->cmbMotor->currentIndex() == 1)
|
||
DEV->Z0AxisCMoveNEnd();
|
||
if(ui->cmbMotor->currentIndex() == 2)
|
||
DEV->Z2AxisCMoveNEnd();
|
||
|
||
}
|
||
|
||
|
||
void dd_motor_test_widget::on_pbEnable_clicked()
|
||
{
|
||
|
||
if(ui->cmbMotor->currentIndex() == 0)
|
||
DEV->enableDisableDAxis();
|
||
if(ui->cmbMotor->currentIndex() == 1)
|
||
DEV->enableDisableZ0Axis();
|
||
if(ui->cmbMotor->currentIndex() == 2)
|
||
DEV->enableDisableZ2Axis();
|
||
}
|
||
|
||
void dd_motor_test_widget::on_dsbZ0Offset_valueChanged(double value)
|
||
{
|
||
RS_SETTINGS->beginGroup("device/LaserMark");
|
||
RS_SETTINGS->writeEntry("/Z0Offset", value);
|
||
RS_SETTINGS->endGroup();
|
||
DEVICE_INFO->printDeviceSystemInfo(QString("Z0轴工作位置改变完成,当前位置为:%1mm").arg(value));
|
||
}
|
||
|
||
void dd_motor_test_widget::on_dsbZ2Offset_valueChanged(double value)
|
||
{
|
||
RS_SETTINGS->beginGroup("device/LaserMark");
|
||
RS_SETTINGS->writeEntry("/Z2Offset", value);
|
||
RS_SETTINGS->endGroup();
|
||
DEVICE_INFO->printDeviceSystemInfo(QString("Z2轴工作位置改变完成,当前位置为:%1mm").arg(value));
|
||
}
|