📄 microwavedlg.cpp
字号:
pWnd->ShowWindow(SW_SHOW);
}
}
}
void CMicroWaveDlg::ShowControlPlane2(int nShow)
{
CWnd *pWnd=NULL;
for( int i=1; i<BOX2_NUMBER; i++ )
{
pWnd = GetDlgItem( m_Box2ID[i] );
if(pWnd!=NULL)
pWnd->ShowWindow( nShow );
}
if(b_Mark2)//此处为后来添加
{
pWnd = GetDlgItem( IDC_GAMMA_THETA );
if(pWnd!=NULL)
{
pWnd->ShowWindow(SW_SHOW);
}
pWnd = GetDlgItem( IDC_R_X );
if(pWnd!=NULL)
{
pWnd->ShowWindow(SW_SHOW);
}
}
}
void CMicroWaveDlg::OnSecond()
{
// TODO: Add your control notification handler code here
if( m_Title2.ClickBut() ) //单击有效区
{
b_Mark2 = !b_Mark2; //修改状态
b_Mark1 = !b_Mark1;
if( b_Mark2 ) //展开/隐藏面板2
{
Invalidate();//关闭演示
for(int i=ID_TIME_1;i<=ID_TIME_14;i++)
{
KillTimer(i);
}
m_RADIO = 12;
UpdateData(false);
ShowControlPlane2( SW_SHOW );
ShowControlPlane1( SW_HIDE );
m_Title1.SetButStatus(BUT_STATUS_RIGHT);
}
else
{
ShowControlPlane2( SW_HIDE );
ShowControlPlane1( SW_SHOW );
m_Title1.SetButStatus(BUT_STATUS_DOWN);
}
if (b_Mark1)
{
SetWindowText("Smith Chart");
}
else
{
SetWindowText("单分支匹配");
}
InvalidateControlPlane(); //刷新面板组
Invalidate();
}
}
void CMicroWaveDlg::OnFirst()
{
// TODO: Add your control notification handler code here
if( m_Title1.ClickBut() ) //单击有效区
{
b_Mark1 = !b_Mark1; //修改状态
b_Mark2 = !b_Mark2;
if( b_Mark1 ){ //展开/隐藏面板1
ShowControlPlane1( SW_SHOW );
ShowControlPlane2( SW_HIDE);
m_Title2.SetButStatus(BUT_STATUS_RIGHT);
}
else
{
Invalidate();//关闭演示
for(int i=ID_TIME_1;i<=ID_TIME_14;i++)
{
KillTimer(i);
}
m_RADIO = 12;
UpdateData(false);
ShowControlPlane1( SW_HIDE );
ShowControlPlane2( SW_SHOW);
m_Title2.SetButStatus(BUT_STATUS_DOWN);
}
if (b_Mark1)
{
SetWindowText("Smith Chart");
}
else
{
SetWindowText("单分支匹配");
}
InvalidateControlPlane(); //刷新面板组
Invalidate();
}
}
void CMicroWaveDlg::InvalidateControlPlane(void)
{
CalculateControlPos1();
CalculateControlPos2();
}
void CMicroWaveDlg::initControlPlane()
{
//m_Box1ID[]数组赋初值
m_Box1ID[0]=IDC_FIRST;
m_Box1ID[1]=IDC_GAMMA_THETA;
m_Box1ID[2]=IDC_R_X;
m_Box1ID[3]=IDC_EDIT_R;
m_Box1ID[4]=IDC_DISP;
m_Box1ID[5]=IDC_RADIO1;
m_Box1ID[6]=IDC_RADIO3;
m_Box1ID[7]=IDC_RADIO5;
m_Box1ID[8]=IDC_RADIO7;
m_Box1ID[9]=IDC_RADIO9;
m_Box1ID[10]=IDC_RADIO11;
m_Box1ID[11]=IDC_RADIO13;
m_Box1ID[12]=IDC_EDIT_X;
m_Box1ID[13]=IDC_BUTTON1;
m_Box1ID[14]=IDC_RADIO2;
m_Box1ID[15]=IDC_RADIO4;
m_Box1ID[16]=IDC_RADIO6;
m_Box1ID[17]=IDC_RADIO8;
m_Box1ID[18]=IDC_RADIO10;
m_Box1ID[19]=IDC_RADIO12;
m_Box1ID[20]=IDC_RADIO14;
//m_Box2ID[]数组赋初值
m_Box2ID[0]=IDC_SECOND;
m_Box2ID[1]=IDC_STATIC_Z0;
m_Box2ID[2]=IDC_STATIC_Z0_R;
m_Box2ID[3]=IDC_STATIC_ZL;
m_Box2ID[4]=IDC_EDIT_ZL_R;
m_Box2ID[5]=IDC_STEP;
m_Box2ID[6]=IDC_AUTO;
m_Box2ID[7]=IDC_EDIT_Z0;
m_Box2ID[8]=IDC_EDIT_ZL_X;
m_Box2ID[9]=IDC_STOP;
m_Box2ID[10]=IDC_STATIC_ZL_J;
m_Box2ID[11]=IDC_RESULT;
b_Mark1 = true; //面板1初态-展开
b_Mark2 = false; //面板2初态-展开
m_Title2.SetButStatus(BUT_STATUS_RIGHT);
ShowControlPlane2(SW_HIDE);
CalculateControlPos1(); //显示面板组
SetControlPos1();
CalculateControlPos2();
SetControlPos2();
}
void CMicroWaveDlg::OnStep() //单击单步计算
{
CString temp;
CGraph *pGraph;
// TODO: Add your control notification handler code here
switch(Step_Num)
{
case 1: //计算归一化导纳
UpdateData(true);
m_Result.Format(_T(""));
UpdateData(false);
m_Ptr_Array.RemoveAll();
if(m_Z0<=0||m_ZL_R<0)
{
MessageBox("Z0 AND ZL.R must be POSITIVE!","ERROR!");
return;
}
if(m_ZL_R==0&&m_ZL_X==0)
{
MessageBox("ZL Can't be ZERO!","ERROR!");
return;
}
if(m_ZL_X==0&&m_ZL_R==m_Z0)
{
MessageBox("阻抗已经匹配!");
return;
}
GetDlgItem(IDC_EDIT_Z0)->EnableWindow(false);
GetDlgItem(IDC_EDIT_ZL_R)->EnableWindow(false);
GetDlgItem(IDC_EDIT_ZL_X)->EnableWindow(false);
YL_R=m_ZL_R*m_Z0/(m_ZL_R*m_ZL_R+m_ZL_X*m_ZL_X);
YL_X=-m_ZL_X*m_Z0/(m_ZL_R*m_ZL_R+m_ZL_X*m_ZL_X);
if(YL_X>=0)
{
temp.Format(_T("第一步:将ZL转化为归一化导纳YL,YL=%.3f + j%.3f ;\r\n"),YL_R,YL_X);
}
else
{
temp.Format(_T("第一步:将ZL转化为归一化导纳YL,YL=%.3f - j%.3f ;\r\n"),YL_R,-YL_X);
}
m_Result+=temp;
UpdateData(false);
Step_Num++;
break;
case 2:
Invalidate();
gam_u_A=(YL_R*YL_R+YL_X*YL_X-1)/((1+YL_R)*(1+YL_R)+YL_X*YL_X);
gam_v_A=2*YL_X/((1+YL_R)*(1+YL_R)+YL_X*YL_X);
gamma_A=sqrt(gam_u_A*gam_u_A+gam_v_A*gam_v_A);
// draw_line(CPoint(1.2*gam_u_A/gamma_A,1.2*gam_v_A/gamma_A),RGB(0,255,0));
// draw_gamma(gamma_A,RGB(0,255,0));
pGraph=new CGraph(3,CPoint(1200*gam_u_A/gamma_A,1200*gam_v_A/gamma_A));
m_Ptr_Array.Add(pGraph);
pGraph=new CGraph(4,gamma_A);
m_Ptr_Array.Add(pGraph);
// draw_gamma(gamma_A,RGB(255,0,0));
pGraph=new CGraph(1,1);
m_Ptr_Array.Add(pGraph);
pGraph=new CGraph(5,CString("A"),CPoint(gam_u_A*1000,gam_v_A*1000));//OA线
m_Ptr_Array.Add(pGraph);
gam_u_D=gamma_A*gamma_A/1;//有几何知识可知
gam_v_D=sqrt(gamma_A*gamma_A-gam_u_D*gam_u_D);
gam_u_C=gam_u_D;
gam_v_C=-gam_v_D;
gamma_D=gamma_C=gamma_A;
pGraph=new CGraph(5,CString("C"),CPoint(gam_u_C*1000,gam_v_C*1000));
m_Ptr_Array.Add(pGraph);
pGraph=new CGraph(5,CString("D"),CPoint(gam_u_D*1000,gam_v_D*1000));
m_Ptr_Array.Add(pGraph);
pGraph=new CGraph(3,CPoint(1200*gam_u_C/gamma_C,1200*gam_v_C/gamma_C));//OC线
m_Ptr_Array.Add(pGraph);
pGraph=new CGraph(3,CPoint(1200*gam_u_D/gamma_D,1200*gam_v_D/gamma_D));//OD线
m_Ptr_Array.Add(pGraph);
d_C=(Calc_Angel(CPoint(gam_u_A*1000,gam_v_A*1000),CPoint(gam_u_C*1000,gam_v_C*1000)))/(4*PI);
d_D=(Calc_Angel(CPoint(gam_u_A*1000,gam_v_A*1000),CPoint(gam_u_D*1000,gam_v_D*1000)))/(4*PI);
temp.Format(_T("第二步:在导纳圆图上找到YL点,即A点。沿等反射系数圆顺时针(向电源)方向等效到G=1的圆上交于D点或C点,\n求出d_C=%.3fλ,d_D=%.3fλ ;\r\n"),d_C,d_D);
m_Result+=temp;
UpdateData(false);
Step_Num++;
break;
case 3:
b_C=2*gam_v_C/((1-gam_u_C)*(1-gam_u_C)+gam_v_C*gam_v_C);
b_D=2*gam_v_D/((1-gam_u_D)*(1-gam_u_D)+gam_v_D*gam_v_D);
pGraph=new CGraph(2,b_C,RGB(255,0,0));
m_Ptr_Array.Add(pGraph);
pGraph=new CGraph(2,b_D,RGB(255,0,0));
m_Ptr_Array.Add(pGraph);
// temp.Format(_T("b_C=%.3f b_D=%.3f"),b_C,b_D);
// MessageBox(temp);
pGraph=new CGraph(3,CPoint(int((b_C*b_C-1)/(b_C*b_C+1)*1200),int(2*b_C/(b_C*b_C+1)*1200)),RGB(255,0,0));
m_Ptr_Array.Add(pGraph);
pGraph=new CGraph(3,CPoint(int((b_D*b_D-1)/(b_D*b_D+1)*1200),int(2*b_D/(b_D*b_D+1)*1200)),RGB(255,0,0));
m_Ptr_Array.Add(pGraph);
pGraph=new CGraph(3,CPoint(1200,0),RGB(255,0,0));
m_Ptr_Array.Add(pGraph);
pGraph=new CGraph(5,CString("F"),CPoint(int((b_C*b_C-1)/(b_C*b_C+1)*1000),int(2*b_C/(b_C*b_C+1)*1000)));//OF线
m_Ptr_Array.Add(pGraph);
pGraph=new CGraph(5,CString("F'"),CPoint(int((b_D*b_D-1)/(b_D*b_D+1)*1000),int(2*b_D/(b_D*b_D+1)*1000)));//OF'线
m_Ptr_Array.Add(pGraph);
pGraph=new CGraph(5,CString("E"),CPoint(1000,0));//OE线
m_Ptr_Array.Add(pGraph);
// d_C=(Calc_Angel(CPoint(gam_u_A*1000,gam_v_A*1000),CPoint(gam_u_C*1000,gam_v_C*1000)))/(4*PI);
l_D=(Calc_Angel(CPoint(1000,0),CPoint(int((b_C*b_C-1)/(b_C*b_C+1)*1000),int(2*b_C/(b_C*b_C+1)*1000))))/(4*PI);
l_C=(Calc_Angel(CPoint(1000,0),CPoint(int((b_D*b_D-1)/(b_D*b_D+1)*1000),int(2*b_D/(b_D*b_D+1)*1000))))/(4*PI);
temp.Format(_T("第三步:在导纳圆图上求出F点(或F'点)沿逆时针(向负载)方向等效到短路点E所转过的电长度,即可求出L_C=%.3fλ,L_D=%.3fλ;\r\n"),l_C,l_D);
m_Result+=temp;
UpdateData(false);
Invalidate();
Step_Num++;
break;
case 4:
// temp.Format(_T(第四步:最终结果\r\n D1=%.3fλ,L1=%.3fλ;\r\n D2=%.3fλ,L2=%.3fλ;)),d_C,l_C,d_D,l_D);
// temp.Format(_T(第四步:最终结果D1=%.3f,L1=%.3f;D2=%.3f,L2=%.3f;),d_C,l_C,d_D,l_D);
temp.Format(_T("第四步:最终结果\r\n D1=%.3fλ,L1=%.3fλ;\r\n D2=%.3fλ,L2=%.3fλ;\r\n单分支匹配完成!"),d_C,l_C,d_D,l_D);
m_Result+=temp;
UpdateData(false);
GetDlgItem(IDC_EDIT_Z0)->EnableWindow(true);
GetDlgItem(IDC_EDIT_ZL_R)->EnableWindow(true);
GetDlgItem(IDC_EDIT_ZL_X)->EnableWindow(true);
// MessageBox("单分支匹配完毕!","完成");
Step_Num=1;
break;
}
}
void CMicroWaveDlg::draw_line(CPoint EndPoint, COLORREF color,CPoint StartPoint)
{
CClientDC dc(this);
CRect rc1;
GetClientRect(&rc1);
rc1.right-=OFFSET;
dc.SetMapMode(MM_ANISOTROPIC);
dc.SetWindowExt(2300,-2300);
if(b_Mark2)
{
rc1.bottom=rc1.bottom*2/3-50;
}
dc.SetViewportExt((rc1.Width()<=rc1.Height())*rc1.Width()+(rc1.Width()>rc1.Height())*rc1.Height(),(rc1.Width()<=rc1.Height())*rc1.Width()+(rc1.Width()>rc1.Height())*rc1.Height());
dc.SetViewportOrg(rc1.right/2,rc1.bottom/2);
CPen pen(PS_SOLID,1,color);
dc.SelectObject(&pen);
dc.MoveTo(CPoint(StartPoint.x,StartPoint.y));
dc.LineTo(CPoint(EndPoint.x,EndPoint.y));
}
void CMicroWaveDlg::draw_gamma(float gamma, COLORREF pen_rgb, int pen_wid)
{
CClientDC dc(this);
CRect rc1;
GetClientRect(&rc1);
rc1.right-=OFFSET;
dc.SetMapMode(MM_ANISOTROPIC);
dc.SetWindowExt(2300,-2300);
if(b_Mark2)
{
rc1.bottom=rc1.bottom*2/3-50;
}
dc.SetViewportExt((rc1.Width()<=rc1.Height())*rc1.Width()+(rc1.Width()>rc1.Height())*rc1.Height(),(rc1.Width()<=rc1.Height())*rc1.Width()+(rc1.Width()>rc1.Height())*rc1.Height());
dc.SetViewportOrg(rc1.right/2,rc1.bottom/2);
CPen pen(PS_SOLID,pen_wid,pen_rgb);
dc.SelectObject(&pen);
dc.Arc(CRect(-gamma*SCALE,-gamma*SCALE,gamma*SCALE,gamma*SCALE),CPoint(-gamma*SCALE,0),CPoint(-gamma*SCALE,0));
}
void CMicroWaveDlg::draw_graph(CGraph *graph)
{
if (graph->Type==1)
{
drawr(graph->value,graph->pen_color);
}
else if (graph->Type==2)
{
drawx(graph->value,graph->pen_color);
}
else if (graph->Type==3)
{
draw_line(graph->EndPoint,graph->pen_color);
}
else if (graph->Type==4)
{
draw_gamma(graph->value,graph->pen_color);
}
else if (graph->Type==5)
{
draw_text(graph->str,graph->pos,RGB(255,0,0));//有点问题
}
}
void CMicroWaveDlg::OnStop()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_EDIT_Z0)->EnableWindow(true);
GetDlgItem(IDC_EDIT_ZL_R)->EnableWindow(true);
GetDlgItem(IDC_EDIT_ZL_X)->EnableWindow(true);
Step_Num=1;
m_Ptr_Array.RemoveAll();
}
void CMicroWaveDlg::draw_text(CString str, CPoint pos, COLORREF pen_color)
{
CClientDC dc(this);
CRect rc1;
GetClientRect(&rc1);
rc1.right-=OFFSET;
dc.SetMapMode(MM_ANISOTROPIC);
dc.SetWindowExt(2300,-2300);
if(b_Mark2)
{
rc1.bottom=rc1.bottom*2/3-50;
}
dc.SetViewportExt((rc1.Width()<=rc1.Height())*rc1.Width()+(rc1.Width()>rc1.Height())*rc1.Height(),(rc1.Width()<=rc1.Height())*rc1.Width()+(rc1.Width()>rc1.Height())*rc1.Height());
dc.SetViewportOrg(rc1.right/2,rc1.bottom/2);
// CPen pen(PS_SOLID,1,color);
// dc.SelectObject(&pen);
dc.SetTextColor(pen_color);
dc.TextOut(pos.x,pos.y,str);
}
void CMicroWaveDlg::OnAuto()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_Z0<=0||m_ZL_R<0)
{
MessageBox("Z0 AND ZL.R must be POSITIVE!","ERROR!");
return;
}
if(m_ZL_R==0&&m_ZL_X==0)
{
MessageBox("ZL Can't be ZERO!","ERROR!");
return;
}
if(m_ZL_X==0&&m_ZL_R==m_Z0)
{
MessageBox("阻抗已经匹配!");
return;
}
GetDlgItem(IDC_EDIT_Z0)->EnableWindow(false);
GetDlgItem(IDC_EDIT_ZL_R)->EnableWindow(false);
GetDlgItem(IDC_EDIT_ZL_X)->EnableWindow(false);
GetDlgItem(IDC_STEP)->EnableWindow(false);
GetDlgItem(IDC_STOP)->EnableWindow(false);
m_Ptr_Array.RemoveAll();
SetTimer(TIMER_AUTO,500,NULL);
time=0;
Step_Num=1;
}
float CMicroWaveDlg::Calc_Angel(CPoint point_STR, CPoint point_END)//通过向量内积和外积来确定顺时针夹角
{
int x1=point_STR.x;
int y1=point_STR.y;
int x2=point_END.x;
int y2=point_END.y;
float abs_STR=sqrt(float(x1*x1+y1*y1));
float abs_END=sqrt(float(x2*x2+y2*y2));
float angel;
angel=acos((x1*x2+y1*y2)/(abs_STR*abs_END));
if(angel<0)
{
angel=PI+angel;
}
if (x1*y2-x2*y1>0)//逆时针
{
angel=2*PI-angel;
}
return angel;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -