123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- // CCollimatorDlg.cpp: 实现文件
- //
- #include "pch.h"
- #include "resource.h" // 主符号
- #include "CCollimatorDlg.h"
- #include "afxdialogex.h"
- #include "CConfigDlg.h"
- #include "CColmImageDlg.h"
- CallFunGetImageData FunGetImageData = NULL;
- CallFunBeginTransImage FunBeginTransImage = NULL;
- CallFunEndTransImage FunEndTransImage = NULL;
- // CCollimatorDlg 对话框
- IMPLEMENT_DYNAMIC(CCollimatorDlg, CDiosBasicDlg)
- CCollimatorDlg::CCollimatorDlg(CWnd* pParent /*=nullptr*/)
- : CDiosBasicDlg(Dev_Collimator, IDD_DIALOG3, pParent)
- {
- }
- CCollimatorDlg::~CCollimatorDlg()
- {
- }
- void CCollimatorDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialogEx::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_EDIT1, m_Edit_XSize);
- DDX_Control(pDX, IDC_EDIT2, m_Edit_YSize);
- DDX_Control(pDX, IDC_EDIT3, m_Edit_SID);
- DDX_Control(pDX, IDC_EDIT4, m_Edit_Angle);
- DDX_Control(pDX, IDC_EDIT5, m_Edit_Filter);
- DDX_Control(pDX, IDC_EDIT6, m_Edit_Mode);
- }
- BEGIN_MESSAGE_MAP(CCollimatorDlg, CDialogEx)
- ON_BN_CLICKED(IDCANCEL, &CCollimatorDlg::OnBnClickedCancel)
- ON_BN_CLICKED(IDC_BUTTON3, &CCollimatorDlg::OnBnClickedButton3)
- ON_BN_CLICKED(IDC_BUTTON1, &CCollimatorDlg::OnBnClickedButton1)
- ON_BN_CLICKED(IDC_BUTTON2, &CCollimatorDlg::OnBnClickedButton2)
- ON_BN_CLICKED(IDC_BUTTON4, &CCollimatorDlg::OnBnClickedButton4)
- ON_BN_CLICKED(IDC_BUTTON5, &CCollimatorDlg::OnBnClickedButton5)
- ON_BN_CLICKED(IDC_BUTTON6, &CCollimatorDlg::OnBnClickedButton6)
- ON_BN_CLICKED(IDC_BUTTON7, &CCollimatorDlg::OnBnClickedButton7)
- ON_BN_CLICKED(IDC_BUTTON8, &CCollimatorDlg::OnBnClickedButton8)
- ON_BN_CLICKED(IDC_BUTTON9, &CCollimatorDlg::OnBnClickedButton9)
- ON_BN_CLICKED(IDC_BUTTON10, &CCollimatorDlg::OnBnClickedButton10)
- ON_BN_CLICKED(IDC_BUTTON11, &CCollimatorDlg::OnBnClickedButton11)
- ON_EN_KILLFOCUS(IDC_EDIT1, &CCollimatorDlg::OnEnKillfocusEdit1)
- ON_EN_KILLFOCUS(IDC_EDIT2, &CCollimatorDlg::OnEnKillfocusEdit2)
- ON_EN_KILLFOCUS(IDC_EDIT3, &CCollimatorDlg::OnEnKillfocusEdit3)
- ON_EN_KILLFOCUS(IDC_EDIT4, &CCollimatorDlg::OnEnKillfocusEdit4)
- ON_EN_KILLFOCUS(IDC_EDIT5, &CCollimatorDlg::OnEnKillfocusEdit5)
- ON_EN_KILLFOCUS(IDC_EDIT6, &CCollimatorDlg::OnEnKillfocusEdit6)
- END_MESSAGE_MAP()
- // CCollimatorDlg 消息处理程序
- //初始化配置
- BOOL CCollimatorDlg::OnInitDialog()
- {
- CDiosBasicDlg::OnInitDialog();
- return TRUE;
- }
- //设备初始化
- bool CCollimatorDlg::AppInitial(bool act)
- {
- CString log;
- return CreatMode(act);
- }
- //获取初始值
- bool CCollimatorDlg::GetInitData()
- {
- CString log;
- CString tempStr;
- string strTempValue;
- if (m_pDevice != nullptr)
- {
- m_nXsize = atoi(DevGetValue(nsCOLL::AttrKey::XSIZE).c_str());
- tempStr.Format("%d", m_nXsize);
- m_Edit_XSize.SetWindowText(tempStr);
- m_nYsize = atof(DevGetValue(nsCOLL::AttrKey::YSIZE).c_str());
- tempStr.Format("%.2f", m_nYsize);
- m_Edit_YSize.SetWindowText(tempStr);
- m_nSID = atof(DevGetValue(nsCOLL::AttrKey::FILTER).c_str());
- tempStr.Format("%.2f", m_nSID);
- m_Edit_SID.SetWindowText(tempStr);
- m_nAngle = atof(DevGetValue(nsCOLL::AttrKey::SID).c_str());
- tempStr.Format("%.2f", m_nAngle);
- m_Edit_Angle.SetWindowText(tempStr);
- m_nFilter = atoi(DevGetValue(nsCOLL::AttrKey::ANGLE).c_str());
- tempStr.Format("%d", m_nFilter);
- m_Edit_Filter.SetWindowText(tempStr);
- int Mode = atoi(DevGetValue(nsCOLL::AttrKey::MODE).c_str());
- tempStr.Format("%d", Mode);
- m_Edit_Mode.SetWindowText(tempStr);
- m_bLight = atoi(DevGetValue(nsCOLL::AttrKey::LIGHT).c_str());
- if (m_bLight)
- {
- GetDlgItem(IDC_BUTTON10)->SetWindowText("LightOn");
- }
- else
- {
- GetDlgItem(IDC_BUTTON10)->SetWindowText("LightOff");
- }
- }
- return true;
- }
- //设置消息对照表
- void CCollimatorDlg::SetMagMap()
- {
- auto HW_UNKNOWN = [this](int NotifyCode, string key, string context)
- {
- CString strNotify;
- strNotify.Format("COLL can not deal with Attribute[%s] \n", key.c_str());
- ToolsDlgLog(strNotify);
- };
- auto HW_XSize = [this](int NotifyCode, string key, string context)//XSize
- {
- m_nXsize = atoi(context.c_str());
- m_Edit_XSize.SetWindowText(context.c_str());
- };
- auto HW_YSize = [this](int NotifyCode, string key, string context)//YSize
- {
- m_nYsize = atoi(context.c_str());
- m_Edit_YSize.SetWindowText(context.c_str());
- };
- auto HW_SID = [this](int NotifyCode, string key, string context)//SID
- {
- m_Edit_SID.SetWindowText(context.c_str());
- };
- auto HW_Angle = [this](int NotifyCode, string key, string context)//Angle
- {
- m_Edit_Angle.SetWindowText(context.c_str());
- };
- auto HW_CollimatorFilter = [this](int NotifyCode, string key, string context)//Filter
- {
- m_Edit_Filter.SetWindowText(context.c_str());
- };
- auto HW_Mode = [this](int NotifyCode, string key, string context)//Mode
- {
- m_Edit_Mode.SetWindowText(context.c_str());
- };
- //Collimator
- m_mapFrame["UnKnown"] = tFrameMapItem(HW_UNKNOWN);
- m_mapFrame[nsCOLL::AttrKey::XSIZE] = tFrameMapItem(HW_XSize);
- m_mapFrame[nsCOLL::AttrKey::YSIZE] = tFrameMapItem(HW_YSize);
- m_mapFrame[nsCOLL::AttrKey::SID] = tFrameMapItem(HW_SID);
- m_mapFrame[nsCOLL::AttrKey::ANGLE] = tFrameMapItem(HW_Angle);
- m_mapFrame[nsCOLL::AttrKey::FILTER] = tFrameMapItem(HW_CollimatorFilter);
- m_mapFrame[nsCOLL::AttrKey::MODE] = tFrameMapItem(HW_Mode);
- }
- void CCollimatorDlg::InitPageElements(bool act)
- {
- if (act)
- {
- ShowPageElements(FALSE, TRUE, FALSE, FALSE);
- SetMagMap();
- GetInitData();
- }
- else
- {
- ShowPageElements(TRUE, FALSE, TRUE, FALSE);
- }
- }
- //设置窗口元素显示
- void CCollimatorDlg::ShowPageElements(bool init, bool exit, bool cfg, bool general)
- {
- __super::ShowPageElements(init,exit,cfg,general);
- bool nomal = exit;
-
- //Size
- GetDlgItem(IDC_BUTTON4)->EnableWindow(nomal);
- GetDlgItem(IDC_EDIT1)->EnableWindow(nomal);
- //YSize
- GetDlgItem(IDC_BUTTON5)->EnableWindow(nomal);
- GetDlgItem(IDC_EDIT2)->EnableWindow(nomal);
- //SID
- GetDlgItem(IDC_BUTTON6)->EnableWindow(nomal);
- GetDlgItem(IDC_EDIT3)->EnableWindow(nomal);
- //Angle
- GetDlgItem(IDC_BUTTON7)->EnableWindow(nomal);
- GetDlgItem(IDC_EDIT4)->EnableWindow(nomal);
- //Filter
- GetDlgItem(IDC_BUTTON8)->EnableWindow(nomal);
- GetDlgItem(IDC_EDIT5)->EnableWindow(nomal);
- //Mode
- GetDlgItem(IDC_BUTTON9)->EnableWindow(general);
- GetDlgItem(IDC_EDIT6)->EnableWindow(general);
- //Light
- GetDlgItem(IDC_BUTTON10)->EnableWindow(nomal);
- //AI
- GetDlgItem(IDC_BUTTON11)->EnableWindow(nomal);
- }
- //统一修改接口
- void CCollimatorDlg::SetSize(int Xvalue, int Yvalue)
- {
- CString log;
- string rsp{ "error" };
- try {
- ResDataObject json;
- json.add("P0", Xvalue);
- json.add("P1", Yvalue);
- RET_STATUS rc0;
- {
- if (m_pDevice != nullptr)
- rc0 = m_pDevice->Action(nsCOLL::ActionKey::SetCollimatorSize, json.encode(), rsp);
- }
- if (rc0 == RET_STATUS::RET_SUCCEED)
- mLog::Debug("{$} [SetCollimatorSize] success", UnitTool_logKey_Col);
- else
- {
- log.Format("%s [SetCollimatorSize] fail", UnitTool_logKey_Col);
- mLog::Error(log);
- ToolsDlgLog(log);
- rsp.clear();
- }
- }
- catch (...)
- {
- log.Format("%s action[SetCollimatorSize] exe failed", UnitTool_logKey_Col);
- mLog::Error(log);
- ToolsDlgLog(log);
- }
- }
- void CCollimatorDlg::OnBnClickedCancel()
- {
- // TODO: 在此添加控件通知处理程序代码
- CDialogEx::OnCancel();
- }
- //选择配置
- void CCollimatorDlg::OnBnClickedButton3()
- {
- CString log;
- nsCFG::CConfigDlg dlgcfg(Dev_Collimator,
- m_strCfgLib,
- m_strCfgFile);
- dlgcfg.DoModal();
- if (m_strCfgFile.empty())
- {
- log.Format("%s COLL m_strCfgFile is empty", UnitTool_logKey_Col);
- mLog::Warn(log);
- ToolsDlgLog(log);
- }
- else
- {
- ShowPageElements(TRUE, FALSE, TRUE, FALSE);
- }
- }
- //初始化
- void CCollimatorDlg::OnBnClickedButton1()
- {
- CString log;
- if (m_pDriver == nullptr)
- if (!m_pDevice)
- {
- if (AppInitial(true))
- {
- ShowPageElements(FALSE, TRUE, FALSE, FALSE);
- SetMagMap();
- GetInitData();
- mLog::Debug("{$} COLL Initial success", UnitTool_logKey_Col);
- }
- else
- {
- log.Format("%s COLL Initial fail", UnitTool_logKey_Col);
- mLog::Error(log);
- ToolsDlgLog(log);
- }
- }
- else
- {
- log.Format("%s m_pDevice not empty", UnitTool_logKey_Col);
- mLog::Warn(log);
- ToolsDlgLog(log);
- }
- else
- {
- log.Format("%s m_pDriver not empty", UnitTool_logKey_Col);
- mLog::Warn(log);
- ToolsDlgLog(log);
- }
- }
- //退出
- void CCollimatorDlg::OnBnClickedButton2()
- {
- if (AppInitial(false))
- {
- ShowPageElements(TRUE, FALSE, TRUE, FALSE);
- }
- }
- //XSize
- void CCollimatorDlg::OnBnClickedButton4()
- {
- SetSize(m_nXsize, m_nYsize);
- }
- //YSize
- void CCollimatorDlg::OnBnClickedButton5()
- {
- SetSize(m_nXsize, m_nYsize);
- }
- //SID
- void CCollimatorDlg::OnBnClickedButton6()
- {
- DevActionValue(nsCOLL::ActionKey::SetCollimatorSID, { to_string(m_nSID) });
- }
- //Angle
- void CCollimatorDlg::OnBnClickedButton7()
- {
- DevActionValue(nsCOLL::ActionKey::SetCollimatorAngle, { to_string(m_nAngle) });
- }
- //Filter
- void CCollimatorDlg::OnBnClickedButton8()
- {
- DevActionValue(nsCOLL::ActionKey::SetCollimatorFilter, { to_string(m_nFilter) });
- }
- //Mode
- void CCollimatorDlg::OnBnClickedButton9()
- {
- //DevActionValue(nsCOLL::ActionKey::SetCollimatorMode, { m_nMode });
- }
- //Light?
- void CCollimatorDlg::OnBnClickedButton10()
- {
- if (m_bLight)
- {
- GetDlgItem(IDC_BUTTON10)->SetWindowText("LightOff");
- m_bLight = false;
- DevActionValue(nsCOLL::ActionKey::SetCollimatorLight, { to_string(m_bLight) });
- }
- else
- {
- m_bLight = true;
- GetDlgItem(IDC_BUTTON10)->SetWindowText("Lighton");
- DevActionValue(nsCOLL::ActionKey::SetCollimatorLight, { to_string(m_bLight) });
- }
- }
- //AI Video
- void CCollimatorDlg::OnBnClickedButton11()
- {
- DevActionValue("OpenSaveImage", { to_string(1) });
- CColmImageDlg ColmTest;
- ColmTest.DoModal();
- DevActionValue("OpenSaveImage", { to_string(0) });
- }
- //XSize_Value
- void CCollimatorDlg::OnEnKillfocusEdit1()
- {
- CString tempStr;
- m_Edit_XSize.GetWindowText(tempStr);
- m_nXsize = atoi(tempStr);
- }
- //YSize_Value
- void CCollimatorDlg::OnEnKillfocusEdit2()
- {
- CString tempStr;
- m_Edit_YSize.GetWindowText(tempStr);
- m_nYsize = atoi(tempStr);
- }
- //SID_Value
- void CCollimatorDlg::OnEnKillfocusEdit3()
- {
- CString tempStr;
- m_Edit_SID.GetWindowText(tempStr);
- m_nSID = atoi(tempStr);
- }
- //Angle_Value
- void CCollimatorDlg::OnEnKillfocusEdit4()
- {
- CString tempStr;
- m_Edit_Angle.GetWindowText(tempStr);
- m_nAngle = atoi(tempStr);
- }
- //Filter_Value
- void CCollimatorDlg::OnEnKillfocusEdit5()
- {
- CString tempStr;
- m_Edit_Filter.GetWindowText(tempStr);
- m_nFilter = atoi(tempStr);
- }
- //Mode_Value
- void CCollimatorDlg::OnEnKillfocusEdit6()
- {
- CString tempStr;
- m_Edit_Mode.GetWindowText(tempStr);
- m_nMode = atoi(tempStr);
- }
- void CCollimatorDlg::CreateCareRaySmartSys()
- {
- //智光器特殊逻辑
- FunGetImageData = (CallFunGetImageData)GetProcAddress(m_hDevLib, "COLM_GET_IMAGE_DATA");
- if (FunGetImageData == NULL)
- {
- ToolsDlgLog("CollimatorDevice:error FunGetImageData is null");
- }
- FunBeginTransImage = (CallFunBeginTransImage)GetProcAddress(m_hDevLib, "COLM_BEGIN_TRANS_IMAGE");
- if (FunBeginTransImage == NULL)
- {
- ToolsDlgLog("CollimatorDevice:error FunBeginTransImage is null");
- }
- FunEndTransImage = (CallFunEndTransImage)GetProcAddress(m_hDevLib, "COLM_END_TRANS_IMAGE");
- if (FunEndTransImage == NULL)
- {
- ToolsDlgLog("CollimatorDevice:error FunEndTransImage is null");
- }
- }
|