📄 smithofpandlg.cpp
字号:
// SmithOfPanDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SmithOfPan.h"
#include "SmithOfPanDlg.h"
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSmithOfPanDlg dialog
CSmithOfPanDlg::CSmithOfPanDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSmithOfPanDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSmithOfPanDlg)
m_hDiankang = 0.0;
m_hDianzu = 0.0;
m_hFansheShibu = _T("");
m_hFansheXubu = _T("");
m_hGuiyiShibu = _T("");
m_hGuiyiXubu = _T("");
m_hSwr = _T("");
m_hTexing = 0.0;
m_hWavelenght = 0.0;
m_hSlider = 0;
m_hShow = _T("");
m_hL = 0.0f;
m_hD = 0.0f;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSmithOfPanDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSmithOfPanDlg)
DDX_Control(pDX, IDC_SLIDER1, m_hSliderControl);
DDX_Text(pDX, IDC_EDIT_DIANKANG, m_hDiankang);
DDX_Text(pDX, IDC_EDIT_DIANZU, m_hDianzu);
DDX_Text(pDX, IDC_EDIT_FANSHE_SHIBU, m_hFansheShibu);
DDX_Text(pDX, IDC_EDIT_FANSHE_XUBU, m_hFansheXubu);
DDX_Text(pDX, IDC_EDIT_GUIYI_SHIBU, m_hGuiyiShibu);
DDX_Text(pDX, IDC_EDIT_GUIYI_XUBU, m_hGuiyiXubu);
DDX_Text(pDX, IDC_EDIT_SWR, m_hSwr);
DDX_Text(pDX, IDC_EDIT_TEXING, m_hTexing);
DDX_Text(pDX, IDC_EDIT_WAVELENGTH, m_hWavelenght);
DDX_Slider(pDX, IDC_SLIDER1, m_hSlider);
DDX_Text(pDX, IDC_EDITShow, m_hShow);
DDX_Text(pDX, IDC_EDIT_L, m_hL);
DDX_Text(pDX, IDC_EDIT_D, m_hD);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSmithOfPanDlg, CDialog)
//{{AFX_MSG_MAP(CSmithOfPanDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_CACUL, OnBtnCacul)
ON_BN_CLICKED(IDC_BTN_FIND, OnBtnFind)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER1, OnReleasedcaptureSlider1)
ON_BN_CLICKED(IDC_Pipei, OnPipei)
ON_BN_CLICKED(IDC_BUTTONchuan_kai, OnBUTTONchuankai)
ON_BN_CLICKED(IDC_BUTTON1, OnAbout)
ON_BN_CLICKED(IDC_BUTTON2, OnButtonbingduan)
ON_BN_CLICKED(IDC_BUTTON3, OnButtonbingkai)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSmithOfPanDlg message handlers
BOOL CSmithOfPanDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//初始化SMITH圆图范围
chart.SetRange(CPoint(0,0),CPoint(400,400),CPoint(200,200));
m_hTexing = 56;
m_hDianzu = 12;
m_hDiankang = 34;
m_hSwr = "";
m_hSliderControl.SetRange(0,100,TRUE);
m_hSliderControl.SetPos(25); //默认光标所在
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSmithOfPanDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSmithOfPanDlg::OnPaint()
{
CDC * pDC = GetDC();
chart.InitSmithChart(pDC);
ReleaseDC(pDC);
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSmithOfPanDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSmithOfPanDlg::OnBtnCacul()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
//数据合法检验
if(m_hTexing <= 0)
{
MessageBox("特性阻抗不能小于等于零!","警告!!!",MB_OK|MB_ICONHAND);
return;
}
if(m_hDianzu<0)
{
MessageBox("电阻不能小于零!","警告!!!",MB_OK|MB_ICONHAND);
return;
}
//获取阻抗
IMPEDANCE impedance;
impedance.Rx = m_hDianzu; //实部
impedance.Ry = m_hDiankang; //虚部
impedance.Z0 = m_hTexing; //特性阻抗
//获取归一化阻抗
RLXL rlxl;
rlxl = chart.CacuRLXL(impedance);
//获取反射系数
FRFL frfl;
frfl = chart.CacuFRFL(rlxl);
//获取R,X圆参数
CIRCLE rCircle = chart.CacuCircleR(rlxl.r);
CIRCLE xCircle = chart.CacuCircleX(rlxl.x);
//获取绘图设备
CDC * pDC = GetDC();
chart.InitSmithChart(pDC);
CPen pen(PS_DOT,2,RGB(255,0,0));//255,0,0
CPen * poldPen = pDC->SelectObject(&pen);
chart.DrawCircleR(rCircle,pDC);//画R圆
chart.DrawCircleX(xCircle,pDC);//画X圆
chart.DrawCircle(frfl,pDC);//画等反射系数圆
chart.ShowImpedance(frfl,rlxl,impedance.Z0,pDC); //在图中显示交点坐标
pDC->SelectObject(poldPen);
ReleaseDC(pDC);//释放绘图设备
//////////////更新界面数据
///////////////////////显示交点坐标
CString str,strS1,strX1,strX2;
strS1.Format("%.2f",rlxl.r*impedance.Z0);
strX1.Format("%.2f",rlxl.x*impedance.Z0);
strX2.Format("%.2f",rlxl.x*impedance.Z0*(-1));
if(rlxl.x>=0)
str.Format("%s +j %s",strS1,strX1);
else
str.Format("%s -j %s",strS1,strX2);
m_hShow=str;
/////////////////////
m_hSwr.Format("%.2f",chart.GetSWR(frfl));//获取驻波比
m_hGuiyiShibu.Format("%.2f",rlxl.r);//归一化阻抗实部
m_hGuiyiXubu.Format("%.2f",rlxl.x);//归一化阻抗虚部
m_hFansheShibu.Format("%.2f",frfl.Fr);//反射系数实部
m_hFansheXubu.Format("%.2f",frfl.Fl);//反射系数虚部
UpdateData(FALSE);
}
void CSmithOfPanDlg::OnBtnFind()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_hTexing <= 0)
{
MessageBox("特性阻抗值必须大于零!","警告!!!",MB_OK|MB_ICONHAND);
return;
}
if(m_hDianzu<0)
{
MessageBox("电阻值不能小于零!","警告!!!",MB_OK|MB_ICONHAND);
return;
}
IMPEDANCE impedance;
impedance.Rx = m_hDianzu;
impedance.Ry = m_hDiankang;
impedance.Z0 = m_hTexing;
RLXL rlxl;
rlxl = chart.CacuRLXL(impedance); //归一化阻抗
FRFL frfl = chart.CacuFRFL(rlxl); //反射系数
/////////////////////////////////////
//获得旋转后新点的反射系数
frfl = chart.Rotate(frfl,m_hWavelenght);
//重新获得归一化阻抗
rlxl = chart.CacuRLXL(frfl);
CIRCLE rCircle = chart.CacuCircleR(rlxl.r);
CIRCLE xCircle = chart.CacuCircleX(rlxl.x);
CDC * pDC = GetDC();
chart.InitSmithChart(pDC);
CPen pen(PS_DOT,2,RGB(255,0,0));
CPen * poldPen = pDC->SelectObject(&pen);
chart.DrawCircleR(rCircle,pDC);
chart.DrawCircleX(xCircle,pDC);
chart.DrawCircle(frfl,pDC);
chart.ShowImpedance(frfl,rlxl,impedance.Z0,pDC);
pDC->SelectObject(poldPen);
ReleaseDC(pDC);
///////////////////////显示交点坐标
CString str,strS1,strX1,strX2;
strS1.Format("%.2f",rlxl.r*impedance.Z0);
strX1.Format("%.2f",rlxl.x*impedance.Z0);
strX2.Format("%.2f",rlxl.x*impedance.Z0*(-1));
if(rlxl.x>=0)
str.Format("%s +j %s",strS1,strX1);
else
str.Format("%s -j %s",strS1,strX2);
m_hShow=str;
m_hSwr.Format("%.2f",chart.GetSWR(frfl));//获取驻波比
m_hGuiyiShibu.Format("%.2f",rlxl.r);//归一化阻抗实部
m_hGuiyiXubu.Format("%.2f",rlxl.x);//归一化阻抗虚部
m_hFansheShibu.Format("%.2f",frfl.Fr);//反射系数实部
m_hFansheXubu.Format("%.2f",frfl.Fl);//反射系数虚部
UpdateData(FALSE);
}
void CSmithOfPanDlg::OnReleasedcaptureSlider1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_hWavelenght = double(m_hSlider)/100;
UpdateData(FALSE);
UpdateData(TRUE);
if(m_hTexing <= 0)
{
MessageBox("特性阻抗不能小于等于零!","警告!!!",MB_OK|MB_ICONHAND);
return;
}
if(m_hDianzu<0)
{
MessageBox("电阻不能小于零!","警告!!!",MB_OK|MB_ICONHAND);
return;
}
IMPEDANCE impedance;
impedance.Rx = m_hDianzu;
impedance.Ry = m_hDiankang;
impedance.Z0 = m_hTexing;
RLXL rlxl;
rlxl = chart.CacuRLXL(impedance);
FRFL frfl = chart.CacuFRFL(rlxl);
/////////////////////////////////////
//获得旋转后新点的反射系数
frfl = chart.Rotate(frfl,m_hWavelenght);
//重新获得归一化阻抗
rlxl = chart.CacuRLXL(frfl);
CIRCLE rCircle = chart.CacuCircleR(rlxl.r);
CIRCLE xCircle = chart.CacuCircleX(rlxl.x);
CDC * pDC = GetDC();
chart.InitSmithChart(pDC);
CPen pen(PS_DOT,2,RGB(255,0,0));
CPen * poldPen = pDC->SelectObject(&pen);
chart.DrawCircleR(rCircle,pDC);
chart.DrawCircleX(xCircle,pDC);
chart.DrawCircle(frfl,pDC);
chart.ShowImpedance(frfl,rlxl,impedance.Z0,pDC);
pDC->SelectObject(poldPen);
ReleaseDC(pDC);
///////////////////////显示交点坐标
CString str,strS1,strX1,strX2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -