| | |
| | | CAlarmPopupDlg::CAlarmPopupDlg(CWnd* pParent /*=NULL*/) |
| | | : CDialogEx(IDD_DIALOG_POPUP_ALARM, pParent) |
| | | { |
| | | m_pPLC = nullptr; |
| | | |
| | | m_crBkgnd = RGB(225, 225, 225); |
| | | m_hbrBkgnd = nullptr; |
| | | m_pActiveAlarm = nullptr; |
| | |
| | | CAlarmPopupDlg::~CAlarmPopupDlg() |
| | | { |
| | | } |
| | | |
| | | void CAlarmPopupDlg::SetPLC(CPLC* pPLC) |
| | | { |
| | | ASSERT(pPLC); |
| | | m_pPLC = pPLC; |
| | | } |
| | | |
| | | |
| | | void CAlarmPopupDlg::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | |
| | | ON_WM_DESTROY() |
| | | ON_WM_SIZE() |
| | | ON_BN_CLICKED(IDC_BUTTON_CLOSE, &CAlarmPopupDlg::OnBnClickedButtonClose) |
| | | ON_BN_CLICKED(IDC_BUTTON_SOUND_OFF, &CAlarmPopupDlg::OnBnClickedButtonSoundOff) |
| | | ON_BN_CLICKED(IDC_BUTTON_ALARM_OFF, &CAlarmPopupDlg::OnBnClickedButtonAlarmOff) |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | |
| | | |
| | | |
| | | // éé³æé® |
| | | bool bMute = theApp.m_model.getBonder().isMute(); |
| | | m_btnSoundOff.SubclassDlgItem(IDC_BUTTON_SOUND_OFF, this); |
| | | m_btnSoundOff.SetFrameColor(BS_NORMAL, BTN_SOUND_OFF_FRAME_NORMAL); |
| | | m_btnSoundOff.SetFrameColor(BS_HOVER, BTN_SOUND_OFF_FRAME_HOVER); |
| | | m_btnSoundOff.SetFrameColor(BS_PRESS, BTN_SOUND_OFF_FRAME_PRESS); |
| | | m_btnSoundOff.SetBkgndColor(BS_NORMAL, BTN_SOUND_OFF_BKGND_NORMAL); |
| | | m_btnSoundOff.SetBkgndColor(BS_HOVER, BTN_SOUND_OFF_BKGND_HOVER); |
| | | m_btnSoundOff.SetBkgndColor(BS_PRESS, BTN_SOUND_OFF_BKGND_PRESS); |
| | | |
| | | SetButtonBackgroundColors(bMute); |
| | | |
| | | // 横线1 |
| | | CHorizontalLine* pLine = CHorizontalLine::Hook(GetDlgItem(IDC_LINE1)->m_hWnd); |
| | |
| | | ShowWindow(SW_HIDE); |
| | | } |
| | | } |
| | | |
| | | void CAlarmPopupDlg::SetButtonBackgroundColors(bool bMute) |
| | | { |
| | | if (!bMute) { |
| | | m_btnSoundOff.SetBkgndColor(BS_NORMAL, BTN_SOUND_OFF_BKGND_NORMAL); |
| | | m_btnSoundOff.SetBkgndColor(BS_HOVER, BTN_SOUND_OFF_BKGND_HOVER); |
| | | m_btnSoundOff.SetBkgndColor(BS_PRESS, BTN_SOUND_OFF_BKGND_PRESS); |
| | | } |
| | | else { |
| | | m_btnSoundOff.SetBkgndColor(BS_NORMAL, BTN_SOUND_ON_BKGND_NORMAL); |
| | | m_btnSoundOff.SetBkgndColor(BS_HOVER, BTN_SOUND_ON_BKGND_HOVER); |
| | | m_btnSoundOff.SetBkgndColor(BS_PRESS, BTN_SOUND_ON_BKGND_PRESS); |
| | | } |
| | | } |
| | | |
| | | void CAlarmPopupDlg::OnBnClickedButtonSoundOff() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | | if (m_pPLC == nullptr || !m_pPLC->isConnected()) { |
| | | return; |
| | | } |
| | | |
| | | // å PLC åå
¥ä¿¡å· |
| | | bool bMute = theApp.m_model.getBonder().isMute(); |
| | | char szWrite[4] = { 0x1, 0x0, 0x0, 0x0 }; |
| | | szWrite[0] = !bMute; |
| | | m_pPLC->writeData(MC::M, 1003, szWrite, 2, [](IMcChannel* pChannel, int nAddr, DWORD nValue, int nFlag) { |
| | | if (nFlag == 0) { |
| | | TRACE("æä½æåï¼å°å=1003\n", nAddr); |
| | | } |
| | | else { |
| | | TRACE("æä½å¤±è´¥ï¼å°å=1003ï¼é误ç =%d\n", nFlag); |
| | | } |
| | | }); |
| | | |
| | | SetButtonBackgroundColors(!bMute); |
| | | } |
| | | |
| | | void CAlarmPopupDlg::OnBnClickedButtonAlarmOff() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | | if (m_pPLC == nullptr || !m_pPLC->isConnected()) { |
| | | return; |
| | | } |
| | | |
| | | // å PLC åå
¥ä¿¡å· |
| | | char szWrite[4] = { 0x1, 0x0, 0x0, 0x0 }; |
| | | m_pPLC->writeData(MC::M, 1009, szWrite, 2, [](IMcChannel* pChannel, int nAddr, DWORD nValue, int nFlag) { |
| | | if (nFlag == 0) { |
| | | TRACE("æä½æåï¼å°å=1009\n", nAddr); |
| | | } |
| | | else { |
| | | TRACE("æä½å¤±è´¥ï¼å°å=1009ï¼é误ç =%d\n", nFlag); |
| | | } |
| | | }); |
| | | |
| | | Sleep(500); |
| | | |
| | | szWrite[0] = 0x0; |
| | | m_pPLC->writeData(MC::M, 1009, szWrite, 2, [](IMcChannel* pChannel, int nAddr, DWORD nValue, int nFlag) { |
| | | if (nFlag == 0) { |
| | | TRACE("æä½æåï¼å°å=1009\n", nAddr); |
| | | } |
| | | else { |
| | | TRACE("æä½å¤±è´¥ï¼å°å=1009ï¼é误ç =%d\n", nFlag); |
| | | } |
| | | }); |
| | | } |
| | |
| | | CAlarmPopupDlg(CWnd* pParent = NULL); // æ åæé 彿° |
| | | virtual ~CAlarmPopupDlg(); |
| | | |
| | | public: |
| | | void SetPLC(CPLC* pPLC); |
| | | |
| | | public: |
| | | void AlarmOn(); |
| | |
| | | |
| | | private: |
| | | void ShowFirstAlarm(); |
| | | void SetButtonBackgroundColors(bool bMute); |
| | | |
| | | private: |
| | | COLORREF m_crBkgnd; |
| | |
| | | CFont m_fontDescription; |
| | | |
| | | private: |
| | | CPLC* m_pPLC; |
| | | CAlarm* m_pActiveAlarm; |
| | | CBlButton m_btnClose; |
| | | CBlButton m_btnSoundOff; |
| | |
| | | afx_msg void OnDestroy(); |
| | | afx_msg void OnSize(UINT nType, int cx, int cy); |
| | | afx_msg void OnBnClickedButtonClose(); |
| | | afx_msg void OnBnClickedButtonSoundOff(); |
| | | afx_msg void OnBnClickedButtonAlarmOff(); |
| | | }; |
| | |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ClInclude Include="AlarmPopupDlg.h" /> |
| | | <ClInclude Include="CBaseDlg.h" /> |
| | | <ClInclude Include="CComponentDlg.h" /> |
| | | <ClInclude Include="CComponentPLCDlg.h" /> |
| | | <ClInclude Include="CPLC.h" /> |
| | |
| | | <ClInclude Include="CPanel.h" /> |
| | | <ClInclude Include="CParam.h" /> |
| | | <ClInclude Include="CProjectPageComponents.h" /> |
| | | <ClInclude Include="CProjectPageMain.h" /> |
| | | <ClInclude Include="CRemoteEqUnitView.h" /> |
| | | <ClInclude Include="CRemoteEqView.h" /> |
| | | <ClInclude Include="CHomeDialog.h" /> |
| | |
| | | <ClInclude Include="View\ChangePasswordDlg.h" /> |
| | | <ClInclude Include="View\IOMonitoringDlg.h" /> |
| | | <ClInclude Include="View\LoginDlg.h" /> |
| | | <ClInclude Include="View\RecipeListDlg.h" /> |
| | | <ClInclude Include="View\SystemLogManagerDlg.h" /> |
| | | <ClInclude Include="View\UserManagerDlg.h" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ClCompile Include="AlarmPopupDlg.cpp" /> |
| | | <ClCompile Include="CBaseDlg.cpp" /> |
| | | <ClCompile Include="CComponentDlg.cpp" /> |
| | | <ClCompile Include="CComponentPLCDlg.cpp" /> |
| | | <ClCompile Include="CPLC.cpp" /> |
| | |
| | | <ClCompile Include="CPanel.cpp" /> |
| | | <ClCompile Include="CParam.cpp" /> |
| | | <ClCompile Include="CProjectPageComponents.cpp" /> |
| | | <ClCompile Include="CProjectPageMain.cpp" /> |
| | | <ClCompile Include="CRemoteEqUnitView.cpp" /> |
| | | <ClCompile Include="CRemoteEqView.cpp" /> |
| | | <ClCompile Include="CHomeDialog.cpp" /> |
| | |
| | | <ClCompile Include="View\ChangePasswordDlg.cpp" /> |
| | | <ClCompile Include="View\IOMonitoringDlg.cpp" /> |
| | | <ClCompile Include="View\LoginDlg.cpp" /> |
| | | <ClCompile Include="View\RecipeListDlg.cpp" /> |
| | | <ClCompile Include="View\SystemLogManagerDlg.cpp" /> |
| | | <ClCompile Include="View\UserManagerDlg.cpp" /> |
| | | </ItemGroup> |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| | | <ItemGroup> |
| | | <Manifest Include="res\application.exe.manifest" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ClCompile Include="CPLC.cpp" /> |
| | | <ClCompile Include="AccordionWnd.cpp" /> |
| | | <ClCompile Include="Alarm.cpp" /> |
| | | <ClCompile Include="AlarmMonitor.cpp" /> |
| | | <ClCompile Include="ApredTreeCtrl.cpp" /> |
| | | <ClCompile Include="BaseSetPage.cpp" /> |
| | | <ClCompile Include="BlButton.cpp" /> |
| | | <ClCompile Include="BondEq.cpp" /> |
| | | <ClCompile Include="BondEqDlg.cpp" /> |
| | | <ClCompile Include="CBaseView.cpp" /> |
| | | <ClCompile Include="CBonder.cpp" /> |
| | | <ClCompile Include="CDataMonitor1.cpp" /> |
| | | <ClCompile Include="Component.cpp" /> |
| | | <ClCompile Include="Context.cpp" /> |
| | | <ClCompile Include="CPanel.cpp" /> |
| | | <ClCompile Include="CParam.cpp" /> |
| | | <ClCompile Include="CRemoteEqUnitView.cpp" /> |
| | | <ClCompile Include="CRemoteEqView.cpp" /> |
| | | <ClCompile Include="CHomeDialog.cpp" /> |
| | | <ClCompile Include="CMainContainer.cpp" /> |
| | | <ClCompile Include="CPageLogcat.cpp" /> |
| | | <ClCompile Include="CProjectPageRemoteEqs.cpp" /> |
| | | <ClCompile Include="Configuration.cpp" /> |
| | | <ClCompile Include="CPanelProject.cpp" /> |
| | | <ClCompile Include="EQState.cpp" /> |
| | | <ClCompile Include="EQStateMonitor.cpp" /> |
| | | <ClCompile Include="HmTab.cpp" /> |
| | | <ClCompile Include="HmVerticalTab.cpp" /> |
| | | <ClCompile Include="HorizontalLine.cpp" /> |
| | | <ClCompile Include="InputDialog.cpp" /> |
| | | <ClCompile Include="Intent.cpp" /> |
| | | <ClCompile Include="LoadMonitor.cpp" /> |
| | | <ClCompile Include="Log.cpp" /> |
| | | <ClCompile Include="LogEdit.cpp" /> |
| | | <ClCompile Include="McBool.cpp" /> |
| | | <ClCompile Include="McInt.cpp" /> |
| | | <ClCompile Include="McItem.cpp" /> |
| | | <ClCompile Include="McString.cpp" /> |
| | | <ClCompile Include="Model.cpp" /> |
| | | <ClCompile Include="CPageAlarm.cpp" /> |
| | | <ClCompile Include="Recipe.cpp" /> |
| | | <ClCompile Include="SetPage1.cpp" /> |
| | | <ClCompile Include="SetPage2.cpp" /> |
| | | <ClCompile Include="SettingsDlg.cpp" /> |
| | | <ClCompile Include="stdafx.cpp" /> |
| | | <ClCompile Include="ToolUnits.cpp" /> |
| | | <ClCompile Include="TopToolbar.cpp" /> |
| | | <ClCompile Include="VerticalLine.cpp" /> |
| | | <ClCompile Include="DBManager\UserManager.cpp"> |
| | | <Filter>DBManager</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="DBManager\SystemLogManager.cpp"> |
| | | <Filter>DBManager</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="View\ChangePasswordDlg.cpp"> |
| | | <Filter>View</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="View\LoginDlg.cpp"> |
| | | <Filter>View</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="View\SystemLogManagerDlg.cpp"> |
| | | <Filter>View</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="View\UserManagerDlg.cpp"> |
| | | <Filter>View</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="CProjectPageComponents.cpp" /> |
| | | <ClCompile Include="GB2860SQLite.cpp" /> |
| | | <ClCompile Include="sqlite3.c" /> |
| | | <ClCompile Include="DBManager\AxisManager.cpp"> |
| | | <Filter>DBManager</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="FileManager\RecipeManager.cpp"> |
| | | <Filter>FileManager</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="FileManager\pugixml.cpp"> |
| | | <Filter>FileManager</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="FileManager\IOManager.cpp"> |
| | | <Filter>FileManager</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="View\IOMonitoringDlg.cpp"> |
| | | <Filter>View</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="CComponentDlg.cpp" /> |
| | | <ClCompile Include="CComponentPLCDlg.cpp" /> |
| | | <ClCompile Include="View\AxisSettingsDlg.cpp"> |
| | | <Filter>View</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="View\AxisDetailSettingsDlg.cpp"> |
| | | <Filter>View</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="RegexEdit.cpp" /> |
| | | <ClCompile Include="AlarmPopupDlg.cpp" /> |
| | | <ClCompile Include="DBManager\AlarmManager.cpp"> |
| | | <Filter>DBManager</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="View\RecipeListDlg.cpp"> |
| | | <Filter>View</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="CBaseDlg.cpp" /> |
| | | <ClCompile Include="CProjectPageMain.cpp" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ClInclude Include="CPLC.h" /> |
| | | <ClInclude Include="AccordionWnd.h" /> |
| | | <ClInclude Include="Alarm.h" /> |
| | | <ClInclude Include="AlarmMonitor.h" /> |
| | | <ClInclude Include="ApredTreeCtrl.h" /> |
| | | <ClInclude Include="BaseSetPage.h" /> |
| | | <ClInclude Include="BlButton.h" /> |
| | | <ClInclude Include="BondEq.h" /> |
| | | <ClInclude Include="BondEqDlg.h" /> |
| | | <ClInclude Include="CBaseView.h" /> |
| | | <ClInclude Include="CBonder.h" /> |
| | | <ClInclude Include="CDataMonitor1.h" /> |
| | | <ClInclude Include="Component.h" /> |
| | | <ClInclude Include="Context.h" /> |
| | | <ClInclude Include="CPanel.h" /> |
| | | <ClInclude Include="CParam.h" /> |
| | | <ClInclude Include="CRemoteEqUnitView.h" /> |
| | | <ClInclude Include="CRemoteEqView.h" /> |
| | | <ClInclude Include="CHomeDialog.h" /> |
| | | <ClInclude Include="CMainContainer.h" /> |
| | | <ClInclude Include="CPageLogcat.h" /> |
| | | <ClInclude Include="CProjectPageRemoteEqs.h" /> |
| | | <ClInclude Include="Common.h" /> |
| | | <ClInclude Include="Configuration.h" /> |
| | | <ClInclude Include="CPanelProject.h" /> |
| | | <ClInclude Include="EQState.h" /> |
| | | <ClInclude Include="EQStateMonitor.h" /> |
| | | <ClInclude Include="HmTab.h" /> |
| | | <ClInclude Include="HmVerticalTab.h" /> |
| | | <ClInclude Include="HorizontalLine.h" /> |
| | | <ClInclude Include="InputDialog.h" /> |
| | | <ClInclude Include="Intent.h" /> |
| | | <ClInclude Include="LoadMonitor.h" /> |
| | | <ClInclude Include="Log.h" /> |
| | | <ClInclude Include="LogEdit.h" /> |
| | | <ClInclude Include="McBool.h" /> |
| | | <ClInclude Include="McInt.h" /> |
| | | <ClInclude Include="McItem.h" /> |
| | | <ClInclude Include="McString.h" /> |
| | | <ClInclude Include="Model.h" /> |
| | | <ClInclude Include="CPageAlarm.h" /> |
| | | <ClInclude Include="Recipe.h" /> |
| | | <ClInclude Include="Resource.h" /> |
| | | <ClInclude Include="SetPage1.h" /> |
| | | <ClInclude Include="SetPage2.h" /> |
| | | <ClInclude Include="SettingsDlg.h" /> |
| | | <ClInclude Include="stdafx.h" /> |
| | | <ClInclude Include="targetver.h" /> |
| | | <ClInclude Include="ToolUnits.h" /> |
| | | <ClInclude Include="TopToolbar.h" /> |
| | | <ClInclude Include="VerticalLine.h" /> |
| | | <ClInclude Include="DBManager\UserManager.h"> |
| | | <Filter>DBManager</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="DBManager\SystemLogManager.h"> |
| | | <Filter>DBManager</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="View\ChangePasswordDlg.h"> |
| | | <Filter>View</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="View\LoginDlg.h"> |
| | | <Filter>View</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="View\SystemLogManagerDlg.h"> |
| | | <Filter>View</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="View\UserManagerDlg.h"> |
| | | <Filter>View</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="CProjectPageComponents.h" /> |
| | | <ClInclude Include="GB2860SQLite.h" /> |
| | | <ClInclude Include="sqlite3.h" /> |
| | | <ClInclude Include="sqlite3ext.h" /> |
| | | <ClInclude Include="DBManager\AxisManager.h"> |
| | | <Filter>DBManager</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="FileManager\RecipeManager.h"> |
| | | <Filter>FileManager</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="FileManager\pugiconfig.hpp"> |
| | | <Filter>FileManager</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="FileManager\pugixml.hpp"> |
| | | <Filter>FileManager</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="FileManager\IOManager.h"> |
| | | <Filter>FileManager</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="View\IOMonitoringDlg.h"> |
| | | <Filter>View</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="CComponentDlg.h" /> |
| | | <ClInclude Include="CComponentPLCDlg.h" /> |
| | | <ClInclude Include="View\AxisSettingsDlg.h"> |
| | | <Filter>View</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="View\AxisDetailSettingsDlg.h"> |
| | | <Filter>View</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="RegexEdit.h" /> |
| | | <ClInclude Include="AlarmPopupDlg.h" /> |
| | | <ClInclude Include="DBManager\AlarmManager.h"> |
| | | <Filter>DBManager</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="View\RecipeListDlg.h"> |
| | | <Filter>View</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="CBaseDlg.h" /> |
| | | <ClInclude Include="CProjectPageMain.h" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ResourceCompile Include="BondEq.rc" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <Image Include="res\BondEq.ico" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <None Include="res\BondEq.rc2" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <Text Include="ReadMe.txt" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <Filter Include="DBManager"> |
| | | <UniqueIdentifier>{6b00bde2-91aa-41eb-9727-72d846b65036}</UniqueIdentifier> |
| | | </Filter> |
| | | <Filter Include="View"> |
| | | <UniqueIdentifier>{d11aa86e-1ee5-4307-89d0-84a9abb7ab1f}</UniqueIdentifier> |
| | | </Filter> |
| | | <Filter Include="FileManager"> |
| | | <UniqueIdentifier>{852d5282-c39d-45a3-b4a4-e6dd2a0c52a5}</UniqueIdentifier> |
| | | </Filter> |
| | | </ItemGroup> |
| | | </Project> |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| | | <PropertyGroup> |
| | | <RESOURCE_FILE>BondEq.rc</RESOURCE_FILE> |
| | | </PropertyGroup> |
| | | </Project> |
| | |
| | | #include "UserManagerDlg.h" |
| | | #include "SystemLogManagerDlg.h" |
| | | |
| | | // æµè¯ |
| | | #include "RecipeListDlg.h" |
| | | |
| | | #ifdef _DEBUG |
| | | #define new DEBUG_NEW |
| | |
| | | |
| | | // 设置é
æ¹æä»¶å¤¹è·¯å¾ |
| | | RecipeManager& recipeManager = RecipeManager::getInstance(); |
| | | std::string strRecipePath = CToolUnits::getCurrentExePath() + _T("\\Recipe"); |
| | | std::string strRecipePath = CToolUnits::getRecipePath(); |
| | | CToolUnits::createDir(strRecipePath.c_str()); |
| | | recipeManager.setRecipeFolder(strRecipePath); |
| | | |
| | | if (!recipeManager.loadRecipe("Default")) { |
| | | AfxMessageBox("Default é
æ¹å 载失败ï¼"); |
| | | } |
| | | |
| | | // èå |
| | | CMenu menu; |
| | |
| | | |
| | | void CBondEqDlg::OnMenuFileSettings() |
| | | { |
| | | CSettingsDlg dlg; |
| | | CRecipeListDlg dlg; |
| | | dlg.DoModal(); |
| | | |
| | | //CSettingsDlg dlg; |
| | | //dlg.DoModal(); |
| | | } |
| | | |
| | | void CBondEqDlg::OnUpdateMenuFileSettings(CCmdUI* pCmdUI) |
| | |
| | | { |
| | | if (m_pAlarmWnd == nullptr) { |
| | | m_pAlarmWnd = new CAlarmPopupDlg(); |
| | | m_pAlarmWnd->SetPLC(theApp.m_model.getBonder().getPLC("PLC(1)")); |
| | | m_pAlarmWnd->Create(IDD_DIALOG_POPUP_ALARM, this); |
| | | m_pAlarmWnd->CenterWindow(); |
| | | } |
| | |
| | | { |
| | | if (m_pAlarmWnd == nullptr) { |
| | | m_pAlarmWnd = new CAlarmPopupDlg(); |
| | | m_pAlarmWnd->SetPLC(theApp.m_model.getBonder().getPLC("PLC(1)")); |
| | | m_pAlarmWnd->Create(IDD_DIALOG_POPUP_ALARM, this); |
| | | m_pAlarmWnd->CenterWindow(); |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #include "stdafx.h" |
| | | #include "CBaseDlg.h" |
| | | #include "GridCtrl.h" |
| | | |
| | | // å
¨å±ä¸»é¢å¯¹è±¡ |
| | | Theme g_lightTheme = { RGB(255, 255, 255), RGB(0, 0, 0), RGB(240, 240, 240), RGB(200, 200, 200) }; |
| | | Theme g_darkTheme = { RGB(40, 40, 40), RGB(255, 255, 255), RGB(60, 60, 60), RGB(80, 80, 80) }; |
| | | |
| | | CFont g_defaultFont; |
| | | Theme* g_currentTheme = &g_lightTheme; |
| | | |
| | | // å
¨å±èµæºå¥æ |
| | | HINSTANCE g_hCurrentResource = NULL; |
| | | |
| | | IMPLEMENT_DYNAMIC(CBaseDlg, CDialogEx) |
| | | |
| | | CBaseDlg::CBaseDlg(UINT nID, CWnd* pPage) : CDialogEx(nID, pPage), m_bResizing(false) |
| | | { |
| | | m_nID = nID; |
| | | m_pParent = pPage; |
| | | m_nInitialWidth = 0; |
| | | m_nInitialHeight = 0; |
| | | } |
| | | |
| | | CBaseDlg::~CBaseDlg() |
| | | { |
| | | // shared_pträ¼èªå¨æ¸
çå
åï¼ä¸éè¦æå¨å é¤ |
| | | m_mapFonts.clear(); |
| | | m_mapCtrlLayouts.clear(); |
| | | m_mapControls.clear(); |
| | | } |
| | | |
| | | void CBaseDlg::SwitchTheme(ThemeType enThemeType) |
| | | { |
| | | // ä½¿ç¨ map æ¥æ ¹æ® themeType æ¥æ¾ä¸»é¢ |
| | | static const std::unordered_map<ThemeType, Theme*> themeMap = { |
| | | { ThemeType::Light, &g_lightTheme }, |
| | | { ThemeType::Dark, &g_darkTheme } |
| | | }; |
| | | |
| | | // 设置å½åä¸»é¢ |
| | | auto it = themeMap.find(enThemeType); |
| | | if (it != themeMap.end()) { |
| | | g_currentTheme = it->second; |
| | | } |
| | | else { |
| | | g_currentTheme = &g_lightTheme; |
| | | } |
| | | |
| | | // æ´æ°æ§ä»¶çå¤è§ |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | pWnd->Invalidate(); |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | |
| | | // æ´æ°å¯¹è¯æ¡èæ¯é¢è² |
| | | SetBackgroundColor(g_currentTheme->backgroundColor); |
| | | } |
| | | |
| | | void CBaseDlg::LoadResourceLibrary(const CString& strLanguage) |
| | | { |
| | | // å¸è½½ä¹åå è½½çèµæºåº |
| | | UnloadResourceLibrary(); |
| | | |
| | | // å è½½æ°çèµæºåº |
| | | g_hCurrentResource = AfxLoadLibrary(strLanguage); |
| | | |
| | | // 设置æ°çèµæºå¥æ |
| | | if (g_hCurrentResource != NULL) { |
| | | AfxSetResourceHandle(g_hCurrentResource); |
| | | } |
| | | } |
| | | |
| | | void CBaseDlg::UnloadResourceLibrary() |
| | | { |
| | | // å¸è½½ä¹åå è½½çèµæºåº |
| | | if (g_hCurrentResource != NULL) { |
| | | FreeLibrary(g_hCurrentResource); // éæ¾å½åèµæºåº |
| | | g_hCurrentResource = NULL; // æ¸
ç©ºèµæºå¥æ |
| | | } |
| | | } |
| | | |
| | | CFont* CBaseDlg::GetOrCreateFont(int nFontSize) |
| | | { |
| | | auto it = m_mapFonts.find(nFontSize); |
| | | if (it != m_mapFonts.end()) { |
| | | return it->second.get(); |
| | | } |
| | | |
| | | // ä½¿ç¨ shared_ptr æ¥ç®¡çåä½å¯¹è±¡ |
| | | auto font = std::make_shared<CFont>(); |
| | | LOGFONT logFont = { 0 }; |
| | | _tcscpy_s(logFont.lfFaceName, _T("Segoe UI")); |
| | | logFont.lfHeight = -nFontSize; |
| | | logFont.lfQuality = CLEARTYPE_QUALITY; |
| | | font->CreateFontIndirect(&logFont); |
| | | m_mapFonts[nFontSize] = font; |
| | | |
| | | return font.get(); |
| | | } |
| | | |
| | | void CBaseDlg::SetDefaultFont() |
| | | { |
| | | CFont* defaultFont = GetOrCreateFont(12); |
| | | |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | pWnd = pWnd->GetNextWindow(); |
| | | continue; |
| | | } |
| | | |
| | | pWnd->SetFont(defaultFont, TRUE); |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | BOOL CBaseDlg::AddControl(UINT nCtrlID, CWnd* pControl) |
| | | { |
| | | // ç¡®ä¿æ§ä»¶ä¸é夿·»å |
| | | if (m_mapControls.find(nCtrlID) != m_mapControls.end()) { |
| | | return FALSE; // æ§ä»¶å·²ç»åå¨ |
| | | } |
| | | |
| | | m_mapControls[nCtrlID] = std::unique_ptr<CWnd>(pControl); |
| | | return TRUE; |
| | | } |
| | | |
| | | BOOL CBaseDlg::RemoveControl(UINT nCtrlID) |
| | | { |
| | | auto it = m_mapControls.find(nCtrlID); |
| | | if (it != m_mapControls.end()) { |
| | | m_mapControls.erase(it); |
| | | return TRUE; |
| | | } |
| | | return FALSE; |
| | | } |
| | | |
| | | BOOL CBaseDlg::UpdateControlText(UINT nCtrlID, const CString& strText) |
| | | { |
| | | auto it = m_mapControls.find(nCtrlID); |
| | | if (it != m_mapControls.end()) { |
| | | CWnd* pWnd = it->second.get(); |
| | | if (pWnd->GetSafeHwnd() != nullptr) |
| | | { |
| | | pWnd->SetWindowText(strText); |
| | | return TRUE; |
| | | } |
| | | } |
| | | return FALSE; |
| | | } |
| | | |
| | | CWnd* CBaseDlg::GetControl(UINT nCtrlID) |
| | | { |
| | | auto it = m_mapControls.find(nCtrlID); |
| | | if (it != m_mapControls.end()) { |
| | | return it->second.get(); |
| | | } |
| | | return nullptr; |
| | | } |
| | | |
| | | void CBaseDlg::AdjustControls(float dScaleX, float dScaleY) |
| | | { |
| | | if (m_bResizing) return; // 鲿¢å¨è°æ´è¿ç¨ä¸éå¤è°æ´ |
| | | |
| | | m_bResizing = true; |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | int nCtrlID = pWnd->GetDlgCtrlID(); |
| | | if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end()) { |
| | | CRect originalRect = m_mapCtrlLayouts[nCtrlID]; |
| | | CRect newRect( |
| | | static_cast<int>(originalRect.left * dScaleX), |
| | | static_cast<int>(originalRect.top * dScaleY), |
| | | static_cast<int>(originalRect.right * dScaleX), |
| | | static_cast<int>(originalRect.bottom * dScaleY)); |
| | | |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | |
| | | if (_tcsicmp(szClassName, _T("ComboBox")) == 0) { |
| | | CComboBox* pComboBox = (CComboBox*)pWnd; |
| | | pComboBox->SetItemHeight(-1, newRect.Height()); // -1 表示ææé¡¹çé«åº¦ |
| | | } |
| | | |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | CGridCtrl* pGridCtrl = (CGridCtrl*)pWnd; |
| | | pGridCtrl->SetDefCellHeight(newRect.Height() / 21); |
| | | pGridCtrl->ExpandColumnsToFit(TRUE); |
| | | pGridCtrl->ExpandLastColumn(); |
| | | pGridCtrl->Invalidate(); |
| | | pGridCtrl->UpdateWindow(); |
| | | } |
| | | |
| | | pWnd->MoveWindow(&newRect); |
| | | AdjustControlFont(pWnd, newRect.Width(), newRect.Height()); |
| | | } |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | m_bResizing = false; |
| | | } |
| | | |
| | | void CBaseDlg::AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight) |
| | | { |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | return; |
| | | } |
| | | |
| | | int fontSize = nHeight / 2; |
| | | if (fontSize < 8) fontSize = 8; |
| | | if (fontSize > 32) fontSize = 32; |
| | | |
| | | CFont* pFont = GetOrCreateFont(fontSize); |
| | | |
| | | pWnd->SetFont(pFont); |
| | | pWnd->Invalidate(); // å·æ°æ§ä»¶æ¾ç¤º |
| | | } |
| | | |
| | | BEGIN_MESSAGE_MAP(CBaseDlg, CDialogEx) |
| | | ON_WM_SIZE() |
| | | ON_WM_GETMINMAXINFO() |
| | | ON_WM_CTLCOLOR() |
| | | END_MESSAGE_MAP() |
| | | |
| | | BOOL CBaseDlg::OnInitDialog() |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | |
| | | // è·åå½åè¯è¨ |
| | | LANGID langId = GetUserDefaultLangID(); |
| | | if (langId == LANG_CHINESE) { |
| | | // å è½½ä¸æèµæº |
| | | } |
| | | else { |
| | | // å è½½è±æèµæº |
| | | } |
| | | |
| | | // è·åå¯¹è¯æ¡çå·¥ä½åºï¼å±å¹å¯ç¨åºåï¼ |
| | | CRect screenRect, dlgRect, clientRect; |
| | | SystemParametersInfo(SPI_GETWORKAREA, 0, &screenRect, 0); |
| | | GetClientRect(&clientRect); |
| | | m_nInitialWidth = clientRect.Width(); |
| | | m_nInitialHeight = clientRect.Height(); |
| | | |
| | | // 设置é»è®¤åä½ |
| | | CFont* pDefaultFont = GetOrCreateFont(12); |
| | | |
| | | // éååçªå£ï¼æ§ä»¶ï¼ |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | int nCtrlID = pWnd->GetDlgCtrlID(); |
| | | if (nCtrlID != -1) { |
| | | // ä¿åæ§ä»¶çåå§å¸å± |
| | | CRect ctrlRect; |
| | | pWnd->GetWindowRect(&ctrlRect); |
| | | ScreenToClient(&ctrlRect); |
| | | m_mapCtrlLayouts[nCtrlID] = ctrlRect; |
| | | |
| | | // æé¤ä¸éè¦æä½çæ§ä»¶ï¼å¦èªå®ä¹æ§ä»¶ GridCtrlï¼ |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | pWnd = pWnd->GetNextWindow(); |
| | | continue; |
| | | } |
| | | |
| | | // 设置æ§ä»¶çé»è®¤åä½ |
| | | pWnd->SetFont(pDefaultFont); |
| | | } |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | |
| | | // å°å¯¹è¯æ¡å±
ä¸ |
| | | GetWindowRect(&dlgRect); |
| | | int dlgWidth = dlgRect.Width() * 2; |
| | | int dlgHeight = dlgRect.Height() * 2; |
| | | |
| | | if (dlgWidth > screenRect.Width()) { |
| | | dlgWidth = screenRect.Width(); |
| | | } |
| | | if (dlgHeight > screenRect.Height()) { |
| | | dlgHeight = screenRect.Height(); |
| | | } |
| | | |
| | | int centerX = screenRect.left + (screenRect.Width() - dlgWidth) / 2; |
| | | int centerY = screenRect.top + (screenRect.Height() - dlgHeight) / 2; |
| | | MoveWindow(centerX, centerY, dlgWidth, dlgHeight); |
| | | |
| | | return TRUE; |
| | | } |
| | | |
| | | void CBaseDlg::OnSize(UINT nType, int cx, int cy) |
| | | { |
| | | CDialogEx::OnSize(nType, cx, cy); |
| | | |
| | | if (nType == SIZE_MINIMIZED || m_mapCtrlLayouts.empty()) { |
| | | return; |
| | | } |
| | | |
| | | // æ£æ¥å°ºå¯¸å忝å¦è¶³å¤å¤§ï¼é¿å
é¢ç¹è°æ´ |
| | | //static int lastWidth = 0, lastHeight = 0; |
| | | //if (abs(cx - lastWidth) < 10 && abs(cy - lastHeight) < 10) { |
| | | // return; |
| | | //} |
| | | |
| | | //lastWidth = cx; |
| | | //lastHeight = cy; |
| | | |
| | | // è®¡ç®æ¯ä¾å¹¶è°æ´å¸å± |
| | | float dScaleX = static_cast<float>(cx) / m_nInitialWidth; |
| | | float dScaleY = static_cast<float>(cy) / m_nInitialHeight; |
| | | |
| | | AdjustControls(dScaleX, dScaleY); |
| | | } |
| | | |
| | | void CBaseDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI) |
| | | { |
| | | lpMMI->ptMinTrackSize.x = 400; |
| | | lpMMI->ptMinTrackSize.y = 300; |
| | | |
| | | CDialogEx::OnGetMinMaxInfo(lpMMI); |
| | | } |
| | | |
| | | HBRUSH CBaseDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) |
| | | { |
| | | if (g_currentTheme) { |
| | | pDC->SetBkColor(g_currentTheme->backgroundColor); |
| | | pDC->SetTextColor(g_currentTheme->textColor); |
| | | |
| | | // è¿åèæ¯ç»å· |
| | | return CreateSolidBrush(g_currentTheme->backgroundColor); |
| | | } |
| | | |
| | | return CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor); |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #pragma once |
| | | #include <memory> |
| | | #include <unordered_map> |
| | | |
| | | enum class ThemeType { |
| | | Light, // æµ
è²ä¸»é¢ |
| | | Dark // æ·±è²ä¸»é¢ |
| | | }; |
| | | |
| | | struct Theme { |
| | | COLORREF backgroundColor; |
| | | COLORREF textColor; |
| | | COLORREF buttonColor; |
| | | COLORREF borderColor; |
| | | }; |
| | | |
| | | class CBaseDlg : public CDialogEx |
| | | { |
| | | DECLARE_DYNAMIC(CBaseDlg) |
| | | |
| | | public: |
| | | CBaseDlg(UINT nID, CWnd* pPage); // æ åæé 彿° |
| | | virtual ~CBaseDlg(); // ææå½æ° |
| | | |
| | | // 主é¢ç®¡ç |
| | | void SwitchTheme(ThemeType enThemeType); // åæ¢ä¸»é¢ |
| | | |
| | | // èµæºç®¡ç |
| | | void LoadResourceLibrary(const CString& strLanguage); // å è½½èµæºåº |
| | | void UnloadResourceLibrary(); // å¸è½½èµæºåº |
| | | |
| | | // åä½ç®¡ç |
| | | CFont* GetOrCreateFont(int nFontSize); // è·åæå建åä½ |
| | | void SetDefaultFont(); // 设置é»è®¤åä½ |
| | | |
| | | // 卿æ§ä»¶ç®¡ç |
| | | BOOL AddControl(UINT nCtrlID, CWnd* pControl); // æ·»å æ§ä»¶ |
| | | BOOL RemoveControl(UINT nCtrlID); // ç§»é¤æ§ä»¶ |
| | | BOOL UpdateControlText(UINT nCtrlID, const CString& strText); // æ´æ°æ§ä»¶ææ¬ |
| | | CWnd* GetControl(UINT nCtrlID); // è·åæ§ä»¶ |
| | | |
| | | private: |
| | | void AdjustControls(float dScaleX, float dScaleY); // è°æ´æ§ä»¶å¤§å° |
| | | void AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight); // è°æ´æ§ä»¶åä½ |
| | | |
| | | private: |
| | | UINT m_nID; // å¯¹è¯æ¡ID |
| | | CWnd* m_pParent; // ç¶çªå£ |
| | | bool m_bResizing; // æ§ä»¶æ¯å¦æ£å¨è°æ´å¤§å° |
| | | int m_nInitialWidth; // å¯¹è¯æ¡åå§å®½åº¦ |
| | | int m_nInitialHeight; // å¯¹è¯æ¡åå§é«åº¦ |
| | | std::unordered_map<int, CRect> m_mapCtrlLayouts; // æ§ä»¶å¸å± |
| | | std::map<UINT, std::unique_ptr<CWnd>> m_mapControls; // æ§ä»¶éå |
| | | std::unordered_map<int, std::shared_ptr<CFont>> m_mapFonts; // æ§ä»¶åä½ |
| | | |
| | | DECLARE_MESSAGE_MAP() |
| | | public: |
| | | virtual BOOL OnInitDialog(); |
| | | afx_msg void OnSize(UINT nType, int cx, int cy); |
| | | afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); |
| | | afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); |
| | | }; |
| | |
| | | AddComponent(pEQStateMonitor1); |
| | | pEQStateMonitor1->init(); |
| | | |
| | | m_bMute = false; |
| | | |
| | | // åå§ååç§ç»ä»¶ |
| | | // 读PLC1é
ç½® |
| | |
| | | return iter->second; |
| | | } |
| | | |
| | | bool CBonder::isMute() |
| | | { |
| | | return m_bMute; |
| | | } |
| | | |
| | | void CBonder::setMute(bool bMute) |
| | | { |
| | | m_bMute = bMute; |
| | | } |
| | |
| | | int loadReady(BEQ::IUnit* pUnit, const char* pszMaterielId, const char* pszRecipeId); |
| | | int loadComplete(BEQ::IUnit* pUnit, int layer); |
| | | int unloadComplete(BEQ::IUnit* pUnit, int layer); |
| | | bool isMute(); |
| | | void setMute(bool bMute); |
| | | |
| | | public: |
| | | int writeInt(int unitId, int addr, int value); |
| | |
| | | BEQ::IEquipment* m_pEquipment; |
| | | std::map<int, CRecipe*> m_recipes; |
| | | std::string m_strCurRecipeName; |
| | | bool m_bMute; |
| | | }; |
| | | |
| | |
| | | |
| | | void CComponentPLCDlg::OnBnClickedButtonAxisSetting() |
| | | { |
| | | std::string strName = RecipeManager::getInstance().getCurrentRecipeName(); |
| | | if (strName.empty()) { |
| | | AfxMessageBox("æªéæ©é
æ¹ï¼", MB_ICONERROR); |
| | | } |
| | | |
| | | CAxisSettingsDlg axisDlg; |
| | | axisDlg.SetPLC((CPLC*)m_pContext); |
| | | axisDlg.SetRecipeName(_T("Default")); |
| | | axisDlg.SetRecipeName(strName.c_str()); |
| | | axisDlg.DoModal(); |
| | | } |
| | | |
| | |
| | | #include "Common.h" |
| | | #include "ToolUnits.h" |
| | | |
| | | #define PAGE_SIZE 20 |
| | | |
| | | // CPageAlarm å¯¹è¯æ¡ |
| | | |
| | |
| | | m_crBkgnd = PAGE_BACKGROUND_COLOR; |
| | | m_hbrBkgnd = nullptr; |
| | | m_pObserver = nullptr; |
| | | |
| | | m_strKeyword = ""; |
| | | m_nCurPage = 0; |
| | | m_nTotalPages = 0; |
| | | m_nDateTimeFlag = 0; |
| | | |
| | | memset(m_szTimeStart, 0, sizeof(m_szTimeStart)); |
| | | memset(m_szTimeEnd, 0, sizeof(m_szTimeEnd)); |
| | | m_szTimeStart[0] = '\0'; |
| | | m_szTimeEnd[0] = '\0'; |
| | | } |
| | | |
| | | CPageAlarm::~CPageAlarm() |
| | |
| | | |
| | | void CPageAlarm::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | DDX_Control(pDX, IDC_DATETIMEPICKER_START, m_dateTimeStart); |
| | | DDX_Control(pDX, IDC_DATETIMEPICKER_END, m_dateTimeEnd); |
| | | CDialogEx::DoDataExchange(pDX); |
| | | } |
| | | |
| | |
| | | ON_WM_CTLCOLOR() |
| | | ON_WM_DESTROY() |
| | | ON_WM_SIZE() |
| | | ON_CBN_SELCHANGE(IDC_COMBO_DATETIME, &CPageAlarm::OnCbnSelchangeComboDatetime) |
| | | ON_BN_CLICKED(IDC_BUTTON_SEARCH, &CPageAlarm::OnBnClickedButtonSearch) |
| | | ON_BN_CLICKED(IDC_BUTTON_EXPORT, &CPageAlarm::OnBnClickedButtonExport) |
| | | ON_BN_CLICKED(IDC_BUTTON_PREV_PAGE, &CPageAlarm::OnBnClickedButtonPrevPage) |
| | | ON_BN_CLICKED(IDC_BUTTON_NEXT_PAGE, &CPageAlarm::OnBnClickedButtonNextPage) |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | |
| | | CDialogEx::OnInitDialog(); |
| | | InitRxWindow(); |
| | | |
| | | // ä¸ææ¡æ§ä»¶ |
| | | CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_DATETIME); |
| | | pComboBox->AddString(_T("ä¸é")); |
| | | pComboBox->AddString(_T("ä»å¤©")); |
| | | pComboBox->AddString(_T("ä¸å¤©å
")); |
| | | pComboBox->AddString(_T("æ¬æ")); |
| | | pComboBox->AddString(_T("ä»å¹´")); |
| | | pComboBox->AddString(_T("èªå®ä¹")); |
| | | pComboBox->SetCurSel(0); |
| | | |
| | | // æ¥ææ§ä»¶ |
| | | m_dateTimeStart.EnableWindow(FALSE); |
| | | m_dateTimeEnd.EnableWindow(FALSE); |
| | | |
| | | // æ¥è¡¨æ§ä»¶ |
| | | CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM); |
| | |
| | | pListCtrl->InsertColumn(4, _T("åçæ¶é´"), LVCFMT_LEFT, 180); |
| | | pListCtrl->InsertColumn(5, _T("è§£é¤æ¶é´"), LVCFMT_LEFT, 180); |
| | | |
| | | // è®¡ç®æ»é¡µæ° |
| | | int totalRecords = AlarmManager::getInstance().getTotalAlarmCount(m_strKeyword, m_szTimeStart, m_szTimeEnd); |
| | | m_nTotalPages = (totalRecords + PAGE_SIZE - 1) / PAGE_SIZE; |
| | | m_nCurPage = 1; |
| | | |
| | | Resize(); |
| | | LoadAlarms(); |
| | |
| | | GetClientRect(&rcClient); |
| | | |
| | | pItem = GetDlgItem(IDC_LIST_ALARM); |
| | | pItem->MoveWindow(12, 12, rcClient.Width() - 24, rcClient.Height() - 24); |
| | | pItem->MoveWindow(12, 52, rcClient.Width() - 24, rcClient.Height() - 64); |
| | | } |
| | | |
| | | void CPageAlarm::LoadAlarms() |
| | | { |
| | | CAlarmMonitor* pMonitor = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent(ALARM_MONITOR); |
| | | |
| | | |
| | | // å½åæ£å¨åççæ¥è¦ |
| | | pMonitor->Lock(); |
| | |
| | | } |
| | | pMonitor->Unlock(); |
| | | |
| | | |
| | | // è·åå岿¥è¦æ°æ® |
| | | auto vecData = AlarmManager::getInstance().getAllAlarms(); |
| | | |
| | | // å¡«å
æ°æ® |
| | | CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM); |
| | | for (auto item : vecData) { |
| | | pListCtrl->InsertItem(0, _T("")); |
| | | pListCtrl->SetItemText(0, 1, item[0].c_str()); |
| | | pListCtrl->SetItemText(0, 2, item[1].c_str()); |
| | | pListCtrl->SetItemText(0, 3, item[2].c_str()); |
| | | pListCtrl->SetItemText(0, 4, item[3].c_str()); |
| | | } |
| | | // å·æ°å岿¥è¦æ°æ® |
| | | m_nCurPage = 1; |
| | | UpdatePageData(); |
| | | } |
| | | |
| | | void CPageAlarm::AddAlarm(CAlarmMonitor* pMonitor, CAlarm* pAlarm) |
| | |
| | | } |
| | | } |
| | | |
| | | void CPageAlarm::UpdatePageData() |
| | | { |
| | | // æ ¹æ®è¿æ»¤æ¡ä»¶å è½½æ°æ® |
| | | auto vecData = AlarmManager::getInstance().getFilteredAlarms(m_strKeyword, m_szTimeStart, m_szTimeEnd, m_nCurPage, PAGE_SIZE); |
| | | |
| | | // å¡«å
æ°æ®å°æ§ä»¶ |
| | | CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM); |
| | | FillDataToListCtrl(pListCtrl, vecData); |
| | | |
| | | // æ´æ°å页æ§ä»¶ï¼é¡µæ°åæé®ï¼ |
| | | UpdatePageControls(); |
| | | } |
| | | |
| | | void CPageAlarm::UpdatePageControls() |
| | | { |
| | | // æ´æ°åé¡µä¿¡æ¯ |
| | | CString strPage; |
| | | strPage.Format(_T("第 %d 页"), m_nCurPage); |
| | | SetDlgItemText(IDC_LABEL_PAGE_NUMBER, strPage); |
| | | |
| | | // å¯ç¨/ç¦ç¨ç¿»é¡µæé® |
| | | GetDlgItem(IDC_BUTTON_PREV_PAGE)->EnableWindow(m_nCurPage > 1); |
| | | GetDlgItem(IDC_BUTTON_NEXT_PAGE)->EnableWindow(m_nCurPage < m_nTotalPages); |
| | | } |
| | | |
| | | void CPageAlarm::FillDataToListCtrl(CListCtrl* pListCtrl, const std::vector<std::vector<std::string>>& vecData) |
| | | { |
| | | // æ¸
空å½åCListCtrlä¸çææé¡¹ |
| | | for (int i = 0; i < pListCtrl->GetItemCount(); i++) { |
| | | CAlarm* pAlarm = (CAlarm*)pListCtrl->GetItemData(i); |
| | | if (pAlarm != nullptr) { |
| | | pAlarm->release(); |
| | | } |
| | | } |
| | | pListCtrl->DeleteAllItems(); |
| | | |
| | | // éåæ°æ®å¹¶æå
¥å°CListCtrlä¸ |
| | | for (const auto& item : vecData) { |
| | | int nItem = pListCtrl->InsertItem(pListCtrl->GetItemCount(), _T("")); // æå
¥æ°è¡ |
| | | pListCtrl->SetItemText(nItem, 1, item[0].c_str()); // 设置第ä¸åçææ¬ |
| | | pListCtrl->SetItemText(nItem, 2, item[1].c_str()); // 设置第äºåçææ¬ |
| | | pListCtrl->SetItemText(nItem, 3, item[2].c_str()); // 设置第ä¸åçææ¬ |
| | | pListCtrl->SetItemText(nItem, 4, item[3].c_str()); // 设置第ååçææ¬ |
| | | } |
| | | } |
| | | |
| | | BOOL CPageAlarm::DestroyWindow() |
| | | { |
| | | CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM); |
| | |
| | | |
| | | return CDialogEx::DestroyWindow(); |
| | | } |
| | | |
| | | void CPageAlarm::OnCbnSelchangeComboDatetime() |
| | | { |
| | | CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_DATETIME); |
| | | int nIndex = pComboBox->GetCurSel(); |
| | | int nCount = pComboBox->GetCount(); |
| | | m_dateTimeStart.EnableWindow(nIndex == nCount - 1); |
| | | m_dateTimeEnd.EnableWindow(nIndex == nCount - 1); |
| | | } |
| | | |
| | | void CPageAlarm::OnBnClickedButtonSearch() |
| | | { |
| | | // è·åå
³é®å |
| | | CString cstrKeyword; |
| | | GetDlgItemText(IDC_EDIT_KEYWORD, cstrKeyword); |
| | | m_strKeyword = CT2A(cstrKeyword); |
| | | |
| | | // è·åæ¥æ |
| | | CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_DATETIME); |
| | | m_nDateTimeFlag = pComboBox->GetCurSel(); |
| | | if (m_nDateTimeFlag == 0) { |
| | | memset(m_szTimeStart, 0, sizeof(m_szTimeStart)); |
| | | memset(m_szTimeEnd, 0, sizeof(m_szTimeEnd)); |
| | | m_szTimeStart[0] = '\0'; |
| | | m_szTimeEnd[0] = '\0'; |
| | | } |
| | | else { |
| | | CTime time = CTime::GetCurrentTime(); |
| | | if (m_nDateTimeFlag == 1) { |
| | | // ä»å¤© |
| | | sprintf_s(m_szTimeStart, 64, "%d-%02d-%02d 00:00:00", time.GetYear(), time.GetMonth(), time.GetDay()); |
| | | sprintf_s(m_szTimeEnd, 64, "%d-%02d-%02d 23:59:59", time.GetYear(), time.GetMonth(), time.GetDay()); |
| | | } |
| | | else if (m_nDateTimeFlag == 2) { |
| | | // 7天å
|
| | | CTime time2 = time - CTimeSpan(7, 0, 0, 0); |
| | | sprintf_s(m_szTimeStart, 64, "%d-%02d-%02d 00:00:00", time2.GetYear(), time2.GetMonth(), time2.GetDay()); |
| | | sprintf_s(m_szTimeEnd, 64, "%d-%02d-%02d 23:59:59", time.GetYear(), time.GetMonth(), time.GetDay()); |
| | | } |
| | | else if (m_nDateTimeFlag == 3) { |
| | | // æ¬æ |
| | | sprintf_s(m_szTimeStart, 64, "%d-%02d-01 00:00:00", time.GetYear(), time.GetMonth()); |
| | | sprintf_s(m_szTimeEnd, 64, "%d-%02d-%02d 23:59:59", time.GetYear(), time.GetMonth(), time.GetDay()); |
| | | } |
| | | else if (m_nDateTimeFlag == 4) { |
| | | // ä»å¹´ |
| | | sprintf_s(m_szTimeStart, 64, "%d-01-01 00:00:00", time.GetYear()); |
| | | sprintf_s(m_szTimeEnd, 64, "%d-12-31 23:59:59", time.GetYear()); |
| | | } |
| | | else if (m_nDateTimeFlag == 5) { |
| | | // èªå®ä¹ |
| | | SYSTEMTIME t1, t2; |
| | | m_dateTimeStart.GetTime(&t1); |
| | | m_dateTimeEnd.GetTime(&t2); |
| | | |
| | | sprintf_s(m_szTimeStart, 64, "%d-%02d-%02d %02d:%02d:%02d", |
| | | t1.wYear, t1.wMonth, t1.wDay, t1.wHour, t1.wMinute, t1.wSecond); |
| | | sprintf_s(m_szTimeEnd, 64, "%d-%02d-%02d %02d:%02d:%02d", |
| | | t2.wYear, t2.wMonth, t2.wDay, t2.wHour, t2.wMinute, t2.wSecond); |
| | | } |
| | | } |
| | | |
| | | // è®¡ç®æ»é¡µæ° |
| | | int totalRecords = AlarmManager::getInstance().getTotalAlarmCount(m_strKeyword, m_szTimeStart, m_szTimeEnd); |
| | | m_nTotalPages = (totalRecords + PAGE_SIZE - 1) / PAGE_SIZE; |
| | | m_nCurPage = 1; |
| | | |
| | | UpdatePageData(); // è°ç¨åé¡µæ´æ°å½æ° |
| | | } |
| | | |
| | | void CPageAlarm::OnBnClickedButtonExport() |
| | | { |
| | | CFileDialog fileDialog(FALSE, "csv", "", OFN_HIDEREADONLY, "csv.files(*.csv)|*.csv||"); |
| | | if (fileDialog.DoModal() != IDOK) { |
| | | return; |
| | | } |
| | | |
| | | CStdioFile file; |
| | | if (!file.Open(fileDialog.GetPathName(), CFile::modeCreate | CFile::modeWrite)) { |
| | | AfxMessageBox("å建æä»¶å¤±è´¥ï¼"); |
| | | } |
| | | |
| | | int nSubItemCount = 0; |
| | | CString strSubItem, strHeader, strRow; |
| | | char szItem[256]; |
| | | HDITEM hdItem[35]; |
| | | for (int i = 0; i < 35; i++) { |
| | | hdItem[i].pszText = szItem; |
| | | hdItem[i].cchTextMax = 256; |
| | | hdItem[i].mask = HDI_TEXT | HDI_WIDTH; |
| | | } |
| | | |
| | | // å
读表头 |
| | | CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM); |
| | | CHeaderCtrl* pHeader = pListCtrl->GetHeaderCtrl(); |
| | | nSubItemCount = pHeader->GetItemCount(); |
| | | ASSERT(nSubItemCount <= 35); |
| | | for (int i = 0; i < pHeader->GetItemCount(); i++) { |
| | | pHeader->GetItem(i, &hdItem[i]); |
| | | if (hdItem[i].cxy > 0) { |
| | | if (!strHeader.IsEmpty()) { |
| | | strHeader.Append(","); |
| | | } |
| | | strHeader.Append(CString(hdItem[i].pszText)); |
| | | } |
| | | } |
| | | strHeader.Append("\n"); |
| | | file.WriteString(strHeader); |
| | | |
| | | // åè¡¨æ ¼å
容 |
| | | int count = pListCtrl->GetItemCount(); |
| | | for (int i = 0; i < count; i++) { |
| | | strRow.Empty(); |
| | | for (int j = 0; j < nSubItemCount; j++) { |
| | | if (hdItem[j].cxy > 0) { |
| | | if (!strRow.IsEmpty()) { |
| | | strRow.Append(","); |
| | | } |
| | | CString strTemp = pListCtrl->GetItemText(i, j); |
| | | strTemp.Replace("* ", ""); |
| | | strRow.Append(strTemp); |
| | | } |
| | | } |
| | | strRow.Append("\n"); |
| | | file.WriteString(strRow); |
| | | } |
| | | |
| | | file.Close(); |
| | | } |
| | | |
| | | void CPageAlarm::OnBnClickedButtonPrevPage() |
| | | { |
| | | // ç¹å»ä¸ä¸é¡µ |
| | | m_nCurPage--; |
| | | UpdatePageData(); // è°ç¨åé¡µæ´æ°å½æ° |
| | | } |
| | | |
| | | void CPageAlarm::OnBnClickedButtonNextPage() |
| | | { |
| | | // ç¹å»ä¸ä¸é¡µ |
| | | m_nCurPage++; |
| | | UpdatePageData(); // è°ç¨åé¡µæ´æ°å½æ° |
| | | } |
| | |
| | | void LoadAlarms(); |
| | | void AddAlarm(CAlarmMonitor* pMonitor, CAlarm* pAlarm); |
| | | void UpdateAlarm(CAlarmMonitor* pMonitor, CAlarm* pAlarm); |
| | | void UpdatePageData(); |
| | | void UpdatePageControls(); |
| | | void FillDataToListCtrl(CListCtrl* pListCtrl, const std::vector<std::vector<std::string>>& vecData); |
| | | |
| | | private: |
| | | COLORREF m_crBkgnd; |
| | | HBRUSH m_hbrBkgnd; |
| | | IObserver* m_pObserver; |
| | | |
| | | // å
³é®å |
| | | std::string m_strKeyword; |
| | | |
| | | // 页ç |
| | | int m_nCurPage; |
| | | int m_nTotalPages; |
| | | |
| | | // æ¥æ |
| | | int m_nDateTimeFlag; |
| | | char m_szTimeStart[64]; |
| | | char m_szTimeEnd[64]; |
| | | |
| | | // æ§ä»¶ |
| | | CDateTimeCtrl m_dateTimeStart; |
| | | CDateTimeCtrl m_dateTimeEnd; |
| | | |
| | | |
| | | // å¯¹è¯æ¡æ°æ® |
| | |
| | | afx_msg void OnDestroy(); |
| | | afx_msg void OnSize(UINT nType, int cx, int cy); |
| | | virtual BOOL DestroyWindow(); |
| | | afx_msg void OnCbnSelchangeComboDatetime(); |
| | | afx_msg void OnBnClickedButtonSearch(); |
| | | afx_msg void OnBnClickedButtonExport(); |
| | | afx_msg void OnBnClickedButtonPrevPage(); |
| | | afx_msg void OnBnClickedButtonNextPage(); |
| | | }; |
| | |
| | | m_hbrBkgnd = nullptr; |
| | | m_nPanelWidth = int((double)GetSystemMetrics(SM_CXSCREEN) * 0.25); |
| | | m_pAccordionWnd = nullptr; |
| | | m_pPageRemoteEqs = nullptr; |
| | | //m_pPageRemoteEqs = nullptr; |
| | | m_pPageMain = nullptr; |
| | | m_pPageComponents = nullptr; |
| | | } |
| | | |
| | |
| | | m_pAccordionWnd->Setpadding(PADDING_BOTTOM, 2); |
| | | m_pAccordionWnd->LoadExpandIcon(strExpandIcon, strCloseIcon); |
| | | |
| | | m_pPageRemoteEqs = new CProjectPageRemoteEqs(); |
| | | m_pPageRemoteEqs->Create(IDD_PROJECT_PAGE_REMOTEEQS, GetDlgItem(IDC_ACCORDION_WND1)); |
| | | m_pPageRemoteEqs->ShowWindow(SW_SHOW); |
| | | m_pAccordionWnd->AddItem("è¿ç¨è®¾å¤", m_pPageRemoteEqs, 0, TRUE, TRUE); |
| | | //m_pPageRemoteEqs = new CProjectPageRemoteEqs(); |
| | | //m_pPageRemoteEqs->Create(IDD_PROJECT_PAGE_REMOTEEQS, GetDlgItem(IDC_ACCORDION_WND1)); |
| | | //m_pPageRemoteEqs->ShowWindow(SW_SHOW); |
| | | //m_pAccordionWnd->AddItem("è¿ç¨è®¾å¤", m_pPageRemoteEqs, 0, TRUE, TRUE); |
| | | |
| | | m_pPageMain = new CProjectPageMain(); |
| | | m_pPageMain->SetPLC(theApp.m_model.getBonder().getPLC("PLC(1)")); |
| | | m_pPageMain->Create(IDD_PROJECT_PAGE_MAIN, GetDlgItem(IDC_ACCORDION_WND1)); |
| | | m_pPageMain->ShowWindow(SW_SHOW); |
| | | m_pAccordionWnd->AddItem("主页é¢", m_pPageMain, 0, TRUE, TRUE); |
| | | |
| | | m_pPageComponents = new CProjectPageComponents(); |
| | | m_pPageComponents->Create(IDD_PROJECT_PAGE_COMPONENTS, GetDlgItem(IDC_ACCORDION_WND1)); |
| | |
| | | m_pPageComponents = nullptr; |
| | | } |
| | | |
| | | if (m_pPageRemoteEqs != nullptr) { |
| | | m_pPageRemoteEqs->DestroyWindow(); |
| | | delete m_pPageRemoteEqs; |
| | | m_pPageRemoteEqs = nullptr; |
| | | //if (m_pPageRemoteEqs != nullptr) { |
| | | // m_pPageRemoteEqs->DestroyWindow(); |
| | | // delete m_pPageRemoteEqs; |
| | | // m_pPageRemoteEqs = nullptr; |
| | | //} |
| | | |
| | | if (m_pPageMain != nullptr) { |
| | | m_pPageMain->DestroyWindow(); |
| | | delete m_pPageMain; |
| | | m_pPageMain = nullptr; |
| | | } |
| | | } |
| | | |
| | |
| | | #pragma once |
| | | #include "VerticalLine.h" |
| | | #include "CProjectPageRemoteEqs.h" |
| | | //#include "CProjectPageRemoteEqs.h" |
| | | #include "CProjectPageMain.h" |
| | | #include "CProjectPageComponents.h" |
| | | #include "AccordionWnd.h" |
| | | |
| | |
| | | HBRUSH m_hbrBkgnd; |
| | | int m_nPanelWidth; |
| | | CAccordionWnd* m_pAccordionWnd; |
| | | CProjectPageRemoteEqs* m_pPageRemoteEqs; |
| | | //CProjectPageRemoteEqs* m_pPageRemoteEqs; |
| | | CProjectPageMain* m_pPageMain; |
| | | CProjectPageComponents* m_pPageComponents; |
| | | |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // CProjectPageMain.cpp: å®ç°æä»¶ |
| | | // |
| | | |
| | | #include "stdafx.h" |
| | | #include "BondEq.h" |
| | | #include "afxdialogex.h" |
| | | #include "CProjectPageMain.h" |
| | | #include "ToolUnits.h" |
| | | |
| | | #define TIMER_INIT 1 |
| | | #define TIMER_READ_PLC_DATA 2 |
| | | |
| | | #define ID_MSG_UPDATA_DATA_TO_UI WM_USER + 101 |
| | | |
| | | // CProjectPageMain å¯¹è¯æ¡ |
| | | |
| | | IMPLEMENT_DYNAMIC(CProjectPageMain, CDialogEx) |
| | | |
| | | CProjectPageMain::CProjectPageMain(CWnd* pParent /*=nullptr*/) |
| | | : CDialogEx(IDD_PROJECT_PAGE_MAIN, pParent) |
| | | { |
| | | m_crBkgnd = PROPAGE_BACKGROUND_COLOR; |
| | | m_hbrBkgnd = nullptr; |
| | | m_pObserver = nullptr; |
| | | |
| | | nVelocityRatio = 0.0; |
| | | dTactTime = 0.0; |
| | | nDayShiftCapacity = 0; |
| | | nNightShiftCapacity = 0; |
| | | } |
| | | |
| | | CProjectPageMain::~CProjectPageMain() |
| | | { |
| | | } |
| | | |
| | | void CProjectPageMain::SetPLC(CPLC* pPLC) |
| | | { |
| | | ASSERT(pPLC); |
| | | m_pPLC = pPLC; |
| | | } |
| | | |
| | | void CProjectPageMain::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | CDialogEx::DoDataExchange(pDX); |
| | | } |
| | | |
| | | void CProjectPageMain::HandleOperation(OperationType eOpType) |
| | | { |
| | | WriteOperationDataToPLC(eOpType, true); |
| | | Sleep(200); |
| | | WriteOperationDataToPLC(eOpType, false); |
| | | } |
| | | |
| | | void CProjectPageMain::WriteOperationDataToPLC(OperationType eOpType, bool bPressed) |
| | | { |
| | | if (m_pPLC == nullptr || !m_pPLC->isConnected()) { |
| | | return; |
| | | } |
| | | |
| | | MC::SOFT_COMPONENT enComponent = MC::M; |
| | | int nStartAddress = 1000; |
| | | |
| | | // æ ¹æ®æä½ç±»å计ç®ç®æ å°å |
| | | char szWrite[4] = { 0x0, 0x0, 0x0, 0x0 }; |
| | | switch (eOpType) { |
| | | case OperationType::RUN: |
| | | nStartAddress = 1002; // RUN ä¿¡å·å°å M1002,éªå¨ä¿¡æ¯ M1103 |
| | | szWrite[0] = bPressed ? 0x01 : 0; |
| | | break; |
| | | case OperationType::AUTO: |
| | | nStartAddress = 1000; // AUTO ä¿¡å·å°å M1000,éªå¨ä¿¡æ¯ M1100 |
| | | szWrite[0] = bPressed ? 0x01 : 0; |
| | | break; |
| | | case OperationType::PUASE: |
| | | nStartAddress = 1004; // PUASE ä¿¡å·å°å M1004,éªå¨ä¿¡æ¯ M1104 |
| | | szWrite[0] = bPressed ? 0x01 : 0; |
| | | break; |
| | | case OperationType::MANUAL: |
| | | nStartAddress = 1001; // MANUAL ä¿¡å·å°å M1001,éªå¨ä¿¡æ¯ M1100 |
| | | szWrite[0] = bPressed ? 0x01 : 0; |
| | | break; |
| | | case OperationType::MUTE: |
| | | nStartAddress = 1003; // MUTE ä¿¡å·å°å M1003,éªå¨ä¿¡æ¯ M1003 |
| | | szWrite[0] = bPressed ? 0x01 : 0; |
| | | break; |
| | | case OperationType::OPR: |
| | | nStartAddress = 1050; // OPR ä¿¡å·å°å M1050,éªå¨ä¿¡æ¯ M1150 |
| | | szWrite[0] = bPressed ? 0x01 : 0; |
| | | break; |
| | | case OperationType::STOP: |
| | | nStartAddress = 1114; // STOP ä¿¡å·å°å M1114,éªå¨ä¿¡æ¯ M1114 |
| | | szWrite[0] = bPressed ? 0x01 : 0; |
| | | break; |
| | | default: |
| | | AfxMessageBox(_T("æªç¥æä½ç±»åï¼")); |
| | | return; |
| | | } |
| | | |
| | | // å PLC åå
¥ä¿¡å· |
| | | m_pPLC->writeData(enComponent, nStartAddress, szWrite, 2, [eOpType, nStartAddress, bPressed](IMcChannel* pChannel, int nAddr, DWORD nValue, int nFlag) { |
| | | if (nFlag == 0) { |
| | | TRACE("æä½æåï¼ç±»å=%dï¼å°å=%dï¼å¼=%d\n", static_cast<int>(eOpType), nAddr, bPressed); |
| | | } |
| | | else { |
| | | TRACE("æä½å¤±è´¥ï¼ç±»å=%dï¼å°å=%dï¼é误ç =%d\n", static_cast<int>(eOpType), nAddr, nFlag); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | void CProjectPageMain::ReadPLCDataToUI() |
| | | { |
| | | ASSERT(m_pPLC->isConnected()); |
| | | |
| | | // æ»ä»»å¡æ° |
| | | int nPendingTasks = 5; |
| | | |
| | | auto createReadTask = [this, &nPendingTasks](MC::SOFT_COMPONENT type, int nAddr, auto onProcessData) { |
| | | return [this, &nPendingTasks, onProcessData](IMcChannel* pChannel, int nAddr, char* pData, unsigned int nDataSize, int nFlag) { |
| | | if (nDataSize == 2 && nFlag == 0 && ::IsWindow(m_hWnd)) { |
| | | onProcessData(CToolUnits::toInt16(&pData[0])); |
| | | } |
| | | |
| | | // ä»»å¡å®æï¼åå°è®¡æ° |
| | | if (--nPendingTasks == 0) { |
| | | PostMessage(ID_MSG_UPDATA_DATA_TO_UI); |
| | | } |
| | | }; |
| | | }; |
| | | |
| | | m_pPLC->readData(MC::M, 1003, 2, createReadTask(MC::M, 1003, [this](int nValue) { |
| | | theApp.m_model.getBonder().setMute(nValue != 0); |
| | | })); |
| | | |
| | | m_pPLC->readData(MC::D, 530, 2, createReadTask(MC::D, 530, [this](int nValue) { |
| | | nVelocityRatio = static_cast<unsigned int>(nValue); |
| | | })); |
| | | |
| | | m_pPLC->readData(MC::ZR, 1500, 2, createReadTask(MC::ZR, 1500, [this](int nValue) { |
| | | dTactTime = nValue; |
| | | })); |
| | | |
| | | m_pPLC->readData(MC::ZR, 2012, 2, createReadTask(MC::ZR, 2012, [this](int nValue) { |
| | | nDayShiftCapacity = nValue; |
| | | })); |
| | | |
| | | m_pPLC->readData(MC::ZR, 2027, 2, createReadTask(MC::ZR, 2027, [this](int nValue) { |
| | | nNightShiftCapacity = nValue; |
| | | })); |
| | | } |
| | | |
| | | BEGIN_MESSAGE_MAP(CProjectPageMain, CDialogEx) |
| | | ON_WM_CTLCOLOR() |
| | | ON_WM_DESTROY() |
| | | ON_WM_SIZE() |
| | | ON_WM_TIMER() |
| | | ON_WM_CLOSE() |
| | | ON_BN_CLICKED(IDC_BUTTON_ACTIVATE, &CProjectPageMain::OnBnClickedButtonActivate) |
| | | ON_BN_CLICKED(IDC_BUTTON_AUTO, &CProjectPageMain::OnBnClickedButtonAuto) |
| | | ON_BN_CLICKED(IDC_BUTTON_PUASE, &CProjectPageMain::OnBnClickedButtonPuase) |
| | | ON_BN_CLICKED(IDC_BUTTON_MANUAL_OPERATION, &CProjectPageMain::OnBnClickedButtonManualOperation) |
| | | ON_BN_CLICKED(IDC_BUTTON_SOUND_OFF, &CProjectPageMain::OnBnClickedButtonSoundOff) |
| | | ON_BN_CLICKED(IDC_BUTTON_RESETTING, &CProjectPageMain::OnBnClickedButtonResetting) |
| | | ON_BN_CLICKED(IDC_BUTTON_STOP, &CProjectPageMain::OnBnClickedButtonStop) |
| | | ON_MESSAGE(ID_MSG_UPDATA_DATA_TO_UI, &CProjectPageMain::OnUpdateDataToUI) |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | | // CProjectPageMain æ¶æ¯å¤çç¨åº |
| | | |
| | | void CProjectPageMain::InitRxWindows() |
| | | { |
| | | /* code */ |
| | | // 订é
æ°æ® |
| | | IRxWindows* pRxWindows = RX_GetRxWindows(); |
| | | pRxWindows->enableLog(5); |
| | | if (m_pObserver == NULL) { |
| | | m_pObserver = pRxWindows->allocObserver([&](IAny* pAny) -> void { |
| | | // onNext |
| | | pAny->addRef(); |
| | | int code = pAny->getCode(); |
| | | //if (true) { |
| | | |
| | | //} |
| | | pAny->release(); |
| | | }, [&]() -> void { |
| | | // onComplete |
| | | }, [&](IThrowable* pThrowable) -> void { |
| | | // onErrorm |
| | | pThrowable->printf(); |
| | | }); |
| | | |
| | | theApp.m_model.getObservable()->observeOn(pRxWindows->mainThread()) |
| | | ->subscribe(m_pObserver); |
| | | } |
| | | } |
| | | |
| | | BOOL CProjectPageMain::OnInitDialog() |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | |
| | | InitRxWindows(); |
| | | SetTimer(TIMER_READ_PLC_DATA, 500, nullptr); |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | // å¼å¸¸: OCX 屿§é¡µåºè¿å FALSE |
| | | } |
| | | |
| | | HBRUSH CProjectPageMain::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) |
| | | { |
| | | HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor); |
| | | |
| | | if (nCtlColor == CTLCOLOR_STATIC) { |
| | | pDC->SetBkColor(m_crBkgnd); |
| | | } |
| | | |
| | | if (m_hbrBkgnd == nullptr) { |
| | | m_hbrBkgnd = CreateSolidBrush(m_crBkgnd); |
| | | } |
| | | |
| | | return m_hbrBkgnd; |
| | | } |
| | | |
| | | void CProjectPageMain::OnDestroy() |
| | | { |
| | | CDialogEx::OnDestroy(); |
| | | |
| | | if (m_hbrBkgnd != nullptr) { |
| | | ::DeleteObject(m_hbrBkgnd); |
| | | } |
| | | |
| | | ASSERT(m_pObserver != NULL); |
| | | m_pObserver->unsubscribe(); |
| | | m_pObserver = NULL; |
| | | } |
| | | |
| | | void CProjectPageMain::OnSize(UINT nType, int cx, int cy) |
| | | { |
| | | CDialogEx::OnSize(nType, cx, cy); |
| | | |
| | | CRect rcClient; |
| | | GetClientRect(&rcClient); |
| | | } |
| | | |
| | | void CProjectPageMain::OnTimer(UINT_PTR nIDEvent) |
| | | { |
| | | if (TIMER_READ_PLC_DATA == nIDEvent) { |
| | | ASSERT(m_pPLC); |
| | | |
| | | if (m_pPLC != nullptr && m_pPLC->isConnected()) { |
| | | ReadPLCDataToUI(); |
| | | } |
| | | } |
| | | |
| | | CDialogEx::OnTimer(nIDEvent); |
| | | } |
| | | |
| | | void CProjectPageMain::OnClose() |
| | | { |
| | | // TODO: 卿¤æ·»å æ¶æ¯å¤çç¨åºä»£ç å/æè°ç¨é»è®¤å¼ |
| | | KillTimer(TIMER_READ_PLC_DATA); |
| | | |
| | | CDialogEx::OnClose(); |
| | | } |
| | | |
| | | void CProjectPageMain::OnBnClickedButtonActivate() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | | HandleOperation(OperationType::RUN); |
| | | } |
| | | |
| | | void CProjectPageMain::OnBnClickedButtonAuto() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | | HandleOperation(OperationType::AUTO); |
| | | } |
| | | |
| | | void CProjectPageMain::OnBnClickedButtonPuase() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | | HandleOperation(OperationType::PUASE); |
| | | } |
| | | |
| | | void CProjectPageMain::OnBnClickedButtonManualOperation() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | | HandleOperation(OperationType::MANUAL); |
| | | } |
| | | |
| | | void CProjectPageMain::OnBnClickedButtonSoundOff() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | | bool bMute = theApp.m_model.getBonder().isMute(); |
| | | WriteOperationDataToPLC(OperationType::MUTE, !bMute); |
| | | } |
| | | |
| | | void CProjectPageMain::OnBnClickedButtonResetting() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | | HandleOperation(OperationType::OPR); |
| | | } |
| | | |
| | | void CProjectPageMain::OnBnClickedButtonStop() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | | HandleOperation(OperationType::STOP); |
| | | } |
| | | |
| | | LRESULT CProjectPageMain::OnUpdateDataToUI(WPARAM wParam, LPARAM lParam) |
| | | { |
| | | CString strText; |
| | | strText.Format(_T("%d %s"), nVelocityRatio, _T("%")); |
| | | GetDlgItem(IDC_EDIT_VELOCITY_RATIO)->SetWindowText(strText); |
| | | |
| | | strText.Format(_T("%.2f"), dTactTime); |
| | | GetDlgItem(IDC_EDIT_TACT_TIME)->SetWindowText(strText); |
| | | |
| | | SetDlgItemInt(IDC_EDIT_DAY_SHIFT_CAPACITY, nDayShiftCapacity); |
| | | SetDlgItemInt(IDC_EDIT_NIGHT_SHIFT_CAPACITY, nNightShiftCapacity); |
| | | |
| | | return 0; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #pragma once |
| | | #include "afxdialogex.h" |
| | | |
| | | // CProjectPageMain å¯¹è¯æ¡ |
| | | |
| | | enum class OperationType { |
| | | RUN = 0, // å¯å¨ |
| | | AUTO, // èªå¨ |
| | | PUASE, // æå |
| | | MANUAL, // æå¨ |
| | | MUTE, // éé³ |
| | | OPR, // å¤ä½ |
| | | STOP // 忢 |
| | | }; |
| | | |
| | | class CProjectPageMain : public CDialogEx |
| | | { |
| | | DECLARE_DYNAMIC(CProjectPageMain) |
| | | |
| | | public: |
| | | CProjectPageMain(CWnd* pParent = nullptr); // æ åæé 彿° |
| | | virtual ~CProjectPageMain(); |
| | | |
| | | public: |
| | | void SetPLC(CPLC* pPLC); |
| | | |
| | | private: |
| | | void InitRxWindows(); |
| | | void HandleOperation(OperationType eOpType); |
| | | void WriteOperationDataToPLC(OperationType eOpType, bool bPressed); |
| | | void ReadPLCDataToUI(); |
| | | |
| | | private: |
| | | COLORREF m_crBkgnd; |
| | | HBRUSH m_hbrBkgnd; |
| | | IObserver* m_pObserver; |
| | | CPLC* m_pPLC; |
| | | |
| | | int nVelocityRatio; // éåº¦æ¯ |
| | | double dTactTime; // 卿æ¶é´ |
| | | int nDayShiftCapacity; |
| | | int nNightShiftCapacity; |
| | | |
| | | // å¯¹è¯æ¡æ°æ® |
| | | #ifdef AFX_DESIGN_TIME |
| | | enum { IDD = IDD_PROJECT_PAGE_MAIN }; |
| | | #endif |
| | | |
| | | protected: |
| | | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV æ¯æ |
| | | |
| | | DECLARE_MESSAGE_MAP() |
| | | public: |
| | | virtual BOOL OnInitDialog(); |
| | | afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); |
| | | afx_msg void OnDestroy(); |
| | | afx_msg void OnSize(UINT nType, int cx, int cy); |
| | | afx_msg void OnTimer(UINT_PTR nIDEvent); |
| | | afx_msg void OnClose(); |
| | | afx_msg void OnBnClickedButtonActivate(); |
| | | afx_msg void OnBnClickedButtonAuto(); |
| | | afx_msg void OnBnClickedButtonPuase(); |
| | | afx_msg void OnBnClickedButtonManualOperation(); |
| | | afx_msg void OnBnClickedButtonSoundOff(); |
| | | afx_msg void OnBnClickedButtonResetting(); |
| | | afx_msg void OnBnClickedButtonStop(); |
| | | afx_msg LRESULT OnUpdateDataToUI(WPARAM wParam, LPARAM lParam); |
| | | }; |
| | |
| | | #define BTN_SOUND_OFF_BKGND_NORMAL RGB(255, 127, 39) |
| | | #define BTN_SOUND_OFF_BKGND_HOVER RGB(255, 157, 59) |
| | | #define BTN_SOUND_OFF_BKGND_PRESS RGB(255, 100, 29) |
| | | #define BTN_SOUND_ON_BKGND_NORMAL RGB(100, 200, 100) |
| | | #define BTN_SOUND_ON_BKGND_HOVER RGB(150, 250, 150) |
| | | #define BTN_SOUND_ON_BKGND_PRESS RGB(50, 150, 50) |
| | | |
| | | |
| | | /* æé®id */ |
| | |
| | | } |
| | | |
| | | // æé 彿° |
| | | RecipeManager::RecipeManager() : m_recipeFolder("Recipe") {} |
| | | RecipeManager::RecipeManager() : m_recipeFolder("Recipe"), m_currentRecipeName("") {} |
| | | |
| | | // 设置é
æ¹æä»¶å¤¹ |
| | | void RecipeManager::setRecipeFolder(const std::string& folderPath) { |
| | | m_recipeFolder = folderPath; |
| | | } |
| | | |
| | | // å è½½é
æ¹ï¼å¦ææä»¶ä¸åå¨ï¼å è½½é»è®¤æ°æ®ï¼ |
| | | bool RecipeManager::loadRecipe(const std::string& recipeName) { |
| | | std::string filePath = m_recipeFolder + "/" + recipeName + ".xml"; |
| | | pugi::xml_document doc; |
| | | |
| | | if (!doc.load_file(filePath.c_str())) { |
| | | std::cerr << "Recipe file not found: " << filePath << ". Loading default recipe." << std::endl; |
| | | generateDefaultRecipe(); |
| | | return false; // æä»¶ä¸åå¨ï¼ä½å è½½äºé»è®¤æ°æ® |
| | | } |
| | | |
| | | // å è½½è½´ä¿¡æ¯ |
| | | bool RecipeManager::loadAxes(pugi::xml_node axesNode) { |
| | | m_axes.clear(); |
| | | |
| | | auto recipe = doc.child("Recipe"); |
| | | for (auto axisNode : recipe.child("Axes").children("Axis")) { |
| | | for (auto axisNode : axesNode.children("Axis")) { |
| | | AxisInfo axisInfo; |
| | | axisInfo.id = axisNode.attribute("id").as_int(); |
| | | axisInfo.number = axisNode.attribute("number").value(); |
| | | axisInfo.description = axisNode.attribute("description").value(); |
| | | axisInfo.startAddress = axisNode.attribute("start_address").value(); |
| | | //axisInfo.maxPositioningSpeed = axisNode.attribute("maxPositioningSpeed").as_double(); |
| | | //axisInfo.maxManualSpeed = axisNode.attribute("maxManualSpeed").as_double(); |
| | | |
| | | // å è½½ ValueRange å¼ |
| | | axisInfo.jogDistance = ValueRange( |
| | |
| | | ); |
| | | |
| | | // å è½½ PositionRange å¼ |
| | | axisInfo.positioningPointCount = axisNode.child("Positions").attribute("positioningPointCount").as_int(); |
| | | axisInfo.positioningPointCount = axisNode.child("Positions").attribute("positioningPointCount").as_int(); |
| | | for (auto positionNode : axisNode.child("Positions").children("Position")) { |
| | | bool isEnable = positionNode.attribute("isEnable").as_bool(); |
| | | bool isEnable = positionNode.attribute("isEnable").as_bool(); |
| | | std::string description = positionNode.attribute("description").value(); |
| | | ValueRange positionRange( |
| | | positionNode.attribute("min").as_double(), |
| | |
| | | return true; |
| | | } |
| | | |
| | | // ä¿åé
æ¹ |
| | | bool RecipeManager::saveRecipe(const std::string& recipeName) { |
| | | // çææä»¶è·¯å¾ |
| | | std::string filePath = m_recipeFolder + "/" + recipeName + ".xml"; |
| | | |
| | | // å建 XML ææ¡£å¯¹è±¡ |
| | | pugi::xml_document doc; |
| | | |
| | | // å¦æè½´æ°æ®ä¸ºç©ºï¼çæé»è®¤é
æ¹ |
| | | if (m_axes.empty()) { |
| | | generateDefaultRecipe(); |
| | | } |
| | | |
| | | // æ·»å é
æ¹æ ¹èç¹ |
| | | auto recipe = doc.append_child("Recipe"); |
| | | |
| | | // æ·»å è½´å表èç¹ |
| | | auto axesNode = recipe.append_child("Axes"); |
| | | |
| | | // éåææè½´æ°æ®å¹¶åå
¥ XML |
| | | // ä¿åè½´ä¿¡æ¯ |
| | | void RecipeManager::saveAxes(pugi::xml_node& axesNode) { |
| | | for (const auto& axisEntry : m_axes) { |
| | | const AxisInfo& axisInfo = axisEntry.second; |
| | | |
| | |
| | | axisNode.append_attribute("number") = axisInfo.number.c_str(); |
| | | axisNode.append_attribute("description") = axisInfo.description.c_str(); |
| | | axisNode.append_attribute("start_address") = axisInfo.startAddress.c_str(); |
| | | //axisNode.append_attribute("maxPositioningSpeed") = axisInfo.maxPositioningSpeed; |
| | | //axisNode.append_attribute("maxManualSpeed") = axisInfo.maxManualSpeed; |
| | | |
| | | // ä¿å ValueRange å¼ |
| | | auto jog_distance = axisNode.append_child("jog_distance"); |
| | |
| | | positionNode.append_attribute("current") = position.range.currentValue; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 设置é
æ¹æä»¶å¤¹ |
| | | void RecipeManager::setRecipeFolder(const std::string& folderPath) { |
| | | m_recipeFolder = folderPath; |
| | | } |
| | | |
| | | // è·åå½åé
æ¹åç§° |
| | | std::string RecipeManager::getCurrentRecipeName() const { |
| | | return m_currentRecipeName; |
| | | } |
| | | |
| | | // å è½½é
æ¹ï¼å¦ææä»¶ä¸åå¨ï¼å è½½é»è®¤æ°æ®ï¼ |
| | | bool RecipeManager::loadRecipe(const std::string& recipeName) { |
| | | std::string filePath = m_recipeFolder + "/" + recipeName + ".xml"; |
| | | pugi::xml_document doc; |
| | | |
| | | if (!doc.load_file(filePath.c_str())) { |
| | | std::cerr << "Recipe file not found: " << filePath << ". Loading default recipe." << std::endl; |
| | | return false; // æä»¶ä¸åå¨ |
| | | } |
| | | m_currentRecipeName = recipeName; |
| | | |
| | | auto recipeNode = doc.child("Recipe"); |
| | | auto axesNode = recipeNode.child("Axes"); |
| | | loadAxes(axesNode); // å è½½è½´ä¿¡æ¯ |
| | | |
| | | return true; |
| | | } |
| | | |
| | | // ä¿åé
æ¹ |
| | | bool RecipeManager::saveRecipe(const std::string& recipeName) { |
| | | // çææä»¶è·¯å¾ |
| | | std::string filePath = m_recipeFolder + "/" + recipeName + ".xml"; |
| | | |
| | | // å建 XML ææ¡£å¯¹è±¡ |
| | | pugi::xml_document doc; |
| | | |
| | | // å¦æè½´æ°æ®ä¸ºç©ºï¼çæé»è®¤é
æ¹ |
| | | if (m_axes.empty()) { |
| | | generateDefaultRecipe(); |
| | | } |
| | | |
| | | // æ·»å é
æ¹æ ¹èç¹ |
| | | auto recipeNode = doc.append_child("Recipe"); |
| | | |
| | | // æ·»å è½´ä¿¡æ¯ |
| | | auto axesNode = recipeNode.append_child("Axes"); |
| | | saveAxes(axesNode); |
| | | |
| | | // ä¿å XML æä»¶ |
| | | return doc.save_file(filePath.c_str()); |
| | |
| | | // çæé»è®¤é
æ¹ |
| | | void RecipeManager::generateDefaultRecipe() { |
| | | m_axes.clear(); |
| | | m_currentRecipeName = "Default"; |
| | | |
| | | for (int axisId = 1; axisId <= 12; ++axisId) { |
| | | AxisInfo axisInfo; |
| | | axisInfo.id = axisId; |
| | | axisInfo.positioningPointCount = 25; |
| | | //axisInfo.maxPositioningSpeed = 100.0; |
| | | //axisInfo.maxManualSpeed = 100.0; |
| | | axisInfo.number = "M100-M" + std::to_string(axisId); |
| | | axisInfo.description = "Default_Axis" + std::to_string(axisId); |
| | | axisInfo.startAddress = "ZR" + std::to_string(10000 + (axisId - 1) * 300); |
| | |
| | | // 设置é
æ¹æä»¶å¤¹è·¯å¾ |
| | | void setRecipeFolder(const std::string& folderPath); |
| | | |
| | | // è·åå½åé
æ¹åç§° |
| | | std::string getCurrentRecipeName() const; |
| | | |
| | | // å è½½é
æ¹ï¼æä»¶ä¸å卿¶å è½½é»è®¤æ°æ®ï¼ |
| | | bool loadRecipe(const std::string& recipeName); |
| | | |
| | |
| | | private: |
| | | RecipeManager(); |
| | | |
| | | // è½´å è½½åä¿å彿° |
| | | bool loadAxes(pugi::xml_node axesNode); |
| | | void saveAxes(pugi::xml_node& axesNode); |
| | | |
| | | private: |
| | | std::string m_currentRecipeName; // å½åé
æ¹åç§° |
| | | std::string m_recipeFolder; // é
æ¹æä»¶å¤¹è·¯å¾ |
| | | std::map<int, AxisInfo> m_axes; // è½´ä¿¡æ¯ç¼å |
| | | }; |
| | |
| | | |
| | | int CToolUnits::toInt32(const char* pBuffer) |
| | | { |
| | | return (pBuffer[0] & 0xff) | (pBuffer[1] & 0xff) << 8 | (pBuffer[2] & 0xff) << 16 | (pBuffer[3] & 0xff) << 24; |
| | | return (pBuffer[0] & 0xff) | ((pBuffer[1] & 0xff) << 8) | ((pBuffer[2] & 0xff) << 16) | ((pBuffer[3] & 0xff) << 24); |
| | | } |
| | | |
| | | int CToolUnits::toInt16(const char* pBuffer) |
| | |
| | | strText.Format(_T("%.03f"), value); |
| | | pWnd->SetDlgItemText(nCtrlId, strText); |
| | | } |
| | | |
| | | std::vector<CString> CToolUnits::GetFileNamesInDirectory(const CString& strFolderPath, const CString& strExtension) |
| | | { |
| | | std::vector<CString> fileNames; |
| | | |
| | | // ç¡®ä¿ç®å½è·¯å¾æåæåææ |
| | | CString strSearchPath = strFolderPath; |
| | | if (strSearchPath[strSearchPath.GetLength() - 1] != '\\') { |
| | | strSearchPath += '\\'; |
| | | } |
| | | |
| | | CString finalExtension = strExtension; |
| | | if (finalExtension.Find('.') == -1) { |
| | | finalExtension = '.' + finalExtension; |
| | | } |
| | | strSearchPath += "*" + finalExtension; |
| | | |
| | | std::unique_ptr<CFileFind> finder = std::make_unique<CFileFind>(); |
| | | BOOL bWorking = finder->FindFile(strSearchPath); |
| | | |
| | | // éåæä»¶å¤¹ |
| | | while (bWorking) { |
| | | bWorking = finder->FindNextFile(); |
| | | if (!finder->IsDirectory()) { |
| | | CString fileName = finder->GetFileName(); |
| | | int dotPos = fileName.ReverseFind('.'); |
| | | if (dotPos != -1) { |
| | | fileName = fileName.Left(dotPos); |
| | | } |
| | | fileNames.push_back(fileName); |
| | | } |
| | | } |
| | | |
| | | return fileNames; |
| | | } |
| | | |
| | | std::string CToolUnits::getRecipePath() |
| | | { |
| | | return getCurrentExePath() + "\\Recipe"; |
| | | } |
| | | |
| | | std::string CToolUnits::getCurrentTimeString() |
| | | { |
| | | struct tm ltm; |
| | | time_t now = time(0); |
| | | localtime_s(<m, &now); // 使ç¨å®å
¨ç localtime_s 彿° |
| | | |
| | | char buffer[256]; |
| | | sprintf_s(buffer, sizeof(buffer), "%04d-%02d-%02d %02d:%02d:%02d", |
| | | ltm.tm_year + 1900, ltm.tm_mon + 1, ltm.tm_mday, |
| | | ltm.tm_hour, ltm.tm_min, ltm.tm_sec); |
| | | |
| | | return std::string(buffer); |
| | | } |
| | |
| | | static BOOL getBit(const char c, int index); |
| | | static void setBit(char* p, int index); |
| | | static void setDlgItemDouble(CWnd* pWnd, int nCtrlId, double value); |
| | | static std::vector<CString> GetFileNamesInDirectory(const CString& strFolderPath, const CString& strExtension); |
| | | static std::string getRecipePath(); |
| | | static std::string getCurrentTimeString(); |
| | | }; |
| | | |
| | |
| | | |
| | | // CAxisDetailSettingsDlg å¯¹è¯æ¡ |
| | | |
| | | IMPLEMENT_DYNAMIC(CAxisDetailSettingsDlg, CDialogEx) |
| | | IMPLEMENT_DYNAMIC(CAxisDetailSettingsDlg, CBaseDlg) |
| | | |
| | | CAxisDetailSettingsDlg::CAxisDetailSettingsDlg(const CString& strRecipeName, int nAxisNO, CWnd* pParent /*=nullptr*/) |
| | | : CDialogEx(IDD_DIALOG_AXIS_DETAIL_SETTINGS, pParent) |
| | | : CBaseDlg(IDD_DIALOG_AXIS_DETAIL_SETTINGS, pParent) |
| | | { |
| | | m_strRecipeName = strRecipeName; |
| | | m_nAxisNO = nAxisNO; |
| | | |
| | | m_pPLC = nullptr; |
| | | m_nInitialWidth = 0; |
| | | m_nInitialHeight = 0; |
| | | } |
| | | |
| | | CAxisDetailSettingsDlg::~CAxisDetailSettingsDlg() |
| | |
| | | GetDlgItem(IDC_EDIT_AXIS_MODITFY_DECE_TIME_MAX)->SetWindowText(formatDouble(axisDetails.decelerationTime.maxValue)); |
| | | } |
| | | |
| | | bool CAxisDetailSettingsDlg::ParsePLCAddress(const CString& address, MC::SOFT_COMPONENT& component, int& addr) |
| | | { |
| | | if (address.GetLength() < 2) { |
| | | return false; |
| | | } |
| | | |
| | | // æåç»ä»¶ç±»åï¼ç¬¬ä¸ä¸ªåç¬¦ï¼ |
| | | TCHAR componentChar = address[0]; |
| | | if (address.Left(2) == _T("ZR")) { |
| | | component = MC::SOFT_COMPONENT::ZR; |
| | | // æåæ°åé¨åï¼å»é¤ZRåç¼ï¼ |
| | | CString numericAddress = address.Mid(2); |
| | | addr = _ttoi(numericAddress); |
| | | return addr != 0 || numericAddress.CompareNoCase(_T("0")) == 0; // å¦ææ¯ "0"ï¼ä¹è®¤ä¸ºææ |
| | | } |
| | | |
| | | // 对äºå
¶ä»ç»ä»¶ï¼æç
§å¸¸è§è§åå¤ç |
| | | CString hexAddress = address.Mid(1); |
| | | switch (componentChar) { |
| | | case 'D': |
| | | component = MC::SOFT_COMPONENT::D; |
| | | addr = _ttoi(hexAddress); |
| | | break; |
| | | case 'M': |
| | | component = MC::SOFT_COMPONENT::M; |
| | | addr = _tcstoul(hexAddress, nullptr, 16); |
| | | break; |
| | | case 'X': |
| | | component = MC::SOFT_COMPONENT::X; |
| | | addr = _tcstoul(hexAddress, nullptr, 16); |
| | | break; |
| | | case 'Y': |
| | | component = MC::SOFT_COMPONENT::Y; |
| | | addr = _tcstoul(hexAddress, nullptr, 16); |
| | | break; |
| | | case 'W': |
| | | component = MC::SOFT_COMPONENT::W; |
| | | addr = _tcstoul(hexAddress, nullptr, 16); |
| | | break; |
| | | case 'L': |
| | | component = MC::SOFT_COMPONENT::L; |
| | | addr = _tcstoul(hexAddress, nullptr, 16); |
| | | break; |
| | | case 'S': |
| | | component = MC::SOFT_COMPONENT::S; |
| | | addr = _tcstoul(hexAddress, nullptr, 16); |
| | | break; |
| | | case 'B': |
| | | component = MC::SOFT_COMPONENT::B; |
| | | addr = _tcstoul(hexAddress, nullptr, 16); |
| | | break; |
| | | case 'F': |
| | | component = MC::SOFT_COMPONENT::F; |
| | | addr = _tcstoul(hexAddress, nullptr, 16); |
| | | break; |
| | | default: |
| | | return false; |
| | | } |
| | | |
| | | // æ£æ¥å°åæ¯å¦ææ |
| | | if (addr == 0 && hexAddress.CompareNoCase(_T("0")) != 0) { |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | void CAxisDetailSettingsDlg::writeAxisDataToPLC(int nAxisId) |
| | | { |
| | | // è·åè½´æ°æ® |
| | | RecipeManager& recipeManager = RecipeManager::getInstance(); |
| | | AxisInfo axisData = recipeManager.getAxis(nAxisId); |
| | | |
| | | MC::SOFT_COMPONENT enComponent; |
| | | int nStartAddress, nEndAddress, nSize; |
| | | if (!ParsePLCAddress(CString(axisData.startAddress.c_str()), enComponent, nStartAddress)) { |
| | | AfxMessageBox(_T("æ æçèµ·å§å°åï¼")); |
| | | } |
| | | nEndAddress = nStartAddress + 300; |
| | | nSize = (nEndAddress - nStartAddress + 1) * 2; |
| | | |
| | | char szWrite[300] = { 0 }; |
| | | |
| | | auto writeIntToBuffer = [&](int value, int nWriteIndex) { |
| | | if (nWriteIndex + 4 <= sizeof(szWrite)) { |
| | | // å°ç«¯ |
| | | szWrite[nWriteIndex] = static_cast<char>(value & 0xFF); // ä½åè |
| | | szWrite[nWriteIndex + 1] = static_cast<char>((value >> 8) & 0xFF); // 次ä½åè |
| | | szWrite[nWriteIndex + 2] = static_cast<char>((value >> 16) & 0xFF); // 次é«åè |
| | | szWrite[nWriteIndex + 3] = static_cast<char>((value >> 24) & 0xFF); // é«åè |
| | | |
| | | // 大端 |
| | | //szWrite[nWriteIndex + 3] = static_cast<char>(value & 0xFF); // é«åè |
| | | //szWrite[nWriteIndex + 2] = static_cast<char>((value >> 8) & 0xFF); // 次é«åè |
| | | //szWrite[nWriteIndex + 1] = static_cast<char>((value >> 16) & 0xFF); // 次ä½åè |
| | | //szWrite[nWriteIndex] = static_cast<char>((value >> 24) & 0xFF); // ä½åè |
| | | } |
| | | }; |
| | | |
| | | // åå
¥æå¨é度 |
| | | // writeIntToBuffer(static_cast<int>(axisData.manualSpeed.minValue * 1000), 0); |
| | | writeIntToBuffer(static_cast<int>(axisData.manualSpeed.currentValue * 1000), 82); |
| | | // writeIntToBuffer(static_cast<int>(axisData.manualSpeed.maxValue * 1000), 0); |
| | | |
| | | // åå
¥èªå¨é度 |
| | | // writeIntToBuffer(static_cast<int>(axisData.autoSpeed.minValue * 1000), 0); |
| | | writeIntToBuffer(static_cast<int>(axisData.autoSpeed.currentValue * 1000), 84); |
| | | // writeIntToBuffer(static_cast<int>(axisData.autoSpeed.maxValue * 1000), 0); |
| | | |
| | | // åå
¥å éæ¶é´ |
| | | // writeIntToBuffer(static_cast<int>(axisData.accelerationTime.minValue * 1000), 0); |
| | | writeIntToBuffer(static_cast<int>(axisData.accelerationTime.currentValue * 1000), 62); |
| | | // writeIntToBuffer(static_cast<int>(axisData.accelerationTime.maxValue * 1000), 0); |
| | | |
| | | // åå
¥åéæ¶é´ |
| | | // writeIntToBuffer(static_cast<int>(axisData.decelerationTime.minValue * 1000), 0); |
| | | writeIntToBuffer(static_cast<int>(axisData.decelerationTime.currentValue * 1000), 64); |
| | | // writeIntToBuffer(static_cast<int>(axisData.decelerationTime.maxValue * 1000), 0); |
| | | |
| | | // åå
¥å¾®å¨é |
| | | // writeIntToBuffer(static_cast<int>(axisData.jogDistance.minValue * 1000), 0); |
| | | writeIntToBuffer(static_cast<int>(axisData.jogDistance.currentValue * 1000), 81); |
| | | // writeIntToBuffer(static_cast<int>(axisData.jogDistance.maxValue * 1000), 0); |
| | | |
| | | // å®ä½ç¹æ°æ® |
| | | int nIndex = 100; |
| | | for (int i = 0; i < axisData.positions.size(); ++i) { |
| | | const auto& position = axisData.positions[i]; |
| | | // writeIntToBuffer(static_cast<int>(position.range.minValue * 1000), 0); |
| | | writeIntToBuffer(static_cast<int>(position.range.currentValue * 1000), nIndex + (i * 2)); |
| | | // writeIntToBuffer(static_cast<int>(position.range.maxValue * 1000), 0); |
| | | } |
| | | |
| | | // å PLC åå
¥ä¿¡å· |
| | | m_pPLC->writeData(enComponent, nStartAddress, szWrite, nSize, [nStartAddress, &szWrite](IMcChannel* pChannel, int nAddr, DWORD nValue, int nFlag) { |
| | | if (nFlag == 0) { |
| | | TRACE("æä½æåï¼å°å=%dï¼å¼=%s\n", nStartAddress, szWrite); |
| | | } |
| | | else { |
| | | TRACE("æä½å¤±è´¥ï¼å°å=%dï¼é误ç =%d\n", nStartAddress, nFlag); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | void CAxisDetailSettingsDlg::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | CDialogEx::DoDataExchange(pDX); |
| | | CBaseDlg::DoDataExchange(pDX); |
| | | DDX_Control(pDX, IDC_STATIC_AXIS_NUMBER, m_staticAxisNO); |
| | | DDX_Control(pDX, IDC_STATIC_AXIS_DESCRIP, m_staticAxisDescription); |
| | | DDX_Control(pDX, IDC_STATIC_START_ADDRESS, m_staticStartAddress); |
| | |
| | | } |
| | | |
| | | |
| | | BEGIN_MESSAGE_MAP(CAxisDetailSettingsDlg, CDialogEx) |
| | | BEGIN_MESSAGE_MAP(CAxisDetailSettingsDlg, CBaseDlg) |
| | | ON_NOTIFY(NM_CLICK, IDC_CUSTOM_AXIS_ANCHOR_POINT, &CAxisDetailSettingsDlg::OnGridItemChanged) |
| | | ON_BN_CLICKED(IDC_BUTTON_AXIS_DETAIL_SETTINGS_SAVE, &CAxisDetailSettingsDlg::OnBnClickedButtonAxisDetailSettingsSave) |
| | | ON_BN_CLICKED(IDC_BUTTON_SET_AXIS_POSITIONING_POINTS, &CAxisDetailSettingsDlg::OnBnClickedButtonSetAxisPositioningPoints) |
| | |
| | | |
| | | BOOL CAxisDetailSettingsDlg::OnInitDialog() |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | CBaseDlg::OnInitDialog(); |
| | | |
| | | // TODO: 卿¤æ·»å é¢å¤çåå§å |
| | | CString strTitle; |
| | |
| | | // ä¿åè½´æ°æ®å°æä»¶ |
| | | CString cstrMessage; |
| | | if (RecipeManager::getInstance().saveRecipe(std::string(CT2A(m_strRecipeName)))) { |
| | | writeAxisDataToPLC(m_nAxisNO); |
| | | cstrMessage.Format(_T("ä¿åè½´ [%d] ç»é¨åæ°æåï¼"), m_nAxisNO); |
| | | SystemLogManager::getInstance().log(SystemLogManager::LogType::Operation, std::string(CT2A(cstrMessage))); |
| | | } |
| | |
| | | #pragma once |
| | | #include "afxdialogex.h" |
| | | #include "GridCtrl.h" |
| | | #include "CBaseDlg.h" |
| | | |
| | | |
| | | // CAxisDetailSettingsDlg å¯¹è¯æ¡ |
| | | |
| | | class CAxisDetailSettingsDlg : public CDialogEx |
| | | class CAxisDetailSettingsDlg : public CBaseDlg |
| | | { |
| | | DECLARE_DYNAMIC(CAxisDetailSettingsDlg) |
| | | |
| | |
| | | void InitAnchorPontManager(); |
| | | void FillAnchorPontManager(); |
| | | void UpdateAxisDetailSettings(); |
| | | |
| | | bool ParsePLCAddress(const CString& address, MC::SOFT_COMPONENT& component, int& addr); |
| | | void writeAxisDataToPLC(int nAxisId); |
| | | |
| | | private: |
| | | CPLC* m_pPLC; |
| | | int m_nInitialWidth; |
| | | int m_nInitialHeight; |
| | | |
| | | // æ°æ® |
| | | int m_nAxisNO; |
| | |
| | | |
| | | // CAxisSettingsDlg å¯¹è¯æ¡ |
| | | |
| | | IMPLEMENT_DYNAMIC(CAxisSettingsDlg, CDialogEx) |
| | | IMPLEMENT_DYNAMIC(CAxisSettingsDlg, CBaseDlg) |
| | | |
| | | CAxisSettingsDlg::CAxisSettingsDlg(CWnd* pParent /*=nullptr*/) |
| | | : CDialogEx(IDD_DIALOG_AXIS_SETTINGS, pParent) |
| | | : CBaseDlg(IDD_DIALOG_AXIS_SETTINGS, pParent) |
| | | { |
| | | m_nInitialWidth = 0; |
| | | m_nInitialHeight = 0; |
| | | m_pPLC = nullptr; |
| | | |
| | | m_bSEV = FALSE; |
| | |
| | | |
| | | CAxisSettingsDlg::~CAxisSettingsDlg() |
| | | { |
| | | for (auto& pair : m_mapFonts) { |
| | | if (pair.second) { |
| | | pair.second->DeleteObject(); |
| | | delete pair.second; |
| | | } |
| | | } |
| | | m_mapFonts.clear(); |
| | | |
| | | for (int i = 0; i < BTN_MAX; i++) { |
| | | delete m_pBlBtns[i]; |
| | | } |
| | |
| | | |
| | | void CAxisSettingsDlg::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | CDialogEx::DoDataExchange(pDX); |
| | | CBaseDlg::DoDataExchange(pDX); |
| | | DDX_Control(pDX, IDC_COMBO_AXIS_NAME, m_comboAxisNO); |
| | | DDX_Control(pDX, IDC_STATIC_AXIS_NUMBER, m_staticAxisNO); |
| | | DDX_Control(pDX, IDC_STATIC_AXIS_DESCRIP, m_staticAxisDescription); |
| | |
| | | return 0; |
| | | } |
| | | |
| | | CFont* CAxisSettingsDlg::GetOrCreateFont(int nFontSize) |
| | | { |
| | | auto it = m_mapFonts.find(nFontSize); |
| | | if (it != m_mapFonts.end()) { |
| | | return it->second; |
| | | } |
| | | |
| | | CFont* font = new CFont(); |
| | | LOGFONT logFont = { 0 }; |
| | | _tcscpy_s(logFont.lfFaceName, _T("Segoe UI")); |
| | | logFont.lfHeight = -nFontSize; |
| | | logFont.lfQuality = CLEARTYPE_QUALITY; |
| | | font->CreateFontIndirect(&logFont); |
| | | m_mapFonts[nFontSize] = font; |
| | | |
| | | return font; |
| | | } |
| | | |
| | | void CAxisSettingsDlg::SetDefaultFont() |
| | | { |
| | | CFont* defaultFont = GetOrCreateFont(12); |
| | | |
| | | // éåæææ§ä»¶ï¼åºç¨é»è®¤åä½ |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | pWnd->SetFont(defaultFont, TRUE); |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | void CAxisSettingsDlg::AdjustControls(float dScaleX, float dScaleY) |
| | | { |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | int nCtrlID = pWnd->GetDlgCtrlID(); |
| | | if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end()) |
| | | { |
| | | CRect originalRect = m_mapCtrlLayouts[nCtrlID]; |
| | | CRect newRect( |
| | | static_cast<int>(originalRect.left * dScaleX), |
| | | static_cast<int>(originalRect.top * dScaleY), |
| | | static_cast<int>(originalRect.right * dScaleX), |
| | | static_cast<int>(originalRect.bottom * dScaleY)); |
| | | |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | |
| | | if (_tcsicmp(szClassName, _T("ComboBox")) == 0) { |
| | | CComboBox* pComboBox = (CComboBox*)pWnd; |
| | | pComboBox->SetItemHeight(-1, newRect.Height()); // -1 表示ææé¡¹çé«åº¦ |
| | | } |
| | | |
| | | pWnd->MoveWindow(&newRect); |
| | | AdjustControlFont(pWnd, newRect.Width(), newRect.Height()); |
| | | } |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | void CAxisSettingsDlg::AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight) |
| | | { |
| | | // æ ¹æ®æ§ä»¶é«åº¦å¨æè°æ´åä½å¤§å° |
| | | int fontSize = nHeight / 2; |
| | | if (fontSize < 8) fontSize = 8; |
| | | if (fontSize > 24) fontSize = 24; // æå¤§åä½å¤§å° |
| | | |
| | | // è·åæå建åä½ |
| | | CFont* pFont = GetOrCreateFont(fontSize); |
| | | |
| | | pWnd->SetFont(pFont); |
| | | pWnd->Invalidate(); // å·æ°æ§ä»¶æ¾ç¤º |
| | | } |
| | | |
| | | void CAxisSettingsDlg::AdjustLabelFont(CBLLabel& label) |
| | | { |
| | | if (label.m_hWnd == nullptr) { |
| | | return; |
| | | } |
| | | |
| | | // è·åæ§ä»¶çç©å½¢åºå |
| | | CRect rect; |
| | | label.GetClientRect(&rect); |
| | |
| | | // å¨æè®¡ç®åä½å¤§å°ï¼åºäºæ§ä»¶çé«åº¦ |
| | | int fontSize = rect.Height() / 2; // æ§ä»¶é«åº¦çä¸åä½ä¸ºåä½å¤§å° |
| | | if (fontSize < 8) fontSize = 8; // æå°åä½å¤§å° |
| | | if (fontSize > 30) fontSize = 30; // æå¤§åä½å¤§å° |
| | | if (fontSize > 20) fontSize = 20; // æå¤§åä½å¤§å° |
| | | |
| | | // 设置åä½å¤§å° |
| | | label.SetFontSize(fontSize); |
| | |
| | | RecipeManager& recipeManager = RecipeManager::getInstance(); |
| | | if (m_strRecipeName.IsEmpty() || !recipeManager.loadRecipe(std::string(CT2A(m_strRecipeName)))) { |
| | | AfxMessageBox(_T("å è½½é
æ¹å¤±è´¥ï¼")); |
| | | recipeManager.saveRecipe(std::string(CT2A(m_strRecipeName))); |
| | | return; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | BEGIN_MESSAGE_MAP(CAxisSettingsDlg, CDialogEx) |
| | | BEGIN_MESSAGE_MAP(CAxisSettingsDlg, CBaseDlg) |
| | | ON_BN_CLICKED(IDC_BUTTON_AXIS_LAST, &CAxisSettingsDlg::OnBnClickedButtonAxisLast) |
| | | ON_BN_CLICKED(IDC_BUTTON_AXIS_NEXT, &CAxisSettingsDlg::OnBnClickedButtonAxisNext) |
| | | ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP1, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup1) |
| | |
| | | ON_BN_CLICKED(IDC_BUTTON_AXIS_DETAIL_SETTINGS, &CAxisSettingsDlg::OnBnClickedButtonAxisDetailSettings) |
| | | ON_MESSAGE(ID_MSG_UPDATA_DATA_TO_UI, &CAxisSettingsDlg::OnUpdateDataToUI) |
| | | ON_WM_SIZE() |
| | | ON_WM_CTLCOLOR() |
| | | ON_WM_SIZING() |
| | | ON_WM_TIMER() |
| | | ON_WM_CLOSE() |
| | | END_MESSAGE_MAP() |
| | |
| | | |
| | | BOOL CAxisSettingsDlg::OnInitDialog() |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | CBaseDlg::OnInitDialog(); |
| | | |
| | | // TODO: 卿¤æ·»å é¢å¤çåå§å |
| | | CString strTitle; |
| | |
| | | pLabel->SetTextColor(RGB(255, 255, 255)); |
| | | pLabel->SetAlignment(AlignCenter); |
| | | pLabel->SetDynamicFont(TRUE); |
| | | |
| | | AdjustLabelFont(*pLabel); |
| | | } |
| | | |
| | | // åå§åç¼è¾æ¡ |
| | |
| | | initializeAxisIDCombo(); |
| | | refreshAxisDetails(1); |
| | | refreshPositionDetails(1, m_currentPage); |
| | | |
| | | CRect screenRect, dlgRect, clientRect; |
| | | GetClientRect(&clientRect); |
| | | m_nInitialWidth = clientRect.Width(); |
| | | m_nInitialHeight = clientRect.Height(); |
| | | |
| | | // åå§åé»è®¤åä½ |
| | | CFont* pDefaultFont = GetOrCreateFont(12); |
| | | |
| | | // éåææåæ§ä»¶ï¼è®°å½åå§ä½ç½®å¹¶è®¾ç½®é»è®¤åä½ |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | int nCtrlID = pWnd->GetDlgCtrlID(); |
| | | if (nCtrlID != -1) { |
| | | // è®°å½æ§ä»¶åå§å¸å± |
| | | CRect ctrlRect; |
| | | pWnd->GetWindowRect(&ctrlRect); |
| | | ScreenToClient(&ctrlRect); |
| | | m_mapCtrlLayouts[nCtrlID] = ctrlRect; |
| | | |
| | | // 设置é»è®¤åä½ |
| | | pWnd->SetFont(pDefaultFont); |
| | | } |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | |
| | | GetWindowRect(&dlgRect); |
| | | int dlgWidth = dlgRect.Width() * 2; |
| | | int dlgHeight = dlgRect.Height() * 2; |
| | | |
| | | SystemParametersInfo(SPI_GETWORKAREA, 0, &screenRect, 0); |
| | | if (dlgWidth > screenRect.Width()) { |
| | | dlgWidth = screenRect.Width(); |
| | | } |
| | | if (dlgHeight > screenRect.Height()) { |
| | | dlgHeight = screenRect.Height(); |
| | | } |
| | | |
| | | int centerX = screenRect.left + (screenRect.Width() - dlgWidth) / 2; |
| | | int centerY = screenRect.top + (screenRect.Height() - dlgHeight) / 2; |
| | | MoveWindow(centerX, centerY, dlgWidth, dlgHeight); |
| | | |
| | | SetTimer(TIMER_READ_PLC_DATA, 500, nullptr); |
| | | |
| | |
| | | } |
| | | |
| | | if (currentIndex == -1) { |
| | | return CDialogEx::PreTranslateMessage(pMsg); |
| | | return CBaseDlg::PreTranslateMessage(pMsg); |
| | | } |
| | | |
| | | CString descriptionCtrlName, positionCtrlName; |
| | |
| | | CWnd* pPositionCtrl = GetDlgItem(positionCtrlId); |
| | | |
| | | if (pDescriptionCtrl == nullptr || pPositionCtrl == nullptr) { |
| | | return CDialogEx::PreTranslateMessage(pMsg); |
| | | return CBaseDlg::PreTranslateMessage(pMsg); |
| | | } |
| | | |
| | | PositionRange& position = recipeManager.getPositionByIndex(getCurrentSelectedAxisID(), m_currentPage, AXIS_PAGE_SIZE, currentIndex); |
| | |
| | | CString strText; |
| | | GetDlgItem(IDC_EDIT_AXIS_CURR_POS)->GetWindowText(strText); |
| | | if (strText.IsEmpty()) { |
| | | return CDialogEx::PreTranslateMessage(pMsg);; |
| | | return CBaseDlg::PreTranslateMessage(pMsg);; |
| | | } |
| | | |
| | | double enteredValue = _ttof(strText); |
| | |
| | | } |
| | | } |
| | | |
| | | return CDialogEx::PreTranslateMessage(pMsg); |
| | | return CBaseDlg::PreTranslateMessage(pMsg); |
| | | } |
| | | |
| | | void CAxisSettingsDlg::OnSize(UINT nType, int cx, int cy) |
| | | { |
| | | CDialogEx::OnSize(nType, cx, cy); |
| | | CBaseDlg::OnSize(nType, cx, cy); |
| | | |
| | | // TODO: 卿¤å¤æ·»å æ¶æ¯å¤çç¨åºä»£ç |
| | | if (nType == SIZE_MINIMIZED || m_mapCtrlLayouts.empty()) { |
| | | return; |
| | | } |
| | | |
| | | float dScaleX = static_cast<float>(cx) / m_nInitialWidth; |
| | | float dScaleY = static_cast<float>(cy) / m_nInitialHeight; |
| | | |
| | | // éåå¯¹è¯æ¡ä¸çæææ§ä»¶ |
| | | AdjustControls(dScaleX, dScaleY); |
| | | |
| | | // å¨æè°æ´å个 CBLLabel çåä½å¤§å° |
| | | for (auto pLabel : m_pBlLabels) { |
| | | AdjustLabelFont(*pLabel); |
| | |
| | | pComboBox->MoveWindow(&rectComboBox); |
| | | pComboBox->SetItemHeight(-1, rectButton.Height() - 6); |
| | | } |
| | | } |
| | | |
| | | void CAxisSettingsDlg::OnSizing(UINT fwSide, LPRECT pRect) |
| | | { |
| | | if (fwSide == WMSZ_BOTTOMRIGHT) { |
| | | if (pRect->right - pRect->left < 200) { |
| | | pRect->right = pRect->left + 200; |
| | | } |
| | | if (pRect->bottom - pRect->top < 150) { |
| | | pRect->bottom = pRect->top + 150; |
| | | } |
| | | } |
| | | |
| | | CDialogEx::OnSizing(fwSide, pRect); |
| | | } |
| | | |
| | | HBRUSH CAxisSettingsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) |
| | | { |
| | | HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor); |
| | | |
| | | // TODO: 卿¤æ´æ¹ DC çä»»ä½ç¹æ§ |
| | | |
| | | // TODO: 妿é»è®¤ç䏿¯æéç»ç¬ï¼åè¿åå¦ä¸ä¸ªç»ç¬ |
| | | return hbr; |
| | | } |
| | | |
| | | void CAxisSettingsDlg::OnBnClickedButtonAxisLast() |
| | |
| | | readPLCDataToUI(nAxisId); |
| | | } |
| | | |
| | | CDialogEx::OnTimer(nIDEvent); |
| | | CBaseDlg::OnTimer(nIDEvent); |
| | | } |
| | | |
| | | void CAxisSettingsDlg::OnClose() |
| | |
| | | // TODO: 卿¤æ·»å æ¶æ¯å¤çç¨åºä»£ç å/æè°ç¨é»è®¤å¼ |
| | | KillTimer(TIMER_READ_PLC_DATA); |
| | | |
| | | CDialogEx::OnClose(); |
| | | CBaseDlg::OnClose(); |
| | | } |
| | |
| | | #include "BLLabel.h" |
| | | #include "RegexEdit.h" |
| | | #include "CPLC.h" |
| | | #include "CBaseDlg.h" |
| | | |
| | | // æ¯é¡µå®ä½ç¹æ¾ç¤ºä¸ªæ° |
| | | #define AXIS_PAGE_SIZE 5 |
| | |
| | | POSITION_5 // å®ä½ç¹5 |
| | | }; |
| | | |
| | | class CAxisSettingsDlg : public CDialogEx |
| | | class CAxisSettingsDlg : public CBaseDlg |
| | | { |
| | | DECLARE_DYNAMIC(CAxisSettingsDlg) |
| | | |
| | |
| | | |
| | | private: |
| | | UINT FindIDByName(const CString& strControlID); |
| | | CFont* GetOrCreateFont(int nFontSize); |
| | | void SetDefaultFont(); |
| | | void AdjustControls(float dScaleX, float dScaleY); |
| | | void AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight); |
| | | void AdjustLabelFont(CBLLabel& label); |
| | | void SetLabelColor(CBLLabel& label, COLORREF color); |
| | | void SetLabelColorBasedOnState(CBLLabel& label, BOOL bState, COLORREF colorTrue, COLORREF colorFalse); |
| | |
| | | |
| | | private: |
| | | CPLC* m_pPLC; |
| | | int m_nInitialWidth; |
| | | int m_nInitialHeight; |
| | | |
| | | // å½åéä¸çå®ä½é¡µé¢ç´¢å¼ |
| | | int m_currentPage; |
| | |
| | | CRegexEdit* m_pRegexEdit[EDIT_MAX]; |
| | | CComboBox m_comboAxisNO; |
| | | CStatic m_staticAxisNO, m_staticAxisDescription, m_staticStartAddress; |
| | | //CEdit m_editManualSpeed, m_editAutoSpeed, m_editAccelerationTime, m_editDecelerationTime, m_editJogDistance; |
| | | |
| | | std::map<int, CRect> m_mapCtrlLayouts; |
| | | std::map<int, CFont*> m_mapFonts; |
| | | |
| | | // 读å°çæ°æ® |
| | | BOOL m_bSEV; |
| | |
| | | virtual BOOL OnInitDialog(); |
| | | virtual BOOL PreTranslateMessage(MSG* pMsg); |
| | | afx_msg void OnSize(UINT nType, int cx, int cy); |
| | | afx_msg void OnSizing(UINT fwSide, LPRECT pRect); |
| | | afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); |
| | | afx_msg void OnBnClickedButtonAxisLast(); |
| | | afx_msg void OnBnClickedButtonAxisNext(); |
| | | afx_msg void OnBnClickedButtonAxisAnchorPointGroup1(); |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // RecipeLiseDlg.cpp: å®ç°æä»¶ |
| | | // |
| | | |
| | | #include "stdafx.h" |
| | | #include "BondEq.h" |
| | | #include "afxdialogex.h" |
| | | #include "RecipeListDlg.h" |
| | | #include "InputDialog.h" |
| | | #include "ToolUnits.h" |
| | | #include <fstream> |
| | | #include <sstream> |
| | | #include <map> |
| | | |
| | | |
| | | // CRecipeListDlg å¯¹è¯æ¡ |
| | | |
| | | IMPLEMENT_DYNAMIC(CRecipeListDlg, CBaseDlg) |
| | | |
| | | CRecipeListDlg::CRecipeListDlg(CWnd* pParent /*=nullptr*/) |
| | | : CBaseDlg(IDD_DIALOG_RECIPE_LIST, pParent) |
| | | { |
| | | m_staticCurrRecipe = new CBLLabel(); |
| | | } |
| | | |
| | | CRecipeListDlg::~CRecipeListDlg() |
| | | { |
| | | if (m_staticCurrRecipe != nullptr) { |
| | | delete m_staticCurrRecipe; |
| | | m_staticCurrRecipe = nullptr; |
| | | } |
| | | } |
| | | |
| | | void CRecipeListDlg::AdjustLabelFont(CBLLabel& label) |
| | | { |
| | | if (label.m_hWnd == nullptr) { |
| | | return; |
| | | } |
| | | |
| | | // è·åæ§ä»¶çç©å½¢åºå |
| | | CRect rect; |
| | | label.GetClientRect(&rect); |
| | | |
| | | // å¨æè®¡ç®åä½å¤§å°ï¼åºäºæ§ä»¶çé«åº¦ |
| | | int fontSize = rect.Height() / 2; // æ§ä»¶é«åº¦çä¸åä½ä¸ºåä½å¤§å° |
| | | if (fontSize < 8) fontSize = 8; // æå°åä½å¤§å° |
| | | if (fontSize > 30) fontSize = 30; // æå¤§åä½å¤§å° |
| | | |
| | | // 设置åä½å¤§å° |
| | | label.SetFontSize(fontSize); |
| | | |
| | | // å·æ°æ§ä»¶æ¾ç¤º |
| | | label.Invalidate(); |
| | | label.UpdateWindow(); |
| | | } |
| | | |
| | | void CRecipeListDlg::InitRecipeLise() |
| | | { |
| | | if (m_grid.GetSafeHwnd() == NULL) |
| | | return; |
| | | |
| | | int nRows = 1; |
| | | int nCols = 4; |
| | | |
| | | int nFixRows = 1; |
| | | int nFixCols = 0; |
| | | int nRowIdx = 0; |
| | | int nColIdx = 0; |
| | | |
| | | m_grid.DeleteAllItems(); |
| | | m_grid.SetVirtualMode(FALSE); |
| | | m_grid.GetDefaultCell(TRUE, FALSE)->SetBackClr(g_nGridFixCellColor); // 设置åºå®è¡èæ¯è² |
| | | m_grid.GetDefaultCell(FALSE, TRUE)->SetBackClr(g_nGridFixCellColor); // 设置åºå®åèæ¯è² |
| | | m_grid.GetDefaultCell(FALSE, FALSE)->SetBackClr(g_nGridCellColor); // 设置åå
æ ¼èæ¯è² |
| | | m_grid.SetFixedTextColor(g_nGridFixFontColor); // 设置åºå®è¡ååä½é¢è² |
| | | |
| | | m_grid.SetRowCount(nRows); |
| | | m_grid.SetColumnCount(nCols); |
| | | m_grid.SetFixedRowCount(nFixRows); |
| | | m_grid.SetFixedColumnCount(nFixCols); |
| | | |
| | | // Col |
| | | m_grid.SetColumnWidth(nColIdx, 10); |
| | | m_grid.SetItemText(nRowIdx, nColIdx++, _T("No.")); |
| | | m_grid.SetColumnWidth(nColIdx, 10); |
| | | m_grid.SetItemText(nRowIdx, nColIdx++, _T("åç§°")); |
| | | m_grid.SetColumnWidth(nColIdx, 120); |
| | | m_grid.SetItemText(nRowIdx, nColIdx++, _T("æè¿°")); |
| | | m_grid.SetColumnWidth(nColIdx, 30); |
| | | m_grid.SetItemText(nRowIdx, nColIdx++, _T("å建æ¶é´")); |
| | | |
| | | m_grid.SetFixedRowSelection(FALSE); // 设置åºå®è¡ä¸å¯éä¸ |
| | | m_grid.SetFixedColumnSelection(FALSE); // 设置åºå®åä¸å¯éä¸ |
| | | m_grid.SetEditable(FALSE); // 设置åå
æ ¼å¯ç¼è¾ |
| | | m_grid.SetRowResize(FALSE); // 设置è¡ä¸å¯è°æ´å¤§å° |
| | | m_grid.SetColumnResize(TRUE); // 设置åå¯è°æ´å¤§å° |
| | | m_grid.ExpandColumnsToFit(TRUE); // èªå¨è°æ´å宽 |
| | | m_grid.SetListMode(TRUE); // å¯ç¨åè¡¨æ¨¡å¼ |
| | | m_grid.EnableSelection(TRUE); // å¯ç¨éæ© |
| | | m_grid.SetSingleRowSelection(TRUE); // èªå¨æ´è¡é«äº®ï¼éå¶ä¸ºåè¡éæ©ï¼ |
| | | m_grid.ExpandLastColumn(); // æåä¸åå¡«å
ç½æ ¼ |
| | | |
| | | FillRecipeLise(); |
| | | } |
| | | |
| | | void CRecipeListDlg::FillRecipeLise() |
| | | { |
| | | // æ¸
餿°æ®è¡ï¼ä¿ç表头 |
| | | for (int i = m_grid.GetRowCount() - 1; i > 0; --i) { |
| | | m_grid.DeleteRow(i); |
| | | } |
| | | |
| | | // 1. éåæä»¶å¤¹ä¸ææXMLæä»¶ |
| | | std::string strRecipePath = CToolUnits::getRecipePath(); |
| | | std::vector<CString> vecFile = CToolUnits::GetFileNamesInDirectory(strRecipePath.c_str(), _T(".xml")); |
| | | |
| | | // 2. 读å RecipeList.txt æä»¶ |
| | | std::map<CString, std::pair<CString, CString>> recipeData; // {é
æ¹å, {æè¿°, å建æ¶é´}} |
| | | std::ifstream inFile(strRecipePath + "\\RecipeList.txt"); |
| | | if (inFile.is_open()) { |
| | | std::string line; |
| | | while (std::getline(inFile, line)) { |
| | | if (line.empty()) continue; // è·³è¿ç©ºè¡ |
| | | |
| | | std::istringstream ss(line); |
| | | std::string name, description, createTime; |
| | | |
| | | // CSVæ ¼å¼è§£æï¼éå·åéï¼ |
| | | if (std::getline(ss, name, ',') && |
| | | std::getline(ss, description, ',') && |
| | | std::getline(ss, createTime)) { |
| | | recipeData[CString(name.c_str())] = std::make_pair(CString(description.c_str()), CString(createTime.c_str())); |
| | | } |
| | | } |
| | | inFile.close(); |
| | | } |
| | | |
| | | // 3. æ´æ°è¡¨æ ¼æ°æ® |
| | | int rowIdx = 1; |
| | | m_grid.SetRowCount(static_cast<int>(vecFile.size()) + 1); |
| | | for (const auto& fileName : vecFile) { |
| | | // ä» RecipeList.txt æ°æ®ä¸æ¥æ¾å¯¹åºçæè¿°åå建æ¶é´ |
| | | CString description = _T(""); |
| | | CString createTime = _T(""); |
| | | auto it = recipeData.find(fileName); |
| | | if (it != recipeData.end()) { |
| | | description = it->second.first; // é
æ¹æè¿° |
| | | createTime = it->second.second; // å建æ¶é´ |
| | | } |
| | | |
| | | // å¡«å
è¡¨æ ¼æ°æ® |
| | | m_grid.SetItemText(rowIdx, 0, CString(std::to_string(rowIdx).c_str())); // No. |
| | | m_grid.SetItemText(rowIdx, 1, fileName); // é
æ¹åç§° |
| | | m_grid.SetItemText(rowIdx, 2, description); // é
æ¹æè¿° |
| | | m_grid.SetItemText(rowIdx, 3, createTime); // å建æ¶é´ |
| | | |
| | | ++rowIdx; |
| | | } |
| | | |
| | | m_grid.ExpandColumnsToFit(FALSE); // èªå¨è°æ´å宽 |
| | | m_grid.ExpandLastColumn(); // æåä¸åå¡«å
ç½æ ¼ |
| | | |
| | | // å·æ°ç½æ ¼æ§ä»¶ |
| | | m_grid.Invalidate(); |
| | | m_grid.UpdateWindow(); |
| | | } |
| | | |
| | | void CRecipeListDlg::UpdateDataFile(const CString& strRecipeName, const CString& strNewDescription) |
| | | { |
| | | CStdioFile file; |
| | | CFileException fe; |
| | | |
| | | // æå¼æä»¶ä»¥è¯»åååå
¥ |
| | | CString strFilePath; |
| | | strFilePath.Format(_T("%s\\RecipeList.txt"), CToolUnits::getRecipePath().c_str()); |
| | | if (file.Open(strFilePath, CFile::modeReadWrite | CFile::shareDenyNone, &fe)) { |
| | | CString strLine; |
| | | CStringArray arrLines; |
| | | BOOL bFound = FALSE; |
| | | |
| | | // 读åæä»¶å
容å°å
å |
| | | while (file.ReadString(strLine)) { |
| | | // å°è¿ä¸è¡æéå·åå² |
| | | CStringArray arrColumns; |
| | | int nPos = 0; |
| | | while ((nPos = strLine.Find(_T(','))) != -1) { |
| | | arrColumns.Add(strLine.Left(nPos)); |
| | | strLine = strLine.Mid(nPos + 1); |
| | | } |
| | | arrColumns.Add(strLine); // æåä¸å |
| | | |
| | | // å¦æç¬¬ä¸åï¼é
æ¹åç§°ï¼å¹é
ï¼ä¿®æ¹ç¬¬äºåï¼é
æ¹æè¿°ï¼ |
| | | if (arrColumns.GetSize() > 0 && arrColumns[0] == strRecipeName) { |
| | | arrColumns[1] = strNewDescription; // ä¿®æ¹é
æ¹æè¿°å |
| | | bFound = TRUE; |
| | | } |
| | | |
| | | // å°ä¿®æ¹åçè¡ä¿ååå
å |
| | | CString strUpdatedLine; |
| | | for (int i = 0; i < arrColumns.GetSize(); ++i) { |
| | | if (i > 0) strUpdatedLine += _T(","); |
| | | strUpdatedLine += arrColumns[i]; |
| | | } |
| | | arrLines.Add(strUpdatedLine); |
| | | } |
| | | |
| | | if (bFound) { |
| | | // 妿æ¾å°äºé
æ¹åç§°ï¼ä¿åä¿®æ¹åçå
容åæä»¶ |
| | | file.SeekToBegin(); |
| | | file.SetLength(0); // æ¸
空æä»¶å
容 |
| | | for (int i = 0; i < arrLines.GetSize(); ++i) { |
| | | file.WriteString(arrLines[i] + _T("\n")); |
| | | } |
| | | } |
| | | else { |
| | | // å¦ææ²¡ææ¾å°é
æ¹åç§°ï¼åè¿½å æ°é
æ¹ |
| | | CString strNewLine; |
| | | strNewLine.Format(_T("%s,%s,%s"), strRecipeName, strNewDescription, CToolUnits::getCurrentTimeString().c_str()); |
| | | file.SeekToEnd(); |
| | | file.WriteString(strNewLine + _T("\n")); |
| | | } |
| | | |
| | | file.Close(); |
| | | } |
| | | else { |
| | | AfxMessageBox(_T("æ æ³æå¼æä»¶")); |
| | | } |
| | | } |
| | | |
| | | void CRecipeListDlg::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | CBaseDlg::DoDataExchange(pDX); |
| | | DDX_Control(pDX, IDC_CUSTOM_RECIPE_LIST, m_grid); |
| | | } |
| | | |
| | | |
| | | BEGIN_MESSAGE_MAP(CRecipeListDlg, CBaseDlg) |
| | | ON_BN_CLICKED(IDC_BUTTON_CREATE_RECIPE, &CRecipeListDlg::OnBnClickedButtonCreateRecipe) |
| | | ON_BN_CLICKED(IDC_BUTTON_DELETE_RECIPE, &CRecipeListDlg::OnBnClickedButtonDeleteRecipe) |
| | | ON_BN_CLICKED(IDC_BUTTON_SELECT_RECIPE, &CRecipeListDlg::OnBnClickedButtonSelectRecipe) |
| | | ON_NOTIFY(NM_DBLCLK, IDC_CUSTOM_RECIPE_LIST, &CRecipeListDlg::OnGridCellEditFinished) |
| | | ON_WM_SIZE() |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | | // CRecipeListDlg æ¶æ¯å¤çç¨åº |
| | | |
| | | |
| | | BOOL CRecipeListDlg::OnInitDialog() |
| | | { |
| | | CBaseDlg::OnInitDialog(); |
| | | |
| | | // TODO: 卿¤æ·»å é¢å¤çåå§å |
| | | m_staticCurrRecipe->SubclassDlgItem(IDC_STATIC_CURR_RECIPE, this); |
| | | m_staticCurrRecipe->SetBkColor(RGB(0, 110, 110)); |
| | | m_staticCurrRecipe->ModifyStyle(0, SS_NOTIFY); |
| | | m_staticCurrRecipe->SetTextColor(RGB(255, 255, 255)); |
| | | m_staticCurrRecipe->SetAlignment(AlignCenter); |
| | | m_staticCurrRecipe->SetDynamicFont(TRUE); |
| | | m_staticCurrRecipe->SetWindowText(RecipeManager::getInstance().getCurrentRecipeName().c_str()); |
| | | |
| | | AdjustLabelFont(*m_staticCurrRecipe); |
| | | |
| | | InitRecipeLise(); |
| | | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | // å¼å¸¸: OCX 屿§é¡µåºè¿å FALSE |
| | | } |
| | | |
| | | void CRecipeListDlg::OnSize(UINT nType, int cx, int cy) |
| | | { |
| | | CBaseDlg::OnSize(nType, cx, cy); |
| | | |
| | | // TODO: 卿¤å¤æ·»å æ¶æ¯å¤çç¨åºä»£ç |
| | | AdjustLabelFont(*m_staticCurrRecipe); |
| | | } |
| | | |
| | | void CRecipeListDlg::OnBnClickedButtonCreateRecipe() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | | CInputDialog inputDialog(_T("é
æ¹åç§°"), _T("请è¾å
¥é
æ¹åç§°ï¼")); |
| | | if (inputDialog.DoModal() != IDOK) { |
| | | return; |
| | | } |
| | | CString newRecipeName = inputDialog.GetInputText(); |
| | | |
| | | // éªè¯åç§°ä¸éå¤ |
| | | std::string recipePath = CToolUnits::getRecipePath(); |
| | | std::string recipeListPath = recipePath + "\\RecipeList.txt"; |
| | | std::vector<CString> existingFiles = CToolUnits::GetFileNamesInDirectory(recipePath.c_str(), ".xml"); |
| | | |
| | | for (const auto& fileName : existingFiles) { |
| | | if (newRecipeName.Compare(fileName) == 0) { |
| | | AfxMessageBox(_T("é
æ¹åç§°å·²åå¨ï¼è¯·è¾å
¥å
¶ä»åç§°ï¼")); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | // æ£æ¥æ¯å¦è¦å¤å¶éä¸é
æ¹ |
| | | CString strCopyRecipe = _T(""); |
| | | for (int i = 1; i < m_grid.GetRowCount(); i++) { |
| | | if (m_grid.IsCellSelected(i, 1)) { |
| | | strCopyRecipe = m_grid.GetItemText(i, 1); |
| | | |
| | | CString strMessage; |
| | | strMessage.Format(_T("Copy [%s] -> [%s]?"), strCopyRecipe, newRecipeName); |
| | | if (AfxMessageBox(strMessage, MB_YESNO | MB_ICONQUESTION) != IDYES) { |
| | | strCopyRecipe = _T(""); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | |
| | | // å建æ°çXMLæä»¶ |
| | | CString newRecipeFile = CString(recipePath.c_str()) + "\\" + newRecipeName + ".xml"; |
| | | if (!strCopyRecipe.IsEmpty()) { |
| | | CString sourceFile = CString(recipePath.c_str()) + "\\" + strCopyRecipe + ".xml"; |
| | | CopyFile(sourceFile, newRecipeFile, FALSE); |
| | | } |
| | | else { |
| | | // çæé»è®¤XMLæä»¶ |
| | | RecipeManager& recipeManager = RecipeManager::getInstance(); |
| | | recipeManager.generateDefaultRecipe(); |
| | | if (!recipeManager.saveRecipe(std::string(CT2A(newRecipeName)))) { |
| | | AfxMessageBox(_T("å建é
æ¹å¤±è´¥ï¼")); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | // æ´æ° RecipeList.txt |
| | | std::ofstream outFile(recipeListPath, std::ios::app); // è¿½å æ¨¡å¼ |
| | | if (outFile.is_open()) { |
| | | SYSTEMTIME sysTime; |
| | | GetLocalTime(&sysTime); |
| | | char buffer[64]; |
| | | sprintf_s(buffer, "%04d-%02d-%02d %02d:%02d:%02d", |
| | | sysTime.wYear, sysTime.wMonth, sysTime.wDay, |
| | | sysTime.wHour, sysTime.wMinute, sysTime.wSecond); |
| | | |
| | | outFile << CT2A(newRecipeName) << ",é»è®¤æè¿°," << buffer << std::endl; |
| | | outFile.close(); |
| | | } |
| | | |
| | | // å·æ°ç½æ ¼æ§ä»¶ |
| | | FillRecipeLise(); |
| | | } |
| | | |
| | | void CRecipeListDlg::OnBnClickedButtonDeleteRecipe() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | | int nSelect = -1; |
| | | for (int i = 1; i < m_grid.GetRowCount(); i++) { |
| | | if (m_grid.IsCellSelected(i, 1)) { |
| | | nSelect = i; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (nSelect < 0) { |
| | | AfxMessageBox(_T("è¯·éæ©è¦å é¤çé
æ¹ï¼")); |
| | | return; |
| | | } |
| | | |
| | | CString selectedRecipe = m_grid.GetItemText(nSelect, 1); |
| | | if (selectedRecipe.IsEmpty()) { |
| | | AfxMessageBox(_T("é
æ¹åç§°æ æï¼")); |
| | | return; |
| | | } |
| | | |
| | | CString message = _T("ç¡®å®è¦å é¤é
æ¹ \"") + selectedRecipe + _T("\" åï¼"); |
| | | if (AfxMessageBox(message, MB_YESNO | MB_ICONQUESTION) != IDYES) { |
| | | return; |
| | | } |
| | | |
| | | // å é¤XMLæä»¶ |
| | | std::string recipePath = CToolUnits::getRecipePath(); |
| | | CString xmlFilePath = CString(recipePath.c_str()) + "\\" + selectedRecipe + ".xml"; |
| | | if (!DeleteFile(xmlFilePath)) { |
| | | AfxMessageBox(_T("å é¤XMLæä»¶å¤±è´¥ï¼")); |
| | | return; |
| | | } |
| | | |
| | | // æ´æ°RecipeList.txtæä»¶ |
| | | std::string recipeListPath = recipePath + "\\RecipeList.txt"; |
| | | std::ifstream inFile(recipeListPath); |
| | | std::ofstream outFile(recipeListPath + ".tmp"); // åå»ºä¸´æ¶æä»¶ |
| | | |
| | | if (inFile.is_open() && outFile.is_open()) { |
| | | std::string line; |
| | | while (std::getline(inFile, line)) { |
| | | std::istringstream ss(line); |
| | | std::string name; |
| | | if (std::getline(ss, name, ',')) { |
| | | if (selectedRecipe != CString(name.c_str())) { |
| | | outFile << line << std::endl; // ä¿çä¸å¹é
çè¡ |
| | | } |
| | | } |
| | | } |
| | | inFile.close(); |
| | | outFile.close(); |
| | | |
| | | // æ¿æ¢æä»¶ |
| | | DeleteFile(CString(recipeListPath.c_str())); |
| | | MoveFile(CString((recipeListPath + ".tmp").c_str()), CString(recipeListPath.c_str())); |
| | | } |
| | | |
| | | // å·æ°ç½æ ¼æ§ä»¶ |
| | | FillRecipeLise(); |
| | | } |
| | | |
| | | void CRecipeListDlg::OnBnClickedButtonSelectRecipe() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | | int nSelect = -1; |
| | | for (int i = 1; i < m_grid.GetRowCount(); i++) { |
| | | if (m_grid.IsCellSelected(i, 1)) { |
| | | nSelect = i; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (nSelect < 0) { |
| | | AfxMessageBox(_T("è¯·éæ©é
æ¹ï¼")); |
| | | return; |
| | | } |
| | | |
| | | CString strSelectedRecipe = m_grid.GetItemText(nSelect, 1); |
| | | if (RecipeManager::getInstance().loadRecipe(std::string(CT2A(strSelectedRecipe)))) { |
| | | m_staticCurrRecipe->SetWindowText(strSelectedRecipe); |
| | | m_staticCurrRecipe->SetBkColor(RGB(0, 110, 110)); |
| | | } |
| | | else { |
| | | AfxMessageBox(_T("å è½½é
æ¹å¤±è´¥ï¼")); |
| | | } |
| | | } |
| | | |
| | | void CRecipeListDlg::OnGridCellEditFinished(NMHDR* pNotifyStruct, LRESULT* pResult) |
| | | { |
| | | // è·åä¿®æ¹çè¡åä¿¡æ¯ |
| | | NM_GRIDVIEW* pItem = (NM_GRIDVIEW*)pNotifyStruct; |
| | | int nRow = pItem->iRow; |
| | | int nCol = pItem->iColumn; |
| | | |
| | | // åªå¤çâé
æ¹æè¿°âåçä¿®æ¹ |
| | | if (nCol == 2) { |
| | | CString strRecipeName = m_grid.GetItemText(nRow, 1); |
| | | CInputDialog inputDialog(_T("é
æ¹æè¿°"), _T("请è¾å
¥é
æ¹æè¿°ï¼")); |
| | | if (inputDialog.DoModal() != IDOK) { |
| | | *pResult = 0; |
| | | return; |
| | | } |
| | | CString strText = inputDialog.GetInputText(); |
| | | m_grid.SetItemText(nRow, nCol, strText); |
| | | UpdateDataFile(strRecipeName, strText); |
| | | |
| | | m_grid.ExpandColumnsToFit(FALSE); // èªå¨è°æ´å宽 |
| | | m_grid.ExpandLastColumn(); // æåä¸åå¡«å
ç½æ ¼ |
| | | |
| | | // å·æ°ç½æ ¼æ§ä»¶ |
| | | m_grid.Invalidate(); |
| | | m_grid.UpdateWindow(); |
| | | } |
| | | |
| | | *pResult = 0; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #pragma once |
| | | #include "afxdialogex.h" |
| | | #include "GridCtrl.h" |
| | | #include "CBaseDlg.h" |
| | | #include "BLLabel.h" |
| | | |
| | | |
| | | // CRecipeListDlg å¯¹è¯æ¡ |
| | | |
| | | class CRecipeListDlg : public CBaseDlg |
| | | { |
| | | DECLARE_DYNAMIC(CRecipeListDlg) |
| | | |
| | | public: |
| | | CRecipeListDlg(CWnd* pParent = nullptr); // æ åæé 彿° |
| | | virtual ~CRecipeListDlg(); |
| | | |
| | | // å¯¹è¯æ¡æ°æ® |
| | | #ifdef AFX_DESIGN_TIME |
| | | enum { IDD = IDD_DIALOG_RECIPE_LIST }; |
| | | #endif |
| | | |
| | | private: |
| | | //CFont* GetOrCreateFont(int nFontSize); |
| | | //void AdjustControls(float dScaleX, float dScaleY); |
| | | //void AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight); |
| | | void AdjustLabelFont(CBLLabel& label); |
| | | void InitRecipeLise(); |
| | | void FillRecipeLise(); |
| | | void UpdateDataFile(const CString& strRecipeName, const CString& strNewDescription); |
| | | |
| | | private: |
| | | //int m_nInitialWidth; |
| | | //int m_nInitialHeight; |
| | | //std::map<int, CFont*> m_mapFonts; // å使 å° |
| | | //std::map<int, CRect> m_mapCtrlLayouts; // æ§ä»¶å¸å±æ å° |
| | | |
| | | // æ§ä»¶ |
| | | CBLLabel* m_staticCurrRecipe; |
| | | CGridCtrl m_grid; |
| | | |
| | | protected: |
| | | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV æ¯æ |
| | | virtual BOOL OnInitDialog(); |
| | | afx_msg void OnSize(UINT nType, int cx, int cy); |
| | | afx_msg void OnBnClickedButtonCreateRecipe(); |
| | | afx_msg void OnBnClickedButtonDeleteRecipe(); |
| | | afx_msg void OnBnClickedButtonSelectRecipe(); |
| | | afx_msg void OnGridCellEditFinished(NMHDR* pNotifyStruct, LRESULT* pResult); |
| | | DECLARE_MESSAGE_MAP() |
| | | }; |
| | |
| | | |
| | | // CSystemLogManagerDlg å¯¹è¯æ¡ |
| | | |
| | | IMPLEMENT_DYNAMIC(CSystemLogManagerDlg, CDialogEx) |
| | | IMPLEMENT_DYNAMIC(CSystemLogManagerDlg, CBaseDlg) |
| | | |
| | | CSystemLogManagerDlg::CSystemLogManagerDlg(CWnd* pParent /*=nullptr*/) |
| | | : CDialogEx(IDD_DIALOG_SYSTEM_LOG_MANAGER, pParent) |
| | | : CBaseDlg(IDD_DIALOG_SYSTEM_LOG_MANAGER, pParent) |
| | | { |
| | | m_nInitialWidth = 0; |
| | | m_nInitialHeight = 0; |
| | | } |
| | | |
| | | CSystemLogManagerDlg::~CSystemLogManagerDlg() |
| | | { |
| | | for (auto& pair : m_mapFonts) { |
| | | if (pair.second) { |
| | | pair.second->DeleteObject(); |
| | | delete pair.second; |
| | | } |
| | | } |
| | | m_mapFonts.clear(); |
| | | } |
| | | |
| | | void CSystemLogManagerDlg::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | CDialogEx::DoDataExchange(pDX); |
| | | CBaseDlg::DoDataExchange(pDX); |
| | | DDX_Control(pDX, IDC_COMBO_TYPE, m_comboType); |
| | | DDX_Control(pDX, IDC_COMBO_USER, m_comboUser); |
| | | DDX_Control(pDX, IDC_DATETIMEPICKER_START, m_dateTimeStart); |
| | |
| | | UpdatePageInfo(); |
| | | } |
| | | |
| | | CFont* CSystemLogManagerDlg::GetOrCreateFont(int nFontSize) |
| | | { |
| | | auto it = m_mapFonts.find(nFontSize); |
| | | if (it != m_mapFonts.end()) { |
| | | return it->second; |
| | | } |
| | | |
| | | CFont* font = new CFont(); |
| | | LOGFONT logFont = { 0 }; |
| | | _tcscpy_s(logFont.lfFaceName, _T("Segoe UI")); |
| | | logFont.lfHeight = -nFontSize; |
| | | logFont.lfQuality = CLEARTYPE_QUALITY; |
| | | font->CreateFontIndirect(&logFont); |
| | | m_mapFonts[nFontSize] = font; |
| | | |
| | | return font; |
| | | } |
| | | |
| | | void CSystemLogManagerDlg::UpdatePageInfo() |
| | | { |
| | | // æ ¼å¼å页ç ä¿¡æ¯ä¸º "å½å页/æ»é¡µæ°" |
| | |
| | | m_staticPageNum.SetWindowText(pageInfo); |
| | | } |
| | | |
| | | void CSystemLogManagerDlg::SetDefaultFont() |
| | | { |
| | | CFont* defaultFont = GetOrCreateFont(12); |
| | | |
| | | // éåæææ§ä»¶ï¼åºç¨é»è®¤åä½ |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | // è·³è¿ç¹æ®æ§ä»¶ï¼å¦ MFCGridCtrlï¼ |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | pWnd = pWnd->GetNextWindow(); |
| | | continue; |
| | | } |
| | | |
| | | pWnd->SetFont(defaultFont, TRUE); |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | void CSystemLogManagerDlg::AdjustControls(float dScaleX, float dScaleY) |
| | | { |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | int nCtrlID = pWnd->GetDlgCtrlID(); |
| | | if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end()) |
| | | { |
| | | CRect originalRect = m_mapCtrlLayouts[nCtrlID]; |
| | | CRect newRect( |
| | | static_cast<int>(originalRect.left * dScaleX), |
| | | static_cast<int>(originalRect.top * dScaleY), |
| | | static_cast<int>(originalRect.right * dScaleX), |
| | | static_cast<int>(originalRect.bottom * dScaleY)); |
| | | |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | |
| | | if (_tcsicmp(szClassName, _T("ComboBox")) == 0) { |
| | | CComboBox* pComboBox = (CComboBox*)pWnd; |
| | | pComboBox->SetItemHeight(-1, newRect.Height()); // -1 表示ææé¡¹çé«åº¦ |
| | | } |
| | | |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | CGridCtrl* pGridCtrl = (CGridCtrl*)pWnd; |
| | | pGridCtrl->SetDefCellHeight(newRect.Height() / 21); |
| | | pGridCtrl->ExpandColumnsToFit(TRUE); |
| | | pGridCtrl->ExpandLastColumn(); |
| | | pGridCtrl->Invalidate(); |
| | | pGridCtrl->UpdateWindow(); |
| | | } |
| | | |
| | | pWnd->MoveWindow(&newRect); |
| | | AdjustControlFont(pWnd, newRect.Width(), newRect.Height()); |
| | | } |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | void CSystemLogManagerDlg::AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight) |
| | | { |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | |
| | | // è·³è¿ç¹æ®æ§ä»¶ï¼å¦ MFCGridCtrlï¼ |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | return; |
| | | } |
| | | |
| | | // æ ¹æ®æ§ä»¶é«åº¦å¨æè°æ´åä½å¤§å° |
| | | int fontSize = nHeight / 2; |
| | | if (fontSize < 8) fontSize = 8; |
| | | |
| | | // è·åæå建åä½ |
| | | CFont* pFont = GetOrCreateFont(fontSize); |
| | | |
| | | pWnd->SetFont(pFont); |
| | | pWnd->Invalidate(); // å·æ°æ§ä»¶æ¾ç¤º |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::AdjustComboBoxStyle(CComboBox& comboBox) |
| | | { |
| | | DWORD dwStyle = comboBox.GetStyle(); |
| | | comboBox.ModifyStyle(0, CBS_DROPDOWNLIST | CBS_HASSTRINGS | CBS_OWNERDRAWFIXED); |
| | | |
| | | comboBox.Invalidate(); |
| | | comboBox.UpdateWindow(); |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::AdjustDateTimeCtrlStyle(CDateTimeCtrl& dateTimeCtrl) |
| | | { |
| | | dateTimeCtrl.ModifyStyle(0, DTS_RIGHTALIGN); |
| | | dateTimeCtrl.Invalidate(); |
| | | dateTimeCtrl.UpdateWindow(); |
| | | } |
| | | |
| | | |
| | | BEGIN_MESSAGE_MAP(CSystemLogManagerDlg, CDialogEx) |
| | | BEGIN_MESSAGE_MAP(CSystemLogManagerDlg, CBaseDlg) |
| | | ON_BN_CLICKED(IDC_BUTTON_SEARCH, &CSystemLogManagerDlg::OnBnClickedButtonSearch) |
| | | ON_BN_CLICKED(IDC_BUTTON_PREV_PAGE, &CSystemLogManagerDlg::OnBnClickedButtonPrevPage) |
| | | ON_BN_CLICKED(IDC_BUTTON_NEXT_PAGE, &CSystemLogManagerDlg::OnBnClickedButtonNextPage) |
| | | ON_CBN_SELCHANGE(IDC_COMBO_TYPE, &CSystemLogManagerDlg::OnSelchangeComboType) |
| | | ON_CBN_SELCHANGE(IDC_COMBO_USER, &CSystemLogManagerDlg::OnSelchangeComboUser) |
| | | ON_WM_SIZE() |
| | | ON_WM_GETMINMAXINFO() |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | |
| | | |
| | | BOOL CSystemLogManagerDlg::OnInitDialog() |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | CBaseDlg::OnInitDialog(); |
| | | |
| | | // TODO: 卿¤æ·»å é¢å¤çåå§å |
| | | SetWindowText(_T("ç³»ç»è¿è¡æ¥å¿")); |
| | |
| | | COleDateTime defaultStartTime = currentTime - COleDateTimeSpan(30, 0, 0, 0); |
| | | m_dateTimeStart.SetTime(defaultStartTime); |
| | | |
| | | CRect screenRect, dlgRect, clientRect; |
| | | GetClientRect(&clientRect); |
| | | m_nInitialWidth = clientRect.Width(); |
| | | m_nInitialHeight = clientRect.Height(); |
| | | |
| | | // åå§åé»è®¤åä½ |
| | | CFont* pDefaultFont = GetOrCreateFont(12); |
| | | |
| | | // éåææåæ§ä»¶ï¼è®°å½åå§ä½ç½®å¹¶è®¾ç½®é»è®¤åä½ |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | int nCtrlID = pWnd->GetDlgCtrlID(); |
| | | if (nCtrlID != -1) { |
| | | // è®°å½æ§ä»¶åå§å¸å± |
| | | CRect ctrlRect; |
| | | pWnd->GetWindowRect(&ctrlRect); |
| | | ScreenToClient(&ctrlRect); |
| | | m_mapCtrlLayouts[nCtrlID] = ctrlRect; |
| | | |
| | | // è·³è¿ç¹æ®æ§ä»¶ï¼å¦ MFCGridCtrlï¼ |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | pWnd = pWnd->GetNextWindow(); |
| | | continue; |
| | | } |
| | | |
| | | // 设置é»è®¤åä½ |
| | | pWnd->SetFont(pDefaultFont); |
| | | } |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | |
| | | GetWindowRect(&dlgRect); |
| | | int dlgWidth = dlgRect.Width() * 2; |
| | | int dlgHeight = dlgRect.Height() * 2; |
| | | |
| | | SystemParametersInfo(SPI_GETWORKAREA, 0, &screenRect, 0); |
| | | if (dlgWidth > screenRect.Width()) { |
| | | dlgWidth = screenRect.Width(); |
| | | } |
| | | if (dlgHeight > screenRect.Height()) { |
| | | dlgHeight = screenRect.Height(); |
| | | } |
| | | |
| | | int centerX = screenRect.left + (screenRect.Width() - dlgWidth) / 2; |
| | | int centerY = screenRect.top + (screenRect.Height() - dlgHeight) / 2; |
| | | MoveWindow(centerX, centerY, dlgWidth, dlgHeight); |
| | | |
| | | InitSystemLogManager(); |
| | | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | // å¼å¸¸: OCX 屿§é¡µåºè¿å FALSE |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::OnSize(UINT nType, int cx, int cy) |
| | | { |
| | | CDialogEx::OnSize(nType, cx, cy); |
| | | |
| | | // TODO: 卿¤å¤æ·»å æ¶æ¯å¤çç¨åºä»£ç |
| | | if (nType == SIZE_MINIMIZED || m_mapCtrlLayouts.empty()) { |
| | | return; |
| | | } |
| | | |
| | | float dScaleX = static_cast<float>(cx) / m_nInitialWidth; |
| | | float dScaleY = static_cast<float>(cy) / m_nInitialHeight; |
| | | |
| | | // éåå¯¹è¯æ¡ä¸çæææ§ä»¶ |
| | | AdjustControls(dScaleX, dScaleY); |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI) |
| | | { |
| | | // TODO: 卿¤æ·»å æ¶æ¯å¤çç¨åºä»£ç å/æè°ç¨é»è®¤å¼ |
| | | lpMMI->ptMinTrackSize.x = 400; // æå°å®½åº¦ |
| | | lpMMI->ptMinTrackSize.y = 300; // æå°é«åº¦ |
| | | |
| | | CDialogEx::OnGetMinMaxInfo(lpMMI); |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::OnBnClickedButtonSearch() |
| | | { |
| | |
| | | AfxMessageBox(errorMsg, MB_ICONERROR); |
| | | } |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::OnBnClickedButtonPrevPage() |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::OnBnClickedButtonNextPage() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::OnSelchangeComboType() |
| | | { |
| | | // TODO: 卿¤æ·»å æ§ä»¶éç¥å¤çç¨åºä»£ç |
| | |
| | | AfxMessageBox(errorMsg, MB_ICONERROR); |
| | | } |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::OnSelchangeComboUser() |
| | | { |
| | |
| | | #pragma once |
| | | #include "afxdialogex.h" |
| | | #include "GridCtrl.h" |
| | | #include "CBaseDlg.h" |
| | | |
| | | // CSystemLogManagerDlg å¯¹è¯æ¡ |
| | | |
| | | class CSystemLogManagerDlg : public CDialogEx |
| | | class CSystemLogManagerDlg : public CBaseDlg |
| | | { |
| | | DECLARE_DYNAMIC(CSystemLogManagerDlg) |
| | | |
| | |
| | | private: |
| | | void InitSystemLogManager(); |
| | | void FillSystemLogManager(); |
| | | CFont* GetOrCreateFont(int nFontSize); |
| | | void UpdatePageInfo(); |
| | | void SetDefaultFont(); |
| | | void AdjustControls(float dScaleX, float dScaleY); |
| | | void AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight); |
| | | void AdjustComboBoxStyle(CComboBox& comboBox); |
| | | void AdjustDateTimeCtrlStyle(CDateTimeCtrl& dateTimeCtrl); |
| | | |
| | | private: |
| | | int m_nInitialWidth; // åå§å®½åº¦ |
| | | int m_nInitialHeight; // åå§é«åº¦ |
| | | int m_nCurrentPage; // å½å页ç |
| | | int m_nTotalPages; // æ»é¡µæ° |
| | | std::map<int, CRect> m_mapCtrlLayouts; // å卿§ä»¶çåå§å¸å±ä¿¡æ¯ |
| | | std::map<int, CFont*> m_mapFonts; // 管çåä½ç容å¨ï¼é®ä¸ºåä½å¤§å° |
| | | |
| | | private: |
| | | CComboBox m_comboType; |
| | |
| | | |
| | | protected: |
| | | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV æ¯æ |
| | | |
| | | DECLARE_MESSAGE_MAP() |
| | | public: |
| | | virtual BOOL OnInitDialog(); |
| | | afx_msg void OnSize(UINT nType, int cx, int cy); |
| | | afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); |
| | | afx_msg void OnBnClickedButtonSearch(); |
| | | afx_msg void OnBnClickedButtonPrevPage(); |
| | | afx_msg void OnBnClickedButtonNextPage(); |
| | | afx_msg void OnSelchangeComboType(); |
| | | afx_msg void OnSelchangeComboUser(); |
| | | DECLARE_MESSAGE_MAP() |
| | | }; |
| | |
| | | #include "InputDialog.h" |
| | | #include "NewCellTypes/GridCellCombo.h" |
| | | #include "NewCellTypes/GridCellNumeric.h" |
| | | |
| | | #include <set> |
| | | |
| | | const COLORREF CURR_USER_BK_COLOR = RGB(0, 255, 0); |
| | | |
| | | // CUserManagerDlg å¯¹è¯æ¡ |
| | | |
| | | IMPLEMENT_DYNAMIC(CUserManagerDlg, CDialogEx) |
| | | IMPLEMENT_DYNAMIC(CUserManagerDlg, CBaseDlg) |
| | | |
| | | CUserManagerDlg::CUserManagerDlg(CWnd* pParent /*=nullptr*/) |
| | | : CDialogEx(IDD_DIALOG_USER_MANAGER, pParent) |
| | | : CBaseDlg(IDD_DIALOG_USER_MANAGER, pParent) |
| | | { |
| | | m_nInitialWidth = 0; |
| | | m_nInitialHeight = 0; |
| | | } |
| | | |
| | | CUserManagerDlg::~CUserManagerDlg() |
| | | { |
| | | for (auto& pair : m_mapFonts) { |
| | | if (pair.second) { |
| | | pair.second->DeleteObject(); |
| | | delete pair.second; |
| | | } |
| | | } |
| | | m_mapFonts.clear(); |
| | | } |
| | | |
| | | void CUserManagerDlg::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | DDX_Control(pDX, IDC_CUSTOM_USER, m_gridUserManager); |
| | | CDialogEx::DoDataExchange(pDX); |
| | | CBaseDlg::DoDataExchange(pDX); |
| | | } |
| | | |
| | | void CUserManagerDlg::InitUserManager() |
| | |
| | | return false; |
| | | } |
| | | |
| | | CFont* CUserManagerDlg::GetOrCreateFont(int nFontSize) |
| | | { |
| | | auto it = m_mapFonts.find(nFontSize); |
| | | if (it != m_mapFonts.end()) { |
| | | return it->second; |
| | | } |
| | | |
| | | CFont* font = new CFont(); |
| | | LOGFONT logFont = { 0 }; |
| | | _tcscpy_s(logFont.lfFaceName, _T("Segoe UI")); |
| | | logFont.lfHeight = -nFontSize; |
| | | logFont.lfQuality = CLEARTYPE_QUALITY; |
| | | font->CreateFontIndirect(&logFont); |
| | | m_mapFonts[nFontSize] = font; |
| | | |
| | | return font; |
| | | } |
| | | |
| | | void CUserManagerDlg::SetDefaultFont() |
| | | { |
| | | CFont* defaultFont = GetOrCreateFont(12); |
| | | |
| | | // éåæææ§ä»¶ï¼åºç¨é»è®¤åä½ |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | // è·³è¿ç¹æ®æ§ä»¶ï¼å¦ MFCGridCtrlï¼ |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | pWnd = pWnd->GetNextWindow(); |
| | | continue; |
| | | } |
| | | |
| | | pWnd->SetFont(defaultFont, TRUE); |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | void CUserManagerDlg::AdjustControls(float dScaleX, float dScaleY) |
| | | { |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | int nCtrlID = pWnd->GetDlgCtrlID(); |
| | | if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end()) |
| | | { |
| | | CRect originalRect = m_mapCtrlLayouts[nCtrlID]; |
| | | CRect newRect( |
| | | static_cast<int>(originalRect.left * dScaleX), |
| | | static_cast<int>(originalRect.top * dScaleY), |
| | | static_cast<int>(originalRect.right * dScaleX), |
| | | static_cast<int>(originalRect.bottom * dScaleY)); |
| | | |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | |
| | | if (_tcsicmp(szClassName, _T("ComboBox")) == 0) { |
| | | CComboBox* pComboBox = (CComboBox*)pWnd; |
| | | pComboBox->SetItemHeight(-1, newRect.Height()); // -1 表示ææé¡¹çé«åº¦ |
| | | } |
| | | |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | CGridCtrl* pGridCtrl = (CGridCtrl*)pWnd; |
| | | pGridCtrl->SetDefCellHeight(newRect.Height() / 21); |
| | | pGridCtrl->ExpandColumnsToFit(TRUE); |
| | | pGridCtrl->ExpandLastColumn(); |
| | | pGridCtrl->Invalidate(); |
| | | pGridCtrl->UpdateWindow(); |
| | | } |
| | | |
| | | pWnd->MoveWindow(&newRect); |
| | | AdjustControlFont(pWnd, newRect.Width(), newRect.Height()); |
| | | } |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | void CUserManagerDlg::AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight) |
| | | { |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | |
| | | // è·³è¿ç¹æ®æ§ä»¶ï¼å¦ MFCGridCtrlï¼ |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | return; |
| | | } |
| | | |
| | | // æ ¹æ®æ§ä»¶é«åº¦å¨æè°æ´åä½å¤§å° |
| | | int fontSize = nHeight / 2; |
| | | if (fontSize < 8) fontSize = 8; |
| | | |
| | | // è·åæå建åä½ |
| | | CFont* pFont = GetOrCreateFont(fontSize); |
| | | |
| | | pWnd->SetFont(pFont); |
| | | pWnd->Invalidate(); // å·æ°æ§ä»¶æ¾ç¤º |
| | | } |
| | | |
| | | BEGIN_MESSAGE_MAP(CUserManagerDlg, CDialogEx) |
| | | ON_WM_SIZE() |
| | | BEGIN_MESSAGE_MAP(CUserManagerDlg, CBaseDlg) |
| | | ON_NOTIFY(GVN_COMBOSELCHANGE, IDC_CUSTOM_USER, &CUserManagerDlg::OnGridComboSelChange) |
| | | ON_BN_CLICKED(IDC_BUTTON_ADD, &CUserManagerDlg::OnBnClickedButtonAdd) |
| | | ON_BN_CLICKED(IDC_BUTTON_DEL, &CUserManagerDlg::OnBnClickedButtonDel) |
| | | ON_BN_CLICKED(IDOK, &CUserManagerDlg::OnBnClickedOk) |
| | | ON_BN_CLICKED(IDC_BUTTON_INSERT, &CUserManagerDlg::OnBnClickedButtonInsert) |
| | | ON_WM_GETMINMAXINFO() |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | |
| | | |
| | | BOOL CUserManagerDlg::OnInitDialog() |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | CBaseDlg::OnInitDialog(); |
| | | |
| | | // TODO: 卿¤æ·»å é¢å¤çåå§å |
| | | CRect screenRect, dlgRect, clientRect; |
| | | SetWindowText(_T("ç¨æ·ç®¡ç")); |
| | | SystemParametersInfo(SPI_GETWORKAREA, 0, &screenRect, 0); |
| | | |
| | | GetClientRect(&clientRect); |
| | | m_nInitialWidth = clientRect.Width(); |
| | | m_nInitialHeight = clientRect.Height(); |
| | | |
| | | // åå§åé»è®¤åä½ |
| | | CFont* pDefaultFont = GetOrCreateFont(12); |
| | | |
| | | // éåææåæ§ä»¶ï¼è®°å½åå§ä½ç½®å¹¶è®¾ç½®é»è®¤åä½ |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | int nCtrlID = pWnd->GetDlgCtrlID(); |
| | | if (nCtrlID != -1) { |
| | | // è®°å½æ§ä»¶åå§å¸å± |
| | | CRect ctrlRect; |
| | | pWnd->GetWindowRect(&ctrlRect); |
| | | ScreenToClient(&ctrlRect); |
| | | m_mapCtrlLayouts[nCtrlID] = ctrlRect; |
| | | |
| | | // è·³è¿ç¹æ®æ§ä»¶ï¼å¦ MFCGridCtrlï¼ |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | pWnd = pWnd->GetNextWindow(); |
| | | continue; |
| | | } |
| | | |
| | | // 设置é»è®¤åä½ |
| | | pWnd->SetFont(pDefaultFont); |
| | | } |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | |
| | | GetWindowRect(&dlgRect); |
| | | int dlgWidth = dlgRect.Width() * 3; |
| | | int dlgHeight = dlgRect.Height() * 3; |
| | | |
| | | if (dlgWidth > screenRect.Width()) { |
| | | dlgWidth = screenRect.Width(); |
| | | } |
| | | if (dlgHeight > screenRect.Height()) { |
| | | dlgHeight = screenRect.Height(); |
| | | } |
| | | |
| | | int centerX = screenRect.left + (screenRect.Width() - dlgWidth) / 2; |
| | | int centerY = screenRect.top + (screenRect.Height() - dlgHeight) / 2; |
| | | MoveWindow(centerX, centerY, dlgWidth, dlgHeight); |
| | | |
| | | // åå§åç¨æ·ç®¡çè¡¨æ ¼ |
| | | InitUserManager(); |
| | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | // å¼å¸¸: OCX 屿§é¡µåºè¿å FALSE |
| | | } |
| | | |
| | | |
| | | void CUserManagerDlg::OnSize(UINT nType, int cx, int cy) |
| | | { |
| | | CDialogEx::OnSize(nType, cx, cy); |
| | | |
| | | // TODO: 卿¤å¤æ·»å æ¶æ¯å¤çç¨åºä»£ç |
| | | if (nType == SIZE_MINIMIZED || m_mapCtrlLayouts.empty()) { |
| | | return; |
| | | } |
| | | |
| | | float dScaleX = static_cast<float>(cx) / m_nInitialWidth; |
| | | float dScaleY = static_cast<float>(cy) / m_nInitialHeight; |
| | | |
| | | // éåå¯¹è¯æ¡ä¸çæææ§ä»¶ |
| | | AdjustControls(dScaleX, dScaleY); |
| | | } |
| | | |
| | | |
| | | void CUserManagerDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI) |
| | | { |
| | | // TODO: 卿¤æ·»å æ¶æ¯å¤çç¨åºä»£ç å/æè°ç¨é»è®¤å¼ |
| | | lpMMI->ptMinTrackSize.x = 400; // æå°å®½åº¦ |
| | | lpMMI->ptMinTrackSize.y = 300; // æå°é«åº¦ |
| | | |
| | | CDialogEx::OnGetMinMaxInfo(lpMMI); |
| | | } |
| | | |
| | | |
| | | void CUserManagerDlg::OnGridComboSelChange(NMHDR* pNMHDR, LRESULT* pResult) |
| | | { |
| | |
| | | } |
| | | |
| | | userManager.setUsers(vecData); |
| | | CDialogEx::OnOK(); |
| | | CBaseDlg::OnOK(); |
| | | } |
| | |
| | | #pragma once |
| | | #include "afxdialogex.h" |
| | | #include "GridCtrl.h" |
| | | #include "CBaseDlg.h" |
| | | |
| | | // CUserManagerDlg å¯¹è¯æ¡ |
| | | |
| | | class CUserManagerDlg : public CDialogEx |
| | | class CUserManagerDlg : public CBaseDlg |
| | | { |
| | | DECLARE_DYNAMIC(CUserManagerDlg) |
| | | |
| | |
| | | void AddRow(CGridCtrl* pGridCtrl); |
| | | void DeleteSelectedRow(CGridCtrl* pGridCtrl); |
| | | bool IsUsernameDuplicate(const CString& username); |
| | | CFont* GetOrCreateFont(int nFontSize); |
| | | void SetDefaultFont(); |
| | | void AdjustControls(float dScaleX, float dScaleY); |
| | | void AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight); |
| | | |
| | | private: |
| | | int m_nInitialWidth; |
| | | int m_nInitialHeight; |
| | | std::map<int, CRect> m_mapCtrlLayouts; |
| | | std::map<int, CFont*> m_mapFonts; |
| | | std::map<CString, CString> m_mapRoleDescriptions; |
| | | |
| | | private: |
| | | // æ§ä»¶ |
| | | CGridCtrl m_gridUserManager; |
| | | |
| | | protected: |
| | |
| | | DECLARE_MESSAGE_MAP() |
| | | public: |
| | | virtual BOOL OnInitDialog(); |
| | | afx_msg void OnSize(UINT nType, int cx, int cy); |
| | | afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); |
| | | afx_msg void OnGridComboSelChange(NMHDR* pNMHDR, LRESULT* pResult); |
| | | afx_msg void OnBnClickedButtonAdd(); |
| | | afx_msg void OnBnClickedButtonInsert(); |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //{{NO_DEPENDENCIES}} |
| | | // Microsoft Visual C++ generated include file. |
| | | // Used by res_en.rc |
| | | |
| | | // æ°å¯¹è±¡çä¸ä¸ç»é»è®¤å¼ |
| | | // |
| | | #ifdef APSTUDIO_INVOKED |
| | | #ifndef APSTUDIO_READONLY_SYMBOLS |
| | | #define _APS_NEXT_RESOURCE_VALUE 101 |
| | | #define _APS_NEXT_COMMAND_VALUE 40001 |
| | | #define _APS_NEXT_CONTROL_VALUE 1001 |
| | | #define _APS_NEXT_SYMED_VALUE 101 |
| | | #endif |
| | | #endif |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | //{{NO_DEPENDENCIES}} |
| | | // Microsoft Visual C++ generated include file. |
| | | // Used by res_zh.rc |
| | | |
| | | // æ°å¯¹è±¡çä¸ä¸ç»é»è®¤å¼ |
| | | // |
| | | #ifdef APSTUDIO_INVOKED |
| | | #ifndef APSTUDIO_READONLY_SYMBOLS |
| | | #define _APS_NEXT_RESOURCE_VALUE 101 |
| | | #define _APS_NEXT_COMMAND_VALUE 40001 |
| | | #define _APS_NEXT_CONTROL_VALUE 1001 |
| | | #define _APS_NEXT_SYMED_VALUE 101 |
| | | #endif |
| | | #endif |
| | |
| | | // æ§ä»¶æ ·å¼ |
| | | static UINT g_nGridFixCellColor = RGB(144, 200, 246); |
| | | static UINT g_nGridFixFontColor = RGB(0, 0, 0); |
| | | static UINT g_nGridCellColor = RGB(255, 255, 255); |
| | | static UINT g_nGridCellColor = RGB(255, 255, 224); |
| | | static UINT g_nGridCellColor_NonSelect = RGB(150, 150, 150); |
| | | static UINT g_nGridCellReadyColor = RGB(255, 255, 0); |
| | | static UINT g_nGridCellOnColor = RGB(255, 69, 0); |