📄 trendlistview.cpp
字号:
/////////////////////////////////////////////////////////////////////////////
//
// OPC Trend VC++ Client: TrendListView.CPP
// (Source File)
//
/////////////////////////////////////////////////////////////////////////////
//
// Author: Raphael Imhof
// Initial Date: 11/04/98
// $Workfile: TrendListView.cpp $
// $Revision: 1 $
// $Date: 7/27/99 5:24p $
// Target System: Microsoft Windows NT 4.0
// Environment: Visual C++ 5.0 / OPC DataAccess 1.0 / 2.0
// Remarks:
//
/////////////////////////////////////////////////////////////////////////////
//
// Description: implements the report representation of the trend
//
//
/////////////////////////////////////////////////////////////////////////////
//
// History of Changes (Please remove very old comments and blank lines!)
// $Log: /IDK/OPCServer/clients/VC++/Trend/TrendListView.cpp $
//
// 1 7/27/99 5:24p Imhof
//
// 1 7/27/99 5:20p Imhof
//
// 6 1/15/99 7:04p Imhof
// Updated legal notice.
//
// 5 12/15/98 10:30a Imhof
// Modifications for OPC 2.0
//
// 4 11/06/98 5:53p Imhof
// Added header, comment and made some small code changes.
//
//
// $Nokeywords:$ (To avoid useless search while checking in.)
/////////////////////////////////////////////////////////////////////////////
// Copyright (C) 1998, Siemens Building Technologies, Inc. Landis Division
//
// SIEMENS BUILDING TECHNOLOGIES, INC. IS PROVIDING THE FOLLOWING
// EXAMPLES OF CODE AS SAMPLE ONLY.
//
// SIEMENS BUILDING TECHNOLOGIES, INC. MAKES NO REPRESENTATIONS
// OR WARRANTIES OF ANY KIND WITH RESPECT TO THE VALIDTY OF THE
// CODES OR DESIRED RESULTS AND DISCLAIMS ALL SUCH
// REPRESENTATIONS AND WARRANTIES, INCLUDING FOR EXAMPLE,
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE. SIEMENS BUILIDNG TECHNOLOGIES, INC. DOES NOT
// REPRESENT OR WARRANT THAT THE FOLLOWING CODE SAMPLES ARE
// ACCURATE, VALID, COMPLETE OR CURRENT.
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Trend.h"
#include "TrendDoc.h"
#include "TrendListView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTrendListView
IMPLEMENT_DYNCREATE(CTrendListView, CListView)
CTrendListView::CTrendListView()
{
}
CTrendListView::~CTrendListView()
{
}
BEGIN_MESSAGE_MAP(CTrendListView, CListView)
//{{AFX_MSG_MAP(CTrendListView)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTrendListView drawing
void CTrendListView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// CTrendListView diagnostics
#ifdef _DEBUG
void CTrendListView::AssertValid() const
{
CListView::AssertValid();
}
void CTrendListView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTrendListView message handlers
void CTrendListView::OnInitialUpdate()
{
// TODO: Add your specialized code here and/or call the base class
CListCtrl& list = GetListCtrl();
list.ModifyStyle(NULL, LVS_REPORT,0);
while( list.DeleteColumn( 0 ) );
list.InsertColumn(COLUMN_TIME, _T("Time"), LVCFMT_LEFT, 150, 0 );
list.InsertColumn(COLUMN_VALUE, _T("Value"), LVCFMT_LEFT, 150, 1 );
list.InsertColumn(COLUMN_PRIORITY, _T("Priority"), LVCFMT_LEFT, 150, 1 );
list.InsertColumn(COLUMN_ALARM, _T("Alarm"), LVCFMT_LEFT, 150, 1);
list.InsertColumn(COLUMN_DATALOS, _T("Dataloss"), LVCFMT_LEFT, 150, 1 );
CListView::OnInitialUpdate();
}
void CTrendListView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
USES_CONVERSION;
int iPos = -1;
CListCtrl& list = GetListCtrl();
//empty the list first
list.DeleteAllItems();
CArray<OPCITEMSTATE, OPCITEMSTATE>* pTrenData;
unsigned int nTrendDataValues = 0;
CItem* pItem = ((CTrendDoc*)GetDocument())->GetItem();
nTrendDataValues = pItem->GetTrendData(&pTrenData);
for (unsigned int i = 0; i < nTrendDataValues; i++)
{
CString sPriority;
/* defined in trend.cpp of BCSAcs
#define SAMPLE_NOT_VALID 0x8000
#define SAMPLE_NOT_AVAILABLE 0x4000
#define SAMPLE_IN_ALARM 0x2000
*/
WORD wQuality = (*pTrenData)[i].wQuality;
BOOL bDataLoss;
BOOL bAlarm;
BOOL bNotValid;
if(wQuality & 0x4000)
bDataLoss = TRUE;
else
bDataLoss = FALSE;
if(wQuality & 0x2000)
bAlarm = TRUE;
else
bAlarm = FALSE;
if(wQuality & 0x8000)
{
bNotValid = TRUE;
}
else
bNotValid = FALSE;
/*
CMD_PRIORITY CGroup::MapCmdPrioTable [16] = {
CMDPRI_NONE, CMDPRI_PDL, CMDPRI_EMER, CMDPRI_SMOKE,
CMDPRI_OPER, CMDPRI_TECOVRD, CMDPRI_HOST_2, CMDPRI_HOST_3,
CMDPRI_HOST_4, CMDPRI_HOST_5, CMDPRI_HOST_6, CMDPRI_UNKNOWN,
CMDPRI_NONE, CMDPRI_NONE, CMDPRI_NONE, CMDPRI_NONE};
*/
WORD wPriority = wQuality & 0x0F00; //retrieve the priority bits
wPriority = wPriority >>8;
switch(wPriority)
{
case 0: sPriority = _T("NONE"); break;
case 1: sPriority = _T("PDL"); break;
case 2: sPriority = _T("EMER"); break;
case 3: sPriority = _T("SMOKE"); break;
case 4: sPriority = _T("OPER"); break;
case 5: sPriority = _T("TECOVRD"); break;
case 6: sPriority = _T("HOST_2"); break;
case 7: sPriority = _T("HOST_3"); break;
case 8: sPriority = _T("HOST_4"); break;
case 9: sPriority = _T("HOST_5"); break;
case 10: sPriority = _T("HOST_6"); break;
case 11:
default: sPriority = _T("UNKNOWN"); break;
case 12: sPriority = _T("NONE"); break;
case 13: sPriority = _T("NONE"); break;
case 14: sPriority = _T("NONE"); break;
case 15: sPriority = _T("NONE"); break;
}
if(!bNotValid)
{
CTime time = (*pTrenData)[i].ftTimeStamp;
CString sTime = time.Format("%c");
LV_ITEM lv_item;
lv_item.mask = LVIF_TEXT | LVIF_PARAM;
lv_item.iSubItem = COLUMN_TIME;
lv_item.iItem = 0;
lv_item.pszText = (LPTSTR)(LPCTSTR)sTime;
lv_item.lParam = NULL;
iPos = list.InsertItem(&lv_item);
COleVariant Values = COleVariant((*pTrenData)[i].vDataValue);
Values.ChangeType(VT_BSTR);
CString sValue = OLE2A(Values.bstrVal);
list.SetItem(iPos,COLUMN_VALUE,LVIF_TEXT,(LPTSTR)(LPCTSTR)sValue,0,0,0,0);
list.SetItem(iPos,COLUMN_PRIORITY,LVIF_TEXT,(LPTSTR)(LPCTSTR)sPriority,0,0,0,0);
if(bAlarm)
list.SetItem(iPos,COLUMN_ALARM,LVIF_TEXT,(LPTSTR)(LPCTSTR) _T("Yes"),0,0,0,0);
else
list.SetItem(iPos,COLUMN_ALARM,LVIF_TEXT,(LPTSTR)(LPCTSTR) _T("No"),0,0,0,0);
if(bDataLoss)
list.SetItem(iPos,COLUMN_DATALOS,LVIF_TEXT,(LPTSTR)(LPCTSTR) _T("Yes"),0,0,0,0);
else
list.SetItem(iPos,COLUMN_DATALOS,LVIF_TEXT,(LPTSTR)(LPCTSTR) _T("No"),0,0,0,0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -