You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
3.1 KiB
C++
132 lines
3.1 KiB
C++
#include "StdAfx.h"
|
|
#include "PropertieMgr.h"
|
|
#include "Propertie.h"
|
|
#include "GlobalFunction.h"
|
|
CPropertieMgr gDevicePropertieMgr;//设备属性管理
|
|
CPropertieMgr gDrawPropertieMgr;//绘制属性管理
|
|
|
|
CPropertieMgr::CPropertieMgr(void)
|
|
{
|
|
m_bSaveAllPropertie = true;//保存所有需要存储的属性
|
|
}
|
|
CPropertieMgr::~CPropertieMgr(void)
|
|
{
|
|
//删除所有属性
|
|
DelAllPropertie();
|
|
DelAllPropertieVec();
|
|
}
|
|
//响应属性变化-->通知对应的模块
|
|
void CPropertieMgr::OnPropertyChanged(LPARAM lParam)
|
|
{
|
|
CMFCPropertyGridProperty*pProp = (CMFCPropertyGridProperty*)lParam;
|
|
//取得映射变量
|
|
if (m_PropertieValMap.count(pProp))
|
|
{
|
|
CPropertie *pPropertie = m_PropertieValMap[pProp];
|
|
pPropertie->PropertyChangeVal(pProp->GetValue());//设置新值
|
|
}
|
|
}
|
|
//添加映射
|
|
void CPropertieMgr::Insert(CMFCPropertyGridProperty* p1,CPropertie* p2)
|
|
{
|
|
if(m_bSaveAllPropertie)
|
|
{
|
|
m_AllPropertieVec.push_back(p2);
|
|
}
|
|
else
|
|
{
|
|
m_PropertieValMap.insert(make_pair(p1, p2));
|
|
}
|
|
}
|
|
void CPropertieMgr::DelAllPropertieVec()
|
|
{
|
|
vector<CPropertie*>::iterator iter = m_AllPropertieVec.begin();
|
|
vector<CPropertie*>::iterator iter_end = m_AllPropertieVec.end();
|
|
for(;iter!=iter_end;iter++)
|
|
{
|
|
CPropertie *pPropertie = (*iter);
|
|
if(pPropertie)
|
|
{
|
|
delete pPropertie;
|
|
}
|
|
}
|
|
}
|
|
//删除所有属性
|
|
void CPropertieMgr::DelAllPropertie()
|
|
{
|
|
map<CMFCPropertyGridProperty*,CPropertie*>::iterator iter = m_PropertieValMap.begin();
|
|
map<CMFCPropertyGridProperty*,CPropertie*>::iterator iter_end = m_PropertieValMap.end();
|
|
for(;iter!=iter_end;iter++)
|
|
{
|
|
if((*iter).second)
|
|
{
|
|
delete (*iter).second;
|
|
}
|
|
}
|
|
m_PropertieValMap.clear();
|
|
}
|
|
//强制保存所有的属性到文件
|
|
void CPropertieMgr::SaveAllPropertie()
|
|
{
|
|
vector<CPropertie*>::iterator iter = m_AllPropertieVec.begin();
|
|
vector<CPropertie*>::iterator iter_end = m_AllPropertieVec.end();
|
|
for(;iter!=iter_end;iter++)
|
|
{
|
|
CPropertie *pPropertie = (*iter);
|
|
if(pPropertie)
|
|
{
|
|
pPropertie->WriteRead(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool CPropertieMgr::ChangePropertieByName(CString name, _variant_t newVal)
|
|
{
|
|
auto iter = m_PropertieValMap.begin();
|
|
auto iter_end = m_PropertieValMap.end();
|
|
for (;iter != iter_end;iter++)
|
|
{
|
|
if ((iter->first)->GetName() == name)
|
|
{
|
|
iter->second->PropertyChangeVal(newVal);
|
|
gDevicePropertieMgr.UpdateDevicePropertyPage();
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool CPropertieMgr::ChangePropertieByVal(void * pVal, _variant_t newVal)
|
|
{
|
|
auto iter = m_AllPropertieVec.begin();
|
|
auto iter_end = m_AllPropertieVec.end();
|
|
for (;iter != iter_end;iter++)
|
|
{
|
|
if ((*iter)->GetpVal() == pVal)
|
|
{
|
|
(*iter)->PropertyChangeVal(newVal);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void CPropertieMgr::UpdateDevicePropertyPage()
|
|
{
|
|
GetFrame()->m_PaneDevicePar.OnCbnSelPropertyChange();
|
|
}
|
|
/*
|
|
CPropertie * CPropertieMgr::GetPropertie(void * pVal)
|
|
{
|
|
auto iter = m_AllPropertieVec.begin();
|
|
auto iter_end = m_AllPropertieVec.end();
|
|
for (;iter != iter_end;iter++)
|
|
{
|
|
if ((*iter)->GetpVal() == pVal)
|
|
{
|
|
return *iter;
|
|
}
|
|
}
|
|
return NULL;
|
|
}*/
|