📄 pmacctrldlg.cpp
字号:
}
}
// 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 CPmacCtrlDlg::OnPaint()
{
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 CPmacCtrlDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
// *******************菜单栏项目(文件——控制——构型——帮助)*******************
// ==========文件-菜单==========
// ================="新建"-函数=================
// 首先判断选择的轨迹类型,然后将相应的参数全部设置为0;
// ========================================
void CPmacCtrlDlg::OnFileNew()
{
// TODO: Add your command handler code here
CString msg;
m_cb.GetLBText(m_cb.GetCurSel(),msg);
// Judge which option is chosen
if(msg == "直线_LINE")
{
UpdateData(TRUE);
m_SxEdit = 0; m_ExEdit = 0;
m_SyEdit = 0; m_EyEdit = 0;
m_SzEdit = 0; m_EzEdit = 0;
m_SaEdit = 0; m_EaEdit = 0;
m_SbEdit = 0; m_EbEdit = 0;
UpdateData(FALSE);
}
else if(msg == "圆_CIRCLE")
{
UpdateData(TRUE);
m_SrEdit = 0; m_ErEdit = m_SrEdit;
m_SangEdit = 0; m_EangEdit = 0;
m_ScpxEdit = 0; m_EcpxEdit = m_ScpxEdit;
m_ScpyEdit = 0; m_EcpyEdit = m_ScpyEdit;
m_ScpzEdit = 0; m_EcpzEdit = m_ScpzEdit;
UpdateData(FALSE);
}
else
{
UpdateData(TRUE);
m_SrEdit = 0; m_ErEdit = 0;
m_SangEdit = 0; m_EangEdit = 0;
m_ScpxEdit = 0; m_EcpxEdit = 0;
m_ScpyEdit = 0; m_EcpyEdit = 0;
m_ScpzEdit = 0; m_EcpzEdit = 0;
UpdateData(FALSE);
}
}
// ================="打开"-函数=================
// 打开以前保存的运动轨迹几何参数文件,将其中的几何参数读入相应轨迹的参数编辑框内。
// 首先弹出打开对话框,供用户选择要打开的文件,然后读取当前选择的轨迹类型,与用户
// 选择的文件的轨迹类型比较,如一致,则读取轨迹参数,否则提示轨迹类型不符。
// ========================================
void CPmacCtrlDlg::OnFileOpen()
{
// TODO: Add your command handler code here
// Pop-up the file open dialog box
static char BASED_CODE szFilter[] = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*||";
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
if(dlg.DoModal() == IDOK)
{
// Get the full path of the specified file
CString fileopen;
fileopen = dlg.GetPathName();
if(fileopen == "") return;
CPmacCtrlDlg::OnOpen(fileopen);
}
}
// =================File Open=================
void CPmacCtrlDlg::OnOpen(CString fileopen)
{
// Open the file
FILE* fpopen;
fpopen = fopen(fileopen, "r");
// line parameter
char row[100], judge[100], spoint[100], sang[100], epoint[100], eang[100];
char sx[20], sy[20], sz[20], sa[20], sb[20];
char ex[20], ey[20], ez[20], ea[20], eb[20];
// circle parameter
char center[100], radius[100], Csang[100], Ceang[100];
char Cx[20], Cy[20], Cz[20];
// helix parameter
char Scenter[100], Sradius[100], Hsang[100], Ecenter[100], Eradius[100], Heang[100];
char Hsx[20], Hsy[20], Hsz[20], Hex[20], Hey[20], Hez[20];
int num = 100;
// Get the 4th line of the file to judge which track it is
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(judge, num, fpopen);
// Get current type of track
CString msg;
m_cb.GetLBText(m_cb.GetCurSel(),msg);
// Read the file to read in the parameters, and show them to edit box
if(msg == "直线_LINE")
{
if(judge[0]=='L')
{
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(spoint, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(sang, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(epoint, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(eang, num, fpopen);
sscanf(spoint, "%s %s %s", sx, sy, sz);
sscanf(sang, "%s %s", sa, sb);
sscanf(epoint, "%s %s %s", ex, ey, ez);
sscanf(eang, "%s %s", ea, eb);
UpdateData(TRUE);
m_SxEdit = atof(sx); m_ExEdit = atof(ex);
m_SyEdit = atof(sy); m_EyEdit = atof(ey);
m_SzEdit = atof(sz); m_EzEdit = atof(ez);
m_SaEdit = atof(sa); m_EaEdit = atof(ea);
m_SbEdit = atof(sb); m_EbEdit = atof(eb);
UpdateData(FALSE);
AfxMessageBox("指定文件中的参数已被读入!");
}
else
AfxMessageBox("所选参数文件轨迹类型与当前指定的轨迹类型不同,不能读取文件!");
}
else if(msg == "圆_CIRCLE")
{
if(judge[0]=='C')
{
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(center, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(radius, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(Csang, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(Ceang, num, fpopen);
sscanf(center, "%s %s %s", Cx, Cy, Cz);
UpdateData(TRUE);
m_SrEdit = atof(radius); m_ErEdit = m_SrEdit;
m_SangEdit = atof(Csang); m_EangEdit = atof(Ceang);
m_ScpxEdit = atof(Cx); m_EcpxEdit = m_ScpxEdit;
m_ScpyEdit = atof(Cy); m_EcpyEdit = m_ScpyEdit;
m_ScpzEdit = atof(Cz); m_EcpzEdit = m_ScpzEdit;
UpdateData(FALSE);
AfxMessageBox("指定文件中的参数已被读入!");
}
else
AfxMessageBox("所选参数文件轨迹类型与当前指定的轨迹类型不同,不能读取文件!");
}
else
{
if(judge[0]=='H')
{
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(Scenter, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(Sradius, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(Hsang, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(Ecenter, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(Eradius, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(row, num, fpopen);
fgets(Heang, num, fpopen);
sscanf(Scenter, "%s %s %s", Hsx, Hsy, Hsz);
sscanf(Ecenter, "%s %s %s", Hex, Hey, Hez);
UpdateData(TRUE);
m_SrEdit = atof(Sradius); m_ErEdit = atof(Eradius);
m_SangEdit = atof(Hsang); m_EangEdit = atof(Heang);
m_ScpxEdit = atof(Hsx); m_EcpxEdit = atof(Hex);
m_ScpyEdit = atof(Hsy); m_EcpyEdit = atof(Hey);
m_ScpzEdit = atof(Hsz); m_EcpzEdit = atof(Hez);
UpdateData(FALSE);
AfxMessageBox("指定文件中的参数已被读入!");
}
else
AfxMessageBox("所选参数文件轨迹类型与当前指定的轨迹类型不同,不能读取文件!");
}
}
// ================="保存"-函数=================
// 首先判断轨迹类型,然后将当前输入的轨迹参数保存在相应的默认文件中,并提示用户。
// line - Lpmac.txt; circle - Cpmac.txt; helix - Hpmac.txt;
// ========================================
void CPmacCtrlDlg::OnFileSave()
{
// TODO: Add your command handler code here
CString msg;
m_cb.GetLBText(m_cb.GetCurSel(),msg);
if(msg == "直线_LINE")
CPmacCtrlDlg::OnSaveText(BASEDIR + FILESAVEL);
else if(msg == "圆_CIRCLE")
CPmacCtrlDlg::OnSaveText(BASEDIR + FILESAVEC);
else
CPmacCtrlDlg::OnSaveText(BASEDIR + FILESAVEH);
AfxMessageBox(MSGSAVE);
}
// ================="另存为"-函数=================
// 用户自己指定名称保存运动轨迹参数
// =========================================
void CPmacCtrlDlg::OnFileSaveas()
{
// TODO: Add your command handler code here
// Pop-up the file open dialog box
static char BASED_CODE szFilter[] = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*||";
CFileDialog dlg(FALSE,".txt",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
if(dlg.DoModal () == IDOK )
{
CString filesaveas;
filesaveas = dlg.GetPathName();
if(filesaveas == "") return;
CPmacCtrlDlg::OnSaveText(filesaveas);
AfxMessageBox(MSGSAVEAS);
}
}
// ================="默认数据"-函数=================
// 判断当前轨迹类型,将相应的参数设置为默认值。
// ==========================================
void CPmacCtrlDlg::OnFileDefault()
{
// TODO: Add your command handler code here
CString msg;
m_cb.GetLBText(m_cb.GetCurSel(),msg);
// Judge which track is chosen
if(msg == "直线_LINE")
{
UpdateData(TRUE);
m_SxEdit = 90; m_ExEdit = 0;
m_SyEdit = 90; m_EyEdit = 0;
m_SzEdit = -800; m_EzEdit = -800;
m_SaEdit = 0; m_EaEdit = 0;
m_SbEdit = 0; m_EbEdit = 0;
UpdateData(FALSE);
}
else if(msg == "圆_CIRCLE")
{
UpdateData(TRUE);
m_SrEdit = 90; m_ErEdit = m_SrEdit;
m_SangEdit = 0; m_EangEdit = 360;
m_ScpxEdit = 0; m_EcpxEdit = m_ScpxEdit;
m_ScpyEdit = 0; m_EcpyEdit = m_ScpyEdit;
m_ScpzEdit = -800; m_EcpzEdit = m_ScpzEdit;
UpdateData(FALSE);
}
else
{
UpdateData(TRUE);
m_SrEdit = 90; m_ErEdit = 50;
m_SangEdit = 0; m_EangEdit = 360;
m_ScpxEdit = 0; m_EcpxEdit = 0;
m_ScpyEdit = 0; m_EcpyEdit = 0;
m_ScpzEdit = -800; m_EcpzEdit = -400;
UpdateData(FALSE);
}
}
// ================="退出"-函数=================
// 关闭PMAC,释放DLL,退出程序。
// ========================================
void CPmacCtrlDlg::OnFileExit()
{
// TODO: Add your command handler code here
ClosePmacDevice(0);
FreeLibrary(hlib);
OnCancel();
}
// ==========控制-菜单==========
// ================="数据处理"-函数=================
// 首先判断当前选择的轨迹类型,然后对相应轨迹参数进行插补和逆解处理,生成供查看用的插补
// 、逆解文件,以及供下载用的*.pmc文件。
// line - Ltest.pmc; circle - Ctest.pmc; helix - Htest.pmc;
// ==========================================
void CPmacCtrlDlg::OnCtrlProcess()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -