123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- #include "stdafx.h"
- #include "OTSSpectrumLibFileMgr.h"
- #include "OTSFileSys.h"
- using namespace OTSTools;
- namespace OTSClassifyEngine
- {
- // project file extension
- const CString ORETYPE_FILE_EXT = _T("db");
- const CString ORETYPE_FILE_FILTER = _T("Particle Type Files (*.db)|*.db|All Files (*.*)|*.*||");
- const CString SysSTDLibFilePath = ".\\Config\\SysData\\";
- // constructor
- CSpectrumLibFileMgr::CSpectrumLibFileMgr(std::string fileName)
- {
- m_strPathName = SysSTDLibFilePath+fileName.c_str();
- Init();
- }
- // destructor
- CSpectrumLibFileMgr::~CSpectrumLibFileMgr()
- {
- // cleanup
- Cleanup();
- }
- BOOL CSpectrumLibFileMgr::CreateSTDLibFile()
- {
- // check file name
- m_strPathName.Trim();
- if (m_strPathName.IsEmpty())
- {
- // error, wrong file name
- LogErrorTrace(__FILE__, __LINE__, _T("Empty file path name"));
- ASSERT(FALSE);
- return FALSE;
- }
- if (COTSFileSys::Exists(m_strPathName))
- {
- if (!Open(m_strPathName, FALSE))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("Open STD file failed."));
- ASSERT(FALSE);
- return FALSE;
- }
- }
- else
- {
- if (!Create(m_strPathName))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("Create STD file failed."));
- ASSERT(FALSE);
- return FALSE;
- }
- }
- return TRUE;
- }
- // Load/Save
- BOOL CSpectrumLibFileMgr::LoadSTDSpectrumItems(CSpectrumSTDItemList& itms, BOOL bClear /*= TRUE*/)
- {
-
- ;
- // program manager param file exists?
- if (!COTSFileSys::Exists(m_strPathName))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("GenerateSTDLib: there is no STD lib file."+ m_strPathName));
- return FALSE;
- }
-
-
-
- if (!CreateSTDLibFile())
- {
- LogErrorTrace(__FILE__, __LINE__, _T("Create or open STD file failed."));
- return FALSE;
- }
- m_pSTDLibDB=GetSTDLibDB();
-
- auto specItms= m_pSTDLibDB->GetSTDItems(bClear);
- for (auto itm : specItms)
- {
- itms.push_back(itm);
- }
- return TRUE;
- }
- BOOL CSpectrumLibFileMgr::InsertSpectrumSTDItemIntoDB(CSpectrumSTDItemPtr itm)
- {
- if (!CreateSTDLibFile())
- {
- LogErrorTrace(__FILE__, __LINE__, _T("Create or open STD file failed."));
- return FALSE;
- }
- auto specDB = GetSTDLibDB();
- auto specTableInfoPtr = specDB->GetTableInfo();
- auto datastorePtr = specDB->GetDatastore();
- auto sInsertFormat = specTableInfoPtr->GetInsertCommandFormatString(TRUE);
- CString sSQLCommand;
- DWORD* xrayData =itm->GetXraySpectrum()->GetXrayData();
- sSQLCommand.Format(sInsertFormat,
- itm->GetID(),
- itm->GetName(),
- "",
- 0.0,
- 0,
- 0,
- 0,
- itm->GetColor()
-
-
- );
-
- auto sql = sSQLCommand.GetBuffer();
- if (!datastorePtr->InsertBlobData(sql, xrayData, GENERALXRAYCHANNELS * 4))
- {
- ASSERT(FALSE);
- return FALSE;
- }
- return TRUE;
- }
- CSTDLibDBPtr CSpectrumLibFileMgr::GetSTDLibDB()
- {
- if (!m_pSTDLibDB)
- {
- auto datastorePtr = GetDatastore();
- if (datastorePtr)
- {
- m_pSTDLibDB = std::make_shared<CSTDLibDB>(datastorePtr);
- }
- }
- ASSERT(m_pSTDLibDB);
- return m_pSTDLibDB;
- }
-
- void CSpectrumLibFileMgr::Init()
- {
- }
- void CSpectrumLibFileMgr::Cleanup()
- {
- }
- }
|