⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iopoint.cpp

📁 PLC程序集成开发平台
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//FILE:iopoint.CPP
#include "stdafx.h"
#include "iopoint.h"
//extern int CurrentCols;
extern FILE *fp;
extern int CurH;
extern int CurW;
extern CString filename;

IMPLEMENT_SERIAL(CIO,CObject,1)

CIO::CIO()
{
	name="";
	addr="";
	code="";
	Rows=0;
	Cols=0;
	flag=0;
	fiveflag=0;
	xpoint=0;
	ypoint=0;
}
int IOPOINT::testaddr()
{
	char ch;
    if ((addr.GetLength()!=4) 
		|| addr[2]>'7' || addr[3]>'7')
       return 1;
    else
    {
		ch=addr[0];
		switch (ch)
		{
		case 'X':
				if (addr<"X000" || addr>"X527")
					return 1;
				else
					break;	
		case 'Y':
				if (addr<"Y000" || addr>"Y647")
					return 1;
				else
					break;
		case 'M':
				if (addr<"M000" || addr>"M977")
					return 1;
				else
					break;
		case 'C':
				if (addr<"C060" || addr>"C067" &&	addr>"C460"
						|| addr>"C467")
					return 1;
				else
					break;
		case 'T':
				if (!((addr>="T050" && addr<="T057") 
					||(addr>="T450" && addr<="T457") 
					||(addr>="T550" && addr<="T557") 
					||(addr>="T650" && addr<="T657") 
					||(addr>="T700" && addr<="T777")))
					return 1;
				else 
					break;
		default:
				return 1;
		}
	return 0;
	}
}

void IOPOINT::changeimg(int x,int y,CDC *pDC)
{
    int x1,y1,x2,y2;
	if (down!=NULL)
	   {
		x1=x+::CurW;
	   y1=y+::CurH-10;
	   x2=x1;
	   y2=y1+::CurH;
	   pDC->MoveTo(x1,y1);
	   pDC->LineTo(x2,y2);
	   if (down->up!=NULL)
	      {
	       x1=x;
	       x2=x1;
	       pDC->MoveTo(x1,y1);
		   pDC->LineTo(x2,y2);
	      }

	   }
	if (up!=NULL)
	   {
	   x1=x;
	   y1=y+::CurH-10;
	   x2=x1;
	   y2=y1-::CurH;
	   pDC->MoveTo(x1,y1);
	   pDC->LineTo(x2,y2);
	   if (up->down!=NULL)
	      {
		   x1=x+::CurW;
	      x2=x1;
		  pDC->MoveTo(x1,y1);
		  pDC->LineTo(x2,y2);
	      }
	   }
	if (fiveflag==5)
	{
		x1=x+::CurW;
		y1=y+::CurH-10;
		x2=x1;
		y2=y1-::CurH;
	   pDC->MoveTo(x1,y1);
	   pDC->LineTo(x2,y2);
	}
		
}

void LD::put_img(int x,int y,CDC *pDC)
{
	int x1,y1;
	x1=x;
	y1=y+::CurH-10;
	pDC->MoveTo(x1,y1);
	x1=x1+20;
	pDC->LineTo(x1,y1);
	pDC->MoveTo(x1,y1-10);
	y1=y+::CurH;
	pDC->LineTo(x1,y1);
	x1=x1+20;
	pDC->MoveTo(x1,y1);
	pDC->LineTo(x1,y1-20);
	pDC->MoveTo(x1,y1-10);
	pDC->LineTo(x+::CurW,y1-10);

}
void LD::print(int x,int y,CDC *pDC)
{
	put_img(x,y,pDC);
	pDC->SetBkMode(TRANSPARENT);
	pDC->SetTextAlign(TA_CENTER+TA_BOTTOM);
	pDC->TextOut(x+::CurW/2,y+40,name);
	pDC->TextOut(x+::CurW/2,y+60,addr);
	changeimg(x,y,pDC);
}

