// WavePanel.cpp : 实现文件
//
#include "stdafx.h"
#include "WavePanel.h"
#include <math.h>
#include "Shell.h"
#include "vector"
#define WAVEFROMTOP 152 //波形区顶部所在位置y值(相对与此界面
#include <iostream>
using namespace std;
#define BLANK_THICK (GREYSTRIPHEIGHT / 2 + 2) //设置消隐厚度
#define TRIANGL_HIGHT ((30 * 1080) / 1920 + 4) //消隐三角形高度
#define GATE_COLOR RGB(0,210,255) //设置闸门颜色
extern CString s_data[5];
int nRightModel;
extern int poleFlag; //单 多 极性标志位
extern int connectsuccess;
extern int openFileFlag; //打开文件标志位
extern int frozenFlag; //冻结标志位
extern int select_channel;
extern int flagAorB;
int nRangeValue;
int nDelayValue;
int rectWaveformValue;
int rectificationValue;
int nVelValue;
int nStartValue;
int nSlopeValue;
int nMaxGainValue;
int nInitGainValue;
// WavePanel
IMPLEMENT_DYNAMIC(WavePanel, CStatic)
WavePanel::WavePanel()
{
m_redPen.CreatePen(PS_SOLID, 1, colRED);
m_redBrush.CreateSolidBrush(colRED);
m_whiteBrush.CreateSolidBrush(colWHITE);
m_bluePen.CreatePen(PS_SOLID, 1, colBLUE);
m_greyDashedPen.CreatePen(PS_DOT, 1, colGREY);
updating = 0;
cal = 0;
adjust = 0;
m_FontAxis1.CreateFont(23 * PROPORTION_Y, 0, 0, 0, FW_THIN, FALSE, FALSE, FALSE, DEFAULT_CHARSET, //创建小字体用于右侧刻度值的显示
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, _T("Arial"));
m_FontAxis2.CreateFont(20 * PROPORTION_Y, 0, 0, 0, FW_THIN, FALSE, FALSE, FALSE, DEFAULT_CHARSET, //创建小字体用于底部刻度值的显示(B扫界面A扫底部刻度)
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, _T("Arial"));
m_FontAxis3.CreateFont(25 * PROPORTION_Y, 0, 0, 0, FW_THIN, FALSE, FALSE, FALSE, DEFAULT_CHARSET, //创建小字体用于底部刻度值的显示(主界面A扫底部刻度)
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, _T("Arial"));
m_FontAxis_big.CreateFont(80 * PROPORTION_Y, 0, 0, 0, FW_THIN, FALSE, FALSE, FALSE, DEFAULT_CHARSET, //创建大字体
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, _T("Arial"));
int end_x = 0;
if (flagAorB == 0)
{
if (cal == 0 && adjust == 0) // 正常 虚线长24
{
segmentLength = 24;
end_x = (((int)(1864 * ((float)GetSystemMetrics(SM_CXSCREEN) / 1920))) / 8 * 8);
rectAScope = CRect(0 * PROPORTION_X, GREYSTRIPHEIGHT * PROPORTION_Y,
end_x, WAVEPARTEHEIGHT * PROPORTION_Y + GREYSTRIPHEIGHT * PROPORTION_Y);
savedotnum = rectAScope.Width() / 4 + 1;
}
else if (cal == 1 && adjust == 0) // 弹出校准 虚线长18
{
segmentLength = 18;
end_x = (GREYSTRIPWIDTH * PROPORTION_X) - (GREYSTRIPWIDTH * PROPORTION_X - (PARAMETER_WIDTH * 2)) % 4;
rectAScope = CRect(PARAMETER_WIDTH * 2, GREYSTRIPHEIGHT * PROPORTION_Y,
end_x, WAVEPARTEHEIGHT * PROPORTION_Y + GREYSTRIPHEIGHT * PROPORTION_Y);
}
else if (cal == 0 && adjust == 1) // 弹出设置参数 虚线长20
{
segmentLength = 20;
end_x = (SCREEN_WIDTH - PARAMETER_WIDTH) - ((SCREEN_WIDTH - PARAMETER_WIDTH) % 4);
rectAScope = CRect(0 * PROPORTION_X, GREYSTRIPHEIGHT * PROPORTION_Y,
end_x, WAVEPARTEHEIGHT * PROPORTION_Y + GREYSTRIPHEIGHT * PROPORTION_Y);
}
else if (cal == 1 && adjust == 1) // 同时弹出时 虚线长15
{
segmentLength = 15;
end_x = SCREEN_WIDTH - PARAMETER_WIDTH - (SCREEN_WIDTH - PARAMETER_WIDTH - PARAMETER_WIDTH * 2) % 4;
rectAScope = CRect(PARAMETER_WIDTH * 2, GREYSTRIPHEIGHT * PROPORTION_Y,
end_x, WAVEPARTEHEIGHT * PROPORTION_Y + GREYSTRIPHEIGHT * PROPORTION_Y);
}
}
else if (flagAorB == 1)
{
segmentLength = 24;
end_x = (((int)(1864 * ((float)GetSystemMetrics(SM_CXSCREEN) / 1920))) / 8 * 8);
rectAScope = CRect(0 * PROPORTION_X, B_WAVEPARTY * PROPORTION_Y,
end_x, (B_WAVEPARTEHEIGHT + B_WAVEPARTY) * PROPORTION_Y);
}
dotnum = rectAScope.Width() / dotnumRatio + 1;
CYSXF_ComportApp::getInstance().SendWave(1, dotnum);
}
WavePanel::~WavePanel()
{
m_redPen.DeleteObject(); // 预创建的红色画笔
m_redBrush.DeleteObject(); // 预创建的红色画刷
m_whiteBrush.DeleteObject(); // 预创建的红色画刷
m_bluePen.DeleteObject();
m_greyDashedPen.DeleteObject();
}
BEGIN_MESSAGE_MAP(WavePanel, CStatic)
ON_WM_PAINT()
ON_WM_CTLCOLOR()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
// CWave 消息处理程序
void WavePanel::SetARect(int c, int a)
{
cal = c;
adjust = a;
int end_x = 0;
if (flagAorB == 0)
{
if (cal == 0 && adjust == 0) // 正常 虚线长24
{
segmentLength = 24;
end_x = (((int)(1864 * ((float)GetSystemMetrics(SM_CXSCREEN) / 1920))) / 8 * 8);
rectAScope = CRect(0 * PROPORTION_X, GREYSTRIPHEIGHT * PROPORTION_Y,
end_x, WAVEPARTEHEIGHT * PROPORTION_Y + GREYSTRIPHEIGHT * PROPORTION_Y);
savedotnum = rectAScope.Width() / 4 + 1;
}
else if (cal == 1 && adjust == 0) // 弹出校准 虚线长18
{
segmentLength = 18;
end_x = (GREYSTRIPWIDTH * PROPORTION_X) - (GREYSTRIPWIDTH * PROPORTION_X - (PARAMETER_WIDTH * 2)) % 4;
rectAScope = CRect(PARAMETER_WIDTH * 2, GREYSTRIPHEIGHT * PROPORTION_Y,
end_x, WAVEPARTEHEIGHT * PROPORTION_Y + GREYSTRIPHEIGHT * PROPORTION_Y);
}
else if (cal == 0 && adjust == 1) // 弹出设置参数 虚线长20
{
segmentLength = 20;
end_x = (SCREEN_WIDTH - PARAMETER_WIDTH) - ((SCREEN_WIDTH - PARAMETER_WIDTH) % 4);
rectAScope = CRect(0 * PROPORTION_X, GREYSTRIPHEIGHT * PROPORTION_Y,
end_x, WAVEPARTEHEIGHT * PROPORTION_Y + GREYSTRIPHEIGHT * PROPORTION_Y);
}
else if (cal == 1 && adjust == 1) // 同时弹出时 虚线长15
{
segmentLength = 15;
end_x = SCREEN_WIDTH - PARAMETER_WIDTH - (SCREEN_WIDTH - PARAMETER_WIDTH - PARAMETER_WIDTH * 2) % 4;
rectAScope = CRect(PARAMETER_WIDTH * 2, GREYSTRIPHEIGHT * PROPORTION_Y,
end_x, WAVEPARTEHEIGHT * PROPORTION_Y + GREYSTRIPHEIGHT * PROPORTION_Y);
}
dotnumRatio = 4;
}
else if (flagAorB == 1)
{
if (printMode == 2)
{
segmentLength = 10;
end_x = ((int)((int)(1864 * ((float)GetSystemMetrics(SM_CXSCREEN) / 1920))) / 8 * 8);
end_x = end_x - end_x / 2 - 56 * PROPORTION_X;
end_x = end_x - end_x % 4;
rectAScope = CRect(0 * PROPORTION_X, B_WAVEPARTY * PROPORTION_Y,
end_x, (B_WAVEPARTEHEIGHT + B_WAVEPARTY) * PROPORTION_Y);
dotnumRatio = 2;
}
else if (printMode == 0 || printMode == 1)
{
segmentLength = 24;
end_x = (((int)(1864 * ((float)GetSystemMetrics(SM_CXSCREEN) / 1920))) / 8 * 8);
rectAScope = CRect(0 * PROPORTION_X, B_WAVEPARTY * PROPORTION_Y,
end_x, (B_WAVEPARTEHEIGHT + B_WAVEPARTY) * PROPORTION_Y);
dotnumRatio = 4;
}
else if(printMode == 3)
{
segmentLength = 12;
rectAScope = CRect(74 * PROPORTION_X, 88 * PROPORTION_Y, (74 + 532) * PROPORTION_X, (88 + 300) * PROPORTION_Y);
dotnumRatio = 4;
}
}
dotnum = rectAScope.Width() / dotnumRatio + 1;
CYSXF_ComportApp::getInstance().SendWave(1, dotnum);
m_bBgDirty = 1;
UpdatescopeA(numberX);
}
//函数名称:DrawWG
//函数作用:画波形界面的网格,框架。
void WavePanel::DrawWG(CDC* pDC) //画网格
{
CRect rcClient;
GetClientRect(&rcClient);
CBrush brush;
brush.CreateSolidBrush(colFORDGREY);
pDC->FillRect(rcClient, &brush);
CPen pen, pen1;
pen.CreatePen(PS_SOLID, 1, colGrey1);
pen1.CreatePen(PS_SOLID, 1, colGreyStrip);
int i, x, y, a, b;
int X1, Y1, X2, Y2;
X1 = rectAScope.left;
X2 = rectAScope.right;
Y1 = rectAScope.top;
Y2 = rectAScope.bottom;
CBrush blackBrush(colBLACK);
CBrush* pBackBrush = pDC->SelectObject(&blackBrush);
pDC->Rectangle(X1, Y1, X2, Y2); //波形区黑色背景
pDC->SelectObject(&pen);
DrawInnerRowLine(pDC);//内部线条 横线
DrawInnerColLine(pDC);//内部的竖线
pDC->SelectObject(&pen1);
// 释放
pen1.DeleteObject();
pen.DeleteObject();
blackBrush.DeleteObject();
pBackBrush->DeleteObject();
}
void WavePanel::Updatescopebackground()
{
CClientDC dcScreen(this);
CRect rcClient;
GetClientRect(&rcClient);
// 创建背景缓冲区
m_dcBg.CreateCompatibleDC(&dcScreen);
m_bmpBg.DeleteObject();
m_bmpBg.CreateCompatibleBitmap(&dcScreen, rcClient.Width(), rcClient.Height());
m_dcBg.SelectObject(&m_bmpBg);
m_dcBg.SetBkMode(TRANSPARENT);
// 绘制静态界面到背景缓冲区
DrawWG(&m_dcBg);//画波形界面的网格框架
m_bBgDirty = 0;
}
//函数名称:UpdategateA
//函数作用:刷新A扫描界面函数
void WavePanel::UpdatescopeA(int numberX)
{
if (updating == 1)
{
return;
}
updating = 1;
CClientDC dc(this);
CRect rcClient;
GetClientRect(&rcClient);
// 动态缓冲区
CDC dcBuffer;
CBitmap bmpBuffer;
dcBuffer.CreateCompatibleDC(&dc);
bmpBuffer.CreateCompatibleBitmap(&dc, rcClient.Width(), rcClient.Height());
CBitmap* pOldBmp = dcBuffer.SelectObject(&bmpBuffer);
if (m_bBgDirty == 1)
{
Updatescopebackground();
}
dcBuffer.BitBlt(0, 0, rcClient.Width(), rcClient.Height(), &m_dcBg, 0, 0, SRCCOPY);
dc.BitBlt(0, 0, rcClient.Width(), rcClient.Height(), &dcBuffer, 0, 0, SRCCOPY);
// 清理资源
dcBuffer.SelectObject(pOldBmp);
dcBuffer.DeleteDC();
bmpBuffer.DeleteObject();
updating = 0;
}
void WavePanel::OnPaint()
{
CPaintDC dc(this); // device context for painting
if(openFileFlag)
UpdatescopeA(0);
}
HBRUSH WavePanel::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CStatic::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: 在此更改 DC 的任何特性
if (CTLCOLOR_STATIC == nCtlColor)//设置STATIC的字体
{
}
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
return hbr;
}
/************************************************************************/
/*
画内部竖线
@param pDC 画笔
*/
/************************************************************************/
void WavePanel::DrawInnerColLine(CDC* pDC)
{
int X1, Y1, X2, Y2;
X1 = rectAScope.left;
X2 = rectAScope.right;
Y1 = rectAScope.top;
Y2 = rectAScope.bottom;
int nInnerRowSpace = (X2 - X1) % 10; // 竖线多余像素
int nInnerRowCount = (X2 - X1 - nInnerRowSpace) / 10; // 去掉竖线剩余像素 (每格间距)
for (int k = 1; k <= 9; k++) //决定竖线的个数
{
int nInnerBigRightSpace;// 大格像素基础
int nInnerBigRightSpaceCount = (Y2 - Y1) % 8;// 大格剩余像素
nInnerBigRightSpace = (Y2 - Y1 - nInnerBigRightSpaceCount) / 8;
int nInnerSmallRightSpaceBCount = (nInnerBigRightSpace) % 2;// 小格多余像素(最后分配给中间线段)
int nInnerSmallRightSpace = (nInnerBigRightSpace - nInnerSmallRightSpaceBCount) / 2;// 空格和线段共占像素
int nInnerRowLineWidth[2] = { 24 * PROPORTION_Y ,10 * PROPORTION_Y }; // 线段长度 0:主界面A扫 1:B扫界面A扫
int nInnerRowSpceWidth = nInnerSmallRightSpace - nInnerRowLineWidth[flagAorB]; // 空格
int nInnerIndex = nInnerRowCount * k;// 每条竖线所在的X轴
int ystart; //每条竖线段起点
int yend; //每条竖线段终点
for (int i = 0; i < 8; i++)
{
ystart = Y1 + nInnerRowSpceWidth + nInnerBigRightSpace * i;
yend = ystart + nInnerRowLineWidth[flagAorB] + nInnerSmallRightSpaceBCount;
pDC->MoveTo(nInnerIndex + 2 * PROPORTION_Y + X1, ystart);
pDC->LineTo(nInnerIndex + 2 * PROPORTION_Y + X1, yend);
ystart = yend + nInnerRowSpceWidth;
yend = ystart + nInnerRowLineWidth[flagAorB];
pDC->MoveTo(nInnerIndex + 2 * PROPORTION_Y + X1, ystart);
pDC->LineTo(nInnerIndex + 2 * PROPORTION_Y + X1, yend);
}
}
}
/************************************************************************/
/*
画内部横线
@param pDC
*/
/************************************************************************/
void WavePanel::DrawInnerRowLine(CDC* pDC)
{
int X1, Y1, X2, Y2;
X1 = rectAScope.left;
X2 = rectAScope.right;
Y1 = rectAScope.top;
Y2 = rectAScope.bottom;
int nInnerLineSpace;
int nInnerLineCount = (Y2 - Y1) % 8; //余出补在最后一格
nInnerLineSpace = (Y2 - Y1 - nInnerLineCount) / 8;//每条横线纵向间距 一格像素
int nInnerBottomSpaceB; // 横向每大格共余出像素
nInnerBottomSpaceB = (X2 - X1) % 5;
int nInnerBottomSpaceBCount = (X2 - X1 - nInnerBottomSpaceB) / 10; // 空格加虚线段占像素
int nInnerBottomSpaceS = segmentLength * PROPORTION_X;// 线段像素基础
int nInnerBottomSpaceCountS = ((nInnerBottomSpaceBCount / 5) - nInnerBottomSpaceS);// 空格像素
int nInnerBottomWidth = nInnerBottomSpaceCountS + nInnerBottomSpaceB;//将横向每大格余出像素分给中间空格
for (int i = 0; i <= 7; i++)
{
int nInnerBottomHeight = Y1 + nInnerLineSpace * i;//每条横线Y轴所在坐标
int xstart;//每条线段X轴起点
int xend;//每条线段Y轴起点
for (int k = 0; k < 10; k++)
{
if (k == 3 || k == 4 || k == 5 || k == 6 || k == 7 || k == 8)
{
xstart = ((X2 - X1) / 10) * k + X1;
xend = ((X2 - X1) / 10) * k + nInnerBottomSpaceS / 2 + 2 * PROPORTION_X + X1;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend + 1 * PROPORTION_X, nInnerBottomHeight);
xstart = xend + nInnerBottomSpaceCountS;
xend = xstart + nInnerBottomSpaceS;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend + 1 * PROPORTION_X, nInnerBottomHeight);
xstart = xend + nInnerBottomSpaceCountS;
xend = xstart + nInnerBottomSpaceS;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend + 1 * PROPORTION_X, nInnerBottomHeight);
xstart = xend + nInnerBottomWidth;
xend = xstart + nInnerBottomSpaceS;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend + 1 * PROPORTION_X, nInnerBottomHeight);
xstart = xend + nInnerBottomSpaceCountS;
xend = xstart + nInnerBottomSpaceS;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend + 1 * PROPORTION_X, nInnerBottomHeight);
xstart = xend + nInnerBottomSpaceCountS;
xend = xstart + nInnerBottomSpaceS / 2;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend + 4 * PROPORTION_X, nInnerBottomHeight);
}
if (k == 9)
{
xstart = ((X2 - X1) / 10) * k + X1;
xend = ((X2 - X1) / 10) * k + nInnerBottomSpaceS / 2 + 2 * PROPORTION_X + X1;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend + 1 * PROPORTION_X, nInnerBottomHeight);
xstart = xend + nInnerBottomSpaceCountS;
xend = xstart + nInnerBottomSpaceS;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend + 1 * PROPORTION_X, nInnerBottomHeight);
xstart = xend + nInnerBottomSpaceCountS;
xend = xstart + nInnerBottomSpaceS;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend + 1 * PROPORTION_X, nInnerBottomHeight);
xstart = xend + nInnerBottomWidth;
xend = xstart + nInnerBottomSpaceS;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend + 1 * PROPORTION_X, nInnerBottomHeight);
xstart = xend + nInnerBottomSpaceCountS;
xend = xstart + nInnerBottomSpaceS;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend + 1 * PROPORTION_X, nInnerBottomHeight);
xstart = xend + nInnerBottomSpaceCountS;
xend = xstart + nInnerBottomSpaceS / 2;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend, nInnerBottomHeight);
}
else
{
xstart = ((X2 - X1) / 10) * k + X1;
xend = ((X2 - X1) / 10) * k + nInnerBottomSpaceS / 2 + 4 * PROPORTION_X + X1;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend, nInnerBottomHeight);
xstart = xend + nInnerBottomSpaceCountS;
xend = xstart + nInnerBottomSpaceS;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend, nInnerBottomHeight);
xstart = xend + nInnerBottomSpaceCountS;
xend = xstart + nInnerBottomSpaceS;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend, nInnerBottomHeight);
xstart = xend + nInnerBottomWidth;
xend = xstart + nInnerBottomSpaceS;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend, nInnerBottomHeight);
xstart = xend + nInnerBottomSpaceCountS;
xend = xstart + nInnerBottomSpaceS;
pDC->MoveTo(xstart, nInnerBottomHeight);
pDC->LineTo(xend, nInnerBottomHeight);
xstart = xend + nInnerBottomSpaceCountS;
xend = xstart + nInnerBottomSpaceS / 2;
pDC->MoveTo(xstart - 2 * PROPORTION_X, nInnerBottomHeight);
pDC->LineTo(xend, nInnerBottomHeight);
}
}
}
}
使竖虚线垂直平分横虚线
最新发布