// CPagePortProperty.cpp: 实现文件
|
//
|
|
#include "stdafx.h"
|
#include "Servo.h"
|
#include "CPagePortProperty.h"
|
#include "afxdialogex.h"
|
#include "Log.h"
|
#include "MsgDlg.h"
|
|
|
// CPagePortProperty 对话框
|
|
IMPLEMENT_DYNAMIC(CPagePortProperty, CHMPropertyPage)
|
|
CPagePortProperty::CPagePortProperty(CWnd* pParent /*=nullptr*/)
|
: CHMPropertyPage(IDD_PAGE_PORT_PROPERTY, pParent)
|
{
|
m_pPort = nullptr;
|
}
|
|
CPagePortProperty::~CPagePortProperty()
|
{
|
}
|
|
void CPagePortProperty::DoDataExchange(CDataExchange* pDX)
|
{
|
CHMPropertyPage::DoDataExchange(pDX);
|
}
|
|
|
BEGIN_MESSAGE_MAP(CPagePortProperty, CHMPropertyPage)
|
ON_WM_CTLCOLOR()
|
ON_WM_DESTROY()
|
ON_WM_SIZE()
|
ON_BN_CLICKED(IDC_CHECK_ENABLE, &CPagePortProperty::OnBnClickedCheckEnable)
|
ON_CBN_SELCHANGE(IDC_COMBO_PORT_TYPE, &CPagePortProperty::OnCbnSelchangeComboPortType)
|
ON_CBN_SELCHANGE(IDC_COMBO_PORT_MODE, &CPagePortProperty::OnCbnSelchangeComboPortMode)
|
ON_CBN_SELCHANGE(IDC_COMBO_PORT_CASSERT_TYPE, &CPagePortProperty::OnCbnSelchangeComboPortCassertType)
|
ON_CBN_SELCHANGE(IDC_COMBO_PORT_TRANSFER_MODE, &CPagePortProperty::OnCbnSelchangeComboPortTransferMode)
|
ON_BN_CLICKED(IDC_CHECK_AUTO_CHANGE, &CPagePortProperty::OnBnClickedCheckAutoChange)
|
END_MESSAGE_MAP()
|
|
|
// CPagePortProperty 消息处理程序
|
void CPagePortProperty::setLoadPort(SERVO::CLoadPort* pPort)
|
{
|
m_pPort = pPort;
|
}
|
|
BOOL CPagePortProperty::OnInitDialog()
|
{
|
CHMPropertyPage::OnInitDialog();
|
|
|
ASSERT(m_pPort);
|
CComboBox* pComboBox;
|
std::string strTemp;
|
|
|
pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_PORT_TYPE);
|
for (int i = 1; i <= 7; i++) {
|
pComboBox->InsertString(i - 1, SERVO::CLoadPort::getPortTypeDescription((SERVO::PortType)i, strTemp).c_str());
|
}
|
int portType = (int)m_pPort->getPortType();
|
if (1 <= portType && portType <= 7) {
|
pComboBox->SetCurSel(portType - 1);
|
}
|
|
pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_PORT_MODE);
|
for (int i = 0; i <= 5; i++) {
|
pComboBox->InsertString(i, SERVO::CLoadPort::getPortModeDescription((SERVO::PortMode)i, strTemp).c_str());
|
}
|
int portMode = (int)m_pPort->getPortMode();
|
if (0 <= portMode && portMode <= 5) {
|
pComboBox->SetCurSel(portMode);
|
}
|
|
pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_PORT_CASSERT_TYPE);
|
for (int i = 1; i <= 3; i++) {
|
pComboBox->InsertString(i - 1, SERVO::CLoadPort::getPortCassetteTypeDescription((SERVO::CassetteType)i, strTemp).c_str());
|
}
|
int cessetteType = (int)m_pPort->getCessetteType();
|
if (1 <= cessetteType && cessetteType <= 3) {
|
pComboBox->SetCurSel(cessetteType - 1);
|
}
|
|
pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_PORT_TRANSFER_MODE);
|
for (int i = 1; i <= 3; i++) {
|
pComboBox->InsertString(i - 1, SERVO::CLoadPort::getPortTransferModeDescription((SERVO::TransferMode)i, strTemp).c_str());
|
}
|
int transferMode = (int)m_pPort->getTransferMode();
|
if (1 <= transferMode && transferMode <= 3) {
|
pComboBox->SetCurSel(transferMode - 1);
|
}
|
|
((CButton*)GetDlgItem(IDC_CHECK_AUTO_CHANGE))->SetCheck(m_pPort->isAutoChange() ? BST_CHECKED : BST_UNCHECKED);
|
|
|
|
EnableCtrls(m_pPort->isEnable());
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
// 异常: OCX 属性页应返回 FALSE
|
}
|
|
HBRUSH CPagePortProperty::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
{
|
HBRUSH hbr = CHMPropertyPage::OnCtlColor(pDC, pWnd, nCtlColor);
|
|
// TODO: 在此更改 DC 的任何特性
|
|
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
|
return hbr;
|
}
|
|
void CPagePortProperty::OnDestroy()
|
{
|
CHMPropertyPage::OnDestroy();
|
|
// TODO: 在此处添加消息处理程序代码
|
}
|
|
void CPagePortProperty::OnSize(UINT nType, int cx, int cy)
|
{
|
CHMPropertyPage::OnSize(nType, cx, cy);
|
|
// TODO: 在此处添加消息处理程序代码
|
}
|
|
void CPagePortProperty::OnBnClickedCheckEnable()
|
{
|
BOOL bCheck = ((CButton*)GetDlgItem(IDC_CHECK_ENABLE))->GetCheck() == BST_CHECKED;
|
EnableCtrls(bCheck);
|
|
|
// enable port
|
CMsgDlg msgDlg("请等待", "正在操作,请等待...");
|
|
ASSERT(m_pPort != nullptr);
|
m_pPort->eablePort(bCheck, [&](int code) -> int {
|
Sleep(100);
|
CString strMsg;
|
|
if (code == WOK) {
|
LOGI("%s Port 成功.", bCheck ? _T("enable") : _T("disable"));
|
|
msgDlg.DelayClose(3000);
|
strMsg.Format(_T("%s Port 成功."), bCheck ? _T("enable") : _T("disable"));
|
msgDlg.DelayClose(3000);
|
msgDlg.SetIcon(MSG_BOX_SUCCEED);
|
msgDlg.SetTitle(_T("操作成功"));
|
msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
|
msgDlg.SetMarquee(FALSE, 0);
|
msgDlg.SetCompleteCode(0);
|
}
|
else {
|
LOGI("%s Port 失败,code:%d", bCheck ? _T("enable") : _T("disable"), code);
|
|
msgDlg.DelayClose(3000);
|
strMsg.Format(_T("%s Port 失败,code:%d"), bCheck ? _T("enable") : _T("disable"), code);
|
msgDlg.DelayClose(3000);
|
msgDlg.SetIcon(MSG_BOX_ERROR);
|
msgDlg.SetTitle(_T("操作失败"));
|
msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
|
msgDlg.SetMarquee(FALSE, 0);
|
msgDlg.SetCompleteCode(-1);
|
|
// 还原控件状态
|
EnableCtrls(!bCheck);
|
((CButton*)GetDlgItem(IDC_CHECK_ENABLE))->SetCheck(!bCheck ? BST_CHECKED : BST_UNCHECKED);
|
}
|
|
return 0;
|
});
|
|
msgDlg.DoModal();
|
}
|
|
void CPagePortProperty::OnCbnSelchangeComboPortType()
|
{
|
CMsgDlg msgDlg("请等待", "正在操作,请等待...");
|
msgDlg.SetData((DWORD_PTR)this);
|
|
ASSERT(m_pPort != nullptr);
|
int index = ((CComboBox*)GetDlgItem(IDC_COMBO_PORT_TYPE))->GetCurSel();
|
m_pPort->setPortType(SERVO::PortType(index + 1), [&](int code) -> int {
|
Sleep(100);
|
CString strMsg;
|
|
if (code == WOK) {
|
LOGI("设置Port Type(%d)成功.", index + 1);
|
|
msgDlg.DelayClose(3000);
|
strMsg.Format(_T("设置Port Type(%d)成功"), index + 1);
|
msgDlg.DelayClose(3000);
|
msgDlg.SetIcon(MSG_BOX_SUCCEED);
|
msgDlg.SetTitle(_T("操作成功"));
|
msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
|
msgDlg.SetMarquee(FALSE, 0);
|
msgDlg.SetCompleteCode(0);
|
}
|
else {
|
LOGI("设置Port Type(%d)失败,code:%d", index + 1, code);
|
|
msgDlg.DelayClose(3000);
|
strMsg.Format(_T("设置Port Type(%d)失败,code:%d"), index + 1, code);
|
msgDlg.DelayClose(3000);
|
msgDlg.SetIcon(MSG_BOX_ERROR);
|
msgDlg.SetTitle(_T("操作失败"));
|
msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
|
msgDlg.SetMarquee(FALSE, 0);
|
msgDlg.SetCompleteCode(-1);
|
}
|
|
return 0;
|
});
|
|
msgDlg.DoModal();
|
}
|
|
void CPagePortProperty::OnCbnSelchangeComboPortMode()
|
{
|
CMsgDlg msgDlg("请等待", "正在操作,请等待...");
|
msgDlg.SetData((DWORD_PTR)this);
|
|
ASSERT(m_pPort != nullptr);
|
int index = ((CComboBox*)GetDlgItem(IDC_COMBO_PORT_MODE))->GetCurSel();
|
m_pPort->setPortMode(SERVO::PortMode(index), [&](int code) -> int {
|
Sleep(100);
|
CString strMsg;
|
|
if (code == WOK) {
|
LOGI("设置Port Mode(%d)成功.", index);
|
|
msgDlg.DelayClose(3000);
|
strMsg.Format(_T("设置Port Mode(%d)成功"), index);
|
msgDlg.DelayClose(3000);
|
msgDlg.SetIcon(MSG_BOX_SUCCEED);
|
msgDlg.SetTitle(_T("操作成功"));
|
msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
|
msgDlg.SetMarquee(FALSE, 0);
|
msgDlg.SetCompleteCode(0);
|
}
|
else {
|
LOGI("设置Port Mode(%d)失败,code:%d", index, code);
|
|
msgDlg.DelayClose(3000);
|
strMsg.Format(_T("设置Port Mode(%d)失败,code:%d"), index, code);
|
msgDlg.DelayClose(3000);
|
msgDlg.SetIcon(MSG_BOX_ERROR);
|
msgDlg.SetTitle(_T("操作失败"));
|
msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
|
msgDlg.SetMarquee(FALSE, 0);
|
msgDlg.SetCompleteCode(-1);
|
}
|
|
return 0;
|
});
|
|
msgDlg.DoModal();
|
}
|
|
void CPagePortProperty::OnCbnSelchangeComboPortCassertType()
|
{
|
CMsgDlg msgDlg("请等待", "正在操作,请等待...");
|
msgDlg.SetData((DWORD_PTR)this);
|
|
ASSERT(m_pPort != nullptr);
|
int index = ((CComboBox*)GetDlgItem(IDC_COMBO_PORT_CASSERT_TYPE))->GetCurSel();
|
m_pPort->setPortMode(SERVO::PortMode(index + 1), [&](int code) -> int {
|
Sleep(100);
|
CString strMsg;
|
|
if (code == WOK) {
|
LOGI("设置Cassette type(%d)成功.", index + 1);
|
|
msgDlg.DelayClose(3000);
|
strMsg.Format(_T("设置Cassette type(%d)成功"), index + 1);
|
msgDlg.DelayClose(3000);
|
msgDlg.SetIcon(MSG_BOX_SUCCEED);
|
msgDlg.SetTitle(_T("操作成功"));
|
msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
|
msgDlg.SetMarquee(FALSE, 0);
|
msgDlg.SetCompleteCode(0);
|
}
|
else {
|
LOGI("设置Cassette type(%d)失败,code:%d", index + 1, code);
|
|
msgDlg.DelayClose(3000);
|
strMsg.Format(_T("设置Cassette type(%d)失败,code:%d"), index + 1, code);
|
msgDlg.DelayClose(3000);
|
msgDlg.SetIcon(MSG_BOX_ERROR);
|
msgDlg.SetTitle(_T("操作失败"));
|
msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
|
msgDlg.SetMarquee(FALSE, 0);
|
msgDlg.SetCompleteCode(-1);
|
}
|
|
return 0;
|
});
|
|
msgDlg.DoModal();
|
}
|
|
void CPagePortProperty::OnCbnSelchangeComboPortTransferMode()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
CMsgDlg msgDlg("请等待", "正在操作,请等待...");
|
msgDlg.SetData((DWORD_PTR)this);
|
|
ASSERT(m_pPort != nullptr);
|
int index = ((CComboBox*)GetDlgItem(IDC_COMBO_PORT_TRANSFER_MODE))->GetCurSel();
|
m_pPort->setPortMode(SERVO::PortMode(index + 1), [&](int code) -> int {
|
Sleep(100);
|
CString strMsg;
|
|
if (code == WOK) {
|
LOGI("设置Transfer mode(%d)成功.", index + 1);
|
|
msgDlg.DelayClose(3000);
|
strMsg.Format(_T("设置Transfer mode(%d)成功"), index + 1);
|
msgDlg.DelayClose(3000);
|
msgDlg.SetIcon(MSG_BOX_SUCCEED);
|
msgDlg.SetTitle(_T("操作成功"));
|
msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
|
msgDlg.SetMarquee(FALSE, 0);
|
msgDlg.SetCompleteCode(0);
|
}
|
else {
|
LOGI("设置Transfer mode(%d)失败,code:%d", index + 1, code);
|
|
msgDlg.DelayClose(3000);
|
strMsg.Format(_T("设置Transfer mode(%d)失败,code:%d"), index + 1, code);
|
msgDlg.DelayClose(3000);
|
msgDlg.SetIcon(MSG_BOX_ERROR);
|
msgDlg.SetTitle(_T("操作失败"));
|
msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
|
msgDlg.SetMarquee(FALSE, 0);
|
msgDlg.SetCompleteCode(-1);
|
}
|
|
return 0;
|
});
|
|
msgDlg.DoModal();
|
}
|
|
void CPagePortProperty::OnBnClickedCheckAutoChange()
|
{
|
BOOL bCheck = ((CButton*)GetDlgItem(IDC_CHECK_AUTO_CHANGE))->GetCheck() == BST_CHECKED;
|
EnableCtrls(bCheck);
|
|
|
// enable port
|
CMsgDlg msgDlg("请等待", "正在操作,请等待...");
|
|
ASSERT(m_pPort != nullptr);
|
m_pPort->eableAutoChange(bCheck, [&](int code) -> int {
|
Sleep(100);
|
CString strMsg;
|
|
if (code == WOK) {
|
LOGI("%s Auto Change 成功.", bCheck ? _T("enable") : _T("disable"));
|
|
msgDlg.DelayClose(3000);
|
strMsg.Format(_T("%s Auto Change 成功."), bCheck ? _T("enable") : _T("disable"));
|
msgDlg.DelayClose(3000);
|
msgDlg.SetIcon(MSG_BOX_SUCCEED);
|
msgDlg.SetTitle(_T("操作成功"));
|
msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
|
msgDlg.SetMarquee(FALSE, 0);
|
msgDlg.SetCompleteCode(0);
|
}
|
else {
|
LOGI("%s Auto Change 失败,code:%d", bCheck ? _T("enable") : _T("disable"), code);
|
|
msgDlg.DelayClose(3000);
|
strMsg.Format(_T("%s Auto Change 失败,code:%d"), bCheck ? _T("enable") : _T("disable"), code);
|
msgDlg.DelayClose(3000);
|
msgDlg.SetIcon(MSG_BOX_ERROR);
|
msgDlg.SetTitle(_T("操作失败"));
|
msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
|
msgDlg.SetMarquee(FALSE, 0);
|
msgDlg.SetCompleteCode(-1);
|
|
// 还原控件状态
|
((CButton*)GetDlgItem(IDC_CHECK_AUTO_CHANGE))->SetCheck(!bCheck ? BST_CHECKED : BST_UNCHECKED);
|
}
|
|
return 0;
|
});
|
|
msgDlg.DoModal();
|
}
|
|
void CPagePortProperty::EnableCtrls(BOOL bEnable)
|
{
|
GetDlgItem(IDC_COMBO_PORT_TYPE)->EnableWindow(bEnable);
|
GetDlgItem(IDC_COMBO_PORT_MODE)->EnableWindow(bEnable);
|
GetDlgItem(IDC_COMBO_PORT_CASSERT_TYPE)->EnableWindow(bEnable);
|
GetDlgItem(IDC_COMBO_PORT_TRANSFER_MODE)->EnableWindow(bEnable);
|
GetDlgItem(IDC_CHECK_AUTO_CHANGE)->EnableWindow(bEnable);
|
}
|