void CTestView::OnDraw(CDC* pDC)
{
CTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//EmptyAndSerializeToList();
if(pT)
{
if(pT->GetRoot())
{
pT-> PreOrderBSTPrint(pT->GetRoot() , pDC);
OnDrawDimension(pDC);
}
}
}
/
/
void CTestView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
pT = & GetDocument()->T ;
m_pSetX = & GetDocument()->m_SetX;
m_pSetY = & GetDocument()->m_SetY;
//m = & GetDocument()->m_SeriesData;
CTestDoc * pDoc = GetDocument() ;
ml = & GetDocument()-> ml;
if (!ml->IsEmpty())
{
//把数据写入二叉树
POSITION pos0 = ml->FindIndex(0);
CBox* c0 = (CBox* )ml->GetAt(pos0);
BinarySearchTreeNode* n0 = new BinarySearchTreeNode (c0);
pT->SetRoot(n0);
/
POSITION pos1 = ml->FindIndex(1);
CBox* c1 = (CBox* )ml->GetAt(pos1);
BinarySearchTreeNode* n1 = new BinarySearchTreeNode (c1);
n0->leftChild = n1 ;
n1->ParentChild = n0;
// Dump the list elements to the debug window.
POSITION pos3 = ml->GetHeadPosition();
for (int i = 0; i < ml->GetCount(); i++)
{
//从第3个开始
if(i >= 2)
{
//取得中心点
POSITION pos4 = ml->FindIndex(i);
CBox* d1 = (CBox* )ml->GetAt(pos4);
CRect * rt4 = & d1->GetBox();
CPoint pt = rt4->CenterPoint();
int boxtype = d1->GetToType();
if(2 == boxtype)
{
//插入节点
pT-> InsertBST( pT->GetRoot(), pt ,2);
}
if(12 == boxtype)
{
//插入节点
pT-> InsertBST( pT->GetRoot(), pt ,12);
}
if(5 == boxtype)
{
//左平开
pT-> OperateToNode( pT->GetRoot(), pt, 0, 5);
}
if(6 == boxtype)
{
//左平开
pT-> OperateToNode( pT->GetRoot(), pt, 0, 6);
}
if(7 == boxtype)
{
//左平开
pT-> OperateToNode( pT->GetRoot(), pt, 0, 7);
}
delete d1;
}
}
EmptyAndSerializeToList();
}
void CTestView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(pT)
{
if(pT->GetRoot())
{
// AfxMessageBox("0");
//更新选中状态
pT-> SetIsSeleted(pT->GetRoot() , point);
if(2 == iDrawStatic)
{
//插入节点
pT-> InsertBST( pT->GetRoot(), point ,2);
//清空链表,二叉树中的节点重新插入链表
EmptyAndSerializeToList();
}
if(12 == iDrawStatic)
{
//插入节点
pT-> InsertBST( pT->GetRoot(), point ,12);
//清空链表,二叉树中的节点重新插入链表
EmptyAndSerializeToList();
}
iDrawStatic = 0 ;
GetDocument()->UpdateAllViews(NULL);
}
}
CView::OnLButtonDown(nFlags, point);
}
void CTestView::OnMenuModify()
{
// TODO: Add your command handler code here
CInPutDlg dlg;
if(IDOK == dlg.DoModal())
{
CString str = dlg.m_Edit1;
pT-> OperateToNode( pT->GetRoot(), tempPt, atoi(str), 75);
GetDocument()->UpdateAllViews(NULL);
}
}
void CTestView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//加载菜单
CMenu menu;
menu.LoadMenu(IDR_MENU1); // 读取资源
ClientToScreen(&point);
menu.GetSubMenu(0) -> TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this );
//先转换座标, 再赋值
ScreenToClient(&point);
tempPt = point ;
CView::OnRButtonDown(nFlags, point);
}
void CTestView::OnMenuDeleted()
{
// TODO: Add your command handler code here
pT-> OperateToNode( pT->GetRoot(), tempPt, 0, 76);
GetDocument()->UpdateAllViews(NULL);
}
void CTestView::OnMenuitem32774()
{
// TODO: Add your command handler code here
iDrawStatic = 12 ;
}
void CTestView::OnMenuitem32778()
{
// TODO: Add your command handler code here
//左平开
pT-> OperateToNode( pT->GetRoot(), tempPt, 0, 6);
//清空链表,二叉树中的节点重新插入链表
EmptyAndSerializeToList();
GetDocument()->UpdateAllViews(NULL);
}
void CTestView::OnMenuitem32777()
{
// TODO: Add your command handler code here
//左平开
pT-> OperateToNode( pT->GetRoot(), tempPt, 0, 5);
//清空链表,二叉树中的节点重新插入链表
EmptyAndSerializeToList();
GetDocument()->UpdateAllViews(NULL);
}
void CTestView::OnMenuitem32779()
{
// TODO: Add your command handler code here
//左平开
pT-> OperateToNode( pT->GetRoot(), tempPt, 0, 7);
//清空链表,二叉树中的节点重新插入链表
EmptyAndSerializeToList();
GetDocument()->UpdateAllViews(NULL);
}
void CTestView::OnMenuFrame()
{
// TODO: Add your command handler code here
if(pT && !pT->GetRoot())
{
//窗框
CRect* r1 = new CRect(100,100,800,500);
CBox* c1 = new CBox(r1);
BinarySearchTreeNode* n1 = new BinarySearchTreeNode (c1);
pT->SetRoot(n1);
CRect* r2 = new CRect(110,110,790,490);
CBox* c2 = new CBox(r2);
BinarySearchTreeNode* n2 = new BinarySearchTreeNode (c2);
n1->leftChild = n2 ;
n2->ParentChild = n1;
//清空链表,二叉树中的节点重新插入链表
EmptyAndSerializeToList();
m_pSetX->insert(100);
m_pSetX->insert(800);
m_pSetY->insert(100);
m_pSetY->insert(500);
GetDocument()->UpdateAllViews(NULL);
}
}
void CTestView::OnDrawDimension(CDC *pDC)
{
pDC->SelectStockObject(NULL_BRUSH);
pT-> UpDataToSet( pT->GetRoot(), &m_pSetX, &m_pSetY);
//CString strx ;
set
itx = m_pSetX->begin();
//int i = 0;
while(itx != m_pSetX->end())
{
// //输出左边数据
// str.Format("%d--%d", i,*it);
// pDC->TextOut(50,i*20,str);
//不是第一个
if(*itx != *(m_pSetX->begin()) )
{
// m表示it的前一个
int m = *(--itx );
++itx;
//输出中梃尺寸标注
CString str1 ;
str1.Format("%d", *itx-m);
pDC->TextOut(m+ (*itx-m)/2,510,str1);
pDC->MoveTo(m,530); pDC->LineTo(*itx,530);
pDC->MoveTo(m,520); pDC->LineTo(m,540);
pDC->MoveTo(*itx,520); pDC->LineTo(*itx,540);
}
//i++;
++itx;
}
//
int sx = *(m_pSetX->begin());
int ex = *(--m_pSetX->end() );
//int r =0 ;
//输出总宽度
if(m_pSetX->size() > 2 )
{
//输出总宽度尺寸标注
CString str2 ;
str2.Format("%d", (ex-sx));
pDC->TextOut(sx+(ex-sx)/2,540,str2);
pDC->MoveTo(sx,560); pDC->LineTo(ex,560);
pDC->MoveTo(sx,550); pDC->LineTo(sx,570);
pDC->MoveTo(ex,550); pDC->LineTo(ex,570);
}
//CString strx ;
set
ity = m_pSetY->begin();
//int j = 0;
while(ity != m_pSetY->end())
{
//不是第一个
if(*ity != *(m_pSetY->begin()) )
{
// m表示it的前一个
int m = *(--ity );
++ity;
//输出中梃尺寸标注
CString str1 ;
str1.Format("%d", *ity-m);
pDC->TextOut(830,m+ (*ity-m)/2,str1);
pDC->MoveTo(830,m); pDC->LineTo(830,*ity);
pDC->MoveTo(820,m); pDC->LineTo(840,m);
pDC->MoveTo(820,*ity); pDC->LineTo(840,*ity);
}
//j++;
++ity;
}
/*
*/
//
int sy = *(m_pSetY->begin());
int ey = *(--m_pSetY->end() );
//int r =0 ;
//输出总宽度
if(m_pSetY->size() > 2 )
{
//输出总高度尺寸标注
CString str2 ;
str2.Format("%d", (ey-sy));
pDC->TextOut(860,sy+(ey-sy)/2,str2);
pDC->MoveTo(860,sy); pDC->LineTo(860,ey);
pDC->MoveTo(850,sy); pDC->LineTo(870,sy);
pDC->MoveTo(850,ey); pDC->LineTo(870,ey);
}
}
void CTestView::OnMenuitem32782()
{
// TODO: Add your command handler code here
CSeriesDataDlg dlg;
//初始化对话框的CTypedPtrMap指针
dlg.pmap = &m_Records;
dlg.DoModal();
}
void CTestView::OnMenuVent()
{
// TODO: Add your command handler code here
iDrawStatic = 2 ;
}
void CTestView::EmptyAndSerializeToList()
{
//清空链表,二叉树中的节点重新插入链表
while (!ml->IsEmpty())
{
ml->RemoveHead();
}
pT->ml = ml;
pT->BSTSerialize( pT->GetRoot());
}