📄 jianyangview.cpp
字号:
// JianyangView.cpp : implementation of the CJianyangView class
//
#include "stdafx.h"
#include "Jianyang.h"
#include "JianyangDoc.h"
#include "JianyangView.h"
#include "Math.h"
#include "Last.h"
#include <fstream.h> //#include <fstream>不行
#include <io.h>
#include "Shlwapi.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CJianyangView
IMPLEMENT_DYNCREATE(CJianyangView, CView)
BEGIN_MESSAGE_MAP(CJianyangView, CView)
//{{AFX_MSG_MAP(CJianyangView)
ON_COMMAND(ID_GCODE_OPEN, OnGcodeOpen)
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_SPEEDDATA_OPEN, OnSpeeddataOpen)
ON_WM_CANCELMODE()
ON_COMMAND(ID_ERRORSPEEDDATA_OPEN, OnErrorspeeddataOpen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJianyangView construction/destruction
CJianyangView::CJianyangView()
{
// TODO: add construction code here
// GCodePoint = new CLast;
}
CJianyangView::~CJianyangView()
{
}
BOOL CJianyangView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CJianyangView drawing
void CJianyangView::OnDraw(CDC* pDC)
{
CJianyangDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CJianyangView diagnostics
#ifdef _DEBUG
void CJianyangView::AssertValid() const
{
CView::AssertValid();
}
void CJianyangView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CJianyangDoc* CJianyangView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CJianyangDoc)));
return (CJianyangDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CJianyangView message handlers
void CJianyangView::OnGcodeOpen()
{
// TODO: Add your command handler code here
char line[100000];
int iFlag = 0;
//#include "Shlwapi.h" for PathIsDirectory(),而且要在Project下Setting中的Link项加入:Shlwapi.lib
if(PathIsDirectory("Data")) //要把正斜杠改成反斜杠eg:C://WINDOWS
{
if(_access("Data\\SpeedData.txt",0) != -1)
{
DeleteFile("Data\\SpeedData.txt");
}
if(_access("Data\\ErrorSpeedData.txt",0) != -1)
{
DeleteFile("Data\\ErrorSpeedData.txt");
}
// 如果要删除文件夹下所有文件,用递归查找文件,然后再删除
// 删除空目录用RemoveDirectory
// 删除文件用DeleteFile
// 文件查找用CFileFind
// void CPTestDlg::DeleteAllFile(CString strParent)
// {
// CFileFind f;
// BOOL bFind = f.FindFile(strParent + "*.*");
// while(bFind)
// {
// bFind = f.FindNextFile();
// if(f.IsDots()) continue;
// if(f.IsDirectory())
// {
// DeleteAllFile(strParent + f.GetFileName() + "\\");
// }
// DeleteFile(strParent + f.GetFileName());
// }
// RemoveDirectory(strParent);
// }
//
}
else
{
CreateDirectory("Data",NULL);
//RemoveDirectory("Data");
}
//system("md Data"); //在程序运行时弹出cmd的黑色对话框,其实不新建文件夹也可以的,直接写文件就行
//system("md d:\\aa\\zhao ");
//system("del d:\\aa\\zhao "); // 删除该文件夹下的所有文件
CFileDialog fileDlg(TRUE); //Ture 表示读取
fileDlg.m_ofn.lpstrTitle = "Please Open a GCode File!";
fileDlg.m_ofn.lpstrFilter = "Text Files(*.txt)\0*.txt\0GCode Files(*.nc)\0*.nc\0All Files(*.*)\0*.*\0\0"; //\0*.txt为扩展,每写一个字符都要用\0隔开
if(IDOK == fileDlg.DoModal())
{
ifstream openfile( fileDlg.GetFileName(), ios::binary | ios::nocreate );
if(openfile)
{
if(openfile.good())
{
void BeginWaitCursor();
while(1)
{
openfile.getline(line,100,'\n');
//若此行为空,即最后一行,结束操作
//NULL表示一行为空,ASCII码13表示硬回车
if(line[0] == 13 || line[0] == NULL)
{
break;
}
switch(line[0])
{
case 'N':
{
//*iOpenGCodeLine ++; //统计读入G代码行数
//读入单元字符串
int i = ReadUnitGCode(line,0);
UnitChar += '*'; //以备在boost中用
CMath *Jianyang = new CMath;
Jianyang->AnalyzeGCode(UnitChar, iFlag%2);
iFlag ++;
}
break;
default:
break;
}
}
EndWaitCursor();
}
}
openfile.close();
}
}
int CJianyangView::ReadUnitGCode(char letter[], int i)
{
//将UnitChar的内容置空
UnitChar.Empty();
//再次给UnitChar赋值
if(UnitChar.IsEmpty())
{
while(1)
{
if(letter[i] == 13 || letter[i] == ' ' || letter[i] == '\n' )
{
break;
}
UnitChar += letter[i];
i++;
}
}
//返回下一个Keyword的首地址
return ++i;
}
void CJianyangView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CString str;
str.Format("x=%d,y=%d", point.x, point.y); //坐标参数化
CView::OnMouseMove(nFlags, point);
GetParent()->GetDescendantWindow(AFX_IDW_STATUS_BAR)->SetWindowText(str);
}
void CJianyangView::OnSpeeddataOpen()
{
// TODO: Add your command handler code here
// WinExec
// CreateProcess
// ShellExecute
void BeginWaitCursor();
ShellExecute(this->m_hWnd, "open", "notepad.exe", "Data\\SpeedData.txt", "", SW_SHOW );
EndWaitCursor();
}
void CJianyangView::OnErrorspeeddataOpen()
{
// TODO: Add your command handler code here
void BeginWaitCursor();
ShellExecute(this->m_hWnd, "open", "notepad.exe", "Data\\ErrorSpeedData.txt", "", SW_SHOW );
EndWaitCursor();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -