| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 | // MsrParamFileMgr.cpp : implementation file//#include "stdafx.h"#include "MsrParamFileMgr.h"namespace OTSMODEL {	using namespace OTSDATA;	// CMsrParamFileMrg 	// constructor	CMsrParamFileMrg::CMsrParamFileMrg()	{		// initialization		void Init();	}	// destructor	CMsrParamFileMrg::~CMsrParamFileMrg()	{		// cleanup		Cleanup();	}	// CMsrParamFileMrg member functions	// public	// serialization	 	void CMsrParamFileMrg::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)	{				xmls::xInt xMrsParamFileMark; 		xmls::xString xMrsOaramFileVersion; 		xmls::Slo slo;		slo.Register("MrsParamFileMark", &xMrsParamFileMark);		slo.Register("MrsParamFileVersion", &xMrsOaramFileVersion);		slo.Register("MsrParams", m_poMsrParams.get());				if (isStoring)		{			xMrsParamFileMark = MRS_PARAM_FILE_MARK;			xMrsOaramFileVersion = MRS_PARAM_FILE_VERSION;						slo.Serialize(true, classDoc, rootNode);		}		else		{			slo.Serialize(false, classDoc, rootNode);					}	}	// Load/Save	BOOL CMsrParamFileMrg::Load(CString a_strPathName /*= _T("")*/, BOOL a_bClear /*= TRUE*/)	{		AFX_MANAGE_STATE(AfxGetStaticModuleState());		// clear all data if necessary		if (a_bClear)		{			Init();		}		// check file pathname		a_strPathName.Trim();		if (a_strPathName.IsEmpty())		{			// file open dialog						CFileDialog dlg(TRUE, MESUREMENT_PARAM_FILE_EXT,NULL, OFN_FILEMUSTEXIST, MESUREMENT_PARAM_FILE_FILTER);			TCHAR _szPath[MAX_PATH + 1] = { 0 };			GetModuleFileName(NULL, _szPath, MAX_PATH);			(_tcsrchr(_szPath, _T('\\')))[1] = 0;//删除文件名,只获得路径字串			CString strPath;			for (int n = 0; _szPath[n]; n++) {				if (_szPath[n] != _T('\\')) {					strPath += _szPath[n];				}				else {					strPath += _T("\\");				}			}			CString Suffix = "Config\\ProData";			CString FinalPath = strPath + Suffix;			dlg.m_ofn.lpstrInitialDir = FinalPath;			if (dlg.DoModal() != IDOK)			{				return FALSE;			}			// get file pathname			a_strPathName = dlg.GetPathName();		}				// open the particle analysis standard file				tinyxml2::XMLDocument doc;		doc.LoadFile(a_strPathName);//载入xml文件		tinyxml2::XMLElement *rootNode;		rootNode = doc.FirstChildElement(RootClassName);		Serialize(false, &doc, rootNode);		// file pathname		m_strPathName = a_strPathName;		// ok, return TRUE		return TRUE;	}	BOOL CMsrParamFileMrg::Save(CString a_strPathName /*= _T("")*/)	{		AFX_MANAGE_STATE(AfxGetStaticModuleState());		// check file pathname		a_strPathName.Trim();		if (a_strPathName.IsEmpty())		{			// file save as dialog			CFileDialog dlg(FALSE, MESUREMENT_PARAM_FILE_EXT, NULL, OFN_OVERWRITEPROMPT, MESUREMENT_PARAM_FILE_FILTER);			TCHAR _szPath[MAX_PATH + 1] = { 0 };			GetModuleFileName(NULL, _szPath, MAX_PATH);			(_tcsrchr(_szPath, _T('\\')))[1] = 0;//删除文件名,只获得路径字串			CString strPath;			for (int n = 0; _szPath[n]; n++) {				if (_szPath[n] != _T('\\')) {					strPath += _szPath[n];				}				else {					strPath += _T("\\");				}			}			CString Suffix = "Config\\ProData";			CString FinalPath = strPath + Suffix;			dlg.m_ofn.lpstrInitialDir = FinalPath;			if (dlg.DoModal() != IDOK)			{				return FALSE;			}			// get file pathname			a_strPathName = dlg.GetPathName();		}		// create the file				tinyxml2::XMLDocument doc;		doc.LoadFile(a_strPathName);//载入xml文件		doc.Clear();		tinyxml2::XMLDeclaration* declaration = doc.NewDeclaration();//添加xml文件头申明		doc.InsertFirstChild(declaration);		tinyxml2::XMLElement *rootNode;		rootNode = doc.NewElement(RootClassName);		doc.InsertEndChild(rootNode);		Serialize(true, &doc, rootNode);		int result = doc.SaveFile(a_strPathName);		// file pathname		m_strPathName = a_strPathName;				// ok, return TRUE		return TRUE;	}	void CMsrParamFileMrg::SetMsrParamFile(CMsrParamsPtr a_poMsrParams)	{		ASSERT(a_poMsrParams);		if (!a_poMsrParams)		{			LogErrorTrace(__FILE__, __LINE__, _T("SetMsrParamFile::invalid param pointer"));			return;		}		m_poMsrParams = CMsrParamsPtr(new CMsrParams(*a_poMsrParams.get()));	}	// protected	// cleanup 	void CMsrParamFileMrg::Cleanup()	{		// need to do nothing at the moment	}	// initialization	void CMsrParamFileMrg::Init()	{		// initialization		m_poMsrParams = CMsrParamsPtr(new CMsrParams());	}	// duplication 	void CMsrParamFileMrg::Duplicate(const CMsrParamFileMrg& a_oSource)	{		// initialization		Init();		// copy data over 		m_poMsrParams = CMsrParamsPtr(new CMsrParams(a_oSource.m_poMsrParams.get()));	}}
 |