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.

140 lines
4.2 KiB
C++

#include "StdAfx.h"
#include "PropertieMgr.h"
#include "Propertie.h"
#include "LogMgr.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::SavePropertieByName(vector<CString> &PropertieNameVec)
{
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)
{
int size = PropertieNameVec.size();
for(int k=0;k<size;k++)
{
if(pPropertie->GetPropertieName()==PropertieNameVec[k])
{
pPropertie->WriteRead(false);
CString s;
s = "Par---->Save Par By Name: "+PropertieNameVec[k];
gLogMgr->WriteDebugLog(s);
break;
}
}
}
}
}
#if 1
//保存所有属性到一个文本文件
void CPropertieMgr::SaveAllPropertieToTxtFile(CString FilePath)
{
gLogMgr->WriteDebugLog("Func---->SaveAllPropertieToTxtFile");
ofstream FileStream;
FileStream.open(FilePath);
set<void *> PropertieSet;
CString CurGroupName;
CString NewGroupName;
CString CurModuleName;
CString NewModuleName;
vector<CPropertie*>::iterator iter = m_AllPropertieVec.begin();
vector<CPropertie*>::iterator iter_end = m_AllPropertieVec.end();
for(;iter!=iter_end;iter++)
{
CPropertie *pPropertie = (*iter);
if(PropertieSet.count(pPropertie->m_pVal))//过滤重复的参数
continue;
PropertieSet.insert(pPropertie->m_pVal);
if(pPropertie && pPropertie->m_ShowName !="")
{
NewModuleName = (pPropertie->m_ModuleName);
if(NewModuleName != "" && CurGroupName != NewModuleName)
{
CurModuleName = NewModuleName;
FileStream<<"<--------------------------["<<NewModuleName<<"]-------------------------->\n";
}
NewGroupName = (pPropertie->m_GroupName);
if(NewGroupName != "" && CurGroupName != NewGroupName)
{
CurGroupName = NewGroupName;
FileStream<<"<---------------["<<NewGroupName<<"]--------------->\n";
}
FileStream<<"["<<(pPropertie->m_ShowName)<<"]";
FileStream<<"[";
pPropertie->WriteToStream(FileStream);
FileStream<<"]\n";
}
}
}
#endif