flexibleview.cpp
来自「柔性制造是一种十分重要的加工生产模式」· C++ 代码 · 共 854 行 · 第 1/2 页
CPP
854 行
// flexibleView.cpp : implementation of the CFlexibleView class
//
#include "stdafx.h"
#include "flexible.h"
#include "flexibleDoc.h"
#include "flexibleView.h"
#include "gongjiandlg.h"
#include "gongjiangongyidlg.h"
#include "timeset.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFlexibleView
IMPLEMENT_DYNCREATE(CFlexibleView, CView)
BEGIN_MESSAGE_MAP(CFlexibleView, CView)
//{{AFX_MSG_MAP(CFlexibleView)
ON_COMMAND(ID_GONGJIANSHURU, OnGongjianshuru)
ON_COMMAND(ID_GONGJIANGONGYI, OnGongjiangongyi)
ON_COMMAND(ID_Start, OnStart)
ON_WM_MOUSEMOVE()
ON_WM_ERASEBKGND()
ON_COMMAND(ID_STOP, OnStop)
ON_COMMAND(ID_saddsaf, Onsaddsaf)
ON_COMMAND(ID_TIMESET, OnTimeset)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFlexibleView construction/destruction
CFlexibleView::CFlexibleView()
{
//SetTimer(1,1000,NULL);
CFlexibleApp *app = (CFlexibleApp *)AfxGetApp(); //生成指向应用程序类的指针
app->cheche.x=121;//初始化一开始的位置
x_car=121;
app->gw[0].x=app->gw[5].x=189;
app->gw[1].x=app->gw[6].x=290;
app->gw[2].x=app->gw[7].x=388;
app->gw[3].x=app->gw[8].x=489;
app->gw[4].x=app->gw[9].x=590;
///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
CRect rect11(95,336,900,403);
app->cheche.rect=rect11;
CRect rect0(189,305,277,333);
app->gw[0].rect=rect0;
CRect rect1(290,305,378,333);
app->gw[1].rect=rect1;
CRect rect2(388,305,476,333);
app->gw[2].rect=rect2;
CRect rect3(489,305,578,333);
app->gw[3].rect=rect3;
CRect rect4(591,305,677,333);
app->gw[4].rect=rect4;
CRect rect5(189,408,275,436);
app->gw[5].rect=rect5;
CRect rect6(290,408,378,436);
app->gw[6].rect=rect6;
CRect rect7(388,408,476,436);
app->gw[7].rect=rect7;
CRect rect8(489,408,578,436);
app->gw[8].rect=rect8;
CRect rect9(591,408,677,436);
app->gw[9].rect=rect9;
//////////////////////////////////////////////////////////////
app->gw[0].time_jiagong=app->gw[1].time_jiagong=app->gw[2].time_jiagong=app->gw[3].time_jiagong=app->gw[4].time_jiagong=app->gw[5].time_jiagong=app->gw[6].time_jiagong=app->gw[7].time_jiagong=app->gw[8].time_jiagong=app->gw[9].time_jiagong=0;
//////////////////////////////////////////////////////////////////////////////////
app->gw[0].str_status=app->gw[1].str_status=app->gw[2].str_status=app->gw[3].str_status=app->gw[4].str_status=app->gw[5].str_status=app->gw[6].str_status=app->gw[7].str_status=app->gw[8].str_status=app->gw[9].str_status="工位闲";
////////////////////////////////////////////////
}
CFlexibleView::~CFlexibleView()
{
}
BOOL CFlexibleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CFlexibleView drawing
void CFlexibleView::OnDraw(CDC* pDC)
{
CFlexibleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
textout(96,412,0,0,"小车的状态:",RGB(255,0,0));
textout(11,507,0,0,str_zhuangxiezhan,RGB(255,0,0));
textout(726,579,0,0,str_cangku,RGB(255,0,0));
CFlexibleApp *app = (CFlexibleApp *)AfxGetApp(); //生成指向应用程序类的指针
textout(97,440,0,0,app->cheche.str_status,RGB(255,0,0));
textout(app->gw[0].x,306,0,0,app->gw[0].str_status,RGB(0,0,255));
textout(app->gw[1].x,306,0,0,app->gw[1].str_status,RGB(0,0,255));
textout(app->gw[2].x,306,0,0,app->gw[2].str_status,RGB(0,0,255));
textout(app->gw[3].x,306,0,0,app->gw[3].str_status,RGB(0,0,255));
textout(app->gw[4].x,306,0,0,app->gw[4].str_status,RGB(0,0,255));
textout(app->gw[5].x,409,0,0,app->gw[5].str_status,RGB(0,0,255));
textout(app->gw[6].x,409,0,0,app->gw[6].str_status,RGB(0,0,255));
textout(app->gw[7].x,409,0,0,app->gw[7].str_status,RGB(0,0,255));
textout(app->gw[8].x,409,0,0,app->gw[8].str_status,RGB(0,0,255));
textout(app->gw[9].x,409,0,0,app->gw[9].str_status,RGB(0,0,255));
xiaochexianshi();
Move(x_car);
}
/////////////////////////////////////////////////////////////////////////////
// CFlexibleView printing
BOOL CFlexibleView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CFlexibleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CFlexibleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CFlexibleView diagnostics
#ifdef _DEBUG
void CFlexibleView::AssertValid() const
{
CView::AssertValid();
}
void CFlexibleView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CFlexibleDoc* CFlexibleView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFlexibleDoc)));
return (CFlexibleDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFlexibleView message handlers
void CFlexibleView::OnGongjianshuru()
{
Cgongjiandlg dlg;
dlg.DoModal();
}
void CFlexibleView::OnGongjiangongyi()
{
Cgongjiangongyidlg dlg;
dlg.DoModal();
}
DWORD WINAPI zhuangpei(LPVOID lpparameter)//小球运动线程的主函数
{ CFlexibleApp *app = (CFlexibleApp *)AfxGetApp(); //生成指向应用程序类的指针
LPINFO temp=(LPINFO)lpparameter;//传递数据
while(TRUE)
{
if(temp->status==3)//如果工位处于就绪状态
{
temp->status=1;//工位开始装配,处于忙状态
app->gw[temp->index].str_status=temp->name_gongjian;//显示该工位正在装配的工件名
::InvalidateRect(temp->hwnd,&(temp->rect),TRUE);//刷新指定区域
Sleep(1000);//停顿下,让人看清楚
app->gw[temp->index].str_status="状态:忙"; //显示当前的状态
::InvalidateRect(temp->hwnd,&(temp->rect),TRUE);//刷新指定区域
Sleep((temp->time_jiagong*1000));//停顿时间为该类型零件在该工位的装配时间
temp->status=2;//工位加工完,处于等待状态
app->gw[temp->index].str_status="状态:完成等待";//显示当前的状态
::InvalidateRect(temp->hwnd,&(temp->rect),TRUE);//刷新指定区域
}
else
{
}
}
return 0;
}
DWORD WINAPI car(LPVOID lpparameter)//小球运动线程的主函数
{
CFlexibleApp *app = (CFlexibleApp *)AfxGetApp(); //生成指向应用程序类的指针
LPINFO temp=(LPINFO)lpparameter;
int tt=0;
while(TRUE)
{
for(int i=0;i<10;i++)//处理所有的工位等待事件
{
if(app->gw[i].status==2)//如果有工位处于等待状态
{
app->cheche.status=1; //将小车的状态置为忙
app->cheche.str_status="小车忙";
CRect rect(97,400,186,540);
::InvalidateRect(temp->hwnd,&rect,TRUE);//显示小车状态
// Sleep(1000);//停顿下
x_car=app->gw[i].x; //移到到该工位
::InvalidateRect(temp->hwnd,&(temp->rect),TRUE);//刷新小车位置
Sleep(3000); //小车将工件从工位上搬下来
app->gw[i].status=0;
app->gw[i].str_status="工位闲";
::InvalidateRect(temp->hwnd,&(app->gw[i].rect),TRUE);//显示工位状态
for(int t=0;t<9;t++)//获得该工件已加工完的工位是它的第几个工位
{
if(gongyi[(app->gw[i].xuhao)-1][t]==(i+1))
{
tt=t;
}
else
{}
}
Sleep(200);
if(gongyi[(app->gw[i].xuhao)-1][num_gongyi[(app->gw[i].xuhao)-1]-1]!=(i+1))
{//如果工件还没有完全加工完
// CString susan;
x_car=app->gw[gongyi[(app->gw[i].xuhao)-1][tt+1]-1].x;//移到到下一个工位
// susan.Format("%d",gongyi[(app->gw[i].xuhao)-1][tt+1]);
// ::MessageBox(temp->hwnd,susan,"信息",NULL);
::InvalidateRect(temp->hwnd,&rect,TRUE);//刷新显示
Sleep(3000);//将工件从小车上搬到工位上
app->gw[gongyi[(app->gw[i].xuhao)-1][tt+1]-1].str_status="工位就绪";
::InvalidateRect(temp->hwnd,&(app->gw[gongyi[(app->gw[i].xuhao)-1][tt+1]].rect),TRUE);//刷新显示
// Sleep(2000);
app->gw[gongyi[(app->gw[i].xuhao)-1][tt+1]-1].status=3;//将该工位置为就绪
app->gw[gongyi[(app->gw[i].xuhao)-1][tt+1]-1].xuhao=app->gw[i].xuhao;//该工件的序号
app->gw[gongyi[(app->gw[i].xuhao)-1][tt+1]-1].name_gongjian=app->gw[i].name_gongjian;//该工件的名称
app->gw[gongyi[(app->gw[i].xuhao)-1][tt+1]-1].time_jiagong=time_gongyi[app->gw[i].xuhao-1][tt+1];//该工件的该工位加工时间
}
else//如果工件所有工序都已经加工完,那么将工件送到仓库
{
x_car=646;//小车运动到仓库
::InvalidateRect(temp->hwnd,&(temp->rect),TRUE);
Sleep(3000);//将小车上的工件搬到仓库
str_cangku=app->gw[i].name_gongjian;//显示送到仓库的工件名称
CRect rect1(725,578,920,630);
::InvalidateRect(temp->hwnd,&rect1,TRUE);
}
}
else
{
}
}
x_car=121;//小车返回到装卸站
::InvalidateRect(temp->hwnd,&(temp->rect),TRUE);
app->cheche.status=0;
app->cheche.str_status="小车闲";//小车状态变为闲
CRect rect10(97,400,186,540);
::InvalidateRect(temp->hwnd,&rect10,TRUE);//显示小车状态
// Sleep(1000);//停顿下
////////////////////////////////////////////////////////////////////////
if(num[0]>0||num[1]>0||num[2]>0||num[3]>0||num[4]>0||num[5]>0)
{
if(num[0]>0&&app->gw[gongyi[0][0]-1].status==0)
{
num[0]--;
str_zhuangxiezhan=name[0];
CRect rect2(10,506,100,550);
::InvalidateRect(temp->hwnd,&rect2,TRUE);
Sleep(3000);
x_car=app->gw[gongyi[0][0]-1].x;
::InvalidateRect(temp->hwnd,&(temp->rect),TRUE);
Sleep(3000);
app->cheche.status=0;
app->cheche.str_status="小车闲";//小车状态变为闲
CRect rect12(97,400,186,540);
::InvalidateRect(temp->hwnd,&rect12,TRUE);//显示小车状态
app->gw[gongyi[0][0]-1].status=3;
app->gw[gongyi[0][0]-1].str_status="工位就绪";
::InvalidateRect(temp->hwnd,&(app->gw[gongyi[0][0]-1].rect),TRUE);//刷新显示
Sleep(3000);
app->gw[gongyi[0][0]-1].xuhao=1;
app->gw[gongyi[0][0]-1].name_gongjian=name[0];
app->gw[gongyi[0][0]-1].time_jiagong=time_gongyi[0][0];
}
else
{
if(num[1]>0&&app->gw[gongyi[1][0]-1].status==0)
{
num[1]--;
str_zhuangxiezhan=name[1];
CRect rect3(10,506,100,550);
::InvalidateRect(temp->hwnd,&rect3,TRUE);
Sleep(3000);
x_car=app->gw[gongyi[1][0]-1].x;
::InvalidateRect(temp->hwnd,&(temp->rect),TRUE);
Sleep(3000);
app->cheche.status=0;
app->cheche.str_status="小车闲";//小车状态变为闲
CRect rect13(97,400,186,540);
::InvalidateRect(temp->hwnd,&rect13,TRUE);//显示小车状态
app->gw[gongyi[1][0]-1].status=3;
app->gw[gongyi[1][0]-1].str_status="工位就绪";
::InvalidateRect(temp->hwnd,&(app->gw[gongyi[1][0]-1].rect),TRUE);//刷新显示
Sleep(3000);
app->gw[gongyi[1][0]-1].xuhao=2;
app->gw[gongyi[1][0]-1].name_gongjian=name[1];
app->gw[gongyi[1][0]-1].time_jiagong=time_gongyi[1][0];
}
else
{
if(num[2]>0&&app->gw[gongyi[2][0]-1].status==0)
{
num[2]--;
str_zhuangxiezhan=name[2];
CRect rect4(10,506,100,550);
::InvalidateRect(temp->hwnd,&rect4,TRUE);
Sleep(3000);
x_car=app->gw[gongyi[2][0]-1].x;
::InvalidateRect(temp->hwnd,&(temp->rect),TRUE);
Sleep(3000);
app->cheche.status=0;
app->cheche.str_status="小车闲";//小车状态变为闲
CRect rect14(97,400,186,540);
::InvalidateRect(temp->hwnd,&rect14,TRUE);//显示小车状态
app->gw[gongyi[2][0]-1].status=3;
app->gw[gongyi[2][0]-1].str_status="工位就绪";
::InvalidateRect(temp->hwnd,&(app->gw[gongyi[2][0]-1].rect),TRUE);//刷新显示
Sleep(3000);
app->gw[gongyi[2][0]-1].xuhao=3;
app->gw[gongyi[2][0]-1].name_gongjian=name[2];
app->gw[gongyi[2][0]-1].time_jiagong=time_gongyi[2][0];
}
else
{
if(num[3]>0&&app->gw[gongyi[3][0]-1].status==0)
{
num[3]--;
str_zhuangxiezhan=name[3];
CRect rect5(10,506,100,550);
::InvalidateRect(temp->hwnd,&rect5,TRUE);
Sleep(3000);
x_car=app->gw[gongyi[3][0]-1].x;
::InvalidateRect(temp->hwnd,&(temp->rect),TRUE);
Sleep(3000);
app->cheche.status=0;
app->cheche.str_status="小车闲";//小车状态变为闲
CRect rect15(97,400,186,540);
::InvalidateRect(temp->hwnd,&rect15,TRUE);//显示小车状态
app->gw[gongyi[3][0]-1].status=3;
app->gw[gongyi[3][0]-1].str_status="工位就绪";
::InvalidateRect(temp->hwnd,&(app->gw[gongyi[3][0]-1].rect),TRUE);//刷新显示
Sleep(3000);
app->gw[gongyi[3][0]-1].xuhao=4;
app->gw[gongyi[3][0]-1].name_gongjian=name[3];
app->gw[gongyi[3][0]-1].time_jiagong=time_gongyi[3][0];
}
else
{
if(num[4]>0&&app->gw[gongyi[4][0]-1].status==0)
{
num[4]--;
str_zhuangxiezhan=name[4];
CRect rect6(10,506,100,550);
::InvalidateRect(temp->hwnd,&rect6,TRUE);
Sleep(3000);
x_car=app->gw[gongyi[4][0]-1].x;
::InvalidateRect(temp->hwnd,&(temp->rect),TRUE);
Sleep(3000);
app->cheche.status=0;
app->cheche.str_status="小车闲";//小车状态变为闲
CRect rect16(97,400,186,540);
::InvalidateRect(temp->hwnd,&rect16,TRUE);//显示小车状态
app->gw[gongyi[4][0]-1].status=3;
app->gw[gongyi[4][0]-1].str_status="工位就绪";
::InvalidateRect(temp->hwnd,&(app->gw[gongyi[4][0]-1].rect),TRUE);//刷新显示
Sleep(3000);
app->gw[gongyi[4][0]-1].xuhao=5;
app->gw[gongyi[4][0]-1].name_gongjian=name[4];
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?