// PageUnit.cpp : ʵÏÖÎļþ
|
//
|
|
#include "stdafx.h"
|
#include "GangBond2860Emulator.h"
|
#include "PageUnit.h"
|
#include "afxdialogex.h"
|
#include <chrono>
|
|
|
// CPageUnit ¶Ô»°¿ò
|
|
IMPLEMENT_DYNAMIC(CPageUnit, CDialogEx)
|
|
CPageUnit::CPageUnit(CWnd* pParent /*=NULL*/)
|
: CDialogEx(IDD_PAGE_UNIT, pParent)
|
{
|
m_nIdIndex = 1;
|
m_nTvTime = 0;
|
for (int i = 0; i < 12; i++) {
|
m_fTmp[i] = 10.0f + i;
|
}
|
m_fAir = 300.0;
|
for (int i = 0; i < 5; i++) {
|
m_fPre[i] = 5000.0f + i;
|
}
|
m_nDoorState = 0;
|
}
|
|
CPageUnit::~CPageUnit()
|
{
|
}
|
|
void CPageUnit::DoDataExchange(CDataExchange* pDX)
|
{
|
CDialogEx::DoDataExchange(pDX);
|
}
|
|
|
BEGIN_MESSAGE_MAP(CPageUnit, CDialogEx)
|
ON_CBN_SELCHANGE(IDC_COMBO_STATE, &CPageUnit::OnCbnSelchangeComboState)
|
ON_BN_CLICKED(IDC_RADIO_CLOSE1, &CPageUnit::OnBnClickedRadioClose1)
|
ON_BN_CLICKED(IDC_RADIO_OPEN1, &CPageUnit::OnBnClickedRadioOpen1)
|
ON_CBN_SELCHANGE(IDC_COMBO_ALARM, &CPageUnit::OnCbnSelchangeComboAlarm)
|
ON_BN_CLICKED(IDC_BUTTON_REMOVE, &CPageUnit::OnBnClickedButtonRemove)
|
ON_BN_CLICKED(IDC_BUTTON_STEP_NEXT, &CPageUnit::OnBnClickedButtonStepNext)
|
ON_WM_TIMER()
|
ON_BN_CLICKED(IDC_RADIO_CLOSE2, &CPageUnit::OnBnClickedRadioClose2)
|
ON_BN_CLICKED(IDC_RADIO_OPEN2, &CPageUnit::OnBnClickedRadioOpen2)
|
ON_BN_CLICKED(IDC_RADIO_CLOSE3, &CPageUnit::OnBnClickedRadioClose3)
|
ON_BN_CLICKED(IDC_RADIO_OPEN3, &CPageUnit::OnBnClickedRadioOpen3)
|
ON_BN_CLICKED(IDC_RADIO_CLOSE4, &CPageUnit::OnBnClickedRadioClose4)
|
ON_BN_CLICKED(IDC_RADIO_OPEN4, &CPageUnit::OnBnClickedRadioOpen4)
|
ON_BN_CLICKED(IDC_RADIO_CLOSE5, &CPageUnit::OnBnClickedRadioClose5)
|
ON_BN_CLICKED(IDC_RADIO_OPEN5, &CPageUnit::OnBnClickedRadioOpen5)
|
END_MESSAGE_MAP()
|
|
|
// CPageUnit ÏûÏ¢´¦Àí³ÌÐò
|
|
|
void CPageUnit::setName(const char* pszName)
|
{
|
m_strName = pszName;
|
}
|
|
BOOL CPageUnit::OnInitDialog()
|
{
|
CDialogEx::OnInitDialog();
|
|
|
// »úÆ÷״̬
|
CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_STATE);
|
pComboBox->AddString("IDLE");
|
pComboBox->AddString("RUN");
|
pComboBox->AddString("DOWN");
|
pComboBox->AddString("MAINTENANCE");
|
pComboBox->AddString("MCHG");
|
pComboBox->AddString("E_TIME");
|
pComboBox->SetCurSel(0);
|
|
|
// ¸æ¾¯ÐÅÏ¢ÑÝʾ
|
pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_ALARM);
|
pComboBox->AddString("ûÓи澯ÐÅÏ¢");
|
pComboBox->AddString("1,A¼±Í£_01");
|
pComboBox->AddString("201,ÉÏÇ»ÌåѹºÏZÖá1Òì³£");
|
pComboBox->AddString("212,·ÖÀ뽺¹õµ÷½ÚZÖáÒì³£");
|
pComboBox->AddString("501,·ÖÀëĤÊÕĤѹ½ôÆø¸×Òì³£");
|
pComboBox->SetCurSel(0);
|
|
|
// ÖÆ³Ì
|
pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_STEP);
|
pComboBox->AddString("IDLE");
|
pComboBox->AddString("MATERIAL_RECEIVED");
|
pComboBox->AddString("PROCESSING_STARTED");
|
pComboBox->AddString("PROCESSING");
|
pComboBox->AddString("PROCESSING_COMPLETED");
|
pComboBox->AddString("MATERIAL_REMOVEED");
|
pComboBox->SetCurSel(0);
|
|
|
// Åä·½
|
CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LIST_RECIPE);
|
pListBox->AddString("1,RECIPE1");
|
pListBox->AddString("2,RECIPE2");
|
pListBox->AddString("3,RECIPE3");
|
|
|
// ÃÅ״̬Á½¸ö°´Å¥
|
CButton* pRadioClose = (CButton*)GetDlgItem(IDC_RADIO_CLOSE1);
|
pRadioClose->SetCheck(BST_CHECKED);
|
pRadioClose = (CButton*)GetDlgItem(IDC_RADIO_CLOSE2);
|
pRadioClose->SetCheck(BST_CHECKED);
|
pRadioClose = (CButton*)GetDlgItem(IDC_RADIO_CLOSE3);
|
pRadioClose->SetCheck(BST_CHECKED);
|
pRadioClose = (CButton*)GetDlgItem(IDC_RADIO_CLOSE4);
|
pRadioClose->SetCheck(BST_CHECKED);
|
pRadioClose = (CButton*)GetDlgItem(IDC_RADIO_CLOSE5);
|
pRadioClose->SetCheck(BST_CHECKED);
|
|
SetTimer(2, 2000, nullptr);
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
// Òì³£: OCX ÊôÐÔÒ³Ó¦·µ»Ø FALSE
|
}
|
|
|
void CPageUnit::OnCbnSelchangeComboState()
|
{
|
BEQ::IEquipment* pEquipment = theApp.m_model.getEquipment();
|
if (pEquipment == nullptr) return;
|
BEQ::IUnit* pUnit = pEquipment->getUnit((LPTSTR)(LPCTSTR)m_strName);
|
if (pUnit == nullptr) return;
|
|
CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_STATE);
|
int state = pComboBox->GetCurSel();
|
pUnit->setState((BEQ::EQ_STATE)state);
|
}
|
|
void CPageUnit::OnBnClickedRadioClose1()
|
{
|
BEQ::IEquipment* pEquipment = theApp.m_model.getEquipment();
|
if (pEquipment == nullptr) return;
|
BEQ::IUnit* pUnit = pEquipment->getUnit((LPTSTR)(LPCTSTR)m_strName);
|
if (pUnit == nullptr) return;
|
|
m_nDoorState &= ~(0x1 << 0);
|
pUnit->setDoorState(m_nDoorState);
|
}
|
|
void CPageUnit::OnBnClickedRadioOpen1()
|
{
|
BEQ::IEquipment* pEquipment = theApp.m_model.getEquipment();
|
if (pEquipment == nullptr) return;
|
BEQ::IUnit* pUnit = pEquipment->getUnit((LPTSTR)(LPCTSTR)m_strName);
|
if (pUnit == nullptr) return;
|
|
m_nDoorState |= (0x1 << 0);
|
pUnit->setDoorState(m_nDoorState);
|
}
|
|
void CPageUnit::OnBnClickedRadioClose2()
|
{
|
BEQ::IEquipment* pEquipment = theApp.m_model.getEquipment();
|
if (pEquipment == nullptr) return;
|
BEQ::IUnit* pUnit = pEquipment->getUnit((LPTSTR)(LPCTSTR)m_strName);
|
if (pUnit == nullptr) return;
|
|
m_nDoorState &= ~(0x1 << 1);
|
pUnit->setDoorState(m_nDoorState);
|
}
|
|
|
void CPageUnit::OnBnClickedRadioOpen2()
|
{
|
BEQ::IEquipment* pEquipment = theApp.m_model.getEquipment();
|
if (pEquipment == nullptr) return;
|
BEQ::IUnit* pUnit = pEquipment->getUnit((LPTSTR)(LPCTSTR)m_strName);
|
if (pUnit == nullptr) return;
|
|
m_nDoorState |= (0x1 << 1);
|
pUnit->setDoorState(m_nDoorState);
|
}
|
|
|
void CPageUnit::OnBnClickedRadioClose3()
|
{
|
BEQ::IEquipment* pEquipment = theApp.m_model.getEquipment();
|
if (pEquipment == nullptr) return;
|
BEQ::IUnit* pUnit = pEquipment->getUnit((LPTSTR)(LPCTSTR)m_strName);
|
if (pUnit == nullptr) return;
|
|
m_nDoorState &= ~(0x1 << 2);
|
pUnit->setDoorState(m_nDoorState);
|
}
|
|
|
void CPageUnit::OnBnClickedRadioOpen3()
|
{
|
BEQ::IEquipment* pEquipment = theApp.m_model.getEquipment();
|
if (pEquipment == nullptr) return;
|
BEQ::IUnit* pUnit = pEquipment->getUnit((LPTSTR)(LPCTSTR)m_strName);
|
if (pUnit == nullptr) return;
|
|
m_nDoorState |= (0x1 << 2);
|
pUnit->setDoorState(m_nDoorState);
|
}
|
|
|
void CPageUnit::OnBnClickedRadioClose4()
|
{
|
BEQ::IEquipment* pEquipment = theApp.m_model.getEquipment();
|
if (pEquipment == nullptr) return;
|
BEQ::IUnit* pUnit = pEquipment->getUnit((LPTSTR)(LPCTSTR)m_strName);
|
if (pUnit == nullptr) return;
|
|
m_nDoorState &= ~(0x1 << 3);
|
pUnit->setDoorState(m_nDoorState);
|
}
|
|
|
void CPageUnit::OnBnClickedRadioOpen4()
|
{
|
BEQ::IEquipment* pEquipment = theApp.m_model.getEquipment();
|
if (pEquipment == nullptr) return;
|
BEQ::IUnit* pUnit = pEquipment->getUnit((LPTSTR)(LPCTSTR)m_strName);
|
if (pUnit == nullptr) return;
|
|
m_nDoorState |= (0x1 << 3);
|
pUnit->setDoorState(m_nDoorState);
|
}
|
|
|
void CPageUnit::OnBnClickedRadioClose5()
|
{
|
BEQ::IEquipment* pEquipment = theApp.m_model.getEquipment();
|
if (pEquipment == nullptr) return;
|
BEQ::IUnit* pUnit = pEquipment->getUnit((LPTSTR)(LPCTSTR)m_strName);
|
if (pUnit == nullptr) return;
|
|
m_nDoorState &= ~(0x1 << 4);
|
pUnit->setDoorState(m_nDoorState);
|
}
|
|
|
void CPageUnit::OnBnClickedRadioOpen5()
|
{
|
BEQ::IEquipment* pEquipment = theApp.m_model.getEquipment();
|
if (pEquipment == nullptr) return;
|
BEQ::IUnit* pUnit = pEquipment->getUnit((LPTSTR)(LPCTSTR)m_strName);
|
if (pUnit == nullptr) return;
|
|
m_nDoorState |= (0x1 << 4);
|
pUnit->setDoorState(m_nDoorState);
|
}
|
|
void CPageUnit::OnCbnSelchangeComboAlarm()
|
{
|
BEQ::IEquipment* pEquipment = theApp.m_model.getEquipment();
|
if (pEquipment == nullptr) return;
|
BEQ::IUnit* pUnit = pEquipment->getUnit((LPTSTR)(LPCTSTR)m_strName);
|
if (pUnit == nullptr) return;
|
|
CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_ALARM);
|
int index = pComboBox->GetCurSel();
|
if (index == 0) {
|
pUnit->setAlarm(0, 0, "");
|
}
|
else if (index == 1) {
|
pUnit->setAlarm(1, 1, "¼±Í£_01");
|
}
|
else if (index == 2) {
|
pUnit->setAlarm(201, 1, "ÉÏÇ»ÌåѹºÏZÖá1Òì³£");
|
}
|
else if (index == 3) {
|
pUnit->setAlarm(212, 1, "·ÖÀ뽺¹õµ÷½ÚZÖáÒì³£");
|
}
|
else if (index == 4) {
|
pUnit->setAlarm(501, 1, "·ÖÀëĤÊÕĤѹ½ôÆø¸×Òì³£");
|
}
|
}
|
|
void CPageUnit::OnBnClickedButtonRemove()
|
{
|
BEQ::IEquipment* pEquipment = theApp.m_model.getEquipment();
|
if (pEquipment == nullptr) return;
|
BEQ::IUnit* pUnit = pEquipment->getUnit((LPTSTR)(LPCTSTR)m_strName);
|
if (pUnit == nullptr) return;
|
|
CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_ALARM);
|
pComboBox->SetCurSel(0);
|
pUnit->setAlarm(0, 0, "");
|
}
|
|
void CPageUnit::OnBnClickedButtonStepNext()
|
{
|
BEQ::IEquipment* pEquipment = theApp.m_model.getEquipment();
|
if (pEquipment == nullptr) return;
|
BEQ::IUnit* pUnit = pEquipment->getUnit((LPTSTR)(LPCTSTR)m_strName);
|
if (pUnit == nullptr) return;
|
|
CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_STEP);
|
int index = pComboBox->GetCurSel();
|
if (index == 0) {
|
m_strID.Format("%s%06d", m_strName, m_nIdIndex);
|
m_strID.Delete(0, 4);
|
m_nIdIndex++;
|
SetDlgItemText(IDC_EDIT_ID, m_strID);
|
|
pUnit->stepMaterialReceived((LPTSTR)(LPCTSTR)m_strID);
|
pComboBox->SetCurSel(1);
|
}
|
else if (index == 1) {
|
GetDlgItemText(IDC_EDIT_ID, m_strID);
|
pUnit->stepProcessingStarted((LPTSTR)(LPCTSTR)m_strID);
|
pComboBox->SetCurSel(2);
|
}
|
else if (index == 2) {
|
GetDlgItemText(IDC_EDIT_ID, m_strID);
|
pComboBox->SetCurSel(3);
|
GetDlgItem(IDC_BUTTON_STEP_NEXT)->EnableWindow(FALSE);
|
SetTimer(1, 1000, nullptr);
|
}
|
else if (index == 3) {
|
GetDlgItemText(IDC_EDIT_ID, m_strID);
|
pUnit->stepProcessingCompleted((LPTSTR)(LPCTSTR)m_strID);
|
pComboBox->SetCurSel(4);
|
}
|
else if (index == 4) {
|
GetDlgItemText(IDC_EDIT_ID, m_strID);
|
pUnit->stepMaterialRemoved((LPTSTR)(LPCTSTR)m_strID);
|
pComboBox->SetCurSel(5);
|
}
|
else if (index == 5) {
|
GetDlgItemText(IDC_EDIT_ID, m_strID);
|
pUnit->stepIdle();
|
pComboBox->SetCurSel(0);
|
}
|
}
|
|
void CPageUnit::OnTimer(UINT_PTR nIDEvent)
|
{
|
if (1 == nIDEvent) {
|
BEQ::IUnit* pUnit = nullptr;
|
BEQ::IEquipment* pEquipment = theApp.m_model.getEquipment();
|
if (pEquipment != nullptr) {
|
pUnit = pEquipment->getUnit((LPTSTR)(LPCTSTR)m_strName);
|
}
|
|
static int index = 0;
|
index++;
|
if (index % 3 == 0) {
|
m_nTvTime++;
|
if (pUnit != nullptr) {
|
pUnit->stepProcessing((LPTSTR)(LPCTSTR)m_strID, 3, m_nTvTime);
|
}
|
|
if (m_nTvTime == 3) {
|
m_nTvTime = 0;
|
GetDlgItem(IDC_BUTTON_STEP_NEXT)->EnableWindow(TRUE);
|
KillTimer(1);
|
}
|
}
|
|
|
// ´«¸ÐÆ÷Êý¾Ý
|
CString strTmp, strAir, strPre;
|
for (int i = 0; i < 12; i++) {
|
m_fTmp[i] += 1;
|
strTmp.AppendFormat("%.2f,", m_fTmp[i]);
|
}
|
strTmp.Delete(strTmp.GetLength() - 1);
|
SetDlgItemText(IDC_EDIT_TEMP, strTmp);
|
|
m_fAir += 1;
|
strAir.Format("%.2f", m_fAir);
|
SetDlgItemText(IDC_EDIT_AIR, strAir);
|
|
for (int i = 0; i < 5; i++) {
|
m_fPre[i] += 1;
|
strPre.AppendFormat("%.2f,", m_fPre[i]);
|
}
|
strPre.Delete(strPre.GetLength() - 1);
|
SetDlgItemText(IDC_EDIT_PRE, strPre);
|
|
if (pUnit != nullptr) {
|
auto now = std::chrono::system_clock::now();
|
auto duration_in_milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
|
uint64_t timestamp = duration_in_milliseconds.count();
|
pUnit->setDataTimeAndResetData(timestamp);
|
pUnit->addData("TMP", (LPTSTR)(LPCTSTR)strTmp, false);
|
pUnit->addData("AIR", (LPTSTR)(LPCTSTR)strAir, false);
|
pUnit->addData("PRE", (LPTSTR)(LPCTSTR)strPre, true);
|
}
|
}
|
else if (2 == nIDEvent) {
|
int id = theApp.m_model.getRecipeName((LPTSTR)(LPCTSTR)m_strName);
|
CString strText;
|
strText.Format(_T("ÒÑÇл»µ½Åä·½: %d"), id);
|
SetDlgItemText(IDC_LABEL_RUN_RECIPE, strText);
|
}
|
|
CDialogEx::OnTimer(nIDEvent);
|
}
|