diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.cpp b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.cpp new file mode 100644 index 0000000..bc24a99 --- /dev/null +++ b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.cpp @@ -0,0 +1,94 @@ + +// Utility_Lite.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "Utility_Lite.h" +#include "Utility_LiteDlg.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + + +// CUtility_LiteApp + +BEGIN_MESSAGE_MAP(CUtility_LiteApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CUtility_LiteApp construction + +CUtility_LiteApp::CUtility_LiteApp() +{ + // support Restart Manager + m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; + + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CUtility_LiteApp object + +CUtility_LiteApp theApp; + + +// CUtility_LiteApp initialization + +BOOL CUtility_LiteApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CUtility_LiteDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + + // Delete the shell manager created above. + if (pShellManager != NULL) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.h b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.h new file mode 100644 index 0000000..acc112e --- /dev/null +++ b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.h @@ -0,0 +1,32 @@ + +// Utility_Lite.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CUtility_LiteApp: +// See Utility_Lite.cpp for the implementation of this class +// + +class CUtility_LiteApp : public CWinApp +{ +public: + CUtility_LiteApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CUtility_LiteApp theApp; \ No newline at end of file diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.rc b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.rc new file mode 100644 index 0000000..fdd69f5 Binary files /dev/null and b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.rc differ diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.vcxproj b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.vcxproj new file mode 100644 index 0000000..d9a4854 --- /dev/null +++ b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.vcxproj @@ -0,0 +1,127 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {0E5F6F86-6883-47F0-9DC9-8232BBF13B58} + Utility_Lite + MFCProj + + + + Application + true + Unicode + Dynamic + + + Application + false + true + Unicode + Dynamic + + + + + + + + + + + + + true + + + false + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + Create + Create + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.vcxproj.filters b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.vcxproj.filters new file mode 100644 index 0000000..18ca7f4 --- /dev/null +++ b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.vcxproj.filters @@ -0,0 +1,59 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.vcxproj.user b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.vcxproj.user new file mode 100644 index 0000000..695b5c7 --- /dev/null +++ b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_Lite.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_LiteDlg.cpp b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_LiteDlg.cpp new file mode 100644 index 0000000..6619ca3 --- /dev/null +++ b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_LiteDlg.cpp @@ -0,0 +1,1281 @@ + +// Utility_LiteDlg.cpp : implementation file +// +#include "stdafx.h" +#include +#include +#include "Resource.h" +#include "Utility_Lite.h" +#include "Utility_LiteDlg.h" +#include "afxdialogex.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif +#define M_E 2.71828182845904523536 +#define M_LOG2E 1.44269504088896340736 +#define M_LOG10E 0.434294481903251827651 +#define M_LN2 0.693147180559945309417 +#define M_LN10 2.30258509299404568402 +#define M_PI 3.14159265358979323846 +#define M_PI_2 1.57079632679489661923 +#define M_PI_4 0.785398163397448309616 +#define M_1_PI 0.318309886183790671538 +#define M_2_PI 0.636619772367581343076 +#define M_2_SQRTPI 1.12837916709551257390 +#define M_SQRT2 1.41421356237309504880 +#define M_SQRT1_2 0.707106781186547524401 +std::vector g_Report; + +// CAboutDlg dialog used for App About + +class CAboutDlg : public CDialogEx +{ +public: + CAboutDlg(); + + // Dialog Data + enum { IDD = IDD_ABOUTBOX }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + + // Implementation +protected: + DECLARE_MESSAGE_MAP() +}; + +CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) +{ +} + +void CAboutDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); +} + +BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) +END_MESSAGE_MAP() + + +// CUtility_LiteDlg dialog + + + + +CUtility_LiteDlg::CUtility_LiteDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(CUtility_LiteDlg::IDD, pParent) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CUtility_LiteDlg::DoDataExchange(CDataExchange* pDX) +{ + DDX_Control(pDX, IDC_EDIT_MSG_OUT, m_edMSG); + CDialogEx::DoDataExchange(pDX); +} + +BEGIN_MESSAGE_MAP(CUtility_LiteDlg, CDialogEx) + ON_WM_SYSCOMMAND() + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_BUTTON_IMAGEDLL_2LASER_CALCULATE, &CUtility_LiteDlg::OnBnClickedButtonImagedll2laserCalculate) + ON_BN_CLICKED(IDC_BUTTON_SAVE_ALL_MSG, &CUtility_LiteDlg::OnBnClickedButtonSaveAllMsg) + ON_BN_CLICKED(IDC_BUTTON_CLEAR_ALL_MSG, &CUtility_LiteDlg::OnBnClickedButtonClearAllMsg) + ON_BN_CLICKED(IDC_BUTTON_OPEN_DATA_FILE, &CUtility_LiteDlg::OnBnClickedButtonOpenDataFile) +END_MESSAGE_MAP() + + +// CUtility_LiteDlg message handlers + +BOOL CUtility_LiteDlg::OnInitDialog() +{ + CDialogEx::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) + { + BOOL bNameValid; + CString strAboutMenu; + bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); + ASSERT(bNameValid); + 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_BTNFont.CreatePointFont(150,L"Arial Black") ; + ((CButton*)(GetDlgItem(IDC_BUTTON_IMAGEDLL_2LASER_CALCULATE)))->SetFont(&m_BTNFont); + for (int i=0;i<4;i++) + { + TopPlaneCoeff[i]=0.0; + BottomPlaneCoeff[i]=0.0; + ReferencePlaneCoeff[i]=0.0; + } + CalibrateValue=0.0; + CalibrateTopLaserValue=0.0; + CalibrateBottomLaserValue=0.0; + dStandThickness=0.0; + CalXShiftMin=0.0; + CalXShiftMax=0.0; + CalXShiftStep=0.0; + CalYShiftMin=0.0; + CalYShiftMax=0.0; + CalYShiftStep=0.0; + TopLaserValue=0.0; + dYShiftInputVal=0.0; + dXShiftInputVal=0.0; + + InitData(); + ((CButton*)(GetDlgItem(IDC_RADIO_CALCULATE_THICKNESS)))->SetCheck(FALSE); + ((CButton*)(GetDlgItem(IDC_RADIO_CALCULATE_XYSHIFT)))->SetCheck(TRUE); + return TRUE; // return TRUE unless you set the focus to a control +} + +void CUtility_LiteDlg::OnSysCommand(UINT nID, LPARAM lParam) +{ + if ((nID & 0xFFF0) == IDM_ABOUTBOX) + { + CAboutDlg dlgAbout; + dlgAbout.DoModal(); + } + else + { + CDialogEx::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 CUtility_LiteDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(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 + { + CDialogEx::OnPaint(); + } +} + +// The system calls this function to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CUtility_LiteDlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + + +//=================================================================== +void CUtility_LiteDlg::OnBnClickedButtonImagedll2laserCalculate() +{ + if(((CButton *)GetDlgItem(IDC_RADIO_CALCULATE_THICKNESS))->GetCheck()) + { + CalculatePNT2Plane(); + } + else if(((CButton *)GetDlgItem(IDC_RADIO_CALCULATE_XYSHIFT_fORMULA))->GetCheck()) + { + CalculateXYSHIFT_METHOD2(); + } + else if(((CButton *)GetDlgItem(IDC_RADIO_CALCULATE_XYSHIFT_fORMULA2))->GetCheck()) + { + CalculateXYSHIFT_METHOD3(); + } + else if(((CButton *)GetDlgItem(IDC_RADIO_CALCULATE_XYSHIFT_RESULT))->GetCheck()) + { + CalculateXYSHIFT_Result(); + } + else + { + g_Report.clear(); + CalculateXYSHIFT(); + } + +} + +//=================================================================== +void CUtility_LiteDlg::CalculatePNT2Plane() +{ + GetPNTSData(); + ThreePntsConstructPlane(ReferencePlanePnts,ReferencePlaneCoeff); + ThreePntsConstructPlane(TopSurfacePnts,TopPlaneCoeff); + ThreePntsConstructPlane(BottomSurfacePnts,BottomPlaneCoeff); + /**************************************************************** + Result + *****************************************************************/ + m_OutMessage=_T("===========================Thickness========================"); + OutputWithScroll(m_OutMessage,m_edMSG); + double Top2ReferenceDis[4]={0.0}; + double Bottom2ReferenceDis[4]={0.0}; + double dAnswer(0.0); + CString csOutput; + //==================Top - Reference================================ + Top2ReferenceDis[0]=PointToPlaneDistance(TopSurfacePnts[0],ReferencePlaneCoeff); + Top2ReferenceDis[1]=PointToPlaneDistance(TopSurfacePnts[1],ReferencePlaneCoeff); + Top2ReferenceDis[2]=PointToPlaneDistance(TopSurfacePnts[2],ReferencePlaneCoeff); + Top2ReferenceDis[3]=(Top2ReferenceDis[0]+Top2ReferenceDis[1]+Top2ReferenceDis[2])/3.0; + + + csOutput.Format(_T("%.4g"),Top2ReferenceDis[0]); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE)))->SetWindowText(csOutput); + csOutput.Format(_T("%.4g"),Top2ReferenceDis[1]); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE2)))->SetWindowText(csOutput); + csOutput.Format(_T("%.4g"),Top2ReferenceDis[2]); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE3)))->SetWindowText(csOutput); + csOutput.Format(_T("%.4g"),Top2ReferenceDis[3]); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE4)))->SetWindowText(csOutput); + + + Bottom2ReferenceDis[0]=PointToPlaneDistance(BottomSurfacePnts[0],ReferencePlaneCoeff); + Bottom2ReferenceDis[1]=PointToPlaneDistance(BottomSurfacePnts[1],ReferencePlaneCoeff); + Bottom2ReferenceDis[2]=PointToPlaneDistance(BottomSurfacePnts[2],ReferencePlaneCoeff); + Bottom2ReferenceDis[3]=(Bottom2ReferenceDis[0]+Bottom2ReferenceDis[1]+Bottom2ReferenceDis[2])/3.0; + dAnswer=Top2ReferenceDis[3]-Bottom2ReferenceDis[3]; + + csOutput.Format(_T("%.4g"),Bottom2ReferenceDis[0]); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE5)))->SetWindowText(csOutput); + csOutput.Format(_T("%.4g"),Bottom2ReferenceDis[1]); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE6)))->SetWindowText(csOutput); + csOutput.Format(_T("%.4g"),Bottom2ReferenceDis[2]); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE7)))->SetWindowText(csOutput); + csOutput.Format(_T("%.4g"),Bottom2ReferenceDis[3]); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE8)))->SetWindowText(csOutput); + csOutput.Format(_T("%.4g"),dAnswer); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE9)))->SetWindowText(csOutput); + UpdateData(FALSE); + +} +//=================================================================== +//´úÈë·¨ +void CUtility_LiteDlg::CalculateXYSHIFT() +{ + GetPNTSData(); + ThreePntsConstructPlane(TopSurfacePnts,TopPlaneCoeff); + ThreePntsConstructPlane(BottomSurfacePnts,BottomPlaneCoeff); + + /**************************************************************** + Result + *****************************************************************/ + m_OutMessage=_T("============================XYShift========================="); + OutputWithScroll(m_OutMessage,m_edMSG); + + double Top2BottomDis[4]={0.0}; + double Bottom2ReferenceDis[4]={0.0}; + double dXShiftCalVal(CalXShiftMin),dYShiftCalVal(CalYShiftMin); + CalShiftReport TmpReport,TmpMinErrRpt; + int MinErrX(0),MinErrY(0); + CString csOutput; + Struct_3DPoint CalPNTs[3]; + CalPNTs[0]=TopSurfacePnts[0]; + CalPNTs[1]=TopSurfacePnts[1]; + CalPNTs[2]=TopSurfacePnts[2]; + + int m_Xsteps=static_cast((CalXShiftMax-CalXShiftMin)/CalXShiftStep); + int m_Ysteps=static_cast((CalYShiftMax-CalYShiftMin)/CalYShiftStep); + + //==================Dis================================ + for (int i=0;i1) + { +#ifdef _DEBUG + m_OutMessage=_T("---------------------------Err<0.005u-----------------------"); + OutputWithScroll(m_OutMessage,m_edMSG); +#endif + TmpMinErrRpt=g_Report.at(0); + for(size_t i=0;iSetWindowText(csOutput); + csOutput.Format(_T("%.4g"),TmpMinErrRpt.YShift); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_YSHIFT)))->SetWindowText(csOutput); + csOutput.Format(_T("%.4g"),TmpMinErrRpt.DisAverage); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_RESULT)))->SetWindowText(csOutput); + } + else + { + m_OutMessage=_T("Error: no data."); + OutputWithScroll(m_OutMessage,m_edMSG); + } + UpdateData(FALSE); + +} +//=================================================================== +//¼ÆËã·¨ µÃµ½µÄ½á¹ûΪµãµ½ÃæÆ½¾ù +void CUtility_LiteDlg::CalculateXYSHIFT_METHOD2() +{ + GetPNTSData(); + ThreePntsConstructPlane(TopSurfacePnts,TopPlaneCoeff); + ThreePntsConstructPlane(BottomSurfacePnts,BottomPlaneCoeff); + + /**************************************************************** + Result + *****************************************************************/ + m_OutMessage=_T("========================XYShift Formula====================="); + OutputWithScroll(m_OutMessage,m_edMSG); + + double HorizontalCoe[4]={0,0,1,0}; + double BOTXZLineV[3]={0.0}; + double BOTYZLineV[3]={0.0}; + double TOPXZLineV[3]={0.0}; + double TOPYZLineV[3]={0.0}; + double TOPAngle[3]={0.0}; + double BOTAngle[3]={0.0}; + + TOPXZLineV[0]=TopSurfacePnts[2].x-TopSurfacePnts[1].x; + TOPXZLineV[1]=TopSurfacePnts[2].y-TopSurfacePnts[1].y; + TOPXZLineV[2]=TopSurfacePnts[2].z-TopSurfacePnts[1].z; + + TOPYZLineV[0]=TopSurfacePnts[1].x-TopSurfacePnts[0].x; + TOPYZLineV[1]=TopSurfacePnts[1].y-TopSurfacePnts[0].y; + TOPYZLineV[2]=TopSurfacePnts[1].z-TopSurfacePnts[0].z; + + TOPAngle[0]=LineToPlaneAngle(TOPXZLineV,HorizontalCoe); + TOPAngle[1]=LineToPlaneAngle(TOPYZLineV,HorizontalCoe); + TOPAngle[2]=DoublePlaneAngle(TopPlaneCoeff,HorizontalCoe); + m_OutMessage.Format(_T("[Top Surface]X(DEG):%.6f,Y(DEG):%.6f,Plane(DEG):%.6f"),(TOPAngle[0]*180.0/M_PI),(TOPAngle[1]*180.0/M_PI),(TOPAngle[2]*180.0/M_PI)); + OutputWithScroll(m_OutMessage,m_edMSG); + + BOTXZLineV[0]=BottomSurfacePnts[2].x-BottomSurfacePnts[1].x; + BOTXZLineV[1]=BottomSurfacePnts[2].y-BottomSurfacePnts[1].y; + BOTXZLineV[2]=BottomSurfacePnts[2].z-BottomSurfacePnts[1].z; + + BOTYZLineV[0]=BottomSurfacePnts[1].x-BottomSurfacePnts[0].x; + BOTYZLineV[1]=BottomSurfacePnts[1].y-BottomSurfacePnts[0].y; + BOTYZLineV[2]=BottomSurfacePnts[1].z-BottomSurfacePnts[0].z; + + BOTAngle[0]=LineToPlaneAngle(BOTXZLineV,HorizontalCoe); + BOTAngle[1]=LineToPlaneAngle(BOTYZLineV,HorizontalCoe); + BOTAngle[2]=DoublePlaneAngle(HorizontalCoe,BottomPlaneCoeff); + m_OutMessage.Format(_T("[Bot Surface]X(DEG):%.6f,Y(DEG):%.6f,Plane(DEG):%.6f"),(BOTAngle[0]*180.0/M_PI),(BOTAngle[1]*180.0/M_PI),(BOTAngle[2]*180.0/M_PI)); + OutputWithScroll(m_OutMessage,m_edMSG); + + /*************************************************************** + result + ****************************************************************/ + double Top2BottomDis[4]={0.0}; + double dXYShift[4]={0.0}; + double dXShiftCalVal(0.0),dYShiftCalVal(0.0); + double ShiftAver[4]={0.0}; + Top2BottomDis[0]=TopSurfacePnts[0].z-BottomSurfacePnts[0].z; + Top2BottomDis[1]=TopSurfacePnts[1].z-BottomSurfacePnts[1].z; + Top2BottomDis[2]=TopSurfacePnts[2].z-BottomSurfacePnts[2].z; + Top2BottomDis[3]=(Top2BottomDis[0]+Top2BottomDis[1]+Top2BottomDis[2])/3.0; + //=====================================X============================================== + int i=0; + dXYShift[0]=(dStandThickness-(Top2BottomDis[0]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + dXYShift[1]=(dStandThickness-(Top2BottomDis[1]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + dXYShift[2]=(dStandThickness-(Top2BottomDis[2]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + dXYShift[3]=(dStandThickness-(Top2BottomDis[3]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + ShiftAver[0]=dXYShift[3]; + m_OutMessage.Format(_T("[Top Surface]Delta X1:%.6f,Delta X2:%.6f,Delta X3:%.6f,Average:%.6f"),dXYShift[0],dXYShift[1],dXYShift[2],dXYShift[3]); + OutputWithScroll(m_OutMessage,m_edMSG); + i=1; + dXYShift[0]=(dStandThickness-(Top2BottomDis[0]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + dXYShift[1]=(dStandThickness-(Top2BottomDis[1]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + dXYShift[2]=(dStandThickness-(Top2BottomDis[2]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + dXYShift[3]=(dStandThickness-(Top2BottomDis[3]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + ShiftAver[1]=dXYShift[3]; + m_OutMessage.Format(_T("[Top Surface]Delta Y1:%.6f,Delta Y2:%.6f,Delta Y3:%.6f,Average:%.6f"),dXYShift[0],dXYShift[1],dXYShift[2],dXYShift[3]); + OutputWithScroll(m_OutMessage,m_edMSG); + //=====================================Y============================================== + i=0; + dXYShift[0]=(dStandThickness-(Top2BottomDis[0]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + dXYShift[1]=(dStandThickness-(Top2BottomDis[1]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + dXYShift[2]=(dStandThickness-(Top2BottomDis[2]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + dXYShift[3]=(dStandThickness-(Top2BottomDis[3]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + ShiftAver[2]=dXYShift[3]; + m_OutMessage.Format(_T("[Bot Surface]Delta X1:%.6f,Delta X2:%.6f,Delta X3:%.6f,Average:%.6f"),dXYShift[0],dXYShift[1],dXYShift[2],dXYShift[3]); + OutputWithScroll(m_OutMessage,m_edMSG); + i=1; + dXYShift[0]=(dStandThickness-(Top2BottomDis[0]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + dXYShift[1]=(dStandThickness-(Top2BottomDis[1]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + dXYShift[2]=(dStandThickness-(Top2BottomDis[2]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + dXYShift[3]=(dStandThickness-(Top2BottomDis[3]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + ShiftAver[3]=dXYShift[3]; + m_OutMessage.Format(_T("[Bot Surface]Delta Y1:%.6f,Delta Y2:%.6f,Delta Y3:%.6f,Average:%.6f"),dXYShift[0],dXYShift[1],dXYShift[2],dXYShift[3]); + OutputWithScroll(m_OutMessage,m_edMSG); + dXShiftCalVal=0.5*(ShiftAver[0]+ShiftAver[2]); + dYShiftCalVal=0.5*(ShiftAver[1]+ShiftAver[3]); + m_OutMessage.Format(_T("[Average Result]Delta X:%.6f,Delta Y:%.6f"),dXShiftCalVal,dYShiftCalVal); + OutputWithScroll(m_OutMessage,m_edMSG); + + Struct_3DPoint CalPNTs[3]; + CalPNTs[0]=TopSurfacePnts[0]; + CalPNTs[1]=TopSurfacePnts[1]; + CalPNTs[2]=TopSurfacePnts[2]; + CalPNTs[0].x=TopSurfacePnts[0].x+dXShiftCalVal; + CalPNTs[1].x=TopSurfacePnts[1].x+dXShiftCalVal; + CalPNTs[2].x=TopSurfacePnts[2].x+dXShiftCalVal; + + CalPNTs[0].y=TopSurfacePnts[0].y+dYShiftCalVal; + CalPNTs[1].y=TopSurfacePnts[1].y+dYShiftCalVal; + CalPNTs[2].y=TopSurfacePnts[2].y+dYShiftCalVal; + + Top2BottomDis[0]=PointToPlaneDistance(CalPNTs[0],BottomPlaneCoeff); + Top2BottomDis[1]=PointToPlaneDistance(CalPNTs[1],BottomPlaneCoeff); + Top2BottomDis[2]=PointToPlaneDistance(CalPNTs[2],BottomPlaneCoeff); + Top2BottomDis[3]=(Top2BottomDis[0]+Top2BottomDis[1]+Top2BottomDis[2])/3.0; + + CString csOutput; + + csOutput.Format(_T("%.4g"),0.5*(ShiftAver[0]+ShiftAver[2])); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_XSHIFT)))->SetWindowText(csOutput); + csOutput.Format(_T("%.4g"),0.5*(ShiftAver[1]+ShiftAver[3])); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_YSHIFT)))->SetWindowText(csOutput); + csOutput.Format(_T("%.4g"),Top2BottomDis[3]); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_RESULT)))->SetWindowText(csOutput); + + + UpdateData(FALSE); + +} + +//=================================================================== +//¼ÆËã·¨ µÃµ½µÄ½á¹ûΪµãµ½ÃæµÄ¾àÀë¼Ó£¨¼õ£©Æ«ÒƵÄÎó²î +void CUtility_LiteDlg::CalculateXYSHIFT_METHOD3() +{ + GetPNTSData(); + ThreePntsConstructPlane(TopSurfacePnts,TopPlaneCoeff); + ThreePntsConstructPlane(BottomSurfacePnts,BottomPlaneCoeff); + /**************************************************************** + Result + *****************************************************************/ + m_OutMessage=_T("========================XYShift Formula2===================="); + OutputWithScroll(m_OutMessage,m_edMSG); + + + double HorizontalCoe[4]={0,0,1,0}; + double BOTXZLineV[3]={0.0}; + double BOTYZLineV[3]={0.0}; + double TOPXZLineV[3]={0.0}; + double TOPYZLineV[3]={0.0}; + double TOPAngle[3]={0.0}; + double BOTAngle[3]={0.0}; + + TOPXZLineV[0]=TopSurfacePnts[2].x-TopSurfacePnts[1].x; + TOPXZLineV[1]=TopSurfacePnts[2].y-TopSurfacePnts[1].y; + TOPXZLineV[2]=TopSurfacePnts[2].z-TopSurfacePnts[1].z; + + TOPYZLineV[0]=TopSurfacePnts[1].x-TopSurfacePnts[0].x; + TOPYZLineV[1]=TopSurfacePnts[1].y-TopSurfacePnts[0].y; + TOPYZLineV[2]=TopSurfacePnts[1].z-TopSurfacePnts[0].z; + + TOPAngle[0]=LineToPlaneAngle(TOPXZLineV,HorizontalCoe); + TOPAngle[1]=LineToPlaneAngle(TOPYZLineV,HorizontalCoe); + TOPAngle[2]=DoublePlaneAngle(TopPlaneCoeff,HorizontalCoe); + m_OutMessage.Format(_T("[Top Surface]X(DEG):%.6f,Y(DEG):%.6f,Plane(DEG):%.6f"),(TOPAngle[0]*180.0/M_PI),(TOPAngle[1]*180.0/M_PI),(TOPAngle[2]*180.0/M_PI)); + OutputWithScroll(m_OutMessage,m_edMSG); + + BOTXZLineV[0]=BottomSurfacePnts[2].x-BottomSurfacePnts[1].x; + BOTXZLineV[1]=BottomSurfacePnts[2].y-BottomSurfacePnts[1].y; + BOTXZLineV[2]=BottomSurfacePnts[2].z-BottomSurfacePnts[1].z; + + BOTYZLineV[0]=BottomSurfacePnts[1].x-BottomSurfacePnts[0].x; + BOTYZLineV[1]=BottomSurfacePnts[1].y-BottomSurfacePnts[0].y; + BOTYZLineV[2]=BottomSurfacePnts[1].z-BottomSurfacePnts[0].z; + + BOTAngle[0]=LineToPlaneAngle(BOTXZLineV,HorizontalCoe); + BOTAngle[1]=LineToPlaneAngle(BOTYZLineV,HorizontalCoe); + BOTAngle[2]=DoublePlaneAngle(HorizontalCoe,BottomPlaneCoeff); + m_OutMessage.Format(_T("[Bot Surface]X(DEG):%.6f,Y(DEG):%.6f,Plane(DEG):%.6f"),(BOTAngle[0]*180.0/M_PI),(BOTAngle[1]*180.0/M_PI),(BOTAngle[2]*180.0/M_PI)); + OutputWithScroll(m_OutMessage,m_edMSG); + + /*************************************************************** + result + ****************************************************************/ + double Top2BottomDis[4]={0.0}; + double dXYShift[4]={0.0}; + double dXShiftCalVal(0.0),dYShiftCalVal(0.0); + double ShiftAver[4]={0.0}; + Top2BottomDis[0]=TopSurfacePnts[0].z-BottomSurfacePnts[0].z; + Top2BottomDis[1]=TopSurfacePnts[1].z-BottomSurfacePnts[1].z; + Top2BottomDis[2]=TopSurfacePnts[2].z-BottomSurfacePnts[2].z; + Top2BottomDis[3]=(Top2BottomDis[0]+Top2BottomDis[1]+Top2BottomDis[2])/3.0; + + //=====================================X============================================== + int i=0; + dXYShift[0]=(dStandThickness-(Top2BottomDis[0]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + dXYShift[1]=(dStandThickness-(Top2BottomDis[1]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + dXYShift[2]=(dStandThickness-(Top2BottomDis[2]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + dXYShift[3]=(dStandThickness-(Top2BottomDis[3]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + ShiftAver[0]=dXYShift[3]; + m_OutMessage.Format(_T("[Top Surface]Delta X1:%.6f,Delta X2:%.6f,Delta X3:%.6f,Average:%.6f"),dXYShift[0],dXYShift[1],dXYShift[2],dXYShift[3]); + OutputWithScroll(m_OutMessage,m_edMSG); + i=1; + dXYShift[0]=(dStandThickness-(Top2BottomDis[0]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + dXYShift[1]=(dStandThickness-(Top2BottomDis[1]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + dXYShift[2]=(dStandThickness-(Top2BottomDis[2]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + dXYShift[3]=(dStandThickness-(Top2BottomDis[3]*(cos(TOPAngle[i]))))/(sin(TOPAngle[i])); + ShiftAver[1]=dXYShift[3]; + m_OutMessage.Format(_T("[Top Surface]Delta Y1:%.6f,Delta Y2:%.6f,Delta Y3:%.6f,Average:%.6f"),dXYShift[0],dXYShift[1],dXYShift[2],dXYShift[3]); + OutputWithScroll(m_OutMessage,m_edMSG); + //=====================================Y============================================== + i=0; + dXYShift[0]=(dStandThickness-(Top2BottomDis[0]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + dXYShift[1]=(dStandThickness-(Top2BottomDis[1]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + dXYShift[2]=(dStandThickness-(Top2BottomDis[2]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + dXYShift[3]=(dStandThickness-(Top2BottomDis[3]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + ShiftAver[2]=dXYShift[3]; + m_OutMessage.Format(_T("[Bot Surface]Delta X1:%.6f,Delta X2:%.6f,Delta X3:%.6f,Average:%.6f"),dXYShift[0],dXYShift[1],dXYShift[2],dXYShift[3]); + OutputWithScroll(m_OutMessage,m_edMSG); + i=1; + dXYShift[0]=(dStandThickness-(Top2BottomDis[0]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + dXYShift[1]=(dStandThickness-(Top2BottomDis[1]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + dXYShift[2]=(dStandThickness-(Top2BottomDis[2]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + dXYShift[3]=(dStandThickness-(Top2BottomDis[3]*(cos(BOTAngle[i]))))/(sin(BOTAngle[i])); + ShiftAver[3]=dXYShift[3]; + m_OutMessage.Format(_T("[Bot Surface]Delta Y1:%.6f,Delta Y2:%.6f,Delta Y3:%.6f,Average:%.6f"),dXYShift[0],dXYShift[1],dXYShift[2],dXYShift[3]); + OutputWithScroll(m_OutMessage,m_edMSG); + dXShiftCalVal=0.5*(ShiftAver[0]+ShiftAver[2]); + dYShiftCalVal=0.5*(ShiftAver[1]+ShiftAver[3]); + m_OutMessage.Format(_T("[Average Result]Delta X:%.6f,Delta Y:%.6f"),dXShiftCalVal,dYShiftCalVal); + OutputWithScroll(m_OutMessage,m_edMSG); + + Struct_3DPoint CalPNTs[3]; + CalPNTs[0]=TopSurfacePnts[0]; + CalPNTs[1]=TopSurfacePnts[1]; + CalPNTs[2]=TopSurfacePnts[2]; + CalPNTs[0].x=TopSurfacePnts[0].x+dXShiftCalVal; + CalPNTs[1].x=TopSurfacePnts[1].x+dXShiftCalVal; + CalPNTs[2].x=TopSurfacePnts[2].x+dXShiftCalVal; + + CalPNTs[0].y=TopSurfacePnts[0].y+dYShiftCalVal; + CalPNTs[1].y=TopSurfacePnts[1].y+dYShiftCalVal; + CalPNTs[2].y=TopSurfacePnts[2].y+dYShiftCalVal; + ThreePntsConstructPlane(CalPNTs,TopPlaneCoeff); + double m_ShiftedTopAngle=DoublePlaneAngle(TopPlaneCoeff,HorizontalCoe); + double m_Result(0.0); + + Top2BottomDis[0]=PointToPlaneDistance(TopSurfacePnts[0],BottomPlaneCoeff); + Top2BottomDis[1]=PointToPlaneDistance(TopSurfacePnts[1],BottomPlaneCoeff); + Top2BottomDis[2]=PointToPlaneDistance(TopSurfacePnts[2],BottomPlaneCoeff); + Top2BottomDis[3]=(Top2BottomDis[0]+Top2BottomDis[1]+Top2BottomDis[2])/3.0; + if (m_ShiftedTopAngle>M_PI_2) + { + m_Result=Top2BottomDis[3]+sqrt(dXShiftCalVal*dXShiftCalVal+dYShiftCalVal*dYShiftCalVal)*sin(m_ShiftedTopAngle); + m_OutMessage.Format(_T("[Result]%.6f(Thickness)=%.6f(Thick Before calibrate)+%.6f(Delta XY)"),m_Result,Top2BottomDis[3],(sqrt(dXShiftCalVal*dXShiftCalVal+dYShiftCalVal*dYShiftCalVal)*sin(m_ShiftedTopAngle))); + OutputWithScroll(m_OutMessage,m_edMSG); + } + else + { + m_Result=Top2BottomDis[3]-sqrt(dXShiftCalVal*dXShiftCalVal+dYShiftCalVal*dYShiftCalVal)*sin(m_ShiftedTopAngle); + m_OutMessage.Format(_T("[Result]%.6f(Thickness)=%.6f(Thick Before calibrate)-%.6f(Delta XY)"),m_Result,Top2BottomDis[3],(sqrt(dXShiftCalVal*dXShiftCalVal+dYShiftCalVal*dYShiftCalVal)*sin(m_ShiftedTopAngle))); + OutputWithScroll(m_OutMessage,m_edMSG); + } + + + CString csOutput; + + csOutput.Format(_T("%.4g"),0.5*(ShiftAver[0]+ShiftAver[2])); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_XSHIFT)))->SetWindowText(csOutput); + csOutput.Format(_T("%.4g"),0.5*(ShiftAver[1]+ShiftAver[3])); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_YSHIFT)))->SetWindowText(csOutput); + csOutput.Format(_T("%.4g"),m_Result); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_RESULT)))->SetWindowText(csOutput); + + + UpdateData(FALSE); + +} +//¸ù¾ÝXYÆ«ÒÆ¼ÆËã²âÁ¿Öµ +void CUtility_LiteDlg::CalculateXYSHIFT_Result() +{ + GetPNTSData(); + ThreePntsConstructPlane(TopSurfacePnts,TopPlaneCoeff); + ThreePntsConstructPlane(BottomSurfacePnts,BottomPlaneCoeff); + /**************************************************************** + Result + *****************************************************************/ + m_OutMessage=_T("========================XYShift Result===================="); + OutputWithScroll(m_OutMessage,m_edMSG); + double HorizontalCoe[4]={0,0,1,0}; + double Top2BottomDis[4]={0.0}; + Struct_3DPoint CalPNTs[3]; + CalPNTs[0]=TopSurfacePnts[0]; + CalPNTs[1]=TopSurfacePnts[1]; + CalPNTs[2]=TopSurfacePnts[2]; + CalPNTs[0].x=TopSurfacePnts[0].x+dXShiftInputVal; + CalPNTs[1].x=TopSurfacePnts[1].x+dXShiftInputVal; + CalPNTs[2].x=TopSurfacePnts[2].x+dXShiftInputVal; + + CalPNTs[0].y=TopSurfacePnts[0].y+dYShiftInputVal; + CalPNTs[1].y=TopSurfacePnts[1].y+dYShiftInputVal; + CalPNTs[2].y=TopSurfacePnts[2].y+dYShiftInputVal; + ThreePntsConstructPlane(CalPNTs,TopPlaneCoeff); + double m_ShiftedTopAngle=DoublePlaneAngle(TopPlaneCoeff,HorizontalCoe); + double m_Result(0.0); + + Top2BottomDis[0]=PointToPlaneDistance(TopSurfacePnts[0],BottomPlaneCoeff); + Top2BottomDis[1]=PointToPlaneDistance(TopSurfacePnts[1],BottomPlaneCoeff); + Top2BottomDis[2]=PointToPlaneDistance(TopSurfacePnts[2],BottomPlaneCoeff); + Top2BottomDis[3]=(Top2BottomDis[0]+Top2BottomDis[1]+Top2BottomDis[2])/3.0; + if (m_ShiftedTopAngle>M_PI_2) + { + m_Result=Top2BottomDis[3]+sqrt(dXShiftInputVal*dXShiftInputVal+dYShiftInputVal*dYShiftInputVal)*sin(m_ShiftedTopAngle); + m_OutMessage.Format(_T("[Result]%.6f(Thickness)=%.6f(Thick Before calibrate)+%.6f(Delta XY)"),m_Result,Top2BottomDis[3],(sqrt(dXShiftInputVal*dXShiftInputVal+dYShiftInputVal*dYShiftInputVal)*sin(m_ShiftedTopAngle))); + OutputWithScroll(m_OutMessage,m_edMSG); + } + else + { + m_Result=Top2BottomDis[3]-sqrt(dXShiftInputVal*dXShiftInputVal+dYShiftInputVal*dYShiftInputVal)*sin(m_ShiftedTopAngle); + m_OutMessage.Format(_T("[Result]%.6f(Thickness)=%.6f(Thick Before calibrate)-%.6f(Delta XY)"),m_Result,Top2BottomDis[3],(sqrt(dXShiftInputVal*dXShiftInputVal+dYShiftInputVal*dYShiftInputVal)*sin(m_ShiftedTopAngle))); + OutputWithScroll(m_OutMessage,m_edMSG); + } + + CString csOutput; + + csOutput.Format(_T("%.4g"),m_Result); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_RESULT)))->SetWindowText(csOutput); + + + UpdateData(FALSE); + +} + + + +//=================================================================== +BOOL CUtility_LiteDlg::ThreePntsConstructPlane(Struct_3DPoint* pArr,double* Coe) +{ + Struct_3DPoint p1,p2,p3; + + p1 = pArr[0]; + p2 = pArr[1]; + p3 = pArr[2]; + double a(0.0),b(0.0),c(0.0),d(0.0); + a = ( (p2.y-p1.y)*(p3.z-p1.z)-(p2.z-p1.z)*(p3.y-p1.y) ); + b = ( (p2.z-p1.z)*(p3.x-p1.x)-(p2.x-p1.x)*(p3.z-p1.z) ); + c = ( (p2.x-p1.x)*(p3.y-p1.y)-(p2.y-p1.y)*(p3.x-p1.x) ); + d = ( 0-(a*p1.x+b*p1.y+c*p1.z) ); + Coe[0]=a; + Coe[1]=b; + Coe[2]=c; + Coe[3]=d; + + return TRUE; +}; +//=================================================================== +double CUtility_LiteDlg::PointToPlaneDistance(Struct_3DPoint PntPos,double* Coe) +{ + double m_result(0.0); + double a(0.0),b(0.0),c(0.0),d(0.0); + a=Coe[0]; + b=Coe[1]; + c=Coe[2]; + d=Coe[3]; + double x(0.0),y(0.0),z(0.0); + x=PntPos.x; + y=PntPos.y; + z=PntPos.z; + m_result=fabs((a*x+b*y+c*z+d) / sqrt(a*a+b*b+c*c)); + return m_result; +}; +//=================================================================== +double CUtility_LiteDlg::DoublePlaneAngle(double* Coe1,double* Coe2) +{ + double m_result(0.0); + double a1(0.0),b1(0.0),c1(0.0),d1(0.0); + double a2(0.0),b2(0.0),c2(0.0),d2(0.0); + a1=Coe1[0]; + b1=Coe1[1]; + c1=Coe1[2]; + d1=Coe1[3]; + + a2=Coe2[0]; + b2=Coe2[1]; + c2=Coe2[2]; + d2=Coe2[3]; + + m_result=acos((fabs(a1*a2+b1*b2+c1*c2)) / ((sqrt(a1*a1+b1*b1+c1*c1))*(sqrt(a2*a2+b2*b2+c2*c2)))); + return m_result; +}; +//=================================================================== +double CUtility_LiteDlg::LineToPlaneAngle(double* LineVector,double* Coe) +{ + double m_result(0.0); + double m(0.0),n(0.0),p(0.0); + m=LineVector[0]; + n=LineVector[1]; + p=LineVector[2]; + + double a(0.0),b(0.0),c(0.0),d(0.0); + a=Coe[0]; + b=Coe[1]; + c=Coe[2]; + d=Coe[3]; + + m_result=asin((fabs(a*m+b*n+c*p)) / ((sqrt(a*a+b*b+c*c))*(sqrt(m*m+n*n+p*p)))); + return m_result; +}; + +//===================================================================================== +//Print message on edit control +void CUtility_LiteDlg::OutputWithScroll(const CString &strNewText,CEdit &edtOutput) +{ + CString strOutput; + edtOutput.GetWindowText(strOutput); + strOutput += strNewText; + if ("\r\n" != strOutput.Right(2)) + { + strOutput += "\r\n"; + } + + int iCount = strOutput.GetLength(); + + edtOutput.SetRedraw(FALSE); + edtOutput.SetWindowText(strOutput); + int iLine = edtOutput.GetLineCount(); + edtOutput.LineScroll(iLine, 0); + edtOutput.SetSel(iCount, iCount); + edtOutput.SetRedraw(TRUE); +} + +//===================================================================================== +void CUtility_LiteDlg::OnBnClickedButtonSaveAllMsg() +{ + USES_CONVERSION; + + CString FileName; + CString PathName; + + + FileName=_T("Cal_Result.csv"); + CString szFilter=_T("CSV Files(*.csv)|*.csv|TXT Files(*.txt)|*.txt|ALL Files(*.*)|*.*||"); + CFileDialog fdlg(FALSE,_T("TEXT"),FileName,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter); + + if( fdlg.DoModal()==IDOK) + { + PathName=fdlg.GetPathName(); + switch(fdlg.m_ofn.nFilterIndex) + { + case 2: + { + FILE* m_pOutFile; + _wfopen_s(&m_pOutFile, PathName, _T("wt")); + if (!m_pOutFile) + { + MessageBox( _T("File name Error."), _T("Message"), MB_OK); + } + else + { + const char* outBuff=NULL; + CString strOutput; + m_edMSG.GetWindowText(strOutput); + outBuff=T2A(strOutput); + fprintf(m_pOutFile,"%s", outBuff); + fclose(m_pOutFile); + m_OutMessage=_T("[Saving successful] Data Stored into ")+PathName+_T("."); + OutputWithScroll(m_OutMessage,m_edMSG); + } + break; + } + case 1: + { + BOOL bSTATUS=ExportReportCSV(PathName); + if (bSTATUS) + { + m_OutMessage=_T("[Saving successful] Data Stored into ")+PathName+_T("."); + OutputWithScroll(m_OutMessage,m_edMSG); + } + else + { + MessageBox( _T("File name Error."), _T("Message"), MB_OK); + } + break; + } + } + } + delete fdlg; +} + +//=========================================================== +BOOL CUtility_LiteDlg::ExportReportCSV(const CString &FilePathName) +{ + FILE* m_pOutFile=NULL; + char *outBuff = NULL; + _wfopen_s(&m_pOutFile, FilePathName, _T("wt")); + if (!m_pOutFile) + { + free(outBuff); + return FALSE; + } + else + { + //Title + + fprintf(m_pOutFile,"XShift,YShift,Dis1,Dis2,Dis3,DisAverage,Standard Value,Standard Deviation,ABS(Standard Deviation),"); + fprintf(m_pOutFile, "\n"); + + //OUTPUT DATA + CalShiftReport TmpReport; + for(size_t i=0;iSetWindowText(_T("-0.2")); + ((CButton*)(GetDlgItem(IDC_EDIT_CALSHIFT_X_MAX)))->SetWindowText(_T("0.2")); + ((CButton*)(GetDlgItem(IDC_EDIT_CALSHIFT_X_STEP)))->SetWindowText(_T("0.001")); + ((CButton*)(GetDlgItem(IDC_EDIT_CALSHIFT_YMIN)))->SetWindowText(_T("-0.2")); + ((CButton*)(GetDlgItem(IDC_EDIT_CALSHIFT_YMAX)))->SetWindowText(_T("0.2")); + ((CButton*)(GetDlgItem(IDC_EDIT_CALSHIFT_YSTEP)))->SetWindowText(_T("0.001")); + //==================Calibrate Value=============================== + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ_CALIBRATE)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ__CALIBRATE)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_STANDARD_VALUE)))->SetWindowText(cStr); + //==================Standard thickness=========================== + ((CButton*)(GetDlgItem(IDC_EDIT_STANDARD_THICKNESS)))->SetWindowText(cStr); + + //=====================Reference Surface================================== + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X1)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y1)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ1)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X2)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y2)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ2)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X3)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y3)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ3)))->SetWindowText(cStr); + //=====================Top Surface================================== + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X4)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y4)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ4)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X5)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y5)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ5)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X6)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y6)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ6)))->SetWindowText(cStr); + //====================Bottom Surface================================ + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X7)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y7)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ1)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X8)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y8)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ2)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X9)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y9)))->SetWindowText(cStr); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ3)))->SetWindowText(cStr); +} + +//=================================================== +void CUtility_LiteDlg::UpdateDisplayPNTSData() +{ + CString csTmp; + csTmp.Format(_T("%.4f"),m_TopSurfacePNTs[0].x); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X4)))->SetWindowText(csTmp); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X7)))->SetWindowText(csTmp); + csTmp.Format(_T("%.4f"),m_TopSurfacePNTs[0].y); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y4)))->SetWindowText(csTmp); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y7)))->SetWindowText(csTmp); + csTmp.Format(_T("%.4f"),m_TopSurfacePNTs[0].z); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ4)))->SetWindowText(csTmp); + csTmp.Format(_T("%.4f"),m_BottomSurfacePNTs[0].z); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ1)))->SetWindowText(csTmp); + + csTmp.Format(_T("%.4f"),m_TopSurfacePNTs[1].x); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X5)))->SetWindowText(csTmp); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X8)))->SetWindowText(csTmp); + csTmp.Format(_T("%.4f"),m_TopSurfacePNTs[1].y); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y5)))->SetWindowText(csTmp);; + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y8)))->SetWindowText(csTmp); + csTmp.Format(_T("%.4f"),m_TopSurfacePNTs[1].z); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ5)))->SetWindowText(csTmp); + csTmp.Format(_T("%.4f"),m_BottomSurfacePNTs[1].z); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ2)))->SetWindowText(csTmp); + + csTmp.Format(_T("%.4f"),m_TopSurfacePNTs[2].x); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X6)))->SetWindowText(csTmp); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X9)))->SetWindowText(csTmp); + csTmp.Format(_T("%.4f"),m_TopSurfacePNTs[2].y); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y6)))->SetWindowText(csTmp); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y9)))->SetWindowText(csTmp); + csTmp.Format(_T("%.4f"),m_TopSurfacePNTs[2].z); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ6)))->SetWindowText(csTmp); + csTmp.Format(_T("%.4f"),m_BottomSurfacePNTs[2].z); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ3)))->SetWindowText(csTmp); + + csTmp.Format(_T("%.4f"),CalibrateTopLaserValue); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ_CALIBRATE)))->SetWindowText(csTmp); + csTmp.Format(_T("%.4f"),CalibrateBottomLaserValue); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ__CALIBRATE)))->SetWindowText(csTmp); + csTmp.Format(_T("%.4f"),CalibrateValue); + ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_STANDARD_VALUE)))->SetWindowText(csTmp); + csTmp.Format(_T("%.4f"),dStandThickness); + ((CButton*)(GetDlgItem(IDC_EDIT_STANDARD_THICKNESS)))->SetWindowText(csTmp); + + + +} +//=================================================== +void CUtility_LiteDlg::GetPNTSData() +{ + CString str; + UpdateData(TRUE); + USES_CONVERSION; + //=====================XYShift Value=================================== + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_XSHIFT)->GetWindowText(str); + const char* cTempValue=T2A(str); + dXShiftInputVal=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_YSHIFT)->GetWindowText(str); + cTempValue=T2A(str); + dYShiftInputVal=atof(cTempValue); + //==================Standard thickness=========================== + GetDlgItem(IDC_EDIT_STANDARD_THICKNESS)->GetWindowText(str); + cTempValue=T2A(str); + dStandThickness=atof(cTempValue); + //==================Cal Value=============================== + GetDlgItem(IDC_EDIT_CALSHIFT_X_MIN)->GetWindowText(str); + cTempValue=T2A(str); + CalXShiftMin=atof(cTempValue); + GetDlgItem(IDC_EDIT_CALSHIFT_X_MAX)->GetWindowText(str); + cTempValue=T2A(str); + CalXShiftMax=atof(cTempValue); + GetDlgItem(IDC_EDIT_CALSHIFT_X_STEP)->GetWindowText(str); + cTempValue=T2A(str); + CalXShiftStep=atof(cTempValue); + GetDlgItem(IDC_EDIT_CALSHIFT_YMIN)->GetWindowText(str); + cTempValue=T2A(str); + CalYShiftMin=atof(cTempValue); + GetDlgItem(IDC_EDIT_CALSHIFT_YMAX)->GetWindowText(str); + cTempValue=T2A(str); + CalYShiftMax=atof(cTempValue); + GetDlgItem(IDC_EDIT_CALSHIFT_YSTEP)->GetWindowText(str); + cTempValue=T2A(str); + CalYShiftStep=atof(cTempValue); + + //==================Calibrate Value=============================== + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ_CALIBRATE)->GetWindowText(str); + cTempValue=T2A(str); + CalibrateTopLaserValue=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ__CALIBRATE)->GetWindowText(str); + cTempValue=T2A(str); + CalibrateBottomLaserValue=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_STANDARD_VALUE)->GetWindowText(str); + cTempValue=T2A(str); + CalibrateValue=atof(cTempValue); + //==================Reference Surface=============================== + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X1)->GetWindowText(str); + cTempValue=T2A(str); + ReferencePlanePnts[0].x=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y1)->GetWindowText(str); + cTempValue=T2A(str); + ReferencePlanePnts[0].y=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ1)->GetWindowText(str); + cTempValue=T2A(str); + TopLaserValue=atof(cTempValue); + //calibrate + ReferencePlanePnts[0].z=TopLaserValue-CalibrateTopLaserValue+CalibrateValue+CalibrateBottomLaserValue; + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X2)->GetWindowText(str); + cTempValue=T2A(str); + ReferencePlanePnts[1].x=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y2)->GetWindowText(str); + cTempValue=T2A(str); + ReferencePlanePnts[1].y=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ2)->GetWindowText(str); + cTempValue=T2A(str); + TopLaserValue=atof(cTempValue); + //calibrate + ReferencePlanePnts[1].z=TopLaserValue-CalibrateTopLaserValue+CalibrateValue+CalibrateBottomLaserValue; + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X3)->GetWindowText(str); + cTempValue=T2A(str); + ReferencePlanePnts[2].x=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y3)->GetWindowText(str); + cTempValue=T2A(str); + ReferencePlanePnts[2].y=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ3)->GetWindowText(str); + cTempValue=T2A(str); + TopLaserValue=atof(cTempValue); + //calibrate + ReferencePlanePnts[2].z=TopLaserValue-CalibrateTopLaserValue+CalibrateValue+CalibrateBottomLaserValue; + + + //=====================Top Surface================================== + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X4)->GetWindowText(str); + cTempValue=T2A(str); + TopSurfacePnts[0].x=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y4)->GetWindowText(str); + cTempValue=T2A(str); + TopSurfacePnts[0].y=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ4)->GetWindowText(str); + cTempValue=T2A(str); + TopLaserValue=atof(cTempValue); + //calibrate + TopSurfacePnts[0].z=TopLaserValue-CalibrateTopLaserValue+CalibrateValue+CalibrateBottomLaserValue; + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X5)->GetWindowText(str); + cTempValue=T2A(str); + TopSurfacePnts[1].x=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y5)->GetWindowText(str); + cTempValue=T2A(str); + TopSurfacePnts[1].y=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ5)->GetWindowText(str); + cTempValue=T2A(str); + TopLaserValue=atof(cTempValue); + //calibrate + TopSurfacePnts[1].z=TopLaserValue-CalibrateTopLaserValue+CalibrateValue+CalibrateBottomLaserValue; + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X6)->GetWindowText(str); + cTempValue=T2A(str); + TopSurfacePnts[2].x=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y6)->GetWindowText(str); + cTempValue=T2A(str); + TopSurfacePnts[2].y=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ6)->GetWindowText(str); + cTempValue=T2A(str); + TopLaserValue=atof(cTempValue); + //calibrate + TopSurfacePnts[2].z=TopLaserValue-CalibrateTopLaserValue+CalibrateValue+CalibrateBottomLaserValue; + + + //====================Bottom Surface================================ + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X7)->GetWindowText(str); + cTempValue=T2A(str); + BottomSurfacePnts[0].x=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y7)->GetWindowText(str); + cTempValue=T2A(str); + BottomSurfacePnts[0].y=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ1)->GetWindowText(str); + cTempValue=T2A(str); + BottomSurfacePnts[0].z=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X8)->GetWindowText(str); + cTempValue=T2A(str); + BottomSurfacePnts[1].x=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y8)->GetWindowText(str); + cTempValue=T2A(str); + BottomSurfacePnts[1].y=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ2)->GetWindowText(str); + cTempValue=T2A(str); + BottomSurfacePnts[1].z=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X9)->GetWindowText(str); + cTempValue=T2A(str); + BottomSurfacePnts[2].x=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y9)->GetWindowText(str); + cTempValue=T2A(str); + BottomSurfacePnts[2].y=atof(cTempValue); + GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ3)->GetWindowText(str); + cTempValue=T2A(str); + BottomSurfacePnts[2].z=atof(cTempValue); + + +}; +#pragma warning(disable:4996) +//=========================================================== +void CUtility_LiteDlg::ReadData() +{ + +}; + +void CUtility_LiteDlg::OnBnClickedButtonOpenDataFile() +{ + USES_CONVERSION; + + CString FileName; + CString PathName; + + + FileName=_T("Data.csv"); + CFileDialog fdlg(TRUE, _T("*.csv"),(LPCTSTR) FileName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("CSV files (*.csv)|*.csv|TXT files (*.txt)|*.txt||"), this); + + if( fdlg.DoModal()==IDOK) + { + PathName=fdlg.GetPathName(); + + FILE* m_pOutFile; + char szLine[MAX_BUFF_SIZE]; + char *token = NULL; + char seps[] = ","; + char cTemp[20]={0}; + _wfopen_s(&m_pOutFile, PathName, _T("rt")); + if (!m_pOutFile) + { + MessageBox( _T("File name Error."), _T("Message"), MB_OK); + } + else + { + //while (!feof(m_pOutFile)) + { + fgets(szLine,MAX_BUFF_SIZE,m_pOutFile);//forget first line + fgets(szLine,MAX_BUFF_SIZE,m_pOutFile);//read a line + token = strtok(szLine,seps); + strcpy(cTemp,token); + m_TopSurfacePNTs[0].x=atof(cTemp); + m_BottomSurfacePNTs[0].x=atof(cTemp); + + token = strtok( NULL, seps); + strcpy(cTemp,token); + m_TopSurfacePNTs[0].y=atof(cTemp); + m_BottomSurfacePNTs[0].y=atof(cTemp); + + token = strtok( NULL, seps); + strcpy(cTemp,token); + m_TopSurfacePNTs[0].z=atof(cTemp); + + token = strtok( NULL, seps); + strcpy(cTemp,token); + m_BottomSurfacePNTs[0].z=atof(cTemp); + // + token = strtok(NULL,seps); + strcpy(cTemp,token); + m_TopSurfacePNTs[1].x=atof(cTemp); + m_BottomSurfacePNTs[1].x=atof(cTemp); + + token = strtok( NULL, seps); + strcpy(cTemp,token); + m_TopSurfacePNTs[1].y=atof(cTemp); + m_BottomSurfacePNTs[1].y=atof(cTemp); + + token = strtok( NULL, seps); + strcpy(cTemp,token); + m_TopSurfacePNTs[1].z=atof(cTemp); + + token = strtok( NULL, seps); + strcpy(cTemp,token); + m_BottomSurfacePNTs[1].z=atof(cTemp); + // + token = strtok(NULL,seps); + strcpy(cTemp,token); + m_TopSurfacePNTs[2].x=atof(cTemp); + m_BottomSurfacePNTs[2].x=atof(cTemp); + + token = strtok( NULL, seps); + strcpy(cTemp,token); + m_TopSurfacePNTs[2].y=atof(cTemp); + m_BottomSurfacePNTs[2].y=atof(cTemp); + + token = strtok( NULL, seps); + strcpy(cTemp,token); + m_TopSurfacePNTs[2].z=atof(cTemp); + + token = strtok( NULL, seps); + strcpy(cTemp,token); + m_BottomSurfacePNTs[2].z=atof(cTemp); + + token = strtok( NULL, seps); + strcpy(cTemp,token); + CalibrateTopLaserValue=atof(cTemp); + + token = strtok( NULL, seps); + strcpy(cTemp,token); + CalibrateBottomLaserValue=atof(cTemp); + + token = strtok( NULL, seps); + strcpy(cTemp,token); + CalibrateValue=atof(cTemp); + + token = strtok( NULL, seps); + strcpy(cTemp,token); + dStandThickness=atof(cTemp); + } + fclose(m_pOutFile); + UpdateDisplayPNTSData(); + } + + } + +} \ No newline at end of file diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_LiteDlg.h b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_LiteDlg.h new file mode 100644 index 0000000..f289b16 --- /dev/null +++ b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/Utility_LiteDlg.h @@ -0,0 +1,93 @@ + +// Utility_LiteDlg.h : header file +// + +#pragma once +#define MAX_BUFF_SIZE 0x200 +typedef struct{ + double x; + double y; + double z; +}Struct_3DPoint; + +typedef struct{ +double XShift; +double YShift; +double Dis1; +double Dis2; +double Dis3; +double DisAverage; +double StandErr; +}CalShiftReport; + +// CUtility_LiteDlg dialog +class CUtility_LiteDlg : public CDialogEx +{ +// Construction +public: + CUtility_LiteDlg(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + enum { IDD = IDD_UTILITY_LITE_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + + +// Implementation +protected: + HICON m_hIcon; + CFont m_BTNFont; + // Generated message map functions + virtual BOOL OnInitDialog(); + afx_msg void OnSysCommand(UINT nID, LPARAM lParam); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + DECLARE_MESSAGE_MAP() +protected: + CString m_OutMessage; + CEdit m_edMSG; + Struct_3DPoint TopSurfacePnts[3]; + Struct_3DPoint BottomSurfacePnts[3]; + Struct_3DPoint ReferencePlanePnts[3]; + + double TopPlaneCoeff[4]; + double BottomPlaneCoeff[4]; + double ReferencePlaneCoeff[4]; + double CalibrateValue; + double CalibrateTopLaserValue; + double CalibrateBottomLaserValue; + double dStandThickness; + double CalXShiftMin,CalXShiftMax,CalXShiftStep; + double CalYShiftMin,CalYShiftMax,CalYShiftStep; + double TopLaserValue; + double dYShiftInputVal; + double dXShiftInputVal; + + + Struct_3DPoint m_BottomSurfacePNTs[3]; + Struct_3DPoint m_TopSurfacePNTs[3]; + +public: + void InitData(); + + void GetPNTSData(); + void UpdateDisplayPNTSData(); + + afx_msg void OnBnClickedButtonImagedll2laserCalculate(); + BOOL ThreePntsConstructPlane(Struct_3DPoint* pArr,double* Coe); + double PointToPlaneDistance(Struct_3DPoint PntPos,double* Coe); + double DoublePlaneAngle(double* Coe1,double* Coe2); + double LineToPlaneAngle(double* LineVector,double* Coe); + void CalculatePNT2Plane(); + void CalculateXYSHIFT(); + void CalculateXYSHIFT_METHOD2(); + void CalculateXYSHIFT_METHOD3(); + void CalculateXYSHIFT_Result(); + void ReadData(); + void OutputWithScroll(const CString &strNewText,CEdit &edtOutput); + BOOL ExportReportCSV(const CString &FilePathName); + afx_msg void OnBnClickedButtonSaveAllMsg(); + afx_msg void OnBnClickedButtonClearAllMsg(); + afx_msg void OnBnClickedButtonOpenDataFile(); +}; diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/stdafx.cpp b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/stdafx.cpp new file mode 100644 index 0000000..80f569f --- /dev/null +++ b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : source file that includes just the standard includes +// Utility_Lite.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/stdafx.h b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/stdafx.h new file mode 100644 index 0000000..4cb6425 --- /dev/null +++ b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/stdafx.h @@ -0,0 +1,58 @@ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + +#ifndef _SECURE_ATL +#define _SECURE_ATL 1 +#endif + +#ifndef VC_EXTRALEAN +#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers +#endif + +#include "targetver.h" + +#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit + +// turns off MFC's hiding of some common and often safely ignored warning messages +#define _AFX_ALL_WARNINGS + +#include // MFC core and standard components +#include // MFC extensions + + +#include // MFC Automation classes + + + +#ifndef _AFX_NO_OLE_SUPPORT +#include // MFC support for Internet Explorer 4 Common Controls +#endif +#ifndef _AFX_NO_AFXCMN_SUPPORT +#include // MFC support for Windows Common Controls +#endif // _AFX_NO_AFXCMN_SUPPORT + +#include // MFC support for ribbons and control bars + + + + + + + + + +#ifdef _UNICODE +#if defined _M_IX86 +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") +#elif defined _M_X64 +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") +#else +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") +#endif +#endif + + diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/targetver.h b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/targetver.h new file mode 100644 index 0000000..90e767b --- /dev/null +++ b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/LITE/Utility_Lite/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil/SO7_Verfication_Algorithm.cpp b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil/SO7_Verfication_Algorithm.cpp index 269433c..2bb005e 100644 --- a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil/SO7_Verfication_Algorithm.cpp +++ b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil/SO7_Verfication_Algorithm.cpp @@ -111,7 +111,7 @@ void CSO7_Verfication_Algorithm::OnBnClickedButtonImagedll2laserCalculate() //calibrate ReferencePlanePnts[2].z=TopLaserValue-CalibrateTopLaserValue+CalibrateValue+CalibrateBottomLaserValue; - ThreePntsConstructionPanel(ReferencePlanePnts,ReferencePlaneCoeff); + ThreePntsConstructPlane(ReferencePlanePnts,ReferencePlaneCoeff); //=====================Top Surface================================== GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X4)->GetWindowText(str); cTempValue=T2A(str); @@ -147,7 +147,7 @@ void CSO7_Verfication_Algorithm::OnBnClickedButtonImagedll2laserCalculate() //calibrate TopSurfacePnts[2].z=TopLaserValue-CalibrateTopLaserValue+CalibrateValue+CalibrateBottomLaserValue; - ThreePntsConstructionPanel(TopSurfacePnts,TopPlaneCoeff); + ThreePntsConstructPlane(TopSurfacePnts,TopPlaneCoeff); //====================Bottom Surface================================ GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X7)->GetWindowText(str); cTempValue=T2A(str); @@ -177,7 +177,7 @@ void CSO7_Verfication_Algorithm::OnBnClickedButtonImagedll2laserCalculate() cTempValue=T2A(str); BottomSurfacePnts[2].z=atof(cTempValue); - ThreePntsConstructionPanel(BottomSurfacePnts,BottomPlaneCoeff); + ThreePntsConstructPlane(BottomSurfacePnts,BottomPlaneCoeff); /*************************************************************** result @@ -187,9 +187,9 @@ void CSO7_Verfication_Algorithm::OnBnClickedButtonImagedll2laserCalculate() double dAnswer(0.0); CString csOutput; //==================Top - Reference================================ - Top2ReferenceDis[0]=PointToPanelDistance(TopSurfacePnts[0],ReferencePlaneCoeff); - Top2ReferenceDis[1]=PointToPanelDistance(TopSurfacePnts[1],ReferencePlaneCoeff); - Top2ReferenceDis[2]=PointToPanelDistance(TopSurfacePnts[2],ReferencePlaneCoeff); + Top2ReferenceDis[0]=PointToPlaneDistance(TopSurfacePnts[0],ReferencePlaneCoeff); + Top2ReferenceDis[1]=PointToPlaneDistance(TopSurfacePnts[1],ReferencePlaneCoeff); + Top2ReferenceDis[2]=PointToPlaneDistance(TopSurfacePnts[2],ReferencePlaneCoeff); Top2ReferenceDis[3]=(Top2ReferenceDis[0]+Top2ReferenceDis[1]+Top2ReferenceDis[2])/3.0; @@ -203,9 +203,9 @@ void CSO7_Verfication_Algorithm::OnBnClickedButtonImagedll2laserCalculate() ((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE4)))->SetWindowText(csOutput); - Bottom2ReferenceDis[0]=PointToPanelDistance(BottomSurfacePnts[0],ReferencePlaneCoeff); - Bottom2ReferenceDis[1]=PointToPanelDistance(BottomSurfacePnts[1],ReferencePlaneCoeff); - Bottom2ReferenceDis[2]=PointToPanelDistance(BottomSurfacePnts[2],ReferencePlaneCoeff); + Bottom2ReferenceDis[0]=PointToPlaneDistance(BottomSurfacePnts[0],ReferencePlaneCoeff); + Bottom2ReferenceDis[1]=PointToPlaneDistance(BottomSurfacePnts[1],ReferencePlaneCoeff); + Bottom2ReferenceDis[2]=PointToPlaneDistance(BottomSurfacePnts[2],ReferencePlaneCoeff); Bottom2ReferenceDis[3]=(Bottom2ReferenceDis[0]+Bottom2ReferenceDis[1]+Bottom2ReferenceDis[2])/3.0; dAnswer=Top2ReferenceDis[3]-Bottom2ReferenceDis[3]; @@ -224,7 +224,7 @@ void CSO7_Verfication_Algorithm::OnBnClickedButtonImagedll2laserCalculate() } //=================================================================== -BOOL CSO7_Verfication_Algorithm::ThreePntsConstructionPanel(Struct_3DPoint* pArr,double* Coe) +BOOL CSO7_Verfication_Algorithm::ThreePntsConstructPlane(Struct_3DPoint* pArr,double* Coe) { Struct_3DPoint p1,p2,p3; @@ -244,7 +244,7 @@ BOOL CSO7_Verfication_Algorithm::ThreePntsConstructionPanel(Struct_3DPoint* pArr return TRUE; }; //=================================================================== -double CSO7_Verfication_Algorithm::PointToPanelDistance(Struct_3DPoint PntPos,double* Coe) +double CSO7_Verfication_Algorithm::PointToPlaneDistance(Struct_3DPoint PntPos,double* Coe) { double m_result(0.0); double a(0.0),b(0.0),c(0.0),d(0.0); diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil/So7_Manual_Machine.cpp b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil/So7_Manual_Machine.cpp index 4fca2b2..3d50218 100644 --- a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil/So7_Manual_Machine.cpp +++ b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil/So7_Manual_Machine.cpp @@ -154,19 +154,62 @@ void CSo7_Manual_Machine::OnBnClickedRadioSo7ManualMachineCommonCmd3() //=================================================== void CSo7_Manual_Machine::OnBnClickedRadioSo7ManualMachineSendDataTypeHex() { - // TODO: Add your control notification handler code here + m_SendType=HEXADECIMAL; } //=================================================== void CSo7_Manual_Machine::OnBnClickedRadioSo7ManualMachineSendDataTypeAnscii() { - // TODO: Add your control notification handler code here + m_SendType=ANSCII; } //=================================================== void CSo7_Manual_Machine::OnBnClickedButtonSo7ManualMachineSendData() { - // TODO: Add your control notification handler code here + /* + UpdateData(TRUE); + USES_CONVERSION; + CString csSendData(L""); + + GetDlgItem(IDC_EDIT_SO7_MANUAL_MACHINE_DATA)->GetWindowText(csSendData); + const char* cSendData=T2A(csSendData); + if (m_SendType==HEXADECIMAL) + { + char* stop; + BYTE bSendData[MAX_OUTPUT_BUFFER_SIZE]={0}; + INT iSendDataLength=(csSendData.GetLength()+1)/3; + for(INT i=0;im_csRecv=_T(""); + + //¼ÓÉϻسµ»»Ðзû + CString csTemp; + csTemp.Format(_T("\r\n")); + csSendData+=csTemp; + + + cSendData=T2A(csSendData); + } + DWORD iSendDataLength=csSendData.GetLength(); + DWORD iWriteByte=m_pSO7_Serial->Send(cSendData,iSendDataLength); + + ((CListBox *)GetDlgItem(IDC_LIST_SHOWMESSAGE))->InsertString(-1,CString(_T("[Send]: "))+cSendData);// + + csSendData.Format(_T("Send(%dByte)"),iWriteByte); + m_StatusBar.SetText(csSendData, 1, 0); + //½ÓÊÜÊý¾Ý + INT iRetrys(0); + while(!m_pSO7_Serial->m_iRecvState && iRetrys<20) + { + iRetrys++; + Sleep(100); + } + */ } //=================================================== diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil/So7_Manual_Machine.h b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil/So7_Manual_Machine.h index f56bd1e..8954c3a 100644 --- a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil/So7_Manual_Machine.h +++ b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil/So7_Manual_Machine.h @@ -1,6 +1,9 @@ #pragma once - +typedef enum{ + HEXADECIMAL = 0, + ANSCII, +}RS232SendType; // CSo7_Manual_Machine dialog class CSo7_Manual_Machine : public CDialog @@ -21,6 +24,7 @@ protected: protected: CStatusBarCtrl m_StatusBar; CEdit m_edit_Log; + char m_SendType; public: afx_msg void OnBnClickedButtonSo7ManualMachineStartMachine(); afx_msg void OnBnClickedButtonSo7ManualMachineStopMachine(); diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil_VS2010.sln b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil_VS2010.sln index 3197d25..337d6d3 100644 --- a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil_VS2010.sln +++ b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil_VS2010.sln @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Usb_Util", "UsbUtil\Usb_Util.vcxproj", "{50B21A79-C887-4F7E-8911-7E3A685BFA25}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Utility_Lite", "LITE\Utility_Lite\Utility_Lite.vcxproj", "{0E5F6F86-6883-47F0-9DC9-8232BBF13B58}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -25,6 +27,15 @@ Global {50B21A79-C887-4F7E-8911-7E3A685BFA25}.Template|Win32.Build.0 = Template|Win32 {50B21A79-C887-4F7E-8911-7E3A685BFA25}.Template|x64.ActiveCfg = Template|x64 {50B21A79-C887-4F7E-8911-7E3A685BFA25}.Template|x64.Build.0 = Template|x64 + {0E5F6F86-6883-47F0-9DC9-8232BBF13B58}.Debug|Win32.ActiveCfg = Debug|Win32 + {0E5F6F86-6883-47F0-9DC9-8232BBF13B58}.Debug|Win32.Build.0 = Debug|Win32 + {0E5F6F86-6883-47F0-9DC9-8232BBF13B58}.Debug|x64.ActiveCfg = Debug|Win32 + {0E5F6F86-6883-47F0-9DC9-8232BBF13B58}.Release|Win32.ActiveCfg = Release|Win32 + {0E5F6F86-6883-47F0-9DC9-8232BBF13B58}.Release|Win32.Build.0 = Release|Win32 + {0E5F6F86-6883-47F0-9DC9-8232BBF13B58}.Release|x64.ActiveCfg = Release|Win32 + {0E5F6F86-6883-47F0-9DC9-8232BBF13B58}.Template|Win32.ActiveCfg = Release|Win32 + {0E5F6F86-6883-47F0-9DC9-8232BBF13B58}.Template|Win32.Build.0 = Release|Win32 + {0E5F6F86-6883-47F0-9DC9-8232BBF13B58}.Template|x64.ActiveCfg = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil_VS2010.suo b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil_VS2010.suo index 82bf99c..78fce16 100644 Binary files a/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil_VS2010.suo and b/PcDmis/Base/Interfac/Msi/Hsi/Tools/UsbUtility/UsbUtil_VS2010.suo differ