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

📄 tpinfoedit.cpp

📁 AliEditor_Source code
💻 CPP
字号:
// TpInfoEdit.cpp : implementation file
//

#include "stdafx.h"
#include "AliEditor.h"
#include "TpInfoEdit.h"

#include "MainFrm.h"
#include "AliEditorView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTpInfoEdit dialog


CTpInfoEdit::CTpInfoEdit(CWnd* pParent /*=NULL*/)
	: CDialog(CTpInfoEdit::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTpInfoEdit)
	m_tp_freq = 0;
	m_tp_symbol_rate = 0;
	//}}AFX_DATA_INIT
	m_op_type = AddNode;
	m_pSatTp = NULL;
	m_nOrder = 0;
}


void CTpInfoEdit::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTpInfoEdit)
	DDX_Control(pDX, IDC_TP_NAME, m_tp_name);
	DDX_Control(pDX, IDC_TP_INFO_POLARIZATION, m_tp_polar);
	DDX_Text(pDX, IDC_TP_INFO_FREQUENCY, m_tp_freq);
	DDX_Text(pDX, IDC_TP_SYMBOL_RATE, m_tp_symbol_rate);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTpInfoEdit, CDialog)
	//{{AFX_MSG_MAP(CTpInfoEdit)
	ON_WM_CLOSE()
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_TP_RESET, OnTpReset)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTpInfoEdit message handlers

BOOL CTpInfoEdit::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	switch(m_op_type)
	{
	case AddNode://add

		AddTpInfo();
		break;

	case EditNode://edit

		EditTpInfo();
		break;

	default:
		break;
	}

	UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

combox_t polar_combox[] =
{
	{0,   "Horizontal"	},
	{1,   "Vertical"	},
};

void CTpInfoEdit::InitCombox()
{
	int i;

	m_tp_polar.ResetContent();
	
	for(i = 0; i < sizeof(polar_combox) / sizeof(combox_t); i++)
	{
		m_tp_polar.AddString(polar_combox[i].bufsz);
		m_tp_polar.SetItemData(i, polar_combox[i].data);
	}
}

void CTpInfoEdit::AddTpInfo()
{
	if(!m_pSatTp) return;

	CAliEditorView *pEditView = ((CMainFrame *)AfxGetMainWnd())->GetEditorView();
	if(!pEditView) return;

	InitCombox();

	CString namestr;

	//namestr.Format("[ %d ]  TP_0_H_0", m_pSatTp->tp_id);
	namestr.Format("[ %d ]  TP_0_H_0", m_nOrder);

	if(m_pSatTp->pNameStr) delete m_pSatTp->pNameStr;
	m_pSatTp->pNameStr = new CString(namestr);
		
	m_tp_name.SetWindowText(namestr);

	m_tp_name.EnableWindow(FALSE);
	
	m_tp_freq = 0;

	m_tp_polar.SetCurSel(0);

	m_tp_symbol_rate = 0;
}

void CTpInfoEdit::EditTpInfo()
{
	int index;
	char bufsz[64];
	if(!m_pSatTp) return;

	CAliEditorView *pEditView = ((CMainFrame *)AfxGetMainWnd())->GetEditorView();
	if(!pEditView) return;

	InitCombox();

	if(m_pSatTp->pNameStr) m_tp_name.SetWindowText(*m_pSatTp->pNameStr);

	m_tp_name.EnableWindow(FALSE);

	index = GetTpNodeIndex(TKEYZ_FREQ);
	if(index != -1)
	{
		BOOL bRet = ((CMainFrame*)AfxGetMainWnd())->m_dbParser.GetNodeData(TP_NODE, m_pSatTp->offset, index, bufsz);

		if(bRet) m_tp_freq = pEditView->GetDataValue(bufsz);
	}

	index = GetTpNodeIndex(TKEYZ_POL);

	if(index != -1)
	{
		BOOL bRet = ((CMainFrame*)AfxGetMainWnd())->m_dbParser.GetNodeData(TP_NODE, m_pSatTp->offset, index, bufsz);
		if(bRet)
		{
			long tp_polar = pEditView->GetDataValue(bufsz);

			int pol_sel = GetCurSel(polar_combox, sizeof(polar_combox) / sizeof(combox_t), tp_polar);

			if(pol_sel != -1) m_tp_polar.SetCurSel(pol_sel);
		}
	}

	index = GetTpNodeIndex(TKEYZ_SYMBOL);
	if(index != -1)
	{
		BOOL bRet = ((CMainFrame*)AfxGetMainWnd())->m_dbParser.GetNodeData(TP_NODE, m_pSatTp->offset, index, bufsz);

		if(bRet) m_tp_symbol_rate= pEditView->GetDataValue(bufsz);
	}
}

void CTpInfoEdit::SaveTpInfo()
{
	char bufsz[64];
	int index, seleted;
	
	if(!m_pSatTp) return;

	CAliEditorView *pEditView = ((CMainFrame *)AfxGetMainWnd())->GetEditorView();
	if(!pEditView) return;

	UpdateData();

	if(m_op_type == AddNode)
	{
		int offset;
		((CMainFrame*)AfxGetMainWnd())->m_dbParser.AllocNode(TP_NODE, &offset);

		m_pSatTp->offset = offset;

		m_pSatTp->tp_id = ((CMainFrame*)AfxGetMainWnd())->m_dbParser.AllocPID(TP_NODE, m_pSatTp);

		index = GetTpNodeIndex(TKEYZ_SAT_ID);
		if(index != -1)
		{
			sprintf(bufsz, "%d", m_pSatTp->sat_id);
			BOOL bRet = ((CMainFrame*)AfxGetMainWnd())->m_dbParser.SetNodeData(TP_NODE, m_pSatTp->offset, index, bufsz);
		}
		
		index = GetTpNodeIndex(TKEYZ_TP_ID);
		if(index != -1)
		{
			sprintf(bufsz, "%d", m_pSatTp->tp_id);
			BOOL bRet = ((CMainFrame*)AfxGetMainWnd())->m_dbParser.SetNodeData(TP_NODE, m_pSatTp->offset, index, bufsz);
		}
	}	

	index = GetTpNodeIndex(TKEYZ_FREQ);
	if(index != -1)
	{
		sprintf(bufsz, "%d", m_tp_freq);
		BOOL bRet = ((CMainFrame*)AfxGetMainWnd())->m_dbParser.SetNodeData(TP_NODE, m_pSatTp->offset, index, bufsz);
	}
	
	long pol_val = 0;

	index = GetTpNodeIndex(TKEYZ_POL);
	if(index != -1)
	{
		seleted = m_tp_polar.GetCurSel();

		pol_val = m_tp_polar.GetItemData(seleted);

		sprintf(bufsz, "%d", pol_val);

		BOOL bRet = ((CMainFrame*)AfxGetMainWnd())->m_dbParser.SetNodeData(TP_NODE, m_pSatTp->offset, index, bufsz);
	}

	index = GetTpNodeIndex(TKEYZ_SYMBOL);
	if(index != -1)
	{
		sprintf(bufsz, "%d", m_tp_symbol_rate);
		BOOL bRet = ((CMainFrame*)AfxGetMainWnd())->m_dbParser.SetNodeData(TP_NODE, m_pSatTp->offset, index, bufsz);
	}

	CString namestr, tmpstr;

	m_tp_name.GetWindowText(namestr);

	if(!pol_val) tmpstr.Format("TP_%d_H_%d", m_tp_freq, m_tp_symbol_rate);
	else tmpstr.Format("TP_%d_V_%d", m_tp_freq, m_tp_symbol_rate);
	
	int pos = namestr.Find("TP");

	namestr = namestr.Left(pos) + tmpstr;

	if(m_pSatTp->pNameStr) delete m_pSatTp->pNameStr;

	m_pSatTp->pNameStr = new CString(namestr);
	g_bModifyed = true;

}

int CTpInfoEdit::GetCurSel(combox_t *pcmt, int count, DWORD data)
{
	int sel = -1;
	for(int i = 0; i < count; i++)
	{
		if(pcmt[i].data == data) 
		{
			sel = i;
			break;
		}
	}

	return sel;
}

int CTpInfoEdit::GetTpNodeIndex(const char *keysz)
{
	if(!keysz) return -1;

	CAliEditorView *pEditView = ((CMainFrame *)AfxGetMainWnd())->GetEditorView();
	if(!pEditView) return -1;

	NodeField **pTpNode = pEditView->m_strlines.GetNodeFieldInfo(TP_NODE);
	if(!pTpNode) return -1;

	return ((CMainFrame*)AfxGetMainWnd())->m_dbParser.GetIndexOfNodeInfo(pTpNode, keysz);
}

BOOL CTpInfoEdit::CheckPara()
{
	CNavigator *pNavigator = ((CMainFrame *)AfxGetMainWnd())->GetNavigator();

	if(!UpdateData()) return FALSE;

	if(!m_pSatTp->nItemFather)
	{
		AfxMessageBox("nItemFather = NULL");
		ASSERT(0);
	}

	CAliEditorView *pEditView = ((CMainFrame *)AfxGetMainWnd())->GetEditorView();
	if(!pEditView) return FALSE;

	CEdit *pEdit = NULL;
	
	if(m_tp_freq < 3000 || m_tp_freq > 13450)
	{
		AfxMessageBox("Frequency: [3000,  13450]");

		pEdit = (CEdit *)GetDlgItem(IDC_TP_INFO_FREQUENCY);
		ASSERT(pEdit);

		pEdit->SetFocus();
		pEdit->SetSel(0, - 1, TRUE);

		return FALSE;
	}

	if(m_tp_symbol_rate < 1000 || m_tp_symbol_rate > 45000)
	{
		AfxMessageBox("Symbol Rate: [1000,  45000]");

		pEdit = (CEdit *)GetDlgItem(IDC_TP_SYMBOL_RATE);
		ASSERT(pEdit);

		pEdit->SetFocus();
		pEdit->SetSel(0, - 1, TRUE);

		return FALSE;
	}

	int index, seleted;
	long pol_val = 0;

	index = GetTpNodeIndex(TKEYZ_POL);
	if(index != -1)
	{
		seleted = m_tp_polar.GetCurSel();

		pol_val = m_tp_polar.GetItemData(seleted);
	}

	CString namestr, tmpstr;

	m_tp_name.GetWindowText(namestr);

	if(!pol_val) tmpstr.Format("TP_%d_H_%d", m_tp_freq, m_tp_symbol_rate);
	else tmpstr.Format("TP_%d_V_%d", m_tp_freq, m_tp_symbol_rate);
	
	int pos = namestr.Find("TP");

	namestr = namestr.Left(pos) + tmpstr;

	SatTPMod *pCurrent = NULL;
	if(m_op_type == EditNode) pCurrent = m_pSatTp;

	//BOOL bRet = pNavigator->FindSameItemText(m_pSatTp->nItemFather, namestr, TRUE, m_pSatTp);
	BOOL bRet = FALSE;

	if(bRet)
	{
		AfxMessageBox("TP Setting existed!");

		return FALSE;
	}


	return TRUE;
}

void CTpInfoEdit::OnOK() 
{
	// TODO: Add extra validation here
	if(!CheckPara()) return;
	
	m_user_mode = OK;
	
	CDialog::OnOK();
}

void CTpInfoEdit::OnCancel() 
{
	// TODO: Add extra cleanup here
	m_user_mode = CANCEL;

	CDialog::OnCancel();
}

void CTpInfoEdit::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	m_user_mode = CLOSE;

	CDialog::OnClose();
}

void CTpInfoEdit::OnDestroy() 
{
	if(m_user_mode == OK) SaveTpInfo();
	
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here	
}

void CTpInfoEdit::OnTpReset() 
{
	// TODO: Add your control notification handler code here
	/*
	m_tp_freq = 0;

	m_tp_polar.SetCurSel(0);

	m_tp_symbol_rate = 0;
*/
	if(m_op_type == EditNode) EditTpInfo();
	else AddTpInfo();
	
	UpdateData(FALSE);
}

⌨️ 快捷键说明

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