#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::iterator iter = m_AllPropertieVec.begin(); vector::iterator iter_end = m_AllPropertieVec.end(); for(;iter!=iter_end;iter++) { CPropertie *pPropertie = (*iter); if(pPropertie) { delete pPropertie; } } } //删除所有属性 void CPropertieMgr::DelAllPropertie() { map::iterator iter = m_PropertieValMap.begin(); map::iterator iter_end = m_PropertieValMap.end(); for(;iter!=iter_end;iter++) { if((*iter).second) { delete (*iter).second; } } m_PropertieValMap.clear(); } //保存指定名字的参数(避免操作不需要修改的参数) void CPropertieMgr::SavePropertieByName(vector &PropertieNameVec) { vector::iterator iter = m_AllPropertieVec.begin(); vector::iterator iter_end = m_AllPropertieVec.end(); for(;iter!=iter_end;iter++) { CPropertie *pPropertie = (*iter); if(pPropertie) { int size = PropertieNameVec.size(); for(int k=0;kGetPropertieName()==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 PropertieSet; CString CurGroupName; CString NewGroupName; CString CurModuleName; CString NewModuleName; vector::iterator iter = m_AllPropertieVec.begin(); vector::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<<"<--------------------------["<\n"; } NewGroupName = (pPropertie->m_GroupName); if(NewGroupName != "" && CurGroupName != NewGroupName) { CurGroupName = NewGroupName; FileStream<<"<---------------["<\n"; } FileStream<<"["<<(pPropertie->m_ShowName)<<"]"; FileStream<<"["; pPropertie->WriteToStream(FileStream); FileStream<<"]\n"; } } } #endif