📄 tonfaview.cpp
字号:
// TONFAView.cpp : implementation of the CTONFAView class
//
#include "stdafx.h"
#include "TONFA.h"
#include "TONFADoc.h"
#include "TONFAView.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTONFAView
IMPLEMENT_DYNCREATE(CTONFAView, CScrollView)
BEGIN_MESSAGE_MAP(CTONFAView, CScrollView)
//{{AFX_MSG_MAP(CTONFAView)
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_COMMAND(ID_MOVE, OnMove)
ON_UPDATE_COMMAND_UI(ID_MOVE, OnUpdateMove)
ON_COMMAND(ID_ZOOM, OnZoom)
ON_UPDATE_COMMAND_UI(ID_ZOOM, OnUpdateZoom)
ON_COMMAND(ID_NFA, OnNfa)
ON_UPDATE_COMMAND_UI(ID_NFA, OnUpdateNfa)
ON_COMMAND(ID_TABLE, OnTable)
ON_UPDATE_COMMAND_UI(ID_TABLE, OnUpdateTable)
ON_COMMAND(ID_DFA, OnDfa)
ON_UPDATE_COMMAND_UI(ID_DFA, OnUpdateDfa)
ON_WM_ERASEBKGND()
ON_COMMAND(ID_MINTABLE, OnMintable)
ON_UPDATE_COMMAND_UI(ID_MINTABLE, OnUpdateMintable)
ON_COMMAND(ID_MIN, OnMin)
ON_UPDATE_COMMAND_UI(ID_MIN, OnUpdateMin)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTONFAView construction/destruction
CTONFAView::CTONFAView()
{
// TODO: add construction code here
SetNFAPos.LO=40;
SetNFAPos.LOx=300;
SetNFAPos.LOy=100;
SetNFAPos.num=0;
SetDFAPos.LO=35;
SetDFAPos.LOx=80;
SetDFAPos.LOy=80;
SetDFAPos.num=0;
SetMINPos.LO=30;
SetMINPos.LOx=100;
SetMINPos.LOy=200;
SetMINPos.num=0;
DFA_TABLE_LEFT=20;
DFA_TABLE_TOP=80;
DFA_TABLE_WIDTH=160;
DFA_TABLE_HEIGHT=30;
DFA_MINTABLE_LEFT=300;
DFA_MINTABLE_TOP=200;
DFA_MINTABLE_WIDTH=160;
DFA_MINTABLE_HEIGHT=30;
IsInit=true;
LBtnDown=false;
m_Move=true;
m_Zoom=false;
m_TBarNFA=m_TBarDFA=m_TBarTABLE=m_TBarMINTABLE=m_TBarMINDFA=false;
flag=-1;//未生成
moveflag=-1;
m_NFA.CreateRectRgn(0,0,0,0);
m_TABLE.CreateRectRgn(0,0,0,0);
m_DFA.CreateRectRgn(0,0,0,0);
m_MINTABLE.CreateRectRgn(0,0,0,0);
m_MINDFA.CreateRectRgn(0,0,0,0);
}
CTONFAView::~CTONFAView()
{
}
BOOL CTONFAView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTONFAView drawing
void CTONFAView::MyDraw(CDC* pDC)
{
RECT Rect;
GetClientRect(&Rect);
CPoint MyScroll=GetScrollPosition();
CDC *MemDC;
MemDC=new CDC;
MemDC->CreateCompatibleDC(pDC);
CBitmap MemBitmap;
MemBitmap.CreateCompatibleBitmap(pDC,Rect.right+MyScroll.x,Rect.bottom+MyScroll.y);
CBitmap *pOldBitmap=MemDC->SelectObject(&MemBitmap);
//背景设为白色
CRect rc;
GetClientRect(rc);
// CPoint MyScroll=GetScrollPosition();
CRect rc1(MyScroll.x,MyScroll.y,rc.right+MyScroll.x,rc.bottom+MyScroll.y);
//CRect rc(0,0,10000,10000);
COLORREF crBackGroundColor=RGB(255,255,255);
//pDC->FillSolidRect(rc, crBackGroundColor);
MemDC->FillSolidRect(rc1, crBackGroundColor);
switch(flag)
{
case -1:
break;
case 2:
InitMINPosition(GetDocument()->MINTable);
if(m_TBarMINTABLE)
DrawMINTABLE(MemDC);
if(m_TBarMINDFA)
DrawMINDFA(MemDC);
case 1:
InitDFAPosition(GetDocument()->DFATable);
if(m_TBarTABLE)
DrawTABLE(MemDC);
if(m_TBarDFA)
DrawDFA(MemDC);
case 0:
InitNFAPosition(GetDocument()->NFATable);
if(SetNFAPos.num!=0){
if(m_TBarNFA)DrawNFA(MemDC);
}
else
break;
default:
break;
}
pDC->BitBlt(MyScroll.x,MyScroll.y,Rect.right+MyScroll.x,Rect.bottom+MyScroll.y,MemDC,MyScroll.x,MyScroll.y,SRCCOPY);
delete MemDC;
pOldBitmap->DeleteObject();
}
void CTONFAView::OnDraw(CDC* pDC)
{
CTONFADoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if(IsInit)
{
IsInit=false;
/* CRect rc;
GetClientRect(rc);
COLORREF crBackGroundColor=RGB(255,255,255);
pDC->FillSolidRect(rc,crBackGroundColor);
}
else{
MyDraw(pDC);*/
}
MyDraw(pDC);
//pDC->TextOut(0,0,pDoc->m_Title);
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 10000;
SetScrollSizes(MM_TEXT, sizeTotal);
}
void CTONFAView::OnInitialUpdate()
{
LOGFONT m_lf;
memset(&m_lf, 0, sizeof(LOGFONT)); // 成员为0
m_lf.lfCharSet = GB2312_CHARSET;
strcpy((LPSTR)&(m_lf.lfFaceName), "Fixedsys");
//SetTabStops(4 * 4); // 设置一个停止位等于4个字符
HFONT hFont;
hFont = ::CreateFontIndirect(&m_lf);
if (hFont != NULL)
SendMessage(WM_SETFONT, (WPARAM)hFont);
CScrollView::OnInitialUpdate();
CTONFAApp *pApp=(CTONFAApp *)AfxGetApp();
pApp->pView=this;
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 10000;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CTONFAView printing
BOOL CTONFAView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTONFAView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTONFAView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTONFAView diagnostics
#ifdef _DEBUG
void CTONFAView::AssertValid() const
{
CScrollView::AssertValid();
}
void CTONFAView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CTONFADoc* CTONFAView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTONFADoc)));
return (CTONFADoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTONFAView message handlers
void CTONFAView::InitNFAPosition(StateTable &table)
{
for(int i=0;i<TABNUM;i++)
{
table.tableList[i].point.x=SetNFAPos.LOx;
table.tableList[i].point.y=SetNFAPos.LOy;
}
int tempmax=SetNFAPos.LOy-2*SetNFAPos.LO;
if(table.tableList[0].count!=0)
{
ListNode * p;
p=table.tableList[0].next;
while(p!=NULL)
{
// for(int i=0;i<table.tableList[0].count;i++)
// {
for(int j=0;j<TABNUM;j++)
{
if(table.tableList[j].point.x==table.tableList[0].point.x+4*SetNFAPos.LO)
table.tableList[j].point.y=table.tableList[j].point.y-SetNFAPos.LO;
}
for(int k=0;k<TABNUM;k++)
{
if(table.tableList[k].point.x==table.tableList[0].point.x+4*SetNFAPos.LO)
{
if(table.tableList[k].point.y>tempmax)
tempmax=table.tableList[k].point.y;
}
}
table.tableList[p->data].point.x=table.tableList[0].point.x+4*SetNFAPos.LO;
table.tableList[p->data].point.y=tempmax+2*SetNFAPos.LO;
tempmax=-10000;
p=p->next;
}
}
for(int i1=1;i1<TABNUM;i1++)
{
if(table.tableList[i1].count==1)
{
if(table.tableList[table.tableList[i1].next->data].point.x==SetNFAPos.LOx)
{
table.tableList[table.tableList[i1].next->data].point.x=table.tableList[i1].point.x+4*SetNFAPos.LO;
table.tableList[table.tableList[i1].next->data].point.y=table.tableList[i1].point.y;
}
}
if(table.tableList[i1].count>1)
{
for(int j1=0;j1<TABNUM;j1++)
{
if(table.tableList[j1].point.x==table.tableList[i1].point.x)
{
if(table.tableList[j1].point.y>table.tableList[i1].point.y)
table.tableList[j1].point.y=table.tableList[j1].point.y+(table.tableList[i1].count-1)*2*SetNFAPos.LO;
}
}//下面的结点下移
table.tableList[i1].point.y=table.tableList[i1].point.y+(table.tableList[i1].count-1)*SetNFAPos.LO;
//自己居中
/////////////////设置孩子位置x,y
ListNode * p;
p=table.tableList[i1].next;
int i2=0;
while(p!=NULL)
{
//for(int i2=0;i2<table.tableList[i1].count;i2++)
//{
if(table.tableList[p->data].point.x==SetNFAPos.LOx)
{
table.tableList[p->data].point.x=table.tableList[i1].point.x+4*SetNFAPos.LO;
table.tableList[p->data].point.y=table.tableList[i1].point.y+i2*2*SetNFAPos.LO-(table.tableList[i1].count-1)*SetNFAPos.LO;
}
i2++;
p=p->next;
}
}
}
}
void CTONFAView::InitDFAPosition(StateTable &table)
{
for(int i=0;i<TABNUM;i++)
{
table.tableList[i].point.x=SetDFAPos.LOx;
table.tableList[i].point.y=SetDFAPos.LOy;
}
int tempmax=SetDFAPos.LOy-2*SetDFAPos.LO;
if(table.tableList[0].count!=0)
{
ListNode * p;
p=table.tableList[0].next;
while(p!=NULL)
{
// for(int i=0;i<table.tableList[0].count;i++)
// {
for(int j=0;j<TABNUM;j++)
{
if(table.tableList[j].point.x==table.tableList[0].point.x+4*SetDFAPos.LO)
table.tableList[j].point.y=table.tableList[j].point.y-SetDFAPos.LO;
}
for(int k=0;k<TABNUM;k++)
{
if(table.tableList[k].point.x==table.tableList[0].point.x+4*SetDFAPos.LO)
{
if(table.tableList[k].point.y>tempmax)
tempmax=table.tableList[k].point.y;
}
}
table.tableList[p->data].point.x=table.tableList[0].point.x+4*SetDFAPos.LO;
table.tableList[p->data].point.y=tempmax+2*SetDFAPos.LO;
tempmax=-5000;
p=p->next;
}
}
for(int i1=1;i1<TABNUM;i1++)
{
if(table.tableList[i1].count==1)
{
if(table.tableList[table.tableList[i1].next->data].point.x==SetDFAPos.LOx)
{
table.tableList[table.tableList[i1].next->data].point.x=table.tableList[i1].point.x+4*SetDFAPos.LO;
table.tableList[table.tableList[i1].next->data].point.y=table.tableList[i1].point.y;
}
}
if(table.tableList[i1].count>1)
{
for(int j1=0;j1<TABNUM;j1++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -