You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
9.3 KiB
C++

#include "StdAfx.h"
#include "WorkCmdInvoker.h"
#include "GlobalFunction.h"
#include "MsgBox.h"
#include "FileMgr.h"
#include "WorkCmdContainer.h"
#include "ExceptionMsg.h"
#include "ProgressMgr.h"
#include "CommonFlowMgr.h"
#include "ProgramLaserTuiHuo.h"
#include "Laser.h"
#include "WarningMgr.h"
#include "WorkRecord.h"
#include "CStringFuc.h"
#include "CriticalSection.h"
bool gStopAllWrokCmd = false;//全局开关
CWorkCmdInvoker gCmdInvoker_WaferTransfer;//负责管理wafer 传输cmd 的Invoker
CWorkCmdInvoker gCmdInvoker_WaferAneal;//负责管理wafer 退火cmd 的Invoker
CWorkCmdInvoker gCmdInvoker_ManualOperation;//负责管理手动操作 cmd 的Invoker
CWorkCmdInvoker gCmdInvoker_JobQueueCtrl;//用于job 控制的Invoker
CWorkCmdInvoker gCmdInvoker_FoupLoadPort1;//用于FoupLoadPort1 控制的Invoker
CWorkCmdInvoker gCmdInvoker_FoupLoadPort2;//用于FoupLoadPort2 控制的Invoker
CWorkCmdInvoker gCmdInvoker_TrheeLightCtrl;//用于TrheeLightCtrl 控制的Invoker
CWorkCmdInvoker gCmdInvoker_ClearWarning;//用于清除报警的Invoker
bool gAllCmdInvokerStopFlg = false;//用于停止所有CmdInvoker 的标识
CWorkCmdInvoker::CWorkCmdInvoker(void)
{
m_bExcutingStop = false;//是否停止cmd 的执行
m_bExcuting = false;//是否正在执行
m_bNeedUpdateCmdList = false;//是否需要刷新cmd 列表
m_bExcutingPause = false;//执行暂停
}
CWorkCmdInvoker::~CWorkCmdInvoker(void)
{
}
//指令线程执行函数
UINT ExcuteAllCmdThread(LPVOID pParam)
{
CWorkCmdInvoker *p = (CWorkCmdInvoker *)pParam;
p->ExcuteAllCmdExt();
return 0;
}
UINT ExcuteCmdThread(LPVOID pParam)
{
CWorkCmdInvoker *p = (CWorkCmdInvoker *)pParam;
p->ExcuteCmdExt();
return 0;
}
#if 1
//直接执行所有指令
void CWorkCmdInvoker::Excute()
{
//执行指令集
ExcuteAllCmd();
}
//执行指令集中所有的指令-------------------------------------------------
void CWorkCmdInvoker::ExcuteAllCmd(bool bNewThread,bool WaitForThread)
{
if(bNewThread)//在新的线程中执行
{
CWinThread* pThread = AfxBeginThread(ExcuteAllCmdThread,this);
if(WaitForThread)//等待线程结束
WaitForThreadExit(pThread);
}
else
{
ExcuteAllCmdExt();
}
}
void CWorkCmdInvoker::ExcuteAllCmdExt()
{
CWorkCmdContainer &CmdContainer = CWorkCmdContainer::GetInstance();
vector<Sptr<CWorkCmd>> &WorkCmdVec = CmdContainer.GetContainer();
//重新执行的时候重置停止状态
gStopAllWrokCmd = false;
m_bCancel = false;//指令是否终止
int size = WorkCmdVec.size();//用来计算进度
CString ErrMsg;
int CmdCnt = WorkCmdVec.size();//指令的数量
vector<Sptr<CWorkCmd>>::iterator iter = WorkCmdVec.begin();
vector<Sptr<CWorkCmd>>::iterator iter_end = WorkCmdVec.end();
for(double k = 1;iter!=iter_end;iter++,k += 1)
{
if(!m_bCancel && (gStopAllWrokCmd))
{
if(gCommonFlowMgr->IsbStopWorkMsg())//显示停止提示
{
CMsgBox MsgBox;
if(MsgBox.ConfirmOkCancel(_T("停止执行?")))
{
gLogMgr->WriteDebugLog(_T("func : ExcuteAllCmd---->Stop"));
m_bCancel = true;//停止
}
else//继续执行
{
gStopAllWrokCmd = false;
}
}
else
{
m_bCancel = true;//停止
}
}
try
{
m_bCancel = (*iter)->Work(m_bCancel);//如果有指令执行失败,强行终止
//进度
gProgressMgr.SetCurProgress(static_cast<int>(k),size);
}
catch(CExceptionMsg &Msg)
{
ErrMsg = Msg.GetMsgStr();
//设置错误提示信息
gCommonFlowMgr->SetErrMsg(ErrMsg);
gLogMgr->WriteDebugLog(ErrMsg);
m_bCancel = true;
//强制结束进度条
gProgressMgr.SetCurProgress(100,100);
}
}
gWorkRecordMgr->EndRecordTime();//停止计时
if(ErrMsg != "" && gCommonFlowMgr->IsbShowErrMsg())
{
CMsgBox MsgBox;
MsgBox.Show(ErrMsg);
}
}
#endif
#if 1
//添加指令
void CWorkCmdInvoker::AddCmd(CWorkCmd *p)
{
gCriticalSection_WorkCmdInvoker.Lock();
//保存到智能指针
Sptr<CWorkCmd> sPtr(p);
m_WorkCmdVec.push_back(sPtr);
m_bNeedUpdateCmdList = true;//是否需要刷新cmd 列表
gCriticalSection_WorkCmdInvoker.Unlock();
}
void CWorkCmdInvoker::ClearCmd()
{
gCriticalSection_WorkCmdInvoker.Lock();
m_WorkCmdVec.clear();
m_bNeedUpdateCmdList = true;//是否需要刷新cmd 列表
gCriticalSection_WorkCmdInvoker.Unlock();
};
void CWorkCmdInvoker::ExcuteCmd(bool bNewThread,bool WaitForThread)
{
if(bNewThread)//在新的线程中执行
{
CWinThread* pThread = AfxBeginThread(ExcuteCmdThread,this);
if(WaitForThread)//等待线程结束
WaitForThreadExit(pThread);
}
else
{
ExcuteCmdExt();
}
}
void CWorkCmdInvoker::ExcuteCmdExt()
{
m_bExcuting = true;//标记正在执行
m_InvokerWorkTime.StartRecordTime();//开始计时
CString Log;
Log = m_CmdInvokerName + "Start";
gLogMgr->WriteDebugLog(Log);
//重新执行的时候重置停止状态
gStopAllWrokCmd = false;
m_bCancel = false;//指令是否终止
int size = m_WorkCmdVec.size();//用来计算进度
CString ErrMsg;
vector<Sptr<CWorkCmd>>::iterator iter = m_WorkCmdVec.begin();
vector<Sptr<CWorkCmd>>::iterator iter_end = m_WorkCmdVec.end();
for(double k = 1;iter!=iter_end;iter++,k += 1)
{
if(!m_bCancel && (gStopAllWrokCmd || m_bExcutingStop))
{
m_bCancel = true;//停止
}
(*iter)->SetbExcuting(true);
while(m_bExcutingPause)//如果暂停了就一直等待
{
Sleep(500);
}
try
{
if(!m_bCancel)
{
CString s;
s = Int2Str_LeftZero(k) + " ";
s += (*iter)->GetWorkCmdInfoStr();
m_CurExcuteCmdInfo = s;
}
m_bCancel = (*iter)->Work(m_bCancel);//如果有指令执行失败,强行终止
}
catch(CExceptionMsg &Msg)
{
ErrMsg = Msg.GetMsgStr();
//设置错误提示信息
gCommonFlowMgr->SetErrMsg(ErrMsg);
gLogMgr->WriteDebugLog(ErrMsg);
m_bCancel = true;
}
(*iter)->SetbExcuting(false);
}
//恢复状态
m_bExcutingStop = false;
m_bExcutingPause = false;
m_bCancel = false;
m_InvokerWorkTime.StopRecordTime();//结束计时
Log = m_CmdInvokerName + "End";
gLogMgr->WriteDebugLog(Log);
if(ErrMsg != "" && gCommonFlowMgr->IsbShowErrMsg())
{
CMsgBox MsgBox;
MsgBox.Show(ErrMsg);
}
m_bExcuting = false;
}
//是否所有的cmd 都被执行了
bool CWorkCmdInvoker::IsAllCmdExcuted()
{
bool Ret = true;
vector<Sptr<CWorkCmd>>::iterator iter = m_WorkCmdVec.begin();
vector<Sptr<CWorkCmd>>::iterator iter_end = m_WorkCmdVec.end();
for(;iter!=iter_end;iter++)
{
if(!(*iter)->IsbExcuted())
{
Ret = false;
break;
}
}
return Ret;
}
void CWorkCmdInvoker::InitCmdList(CListCtrl &List)
{
//设置风格
List.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
//设置列
int idx = 0;
List.InsertColumn(idx,"Idx",LVCFMT_CENTER,50);
idx++;
List.InsertColumn(idx,"Step Info",LVCFMT_LEFT,400,-1);
idx++;
}
void CWorkCmdInvoker::UpdateCmdList(CListCtrl &List)
{
gCriticalSection_WorkCmdInvoker.Lock();
int size = m_WorkCmdVec.size();
if(m_bNeedUpdateCmdList)
{
List.DeleteAllItems();
}
else//防止行数量不一致
{
if(size != List.GetItemCount())
return;
}
int ExcuteIdx = 0;//当前执行的cmd
for(int k=0;k<size;k++)
{
CString CmdInfoStr = m_WorkCmdVec[k]->GetWorkCmdInfoStr();
if(m_bNeedUpdateCmdList)
List.InsertItem(k," ");
List.SetItemText(k,0,Int2Str_LeftZero(k+1));
List.SetItemText(k,1,CmdInfoStr);
if(m_WorkCmdVec[k]->IsbExcuted())
ExcuteIdx = k;
}
m_bNeedUpdateCmdList = false;
gCriticalSection_WorkCmdInvoker.Unlock();
}
COLORREF CWorkCmdInvoker::GetCmdListColor(int Idx)
{
COLORREF c = RGB_WHITE;
int size = m_WorkCmdVec.size();
if(Idx>=0&&Idx<size)
{
if(m_WorkCmdVec[Idx]->IsbExcuted())
c = RGB_BLUE1;
if(m_WorkCmdVec[Idx]->IsbExcuting())
c = RGB_YELLOW;
}
return c;
}
//设置暂停
void CWorkCmdInvoker::SetbExcutingPause(bool b)
{
m_bExcutingPause = b;
if(b)
{
CString log("Flow--->");
log += m_CmdInvokerName;
log += " ExcutingPause";
gLogMgr->WriteDebugLog(log);
}
}
#endif