📄 slsprj.cpp
字号:
// SlsPrj.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "SlsPrj.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "EntityView.h"
#include "CurrentLayerView.h"
#include "DebugDlg.h"
#include "BaseParm.h"
#include "SysPropertySheet.h"
#include "EntityPropertySheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSlsApp
BEGIN_MESSAGE_MAP(CSlsApp, CWinApp)
//{{AFX_MSG_MAP(CSlsApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_SYS_SETTING, OnSysSetting)
ON_COMMAND(ID_ENTITY_SETTING, OnEntitySetting)
ON_COMMAND(ID_ZERO, OnZero)
ON_COMMAND(ID_DEBUG, OnDebug)
ON_COMMAND(ID_BASEPARM_SETTING, OnBaseparmSetting)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSlsApp construction
CSlsApp::CSlsApp()
{
m_pPathData = NULL;
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CSlsApp object
CSlsApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CSlsApp initialization
BOOL CSlsApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
SetRegistryKey(_T("hrps"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
ReadIniFile(); //Get system parameters etc from the application's INI file
// Register document templates
AddDocTemplate( new CMultiDocTemplate(
IDR_ENTITY_TYPE,
RUNTIME_CLASS(CStlDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CEntityView)));
m_pCurrentLayerViewDocTemplate= new CMultiDocTemplate(
IDR_CURRENTLAYER_TYPE,
RUNTIME_CLASS(CStlDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CCurrentLayerView));
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
// Enable DDE Execute open
EnableShellOpen();
RegisterShellFileTypes(TRUE);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Turn off the display of a new MDI child window during startup
if (cmdInfo.m_nShellCommand = CCommandLineInfo::FileNew)
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The main window has been initialized, so activate it.
pMainFrame->ActivateFrame(m_nCmdShow);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// 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)
// No message handlers
//}}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()
// App command to run the dialog
void CSlsApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CSlsApp commands
BOOL CSlsApp::ProcessShellCommand(CCommandLineInfo & rCmdInfo)
{
if (rCmdInfo.m_nShellCommand =CCommandLineInfo::FileNothing)
{
return TRUE;
}
else
{
return CWinApp::ProcessShellCommand(rCmdInfo);
}
}
void CSlsApp::OnProperties()
{
CSysPropertySheet propSheet;
//initialize
propSheet.m_Page1.m_scanSpeedX=m_scanSpeedX;
propSheet.m_Page1.m_scanSpeedY=m_scanSpeedY;
propSheet.m_Page1.m_zeroSpeed=m_zeroSpeed;
propSheet.m_Page2.m_powderUp=m_powderUp;
propSheet.m_Page2.m_platformDown=m_platformDown;
propSheet.m_Page3.m_scanWidth=m_scanWidth;
propSheet.m_Page3.m_layerThickness=m_layerThickness;
propSheet.m_Page3.m_rotateAngle=m_rotateAngle;
propSheet.m_Page3.m_laserPowerXDir=m_laserPowerXDir;
propSheet.m_Page3.m_laserPowerYDir=m_laserPowerYDir;
propSheet.m_Page4.m_zeroPosX=m_zeroPosX;
propSheet.m_Page4.m_zeroPosY=m_zeroPosY;
propSheet.m_Page4.m_platformLength = m_platformLength;
propSheet.m_Page4.m_platformWidth = m_platformWidth;
propSheet.m_Page4.m_startPosX = m_startPosX;
propSheet.m_Page4.m_startPosY = m_startPosY;
if(propSheet.DoModal() == IDOK)
{
m_scanSpeedX=propSheet.m_Page1.m_scanSpeedX;
m_scanSpeedY=propSheet.m_Page1.m_scanSpeedY;
m_zeroSpeed=propSheet.m_Page1.m_zeroSpeed;
m_powderUp=propSheet.m_Page2.m_powderUp;
m_platformDown=propSheet.m_Page2.m_platformDown;
m_scanWidth=propSheet.m_Page3.m_scanWidth;
m_layerThickness=propSheet.m_Page3.m_layerThickness;
m_rotateAngle=propSheet.m_Page3.m_rotateAngle;
m_laserPowerXDir=propSheet.m_Page3.m_laserPowerXDir;
m_laserPowerYDir=propSheet.m_Page3.m_laserPowerYDir;
m_zeroPosX=propSheet.m_Page4.m_zeroPosX;
m_zeroPosY=propSheet.m_Page4.m_zeroPosY;
m_platformLength = propSheet.m_Page4.m_platformLength;
m_platformWidth = propSheet.m_Page4.m_platformWidth;
m_startPosX = propSheet.m_Page4.m_startPosX;
m_startPosY = propSheet.m_Page4.m_startPosY;
WriteIntoIniFile();
}
}
void CSlsApp::OnSysSetting()
{
OnProperties();
}
void CSlsApp::OnProperties1()
{
CEntityPropertySheet propSheet;
//initialize
propSheet.m_Page1.m_centerPosX=m_centerPosX;
propSheet.m_Page1.m_centerPosY=m_centerPosY;
propSheet.m_Page1.m_startHeight=m_startHeight;
propSheet.m_Page1.m_endHeight=m_endHeight;
if(propSheet.DoModal() == IDOK)
{
m_centerPosX=propSheet.m_Page1.m_centerPosX;
m_centerPosY=propSheet.m_Page1.m_centerPosY;
m_startHeight=propSheet.m_Page1.m_startHeight;
m_endHeight=propSheet.m_Page1.m_endHeight;
WriteIntoIniFile();
}
}
void CSlsApp::OnEntitySetting()
{
SetPartCenterPos();
OnProperties1();
}
void CSlsApp::WriteIntoIniFile()
{
TCHAR buffer[20];
TCHAR strSysSettings[] = _T("System settings");
TCHAR strEntitySettings[] = _T("Entity settings");
TCHAR strBaseParmSettings[] = _T("BaseParm settings");
//Write system settings into the application's INI file
sprintf(buffer,"%lf",m_scanSpeedX);
WriteProfileString(strSysSettings,_T("ScanSpeedX"),buffer);
sprintf(buffer,"%lf",m_scanSpeedY);
WriteProfileString(strSysSettings,_T("ScanSpeedY"),buffer);
sprintf(buffer,"%lf",m_zeroSpeed);
WriteProfileString(strSysSettings,_T("ZeroSpeed"),buffer);
sprintf(buffer,"%lf",m_platformDown);
WriteProfileString(strSysSettings,_T("PlatformDown"),buffer);
sprintf(buffer,"%lf",m_powderUp);
WriteProfileString(strSysSettings,_T("PowderUp"),buffer);
sprintf(buffer,"%lf",m_scanWidth);
WriteProfileString(strSysSettings,_T("ScanWidth"),buffer);
sprintf(buffer,"%lf",m_layerThickness);
WriteProfileString(strSysSettings,_T("LayerThickness"),buffer);
sprintf(buffer,"%lf",m_rotateAngle);
WriteProfileString(strSysSettings,_T("RotateAngle"),buffer);
sprintf(buffer,"%lf",m_laserPowerXDir);
WriteProfileString(strSysSettings,_T("LaserPowerXDir"),buffer);
sprintf(buffer,"%lf",m_laserPowerYDir);
WriteProfileString(strSysSettings,_T("LaserPowerYDir"),buffer);
sprintf(buffer,"%lf",m_zeroPosX);
WriteProfileString(strSysSettings,_T("ZeroPosX"),buffer);
sprintf(buffer,"%lf",m_zeroPosY);
WriteProfileString(strSysSettings,_T("ZeroPosY"),buffer);
sprintf(buffer,"%lf",m_platformLength);
WriteProfileString(strSysSettings,_T("PlatformLength"),buffer);
sprintf(buffer,"%lf",m_platformWidth);
WriteProfileString(strSysSettings,_T("PlatformWidth"),buffer);
sprintf(buffer,"%lf",m_startPosX);
WriteProfileString(strSysSettings,_T("StartPosX"),buffer);
sprintf(buffer,"%lf",m_startPosY);
WriteProfileString(strSysSettings,_T("StartPosY"),buffer);
//Write Entity settings into the application's INI file
sprintf(buffer,"%lf",m_centerPosX);
WriteProfileString(strEntitySettings,_T("CenterPosX"),buffer);
sprintf(buffer,"%lf",m_centerPosY);
WriteProfileString(strEntitySettings,_T("CenterPosY"),buffer);
sprintf(buffer,"%lf",m_startHeight);
WriteProfileString(strEntitySettings,_T("StartHeight"),buffer);
sprintf(buffer,"%lf",m_endHeight);
WriteProfileString(strEntitySettings,_T("EndHeight"),buffer);
//Write base parameters into the application's INI file
sprintf(buffer,"%lf",m_height);
WriteProfileString(strBaseParmSettings,_T("Height"),buffer);
}
void CSlsApp::ReadIniFile()
{
TCHAR strSysSettings[] = _T("System settings");
TCHAR strEntitySettings[] = _T("Entity settings");
TCHAR strBaseParmSettings[] = _T("BaseParm settings");
//Read system settings from the application's INI file
m_scanSpeedX=atof(GetProfileString(strSysSettings,_T("ScanSpeedX")));
m_scanSpeedY=atof(GetProfileString(strSysSettings,_T("ScanSpeedY")));
m_zeroSpeed=atof(GetProfileString(strSysSettings,_T("ZeroSpeed")));
m_platformDown=atof(GetProfileString(strSysSettings,_T("PlatformDown")));
m_powderUp=atof(GetProfileString(strSysSettings,_T("PowderUp")));
m_scanWidth=atof(GetProfileString(strSysSettings,_T("ScanWidth")));
m_layerThickness=atof(GetProfileString(strSysSettings,_T("LayerThickness")));
m_rotateAngle=atof(GetProfileString(strSysSettings,_T("RotateAngle")));
m_laserPowerXDir=atof(GetProfileString(strSysSettings,_T("LaserPowerXDir")));
m_laserPowerYDir=atof(GetProfileString(strSysSettings,_T("LaserPowerYDir")));
m_zeroPosX=atof(GetProfileString(strSysSettings,_T("ZeroPosX")));
m_zeroPosY=atof(GetProfileString(strSysSettings,_T("ZeroPosY")));
m_platformLength=atof(GetProfileString(strSysSettings,_T("PlatformLength")));
m_platformWidth=atof(GetProfileString(strSysSettings,_T("PlatformWidth")));
m_startPosX=atof(GetProfileString(strSysSettings,_T("StartPosX")));
m_startPosY=atof(GetProfileString(strSysSettings,_T("StartPosY")));
//Read Entity settings from the application's INI file
m_centerPosX=atof(GetProfileString(strEntitySettings,_T("CenterPosX")));
m_centerPosY=atof(GetProfileString(strEntitySettings,_T("CenterPosY")));
m_startHeight=atof(GetProfileString(strEntitySettings,_T("StartHeight")));
m_endHeight=atof(GetProfileString(strEntitySettings,_T("EndHeight")));
//Read base parameters into the application's INI file
m_height=atof(GetProfileString(strBaseParmSettings,_T("Height")));
}
void CSlsApp::OnZero()
{
DWORD zeroPosX=DWORD(m_zeroPosX*500);
DWORD zeroPosY=DWORD(m_zeroPosY*500);
_asm
{
mov dx, 0x8321 //清指令
mov al, 0x3
out dx, al
mov dx, 0x8320
mov eax, 0x9 //XY轴回机械零点
out dx, eax
mov eax, zeroPosX
out dx, eax
mov eax, zeroPosY
out dx, eax
mov eax, 7 //设定回零速度(5米/分钟)
out dx, eax
mov eax, 2500000
out dx, eax
mov eax, 0x3 //XY轴回逻辑零点
out dx, eax
mov eax, 0
out dx, eax
mov eax, 0
out dx, eax
}
}
void CSlsApp::OnDebug()
{
CDebugDlg debugWnd;
debugWnd.DoModal();
}
void CSlsApp::OnBaseparmSetting()
{
CBaseParm baseParmDlg;
//initialize
baseParmDlg.m_height=m_height;
if(baseParmDlg.DoModal() == IDOK)
{
m_height=baseParmDlg.m_height;
WriteIntoIniFile();
}
}
void CSlsApp::SetPartCenterPos()
{
double partCenter[2], platformCenter[2], distVal[2];
partCenter[0] = (m_pPathData->m_Solid.m_xMax + m_pPathData->m_Solid.m_xMin)/2.0;
partCenter[1] = (m_pPathData->m_Solid.m_yMax + m_pPathData->m_Solid.m_yMin)/2.0;
platformCenter[0] = m_startPosX + m_platformLength/2.0;
platformCenter[1] = m_startPosY + m_platformWidth/2.0;
distVal[0] = platformCenter[0] - partCenter[0];
distVal[1] = platformCenter[1] - partCenter[1];
m_centerPosX = (int(distVal[0] * 100 + 0.5))/100.0;
m_centerPosY = (int(distVal[1] * 100 + 0.5))/100.0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -