📄 mysmithdlg.cpp
字号:
// TODO: Add your control notification handler code here
smith.m_Q=!smith.m_Q;
}
void CMySmithDlg::OnR()
{
// TODO: Add your control notification handler code here
smith.m_R=!smith.m_R;
}
void CMySmithDlg::OnX()
{
// TODO: Add your control notification handler code here
smith.m_X=!smith.m_X;
}
void CMySmithDlg::OnRPoint()
{
// TODO: Add your control notification handler code here
UpdateData(true);
CClientDC pdc(this);
CPen pen(PS_SOLID,1,RGB(192,192,192));
pdc.SelectObject(pen);
CPoint point=smith.GetPoint(m_r_edit,m_x_edit);
CRect rect(point.x-5,point.y-5,point.x+5,point.y+5);
CPoint cp(point.x+5,point.y);
pdc.Arc(rect,cp,cp);
CString str;
str.Format("%f",m_r_edit);
SetDlgItemText(ID_R,str);
str.Format("%f",m_x_edit);
SetDlgItemText(ID_X,str);
str.Format("%f",smith.GetF(point));
SetDlgItemText(ID_F,str);
str.Format("%f",(point.x-smith.m_dx)/smith.m_r);
SetDlgItemText(ID_FR,str);
str.Format("%f",(smith.m_dy-point.y)/smith.m_r);
SetDlgItemText(ID_FI,str);
str.Format("%f",smith.GetQ(point));
SetDlgItemText(ID_Q,str);
}
void CMySmithDlg::OnRCircle()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CClientDC pdc(this);
CPoint cpl(long(smith.m_dx-smith.m_r),(long) smith.m_dy);
CPoint cpr(long(smith.m_dx+smith.m_r),(long)smith.m_dy);
CPen penRC(PS_SOLID,1,RGB(0,0,255));
CPen penXC(PS_SOLID,1,RGB(0,192,255));
pdc.SelectObject(penRC);
pdc.Arc(smith.DrawRCircle(&pdc,m_r_edit),cpr,cpr);
pdc.SelectObject(penXC);
if(m_x_edit>0) pdc.Arc(smith.DrawXCircle(&pdc,m_x_edit),smith.GetXCircleEnd(m_x_edit),cpr);
else if(m_x_edit<0) pdc.Arc(smith.DrawXCircle(&pdc,m_x_edit),cpr,smith.GetXCircleEnd(m_x_edit));
else {pdc.MoveTo(cpl);pdc.LineTo(cpr);}
CPoint point=smith.GetPoint(m_r_edit,m_x_edit);
if(smith.m_R) {
CPen penRC(PS_SOLID,1,RGB(0,0,255));
pdc.SelectObject(penRC);
pdc.Arc(smith.DrawRCircle(&pdc,m_r_edit),cpr,cpr);
}
if(smith.m_X) {
CPen penXC(PS_SOLID,1,RGB(0,192,255));
pdc.SelectObject(penXC);
if(m_x_edit>0) pdc.Arc(smith.DrawXCircle(&pdc,m_x_edit),smith.GetXCircleEnd(m_x_edit),cpr);
else if(m_x_edit<0) pdc.Arc(smith.DrawXCircle(&pdc,m_x_edit),cpr,smith.GetXCircleEnd(m_x_edit));
else {pdc.MoveTo(cpl);pdc.LineTo(cpr);}
}
if(smith.m_F) {
double m_f=smith.GetF(point);
double m_swr=(1+m_f)/(1-m_f);
CPen penF(PS_SOLID,1,RGB(0,255,192));
pdc.SelectObject(penF);
pdc.Arc(smith.DrawFCircle(&pdc,m_f*smith.m_r),point,point);
}
if(smith.m_Q) {
double m_ql=smith.GetQ(point);
CPen penQ(PS_SOLID,1,RGB(0,192,192));
pdc.SelectObject(penQ);
if(point.y<smith.m_dy) pdc.Arc(smith.DrawQCircle(&pdc,m_ql,point),cpr,cpl);
else if (point.y>smith.m_dy) pdc.Arc(smith.DrawQCircle(&pdc,m_ql,point),cpl,cpr);
else {
pdc.MoveTo(cpr);
pdc.LineTo(cpl);
}
}
CString str;
str.Format("%f",m_r_edit);
SetDlgItemText(ID_R,str);
str.Format("%f",m_x_edit);
SetDlgItemText(ID_X,str);
str.Format("%f",smith.GetF(point));
SetDlgItemText(ID_F,str);
str.Format("%f",(point.x-smith.m_dx)/smith.m_r);
SetDlgItemText(ID_FR,str);
str.Format("%f",(smith.m_dy-point.y)/smith.m_r);
SetDlgItemText(ID_FI,str);
str.Format("%f",smith.GetQ(point));
SetDlgItemText(ID_Q,str);
}
void CMySmithDlg::OnFButton4()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CPoint point(long(smith.m_dx+m_fr_edit*smith.m_r),long(smith.m_dy-m_fi_edit*smith.m_r));
CClientDC pdc(this);
CPen pen(PS_SOLID,1,RGB(192,192,192));
pdc.SelectObject(pen);
CRect rect(point.x-2,point.y-2,point.x+2,point.y+2);
CPoint cp(point.x+2,point.y);
pdc.Arc(rect,cp,cp);
CString str;
str.Format("%f",smith.GetR(point));
SetDlgItemText(ID_R,str);
str.Format("%f",smith.GetX(point));
SetDlgItemText(ID_X,str);
str.Format("%f",smith.GetF(point));
SetDlgItemText(ID_F,str);
str.Format("%f",m_fr_edit);
SetDlgItemText(ID_FR,str);
str.Format("%f",m_fi_edit);
SetDlgItemText(ID_FI,str);
str.Format("%f",smith.GetQ(point));
SetDlgItemText(ID_Q,str);
}
void CMySmithDlg::OnFButton5()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CPoint point(long(smith.m_dx+m_fr_edit*smith.m_r),long(smith.m_dy-m_fi_edit*smith.m_r));
CClientDC pdc(this);
CPoint cpl(long(smith.m_dx-smith.m_r),(long)smith.m_dy);
CPoint cpr(long(smith.m_dx+smith.m_r),(long)smith.m_dy);
if(smith.m_R) {
CPen penRC(PS_SOLID,1,RGB(0,0,255));
pdc.SelectObject(penRC);
pdc.Arc(smith.DrawRCircle(&pdc,smith.GetR(point)),cpr,cpr);
}
if(smith.m_X) {
CPen penXC(PS_SOLID,1,RGB(0,192,255));
pdc.SelectObject(penXC);
double m_x=smith.GetX(point);
if(m_x>0) pdc.Arc(smith.DrawXCircle(&pdc,m_x),smith.GetXCircleEnd(m_x),cpr);
else if(m_x<0) pdc.Arc(smith.DrawXCircle(&pdc,m_x),cpr,smith.GetXCircleEnd(m_x));
else {pdc.MoveTo(cpl);pdc.LineTo(cpr);}
}
if(smith.m_F) {
double m_f=smith.GetF(point);
double m_swr=(1+m_f)/(1-m_f);
CPen penF(PS_SOLID,1,RGB(0,255,192));
pdc.SelectObject(penF);
pdc.Arc(smith.DrawFCircle(&pdc,m_f*smith.m_r),point,point);
}
if(smith.m_Q) {
double m_ql=smith.GetQ(point);
CPen penQ(PS_SOLID,1,RGB(0,192,192));
pdc.SelectObject(penQ);
if(point.y<smith.m_dy) pdc.Arc(smith.DrawQCircle(&pdc,m_ql,point),cpr,cpl);
else if (point.y>smith.m_dy) pdc.Arc(smith.DrawQCircle(&pdc,m_ql,point),cpl,cpr);
else {
pdc.MoveTo(cpr);
pdc.LineTo(cpl);
}
}
CString str;
str.Format("%f",smith.GetR(point));
SetDlgItemText(ID_R,str);
str.Format("%f",smith.GetX(point));
SetDlgItemText(ID_X,str);
str.Format("%f",smith.GetF(point));
SetDlgItemText(ID_F,str);
str.Format("%f",m_fr_edit);
SetDlgItemText(ID_FR,str);
str.Format("%f",m_fi_edit);
SetDlgItemText(ID_FI,str);
str.Format("%f",smith.GetQ(point));
SetDlgItemText(ID_Q,str);
}
void CMySmithDlg::OnStart()
{
// TODO: Add your control notification handler code here
UpdateData(true);
CComplex Zl(m_Zl_r,m_Zl_l),Zg(m_Zg_r,m_Zg_l),Zc(m_Zc,0),Zin,Tl,Tg,U,Ui,I,j(0,1),one(1,0);
int i;
double z,abs,iabs,umax=0,umin=1,imax=0,imin=1;
CClientDC clientDC(this);
CRect rect;
CPoint point(416,519),ipoint(416,519);
CBrush brush(HS_DIAGCROSS,RGB(255,255,255));
clientDC.SelectObject(&brush);
rect.top=423;
rect.left=416;
rect.bottom=614;
rect.right=989;
clientDC.Rectangle(rect);
CPen bpen(PS_SOLID,1,RGB(0,0,255));
clientDC.SelectObject(&bpen);
clientDC.MoveTo(416,519);
clientDC.LineTo(989,519);
clientDC.MoveTo(416,423);
clientDC.LineTo(416,614);
CPen rpen(PS_SOLID,1,RGB(255,0,0));
CPen gpen(PS_SOLID,1,RGB(0,255,0));
Tl=(Zl-Zc)/(Zl+Zc);
Tg=(Zg-Zc)/(Zg+Zc);
Zin=Zc*(Zl+j*Zc*tan(m_b*m_l))/(Zc+j*Zl*tan(m_b*m_l));
Ui=Zin/(Zg+Zin);
for(i=416;i<=989;i++){
z=(989-i)*m_l/573;
if(m_sourse=="直流电源") {
U=one/(one-Tl*Tg*(j*sin(-2*m_b*m_l)+cos(2*m_b*m_l)));
I=U;
}
else if(m_sourse=="交流电源") {
U=Ui*(j*sin(-m_b*m_l)+cos(m_b*m_l))*(j*sin(m_b*z)+cos(m_b*z)+Tl*(j*sin(-m_b*z)+cos(m_b*z)))/(one-Tl*Tg*(j*sin(-2*m_b*m_l)+cos(2*m_b*m_l)));
I=Ui*(j*sin(-m_b*m_l)+cos(m_b*m_l))*(j*sin(m_b*z)+cos(m_b*z)-Tl*(j*sin(-m_b*z)+cos(m_b*z)))/(one-Tl*Tg*(j*sin(-2*m_b*m_l)+cos(2*m_b*m_l)));
}
else {}
abs=U.Abs();
I=I/Zc;
iabs=I.Abs();
if(m_u){
clientDC.SelectObject(&rpen);
clientDC.MoveTo(point.x,point.y);
if((519-abs*96)>=423)clientDC.LineTo(i,long(519-abs*96));
point.x=i;
point.y=long(519-abs*96);
}
if(m_length){
clientDC.SelectObject(&gpen);
clientDC.MoveTo(ipoint.x,ipoint.y);
if((519-iabs*96)>=423)clientDC.LineTo(i,long(519-iabs*96*20));
ipoint.x=i;
ipoint.y=long(519-iabs*96*20);
}
umax=umax>abs?umax:abs;
umin=umin<abs?umin:abs;
imax=imax>iabs?imax:iabs;
imin=imin<iabs?imin:iabs;
}
CString str;
str.Format("%f",umax);
SetDlgItemText(IDC_U,str);
str.Format("%f",umin);
SetDlgItemText(IDC_U_min,str);
str.Format("%f",imax);
SetDlgItemText(IDC_I,str);
str.Format("%f",imin);
SetDlgItemText(IDC_I_min,str);
str.Format("%f",(umax+umin)/(umax-umin));
SetDlgItemText(IDC_P,str);
}
void CMySmithDlg::OnQButton7()
{
// TODO: Add your control notification handler code here
UpdateData(true);
CClientDC pdc(this);
CPoint cpl(long(smith.m_dx-smith.m_r),(long)smith.m_dy);
CPoint cpr(long(smith.m_dx+smith.m_r),(long)smith.m_dy);
CPen penQ(PS_SOLID,1,RGB(0,192,192));
pdc.SelectObject(penQ);
CPoint pu(long (smith.m_dx),long (smith.m_dy+1));
CPoint pd(long (smith.m_dx),long (smith.m_dy-1));
if(m_q_edit==0){
pdc.MoveTo(cpr);
pdc.LineTo(cpl);
}
else {
pdc.Arc(smith.DrawQCircle(&pdc,m_q_edit,pu),cpl,cpr);
pdc.Arc(smith.DrawQCircle(&pdc,m_q_edit,pd),cpr,cpl);
}
}
void CMySmithDlg::OnRErease()
{
// TODO: Add your control notification handler code here
CClientDC clientDC(this);
CRect rect;
rect.top=rect.left=25;
rect.bottom=rect.right=395;
CBrush brush(HS_DIAGCROSS,RGB(255,255,255));
clientDC.SelectObject(&brush);
clientDC.Rectangle(rect);
smith.DrawBackGround(&clientDC,rect);
}
void CMySmithDlg::OnQErease()
{
// TODO: Add your control notification handler code here
CClientDC clientDC(this);
CRect rect;
rect.top=rect.left=25;
rect.bottom=rect.right=395;
CBrush brush(HS_DIAGCROSS,RGB(255,255,255));
clientDC.SelectObject(&brush);
clientDC.Rectangle(rect);
smith.DrawBackGround(&clientDC,rect);
}
void CMySmithDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(smith.GetDistance(point)<smith.m_r){
CClientDC ClientDC(this);
CRect rect;
rect.top=rect.left=25;
rect.bottom=rect.right=395;
smith.m_onlbuttondown=true;
smith.DrawRXCircle(&ClientDC,point,rect);
smith.m_onlbuttondown=false;
CString str;
str.Format("%f",smith.m_re);
SetDlgItemText(ID_R,str);
str.Format("%f",smith.m_x);
SetDlgItemText(ID_X,str);
str.Format("%f",smith.m_f);
SetDlgItemText(ID_F,str);
str.Format("%f",smith.m_fr);
SetDlgItemText(ID_FR,str);
str.Format("%f",smith.m_fi);
SetDlgItemText(ID_FI,str);
str.Format("%f",smith.m_ql);
SetDlgItemText(ID_Q,str);
}
CDialog::OnLButtonDown(nFlags, point);
}
void CMySmithDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(smith.GetDistance(point)<smith.m_r){
CClientDC ClientDC(this);
CRect rect;
rect.top=rect.left=25;
rect.bottom=rect.right=395;
smith.m_onrbuttondown=true;
smith.DrawRXCircle(&ClientDC,point,rect);
smith.m_onrbuttondown=false;
}
CDialog::OnRButtonDown(nFlags, point);
}
void CMySmithDlg::OnStartDraw()
{
// TODO: Add your control notification handler code here
UpdateData(true);
CPoint end;
CComplex j(0,1);
CComplex Zc(m_method2_edit,0),Zl(m_start_r_edit,m_start_x_edit),Z(m_method_edit,m_method2_edit),Zin;
CComplex zl(m_start_r_edit/m_method2_edit,m_start_x_edit/m_method2_edit),zin;
CPoint start=smith.GetPoint(zl.re,zl.im);
CClientDC pdc(this);
CPen pen(PS_SOLID,1,RGB(0,0,255));
CPen endpen(PS_SOLID,1,RGB(255,0,0));
pdc.SelectObject(pen);
CRect rect(start.x-5,start.y-5,start.x+5,start.y+5);
CPoint cp(start.x+5,start.y);
pdc.Arc(rect,cp,cp);
if(m_method_combo=="串联传输线"){
Zin=Zc*(Zl+j*Zc*tan(2*3.1415926*m_method_edit))/(Zc+j*Zl*tan(2*3.1415926*m_method_edit));
}
else if(m_method_combo=="并联开路传输线"){
Zin=Zc/(j*tan(2*3.1415926*m_method_edit))*Zl/(Zl+Zc/(j*tan(2*3.1415926*m_method_edit)));
}
else if(m_method_combo=="串联电抗"){
Zin=Zl+Z;
}
else if(m_method_combo=="并联电抗"){
Zin=Zl*Z/(Zl+Z);
}
else {}
zin=Zin/Zc;
end=smith.GetPoint(zin.re,zin.im);
CRect rectend(end.x-5,end.y-5,end.x+5,end.y+5);
CPoint cpend(end.x+5,end.y);
pdc.SelectObject(endpen);
pdc.MoveTo(rectend.left,rectend.top);
pdc.LineTo(rectend.right,rectend.bottom);
pdc.MoveTo(rectend.right,rectend.top);
pdc.LineTo(rectend.left,rectend.bottom);
CString str;
str.Format("%f",Zin.re);
SetDlgItemText(IDC_END_R,str);
str.Format("%f",Zin.im);
SetDlgItemText(IDC_END_X,str);
}
void CMySmithDlg::OnUShow()
{
// TODO: Add your control notification handler code here
m_u=!m_u;
OnStart();
}
void CMySmithDlg::OnIShow()
{
// TODO: Add your control notification handler code here
m_length=!m_length;
OnStart();
}
void CMySmithDlg::OnUser()
{
// TODO: Add your control notification handler code here
CAboutDlg dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -