📄 trendgraphview.cpp
字号:
/////////////////////////////////////////////////////////////////////////////
//
// OPC Trend VC++ Client: TrendGraphView.CPP
// (Source File)
//
/////////////////////////////////////////////////////////////////////////////
//
// Author: Raphael Imhof
// Initial Date: 11/04/98
// $Workfile: TrendGraphView.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 graphical representation of the trend
//
//
/////////////////////////////////////////////////////////////////////////////
//
// History of Changes (Please remove very old comments and blank lines!)
// $Log: /IDK/OPCServer/clients/VC++/Trend/TrendGraphView.cpp $
//
// 1 7/27/99 5:24p Imhof
//
// 1 7/27/99 5:20p Imhof
//
// 8 2/11/99 1:37p Imhof
// Supplied a license key for the dynamic mschart creation.
//
// 7 1/15/99 7:04p Imhof
// Updated legal notice.
//
// 6 1/15/99 2:52p Betrisey
// Stop processing the trend data after the first invalid sample
//
// 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 "TrendGraphView.h"
#include "vctitle.h" //ms chart title
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTrendGraphView
IMPLEMENT_DYNCREATE(CTrendGraphView, CView)
CTrendGraphView::CTrendGraphView()
{
}
CTrendGraphView::~CTrendGraphView()
{
}
BEGIN_MESSAGE_MAP(CTrendGraphView, CView)
//{{AFX_MSG_MAP(CTrendGraphView)
ON_WM_SIZE()
ON_WM_MOUSEWHEEL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTrendGraphView drawing
void CTrendGraphView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// CTrendGraphView diagnostics
#ifdef _DEBUG
void CTrendGraphView::AssertValid() const
{
CView::AssertValid();
}
void CTrendGraphView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTrendGraphView message handlers
void CTrendGraphView::OnInitialUpdate()
{
// TODO: Add your specialized code here and/or call the base class
CRect ViewClientRect;
GetClientRect(&ViewClientRect);
/*
license key for mschart.ocx
7C35CA30-D112-11cf-8E72-00A0C90F26F8
Note: if a Microsoft distributed ocx is dynamically
created it needs a license key (except if the program
runs on a computer with the corresponding dev studio.
If such a ocx is used in a dialog the resource editor
writes the key into the *.rc file for you.
*/
WCHAR pwchLicenseKey[] =
{
0x0037, 0x0043, 0x0033, 0x0035, 0x0043, 0x0041,
0x0033, 0x0030, 0x002D, 0x0044, 0x0031, 0x0031,
0x0032, 0x002D, 0x0031, 0x0031, 0x0063, 0x0066,
0x002D, 0x0038, 0x0045, 0x0037, 0x0032, 0x002D,
0x0030, 0x0030, 0x0041, 0x0030, 0x0043, 0x0039,
0x0030, 0x0046, 0x0032, 0x0036, 0x0046, 0x0038
};
BSTR bstrLicense = ::SysAllocStringLen(pwchLicenseKey,
sizeof(pwchLicenseKey)/sizeof(WCHAR));
if(m_Chart.Create(_T("graph"), WS_VISIBLE, ViewClientRect,
this, ID_GRAPH, NULL, FALSE, bstrLicense))
{
//1.) size missed => we do it here
m_Chart.MoveWindow(ViewClientRect,TRUE);
m_Chart.SetFocus();
}
else
{
TRACE("CMSChart::Create() failed\n");
}
::SysFreeString(bstrLicense);
CView::OnInitialUpdate();
}
void CTrendGraphView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
// fit the chart to CTrendGraphView size
if (m_Chart.m_hWnd != NULL) //is created ?
{
CRect ViewClientRect;
GetClientRect(&ViewClientRect);
m_Chart.MoveWindow(ViewClientRect,TRUE);
m_Chart.SetFocus();
}
}
void CTrendGraphView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
USES_CONVERSION;
m_Chart.SetChartType(3); //VtChChartType2dLine
m_Chart.SetColumnCount(1);
m_Chart.EnableWindow(FALSE); //not allowing to select
CArray<OPCITEMSTATE, OPCITEMSTATE>* pTrenData;
unsigned int nTrendDataValues = 0;
CItem* pItem = ((CTrendDoc*)GetDocument())->GetItem();
nTrendDataValues = pItem->GetTrendData(&pTrenData);
// m_Chart.SetRowCount(nTrendDataValues);
m_Chart.SetRowCount(1);
m_Chart.SetColumn(1);
int nValidValues = 0;
for (unsigned int i = 0; i < nTrendDataValues; i++)
{
// m_Chart.SetRow(i+1);
/* 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;
if(!bNotValid)
{
m_Chart.SetRowCount(i+1);
m_Chart.SetRow(i+1);
CTime time = (*pTrenData)[i].ftTimeStamp;
CString sTime = time.Format("%c");
nValidValues +=1;
m_Chart.SetRow(nValidValues);
COleVariant Values = COleVariant((*pTrenData)[i].vDataValue);
Values.ChangeType(VT_BSTR);
CString sValue = OLE2A(Values.bstrVal);
m_Chart.SetData(sValue);
m_Chart.SetRowLabel(sTime);
}
else
break;
}
// m_Chart.SetRowCount(nValidValues);
CString sFootNote;
sFootNote.Format(_T("Found samples: %d of %d"), nValidValues, pItem->GetRequestedSamples());
m_Chart.SetFootnoteText(sFootNote);
/*
CVcTitle title = m_Chart.GetTitle();
title.SetText("Chart XY");
*/
}
BOOL CTrendGraphView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
// TODO: Add your message handler code here and/or call default
//normal handler causes an ASSERT
//return CView::OnMouseWheel(nFlags, zDelta, pt);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -