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

📄 tonfaview.cpp

📁 正规(则)表达式转化为NFA
💻 CPP
📖 第 1 页 / 共 4 页
字号:
				pDC->SetTextColor(RGB(241,147,115));
				pDC->TextOut((GetDocument()->MINTable.tableList[i2].point.x+GetDocument()->MINTable.tableList[i2].point.x+4*LO/6)/2,GetDocument()->MINTable.tableList[i2].point.y-LO*4/3,p->token);
			}
			if((i2>p->data)&&(p->data!=-1))
			//if((i2>p->data)&&(p->data!='$')) //小于 画弧线
			{
				pDC->SelectObject(&redpen);
				PO[0]=CPoint(GetDocument()->MINTable.tableList[p->data].point.x,GetDocument()->MINTable.tableList[p->data].point.y);
				PO[3]=CPoint(GetDocument()->MINTable.tableList[i2].point.x,GetDocument()->MINTable.tableList[i2].point.y);
			//	PO[2]=CPoint((PO[0].x+PO[3].x)/2+abs(PO[0].y-PO[3].y)/1.5,(PO[0].y+PO[3].y)/2-abs(PO[0].x-PO[3].x)/6);
				PO[2]=CPoint((PO[0].x+PO[3].x)/2+abs(PO[0].y-PO[3].y)/1.5,(PO[0].y+PO[3].y)/2-abs(PO[0].x-PO[3].x)/6);
				PO[1]=PO[2];//CPoint(((p[0].x+p[3].x)*1)/2+10,((p[0].y+p[3].y)*1)/2-50);					
				pDC->PolyBezier(PO,4);

					//画箭头
	//MessageBox("");
				CString sinfo=GetDocument()->ListStrMIN(p->data);
				double h,w;
				w=SetMINPos.LO*0.2*sinfo.GetLength()/2.0;//椭圆的Width
				h=SetMINPos.LO*0.5/2.0;//椭圆的Heigth;
				float k;//斜率
		        float af=0.5;//角度
				double x1,y1,x2,y2,ox,oy;

				x1=PO[1].x;
				y1=PO[1].y;
				x2=PO[0].x;
				y2=PO[0].y;
                   
				k=(y2-y1)/(x2-x1+0.000001);
	
				ox=x2+w*h/sqrt(pow(h,2)+pow(w,2)*pow(k,2));
				oy=y2+w*h*k/sqrt(pow(h,2)+pow(w,2)*pow(k,2));

				pDC->SelectObject(&Dirbrush);
				pDC->Ellipse(ox-SetMINPos.LO/6,oy-SetMINPos.LO/6,ox+SetMINPos.LO/6,oy+SetMINPos.LO/6);
//10|(01|1)*0|1*#10|(01|1)*0|1*#
		
					//---------------------------
				pDC->SetTextColor(RGB(54,54,54));
				pDC->TextOut(PO[1].x,PO[1].y,p->token);
			}
			p=p->next;
		}
	}	

	//画结点
	int maxw=0;
	pDC->SelectObject(&colorbrush);
	for(int i=0;i<=SetMINPos.num;i++)
	{
		if(GetDocument()->MA[i]->head==NULL)
			continue;
		CString sinfo=GetDocument()->ListStrMIN(i);
		double h,w;
		w=SetMINPos.LO*0.2*sinfo.GetLength()/2;//椭圆的Width
		h=SetMINPos.LO*0.5/2;//椭圆的Heigth;
		if(maxw<w*2)maxw=w*2;
	
		p=GetDocument()->zzList.head;
		while(p!=NULL)
		{
			if(p->data==i)
			{
				pDC->SelectObject(&Tbrush);
				pDC->Ellipse(GetDocument()->MINTable.tableList[i].point.x-w,GetDocument()->MINTable.tableList[i].point.y-h,GetDocument()->MINTable.tableList[i].point.x+w,GetDocument()->MINTable.tableList[i].point.y+h);
				pDC->Ellipse(GetDocument()->MINTable.tableList[i].point.x-w+w/10,GetDocument()->MINTable.tableList[i].point.y-h+h/10,GetDocument()->MINTable.tableList[i].point.x+w-w/10,GetDocument()->MINTable.tableList[i].point.y+h-h/10);
	    		break;
			}
			p=p->next;
		}
		if(p==NULL)
		{
			pDC->SelectObject(&colorbrush);
			pDC->Ellipse(GetDocument()->MINTable.tableList[i].point.x-w,GetDocument()->MINTable.tableList[i].point.y-h,GetDocument()->MINTable.tableList[i].point.x+w,GetDocument()->MINTable.tableList[i].point.y+h);
		}
		CString CtrNum;
		CtrNum.Format("%d",i);
		int m_length=CtrNum.GetLength();
		pDC->SetTextColor(RGB(255,255,0));
		pDC->TextOut(GetDocument()->MINTable.tableList[i].point.x+(SetMINPos.LO/2)-w/1.3-23,GetDocument()->MINTable.tableList[i].point.y-h*1.5+(SetMINPos.LO/2)-15,sinfo);
	}
	//区域
//	
	pDC->BeginPath();
//	CClientDC dc(this);
//	CPoint MyPoint=MyScroll;
//	pDC->DPtoLP(&MyPoint);
	for(i=0;i<=SetMINPos.num;i++)
	{
		CString sinfo=GetDocument()->ListStrMIN(i);
		int h,w;
		w=SetMINPos.LO*0.2*sinfo.GetLength();
		h=SetMINPos.LO;
		pDC->Ellipse(GetDocument()->MINTable.tableList[i].point.x-MyScroll.x-w/2,GetDocument()->MINTable.tableList[i].point.y-MyScroll.y-h/2,GetDocument()->MINTable.tableList[i].point.x-MyScroll.x+w/2,GetDocument()->MINTable.tableList[i].point.y-MyScroll.y+h/2);
	}
	pDC->EndPath();
	CRgn trgn;
	trgn.CreateFromPath(pDC);//	(&dc);
	m_MINDFA.CopyRgn(&trgn);
	trgn.DeleteObject();
//
	stockbrush.DeleteObject();
	colorbrush.DeleteObject();
	Tbrush.DeleteObject();
	Dirbrush.DeleteObject();
	colorpen.DeleteObject();
	redpen.DeleteObject();//bezier
	quanpen.DeleteObject();
	zihuanpen.DeleteObject();
}

void CTONFAView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_NFA.PtInRegion(point)&&m_TBarNFA)
	{
		op=point;	
		moveflag=0;
		LBtnDown=true;
	}
	if(m_TABLE.PtInRegion(point)&&m_TBarTABLE)
	{
		op=point;	
		moveflag=1;
		LBtnDown=true;
	}
	if(m_DFA.PtInRegion(point)&&m_TBarDFA)
	{
		op=point;	
		moveflag=2;
		LBtnDown=true;
	}
	if(m_MINTABLE.PtInRegion(point)&&m_TBarMINTABLE)
	{
		op=point;	
		moveflag=3;
		LBtnDown=true;
	}
	if(m_MINDFA.PtInRegion(point)&&m_TBarMINDFA)
	{
		op=point;	
		moveflag=4;
		LBtnDown=true;
	}
	CScrollView::OnLButtonDown(nFlags, point);
}

void CTONFAView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_Zoom&&m_TBarNFA)
	{
		SetNFAPos.LO=SetNFAPos.LO+4;
	}
	if(m_Zoom&&m_TBarDFA)
	{
		SetDFAPos.LO=SetDFAPos.LO+4;
	}
	if(m_Zoom&&m_TBarMINDFA)
	{
		SetMINPos.LO=SetMINPos.LO+4;
	}
	LBtnDown=false;
	//Invalidate();
	InvalidateRect(NULL,FALSE);
	CScrollView::OnLButtonUp(nFlags, point);
}


void CTONFAView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(LBtnDown==true&&m_Move)
	{
		switch(moveflag)
		{
		case 0://NFA结点
			if(m_TBarNFA&&nFlags==1)
			{
				SetNFAPos.LOx=SetNFAPos.LOx+point.x-op.x;
				SetNFAPos.LOy=SetNFAPos.LOy+point.y-op.y;
				op=point;
				//Invalidate();
				InvalidateRect(NULL,FALSE);
			}
			break;
		case 1:
			if(m_TBarTABLE&&nFlags==1)
			{
				DFA_TABLE_LEFT=DFA_TABLE_LEFT+point.x-op.x;
				DFA_TABLE_TOP=DFA_TABLE_TOP+point.y-op.y;
				op=point;
				//Invalidate();
				InvalidateRect(NULL,FALSE);
			}
			break;
		case 2://DFA结点
			if(m_TBarDFA&&nFlags==1)
			{
				SetDFAPos.LOx=SetDFAPos.LOx+point.x-op.x;
				SetDFAPos.LOy=SetDFAPos.LOy+point.y-op.y;
				op=point;
				//Invalidate();
				InvalidateRect(NULL,FALSE);
			}
			break;
		case 3:
			if(m_TBarMINTABLE&&nFlags==1)
			{
				DFA_MINTABLE_LEFT=DFA_MINTABLE_LEFT+point.x-op.x;
				DFA_MINTABLE_TOP=DFA_MINTABLE_TOP+point.y-op.y;
				op=point;
				//Invalidate();
				InvalidateRect(NULL,FALSE);
			}
			break;
		case 4://MINDFA结点
			if(m_TBarMINDFA&&nFlags==1)
			{
				SetMINPos.LOx=SetMINPos.LOx+point.x-op.x;
				SetMINPos.LOy=SetMINPos.LOy+point.y-op.y;
				op=point;
				//Invalidate();
				InvalidateRect(NULL,FALSE);
			}
			break;
		default:
			break;
		}
		::SetCursor(AfxGetApp()->LoadCursor(IDC_HITMOVE));
	}
	else if(m_Move)
		::SetCursor(AfxGetApp()->LoadCursor(IDC_MOVE));
	CScrollView::OnMouseMove(nFlags, point);
}

void CTONFAView::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_Zoom)
	{
		if(m_TBarNFA)
		{
			SetNFAPos.LO=SetNFAPos.LO-4;
			//Invalidate();
			InvalidateRect(NULL,FALSE);
		}
		if(m_TBarDFA)
		{
			SetDFAPos.LO=SetDFAPos.LO-4;
			//Invalidate();
			InvalidateRect(NULL,FALSE);
		}
		if(m_TBarMINDFA)
		{
			SetMINPos.LO=SetMINPos.LO-4;
			//Invalidate();
			InvalidateRect(NULL,FALSE);
		}
	}
	CScrollView::OnRButtonDown(nFlags, point);
}

void CTONFAView::OnMove() 
{
	// TODO: Add your command handler code here
	m_Move=true;
	m_Zoom=false;
}
void CTONFAView::OnUpdateMove(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_Move);
}

void CTONFAView::OnZoom() 
{
	// TODO: Add your command handler code here
	m_Move=false;
	m_Zoom=true;
}

void CTONFAView::OnUpdateZoom(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_Zoom);
}

void CTONFAView::OnNfa() 
{
	// TODO: Add your command handler code here
	m_TBarNFA=!m_TBarNFA;
	InvalidateRect(NULL,FALSE);
	//m_TBarDFA=m_TBarTABLE=false;
}

void CTONFAView::OnUpdateNfa(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_TBarNFA);
}

void CTONFAView::OnTable() 
{
	// TODO: Add your command handler code here
	m_TBarTABLE=!m_TBarTABLE;
	InvalidateRect(NULL,FALSE);
	//m_TBarNFA=m_TBarDFA=false;
}

void CTONFAView::OnUpdateTable(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_TBarTABLE);
}

void CTONFAView::OnDfa() 
{
	// TODO: Add your command handler code here
	m_TBarDFA=!m_TBarDFA;
	InvalidateRect(NULL,FALSE);
	//m_TBarTABLE=m_TBarNFA=false;
}

void CTONFAView::OnUpdateDfa(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_TBarDFA);
}

void CTONFAView::OnMintable() 
{
	// TODO: Add your command handler code here
	m_TBarMINTABLE=!m_TBarMINTABLE;
	InvalidateRect(NULL,FALSE);
}

void CTONFAView::OnUpdateMintable(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_TBarMINTABLE);
}

void CTONFAView::OnMin() 
{
	// TODO: Add your command handler code here
	m_TBarMINDFA=!m_TBarMINDFA;
	InvalidateRect(NULL,FALSE);
}

void CTONFAView::OnUpdateMin(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_TBarMINDFA);
}


BOOL CTONFAView::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	return TRUE;
	//InvalidateRect(NULL,FALSE);
	return CScrollView::OnEraseBkgnd(pDC);
}

⌨️ 快捷键说明

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