?? 288銑床加工代碼生成軟件dlg.cpp
字號:
// 288銑床加工代碼生成軟件Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "288銑床加工代碼生成軟件.h"
#include "288銑床加工代碼生成軟件Dlg.h"
#include "iostream.h"
#include "fstream.h"
#include "math.h"
#include "WARN.h"
#include "draw.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()
/////////////////////////////////////////////////////////////////////////////
// CMy288Dlg dialog
CMy288Dlg::CMy288Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy288Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMy288Dlg)
m_b = 0.1f;
m_f = 4000;
m_x1 = 3.8f;
m_x2 = 18.999f;
m_z = 10.0f;
m_num = 0;
m_x = 4000;
m_subb = 0.001f;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMy288Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMy288Dlg)
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_Text(pDX, IDC_EDIT_B, m_b);
DDV_MinMaxFloat(pDX, m_b, 5.e-004f, 360.f);
DDX_Text(pDX, IDC_EDIT_F, m_f);
DDV_MinMaxInt(pDX, m_f, 0, 100000);
DDX_Text(pDX, IDC_EDIT_X1, m_x1);
DDX_Text(pDX, IDC_EDIT_X2, m_x2);
DDX_Text(pDX, IDC_EDIT_Z, m_z);
DDX_Text(pDX, IDC_EDIT_Z2, m_num);
DDV_MinMaxInt(pDX, m_num, 0, 9999);
DDX_Text(pDX, IDC_EDIT_X, m_x);
DDV_MinMaxInt(pDX, m_x, 0, 100000);
DDX_Text(pDX, IDC_EDIT1, m_subb);
DDV_MinMaxFloat(pDX, m_subb, 0.f, 1.e+008f);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMy288Dlg, CDialog)
//{{AFX_MSG_MAP(CMy288Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDOK2, OnOk2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy288Dlg message handlers
BOOL CMy288Dlg::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
m_list.AddString("曲線方程1");
m_list.AddString("曲線方程2");
m_list.AddString("曲線方程3");
m_list.AddString("曲線方程4");
m_list.SetCurSel(0);
//UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
}
void CMy288Dlg::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 CMy288Dlg::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 CMy288Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMy288Dlg::OnButton1()
{
Cdraw dlg;
if(dlg.DoModal()!=IDOK)
{
return;
}
delete dlg;
}
void CMy288Dlg::OnOK()
{
// TODO: Add extra validation here
bool first=true;
int n=0;
n=m_list.GetCurSel();
UpdateData(true);
switch(n)
{
case 0:m_x2=18.999;break;
case 1:m_x2=8.319;break;
case 2:break;
default:break;
}
UpdateData(false);
CString str1;
char c1;
double ki=0.0;
int i=0;
double y=0,y1=0,y2=0;
CFileDialog dlg(FALSE,"CNC",strFilePath,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"CNC加工文件(*.CNC)|*.CNC|所有文件(*.*)|*.*||",NULL);
if(dlg.DoModal()!=IDOK)
{
return;
}
strFilePath=dlg.GetPathName();
delete dlg;
FILE *fp=NULL;
if( (fp= fopen(strFilePath, "w" )) == NULL )
{
;//MessageBox("The file 'data' was not opened!");
}
else
{
;//MessageBox("The file 'data' was opened!");
}
switch(n)
{
case 0:
/////////////////////////////////////////////////////////////////////////
m_f=(int)m_f;
///////////////////////////
str1="%\n";
fprintf(fp,"%s",str1);
c1='o';
fputc(c1,fp);
fprintf(fp,"%04d",m_num);
c1='\n';
fputc(c1,fp);
str1="G54";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
str1="G00Z";
fprintf(fp,"%s",str1);
fprintf(fp,"%-6.3f",m_z);
c1='\n';
fputc(c1,fp);
str1="G00X0.000Y0.000";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
str1="M03S";
fprintf(fp,"%s",str1);
fprintf(fp,"%d",m_x);
c1='\n';
fputc(c1,fp);
str1="G00Z4.000";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
str1="G01Z0.000F50";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
////////////////////////////////加工曲線1
i=0;
first=true;
for(k=0.0;k<=220;)
{
ki=k;
l=79.055-pow(ki,0.903)*0.317;
a=l-47.109;
b=l*l-215.33*l+5705.465208;
c=11410.93042*l-268778.7605-94.218*l*l;
e=b*b-4*a*c;
e=sqrt(e);
d=0-(b+e)/(2*a);
x=88.38-l-d;
if(first)
{
str1="G01X";
fprintf(fp,"%s",str1);
fprintf(fp,"%-6.3f",0-x);
c1='Y';
fputc(c1,fp);
fprintf(fp,"%-6.3f",0-k);
c1='F';
fputc(c1,fp);
fprintf(fp,"%d",m_f);
c1='\n';
fputc(c1,fp);
first=false;
}
else
{
c1='X';
fputc(c1,fp);
fprintf(fp,"%-6.3f",0-x);
c1='Y';
fputc(c1,fp);
fprintf(fp,"%-6.3f",0-k);
c1='\n';
fputc(c1,fp);
}
//k=k+m_b;
i=i++;
k=i/(1.0/m_b);
}
/////////////////////////////////////加工曲線2
str1="G00Z";
fprintf(fp,"%s",str1);
fprintf(fp,"%-6.3f",m_z);
c1='\n';
fputc(c1,fp);
str1="G00X";
fprintf(fp,"%s",str1);
fprintf(fp,"%-6.3f",0-m_x2);
str1="Y0.000";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
str1="G00Z4.000";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
str1="G01Z0.000";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
first=true;
//////////////////////////////////////////////////////////
i=0;
for(k=0;k<=220;)
{
ki=k;
l=79.055-pow(ki,0.903)*0.317;
x=98.054-l;
if(first)
{
str1="G01X";
fprintf(fp,"%s",str1);
fprintf(fp,"%-6.3f",0-x);
c1='Y';
fputc(c1,fp);
fprintf(fp,"%-6.3f",0-k);
c1='F';
fputc(c1,fp);
fprintf(fp,"%d",m_f);
c1='\n';
fputc(c1,fp);
first=false;
}
else
{
str1="X";
fprintf(fp,"%s",str1);
fprintf(fp,"%-6.3f",0-x);
c1='Y';
fputc(c1,fp);
fprintf(fp,"%-6.3f",0-k);
c1='\n';
fputc(c1,fp);
}
i=i++;
k=i/(1.0/m_b);
}
/////////////////////////////////////加工曲線2
str1="G00Z";
fprintf(fp,"%s",str1);
fprintf(fp,"%-6.3f",m_z);
c1='\n';
fputc(c1,fp);
str1="M05";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
str1="G00X0.000Y0.000";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
str1="M02";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
str1="%\n";
fprintf(fp,"%s",str1);
break;
////////////////////////////////////////////////////////////////////////
case 1:
m_f=(int)m_f;
str1="%\n";
fprintf(fp,"%s",str1);
c1='o';
fputc(c1,fp);
fprintf(fp,"%04d",m_num);
c1='\n';
fputc(c1,fp);
str1="G54";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
str1="G00Z";
fprintf(fp,"%s",str1);
fprintf(fp,"%-6.3f",m_z);
c1='\n';
fputc(c1,fp);
str1="G00X0.000Y0.000";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
str1="M03S";
fprintf(fp,"%s",str1);
fprintf(fp,"%d",m_x);
c1='\n';
fputc(c1,fp);
str1="G00Z4.000";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
str1="G01Z0.000F50";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
////////////////////////////////加工曲線1
i=0;
first=true;
for(k=0.0;k<=220;)
{
ki=k/220.0;
x=24*pow(ki,2.25);
if(first)
{
str1="G01X";
fprintf(fp,"%s",str1);
fprintf(fp,"%-6.3f",0-x);
c1='Y';
fputc(c1,fp);
fprintf(fp,"%-6.3f",0-k);
c1='F';
fputc(c1,fp);
fprintf(fp,"%d",m_f);
c1='\n';
fputc(c1,fp);
first=false;
}
else
{
c1='X';
fputc(c1,fp);
fprintf(fp,"%-6.3f",0-x);
c1='Y';
fputc(c1,fp);
fprintf(fp,"%-6.3f",0-k);
c1='\n';
fputc(c1,fp);
}
i=i++;
k=i/(1.0/m_b);
}
/////////////////////////////////////加工曲線2
str1="G00Z";
fprintf(fp,"%s",str1);
fprintf(fp,"%-6.3f",m_z);
c1='\n';
fputc(c1,fp);
str1="G00X";
fprintf(fp,"%s",str1);
fprintf(fp,"%-6.3f",0-m_x2);
str1="Y0.000";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
str1="G00Z4.000";
fprintf(fp,"%s",str1);
c1='\n';
fputc(c1,fp);
str1="G01Z0.000F50";
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -