📄 wfmgraph.h
字号:
bi.biClrImportant = 0;
dwBmBitsSize = ((Bitmap.bmWidth*wBitCount+31)/32)*4*Bitmap.bmHeight;
//为位图内容分配内存
hDib = GlobalAlloc(GHND,dwBmBitsSize+dwPaletteSize+sizeof(BITMAPINFOHEADER));
if(hDib==NULL)
AfxMessageBox("null");
lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDib);
*lpbi = bi;
// 处理调色板
hPal = GetStockObject(DEFAULT_PALETTE);
if (hPal)
{
hDC = ::GetDC(NULL);
hOldPal = SelectPalette(hDC, (HPALETTE)hPal, FALSE);
RealizePalette(hDC);
}
// 获取该调色板下新的像素值
GetDIBits(hDC, hbmp, 0, (UINT) Bitmap.bmHeight,
(LPSTR)lpbi + sizeof(BITMAPINFOHEADER)+dwPaletteSize,
(LPBITMAPINFO)lpbi, DIB_RGB_COLORS);
//恢复调色板
if (hOldPal)
{
SelectPalette(hDC, (HPALETTE)hOldPal, TRUE);
RealizePalette(hDC);
::ReleaseDC(NULL, hDC);
}
//////////////////////////////////////////////////////////////////////////////////
//创建位图文件
fh = CreateFile(szPicNm, GENERIC_WRITE,
0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (fh == INVALID_HANDLE_VALUE)
return ;
// 设置位图文件头
bmfHdr.bfType = 0x4D42; // "BM"
dwDIBSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) +
dwPaletteSize + dwBmBitsSize;
bmfHdr.bfSize = dwDIBSize;
bmfHdr.bfReserved1 = 0;
bmfHdr.bfReserved2 = 0;
bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER)
+ (DWORD)sizeof(BITMAPINFOHEADER)
+ dwPaletteSize;
// 写入位图文件头
WriteFile(fh, (LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER), &dwWritten, NULL);
// 写入位图文件其余内容
WriteFile(fh, (LPSTR)lpbi, dwDIBSize,
&dwWritten, NULL);
//消除内存分配
GlobalUnlock(hDib);
GlobalFree(hDib);
CloseHandle(fh);
}
template <class BASETYPE>
void CWfmGraph <BASETYPE>::SetAutoScale()
{
for (int i=1; i<=this->GetPlots().GetCount(); i++)
this->GetPlots().Item(i).SetAutoScale(true);
}
//设定Y轴范围
template <class BASETYPE>
void CWfmGraph <BASETYPE>::SetYRange(int nAxisInd, double dMin, double dMax)
{
//
CNiAxis sYAxis= this->GetPlots().Item(nAxisInd).GetYAxis();
sYAxis.SetMinMax(dMin, dMax);
}
template <class BASETYPE>
void CWfmGraph <BASETYPE>::SetWfmVis(int nDevice, int nChnl, BOOL bVis)
{
char szFmt[36];
::sprintf(szFmt, "Dev%d-Ch%d", nDevice, nChnl);
if (this->GetPlots().GetCount()>0)
this->GetPlots().Item(szFmt).SetVisible(bVis?true:false);
}
template <class BASETYPE>
void CWfmGraph <BASETYPE>::SetWfmAdjMode(WfmAdjMode adjMode)
{
this->SetTrackMode((CNiGraph::GraphTrackModes)adjMode);
}
template <class BASETYPE>
void CWfmGraph <BASETYPE>::ApplyCursors(BOOL bEnable)
{
// this->ClearGraph();
m_critSect.Lock();
CNiCursors sCursors= this->GetCursors();
sCursors.RemoveAll();
if (bEnable)
{
sCursors.Add().SetColor(CNiColor(RGB(242, 232, 242)));
sCursors.Add().SetColor(CNiColor(RGB(89, 254, 16)));
sCursors.Item(1).PointStyle = CNiCursor::PointEmptyCircle;
sCursors.Item(2).PointStyle = CNiCursor::PointEmptyCircle;
sCursors.Item(1).SnapMode = CNiCursor::SnapNearestPoint;
sCursors.Item(2).SnapMode = CNiCursor::SnapNearestPoint;
}
m_critSect.Unlock();
}
/*绘制波形曲线*/
template <class BASETYPE>
void CWfmGraph <BASETYPE>::PaintWfm(int arrWfmSize[]/*每通道波形数*/, double *arrWfmData[]/*波形数据*/,
short nChnls/*通道数*/)
{
ASSERT(nChnls <= m_nMaxChnls);
m_critSect.Lock();
ClearGraph();
for (short i=0; i < nChnls; i++)
{
m_ppWfmVectors[i].Resize(arrWfmSize[i]);
for (int j=0; j<arrWfmSize[i]; j++)
{
m_ppWfmVectors[i][j] = arrWfmData[i][j];
}
//
this->GetPlots().Item(i+1).PlotY(m_ppWfmVectors[i]);
}
m_critSect.Unlock();
}
/*Plot曲线*/
template <class BASETYPE>
void CWfmGraph <BASETYPE>::PlotY(double *dbValue[], ULONG arrWfmSize[], int nCount/*数目*/)
{
ASSERT(nCount <= m_nMaxChnls);
m_critSect.Lock();
for (short i=0; i < nCount; i++)
{
m_ppWfmVectors[i].Resize(arrWfmSize[i]);
for (ULONG j=0; j<arrWfmSize[i]; j++)
{
m_ppWfmVectors[i][j] = dbValue[i][j];
}
this->GetPlots().Item(i+1).PlotY(m_ppWfmVectors[i]);
}
m_critSect.Unlock();
}
/*Chart曲线*/
template <class BASETYPE>
void CWfmGraph <BASETYPE>::ChartY(int nChnls, double dbValue[])
{
m_critSect.Lock();
for (int j=0; j<nChnls; j++)
{
this->GetPlots().Item(j+1).ChartY(dbValue[j], 0.1);
// this->GetPlots().Item(2).ChartY(dbValue[1], 0.1);
// this->GetPlots().Item(3).ChartY(dbValue[2], 0.1);
// this->GetPlots().Item(4).ChartY(dbValue[3], 0.1);
}
m_critSect.Unlock();
}
template <class BASETYPE>
void CWfmGraph <BASETYPE>::ChartY(double *dbValue[], int arrWfmSize[], int Device[], int Chnl[], int nCount/*数目*/)
{
char szFmt[36];
ASSERT(nCount <= m_nMaxChnls);
m_critSect.Lock();
for (short i=0; i < nCount; i++)
{
::sprintf(szFmt, "Dev%d-Ch%d", Device[i], Chnl[i]);
for (int j=0; j<arrWfmSize[i]; j++)
{
this->GetPlots().Item(szFmt).ChartY(dbValue[i][j]);
}
}
m_critSect.Unlock();
}
template <class BASETYPE>
void CWfmGraph <BASETYPE>::ChartY(double dbValue)
{
ASSERT_VALID(this);
this->GetPlots().Item(1).ChartY(dbValue, 0.1);
//TRACE1("%.4f. \n", dbValue);
}
/*改变某通道的颜色*/
template <class BASETYPE>
void CWfmGraph <BASETYPE>::ChangeChnlClr(int nDevice, int nChnl, COLORREF clr)
{
char szFmt[36];
ASSERT(nChnl>=1 && nChnl <=m_nMaxChnls);
::sprintf(szFmt, "Dev%d-Ch%d", nDevice, nChnl);
this->GetPlots().Item(szFmt).SetLineColor(CNiColor(clr));
}
template <class BASETYPE>
void CWfmGraph <BASETYPE>::PlotXY(int nDevice, int nChnl, double dbXValue, double dbYValue)
{
char szFmt[36];
::sprintf(szFmt, "Dev%d-Ch%d", nDevice, nChnl);
m_critSect.Lock();
this->GetPlots().Item(szFmt).PlotXY(dbXValue, dbYValue);
m_critSect.Unlock();
}
template <class BASETYPE>
void CWfmGraph <BASETYPE>::ChartXY(int nDevice, int nChnl, double dbXValue, double dbYValue)
{
char szFmt[36];
::sprintf(szFmt, "Dev%d-Ch%d", nDevice, nChnl);
m_critSect.Lock();
this->GetPlots().Item(szFmt).ChartXY(dbXValue, dbYValue);
m_critSect.Unlock();
}
template <class BASETYPE>
void CWfmGraph <BASETYPE>::SetRange(double Minimum, double Maximum)
{
m_Minimum = Minimum;
m_Maximum = Maximum;
this->GetAxes().Item("XAxis").SetMinMax(Minimum, Maximum);
}
template <class BASETYPE>
void CWfmGraph <BASETYPE>::ClearGraph()
{
this->ClearData();
this->GetAxes().Item("XAxis").SetMinMax(m_Minimum, m_Maximum);
}
template <class BASETYPE>
void CWfmGraph <BASETYPE>::InitRes()
{
m_arrColors[0] = CNiColor(RGB (110, 192, 214));
m_arrColors[1] = CNiColor(RGB (110, 162, 154));
m_arrColors[2] = CNiColor(RGB (170, 132, 134));
m_arrColors[3] = CNiColor(RGB (190, 212, 194));
m_arrColors[4] = CNiColor(RGB (140, 112, 134));
m_arrColors[5] = CNiColor(RGB (150, 202, 154));
m_arrColors[6] = CNiColor(RGB (120, 142, 184));
m_arrColors[7] = CNiColor(RGB (160, 172, 194));
}
/*初始化波形曲线和颜色*/
template <class BASETYPE>
void CWfmGraph <BASETYPE>::InitPlots(CStringArray *pArrChnlNms, CDWordArray *pArrClrChnls)
{
ASSERT(pArrChnlNms);
ASSERT(pArrClrChnls);
m_critSect.Lock();
this->GetPlots().RemoveAll();
for (short i=0; i< m_nMaxChnls; i++)
{
this->GetPlots().Add();
this->GetPlots().Item(i+1).SetName(pArrChnlNms->GetAt(i));
this->GetPlots().Item(i+1).SetLineColor(pArrClrChnls->GetAt(i));
}
m_critSect.Unlock();
}
template <class BASETYPE>
void CWfmGraph <BASETYPE>::DestroyRes()
{}
#endif // !defined(AFX_WFMGRAPH_H__AE6E88E5_9113_42AF_9F99_6B47C53DD109__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -