YXData.cpp
上传用户:asikq0571
上传日期:2014-07-12
资源大小:528k
文件大小:15k
- // YXData.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Peugeot.h"
- #include "YXData.h"
- #include "MainFrm.h"
- #include "PeugeotDoc.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CYXData dialog
- IMPLEMENT_DYNCREATE(CYXData, CDialog)
- CYXData::CYXData(CWnd* pParent /*=NULL*/)
- : CDialog(CYXData::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CYXData)
- m_YXType = -1;
- m_TimeType = -1;
- m_CheckBL = FALSE;
- m_CheckIV = FALSE;
- m_CheckNT = FALSE;
- m_CheckSB = FALSE;
- //}}AFX_DATA_INIT
- m_pYXGridCtrl = NULL;
- }
- void CYXData::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CYXData)
- DDX_Radio(pDX, IDC_YXTYPE, m_YXType);
- DDX_Radio(pDX, IDC_TIMETYPE, m_TimeType);
- DDX_Check(pDX, IDC_CHECK_BL, m_CheckBL);
- DDX_Check(pDX, IDC_CHECK_IV, m_CheckIV);
- DDX_Check(pDX, IDC_CHECK_NT, m_CheckNT);
- DDX_Check(pDX, IDC_CHECK_SB, m_CheckSB);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CYXData, CDialog)
- //{{AFX_MSG_MAP(CYXData)
- ON_WM_DESTROY()
- ON_BN_CLICKED(IDC_YXTYPE, OnYXType_A)
- ON_BN_CLICKED(IDC_YXTYPE_B, OnYXType_B)
- ON_BN_CLICKED(IDC_TIMETYPE, OnTimetype32)
- ON_BN_CLICKED(IDC_TIMETYPE_56, OnTimetype56)
- ON_BN_CLICKED(IDC_CHECK_BL, OnCheckBL)
- ON_BN_CLICKED(IDC_CHECK_IV, OnCheckIV)
- ON_BN_CLICKED(IDC_CHECK_NT, OnCheckNT)
- ON_BN_CLICKED(IDC_CHECK_SB, OnCheckSB)
- //}}AFX_MSG_MAP
- ON_MESSAGE(WM_GRIDEDITCELL,OnNotifyGrid)
- ON_MESSAGE(WM_GRIDDBLCLICK,OnNotifyDblClkGrid)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CYXData message handlers
- BOOL CYXData::OnInitDialog()
- {
- CDialog::OnInitDialog();
- if (m_pYXGridCtrl == NULL)
- {
- //创建m_pDoc->m_pYXGridCtrl对象
- m_pYXGridCtrl = new CGridCtrl;
- m_pYXGridCtrl->m_bIsYXGrid = true;
- // m_pYXGridCtrl->m_hGridOwner=m_hGridOwner;
- if (!m_pYXGridCtrl)
- {
- AfxMessageBox("创建遥信表格失败");
- return false;
- }
- CRect rect;
- rect.left = 0;
- rect.top = 0;
- rect.bottom = 0;
- rect.right = 273;
- m_pYXGridCtrl->Create(rect, this, 100);
-
- m_pYXGridCtrl->SetEditable(TRUE);
- m_pYXGridCtrl->EnableDragAndDrop(TRUE);
- }
- //m_pYXGridCtrl->ShowWindow(SW_HIDE);
- return TRUE;
- }
- //绘制遥信电子表格
- void CYXData::DrawYXGrid()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
- ReDrawCtr();
- try
- {
- m_pYXGridCtrl->SetRowCount(pDoc->m_YXNum+1);
- m_pYXGridCtrl->SetColumnCount(3);
- m_pYXGridCtrl->SetFixedRowCount(1);
- m_pYXGridCtrl->SetFixedColumnCount(1);
- }
- catch (CMemoryException* e)
- {
- e->ReportError();
- e->Delete();
- AfxMessageBox("遥信表格初始化失败");
- }
-
- GV_ITEM Item;
- Item.mask = GVIF_TEXT|GVIF_FORMAT;
- Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
- Item.row = 0;
- Item.col = 0;
- Item.szText = "点地址 D";
- m_pYXGridCtrl->SetItem(&Item);
- Item.col = 1;
- Item.szText = "点名称";
- m_pYXGridCtrl->SetItem(&Item);
- Item.col = 2;
- Item.szText = "码值 H";
- m_pYXGridCtrl->SetItem(&Item);
-
- for(int i=1;i<pDoc->m_YXNum+1;i++)
- {
- Item.row = i;
- Item.col = 0; //点地址
- if ( (pDoc->m_PrtType == pDoc->IEC101_M) || (pDoc->m_PrtType == pDoc->IEC101_S) )
- Item.szText.Format("%d",(pDoc->m_YXAddr+i-1));
- else //MODBUS遥信点地址方式
- {
- int j,k;
- j = ((i-1) / 16) + pDoc->m_YXAddr; //字节地址
- k = (i-1) % 16; //位地址
- Item.szText.Format("%d_%d",j,k);
- }
- m_pYXGridCtrl->SetItem(&Item);
- Item.col = 1; //点名称
- Item.szText.Format("遥信%d",i);
- m_pYXGridCtrl->SetItem(&Item);
- Item.col = 2; //点码值
- Item.szText = "00";
- m_pYXGridCtrl->SetItem(&Item);
- }
- //Item.nFormat = DT_RIGHT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
- //Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
- }
- void CYXData::UpdateYXGrid()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
- CString s1;
- for (int i=0; i<pDoc->m_YXNum; i++)
- {
-
- s1 = ByteToString(pDoc->m_pYXData[i]);
- m_pYXGridCtrl->SetItemText(i+1,2,s1);
- m_pYXGridCtrl->Invalidate(TRUE);
- }
- }
- void CYXData::OnDestroy()
- {
- if (m_pYXGridCtrl != NULL)
- delete m_pYXGridCtrl;
- CDialog::OnDestroy();
- }
- LRESULT CYXData::OnNotifyGrid(WPARAM wParam,LPARAM lParam)
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
-
- CString strData;
- int strLen;
- char c[2];
- strData = m_pYXGridCtrl->GetItemText(wParam,2);
- strLen = strData.GetLength();
-
- for (int i=0; i<2; i++)
- { if (i < strLen)
- {
- c[i] = strData[strLen-1-i]; //从字符右起取值
- ChartToInt(c[i]); //转换成 0-F 整数
- }
- else
- c[i] = 0x00; //字符不足的按0值补
- }
-
- pDoc->m_pYXData[wParam - 1] = c[1]*16 + c[0];
- if (pDoc->m_PrtType == pDoc->Modbus_S)
- {
- if (pDoc->m_pYXData[wParam - 1] > 0)
- pDoc->m_pYXData[wParam - 1] = 1;
- }
- strData = ByteToString(pDoc->m_pYXData[wParam - 1]);
- m_pYXGridCtrl->SetItemText(wParam,2,strData);
- m_pYXGridCtrl->Invalidate(TRUE);
- if (pDoc->m_PrtType == pDoc->IEC101_S)
- pDoc->m_PrtIEC101.SlaveSend_ChangeYX(wParam-1,1); //发送遥信变位报文
- return 0L;
- }
- LRESULT CYXData::OnNotifyDblClkGrid(WPARAM wParam,LPARAM lParam)
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
- SwitchYX(wParam-1);
- CString s1;
- s1 = ByteToString(pDoc->m_pYXData[wParam-1]);
- m_pYXGridCtrl->SetItemText(wParam,2,s1);
- m_pYXGridCtrl->Invalidate(TRUE);
-
- if (pDoc->m_PrtType == pDoc->IEC101_S)
- pDoc->m_PrtIEC101.SlaveSend_ChangeYX(wParam-1,1); //发送遥信变位报文
- return 0L;
- }
- void CYXData::UpdateYXChara(BOOL bSave)
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
-
- if (bSave)
- {
- UpdateData(TRUE);
- if (m_YXType == 0)
- pDoc->m_PrtIEC101.m_YXChara = pDoc->m_PrtIEC101.m_YXChara & 0xfe; //单点
- else
- pDoc->m_PrtIEC101.m_YXChara = pDoc->m_PrtIEC101.m_YXChara | 0x01; //双点
- if (m_TimeType == 0)
- pDoc->m_PrtIEC101.m_YXChara = pDoc->m_PrtIEC101.m_YXChara & 0xfd; //32TIME
- else
- pDoc->m_PrtIEC101.m_YXChara = pDoc->m_PrtIEC101.m_YXChara | 0x02; //56TIME
- }
- else
- {
- m_YXType = pDoc->m_PrtIEC101.m_YXChara & 0x01;
- m_TimeType = (pDoc->m_PrtIEC101.m_YXChara & 0x02)>>1;
- UpdateData(FALSE);
- }
- }
- void CYXData::OnYXType_A() //选择单点方式
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
- UpdateYXChara(TRUE);
- if (pDoc->m_YXAddr != NULL)
- {
- for (int i=0; i<pDoc->m_YXNum; i++)
- {
- if ((pDoc->m_pYXData[i] & 0x03) == 2) //合位,双点
- pDoc->m_pYXData[i] = pDoc->m_pYXData[i] & 0xfc | 0x01; //合位,单点
- else
- pDoc->m_pYXData[i] = pDoc->m_pYXData[i] & 0xfc; //分位,单点
- }
- UpdateYXGrid();
- }
- }
- void CYXData::OnYXType_B() //选择双点点方式
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
-
- UpdateYXChara(TRUE);
- if (pDoc->m_YXAddr != NULL)
- {
- for (int i=0; i<pDoc->m_YXNum; i++)
- {
- if ((pDoc->m_pYXData[i] & 0x01) == 1) //合位,单点
- pDoc->m_pYXData[i] = pDoc->m_pYXData[i] & 0xfc | 0x02; //合位,双点
- else
- pDoc->m_pYXData[i] = pDoc->m_pYXData[i] & 0xfc | 0x01; //分位,双点
- }
- UpdateYXGrid();
- }
- }
- void CYXData::OnTimetype32()
- {
- UpdateYXChara(TRUE);
- }
- void CYXData::OnTimetype56()
- {
- UpdateYXChara(TRUE);
- }
- void CYXData::OnCheckBL()
- {
- UpdateData(TRUE);
- SetCharaDes(m_CheckBL,0x10); //第5位
- }
- void CYXData::OnCheckSB()
- {
- UpdateData(TRUE);
- SetCharaDes(m_CheckSB,0x20); //第6位
- }
- void CYXData::OnCheckNT()
- {
- UpdateData(TRUE);
- SetCharaDes(m_CheckNT,0x40); //第7位
- }
- void CYXData::OnCheckIV()
- {
- UpdateData(TRUE);
- SetCharaDes(m_CheckIV,0x80); //第8位
- }
- //设置品质描述词
- void CYXData::SetCharaDes(BOOL bCheck, BYTE bChara)
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
- if (pDoc->m_YXAddr != NULL)
- {
- for (int i=0; i<pDoc->m_YXNum; i++)
- {
- if (bCheck) //选中
- pDoc->m_pYXData[i] = pDoc->m_pYXData[i] | bChara; //该位置1
- else
- pDoc->m_pYXData[i] = pDoc->m_pYXData[i] & (~bChara); //该位置0
- }
- UpdateYXGrid(); //更新电子表格
- }
- }
- //切换遥信状态
- void CYXData::SwitchYX(UINT nIndex)
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
- if (pDoc->m_PrtType == pDoc->Modbus_S)
- {
- if (pDoc->m_pYXData[nIndex] == 0)
- pDoc->m_pYXData[nIndex] = 1;
- else
- pDoc->m_pYXData[nIndex] = 0;
- }
- else if (pDoc->m_PrtType == pDoc->IEC101_S)
- {
- if ((pDoc->m_PrtIEC101.m_YXChara & 0x01) == 0x00) //单点类型
- {
- if ((pDoc->m_pYXData[nIndex] & 0x01) == 0x00) //分位
- pDoc->m_pYXData[nIndex] = pDoc->m_pYXData[nIndex] | 0x01;
- else
- pDoc->m_pYXData[nIndex] = pDoc->m_pYXData[nIndex] & 0xfe;
- }
- else //双点类型
- {
- if ((pDoc->m_pYXData[nIndex] & 0x03) == 0x01) //分位 01
- pDoc->m_pYXData[nIndex] = (pDoc->m_pYXData[nIndex] & 0xfc) | 0x02;
- else //合位及不确定状态 10 、00 或 11
- pDoc->m_pYXData[nIndex] = (pDoc->m_pYXData[nIndex] & 0xfc) | 0x01;
- }
- }
- }
- //重画对话框控件,根据窗口大小变化调整位置,根据规约显示/隐藏部分控件
- void CYXData::ReDrawCtr()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
- CRect BarRect,GridRect;
- pMainFrame->m_wndMyBar1.GetClientRect(&BarRect);
- int iGridHeight;
- if (pDoc->m_PrtType != pDoc->IEC101_S)
- {
- iGridHeight = BarRect.bottom-30;
- m_pYXGridCtrl->MoveWindow(0,0,271 ,iGridHeight);
- GetDlgItem(IDC_STATIC1)->ShowWindow(SW_HIDE);
- GetDlgItem(IDC_STATIC2)->ShowWindow(SW_HIDE);
- GetDlgItem(IDC_STATIC3)->ShowWindow(SW_HIDE);
- GetDlgItem(IDC_YXTYPE)->ShowWindow(SW_HIDE);
- GetDlgItem(IDC_YXTYPE_B)->ShowWindow(SW_HIDE);
- GetDlgItem(IDC_TIMETYPE)->ShowWindow(SW_HIDE);
- GetDlgItem(IDC_TIMETYPE_56)->ShowWindow(SW_HIDE);
- GetDlgItem(IDC_CHECK_BL)->ShowWindow(SW_HIDE);
- GetDlgItem(IDC_CHECK_NT)->ShowWindow(SW_HIDE);
- GetDlgItem(IDC_CHECK_SB)->ShowWindow(SW_HIDE);
- GetDlgItem(IDC_CHECK_IV)->ShowWindow(SW_HIDE);
- return;
- }
- iGridHeight = BarRect.bottom-120; //120像素高度用于其他控件空间
- m_pYXGridCtrl->MoveWindow(0,0,271 ,iGridHeight);
- m_pYXGridCtrl->GetClientRect(&GridRect);
- int CtrPos = GridRect.bottom + 16;
- CRect c2;
- GetDlgItem(IDC_STATIC1)->GetWindowRect(&c2);
- ScreenToClient(c2);
- int DatumLine = c2.top;
- GetDlgItem(IDC_STATIC1)->MoveWindow(c2.left,CtrPos,c2.Width(),c2.Height());
- GetDlgItem(IDC_STATIC1)->ShowWindow(SW_SHOW);
-
- GetDlgItem(IDC_YXTYPE)->GetWindowRect(&c2);
- ScreenToClient(c2);
- GetDlgItem(IDC_YXTYPE)->MoveWindow(c2.left,(c2.top-DatumLine+CtrPos),c2.Width(),c2.Height());
- GetDlgItem(IDC_YXTYPE)->ShowWindow(SW_SHOW);
- GetDlgItem(IDC_YXTYPE_B)->GetWindowRect(&c2);
- ScreenToClient(c2);
- GetDlgItem(IDC_YXTYPE_B)->MoveWindow(c2.left,(c2.top-DatumLine+CtrPos),c2.Width(),c2.Height());
- GetDlgItem(IDC_YXTYPE_B)->ShowWindow(SW_SHOW);
-
- GetDlgItem(IDC_TIMETYPE)->GetWindowRect(&c2);
- ScreenToClient(c2);
- GetDlgItem(IDC_TIMETYPE)->MoveWindow(c2.left,(c2.top-DatumLine+CtrPos),c2.Width(),c2.Height());
- GetDlgItem(IDC_TIMETYPE)->ShowWindow(SW_SHOW);
- GetDlgItem(IDC_TIMETYPE_56)->GetWindowRect(&c2);
- ScreenToClient(c2);
- GetDlgItem(IDC_TIMETYPE_56)->MoveWindow(c2.left,(c2.top-DatumLine+CtrPos),c2.Width(),c2.Height());
- GetDlgItem(IDC_TIMETYPE_56)->ShowWindow(SW_SHOW);
-
- GetDlgItem(IDC_CHECK_BL)->GetWindowRect(&c2);
- ScreenToClient(c2);
- GetDlgItem(IDC_CHECK_BL)->MoveWindow(c2.left,(c2.top-DatumLine+CtrPos),c2.Width(),c2.Height());
- GetDlgItem(IDC_CHECK_BL)->ShowWindow(SW_SHOW);
- GetDlgItem(IDC_CHECK_NT)->GetWindowRect(&c2);
- ScreenToClient(c2);
- GetDlgItem(IDC_CHECK_NT)->MoveWindow(c2.left,(c2.top-DatumLine+CtrPos),c2.Width(),c2.Height());
- GetDlgItem(IDC_CHECK_NT)->ShowWindow(SW_SHOW);
- GetDlgItem(IDC_CHECK_SB)->GetWindowRect(&c2);
- ScreenToClient(c2);
- GetDlgItem(IDC_CHECK_SB)->MoveWindow(c2.left,(c2.top-DatumLine+CtrPos),c2.Width(),c2.Height());
- GetDlgItem(IDC_CHECK_SB)->ShowWindow(SW_SHOW);
- GetDlgItem(IDC_CHECK_IV)->GetWindowRect(&c2);
- ScreenToClient(c2);
- GetDlgItem(IDC_CHECK_IV)->MoveWindow(c2.left,(c2.top-DatumLine+CtrPos),c2.Width(),c2.Height());
- GetDlgItem(IDC_CHECK_IV)->ShowWindow(SW_SHOW);
- GetDlgItem(IDC_STATIC2)->GetWindowRect(&c2);
- ScreenToClient(c2);
- GetDlgItem(IDC_STATIC2)->MoveWindow(c2.left,(c2.top-DatumLine+CtrPos),c2.Width(),c2.Height());
- GetDlgItem(IDC_STATIC2)->ShowWindow(SW_SHOW);
- GetDlgItem(IDC_STATIC3)->GetWindowRect(&c2);
- ScreenToClient(c2);
- GetDlgItem(IDC_STATIC3)->MoveWindow(c2.left,(c2.top-DatumLine+CtrPos),c2.Width(),c2.Height());
- GetDlgItem(IDC_STATIC3)->ShowWindow(SW_SHOW);
- }