void LDI::put_img(int x,int y,CDC *pDC)
{
	int x1,y1;
	x1=x;
	y1=y+::CurH-10;
	pDC->MoveTo(x1,y1);
	x1=x1+20;
	pDC->LineTo(x1,y1);
	pDC->MoveTo(x1,y1-10);
	y1=y+::CurH;
	pDC->LineTo(x1,y1);
	x1=x1+20;
	pDC->MoveTo(x1,y1);
	pDC->LineTo(x1,y1-20);
	pDC->MoveTo(x1,y1-10);
	pDC->LineTo(x+::CurW,y1-10);
	pDC->MoveTo(x1-3,y1-17);
	pDC->LineTo(x1-17,y1-3);

}
void LDI::print(int x,int y,CDC *pDC)
{
	put_img(x,y,pDC);
	pDC->SetBkMode(TRANSPARENT);
	pDC->SetTextAlign(TA_CENTER+TA_BOTTOM);
	pDC->TextOut(x+::CurW/2,y+40,name);
	pDC->TextOut(x+::CurW/2,y+60,addr);
	changeimg(x,y,pDC);
}
void OR::put_img(int x,int y,CDC *pDC)
{
	int x1,y1;
	x1=x;
	pDC->MoveTo(x1,y-10);
	y1=y+::CurH-10;
	pDC->LineTo(x1,y1);
	x1=x1+20;
	pDC->LineTo(x1,y1);
	pDC->MoveTo(x1,y1-10);
	y1=y+::CurH;
	pDC->LineTo(x1,y1);
	x1=x1+20;
	pDC->MoveTo(x1,y1);
	pDC->LineTo(x1,y1-20);
	pDC->MoveTo(x1,y1-10);
	pDC->LineTo(x+::CurW,y1-10);
	pDC->LineTo(x+::CurW,y-10);
}
void OR::print(int x,int y,CDC *pDC)
{
	put_img(x,y,pDC);
	pDC->SetBkMode(TRANSPARENT);
	pDC->SetTextAlign(TA_CENTER+TA_BOTTOM);
	pDC->TextOut(x+::CurW/2,y+40,name);
	pDC->TextOut(x+::CurW/2,y+60,addr);
	changeimg(x,y,pDC);
}
void ORI::put_img(int x,int y,CDC *pDC)
{
	int x1,y1;
	x1=x;
	pDC->MoveTo(x1,y-10);
	y1=y+::CurH-10;
	pDC->LineTo(x1,y1);
	x1=x1+20;
	pDC->LineTo(x1,y1);
	pDC->MoveTo(x1,y1-10);
	y1=y+::CurH;
	pDC->LineTo(x1,y1);
	x1=x1+20;
	pDC->MoveTo(x1,y1);
	pDC->LineTo(x1,y1-20);
	pDC->MoveTo(x1,y1-10);
	pDC->LineTo(x+::CurW,y1-10);
	pDC->MoveTo(x1-3,y1-17);
	pDC->LineTo(x1-17,y1-3);
	pDC->MoveTo(x+::CurW,y1-10);
	pDC->LineTo(x+::CurW,y-10);
}
void ORI::print(int x,int y,CDC *pDC)
{
	put_img(x,y,pDC);
	pDC->SetBkMode(TRANSPARENT);
	pDC->SetTextAlign(TA_CENTER+TA_BOTTOM);
	pDC->TextOut(x+::CurW/2,y+40,name);
	pDC->TextOut(x+::CurW/2,y+60,addr);
	changeimg(x,y,pDC);
}
void HOR::print(int x,int y,CDC *pDC)
{
	pDC->MoveTo(x,y+::CurH-10);
	pDC->LineTo(x+::CurW,y+::CurH-10);
    changeimg(x,y,pDC);
}

int HOR::testaddr()
{
   return 0;
}

void ERECT::print(int x,int y,CDC *pDC)
{
	pDC->MoveTo(x+::CurW,y-10);
	pDC->LineTo(x+::CurW,y+::CurH-10);
}

void OUTPOINT::put_img(int x,int y,CDC *pDC)
{
	int x1,y1;
	x1=x+21;
	y1=y+::CurH-10;
	pDC->MoveTo(x,y1);
	pDC->LineTo(x1,y1);
	CRect rcEllipse(x1,y1-9,x1+18,y1+9);
	pDC->SelectStockObject(NULL_BRUSH);
	pDC->Ellipse(rcEllipse);
	pDC->MoveTo(x1+18,y1);
	pDC->LineTo(x+::CurW,y1);
}

void OUTPOINT::print(int x,int y,CDC *pDC)
{
	put_img(x,y,pDC);
	pDC->SetBkMode(TRANSPARENT);
	pDC->SetTextAlign(TA_CENTER+TA_BOTTOM);
	pDC->TextOut(x+::CurW/2,y+40,name);
	pDC->TextOut(x+::CurW/2,y+60,addr);
	changeimg(x,y,pDC);
}

