Skip to content

Commit

Permalink
修复之前传感器添加后重新打开对话框数据同步的一些问题
Browse files Browse the repository at this point in the history
  • Loading branch information
vbtang committed Jul 2, 2017
1 parent c5dd680 commit 19f015f
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ ipch/
*.ilk
*.pdb
*.suo
boost/
boost/
*log
*.opensdf
95 changes: 94 additions & 1 deletion Src/Edislab/Edislab Pro/DlgSensorChoose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ void CDlgSensorChoose::InitCtrls()
m_ListSensor.SetImageList(IDB_SENSOR_ICON_LIST, 48);
}

RefreshChoosedSensorList();

}

void CDlgSensorChoose::OnBnClickedCheckAutoRecognize()
Expand Down Expand Up @@ -234,6 +236,19 @@ void CDlgSensorChoose::OnBnClickedBtnDelete()
m_ListSensor.SetItemData(nIndex, element.nSensorID);
m_ListSensor.SetItemImage(nIndex, element.nSensorID);
m_mapCurrentSensor[element.nSensorID] = element;

// 删除传感器信息
CSensorIDGenerator::CreateInstance().DelSensor(element.strSensorName);
// 删除表格数据列
CString strColumnName;
strColumnName.Format(_T("%s(%s)"), CString(element.strSensorSymbol.c_str()), CString(element.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);
}
}
}

Expand Down Expand Up @@ -264,7 +279,7 @@ void CDlgSensorChoose::OnBnClickedBtnOk()
void CDlgSensorChoose::OnCbnSelchangeCmbSensorType()
{
// TODO: 在此添加控件通知处理程序代码
RefreshSensorList();
RefreshSensorList();
}


Expand Down Expand Up @@ -309,8 +324,16 @@ void CDlgSensorChoose::RefreshSensorList()
}

CSensorConfig::CreateInstance().GetSensorList(vecSensorList, type);


BOOST_FOREACH(auto &sensor, vecSensorList)
{
// 已经添加的传感器禁止再次显示
if (CSensorIDGenerator::CreateInstance().IsSensorExist(sensor.strSensorName))
{
continue;
}

CString str(sensor.strSensorName.c_str());
int nIndex = m_ListSensor.AddString(str);
str = sensor.strSensorModelName.c_str();
Expand Down Expand Up @@ -406,3 +429,73 @@ void CDlgSensorChoose::OnCbnSelchangeCmbRange()
m_StaticResolutionRatio.SetWindowText(_T(""));
m_CmbRange.EnableWindow(FALSE);
}


void CDlgSensorChoose::RefreshChoosedSensorList()
{
std::vector<std::string> vecStrSensorList;
CSensorIDGenerator::CreateInstance().GetAllSensorName(vecStrSensorList);

BOOST_FOREACH(auto &strSenorName , vecStrSensorList)
{
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);
}

// 添加列表显示列
COLUMN_INFO AddColumnInfo;
AddColumnInfo.strColumnName.Format(_T("%s(%s)"), CString(element.strSensorSymbol.c_str()), CString(element.strSensorName.c_str()));
CGridColumnGroupManager::CreateInstance().AddDisplayColumnInfo(_T("当前"), AddColumnInfo);

// 删除已有的传感器,防止重新添加
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);
}
}
2 changes: 2 additions & 0 deletions Src/Edislab/Edislab Pro/DlgSensorChoose.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class CDlgSensorChoose : public CBaseDialog

void RefreshRange();

void RefreshChoosedSensorList();

public:
afx_msg void OnBnClickedCheckAutoRecognize();
virtual BOOL OnInitDialog();
Expand Down
23 changes: 23 additions & 0 deletions Src/Edislab/Edislab Pro/SensorConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*功能描述:获取传感器采样信息
Expand Down
3 changes: 3 additions & 0 deletions Src/Edislab/Edislab Pro/SensorConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 19f015f

Please sign in to comment.