📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "PLC_DEMO.h"
#include "PLC_DEMODoc.h"
#include "PLC_DEMOView.h"
#include "MainFrm.h"
#include "Input_link.h"
#include "Output_link.h"
#include "PLCcontrol.h"
#include "choosepoint.h"
#include "Auto_truck_load.h"
#include "Traffic_lump_control.h"
#include "Instruction_define.h"
#include "Run_experiment.h"
#include "Makesure_in_out_point.h"
#include "Object_check.h"
#include "Explain.h"
#include "Explain_experiment.h"
#include "Write_inandout_point.h"
#include "Experiment_help.h"
#include "Truck_help.h"
#include "Traffic_help.h"
#include "Object_help.h"
#include "Experiment_watch.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
bool beginsetchoose=false;
bool runthread=false;
CPLCcontrol *newPLC=NULL;
Cchoosepoint *newchoose=NULL;
CTruck_help *newtruckhelp=NULL;
CTraffic_help *newtraffichelp=NULL;
CObject_help *newobjecthelp=NULL;
CExplain *newexplain=NULL;
CExperiment_help *newhelp=NULL;
bool menuchecksign=false;
extern bool WY[160];
extern bool canexplain;
extern bool inputenable;
extern bool outputenable;
extern int stockinputlink[7][7];
extern int stockoutputlink[9][7];
extern stocknumber;
extern stockoutnumber;
extern bool inputcheck;
extern bool switchcheck;
extern bool outputcheck;
extern bool outcontrolcheck;
extern CPLC_DEMOView *fordraw,*forrun;
extern bool autotruckenable;
extern int currentlinksign;
extern bool beginset;
extern bool trafficlumpenable;
extern bool objectcheckenable;
extern Cchoosepoint *forchoose;
extern bool objectcheckenable;
extern CPLC_DEMOView* forrun;
void makesure_objectcheck();
void autotruckdraw();
void runtheexperiment();
void auto_truck_startset();
void explain_experiment();
void traffic_lump_beginset();
void draw_object_check();
void makesure_trafficlumpcontrol();
void object_check_startset();
void makesure_autotruck();
void storepoint();
void drawpoint();
void startinitializtion();
void input_fetch_message();
void output_fetch_message();
void auto_truck_outresult();
void Runtheplcprogram();
UINT Mywatch(LPVOID);
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_COMMAND(ID_PLC_START_UP, OnPlcStartUp)
ON_COMMAND(ID_CLOSE_PLC, OnClosePlc)
ON_COMMAND(ID_CLEARLINK, OnClearlink)
ON_COMMAND(ID_AUTOTRUCKLOAD, OnAutotruckload)
ON_COMMAND(ID_RUNEXPERIMENT, OnRunexperiment)
ON_COMMAND(ID_LINKLINE, OnLinkline)
ON_COMMAND(ID_REPEALLINK, OnRepeallink)
ON_COMMAND(ID_BEGINSET, OnBeginset)
ON_COMMAND(ID_ENDEXPERIMENT, OnEndexperiment)
ON_COMMAND(ID_CLOSEWORKSPACE, OnCloseworkspace)
ON_COMMAND(ID_TRAFFICLUMPCONTROL, OnTrafficlumpcontrol)
ON_COMMAND(ID_STARTCHOOSE, OnStartchoose)
ON_COMMAND(ID_CLOSECHOOSE, OnClosechoose)
ON_COMMAND(ID_OBJECTCHECK, OnObjectcheck)
ON_COMMAND(ID_EXPLAIN_START, OnExplainStart)
ON_COMMAND(ID_EXPLAIN_CLOSE, OnExplainClose)
ON_COMMAND(ID_USE_SHOW, OnUseShow)
ON_COMMAND(ID_TRUCK_HELP, OnTruckHelp)
ON_COMMAND(ID_TRAFFIC_HELP, OnTrafficHelp)
ON_COMMAND(ID_OBJECT_HELP, OnObjectHelp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnPlcStartUp() //启动PLC对话框
{
// TODO: Add your command handler code here
if(!newPLC)
newPLC=new CPLCcontrol(this);
else newPLC->ShowWindow(SW_SHOW);
}
void CMainFrame::OnClosePlc() //关闭PLC对话框
{
// TODO: Add your command handler code here
if(newPLC)
{
delete newPLC;
newPLC=NULL;
}
}
void CMainFrame::OnClearlink() //清除线段
{
// TODO: Add your command handler code here
for(int i=0;i<7;i++)
stockinputlink[i][0]=0;
for(i=0;i<9;i++)
stockoutputlink[i][0]=0;
fordraw->Invalidate();
stocknumber=0;
stockoutnumber=0;
inputcheck=false;
switchcheck=false;
outputcheck=false;
outcontrolcheck=false;
}
void CMainFrame::OnAutotruckload()
{
// TODO: Add your command handler code here
CMenu* thisMenu=this->GetMenu();
thisMenu->CheckMenuItem(ID_TRAFFICLUMPCONTROL,MF_UNCHECKED);
thisMenu->CheckMenuItem(ID_AUTOTRUCKLOAD,MF_CHECKED);
thisMenu->CheckMenuItem(ID_OBJECTCHECK,MF_UNCHECKED);
autotruckenable=true;
trafficlumpenable=false;
objectcheckenable=false;
forrun->Invalidate();
}
UINT Myrun(LPVOID PHWndView) //线程
{
runthread=true;
while(runthread)
{
input_fetch_message();
Runtheplcprogram();
output_fetch_message();
runtheexperiment();
explain_experiment();
}
if(!runthread)
{
for(int i=1;i<31;i++);
forrun->KillTimer(i);
forrun->Invalidate();
}
return(0);
}
void CMainFrame::OnRunexperiment() //运行实验
{
// TODO: Add your command handler code here
CMenu *thisMenu=this->GetMenu();
thisMenu->CheckMenuItem(ID_RUNEXPERIMENT,MF_CHECKED);
thisMenu->CheckMenuItem(ID_ENDEXPERIMENT,MF_UNCHECKED);
thisMenu->CheckMenuItem(ID_CLOSEWORKSPACE,MF_UNCHECKED);
if(autotruckenable)
{
auto_truck_startset();
makesure_autotruck();
}
if(trafficlumpenable)
{
traffic_lump_beginset();
makesure_trafficlumpcontrol();
}
if(objectcheckenable)
{
object_check_startset();
makesure_objectcheck();
}
if(((autotruckenable)||(trafficlumpenable))||(objectcheckenable))
{
startinitializtion();
forrun->m_pxian1=AfxBeginThread(Myrun,&m_hWnd,
THREAD_PRIORITY_BELOW_NORMAL,0,NULL);
forrun->m_pxian2=AfxBeginThread(Mywatch,&m_hWnd,
THREAD_PRIORITY_BELOW_NORMAL,0,NULL);
}
}
void CMainFrame::OnLinkline() //连线
{
// TODO: Add your command handler code here
menuchecksign=(menuchecksign?false:true);
if(menuchecksign)
{
inputenable=true;
outputenable=true;
CMenu* thisMenu=this->GetMenu();
thisMenu->CheckMenuItem(ID_LINKLINE,MF_CHECKED);
}
else
{
inputenable=false;
outputenable=false;
CMenu* thisMenu=this->GetMenu();
thisMenu->CheckMenuItem(ID_LINKLINE,MF_UNCHECKED);
}
}
void CMainFrame::OnRepeallink() //撤消线段
{
// TODO: Add your command handler code here
if(currentlinksign==1)
{
if(stocknumber!=0)
{
stocknumber-=1;
stockinputlink[stocknumber][0]=0;
forrun->Invalidate();
}
}
else if(currentlinksign==2)
{
if(stockoutnumber!=0)
{
stockoutnumber-=1;
stockoutputlink[stockoutnumber][0]=0;
forrun->Invalidate();
}
}
}
void CMainFrame::OnBeginset() //初始状态设置
{
// TODO: Add your command handler code here
beginsetchoose=(beginsetchoose?false:true);
if(beginsetchoose)
{
CMenu* thisMenu=this->GetMenu();
thisMenu->CheckMenuItem(ID_BEGINSET,MF_CHECKED);
beginset=true;
}
else
{
CMenu* thisMenu=this->GetMenu();
thisMenu->CheckMenuItem(ID_BEGINSET,MF_UNCHECKED);
beginset=false;
}
}
void CMainFrame::OnEndexperiment() //结束实验
{
// TODO: Add your command handler code here
CMenu* thisMenu=this->GetMenu();
thisMenu->CheckMenuItem(ID_RUNEXPERIMENT,MF_UNCHECKED);
thisMenu->CheckMenuItem(ID_ENDEXPERIMENT,MF_CHECKED);
thisMenu->CheckMenuItem(ID_CLOSEWORKSPACE,MF_UNCHECKED);
if(runthread)
{
runthread=false;
forrun->m_pxian1->ExitInstance();
}
}
void CMainFrame::OnCloseworkspace() //关闭工作区
{
// TODO: Add your command handler code here
CMenu* thisMenu=this->GetMenu();
thisMenu->CheckMenuItem(ID_RUNEXPERIMENT,MF_UNCHECKED);
thisMenu->CheckMenuItem(ID_ENDEXPERIMENT,MF_UNCHECKED);
thisMenu->CheckMenuItem(ID_CLOSEWORKSPACE,MF_CHECKED);
thisMenu->CheckMenuItem(ID_LINKLINE,MF_UNCHECKED);
thisMenu->CheckMenuItem(ID_BEGINSET,MF_UNCHECKED);
menuchecksign=false;
beginsetchoose=false;
runthread=false;
beginset=false;
autotruckenable=false;
trafficlumpenable=false;
objectcheckenable=false;
inputenable=false;
outputenable=false;
for(int i=0;i<7;i++)
stockinputlink[i][0]=0;
for(i=0;i<9;i++)
stockoutputlink[i][0]=0;
stocknumber=0;
stockoutnumber=0;
inputcheck=false;
switchcheck=false;
outputcheck=false;
outcontrolcheck=false;
forrun->Invalidate();
if(newchoose)
{
forchoose->m_ninputedit1.Empty();
forchoose->m_ninputedit2.Empty();
forchoose->m_ninputedit3.Empty();
forchoose->m_ninputedit4.Empty();
forchoose->m_ninputedit5.Empty();
forchoose->m_ninputedit6.Empty();
forchoose->m_ninputedit7.Empty();
forchoose->m_noutputedit1.Empty();
forchoose->m_noutputedit2.Empty();
forchoose->m_noutputedit3.Empty();
forchoose->m_noutputedit4.Empty();
forchoose->m_noutputedit5.Empty();
forchoose->m_noutputedit6.Empty();
forchoose->m_noutputedit7.Empty();
forchoose->m_noutputedit8.Empty();
forchoose->m_noutputedit9.Empty();
forchoose->UpdateData(false);
forchoose->UpdateData();
storepoint();
drawpoint();
}
}
void CMainFrame::OnTrafficlumpcontrol()
{
// TODO: Add your command handler code here
CMenu* thisMenu=this->GetMenu();
thisMenu->CheckMenuItem(ID_TRAFFICLUMPCONTROL,MF_CHECKED);
thisMenu->CheckMenuItem(ID_AUTOTRUCKLOAD,MF_UNCHECKED);
thisMenu->CheckMenuItem(ID_OBJECTCHECK,MF_UNCHECKED);
trafficlumpenable=true;
autotruckenable=false;
objectcheckenable=false;
forrun->Invalidate();
}
void CMainFrame::OnStartchoose() //启动输入输出点选择对话框
{
// TODO: Add your command handler code here
if(!newchoose)
newchoose=new Cchoosepoint(this);
else newchoose->ShowWindow(SW_SHOW);
}
void CMainFrame::OnClosechoose() //关闭输入输出点选择对话框
{
// TODO: Add your command handler code here
if(newchoose)
{
delete newchoose;
newchoose=NULL;
}
}
void CMainFrame::OnObjectcheck()
{
// TODO: Add your command handler code here
CMenu* thisMenu=this->GetMenu();
thisMenu->CheckMenuItem(ID_TRAFFICLUMPCONTROL,MF_UNCHECKED);
thisMenu->CheckMenuItem(ID_AUTOTRUCKLOAD,MF_UNCHECKED);
thisMenu->CheckMenuItem(ID_OBJECTCHECK,MF_CHECKED);
trafficlumpenable=false;
autotruckenable=false;
objectcheckenable=true;
forrun->Invalidate();
}
void CMainFrame::OnExplainStart()
{
// TODO: Add your command handler code here
if(!newexplain)
{
newexplain=new CExplain(this);
canexplain=true;
}
else newexplain->ShowWindow(SW_SHOW);
}
void CMainFrame::OnExplainClose()
{
// TODO: Add your command handler code here
if(newexplain)
{
delete newexplain;
newexplain=NULL;
canexplain=false;
}
}
void CMainFrame::OnUseShow() //使用说明对话框
{
// TODO: Add your command handler code here
if(!newhelp)
newhelp=new CExperiment_help(this);
else newhelp->ShowWindow(SW_SHOW);
}
void CMainFrame::OnTruckHelp()
{
// TODO: Add your command handler code here
if(!newtruckhelp)
newtruckhelp=new CTruck_help(this);
else newtruckhelp->ShowWindow(SW_SHOW);
}
void CMainFrame::OnTrafficHelp()
{
// TODO: Add your command handler code here
if(!newtraffichelp)
newtraffichelp=new CTraffic_help(this);
else newtraffichelp->ShowWindow(SW_SHOW);
}
void CMainFrame::OnObjectHelp()
{
// TODO: Add your command handler code here
if(!newobjecthelp)
newobjecthelp=new CObject_help(this);
else newobjecthelp->ShowWindow(SW_SHOW);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -