#pragma once // FileName: OTSEDSBase.h // Brief: EDS Base Class , x-Ray acquisition system // Author: Anna.Hao // Data: 6/30/2017 #include "PosXray.h" #include "Element.h" #include "SEMCommonConst.h" #include "Bruker\OTSBrukerImpl_const.h" namespace OTSController { using namespace OTSDATA; const CString SIMULATION_SPECTRUM_FILENAME = _T("SimSpectrum.txt"); #ifdef UNICODE #define isdigit_t iswdigit #else #define isdigit_t isdigit #endif // Class OTSController::COTSEDS define. class __declspec(dllexport) COTSEDSBase { public: COTSEDSBase(void); ~COTSEDSBase(void); // Get the name of EDS // Input: void // Output: CString, name of EDS CString GetName() { CString strR = EDSController::GetName((int)GetType()); return strR; } // Get EDS type // virtual virtual EDSController::EDS_ID GetType() = 0; // Finished the instance. // virtual //virtual void FinishedInstance() = 0; // Initialization method // virtual virtual BOOL Init() = 0; // To show whether the detector can collect a set of x-Ray one go // virtual virtual BOOL IsSupportSetCollection() = 0; // Quantification virtual BOOL IsSupportQuantification() = 0; virtual BOOL GetQuantificationMethods(std::vector& a_vMethods) = 0; virtual BOOL QuantifyXrayPoint(CPosXray* a_pXRayPoint, LPCTSTR a_sMethodName) = 0; virtual BOOL QuantifySpectrumFile(LPCTSTR a_sFilePathName, LPCTSTR a_sMethodName, CElementChemistriesList& a_listElementChemistry) = 0; virtual BOOL QuantifySpectrumOut(DWORD a_nMilliseconds, long* a_pCounts, DWORD a_nBufferSize, CElementChemistriesList& a_listElementChemistry) = 0; // collect x ray points // virtual /* virtual BOOL CollectXRayPoints(std::vector& a_vXRayPoints, const DWORD a_nXRayAQTime) = 0; virtual BOOL CollectXRayPoints(std::vector& a_vXRayPoints, const DWORD a_nXRayAQTime) = 0; virtual BOOL CollectXRayPointsByFeatures(std::vector& a_listXRayPoints, std::vector>& a_listFeatures, const DWORD a_nXRayAQTime) = 0;*/ // collect spectrum data // virtual virtual BOOL CollectSpectrum(DWORD a_nMilliseconds) = 0; virtual BOOL CollectSpectrum(DWORD a_nMilliseconds, const CPoint& a_oPoint) = 0; virtual BOOL CollectSpectrum(DWORD a_nMilliseconds, long* a_pCounts, DWORD a_nBufferSize) = 0; virtual BOOL StopXrayAcquistion() = 0; // quantify spectrum // Get x-Ray data // virtual virtual DWORD* GetXRayData() = 0; // Set Amp Time Index for all detectors // virtual virtual BOOL SetAmpTimeIndex(long a_nIndex) = 0; // get live time // virtual virtual float GetLiveTime(void) = 0; // get max points limit // virtual virtual long GetMaxPointLimit(void) = 0; virtual BOOL GetXRayByPoints(std::vector& a_vXRayPoints, const DWORD a_nXRayAQTime) = 0; virtual BOOL GetXRayByFeatures(std::vector& a_listXRayPoints, std::vector& a_listFeatures, const DWORD a_nXRayAQTime) = 0; BOOL GetXRayByFeaturesFromMultiPoint(std::vector& a_listXRayPoints, std::vector>& a_listFeatures, const DWORD a_nXRayAQTime); // Quantification virtual void SetQuantification(BOOL a_bQuantification) = 0; virtual BOOL GetQuantification() = 0; virtual DWORD GetNumberOfChannels(void) = 0; BOOL CollectASpectrumFromTxtFile(DWORD* a_pCounts, DWORD a_nBufferSize); // get company system data path CString GetCompanySysDataPathName() { // get common data pathname string CString strCommonDataPathName = GetOSCommonDataPathName(); if (strCommonDataPathName.IsEmpty()) { // failed to get common data pathname string LogErrorTrace(__FILE__, __LINE__, _T("GetOTSPackSysDataPathName: failed to common data pathname string.")); return _T(""); } // company system data pathname // e.g. "c:\ProgramData\Config\" //CString strCmpSysDataPath = strCommonDataPathName + STR_COMPANYNAME + _T("\\") + STR_SYSTEM_DATA + _T("\\"); CString strCmpSysDataPath = strCommonDataPathName + STR_COMPANYNAME + _T("\\") + STR_SIMULATE_DATA + _T("\\"); // return company system data pathname return strCmpSysDataPath; } // get system common data folder pathname // return "" if failed CString GetOSCommonDataPathName() { CString strPathName= _T(".\\"); /*if (strPathName.Right(1) != _T('.\\')) { strPathName += }*/ return strPathName; } // check if the file exists or not BOOL Exists(LPCTSTR a_sPath) { return ::PathFileExists(a_sPath) == TRUE; } std::vector LoadTextFileToCStingList(CString a_strPathName, int a_nLine /*= -1*/) { // string list std::vector listStr; // load try { // open the file CStdioFile file; file.Open(a_strPathName, CFile::modeRead | CFile::shareDenyWrite); // read the file CString strLine; int nLine = 0; while (file.ReadString(strLine) && nLine != a_nLine) { // get a line // remove comments int nCommentPos = strLine.Find(OTS_TEXT_FILE_COMMENT); if (nCommentPos != -1) { // remove comments strLine = strLine.Left(nCommentPos); } // process the line strLine.Trim(); // jump over empty lines if (strLine.IsEmpty()) { continue; } listStr.push_back(strLine); } file.Close(); } catch (CFileException* pe) { pe->Delete(); return listStr; } // return string list return listStr; } // Strings to int. BOOL StringToInt(LPCTSTR a_sValue, int& a_nValue) { if (!IsDigitString(a_sValue)) { LogErrorTrace(__FILE__, __LINE__, _T("StringToInt: value string (%s) is not digit string."), a_sValue); return FALSE; } a_nValue = _ttoi(a_sValue); return TRUE; } // Determines whether is digit string. BOOL IsDigitString(LPCTSTR a_sValue) { CString strInt = a_sValue; strInt.Trim(); if (strInt.IsEmpty()) { LogErrorTrace(__FILE__, __LINE__, _T("IsDigitString: value string is an empty string.")); return FALSE; } int nStart = 0; if (strInt[nStart] == _T('-')) { ++nStart; } // cycle through string and check each character if it is a digit for (; nStart < strInt.GetLength(); ++nStart) { if (!isdigit_t(strInt[nStart])) { LogErrorTrace(__FILE__, __LINE__, _T("IsDigitString: value string (%s) is not a digit string."), strInt); return FALSE; } } return TRUE; } protected: // x-Ray data DWORD m_nRayData[(long)EDSConst::XANA_CHANNELS]; //amplify time list float m_list_ampTime[(long)EDSConst::MAX_AMPTIME_CONSTANTS]; //amplify times long m_nTimeCounts; // do quantification BOOL m_bDoQuantification; }; typedef std::shared_ptr COTSEDSBasePtr; } // namespace OTSController