Skip to content

Commit

Permalink
Merge pull request #9 from vbtang/master
Browse files Browse the repository at this point in the history
	修复之前传感器添加后重新打开对话框数据同步的一些问题
  • Loading branch information
xiaoweihan authored Jul 2, 2017
2 parents 5cdce8d + 023ffa5 commit 98ecbda
Show file tree
Hide file tree
Showing 5 changed files with 182 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
152 changes: 151 additions & 1 deletion Src/Edislab/Edislab Pro/DlgSensorChoose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ void CDlgSensorChoose::InitCtrls()
m_ListSensor.SetImageList(IDB_SENSOR_ICON_LIST, 48);
}

RefreshChoosedSensorList();

}

void CDlgSensorChoose::OnBnClickedCheckAutoRecognize()
Expand Down Expand Up @@ -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);
}
}
}

Expand All @@ -276,6 +293,55 @@ void CDlgSensorChoose::OnBnClickedBtnDeleteAll()
{
// TODO: 在此添加控件通知处理程序代码

int nNum = m_ListChoosedSensor.GetCount();

for (int i = 0; i<nNum; i++)
{
int nIndex = (int)m_ListChoosedSensor.GetItemData(i);
if (-1 == nIndex)
{
continue;
}

if (m_setChooseSensorID.lower_bound(nIndex) != m_setChooseSensorID.end())
{
m_setChooseSensorID.erase(m_setChooseSensorID.lower_bound(nIndex));
}

m_ListChoosedSensor.DeleteString(m_ListChoosedSensor.GetCurSel());
// 为右侧待选传感器恢复删除的传感器
SENSOR_CONFIG_ELEMENT element = CSensorConfig::CreateInstance().GetSensorInfo(nIndex);
CString str(element.strSensorName.c_str());
nIndex = m_ListSensor.AddString(str);
str = element.strSensorModelName.c_str();
m_ListSensor.SetItemDescription(nIndex, str);
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);
}





m_mapChooseSensor.clear();
m_ListChoosedSensor.CleanUp();
m_setChooseSensorID.clear();
Expand All @@ -299,7 +365,7 @@ void CDlgSensorChoose::OnBnClickedBtnOk()
void CDlgSensorChoose::OnCbnSelchangeCmbSensorType()
{
// TODO: 在此添加控件通知处理程序代码
RefreshSensorList();
RefreshSensorList();
}


Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -441,3 +519,75 @@ 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)
{
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);
}
}
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 98ecbda

Please sign in to comment.