📄 navigator.cpp
字号:
// Navigator.cpp : implementation file
//
#include "stdafx.h"
#include "AliEditor.h"
#include "Navigator.h"
#include "MainFrm.h"
//#include "BackDropView.h"
#include "AliEditorView.h"
#include "SatInfoEdit.h"
#include "TpInfoEdit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
bool g_bNodifySelChange = false;
/////////////////////////////////////////////////////////////////////////////
// CNavigator
IMPLEMENT_DYNCREATE(CNavigator, CTreeView)
CNavigator::CNavigator()
{
m_hItemAllService = NULL;
m_hItemAllSatInfo = NULL;
}
CNavigator::~CNavigator()
{
}
BEGIN_MESSAGE_MAP(CNavigator, CTreeView)
//{{AFX_MSG_MAP(CNavigator)
ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
ON_WM_RBUTTONDOWN()
ON_COMMAND(IDM_EDIT_INFO, OnEditInfo)
ON_COMMAND(IDM_ADD_INFO, OnAddInfo)
ON_COMMAND(IDM_DEL_INFO, OnDelInfo)
ON_COMMAND(IDM_MOVE_DOWN, OnMoveDown)
ON_COMMAND(IDM_MOVE_UP, OnMoveUp)
ON_WM_KEYDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNavigator drawing
void CNavigator::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// CNavigator diagnostics
#ifdef _DEBUG
void CNavigator::AssertValid() const
{
CTreeView::AssertValid();
}
void CNavigator::Dump(CDumpContext& dc) const
{
CTreeView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CNavigator message handlers
BOOL CNavigator::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
dwStyle = WS_VISIBLE | WS_TABSTOP | WS_CHILD | WS_BORDER
| TVS_HASBUTTONS | TVS_LINESATROOT | TVS_HASLINES
| TVS_DISABLEDRAGDROP | TVS_SHOWSELALWAYS;
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
int CNavigator::GetChildItemCount(HTREEITEM hTreeItem)
{
CTreeCtrl &theTree = GetTreeCtrl();
if(!theTree.ItemHasChildren(hTreeItem)) return 0;
HTREEITEM hChildItem = theTree.GetChildItem(hTreeItem);
int count = 0;
while (hChildItem != NULL)
{
hChildItem = theTree.GetNextItem(hChildItem, TVGN_NEXT);
count++;
}
return count;
}
int CNavigator::GetItemOrder(HTREEITEM hTreeItem)
{
int nOrder = -1;
if(!hTreeItem) return -1;
CTreeCtrl &m_tree = GetTreeCtrl();
HTREEITEM hParent = m_tree.GetParentItem(hTreeItem);
if(!hParent) return -1;
HTREEITEM hChildItem = m_tree.GetChildItem(hParent);
while (hChildItem != NULL)
{
nOrder++;
if(hTreeItem == hChildItem) return nOrder;
hChildItem = m_tree.GetNextItem(hChildItem, TVGN_NEXT);
}
return -1;
}
void CNavigator::DeleteAllItem()
{
g_bNodifySelChange = true;
CTreeCtrl &tree = GetTreeCtrl();
// tree.SetRedraw(FALSE);
SatTPMod *pSatTpMod = NULL;
if( m_hItemAllSatInfo )
{
HTREEITEM hSatItem = tree.GetChildItem(m_hItemAllSatInfo);
HTREEITEM hTpItem = NULL;
HTREEITEM hTempItem = NULL;
while( hSatItem )
{
hTpItem = tree.GetChildItem(hSatItem);
while( hTpItem )
{
hTempItem = tree.GetNextItem(hTpItem, TVGN_NEXT);
pSatTpMod = (SatTPMod*)tree.GetItemData(hTpItem);
if( pSatTpMod )
{
delete pSatTpMod;
pSatTpMod = NULL;
}
tree.DeleteItem(hTpItem);
hTpItem = hTempItem;
}
hTempItem = tree.GetNextItem(hSatItem, TVGN_NEXT);
pSatTpMod = (SatTPMod*)tree.GetItemData(hSatItem);
if( pSatTpMod )
{
delete pSatTpMod;
pSatTpMod = NULL;
}
tree.DeleteItem(hSatItem);
hSatItem = hTempItem;
}
pSatTpMod = (SatTPMod*)tree.GetItemData(m_hItemAllSatInfo);
delete pSatTpMod;
tree.DeleteItem(m_hItemAllSatInfo);
m_hItemAllSatInfo = NULL;
// pSatTpMod = (SatTPMod*)tree.GetItemData(m_hItemAllService);
// delete pSatTpMod;
// tree.DeleteItem(m_hItemAllService);
}
HTREEITEM hItem = tree.GetRootItem();
HTREEITEM hNext = NULL;
HTREEITEM hChild, hChildNext;
while(hItem)
{
hNext = tree.GetNextItem(hItem, TVGN_NEXT);
pSatTpMod = (SatTPMod*)tree.GetItemData(hItem);
if( pSatTpMod )
{
delete pSatTpMod;
pSatTpMod = NULL;
}
//tree.DeleteItem(hChild);
hChild = tree.GetChildItem(hItem);
while( hChild )
{
hChildNext = tree.GetNextItem(hChild, TVGN_NEXT);
pSatTpMod = (SatTPMod*)tree.GetItemData(hChild);
if( pSatTpMod )
{
delete pSatTpMod;
pSatTpMod = NULL;
}
hChild = hChildNext;
}
hItem = hNext;
}
tree.DeleteAllItems();
m_hItemAllService = NULL;
// tree.SetRedraw(TRUE);
g_bNodifySelChange = false;
}
BOOL CNavigator::InitTreeNode()
{
DeleteAllItem();
CTreeCtrl &tree = GetTreeCtrl();
SatTPMod *pSatTpMod = NULL;
m_hItemAllService = tree.InsertItem("All Services", NULL);
pSatTpMod = new SatTPMod;//new mod
pSatTpMod->type = ALL_SERVICES_TYPE;
tree.SetItemData(m_hItemAllService, (DWORD)pSatTpMod);
m_hItemAllSatInfo = tree.InsertItem("Satellite Information", m_hItemAllService);
pSatTpMod = new SatTPMod;//new mod
pSatTpMod->type = ALL_SAT_INFO_TYPE;
tree.SetItemData(m_hItemAllSatInfo, (DWORD)pSatTpMod);
CMainFrame* pFrm = (CMainFrame*)AfxGetMainWnd();
int i, index;
char bufsz[1024];
db_header_t *pdbheader = &pFrm->m_dbParser.m_satheader;
if(!pdbheader)
return FALSE;
int sat_id;
HTREEITEM nItem;
for(i = 0; i < pdbheader->rec_length; i++)
{
index = pFrm->m_dbParser.GetSatServiceNameIndex();
if(index == -1) continue;
BOOL bRet = pFrm->m_dbParser.GetNodeData(SAT_NODE, i, index, bufsz);
if(!bRet) continue;
pSatTpMod = new SatTPMod;//new mod
memset(pSatTpMod, 0, sizeof(SatTPMod));
pSatTpMod->pNameStr = new CString(bufsz);
ASSERT(pSatTpMod->pNameStr);
index = pFrm->m_dbParser.GetSatIdIndexofSatNode();
if(index == -1) continue;
bRet = pFrm->m_dbParser.GetNodeData(SAT_NODE, i, index, bufsz);
if(!bRet) continue;
sat_id = pFrm->m_dbParser.GetDataValue(bufsz);
pSatTpMod->type = SAT_INFO_TYPE;
pSatTpMod->sat_id = sat_id;
pSatTpMod->nItemFather = m_hItemAllSatInfo;
pSatTpMod->offset = i;
//pSatTpMod->prog_count = GetProgCountBySatID(sat_id);
//pSatTpMod->pProgMapping = GetProgMappingBySatID(sat_id);//
nItem = tree.InsertItem(*pSatTpMod->pNameStr, m_hItemAllSatInfo);
tree.SetItemData(nItem, (DWORD)pSatTpMod);
InitTpNodeInfo(nItem, pSatTpMod);
}
//sub chunk
if( pFrm->m_dbParser.m_pFavoriteGroup )
{
HTREEITEM hItem = tree.InsertItem(pFrm->m_dbParser.m_pFavoriteGroup->strGroupName, NULL);
pSatTpMod = new SatTPMod;
pSatTpMod->type = FAVORITE_ROOT_TYPE;
tree.SetItemData(hItem, (DWORD)pSatTpMod);
HTREEITEM hItemGroup;
SatTPMod* pGroupMod;
for(int i = 0; i < pFrm->m_dbParser.m_pFavoriteGroup->nItemCount; i++)
{
hItemGroup = tree.InsertItem(pFrm->m_dbParser.m_pFavoriteGroup->pItems[i], hItem);
pGroupMod = new SatTPMod;
pGroupMod->offset = i + 1;//From 1
pGroupMod->type = FAVORITE_GROUP_TYPE;
pGroupMod->pFatherMod = pSatTpMod;
tree.SetItemData(hItemGroup, (DWORD)pGroupMod);
}
}
return TRUE;
}
BOOL CNavigator::InitTpNodeInfo(HTREEITEM father, SatTPMod *pFatherMod)
{
int i, index;
char bufsz[1024];
CTreeCtrl &m_TreeCtrl = GetTreeCtrl();
CMainFrame* pFrm = (CMainFrame*)AfxGetMainWnd();
db_header_t *pdbheader = &pFrm->m_dbParser.m_tpheader;
if(!pdbheader)
return FALSE;
/* if(!pSatTpMod->pProgMapping || !pSatTpMod->prog_count)
{
pSatTpMod->prog_count = GetProgCountBySatID(pSatTpMod->sat_id);
if(pSatTpMod->pProgMapping) delete[] pSatTpMod->pProgMapping;
pSatTpMod->pProgMapping = GetProgMappingBySatID(pSatTpMod->sat_id);//
}*/
// int *pNodeMappingOfSat = pFatherMod->pProgMapping;
// int ProgCountOfSat = pFatherMod->prog_count;
int sat_id = pFatherMod->sat_id;
int tp_id, tmp_id;
HTREEITEM nItem;
int pos = 0;
SatTPMod *pSatTpMod = NULL;
for(i = 0; i < pdbheader->rec_length; i++)
{
index = pFrm->m_dbParser.GetSatIdIndexOfTpNode();
if(index == -1) continue;
BOOL bRet = pFrm->m_dbParser.GetNodeData(TP_NODE, i, index, bufsz);
if(!bRet) continue;
tmp_id = pFrm->m_dbParser.GetDataValue(bufsz);
if(tmp_id != sat_id) continue;
pSatTpMod = new SatTPMod;//new mod
memset(pSatTpMod, 0, sizeof(SatTPMod));
index = pFrm->m_dbParser.GetTpIdIndexOfTpNode();
if(index == -1) continue;
pos++;
bRet = pFrm->m_dbParser.GetNodeData(TP_NODE, i, index, bufsz);
if(!bRet) continue;
tp_id = pFrm->m_dbParser.GetDataValue(bufsz);
long m_tp_freq, tp_polar, m_tp_symbol_rate;
index = pFrm->m_dbParser.GetTpNodeIndex(TKEYZ_FREQ);
if(index != -1)
{
BOOL bRet = pFrm->m_dbParser.GetNodeData(TP_NODE, i, index, bufsz);
if(bRet)
m_tp_freq = pFrm->m_dbParser.GetDataValue(bufsz);
}
index = pFrm->m_dbParser.GetTpNodeIndex(TKEYZ_POL);
if(index != -1)
{
BOOL bRet = pFrm->m_dbParser.GetNodeData(TP_NODE, i, index, bufsz);
if(bRet)
tp_polar = pFrm->m_dbParser.GetDataValue(bufsz);
}
index = pFrm->m_dbParser.GetTpNodeIndex(TKEYZ_SYMBOL);
if(index != -1)
{
BOOL bRet = pFrm->m_dbParser.GetNodeData(TP_NODE, i, index, bufsz);
if(bRet)
m_tp_symbol_rate= pFrm->m_dbParser.GetDataValue(bufsz);
}
if(!tp_polar)
sprintf(bufsz, "[ %d ] TP_%d_H_%d", pos, m_tp_freq, m_tp_symbol_rate);
else
sprintf(bufsz, "[ %d ] TP_%d_V_%d", pos, m_tp_freq, m_tp_symbol_rate);
pSatTpMod->pNameStr = new CString(bufsz);
ASSERT(pSatTpMod->pNameStr);
pSatTpMod->type = TP_INFO_TYPE;
pSatTpMod->tp_id = tp_id;
// MarkPID(TP_NODE, tp_id);
pSatTpMod->sat_id = sat_id;
pSatTpMod->nItemFather = father;
pSatTpMod->pFatherMod = pFatherMod;
pSatTpMod->offset = i;
// pSatTpMod->prog_count = GetProgCountByTpID(tp_id, pNodeMappingOfSat, ProgCountOfSat);
// pSatTpMod->pProgMapping = GetProgMappingByTpID(tp_id, pNodeMappingOfSat, ProgCountOfSat);//
nItem = m_TreeCtrl.InsertItem(*pSatTpMod->pNameStr, father);
m_TreeCtrl.SetItemData(nItem, (DWORD)pSatTpMod);
}
return TRUE;
}
int CNavigator::GetProgCount()
{
CMainFrame* pFrm = (CMainFrame*)AfxGetMainWnd();
db_header_t* pdbheader = &pFrm->m_dbParser.m_progheader;//prog
int i, s;
for(i = 0,s = 0; i <pdbheader->rec_length; i++)
{
if(pdbheader->precord[i] == -1) continue;
s++;
}
return s;
}
int *CNavigator::GetProgMapping()
{
CMainFrame* pFrm = (CMainFrame*)AfxGetMainWnd();
db_header_t* pdbheader = &pFrm->m_dbParser.m_progheader;//prog
int *pNodeMapping = NULL;
int count = GetProgCount();
if( count < 1 )
return NULL;
pNodeMapping = new int[count + 1];
int i, s;
for(i = 0,s = 0; i <pdbheader->rec_length, s < count; i++)
{
if(pdbheader->precord[i] == -1) continue;
pNodeMapping[s] = i;
s++;
}
return pNodeMapping;
}
//get prog count by sat id
int CNavigator::GetProgCountBySatID(int sat_id)
{
int idv;
int sat_index;
db_header_t *pdbheader = NULL;
CMainFrame* pFrm = (CMainFrame*)AfxGetMainWnd();
pdbheader = &pFrm->m_dbParser.m_progheader;//prog
if(!pdbheader) return 0;
sat_index = pFrm->m_dbParser.GetSatIdIndexOfProgNode();// sat id of prog
if(sat_index == -1) return 0;
char bufsz[1024];
int i, s;
for(i = 0, s = 0; i < pdbheader->rec_length; i++)
{
if(pdbheader->precord[i] == -1) continue;
BOOL bRet = pFrm->m_dbParser.GetNodeData(PROG_NODE, i, sat_index, bufsz);//prog
if(!bRet) continue;
idv = pFrm->m_dbParser.GetDataValue(bufsz);
if(idv != sat_id) continue;
s++;
}
return s;
}
//get prog mapping by sat id
int *CNavigator::GetProgMappingBySatID(int sat_id)
{
int idv;
int sat_index;
int *pNodeMapping = NULL;
db_header_t *pdbheader = NULL;
CMainFrame* pFrm = (CMainFrame*)AfxGetMainWnd();
pdbheader = &pFrm->m_dbParser.m_progheader;//prog
if(!pdbheader) return NULL;
// int tp_index;
// tp_index = pFrm->m_dbParser.GetTpIdIndexOfProgNode();//tp id of prog
// if(tp_index == -1) return NULL;
sat_index = pFrm->m_dbParser.GetSatIdIndexOfProgNode();//sat id of prog
if(sat_index == -1) return NULL;
int count = GetProgCountBySatID(sat_id);//prog count by sat id
if(count <= 0) return NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -