FunctionView
来源:互联网 发布:中国核事故知乎 编辑:程序博客网 时间:2024/06/07 14:47
#include "stdafx.h"
#include "MainFrm.h"
#include "FunctionView.h"
#include "Resource.h"
#include "iDART_UI.h"
#include "MyPropertySheet.h"
#include "TimerManagerPage.h"
class CFunctionViewMenuButton : public CMFCToolBarMenuButton
{
friend class CFunctionView;
DECLARE_SERIAL(CFunctionViewMenuButton)
public:
CFunctionViewMenuButton(HMENU hMenu = NULL) : CMFCToolBarMenuButton((UINT)-1, hMenu, -1)
{
}
virtual void OnDraw(CDC* pDC, const CRect& rect, CMFCToolBarImages* pImages, BOOL bHorz = TRUE,
BOOL bCustomizeMode = FALSE, BOOL bHighlight = FALSE, BOOL bDrawBorder = TRUE, BOOL bGrayDisabledButtons = TRUE)
{
pImages = CMFCToolBar::GetImages();
CAfxDrawState ds;
pImages->PrepareDrawImage(ds);
CMFCToolBarMenuButton::OnDraw(pDC, rect, pImages, bHorz, bCustomizeMode, bHighlight, bDrawBorder, bGrayDisabledButtons);
pImages->EndDrawImage(ds);
}
};
IMPLEMENT_SERIAL(CFunctionViewMenuButton, CMFCToolBarMenuButton, 1)
//////////////////////////////////////////////////////////////////////
// 构造/析构
//////////////////////////////////////////////////////////////////////
CFunctionView::CFunctionView()
{
m_nCurrSort = ID_SORTING_GROUPBYTYPE;
m_scurItem = "";
//覆盖地理化
m_itemArray.Add("RSCP分布地理化");//-----0
m_itemArray.Add("ECIO分布地理化");
m_itemArray.Add("AMR UE发射功率地理化");
m_itemArray.Add("主服务小区 RSCP分布地理化");
m_itemArray.Add("主服务小区 ECIO分布地理化");
m_itemArray.Add("主服务小区 边界地理化");
m_itemArray.Add("主服务小区 RNC边界地理化");
m_itemArray.Add("主服务小区 LAC边界地理化");//-------7
//切换地理化
m_itemArray.Add("同频盲切分布地理化");//---8
m_itemArray.Add("软切换因子地理化");//----9
//用户分布地理化
m_itemArray.Add("全用户分布地理化");//----10
m_itemArray.Add("AMR用户分布地理化");
m_itemArray.Add("BE用户分布地理化");//----12
//A话务量地理化
m_itemArray.Add("AMR话务量地理化");//----13
//覆盖问题识别
m_itemArray.Add("弱覆盖地理化");//----14
m_itemArray.Add("导频污染地理化分布");
m_itemArray.Add("过覆盖地理化");
m_itemArray.Add("热点专题输出");//----17
}
CFunctionView::~CFunctionView()
{
}
BEGIN_MESSAGE_MAP(CFunctionView, CDockablePane)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_CONTEXTMENU()
ON_COMMAND(ID_CLASS_ADD_MEMBER_FUNCTION, OnClassAddMemberFunction)
ON_COMMAND(ID_CLASS_ADD_MEMBER_VARIABLE, OnClassAddMemberVariable)
ON_COMMAND(ID_CLASS_DEFINITION, OnClassDefinition)
ON_COMMAND(ID_CLASS_PROPERTIES, OnClassProperties)
ON_COMMAND(ID_NEW_FOLDER, OnNewFolder)
ON_WM_PAINT()
ON_WM_SETFOCUS()
ON_COMMAND_RANGE(ID_SORTING_GROUPBYTYPE, ID_SORTING_SORTBYACCESS, OnSort)
ON_UPDATE_COMMAND_UI_RANGE(ID_SORTING_GROUPBYTYPE, ID_SORTING_SORTBYACCESS, OnUpdateSort)
ON_MESSAGE(UM_CHECKSTATECHANGE, OnCheckChange)
ON_COMMAND(ID_PROPERTYSET, &CFunctionView::OnPropertyset)
ON_COMMAND(ID_RUN, &CFunctionView::OnRun)
ON_WM_TIMER()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFunctionView 消息处理程序
int CFunctionView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rectDummy;
rectDummy.SetRectEmpty();
// 创建视图:
const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT |TVS_CHECKBOXES| TVS_HASBUTTONS | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
if (!m_FunctionViewtree.Create(dwViewStyle, rectDummy, this, 2))
{
TRACE0("未能创建类视图\n");
return -1; //未能创建
}
// 加载图像:
m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_SORT);
m_wndToolBar.LoadToolBar(IDR_SORT, 0, 0, TRUE /* 已锁定*/);
OnChangeVisualStyle();
m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() & ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
m_wndToolBar.SetOwner(this);
// 所有命令将通过此控件路由,而不是通过主框架路由:
m_wndToolBar.SetRouteCommandsViaFrame(FALSE);
CMenu menuSort;
menuSort.LoadMenu(IDR_POPUP_SORT);
m_wndToolBar.ReplaceButton(ID_SORT_MENU, CFunctionViewMenuButton(menuSort.GetSubMenu(0)->GetSafeHmenu()));
CFunctionViewMenuButton* pButton = DYNAMIC_DOWNCAST(CFunctionViewMenuButton, m_wndToolBar.GetButton(0));
if (pButton != NULL)
{
pButton->m_bText = FALSE;
pButton->m_bImage = TRUE;
pButton->SetImage(GetCmdMgr()->GetCmdImage(m_nCurrSort));
pButton->SetMessageWnd(this);
}
// 填入一些静态树视图数据(此处只需填入虚拟代码,而不是复杂的数据)
FillFunctionView();
m_bIsStartPro = FALSE;
m_curPos = 0;
return 0;
}
void CFunctionView::OnSize(UINT nType, int cx, int cy)
{
CDockablePane::OnSize(nType, cx, cy);
AdjustLayout();
}
void CFunctionView::FillFunctionView()
{
HTREEITEM titleRoot = m_FunctionViewtree.InsertItem(_T("业务全集"), 0, 0);
m_FunctionViewtree.SetItemState(titleRoot, TVIS_BOLD, TVIS_BOLD);
m_FunctionViewtree.Expand(titleRoot,TVE_EXPAND);
HTREEITEM hRoot = m_FunctionViewtree.InsertItem(_T("覆盖分析"), 0, 0,titleRoot);
m_FunctionViewtree.SetItemState(hRoot, TVIS_BOLD, TVIS_BOLD);
HTREEITEM hClass = m_FunctionViewtree.InsertItem(_T("覆盖地理化"), 1, 1, hRoot);
HTREEITEM hItem;
for (int i = 0;i<8;++i)
{
hItem = m_FunctionViewtree.InsertItem(m_itemArray[i],3,3,hClass);
m_FunctionViewtree.SetItemData(hItem,i+3);//序号从3开始,
}
m_FunctionViewtree.Expand(hRoot, TVE_EXPAND);
hClass = m_FunctionViewtree.InsertItem(_T("切换地理化"), 1, 1, hRoot);
hItem = m_FunctionViewtree.InsertItem(m_itemArray[8], 3, 3, hClass);
m_FunctionViewtree.SetItemData(hItem,8+3);
hItem = m_FunctionViewtree.InsertItem(m_itemArray[9], 3, 3, hClass);
m_FunctionViewtree.SetItemData(hItem,9+3);
hClass = m_FunctionViewtree.InsertItem(_T("用户分布地理化"), 1, 1, hRoot);
hItem = m_FunctionViewtree.InsertItem(m_itemArray[10], 4, 4, hClass);
m_FunctionViewtree.SetItemData(hItem,10+3);//由于要保留这里的位置数,所以暂时处理为+3而不是13
hItem =m_FunctionViewtree.InsertItem(m_itemArray[11], 3, 3, hClass);
m_FunctionViewtree.SetItemData(hItem,11+3);
hItem =m_FunctionViewtree.InsertItem(m_itemArray[12], 3, 3, hClass);
m_FunctionViewtree.SetItemData(hItem,12+3);
hClass = m_FunctionViewtree.InsertItem(_T("话务量地理化"), 1, 1, hRoot);
hItem = m_FunctionViewtree.InsertItem(m_itemArray[13], 4, 4, hClass);
m_FunctionViewtree.SetItemData(hItem,13+3);
m_FunctionViewtree.Expand(hClass, TVE_EXPAND);
hClass = m_FunctionViewtree.InsertItem(_T("覆盖问题识别"), 1, 1, hRoot);
for (int i = 14;i<18;++i)
{
hItem = m_FunctionViewtree.InsertItem(m_itemArray[i],3,3,hClass);
m_FunctionViewtree.SetItemData(hItem,i+3);
}
//hClass = m_FunctionViewtree.InsertItem(_T("Globals"), 2, 2, hRoot);
//m_FunctionViewtree.InsertItem(_T("AAA"), 5, 5, hClass);
m_FunctionViewtree.Expand(titleRoot, TVE_EXPAND);
}
void CFunctionView::OnContextMenu(CWnd* pWnd, CPoint point)
{
CTreeCtrl* pWndTree = (CTreeCtrl*)&m_FunctionViewtree;
ASSERT_VALID(pWndTree);
if (pWnd != pWndTree)
{
CDockablePane::OnContextMenu(pWnd, point);
return;
}
if (point != CPoint(-1, -1))
{
// 选择已单击的项:
CPoint ptTree = point;
pWndTree->ScreenToClient(&ptTree);
UINT flags = 0;
HTREEITEM hTreeItem = pWndTree->HitTest(ptTree, &flags);
if (hTreeItem != NULL)
{
pWndTree->SelectItem(hTreeItem);
m_scurItem = pWndTree->GetItemText(hTreeItem);
}else
{
m_scurItem = "";
}
}
pWndTree->SetFocus();
CMenu menu;
menu.LoadMenu(IDR_POPUP_SORT);
CMenu* pSumMenu = menu.GetSubMenu(0);
if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx)))
{
CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))
return;
((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu);
UpdateDialogControls(this, FALSE);
}
}
void CFunctionView::AdjustLayout()
{
if (GetSafeHwnd() == NULL)
{
return;
}
CRect rectClient;
GetClientRect(rectClient);
int cyTlb = m_wndToolBar.CalcFixedLayout(FALSE, TRUE).cy;
m_wndToolBar.SetWindowPos(NULL, rectClient.left, rectClient.top, rectClient.Width(), cyTlb, SWP_NOACTIVATE | SWP_NOZORDER);
m_FunctionViewtree.SetWindowPos(NULL, rectClient.left + 1, rectClient.top + cyTlb + 1, rectClient.Width() - 2, rectClient.Height() - cyTlb - 2, SWP_NOACTIVATE | SWP_NOZORDER);
}
BOOL CFunctionView::PreTranslateMessage(MSG* pMsg)
{
return CDockablePane::PreTranslateMessage(pMsg);
}
void CFunctionView::OnSort(UINT id)
{
if (m_nCurrSort == id)
{
return;
}
m_nCurrSort = id;
CFunctionViewMenuButton* pButton = DYNAMIC_DOWNCAST(CFunctionViewMenuButton, m_wndToolBar.GetButton(0));
if (pButton != NULL)
{
pButton->SetImage(GetCmdMgr()->GetCmdImage(id));
m_wndToolBar.Invalidate();
m_wndToolBar.UpdateWindow();
}
}
void CFunctionView::OnUpdateSort(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(pCmdUI->m_nID == m_nCurrSort);
}
void CFunctionView::OnClassAddMemberFunction()
{
AfxMessageBox(_T("添加成员函数..."));
}
void CFunctionView::OnClassAddMemberVariable()
{
// TODO: 在此处添加命令处理程序代码
}
void CFunctionView::OnClassDefinition()
{
// TODO: 在此处添加命令处理程序代码
}
void CFunctionView::OnClassProperties()
{
// TODO: 在此处添加命令处理程序代码
}
void CFunctionView::OnNewFolder()
{
AfxMessageBox(_T("新建文件夹..."));
}
void CFunctionView::OnPaint()
{
CPaintDC dc(this); // 用于绘制的设备上下文
CRect rectTree;
m_FunctionViewtree.GetWindowRect(rectTree);
ScreenToClient(rectTree);
rectTree.InflateRect(1, 1);
dc.Draw3dRect(rectTree, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DSHADOW));
}
void CFunctionView::OnSetFocus(CWnd* pOldWnd)
{
CDockablePane::OnSetFocus(pOldWnd);
m_FunctionViewtree.SetFocus();
}
void CFunctionView::OnChangeVisualStyle()
{
m_ClassViewImages.DeleteImageList();
UINT uiBmpId = theApp.m_bHiColorIcons ? IDB_CLASS_VIEW_24 : IDB_CLASS_VIEW;
CBitmap bmp;
if (!bmp.LoadBitmap(uiBmpId))
{
TRACE(_T("无法加载位图: %x\n"), uiBmpId);
ASSERT(FALSE);
return;
}
BITMAP bmpObj;
bmp.GetBitmap(&bmpObj);
UINT nFlags = ILC_MASK;
nFlags |= (theApp.m_bHiColorIcons) ? ILC_COLOR24 : ILC_COLOR4;
m_ClassViewImages.Create(16, bmpObj.bmHeight, nFlags, 0, 0);
m_ClassViewImages.Add(&bmp, RGB(255, 0, 0));
m_FunctionViewtree.SetImageList(&m_ClassViewImages, TVSIL_NORMAL);
m_wndToolBar.CleanUpLockedImages();
m_wndToolBar.LoadBitmap(theApp.m_bHiColorIcons ? IDB_SORT_24 : IDR_SORT, 0, 0, TRUE /* 锁定*/);
}
//响应checkbox
LRESULT CFunctionView::OnCheckChange(WPARAM wp, LPARAM lp)
{
// if we have multiple trees
HTREEITEM hitem = (HTREEITEM) lp;
int curCheck;
int checked = (m_FunctionViewtree.GetItemState(hitem, TVIS_STATEIMAGEMASK) >> 12)-1 ; //为上一次状态的值
CString s = m_FunctionViewtree.GetItemText(hitem);
if (!m_FunctionViewtree.ItemHasChildren(hitem))
{
return 0;
}
if (checked==0)
{
curCheck = 1;
//setCheckAllChildren(hitem,1);
}//s .Append " unchecked";
else if (checked==1)
{
curCheck = 0;
//setCheckAllChildren(hitem,0);
}// s+= " checked";
else if (checked==2)
{
}// s+= " dunno";
else
{
}
//执行
HTREEITEM firshtcChild = m_FunctionViewtree.GetChildItem(hitem);
setCheckAllChildren(firshtcChild,curCheck);
while((firshtcChild = m_FunctionViewtree.GetNextSiblingItem(firshtcChild))!=NULL)
{
setCheckAllChildren(firshtcChild,curCheck);
}
return 0;
}
//设置checkbox
void CFunctionView::setCheckAllChildren(HTREEITEM hitem,int checked)
{
m_FunctionViewtree.SetCheck(hitem,checked);
HTREEITEM currentChild = m_FunctionViewtree.GetChildItem(hitem);
m_FunctionViewtree.SetCheck(currentChild,checked);
while (currentChild!=NULL)
{
setCheckAllChildren(currentChild,checked);
currentChild = m_FunctionViewtree.GetNextSiblingItem(currentChild);
}
}
void CFunctionView::OnPropertyset()
{
// TODO: Add your command handler code here
MyPropertySheet myps("选项设置",m_scurItem,this,0);
myps.initPropertyPage();
myps.DoModal();
}
void CFunctionView::OnRun()
{
// TODO: Add your command handler code here
TimerManagerPage dlg;
if (theApp.m_PrjPath == "")
{
return;
}
getAppSwitch();
//创建并开始线程
if (theApp.m_prj.bLoadMrDataOver == TRUE)
{
theApp.m_pMainWnd->PostMessage(MYWM_STARTPROSESSDLG,MYPRGROSS_FUNCTIONVIEW);
}else
MessageBox("MR数据未导入");
CString path = theApp.m_PrjPath +"NoCluster"+'\\'+"map"+'\\'+"OverShootCellList.kml";
theApp.m_geApplication.OpenKmlFile(path,TRUE);
}
void CFunctionView::getAppSwitch(void)
{
HTREEITEM hitem = m_FunctionViewtree.GetRootItem();
HTREEITEM firshtcChild = m_FunctionViewtree.GetChildItem(hitem);
getAllChildItem(firshtcChild);
while((firshtcChild = m_FunctionViewtree.GetNextSiblingItem(firshtcChild))!=NULL)
{
getAllChildItem(firshtcChild);
}
}
void CFunctionView::getAllChildItem(HTREEITEM hitem)
{
if (!m_FunctionViewtree.ItemHasChildren(hitem))
{
int appSW = m_FunctionViewtree.GetItemData(hitem);
int staus = m_FunctionViewtree.GetCheck(hitem);
theApp.m_prj.setAppSwitch(appSW,staus);
return;
}
HTREEITEM currentChild = m_FunctionViewtree.GetChildItem(hitem);
CString str =m_FunctionViewtree.GetItemText(currentChild);
while (currentChild!=NULL)
{
getAllChildItem(currentChild);
currentChild = m_FunctionViewtree.GetNextSiblingItem(currentChild);
str = m_FunctionViewtree.GetItemText(currentChild);
}
}
void CFunctionView::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CDockablePane::OnTimer(nIDEvent);
}