BrukerSPXFileMgr.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. #include "stdafx.h"
  2. #include "BrukerSPXFileMgr.h"
  3. #include "ControllerHelper.h"
  4. namespace OTSController {
  5. #pragma warning(disable: 4835)
  6. std::vector<SPXLine> CBrukerSPXFileMgr::m_vSpxFileLines = {
  7. { ("<?xml version=\"1.0\" encoding=\"WINDOWS - 1252\" standalone=\"yes\"?>") },
  8. { ("<TRTSpectrum>") },
  9. { (" <RTHeader/>") },
  10. { (" <ClassInstance Type=\"TRTSpectrum\" Name=\"Pyrite real\">"), SPXLineType::NAME },
  11. { (" <TRTHeaderedClass>") },
  12. { (" <ClassInstance Type=\"TRTSpectrumHardwareHeader\">") },
  13. { (" <TRTKnownHeader>") },
  14. { (" <Type>RTHardware</Type>") },
  15. { (" <Size>137</Size>") },
  16. { (" </TRTKnownHeader>") },
  17. { (" <RealTime>9627</RealTime>") },
  18. { (" <LifeTime>8658</LifeTime>") },
  19. { (" <DeadTime>1E1</DeadTime>") },
  20. { (" <ZeroPeakPosition>96</ZeroPeakPosition>") },
  21. { (" <ZeroPeakFrequency>25000</ZeroPeakFrequency>") },
  22. { (" <PulseDensity>113189</PulseDensity>") },
  23. { (" <Amplification>2E4</Amplification>") },
  24. { (" <ShapingTime>400000</ShapingTime>") },
  25. { (" </ClassInstance>") },
  26. { (" <ClassInstance Type=\"TRTDetectorHeader\">") },
  27. { (" <TRTKnownHeader>") },
  28. { (" <Type>RTDetector</Type>") },
  29. { (" <Version>5</Version>") },
  30. { (" <Size>9932</Size>") },
  31. { (" </TRTKnownHeader>") },
  32. { (" <Technology>SD3pr</Technology>") },
  33. { (" <Serial>5322</Serial>") },
  34. { (" <Type>XFlash 6|10</Type>") },
  35. { (" <DetectorThickness>0.45</DetectorThickness>") },
  36. { (" <SiDeadLayerThickness>0.029</SiDeadLayerThickness>") },
  37. { (" <DetLayers>eJyzcUkt8UmsTC0qtrMB0wYKjiX5ubZKhsZKCiEZmcnZeanFxbZKpq66xkr6UDWGUDXmKEos9ICKjOCKjKCKTFEUmSGbYwxVYoZbiQlUiQWqErhV+gj3AwCpRT07</DetLayers>") },
  38. { (" <WindowType>slew AP3.3</WindowType>") },
  39. { (" <WindowLayers>") },
  40. { (" <Layer0 Atom=\"5\" Thickness=\"1.3E-2\"/>") },
  41. { (" <Layer1 Atom=\"6\" Thickness=\"1.45E-1\"/>") },
  42. { (" <Layer2 Atom=\"7\" Thickness=\"4.5E-2\"/>") },
  43. { (" <Layer3 Atom=\"8\" Thickness=\"8.5E-2\"/>") },
  44. { (" <Layer4 Atom=\"13\" Thickness=\"3.5E-2\"/>") },
  45. { (" <Layer5 Atom=\"14\" Thickness=\"3.8E2\" RelativeArea=\"2.3E-1\"/>") },
  46. { (" </WindowLayers>") },
  47. { (" <Corrections>") },
  48. { (" <Escape/>") },
  49. { (" <Tail>") },
  50. { (" <FormulaType>Internal</FormulaType>") },
  51. { (" <MainCorrection>1</MainCorrection>") },
  52. { (" </Tail>") },
  53. { (" <Shelf>") },
  54. { (" <FormulaType>Internal</FormulaType>") },
  55. { (" <RangeStart>8E-2</RangeStart>") },
  56. { (" <RangeEnd>1E1</RangeEnd>") },
  57. { (" <MainCorrection>1</MainCorrection>") },
  58. { (" <Coefficient0>1</Coefficient0>") },
  59. { (" </Shelf>") },
  60. { (" <Shift>") },
  61. { (" <FormulaType>Internal</FormulaType>") },
  62. { (" <RangeStart>8E-2</RangeStart>") },
  63. { (" <RangeEnd>5.55E-1</RangeEnd>") },
  64. { (" <MainCorrection>1</MainCorrection>") },
  65. { (" </Shift>") },
  66. { (" <FWHMShift/>") },
  67. { (" </Corrections>") },
  68. { (" <CorrectionType>3</CorrectionType>") },
  69. { (" <ResponseFunctionCount>21</ResponseFunctionCount>") },
  70. { (" <SampleCount>5</SampleCount>") },
  71. { (" <SampleOffset>-3</SampleOffset>") },
  72. { (" <PulsePairResTimeCount>0</PulsePairResTimeCount>") },
  73. { (" <PileUpMinEnergy>1</PileUpMinEnergy>") },
  74. { (" <PileUpWithBG>False</PileUpWithBG>") },
  75. { (" <TailFactor>1</TailFactor>") },
  76. { (" <ShelfFactor>1</ShelfFactor>") },
  77. { (" <ShiftFactor>1.106</ShiftFactor>") },
  78. { (" <ShiftFactor2>-8.95E-1</ShiftFactor2>") },
  79. { (" <ShiftData>0.07,0.0058,0.183,0.0078,0.277,0.0058,0.555,0,1.1,0,3.293,0.0064,5.89,0,0,0,0,0,</ShiftData>") },
  80. { (" <ResponseFunction>0,0.01,0.000801,0.01,0.00298,0.01,0.008902,0.01,0.025,0.010046,0.041098,0.013475,0.04702,0.017302,0.049199,0.019237,0.05,0.02,</ResponseFunction>") },
  81. { (" <ResponseFunction>0,0.03,0.00444,0.03,0.01651,0.03,0.049318,0.03,0.1385,0.03023,0.227682,0.047375,0.26049,0.06651,0.27256,0.076185,0.277,0.08,</ResponseFunction>") },
  82. { (" <ResponseFunction>0,0.03,0.006283,0.03,0.023364,0.03,0.069793,0.03,0.196,0.030228,0.322207,0.047377,0.368636,0.066512,0.385717,0.076186,0.392,0.08,</ResponseFunction>") },
  83. { (" <ResponseFunction>0,0,0.008415,0,0.031291,0,0.093473,0,0.2625,0,0.431527,0.000035,0.493709,0.000073,0.516585,0.000092,0.525,0.0001,</ResponseFunction>") },
  84. { (" <ResponseFunction>0,0,0.010836,0,0.040291,0,0.120357,0,0.338,0,0.555643,0.000035,0.635709,0.000073,0.665164,0.000092,0.676,0.0001,</ResponseFunction>") },
  85. { (" <ResponseFunction>0,0,0.016687,0,0.062045,0,0.185343,0,0.5205,0,0.855657,0.000035,0.978955,0.000073,1.024313,0.000092,1.041,0.0001,</ResponseFunction>") },
  86. { (" <ResponseFunction>0,0,0.020101,0,0.07474,0,0.223266,0,0.627,0,1.030734,0.000035,1.17926,0.000073,1.233899,0.000092,1.254,0.0001,</ResponseFunction>") },
  87. { (" <ResponseFunction>0,0,0.023836,0,0.088627,0,0.26475,0,0.7435,0,1.22225,0.000035,1.398373,0.000073,1.463164,0.000092,1.487,0.0001,</ResponseFunction>") },
  88. { (" <ResponseFunction>0,0,0.027891,0,0.103707,0,0.309795,0,0.87,0,1.430205,0.000035,1.636293,0.000073,1.712109,0.000092,1.74,0.0001,</ResponseFunction>") },
  89. { (" <ResponseFunction>0,0,0.030776,0,0.114435,0,0.341842,0,0.96,0,1.578158,0.000035,1.805565,0.000073,1.889224,0.000092,1.92,0.0001,</ResponseFunction>") },
  90. { (" <ResponseFunction>0,0,0.032283,0,0.120037,0,0.358578,0,1.007,0,1.655422,0.000035,1.893963,0.000073,1.981717,0.000092,2.014,0.0001,</ResponseFunction>") },
  91. { (" <ResponseFunction>0,0,0.036996,0,0.13756,0,0.410923,0,1.154,0,1.897077,0.000035,2.17044,0.000073,2.271004,0.000092,2.308,0.0001,</ResponseFunction>") },
  92. { (" <ResponseFunction>0,0,0.05918,0,0.220049,0,0.657334,0,1.846,0,3.034665,0.000035,3.471952,0.000073,3.63282,0.000092,3.692,0.0001,</ResponseFunction>") },
  93. { (" <ResponseFunction>0,0,0.079378,0,0.295146,0,0.881668,0,2.476,0,4.070332,0.000035,4.656854,0.000073,4.872623,0.000092,4.952,0.0001,</ResponseFunction>") },
  94. { (" <ResponseFunction>0,0,0.119867,0,0.445699,0,1.331404,0,3.739,0,6.146595,0.000035,7.0323,0.000073,7.358133,0.000092,7.478,0.0001,</ResponseFunction>") },
  95. { (" <ResponseFunction>0,0,0.148303,0,0.551433,0,1.647253,0,4.626,0,7.604747,0.000035,8.700567,0.000073,9.103698,0.000092,9.252,0.0001,</ResponseFunction>") },
  96. { (" <ResponseFunction>0,0,0.176322,0,0.655616,0,1.958472,0,5.5,0,9.041529,0.000035,10.344384,0.000073,10.823678,0.000092,11,0.0001,</ResponseFunction>") },
  97. { (" <ResponseFunction>0,0,0.208381,0,0.774819,0,2.314557,0,6.5,0,10.685443,0.000035,12.225181,0.000073,12.791619,0.000092,13,0.0001,</ResponseFunction>") },
  98. { (" <ResponseFunction>0,0,0.24044,0,0.894022,0,2.670643,0,7.5,0,12.329357,0,14.105978,0,14.759561,0,15,0,</ResponseFunction>") },
  99. { (" <ResponseFunction>0,0,0.320586,0,1.192029,0,3.560857,0,10,0,16.439142,0,18.80797,0,19.679415,0,20,0,</ResponseFunction>") },
  100. { (" <ResponseFunction>0,0,1.60293,0,5.960146,0,17.804287,0,50,0,82.195709,0,94.039856,0,98.397072,0,100,0,</ResponseFunction>") },
  101. { (" </ClassInstance>") },
  102. { (" <ClassInstance Type=\"TRTESMAHeader\">") },
  103. { (" <TRTKnownHeader>") },
  104. { (" <Type>RTESMA</Type>") },
  105. { (" <Size>662</Size>") },
  106. { (" </TRTKnownHeader>") },
  107. { (" <PrimaryEnergy>2E1</PrimaryEnergy>") },
  108. { (" <ReferenceFactor>-1</ReferenceFactor>") },
  109. { (" <ReferenceStdDev>-1</ReferenceStdDev>") },
  110. { (" <BaseRefStdDev>2.000100008E-3</BaseRefStdDev>") },
  111. { (" <ElevationAngle>3.5E1</ElevationAngle>") },
  112. { (" <CoatCorrection/>") },
  113. { (" </ClassInstance>") },
  114. { (" </TRTHeaderedClass>") },
  115. { (" <ClassInstance Type=\"TRTSpectrumHeader\">") },
  116. { (" <Size>82</Size>") },
  117. { (" <Date>9.12.2015</Date>") },
  118. { (" <Time>11:41:21</Time>") },
  119. { (" <ChannelCount>2000</ChannelCount>")/*, SPXLineType::CHANNEL_COUNT*/ },
  120. //{ (" <CalibAbs>0</CalibAbs>"), SPXLineType::CALIB_ABS },
  121. { (" <CalibLin>0.01</CalibLin>")/*, SPXLineType::CALIB_LIN*/ },
  122. { (" <SigmaAbs>7.756682035E-4</SigmaAbs>")/*, SPXLineType::SIGMA_ABS*/ },
  123. { (" <SigmaLin>6.874358396E-4</SigmaLin>")/*, SPXLineType::SIGMA_LIN*/ },
  124. { (" </ClassInstance>") },
  125. { (" <Channels></Channels>"), SPXLineType::CHANNELS },
  126. { (" <ClassInstance Type=\"TRTResult\" Name=\"Results\">") },
  127. { (" <Result>") },
  128. { (" <Atom>16</Atom>") },
  129. { (" <XLine>K-Serie</XLine>") },
  130. { (" <AtomPercent>6.494736045E-1</AtomPercent>") },
  131. { (" <MassPercent>3.709764752E-1</MassPercent>") },
  132. { (" <NetIntens>445355</NetIntens>") },
  133. { (" <Background>1512</Background>") },
  134. { (" <Sigma>3.644878792E-2</Sigma>") },
  135. { (" </Result>") },
  136. { (" <Result>") },
  137. { (" <Atom>26</Atom>") },
  138. { (" <XLine>K-Serie</XLine>") },
  139. { (" <AtomPercent>3.505263955E-1</AtomPercent>") },
  140. { (" <MassPercent>3.487069895E-1</MassPercent>") },
  141. { (" <NetIntens>142063</NetIntens>") },
  142. { (" <Background>462</Background>") },
  143. { (" <Sigma>2.732743857E-2</Sigma>") },
  144. { (" </Result>") },
  145. { (" <ExtResults>") },
  146. { (" <Atom>26</Atom>") },
  147. { (" <FCorrection>1.029448986</FCorrection>") },
  148. { (" </ExtResults>") },
  149. { (" <ExtResults>") },
  150. { (" <Atom>16</Atom>") },
  151. { (" <FCorrection>1.007593036</FCorrection>") },
  152. { (" </ExtResults>") },
  153. { (" </ClassInstance>") },
  154. { (" <ClassInstance Type=\"TRTPSEElementList\" Name=\"Elements\">") },
  155. { (" <ChildClassInstances>") },
  156. { (" <ClassInstance Type=\"TRTPSEElement\" Name=\"Fe\">") },
  157. { (" <Element>26</Element>") },
  158. { (" <Color>65280</Color>") },
  159. { (" <AutomaticMode>1</AutomaticMode>") },
  160. { (" </ClassInstance>") },
  161. { (" <ClassInstance Type=\"TRTPSEElement\" Name=\"S\">") },
  162. { (" <Element>16</Element>") },
  163. { (" <Color>16711680</Color>") },
  164. { (" <AutomaticMode>1</AutomaticMode>") },
  165. { (" </ClassInstance>") },
  166. { (" </ChildClassInstances>") },
  167. { (" </ClassInstance>") },
  168. { (" <ChildClassInstances>") },
  169. { (" <ClassInstance Type=\"TRTSpectrumChartConfigurationData\">") },
  170. { (" <TRTChartConfigurationData>") },
  171. { (" <XMin>0.09784126</XMin>") },
  172. { (" <XMax>20.00089226</XMax>") },
  173. { (" <YMin>0</YMin>") },
  174. { (" <YMax>366.03007760028</YMax>") },
  175. { (" <XAxisLog>0</XAxisLog>") },
  176. { (" <YAxisLog>0</YAxisLog>") },
  177. { (" <YAxisSqrt>0</YAxisSqrt>") },
  178. { (" <LegendeVisible>0</LegendeVisible>") },
  179. { (" <GridStyle>Lines</GridStyle>") },
  180. { (" <GridColor>223,223,223</GridColor>") },
  181. { (" <MinXTicks>5</MinXTicks>") },
  182. { (" <MinYTicks>5</MinYTicks>") },
  183. { (" <SeriesScaling>0</SeriesScaling>") },
  184. { (" <AxisFont>") },
  185. { (" <Name>Verdana</Name>") },
  186. { (" <Size>11</Size>") },
  187. { (" <Color>8,0,0</Color>") },
  188. { (" <Style/>") },
  189. { (" </AxisFont>") },
  190. { (" <LegendeFont>") },
  191. { (" <Name>Verdana</Name>") },
  192. { (" <Size>11</Size>") },
  193. { (" <Color>8,0,0</Color>") },
  194. { (" <Style/>") },
  195. { (" </LegendeFont>") },
  196. { (" <SeriesProperties>") },
  197. { (" <ClassInstance Type=\"TRTChartSeriesConfigurationData\">") },
  198. { (" <Name>Acquisition</Name>") },
  199. { (" <Description>Acquisition</Description>") },
  200. { (" <Visible>1</Visible>") },
  201. { (" <LineColor>194,9,0</LineColor>") },
  202. { (" <FillColor>194,9,0</FillColor>") },
  203. { (" <Filled>1</Filled>") },
  204. { (" <LineStyle>Solid</LineStyle>") },
  205. { (" <LineWidth>1</LineWidth>") },
  206. { (" <Mark>-1</Mark>") },
  207. { (" <Factor>1</Factor>") },
  208. { (" <Offset>0</Offset>") },
  209. { (" </ClassInstance>") },
  210. { (" </SeriesProperties>") },
  211. { (" </TRTChartConfigurationData>") },
  212. { (" <EnergyMode>1</EnergyMode>") },
  213. { (" <YAxisMode>Hertz</YAxisMode>") },
  214. { (" <RescaleStrength>0</RescaleStrength>") },
  215. { (" <InterpolateType>None</InterpolateType>") },
  216. { (" <ForegroundRegion>1</ForegroundRegion>") },
  217. { (" <BackgroundRegion>1</BackgroundRegion>") },
  218. { (" <CurrentSpectrum>0</CurrentSpectrum>") },
  219. { (" <CurrentSpectrumInFront>1</CurrentSpectrumInFront>") },
  220. { (" <ElementLinesVisible>1</ElementLinesVisible>") },
  221. { (" <ElementTextVisible>1</ElementTextVisible>") },
  222. { (" <TransparentText>0</TransparentText>") },
  223. { (" <EscLinesVisible>0</EscLinesVisible>") },
  224. { (" <NegativeCountsAllowed>0</NegativeCountsAllowed>") },
  225. { (" <DynamicLineMarkerHeight>0</DynamicLineMarkerHeight>") },
  226. { (" <CoatingElement>-1</CoatingElement>") },
  227. { (" <LabelFont>") },
  228. { (" <Name>Verdana</Name>") },
  229. { (" <Size>11</Size>") },
  230. { (" <Color>8,0,0</Color>") },
  231. { (" <Style/>") },
  232. { (" </LabelFont>") },
  233. { (" </ClassInstance>") },
  234. { (" </ChildClassInstances>") },
  235. { (" </ClassInstance>") },
  236. { ("</TRTSpectrum>") },
  237. };
  238. #pragma warning(default: 4835)
  239. BOOL CBrukerSPXFileMgr::ExportXrayPoints(LPCTSTR a_sPath, LPCTSTR a_sName, const std::vector<CPosXray*>& a_xrayPoints)
  240. {
  241. ASSERT(a_sPath);
  242. if (!a_sPath)
  243. {
  244. LogErrorTrace(__FILE__, __LINE__, _T("ExportXrayPoints:invalid path"));
  245. return FALSE;
  246. }
  247. for (size_t i = 0; i < a_xrayPoints.size(); i++)
  248. {
  249. auto* pXrayPoint = a_xrayPoints[i];
  250. std::stringstream fileNameStream;
  251. char sPath[MAX_PATH];
  252. CControllerHelper::WCharToChar((const wchar_t*)a_sPath, sPath);
  253. char sName[MAX_PATH] = { "Spectrum" };
  254. if (a_sName)
  255. {
  256. CControllerHelper::WCharToChar((const wchar_t*)a_sName, sName);
  257. }
  258. fileNameStream << sPath << "\\" << sName << i << "_" << pXrayPoint->GetPosition().x << "_" << pXrayPoint->GetPosition().y << ".spx";
  259. std::stringstream xrayNameStream;
  260. xrayNameStream << sName << i;
  261. if (!ExportXrayPoint(fileNameStream.str().c_str(), xrayNameStream.str().c_str(), pXrayPoint))
  262. {
  263. CString sName = CControllerHelper::CharToString(fileNameStream.str().c_str());
  264. LogErrorTrace(__FILE__,__LINE__,_T("Export spectrum(%d) to %s failed."), i, sName);
  265. }
  266. }
  267. return TRUE;
  268. }
  269. BOOL CBrukerSPXFileMgr::ExportXrayPoint(const char* a_sFilePathName, const char* a_sName, CPosXray* a_pXrayPoint)
  270. {
  271. ASSERT(a_sFilePathName);
  272. if (!a_sFilePathName)
  273. {
  274. LogErrorTrace(__FILE__, __LINE__, _T("ExportXrayPoint:invalid path"));
  275. return FALSE;
  276. }
  277. ASSERT(a_pXrayPoint);
  278. if (!a_pXrayPoint)
  279. {
  280. LogErrorTrace(__FILE__, __LINE__, _T("ExportXrayPoint:invalid x-ray point"));
  281. return FALSE;
  282. }
  283. std::ofstream out(a_sFilePathName);
  284. for (auto& spxLine : m_vSpxFileLines)
  285. {
  286. switch (spxLine.m_nLineType)
  287. {
  288. case SPXLineType::NAME:
  289. {
  290. out << " <ClassInstance Type=\"TRTSpectrum\" Name=\"" << a_sName << "\">" << std::endl;
  291. }
  292. break;
  293. //case SPXLineType::CHANNEL_COUNT:
  294. //{
  295. // out << " <ChannelCount>2000</ChannelCount>" << std::endl;
  296. //}
  297. //break;
  298. case SPXLineType::CHANNELS:
  299. {
  300. out << " <Channels>";
  301. auto* pXrayData = a_pXrayPoint->GetXrayData();
  302. out << pXrayData[0];
  303. for (long i = 1; i < GENERALXRAYCHANNELS; i++)
  304. {
  305. out << "," << pXrayData[i];
  306. }
  307. out << "</Channels>" << std::endl;
  308. }
  309. break;
  310. //case SPXLineType::CALIB_ABS:
  311. //{
  312. // continue;
  313. // //out << " <CalibAbs>";
  314. // //out << m_spectrumHeader.CalibrationAbs;
  315. // //out << "</CalibAbs>" << std::endl;
  316. //}
  317. //break;
  318. //case SPXLineType::CALIB_LIN:
  319. //{
  320. // continue;
  321. // //out << " <CalibLin>";
  322. // //out << m_spectrumHeader.CalibrationLin;
  323. // //out << "</CalibLin>" << std::endl;
  324. //}
  325. //break;
  326. //case SPXLineType::SIGMA_ABS:
  327. //{
  328. // out << " <SigmaAbs>";
  329. // out << m_spectrumHeader.SigmaAbs;
  330. // out << "</SigmaAbs>" << std::endl;
  331. //}
  332. //break;
  333. //case SPXLineType::SIGMA_LIN:
  334. //{
  335. // out << " <SigmaLin>";
  336. // out << m_spectrumHeader.SigmaLin;
  337. // out << "</SigmaLin>" << std::endl;
  338. //}
  339. //break;
  340. default:
  341. {
  342. out << spxLine.m_sLineString << std::endl;
  343. }
  344. break;
  345. }
  346. }
  347. out.flush();
  348. out.close();
  349. return true;
  350. }
  351. BOOL CBrukerSPXFileMgr::ExportXrayPoints(LPCTSTR a_sPath, LPCTSTR a_sName, const CPosXrayList& a_xrayPoints)
  352. {
  353. std::vector<CPosXray*> xrayPoints;
  354. for (auto& pXray : a_xrayPoints)
  355. {
  356. xrayPoints.push_back(pXray.get());
  357. }
  358. return ExportXrayPoints(a_sPath, a_sName, xrayPoints);
  359. }
  360. /*BOOL CBrukerSPXFileMgr::ExportXrayPoint(LPCTSTR a_sFilePathName, LPCTSTR a_sSpectrumName, CPosXray* a_pXrayPoint)
  361. {
  362. ASSERT(a_sFilePathName);
  363. if (!a_sFilePathName)
  364. {
  365. LogErrorTrace(__FILE__, __LINE__, _T("ExportXrayPoint:invalid path"));
  366. return FALSE;
  367. }
  368. ASSERT(a_pXrayPoint);
  369. if (!a_pXrayPoint)
  370. {
  371. LogErrorTrace(__FILE__, __LINE__, _T("ExportXrayPoint:invalid x-ray point"));
  372. return FALSE;
  373. }
  374. char sPathName[MAX_PATH];
  375. CControllerHelper::WCharToChar((const wchar_t*)a_sFilePathName, sPathName);
  376. char sName[MAX_PATH] = { "Spectrum" };
  377. if (a_sSpectrumName)
  378. {
  379. CControllerHelper::WCharToChar((const wchar_t*)a_sSpectrumName, sName);
  380. }
  381. return ExportXrayPoint(sPathName, sName, a_pXrayPoint);
  382. }*/
  383. BOOL CBrukerSPXFileMgr::LoadSpectrumHeader(LPCTSTR a_sFilePathName)
  384. {
  385. ASSERT(a_sFilePathName);
  386. if (!a_sFilePathName)
  387. {
  388. LogErrorTrace(__FILE__, __LINE__, _T("ExportXrayPoint:invalid path"));
  389. return FALSE;
  390. }
  391. /* if (!FS::Exists(a_sFilePathName))
  392. {
  393. return FALSE;
  394. }*/
  395. CFile file;
  396. CFileException ex;
  397. if (!file.Open(a_sFilePathName, CFile::modeRead, &ex))
  398. {
  399. TCHAR strError[512] = _T("");
  400. ex.GetErrorMessage(strError, lstrlen(strError));
  401. LogErrorTrace(__FILE__,__LINE__,_T("Open file(%s) failed: %s"), a_sFilePathName, strError);
  402. return FALSE;
  403. }
  404. auto nReadSize = file.Read(&m_spectrumHeader, sizeof(RTSpectrumHeaderRec));
  405. file.Close();
  406. return nReadSize == sizeof(RTSpectrumHeaderRec);
  407. }
  408. BOOL CBrukerSPXFileMgr::SaveSpectrumHeader(LPCTSTR a_sFilePathName)
  409. {
  410. ASSERT(a_sFilePathName);
  411. if (!a_sFilePathName)
  412. {
  413. LogErrorTrace(__FILE__, __LINE__, _T("SaveSpectrumHeader:invalid path"));
  414. return FALSE;
  415. }
  416. // Open the file
  417. CFile file;
  418. CFileException ex;
  419. if (!file.Open(a_sFilePathName, CFile::modeCreate | CFile::modeWrite, &ex))
  420. {
  421. TCHAR szCause[255];
  422. ex.GetErrorMessage(szCause, 255);
  423. LogErrorTrace(__FILE__,__LINE__,_T("Create file %s failed:\r\n %s"), a_sFilePathName, szCause);
  424. return FALSE;
  425. }
  426. file.Write(&m_spectrumHeader, sizeof(RTSpectrumHeaderRec));
  427. file.Close();
  428. return TRUE;
  429. }
  430. BOOL CBrukerSPXFileMgr::SetSpectrumHeader(RTSpectrumHeaderRec* m_pSpectrumHeader)
  431. {
  432. ASSERT(m_pSpectrumHeader);
  433. if (!m_pSpectrumHeader)
  434. {
  435. LogErrorTrace(__FILE__, __LINE__, _T("SetSpectrumHeader:invalid spectrum header"));
  436. return FALSE;
  437. }
  438. memcpy_s(&m_spectrumHeader, sizeof(RTSpectrumHeaderRec), m_pSpectrumHeader, sizeof(RTSpectrumHeaderRec));
  439. return TRUE;
  440. }
  441. void CBrukerSPXFileMgr::Init()
  442. {
  443. InitSpectrumHeader(&m_spectrumHeader);
  444. }
  445. void CBrukerSPXFileMgr::InitSpectrumHeader(RTSpectrumHeaderRec* a_pHeader)
  446. {
  447. if (!a_pHeader)
  448. {
  449. return;
  450. }
  451. memset(a_pHeader, 0, sizeof(RTSpectrumHeaderRec));
  452. std::string sName = "Rontec XRay spectrum";
  453. a_pHeader->IDStringLength = (BYTE)sName.size();
  454. memcpy_s(a_pHeader->IDString, 25, sName.c_str(), sName.size());
  455. a_pHeader->ChannelCount = GENERALXRAYCHANNELS;
  456. a_pHeader->CalibrationAbs = 1;
  457. a_pHeader->CalibrationLin = 0.01;
  458. a_pHeader->SigmaAbs = 0.000752;
  459. a_pHeader->SigmaLin = 0.000687;
  460. }
  461. bool CBrukerSPXFileMgr::InitSpectrumBuffer(char* a_pBuffer, CPosXray* a_pXrayPoint)
  462. {
  463. ASSERT(a_pBuffer);
  464. if (!a_pBuffer)
  465. {
  466. LogErrorTrace(__FILE__, __LINE__, _T("InitSpectrumBuffer:invalid buffer"));
  467. return FALSE;
  468. }
  469. ASSERT(a_pXrayPoint);
  470. if (!a_pXrayPoint)
  471. {
  472. LogErrorTrace(__FILE__, __LINE__, _T("InitSpectrumBuffer:invalid x-ray point"));
  473. return FALSE;
  474. }
  475. RTSpectrumHeaderRec* pHeader = (RTSpectrumHeaderRec*)a_pBuffer;
  476. CBrukerSPXFileMgr::InitSpectrumHeader(pHeader);
  477. auto* pXrayData = a_pXrayPoint->GetXrayData();
  478. char* pXrayBuffer = a_pBuffer + sizeof(RTSpectrumHeaderRec);
  479. size_t nBufferSize = sizeof(long) * GENERALXRAYCHANNELS;
  480. LogTrace(__FILE__,__LINE__,_T("Copy xray buffer size %d"), nBufferSize);
  481. memcpy(pXrayBuffer, pXrayData, nBufferSize);
  482. return true;
  483. }
  484. }