📄 simulationview.cpp
字号:
this->Invalidate();
}
void CSimulationView::OnSimulate()
{
CSimulationDoc* pDoc = GetDocument();
//显示对话框让用户输入动态编组数据
CGroupDlg dlg(this);
if(dlg.DoModal()==IDOK)
{
pDoc->m_GroupData[0]=dlg.m_NodeData1;
pDoc->m_GroupData[1]=dlg.m_NodeData2;
pDoc->m_GroupData[2]=dlg.m_NodeData3;
pDoc->m_GroupData[3]=dlg.m_NodeData4;
pDoc->m_GroupData[4]=dlg.m_NodeData5;
pDoc->m_GroupData[5]=dlg.m_NodeData6;
}
else
return;
//根据动态编组数据产生模拟的剪力和重力数据
//设置显示模拟数据曲线标志并刷新视窗
m_bShowSimuData=true;
m_bShowStanData=false;
Invalidate();
}
void CSimulationView::OnShowRealdata()
{
// TODO: Add your command handler code here
}
void CSimulationView::OnShowSimudata()
{
// TODO: Add your command handler code here
}
void CSimulationView::OnShowSensordata()
{
// TODO: Add your command handler code here
}
void CSimulationView::DrawWave(CDC* pDC)
{
CRect rc;
this->GetClientRect(&rc);
long Interval=10;
long Width = rc.Width();
long BeginX=0;
long BeginY=0;
long EndX=Width;
long Height = rc.Height()-10;
long EndY=Height;
CPoint scrpt = this->GetScrollPosition();
CPoint pt1(BeginX,BeginY);
CPoint pt2(BeginX,Height/3);
CPoint pt3(BeginX,2*Height/3);
CPoint pt4(BeginX,EndY);
CPoint pt5(EndX,Height/3);
CPoint pt6(EndX,2*Height/3);
CPoint pt7(EndX,EndY);
CPen hBluePen(PS_SOLID,1,RGB(0,0,255));
CPen hRedPen(PS_SOLID,1,RGB(255,0,0));
CPen hGreenPen(PS_SOLID,1,RGB(0,255,0));
CPen hPurplePen(PS_SOLID,1,RGB(0,255,255));
CPen *pOldPen;
pOldPen=(CPen*)pDC->SelectObject(hRedPen);
pDC->Rectangle(&rc);
pDC->FillSolidRect(&rc,RGB(0,0,0));
//先画坐标轴
pDC->MoveTo(pt1);
pDC->LineTo(pt4);
pDC->MoveTo(pt2);
pDC->LineTo(pt5);
pDC->MoveTo(pt3);
pDC->LineTo(pt6);
pDC->MoveTo(pt4);
pDC->LineTo(pt7);
CSimulationDoc* pDoc = GetDocument();
long MaxY=Height/3;
long Ratio=1;
CPoint p1,p2;
//显示剪力曲线
if(pDoc->m_pSRShow!=NULL)
{
int datalen=pDoc->m_SRDataLen/pDoc->m_Interval+1;
Ratio=pDoc->m_SRMaxValue/MaxY;
if(Ratio<1) Ratio=1;
BeginX=m_Pages*rc.Width();
BeginY=Height/3-pDoc->m_pSRShow[BeginX]/Ratio;
pDC->MoveTo(0,BeginY);
pDC->SelectObject(hBluePen);
for(int x=0;x<rc.Width();x++)
{
if(x+BeginX<datalen)
{
int y=Height/3-pDoc->m_pSRShow[x+BeginX]/Ratio;
pDC->LineTo(x,y);
}
}
}
//显示重力曲线
if(pDoc->m_pWTShow!=NULL)
{
int datalen=pDoc->m_WTDataLen/pDoc->m_Interval+1;
Ratio=pDoc->m_WTMaxValue/MaxY;
if(Ratio<1) Ratio=1;
BeginX=m_Pages*rc.Width();
BeginY=2*Height/3-pDoc->m_pWTShow[BeginX]/Ratio;
pDC->MoveTo(0,BeginY);
pDC->SelectObject(hGreenPen);
for(int x=0;x<rc.Width();x++)
{
if(x+BeginX<datalen)
{
int y=2*Height/3-pDoc->m_pWTShow[x+BeginX]/Ratio;
pDC->LineTo(x,y);
}
}
}
//显示合力曲线
if(pDoc->m_pCOShow!=NULL)
{
int datalen=pDoc->m_CODataLen/pDoc->m_Interval+1;
Ratio=pDoc->m_COMaxValue/MaxY;
if(Ratio<1) Ratio=1;
BeginX=m_Pages*rc.Width();
BeginY=Height-pDoc->m_pCOShow[BeginX]/Ratio;
pDC->MoveTo(0,BeginY);
pDC->SelectObject(hPurplePen);
for(int x=0;x<rc.Width();x++)
{
if(x+BeginX<datalen)
{
int y=Height-pDoc->m_pCOShow[x+BeginX]/Ratio;
pDC->LineTo(x,y);
}
}
}
//恢复系统原始画笔
pDC->SelectObject(pOldPen);
//标识当前显示状态
this->m_bShowStanData=true;
this->m_bShowSimuData=false;
}
void CSimulationView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar==VK_RIGHT)
{
if(m_Pages<m_MaxPages)
{
m_Pages++;
Invalidate();
}
}
else if(nChar==VK_LEFT)
{
if(m_Pages>0)
{
m_Pages--;
Invalidate();
}
}
else{}
CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
}
/*----------------------------------------------------------------------------
function: 将采集到的重力和剪力数据保存到文件中
parameters:
pSRBuffer 指向采集到的剪力数据的指针
SRLen 采集到的剪力数据长度
pWTBuffer 指向采集到的重力数据的指针
WTLen 采集到的重力数据长度
return: 无
author: 唐富华
date: 2004.5.26
-----------------------------------------------------------------------------*/
void CSimulationView::SaveDataToFile(unsigned short* pSRBuffer,int SRLen,unsigned short* pWTBuffer,int WTLen)
{
//将采集到的一帧重力和剪力数据写入到文件中
SRFile.WriteHuge(pSRBuffer,SRLen*sizeof(unsigned short));
WTFile.WriteHuge(pWTBuffer,WTLen*sizeof(unsigned short));
}
/*----------------------------------------------------------------------------
function: 动态显示采集到的数据波形
parameters:
pDC 设备描述表指针
return: 无
author: 唐富华
date: 2004.5.26
-----------------------------------------------------------------------------*/
void CSimulationView::DynamicShowWave(CDC* pDC)
{
CRect rc;
this->GetClientRect(&rc);
long Width = rc.Width();
long BeginX=0;
long BeginY=0;
long EndX=Width;
long Height = rc.Height()-10;
long EndY=Height;
int x,y;
CPoint pt1(BeginX,BeginY);
CPoint pt2(BeginX,Height/3);
CPoint pt3(BeginX,2*Height/3);
CPoint pt4(BeginX,EndY);
CPoint pt5(EndX,Height/3);
CPoint pt6(EndX,2*Height/3);
CPoint pt7(EndX,EndY);
CPen hBluePen(PS_SOLID,1,RGB(0,0,255));
CPen hRedPen(PS_SOLID,1,RGB(255,0,0));
CPen hGreenPen(PS_SOLID,1,RGB(0,255,0));
CPen hPurplePen(PS_SOLID,1,RGB(0,255,255));
CPen *pOldPen;
pOldPen=(CPen*)pDC->SelectObject(hRedPen);
pDC->Rectangle(&rc);
pDC->FillSolidRect(&rc,RGB(0,0,0));
//先画坐标轴
pDC->MoveTo(pt1);
pDC->LineTo(pt4);
pDC->MoveTo(pt2);
pDC->LineTo(pt5);
pDC->MoveTo(pt3);
pDC->LineTo(pt6);
pDC->MoveTo(pt4);
pDC->LineTo(pt7);
CSimulationDoc* pDoc = GetDocument();
long MaxY=Height/3;
long Ratio=1;
CPoint p1,p2;
//显示剪力曲线
int SRMaxValue=pDoc->GetMaxValue(pDoc->m_ShowSRBuffer,BUFFERSHOW_LEN);
Ratio=SRMaxValue/MaxY;
if(Ratio<1) Ratio=1;
BeginY=Height/3-pDoc->m_ShowSRBuffer[0]/Ratio;
pDC->MoveTo(0,BeginY);
pDC->SelectObject(hBluePen);
for(int i=0;i<BUFFERSHOW_LEN;i++)
{
x=i;
y=Height/3-pDoc->m_ShowSRBuffer[i]/Ratio;
pDC->LineTo(x,y);
}
//显示重力曲线
int WTMaxValue=pDoc->GetMaxValue(pDoc->m_ShowWTBuffer,BUFFERSHOW_LEN);
Ratio=WTMaxValue/MaxY;
if(Ratio<1) Ratio=1;
BeginY=2*Height/3-pDoc->m_ShowWTBuffer[0]/Ratio;
pDC->MoveTo(0,BeginY);
pDC->SelectObject(hGreenPen);
for(i=0;i<BUFFERSHOW_LEN;i++)
{
x=i;
y=2*Height/3-pDoc->m_ShowWTBuffer[i]/Ratio;
pDC->LineTo(x,y);
}
//显示合力曲线
int COMaxValue=pDoc->GetMaxValue(pDoc->m_ShowCOBuffer,BUFFERSHOW_LEN);
Ratio=COMaxValue/MaxY;
if(Ratio<1) Ratio=1;
BeginY=Height-pDoc->m_ShowCOBuffer[0]/Ratio;
pDC->MoveTo(0,BeginY);
pDC->SelectObject(hPurplePen);
for(i=0;i<BUFFERSHOW_LEN;i++)
{
x=i;
y=Height-pDoc->m_ShowCOBuffer[i]/Ratio;
pDC->LineTo(x,y);
}
//恢复系统原始画笔
pDC->SelectObject(pOldPen);
}
void CSimulationView::OnAppExit()
{
// TODO: Add your command handler code here
}
void CSimulationView::OnJudge()
{
// TODO: Add your command handler code here
CSimulationDoc* pDoc = GetDocument();
CPen hBluePen(PS_SOLID,1,RGB(0,0,255));
int win=10;
SaveCOData();
if(m_bShowStanData&&pDoc->m_pSRData!=NULL&&pDoc->m_pWTData!=NULL&&pDoc->m_pCOData!=NULL)
{
pDoc->m_LenDownPoints=0;
pDoc->m_LenUpPoints=0;
for(long i=0;i<pDoc->m_CODataLen-win;i++)
{
if((pDoc->m_pCOData[i+win]-pDoc->m_pCOData[i])>100)
{
pDoc->m_UpPoints[pDoc->m_LenUpPoints++]=i+win;
i=i+win;
}
else if((pDoc->m_pCOData[i]-pDoc->m_pCOData[i+win])>100)
{
pDoc->m_DownPoints[pDoc->m_LenDownPoints++]=i+win;
i=i+win;
}
else
{}
}
}
}
void CSimulationView::SaveCOData()
{
CSimulationDoc* pDoc = GetDocument();
CFileDialog dlg(FALSE,_T("*.TXT"),NULL,NULL,L"TEXT FILES (*.TXT)|*.TXT|ALL FILES(*.*)|*.*||");
if(dlg.DoModal()==IDOK)
{
CString pathName = dlg.GetPathName();
CFile myFile;
if(!myFile.Open( pathName, CFile::modeCreate | CFile::modeWrite) )
{
MessageBox(_T("Could not create the file!"));
}
else
{
for(long i=0;i<pDoc->m_CODataLen;i++)
{
CString str;
str.Format(_T("%d\r\n"),pDoc->m_pCOData[i]);
myFile.Write(str,str.GetLength());
}
myFile.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -