📄 plcview.cpp
字号:
else {return;}
if(lad[hor].m_Kind[ver]>=2)
{
char NameStr[8],Str[6];
strcpy(NameStr,"");
switch(lad[hor].m_Name[ver])
{
case 0: {NameStr[0]='X'; break;}
case 1: {NameStr[0]='Y'; break;}
case 2: {NameStr[0]='M'; break;}
case 3: {NameStr[0]='T'; break;}
case 4: {NameStr[0]='C'; break;}
default: {return; break;}
}
NameStr[1]='\0';
sprintf(Str,"%03d",lad[hor].m_Code[ver]);
strcat(NameStr,Str);
pDC->TextOut(m_StartX+2,m_StartY,NameStr,4);
}
if(lad[hor].m_Branch[ver]==1)
{
pDC->MoveTo(m_StartX+38,m_StartY+25);
pDC->LineTo(m_StartX+38,m_StartY+75);
}
}
//-----------------------------------------------------------
void CPLCView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
// TODO: calculate the total size of this view
////for(short i=0;i<=300;i++)
////{Instruct[i].Order='0';Instruct[i].Name='0';Instruct[i].Code=0;}
BrushRed.CreateSolidBrush(RGB(255,0,0));//red
BrushGreen.CreateSolidBrush(RGB(0,255,0));//green
//sizeTotal.cx = sizeTotal.cy = 100;
sizeTotal.cy = 8000;
SetScrollSizes(MM_TEXT,sizeTotal,sizePage,sizeLine);
RECT ret; GetClientRect(&ret);
PageLeng=int((ret.bottom-100)/50)*50;//每页梯形图的总长度
Output[0]=0; Output[1]=0; Output[2]=0; Output[3]=0; Output[4]=0; Output[5]=0;
Output[6]=0; Output[7]=0; Output[8]=0; Output[9]=0; Output[10]=0; Output[11]=0; Output[12]=0;//???
Input[0]=0; Input[1]=0; Input[2]=0;
for(short num=0;num<16;num++) {CurrT[num]=0; Tison[num]=0; CurrC[num]=0; Cpulse[num]=0; Cison[num]=0;}
}
/////////////////////////////////////////////////////////////////////////////
// CPLCView printing
BOOL CPLCView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CPLCView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CPLCView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CPLCView diagnostics
#ifdef _DEBUG
void CPLCView::AssertValid() const
{
CScrollView::AssertValid();
}
void CPLCView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CPLCDoc* CPLCView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPLCDoc)));
return (CPLCDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CPLCView message handlers
//---------------------------------------------------------------------------
void CPLCView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(FaceKind=='T')
{
if((point.x<8)||(point.x>616)||(point.y<0))
{return;}
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
if((int(point.y/50))>TotalLad) {return;}
dc.LPtoDP(&PCusor);
CDC *pDC=GetDC();
pDC->SelectObject(&pen);
pDC->SetROP2(R2_NOT);
pDC->MoveTo(PCusor.x, PCusor.y);
pDC->LineTo(PCusor.x, PCusor.y+50);
pDC->LineTo(PCusor.x+38, PCusor.y+50);
pDC->LineTo(PCusor.x+38, PCusor.y);
pDC->LineTo(PCusor.x, PCusor.y);
PCusor.x=int((point.x-8)/38)*38+8;
PCusor.y=int(point.y/50)*50;
CurrLadH=point.y/50;//梯形图当前行
CurrLadV=(PCusor.x-8)/38;//梯形图当前列
point=PCusor;
dc.LPtoDP(&point);
pDC->MoveTo(point.x, point.y);
pDC->LineTo(point.x, point.y+50);
pDC->LineTo(point.x+38, point.y+50);
pDC->LineTo(point.x+38, point.y);
pDC->LineTo(point.x, point.y);
}
else if(FaceKind=='I')
{
if((point.x<0)||(point.x>616)||(point.y<0))
{return;}
CClientDC dc(this);
OnPrepareDC(&dc);
CPoint LastPoint;
LastPoint.x=20; LastPoint.y=25*CurrLine;
dc.LPtoDP(&LastPoint);
dc.DPtoLP(&point);
short CurrLine0=point.y/25;
if((CurrLine0>=0)&&(CurrLine0<TotalLine))
{
CDC *pDC=GetDC();
pDC->PatBlt(20,LastPoint.y,500,18,DSTINVERT);
CurrLine=CurrLine0;
LastPoint.x=20; LastPoint.y=25*CurrLine;
dc.LPtoDP(&LastPoint);
pDC->PatBlt(20,LastPoint.y,500,18,DSTINVERT);
}
}
else if(FaceKind=='L')
{
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
bool IsDraw=false;
if((point.x>=60)&&(point.x<=100)&&(point.y>=1)&&(point.y<=21))
{
if(IsRun)
{
IsRun=false; KillTimer(1);
}
else
{
if(LadToInstr()!=0) {return;}//梯形图转换为指令表//LadToInstr返回: 0表正常退出; 1表出错退出
IsRun=true; SetTimer(1,100,NULL);
}
CRect rct; rct.left=60; rct.right=100; rct.top=1; rct.bottom=21;
CDC *pDC=GetDC();
pDC->DrawFrameControl(rct,DFC_BUTTON,DFCS_BUTTONPUSH);
if(IsRun)//true表仿真运行;false表停止
{
pDC->DrawEdge(rct,EDGE_SUNKEN,BF_RECT);
pDC->TextOut(21,1,"[停止]");
}
else
{
pDC->TextOut(21,1,"[启动]");
}
}
else if((point.x>=30)&&(point.x<=50)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&1)==0) {Input[0]=Input[0]|1;} else {Input[0]=Input[0]&(0xFFFF-1);} }
else if((point.x>=55)&&(point.x<=75)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&2)==0) {Input[0]=Input[0]|2;} else {Input[0]=Input[0]&(0xFFFF-2);} }
else if((point.x>=90)&&(point.x<=110)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&4)==0) {Input[0]=Input[0]|4;} else {Input[0]=Input[0]&(0xFFFF-4);} }
else if((point.x>=125)&&(point.x<=145)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&8)==0) {Input[0]=Input[0]|8;} else {Input[0]=Input[0]&(0xFFFF-8);} }
else if((point.x>=160)&&(point.x<=180)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&16)==0) {Input[0]=Input[0]|16;} else {Input[0]=Input[0]&(0xFFFF-16);} }
else if((point.x>=195)&&(point.x<=215)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&32)==0) {Input[0]=Input[0]|32;} else {Input[0]=Input[0]&(0xFFFF-32);} }
else if((point.x>=230)&&(point.x<=250)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&64)==0) {Input[0]=Input[0]|64;} else {Input[0]=Input[0]&(0xFFFF-64);} }
else if((point.x>=265)&&(point.x<=285)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&128)==0) {Input[0]=Input[0]|128;} else {Input[0]=Input[0]&(0xFFFF-128);} }
else if((point.x>=300)&&(point.x<=320)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&0x100)==0) {Input[0]=Input[0]|0x100;} else {Input[0]=Input[0]&(0xFFFF-0x100);} }
else if((point.x>=335)&&(point.x<=355)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&0x200)==0) {Input[0]=Input[0]|0x200;} else {Input[0]=Input[0]&(0xFFFF-0x200);} }
else if((point.x>=370)&&(point.x<=390)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&0x400)==0) {Input[0]=Input[0]|0x400;} else {Input[0]=Input[0]&(0xFFFF-0x400);} }
else if((point.x>=405)&&(point.x<=425)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&0x800)==0) {Input[0]=Input[0]|0x800;} else {Input[0]=Input[0]&(0xFFFF-0x800);} }
else if((point.x>=440)&&(point.x<=460)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&0x1000)==0) {Input[0]=Input[0]|0x1000;} else {Input[0]=Input[0]&(0xFFFF-0x1000);} }
else if((point.x>=475)&&(point.x<=495)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&0x2000)==0) {Input[0]=Input[0]|0x2000;} else {Input[0]=Input[0]&(0xFFFF-0x2000);} }
else if((point.x>=510)&&(point.x<=530)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&0x4000)==0) {Input[0]=Input[0]|0x4000;} else {Input[0]=Input[0]&(0xFFFF-0x4000);} }
else if((point.x>=545)&&(point.x<=565)&&(point.y>=30)&&(point.y<=50))
{IsDraw=true; if((Input[0]&0x8000)==0) {Input[0]=Input[0]|0x8000;} else {Input[0]=Input[0]&(0xFFFF-0x8000);} }
else if((point.x>=30)&&(point.x<=50)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&1)==0) {Input[1]=Input[1]|1;} else {Input[1]=Input[1]&(0xFFFF-1);} }
else if((point.x>=55)&&(point.x<=75)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&2)==0) {Input[1]=Input[1]|2;} else {Input[1]=Input[1]&(0xFFFF-2);} }
else if((point.x>=90)&&(point.x<=110)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&4)==0) {Input[1]=Input[1]|4;} else {Input[1]=Input[1]&(0xFFFF-4);} }
else if((point.x>=125)&&(point.x<=145)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&8)==0) {Input[1]=Input[1]|8;} else {Input[1]=Input[1]&(0xFFFF-8);} }
else if((point.x>=160)&&(point.x<=180)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&16)==0) {Input[1]=Input[1]|16;} else {Input[1]=Input[1]&(0xFFFF-16);} }
else if((point.x>=195)&&(point.x<=215)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&32)==0) {Input[1]=Input[1]|32;} else {Input[1]=Input[1]&(0xFFFF-32);} }
else if((point.x>=230)&&(point.x<=250)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&64)==0) {Input[1]=Input[1]|64;} else {Input[1]=Input[1]&(0xFFFF-64);} }
else if((point.x>=265)&&(point.x<=285)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&128)==0) {Input[1]=Input[1]|128;} else {Input[1]=Input[1]&(0xFFFF-128);} }
else if((point.x>=300)&&(point.x<=320)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&0x100)==0) {Input[1]=Input[1]|0x100;} else {Input[1]=Input[1]&(0xFFFF-0x100);} }
else if((point.x>=335)&&(point.x<=355)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&0x200)==0) {Input[1]=Input[1]|0x200;} else {Input[1]=Input[1]&(0xFFFF-0x200);} }
else if((point.x>=370)&&(point.x<=390)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&0x400)==0) {Input[1]=Input[1]|0x400;} else {Input[1]=Input[1]&(0xFFFF-0x400);} }
else if((point.x>=405)&&(point.x<=425)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&0x800)==0) {Input[1]=Input[1]|0x800;} else {Input[1]=Input[1]&(0xFFFF-0x800);} }
else if((point.x>=440)&&(point.x<=460)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&0x1000)==0) {Input[1]=Input[1]|0x1000;} else {Input[1]=Input[1]&(0xFFFF-0x1000);} }
else if((point.x>=475)&&(point.x<=495)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&0x2000)==0) {Input[1]=Input[1]|0x2000;} else {Input[1]=Input[1]&(0xFFFF-0x2000);} }
else if((point.x>=510)&&(point.x<=530)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&0x4000)==0) {Input[1]=Input[1]|0x4000;} else {Input[1]=Input[1]&(0xFFFF-0x4000);} }
else if((point.x>=545)&&(point.x<=565)&&(point.y>=80)&&(point.y<=100))
{IsDraw=true; if((Input[1]&0x8000)==0) {Input[1]=Input[1]|0x8000;} else {Input[1]=Input[1]&(0xFFFF-0x8000);} }
else if((point.x>=30)&&(point.x<=50)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&1)==0) {Input[2]=Input[2]|1;} else {Input[2]=Input[2]&(0xFFFF-1);} }
else if((point.x>=55)&&(point.x<=75)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&2)==0) {Input[2]=Input[2]|2;} else {Input[2]=Input[2]&(0xFFFF-2);} }
else if((point.x>=90)&&(point.x<=110)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&4)==0) {Input[2]=Input[2]|4;} else {Input[2]=Input[2]&(0xFFFF-4);} }
else if((point.x>=125)&&(point.x<=145)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&8)==0) {Input[2]=Input[2]|8;} else {Input[2]=Input[2]&(0xFFFF-8);} }
else if((point.x>=160)&&(point.x<=180)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&16)==0) {Input[2]=Input[2]|16;} else {Input[2]=Input[2]&(0xFFFF-16);} }
else if((point.x>=195)&&(point.x<=215)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&32)==0) {Input[2]=Input[2]|32;} else {Input[2]=Input[2]&(0xFFFF-32);} }
else if((point.x>=230)&&(point.x<=250)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&64)==0) {Input[2]=Input[2]|64;} else {Input[2]=Input[2]&(0xFFFF-64);} }
else if((point.x>=265)&&(point.x<=285)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&128)==0) {Input[2]=Input[2]|128;} else {Input[2]=Input[2]&(0xFFFF-128);} }
else if((point.x>=300)&&(point.x<=320)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&0x100)==0) {Input[2]=Input[2]|0x100;} else {Input[2]=Input[2]&(0xFFFF-0x100);} }
else if((point.x>=335)&&(point.x<=355)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&0x200)==0) {Input[2]=Input[2]|0x200;} else {Input[2]=Input[2]&(0xFFFF-0x200);} }
else if((point.x>=370)&&(point.x<=390)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&0x400)==0) {Input[2]=Input[2]|0x400;} else {Input[2]=Input[2]&(0xFFFF-0x400);} }
else if((point.x>=405)&&(point.x<=425)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&0x800)==0) {Input[2]=Input[2]|0x800;} else {Input[2]=Input[2]&(0xFFFF-0x800);} }
else if((point.x>=440)&&(point.x<=460)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&0x1000)==0) {Input[2]=Input[2]|0x1000;} else {Input[2]=Input[2]&(0xFFFF-0x1000);} }
else if((point.x>=475)&&(point.x<=495)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&0x2000)==0) {Input[2]=Input[2]|0x2000;} else {Input[2]=Input[2]&(0xFFFF-0x2000);} }
else if((point.x>=510)&&(point.x<=530)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&0x4000)==0) {Input[2]=Input[2]|0x4000;} else {Input[2]=Input[2]&(0xFFFF-0x4000);} }
else if((point.x>=545)&&(point.x<=565)&&(point.y>=130)&&(point.y<=150))
{IsDraw=true; if((Input[2]&0x8000)==0) {Input[2]=Input[2]|0x8000;} else {Input[2]=Input[2]&(0xFFFF-0x8000);} }
else if((point.x>=30)&&(point.x<=50)&&(point.y>=200)&&(point.y<=220))
{IsDraw=true; if((Output[3]&1)==0) {Output[3]=Output[3]|1;} else {Output[3]=Output[3]&(0xFFFF-1);} }
else if((point.x>=55)&&(point.x<=75)&&(point.y>=200)&&(point.y<=220))
{IsDraw=true; if((Output[3]&2)==0) {Output[3]=Output[3]|2;} else {Output[3]=Output[3]&(0xFFFF-2);} }
else if((point.x>=90)&&(point.x<=110)&&(point.y>=200)&&(point.y<=220))
{IsDraw=true; if((Output[3]&4)==0) {Output[3]=Output[3]|4;} else {Output[3]=Output[3]&(0xFFFF-4);} }
else if((point.x>=125)&&(point.x<=145)&&(point.y>=200)&&(point.y<=220))
{IsDraw=true; if((Output[3]&8)==0) {Output[3]=Output[3]|8;} else {Output[3]=Output[3]&(0xFFFF-8);} }
else if((point.x>=160)&&(point.x<=180)&&(point.y>=200)&&(point.y<=220))
{IsDraw=true; if((Output[3]&16)==0) {Output[3]=Output[3]|16;} else {Output[3]=Output[3]&(0xFFFF-16);} }
else if((point.x>=195)&&(point.x<=215)&&(point.y>=200)&&(point.y<=220))
{IsDraw=true; if((Output[3]&32)==0) {Output[3]=Output[3]|32;} else {Output[3]=Output[3]&(0xFFFF-32);} }
else if((point.x>=230)&&(point.x<=250)&&(point.y>=200)&&(point.y<=220))
{IsDraw=true; if((Output[3]&64)==0) {Output[3]=Output[3]|64;} else {Output[3]=Output[3]&(0xFFFF-64);} }
else if((point.x>=265)&&(point.x<=285)&&(point.y>=200)&&(point.y<=220))
{IsDraw=true; if((Output[3]&128)==0) {Output[3]=Output[3]|128;} else {Output[3]=Output[3]&(0xFFFF-128);} }
else if((point.x>=300)&&(point.x<=320)&&(point.y>=200)&&(point.y<=220))
{IsDraw=true; if((Output[3]&0x100)==0) {Output[3]=Output[3]|0x100;} else {Output[3]=Output[3]&(0xFFFF-0x100);} }
else if((point.x>=335)&&(point.x<=355)&&(point.y>=200)&&(point.y<=220))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -