diff --git a/.gitignore b/.gitignore index 153a99a..79077df 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ ipch/ *.ilk *.pdb *.suo -boost/ \ No newline at end of file +boost/ +*log +*.opensdf \ No newline at end of file diff --git a/Src/Edislab/Edislab Pro/DlgSensorChoose.cpp b/Src/Edislab/Edislab Pro/DlgSensorChoose.cpp index e409555..3ded462 100644 --- a/Src/Edislab/Edislab Pro/DlgSensorChoose.cpp +++ b/Src/Edislab/Edislab Pro/DlgSensorChoose.cpp @@ -113,6 +113,8 @@ void CDlgSensorChoose::InitCtrls() m_ListSensor.SetImageList(IDB_SENSOR_ICON_LIST, 48); } + RefreshChoosedSensorList(); + } void CDlgSensorChoose::OnBnClickedCheckAutoRecognize() @@ -268,6 +270,21 @@ void CDlgSensorChoose::OnBnClickedBtnDelete() m_ListSensor.SetItemData(nIndex, element.nSensorID); m_ListSensor.SetItemImage(nIndex, element.nSensorID); m_mapCurrentSensor[element.nSensorID] = element; + + // 删除传感器信息 + std::string strSensorUnit = element.SensorRangeInfoArray[0].strUnitName; + + std::string strSensorName = element.strSensorName + std::string("[") + strSensorUnit + std::string("]"); + CSensorIDGenerator::CreateInstance().DelSensor(strSensorName); + // 删除表格数据列 + CString strColumnName(strSensorName.c_str()); + CGridColumnGroupManager::CreateInstance().RemoveColumnInfo(_T("当前"), strColumnName); + //通知Grid刷新 + CWnd* pWnd = AfxGetMainWnd(); + if (nullptr != pWnd) + { + pWnd->PostMessage(WM_NOTIFY_GRID_GROUP_INFO_CHANGE,0,0); + } } } @@ -276,6 +293,55 @@ void CDlgSensorChoose::OnBnClickedBtnDeleteAll() { // TODO: 在此添加控件通知处理程序代码 + int nNum = m_ListChoosedSensor.GetCount(); + + for (int i = 0; iPostMessage(WM_NOTIFY_GRID_GROUP_INFO_CHANGE,0,0); + } + + + + + m_mapChooseSensor.clear(); m_ListChoosedSensor.CleanUp(); m_setChooseSensorID.clear(); @@ -299,7 +365,7 @@ void CDlgSensorChoose::OnBnClickedBtnOk() void CDlgSensorChoose::OnCbnSelchangeCmbSensorType() { // TODO: 在此添加控件通知处理程序代码 - RefreshSensorList(); + RefreshSensorList(); } @@ -344,8 +410,20 @@ void CDlgSensorChoose::RefreshSensorList() } CSensorConfig::CreateInstance().GetSensorList(vecSensorList, type); + + BOOST_FOREACH(auto &sensor, vecSensorList) { + // 已经添加的传感器禁止再次显示 + std::string strSensorUnit = sensor.SensorRangeInfoArray[0].strUnitName; + + std::string strSensorName = sensor.strSensorName + std::string("[") + strSensorUnit + std::string("]"); + if (CSensorIDGenerator::CreateInstance().IsSensorExist(strSensorName)) + { + continue; + } + + CString str(sensor.strSensorName.c_str()); int nIndex = m_ListSensor.AddString(str); str = sensor.strSensorModelName.c_str(); @@ -441,3 +519,75 @@ void CDlgSensorChoose::OnCbnSelchangeCmbRange() m_StaticResolutionRatio.SetWindowText(_T("")); m_CmbRange.EnableWindow(FALSE); } + + +void CDlgSensorChoose::RefreshChoosedSensorList() +{ + std::vector vecStrSensorList; + CSensorIDGenerator::CreateInstance().GetAllSensorName(vecStrSensorList); + + BOOST_FOREACH(auto &strSenorName , vecStrSensorList) + { + int nIndexof = strSenorName.find_first_of('['); + if (-1 == nIndexof) + { + continue; + } + + strSenorName = strSenorName.substr(0, nIndexof); + SENSOR_CONFIG_ELEMENT element = CSensorConfig::CreateInstance().GetSensorInfo(strSenorName); + if (-1 == element.nSensorID) + { + continue; + } + + CString str; + // 拼凑添加项的头 + // 传感器只能添加一个 2017.06.28 + int nNum = (int)m_setChooseSensorID.count(element.nSensorID); + if (nNum == 0) + { + + if (-1 == CSensorIDGenerator::CreateInstance().AddSensor(element.strSensorName)) + { + return; + } + + str.Format(_T("数据列:%s(%s)"), CString(element.strSensorSymbol.c_str()), CString(element.strSensorName.c_str())); + + // 拼凑添加项描述文字 + m_setChooseSensorID.insert(element.nSensorID); + int nIndex = 0; + if (element.SensorRangeInfoArray.size() > 0) + { + nIndex = m_ListChoosedSensor.AddString(str); + str = element.SensorRangeInfoArray[0].strRangeName.c_str(); + int nCharPos = str.Find('('); + str = str.Left(nCharPos); + str = _T("量程:") + str; + + m_ListChoosedSensor.SetItemDescription(nIndex, str); + // 将sensor ID作为item Data + m_ListChoosedSensor.SetItemData(nIndex, element.nSensorID); + + m_ListChoosedSensor.SetItemImage(nIndex, element.nSensorID); + } + + // 删除已有的传感器,防止重新添加 + nIndex = m_ListSensor.GetCurSel(); + m_ListSensor.DeleteString(nIndex); + auto iter = m_mapCurrentSensor.find(nIndex); + if (m_mapCurrentSensor.end() != iter) + { + m_mapCurrentSensor.erase(iter); + } + } + }; + + //通知Grid刷新 + CWnd* pWnd = AfxGetMainWnd(); + if (nullptr != pWnd) + { + pWnd->PostMessage(WM_NOTIFY_GRID_GROUP_INFO_CHANGE,0,0); + } +} \ No newline at end of file diff --git a/Src/Edislab/Edislab Pro/DlgSensorChoose.h b/Src/Edislab/Edislab Pro/DlgSensorChoose.h index ae62472..e2154c0 100644 --- a/Src/Edislab/Edislab Pro/DlgSensorChoose.h +++ b/Src/Edislab/Edislab Pro/DlgSensorChoose.h @@ -73,6 +73,8 @@ class CDlgSensorChoose : public CBaseDialog void RefreshRange(); + void RefreshChoosedSensorList(); + public: afx_msg void OnBnClickedCheckAutoRecognize(); virtual BOOL OnInitDialog(); diff --git a/Src/Edislab/Edislab Pro/SensorConfig.cpp b/Src/Edislab/Edislab Pro/SensorConfig.cpp index 4fb894d..4d14305 100644 --- a/Src/Edislab/Edislab Pro/SensorConfig.cpp +++ b/Src/Edislab/Edislab Pro/SensorConfig.cpp @@ -499,6 +499,29 @@ SENSOR_CONFIG_ELEMENT CSensorConfig::GetSensorInfo(int nSensorID) return SENSOR_CONFIG_ELEMENT(); } +/******************************************************************* +*函数名称:GetSensorInfo +*功能描述:根据传感器名称获取传感器信息 +*输入参数: +*输出参数: +*返回值: +*作者:xiaowei.han +*日期:2017/06/10 8:39:02 +*******************************************************************/ +SENSOR_CONFIG_ELEMENT CSensorConfig::GetSensorInfo(std::string strSensorName) +{ + BOOST_FOREACH(auto &sensor, m_SensorConfigArray) + { + if (strSensorName == sensor.strSensorName) + { + return sensor; + } + } + + return SENSOR_CONFIG_ELEMENT(); +} + + /******************************************************************* *函数名称:GetSensorRecordInfo *功能描述:获取传感器采样信息 diff --git a/Src/Edislab/Edislab Pro/SensorConfig.h b/Src/Edislab/Edislab Pro/SensorConfig.h index 61d095e..5324a18 100644 --- a/Src/Edislab/Edislab Pro/SensorConfig.h +++ b/Src/Edislab/Edislab Pro/SensorConfig.h @@ -42,6 +42,9 @@ class CSensorConfig //根据传感器ID返回传感器信息 SENSOR_CONFIG_ELEMENT GetSensorInfo(int nSensorID); + + // 根据传感器名称返回传感器信息 + SENSOR_CONFIG_ELEMENT GetSensorInfo(std::string strSensorName); //获取传感器采样配置信息 const SENSOR_RECORD_INFO& GetSensorRecordInfo();