void ADDTION::put_img(int x,int y,CDC *pDC)
{
	pDC->MoveTo(x,y+::CurH-10);
	pDC->LineTo(x+16,y+::CurH-10);
	pDC->MoveTo(x+21,y+::CurH-18);
	pDC->LineTo(x+16,y+::CurH-18);
	pDC->LineTo(x+16,y+::CurH-1);
	pDC->LineTo(x+21,y+::CurH-1);
	pDC->MoveTo(x+37,y+::CurH-1);
	pDC->LineTo(x+42,y+::CurH-1);
	pDC->LineTo(x+42,y+::CurH-18);
	pDC->LineTo(x+37,y+::CurH-18);
	pDC->MoveTo(x+42,y+::CurH-10);
	pDC->LineTo(x+::CurW,y+::CurH-10);

}
void ADDTION::print(int x,int y,CDC *pDC)
{
	put_img(x,y,pDC);
	pDC->SetBkMode(TRANSPARENT);
	pDC->SetTextAlign(TA_CENTER+TA_BOTTOM);
	pDC->TextOut(x+::CurW/2,y+40,name);
	pDC->TextOut(x+::CurW/2,y+60,addr);
	pDC->TextOut(x+30,y+77,code);
	changeimg(x,y,pDC);
}
int ADDTION::testaddr()
{
    char ch;
    int i;
    if (addr.GetLength()>4)// || strlen(name)==0)
	return 1;
    for (i=1;i<name.GetLength();i++)
	if (addr[i]>'7')
		return 1;
		switch (flag)
		{
     /************************************************************
	8--SET		9--S		10--MC		12--K
	18--RST		19--R           11--MCR         13--F
	14--PLS		15--END
     ************************************************************/
		case 8:
		case 9:
		case 18:
		case 19:  
			{
				ch=addr[0];
				switch (ch)
				{
					case 'Y':
							if (addr<"Y000" || addr>"Y647")
								return 1;
							else
								break;
					case 'M':
							if (addr<"M000" || addr>"M977")
								return 1;
							else
								break;
					case 'C':
							if (addr<"C060" || (addr>"C067" &&
								addr<"C460") || addr>"C467")
								return 1;
							else
								break;
					default:
							return 1;
				}//end of switch(ch)
				break;
		    }
		case 10:
		case 11:
		case 14:  
			{ 	
				ch=addr[0];
				switch (ch)
				{
					case 'M':
							if (addr<"M000" || addr>"M777")
								return 1;
							else
								break;
			      default:
						return 1;
				}//end of switch(ch)
				break;
			}
		case 12:  
			{
				if (addr<"K000" || addr>"K777")
					return 1;
				break;
		    }
		case 13:  
			{
				if (addr<"F670" || addr>"F673")
					return 1;
				break;
		    }
		case 15:
                break;
		default:
				return 1;
		}// switch(flag);
		return 0;
}


IOPOINT * LIST::ANBtest(IOPOINT *p)
{
	IOPOINT *q;
	IOPOINT *returnpoint=NULL;
	BOOL flag;
	flag=FALSE;
	while (p->unup!=NULL)
	{
		p=p->unup;
		q=p;
		while (q->getflag()!=0 
			&& (q->right!=NULL|| q->getfiveflag()==5))
		{
			flag=TRUE;
			if (q->undown!=NULL)
			{
				flag=FALSE;
				returnpoint=q;
				break;
		    }
			q=q->right;
		}
		if (flag)
			break;
	}
	return returnpoint;
}

IOPOINT * LIST::ANBcompile(IOPOINT *p,IOPOINT *endpoint)
{
//	IOPOINT *breakpoint;
	IOPOINT *returnpoint;
	IOPOINT *temp;
	IOPOINT point;
	int j;
	BOOL NoAnb;
//	breakpoint=p;
	j=0;
	NoAnb=TRUE;
	while(1)
	{
		if (NoAnb)
		{
			switch (p->getflag())
			{
			case 1:
					if (j>0)
						fprintf(::fp,"%s\t%s\t\t;%s\n","AND",p->addr,p->name);
					else
						fprintf(::fp,"%s\t%s\t\t;%s\n","LD",p->addr,p->name);
					j++;
					break;
			case 2:
					if (j>0)
						fprintf(::fp,"%s\t%s\t\t;%s\n","ANI",p->addr,p->name);
					else
						fprintf(::fp,"%s\t%s\t\t;%s\n","LDI",p->addr,p->name);
					j++;
					break;
			default:
					break;
			}// end of switch (p->getflag())
			p->setvisit(TRUE);
			if (p->down!=NULL)
			{
				temp=ORBtest(p,&point);
				if (temp!=NULL)
				{
					returnpoint=ORBcompile(temp);
					if (returnpoint==endpoint)
						return returnpoint;
					else if (returnpoint->down!=NULL)
					{
						temp=ORBtest(returnpoint,&point);
						if (temp!=NULL)
						{
							returnpoint=ORBcompile(temp);
							if (returnpoint==endpoint)
								return returnpoint;
						}
					}
				}
			}
			while (p->visit==TRUE)
				p=p->right;
		}// end of if (NoAnb)
		if (p->unup!=NULL)
	    {
			temp=ANBtest(p);
			if (temp!=NULL)
			{
				NoAnb=FALSE;
				returnpoint=ANBcompile(p,temp);
				if (j>0)
					fprintf(::fp,"%s\n","ANB");
				if (returnpoint->down!=NULL)
					{
						temp=ORBtest(returnpoint,&point);
						if (temp!=NULL)
						{
							returnpoint=ORBcompile(temp);
							if (returnpoint==endpoint)
								return returnpoint;
						}
					}
			}
			else
				NoAnb=TRUE;
	    }
		while (p->visit==TRUE)
			p=p->right;
	}// end of while(1)

}

IOPOINT * LIST::ORBtest(IOPOINT *p,IOPOINT *q)
{
	q=p->down;
	do
	{
		p=p->down;
		while ((q->left!=NULL)
				&& (q->left->getflag()!=0)
				&& (q->getfiveflag()!=9)
				&& (q->left->visit!=TRUE))
			q=q->left;
		if (((q->up!=NULL)||(q->getypoint()==0))
				&&(q->visit==0)
				&&(q->getflag()!=0))
			return p;
	
		q=q->down;
	}while (q!=NULL);
	p=NULL;
	return p;
}

IOPOINT * LIST::ORBcompile(IOPOINT *p)
{
	IOPOINT *breakpoint;
	IOPOINT *result;
	IOPOINT point;
	IOPOINT *q,*returnpoint;
	IOPOINT *temp;
//	int m;
	int i,j;
	BOOL NoAnb;
	i=0;
	j=1;
	q=p;
	NoAnb=TRUE;
	if (q->getflag()!=6)
	     i++;
	while ((q->left!=NULL)&&(q->left->getflag()!=0)
			&& (q->getfiveflag()!=9) && (q->left->visit!=TRUE))
	{
		q=q->left;
		if (q->getflag()!=6)
			i++;
	}
	returnpoint=p;
	result=p;
	breakpoint=q;
	while(1)
    {
		if (NoAnb)
		{
			switch (q->getflag())
			{
			case 1:
					if (i>1)
					{
						if (j==1)
							fprintf(::fp,"%s\t%s\t\t;%s\n",q->code,q->addr,q->name);
						else
							fprintf(::fp,"%s\t%s\t\t;%s\n","AND",q->addr,q->name);
						j++;
					}
					else
						fprintf(::fp,"%s\t%s\t\t;%s\n","OR",q->addr,q->name);
					break;
			case 2:
					if (i>1)
					{
						if (j==1)
							fprintf(::fp,"%s\t%s\t\t;%s\n",q->code,q->addr,q->name);
						else
							fprintf(::fp,"%s\t%s\t\t;%s\n","ANI",q->addr,q->name);
						j++;
					}
					else
						fprintf(::fp,"%s\t%s\t\t;%s\n","ORI",q->addr,q->name);
					break;
			case 3:
			case 4:
					fprintf(::fp,"%s\t%s\t\t;%s\n",q->code,q->addr,q->name);
			default:
					break;
			}//end of switch (q->getflag())
			q->setvisit(TRUE);
			if (q==p && j>1)
				fprintf(::fp,"%s\n","ORB");
			
			if (q->down!=NULL)
			{
				if (q!=p)
				{
					temp=ORBtest(q,&point);
					if (temp!=NULL)
						result=ORBcompile(temp);
				}
				if (q==p)
				{
					temp=ORBtest(q,&point);
					if (temp!=NULL && breakpoint->getypoint()==point.getypoint())
						returnpoint=ORBcompile(temp);
				}
			}
			if (q==p)
				break;
			else
				q=q->right;
		}// end of if (NoAnb)
		if (q->unup!=NULL)
		{
			temp=ANBtest(q);
			if (temp!=NULL)
			{
				NoAnb=0;
				result=ANBcompile(q,temp);
				if (j>1)
				fprintf(::fp,"%s\n","ANB");
				
				while (q->visit==TRUE)
					if (q==p)
						break;
					else
						q=q->right;
				if (q==p && q->visit==TRUE)
				{
					if (j>1)
						fprintf(::fp,"%s\n","ORB");
					if (result->down!=NULL)
					{
						temp=ORBtest(result,&point);
						if (temp!=NULL && breakpoint->getypoint()==point.getypoint())
							returnpoint=ORBcompile(temp);
					}
					break;
				}
			}// end of (m!=0)
			else
				NoAnb=1;
		}//end of if (q->unup!=NULL)
     }//end of while (1); (q!=p)

     return returnpoint;
}

int LIST::compile(IOPOINT *head)
{
	IOPOINT *p;
	IOPOINT *temp;
	IOPOINT *q;
	IOPOINT *returnpoint;
	IOPOINT point;
	int flag;
	BOOL found;
	BOOL NoAnb;
	//int  r;
	int i;
	if ((fp=fopen(::filename,"a+"))==NULL)
		return 5;
	p=head;
	i=0;
	NoAnb=TRUE;
	flag=p->getflag();
	found=FALSE;
	while(1)
	{
		while ((flag<7) && (p->right!=NULL))
		{
			if (p->unup!=NULL)

⌨️ 快捷键说明

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