output_link.cpp

来自「开发虚拟的被控对象及虚拟的PLC,模似PLC的工作过程进行实验。用户可根据具体的」· C++ 代码 · 共 86 行

CPP
86
字号
#include "stdafx.h"
#include "PLC_DEMO.h"
#include "PLC_DEMODoc.h"
#include "PLC_DEMOView.h"
#include "Output_link.h"

bool outputenable=false;
bool outputcheck=false;
bool outcontrolcheck=false;
int endx,endy,endsign;
int stockoutputlink[9][7];
int stockoutnumber=0;

extern int currentlinksign;
extern CPLC_DEMOView *fordraw;

void outputfetchdraw()
{
	CDC* thisDC=fordraw->GetDC();
	CPen blackpen(PS_SOLID,2,RGB(0,0,0));
	CPen *old=thisDC->SelectObject(&blackpen);
	for(int i=0;i<9;i++)
	{
		if(stockoutputlink[i][0])
		{
			thisDC->MoveTo(stockoutputlink[i][3],
				stockoutputlink[i][4]);
		    thisDC->LineTo(stockoutputlink[i][5],
				stockoutputlink[i][6]);
		}
	
	}
	thisDC->SelectObject(old);
	fordraw->ReleaseDC(thisDC);
}
void outputfetchlink(int i,int j,int m,int n)
{
	currentlinksign=2;
	if(outputcheck&&outcontrolcheck)
	{
		if(stockoutnumber>=9)
		{
			CString link;
		    link.Format("连线已达到最大范围,不能再连线");
		    AfxMessageBox(link);
		}
		else 
		{
			stockoutputlink[stockoutnumber][0]=1;
		    if(i)
			{
				stockoutputlink[stockoutnumber][1]=i;
			    stockoutputlink[stockoutnumber][2]=endsign;
			    stockoutputlink[stockoutnumber][3]=m;
			    stockoutputlink[stockoutnumber][4]=n;
			    stockoutputlink[stockoutnumber][5]=endx;
			    stockoutputlink[stockoutnumber][6]=endy;
			}
		    else
			{
				stockoutputlink[stockoutnumber][1]=endsign;
			    stockoutputlink[stockoutnumber][2]=j;
			    stockoutputlink[stockoutnumber][3]=endx;
			    stockoutputlink[stockoutnumber][4]=endy;
			    stockoutputlink[stockoutnumber][5]=m;
			    stockoutputlink[stockoutnumber][6]=n;
			}
		    stockoutnumber++;
		    outputcheck=false;
		    outcontrolcheck=false;
		    outputfetchdraw();	
		}
	}
	else
	{
		endx=m;
		endy=n;
		if(i)
			endsign=i;
		else endsign=j;
	}
}



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?