OTSControlFunExport.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. #include "stdafx.h"
  2. #include "OTSControlFunExport.h"
  3. namespace OTSCLRINTERFACE
  4. {
  5. COTSHardwareMgrPtr g_ControllerMgrPtr = nullptr;
  6. CSemBasePtr g_SemBasePtr = nullptr;
  7. COTSSimuControlClr::COTSSimuControlClr()
  8. {
  9. g_ControllerMgrPtr = COTSHardwareMgrPtr(new COTSHardwareMgr);
  10. g_SemBasePtr = g_ControllerMgrPtr->GetSemControllerMgrPtr();
  11. }
  12. COTSSimuControlClr::~COTSSimuControlClr()
  13. {
  14. this->!COTSSimuControlClr();
  15. }
  16. COTSSimuControlClr::!COTSSimuControlClr()
  17. {
  18. }
  19. bool COTSSimuControlClr::Connect()
  20. {
  21. if (nullptr == g_SemBasePtr)
  22. {
  23. return false;
  24. }
  25. return g_SemBasePtr->Connect();
  26. }
  27. //bool COTSSimuControlClr::Disconnect()
  28. //{
  29. // if (nullptr == g_SemBasePtr)
  30. // {
  31. // return false;
  32. // }
  33. // return g_SemBasePtr->Disconnect();
  34. //}
  35. bool COTSSimuControlClr::SetWorkingDistance(double a_dWorkingDistance)
  36. {
  37. return g_SemBasePtr->SetWorkingDistance(a_dWorkingDistance);
  38. }
  39. bool COTSSimuControlClr::GetWorkingDistance(double% a_dWorkingDistance)
  40. {
  41. double WDistance;
  42. bool bRev = g_SemBasePtr->GetWorkingDistance(WDistance);
  43. a_dWorkingDistance = WDistance;
  44. return bRev;
  45. }
  46. bool COTSSimuControlClr::SetMagnification(double a_dMag)
  47. {
  48. return g_SemBasePtr->SetMagnification(a_dMag);
  49. }
  50. bool COTSSimuControlClr::GetMagnification(double% a_dMag)
  51. {
  52. double dMag;
  53. bool bRev = g_SemBasePtr->GetMagnification(dMag);
  54. a_dMag = dMag;
  55. return bRev;
  56. }
  57. bool COTSControlFunExport::CollectSpectrum(unsigned long a_nMilliseconds, Point a_oPoint, array<unsigned long>^% a_XrayData)
  58. {
  59. CPoint pt;
  60. pt.x = a_oPoint.X;
  61. pt.y = a_oPoint.Y;
  62. bool bRet = m_pEDS->CollectSpectrum(a_nMilliseconds, pt);
  63. DWORD* xrd;
  64. xrd = m_pEDS->GetXRayData();
  65. for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  66. {
  67. a_XrayData[i] = xrd[i];
  68. }
  69. return bRet;
  70. }
  71. bool COTSControlFunExport::CollectSpectrum(unsigned long a_nMilliseconds, array<unsigned long>^% a_XrayData, unsigned long a_nBufferSize)
  72. {
  73. long* aData = new long[a_nBufferSize];
  74. memset(aData, 0, a_nBufferSize);
  75. bool bRet = m_pEDS->CollectSpectrum(a_nMilliseconds, aData, a_nBufferSize);
  76. for (int i = a_nBufferSize; i < (int)a_nBufferSize; i++)
  77. {
  78. a_XrayData[i] = aData[i];
  79. }
  80. delete[] aData;
  81. return bRet;
  82. }
  83. bool COTSControlFunExport::CollectSpectrum(unsigned long a_nMilliseconds, array<unsigned long>^% a_XrayData)
  84. {
  85. bool bRet = m_pEDS->CollectSpectrum(a_nMilliseconds);
  86. DWORD* xrd;
  87. xrd = m_pEDS->GetXRayData();
  88. for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  89. {
  90. a_XrayData[i] = xrd[i];
  91. }
  92. return bRet;
  93. }
  94. bool COTSControlFunExport::GetXRayByPoints(unsigned long a_nMilliseconds, array<Point>^ points, array<array<unsigned long>^>^% a_XrayData, array<String^>^% a_strEleResult, bool bQuant)
  95. {
  96. std::vector<CPosXrayPtr> listXRayPoints;
  97. for (int i = 0; i < points->Length; i++)
  98. {
  99. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  100. pXRayPoint->SetPosition(CPoint(points[i].X, points[i].Y));
  101. listXRayPoints.push_back(pXRayPoint);
  102. }
  103. // set get quantify info flag
  104. if (bQuant)
  105. {
  106. m_pEDS->SetQuantification(TRUE);
  107. }
  108. else
  109. {
  110. m_pEDS->SetQuantification(FALSE);
  111. }
  112. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  113. DWORD* xrd;
  114. for (int i = 0; i < points->Length; i++)
  115. {
  116. xrd = listXRayPoints[i]->GetXrayData();
  117. for (int j = 0; j < (int)EDSConst::XANA_CHANNELS; j++)
  118. {
  119. a_XrayData[i][j] = xrd[j];
  120. }
  121. }
  122. if (bQuant)
  123. {
  124. for (int i = 0; i < points->Length; i++)
  125. {
  126. CElementChemistriesList& listElement = listXRayPoints[i]->GetElementQuantifyData();
  127. int nElementNum = (int)listElement.size();
  128. CString strElementResult = _T("");
  129. for (auto pElement : listElement)
  130. {
  131. CString strResult;
  132. CString strName = pElement->GetName();
  133. double dPercent = pElement->GetPercentage();
  134. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  135. strElementResult += strResult;
  136. }
  137. a_strEleResult[i] = gcnew String(strElementResult);
  138. }
  139. }
  140. return bRet;
  141. }
  142. bool COTSControlFunExport::GetXRayByPoints(unsigned long a_nMilliseconds, array<Point>^ points, array<COTSParticleClr^>^ parts, bool bQuant)
  143. {
  144. std::vector<CPosXrayPtr> listXRayPoints;
  145. for (int i = 0; i < points->Length; i++)
  146. {
  147. CPosXrayPtr pXRayPoint = parts[i]->GetXray()->GetPosXrayPtr();
  148. pXRayPoint->SetPosition(CPoint(points[i].X, points[i].Y));
  149. listXRayPoints.push_back(pXRayPoint);
  150. }
  151. // set get quantify info flag
  152. if (bQuant)
  153. {
  154. m_pEDS->SetQuantification(TRUE);
  155. }
  156. else
  157. {
  158. m_pEDS->SetQuantification(FALSE);
  159. }
  160. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  161. //DWORD* xrd;
  162. for (int i = 0; i < points->Length; i++)
  163. {
  164. auto part = parts[i]->GetOTSParticlePtr();
  165. part->SetXrayInfo(listXRayPoints[i]);
  166. }
  167. return bRet;
  168. }
  169. bool COTSControlFunExport::GetXRayByFeatures(unsigned long a_nMilliseconds, array<COTSFeatureClr^>^ features, array<array<unsigned long>^>^% a_XrayData, array<String^>^% a_strEleResult, bool bQuant)
  170. {
  171. std::vector<CPosXrayPtr> listXRayPoints;
  172. long xraynum = features->Length;
  173. for (int i = 0; i < xraynum; i++)
  174. {
  175. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  176. listXRayPoints.push_back(pXRayPoint);
  177. }
  178. std::vector<BrukerFeature>listFeatures;
  179. for (int i = 0; i < xraynum; i++)
  180. {
  181. auto feature = features[i]->GetOTSFeaturePtr();
  182. auto otsSegs = feature->GetSegmentsList();
  183. std::vector<BrukerSegment> listSegment;
  184. for (int j = 0; j < otsSegs.size(); j++)
  185. {
  186. auto seg = otsSegs[j];
  187. BrukerSegment oSegment;
  188. oSegment.XCount = seg->GetLength();
  189. oSegment.XStart = seg->GetStart();
  190. oSegment.Y = seg->GetHeight();
  191. listSegment.push_back(oSegment);
  192. }
  193. BrukerFeature oFeature;
  194. oFeature.SegmentCount = listSegment.size();
  195. oFeature.pSegment = &listSegment[0];
  196. listFeatures.push_back(oFeature);
  197. }
  198. // set get quantify info flag
  199. if (bQuant)
  200. {
  201. m_pEDS->SetQuantification(TRUE);
  202. }
  203. else
  204. {
  205. m_pEDS->SetQuantification(FALSE);
  206. }
  207. bool bRet = m_pEDS->GetXRayByFeatures(listXRayPoints, listFeatures, a_nMilliseconds);
  208. DWORD* xrd;
  209. for (int i = 0; i < xraynum; i++)
  210. {
  211. xrd = listXRayPoints[i]->GetXrayData();
  212. for (int j = 0; j < (int)EDSConst::XANA_CHANNELS; j++)
  213. {
  214. a_XrayData[i][j] = xrd[j];
  215. }
  216. }
  217. if (bQuant)
  218. {
  219. for (int i = 0; i < features->Length; i++)
  220. {
  221. CElementChemistriesList& listElement = listXRayPoints[i]->GetElementQuantifyData();
  222. int nElementNum = (int)listElement.size();
  223. CString strElementResult = _T("");
  224. for (auto pElement : listElement)
  225. {
  226. CString strResult;
  227. CString strName = pElement->GetName();
  228. double dPercent = pElement->GetPercentage();
  229. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  230. strElementResult += strResult;
  231. }
  232. a_strEleResult[i] = gcnew String(strElementResult);
  233. }
  234. }
  235. return bRet;
  236. }
  237. bool COTSControlFunExport::GetXRayByFeatures(unsigned long a_nMilliseconds, array<COTSParticleClr^>^ parts, bool bQuant)
  238. {
  239. std::vector<CPosXrayPtr> listXRayPoints;
  240. long xraynum = parts->Length;
  241. for (int i = 0; i < xraynum; i++)
  242. {
  243. //CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  244. CPosXrayPtr pXRayPoint = parts[i]->GetXray()->GetPosXrayPtr();
  245. listXRayPoints.push_back(pXRayPoint);
  246. }
  247. //std::vector<std::vector<BrukerSegment>>listFeatures;
  248. std::vector<BrukerFeature>listFeatures;
  249. for (int i = 0; i < xraynum; i++)
  250. {
  251. auto feature = parts[i]->GetOTSParticlePtr()->GetFeature();
  252. auto otsSegs = feature->GetSegmentsList();
  253. std::vector<BrukerSegment> listSegment;
  254. for (int j = 0; j < otsSegs.size(); j++)
  255. {
  256. auto seg = otsSegs[j];
  257. BrukerSegment oSegment;
  258. oSegment.XCount = seg->GetLength();
  259. oSegment.XStart = seg->GetStart();
  260. oSegment.Y = seg->GetHeight();
  261. listSegment.push_back(oSegment);
  262. }
  263. BrukerFeature oFeature;
  264. oFeature.SegmentCount = listSegment.size();
  265. oFeature.pSegment = &listSegment[0];
  266. listFeatures.push_back(oFeature);
  267. }
  268. // set get quantify info flag
  269. if (bQuant)
  270. {
  271. m_pEDS->SetQuantification(TRUE);
  272. }
  273. else
  274. {
  275. m_pEDS->SetQuantification(FALSE);
  276. }
  277. bool bRet = m_pEDS->GetXRayByFeatures(listXRayPoints, listFeatures, a_nMilliseconds);
  278. //DWORD* xrd;
  279. for (int i = 0; i < xraynum; i++)
  280. {
  281. auto part = parts[i]->GetOTSParticlePtr();
  282. part->SetXrayInfo(listXRayPoints[i]);
  283. }
  284. return bRet;
  285. }
  286. bool COTSControlFunExport::GetXRayBySinglePoint(unsigned long a_nMilliseconds, Point point, array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant)
  287. {
  288. std::vector<CPosXrayPtr> listXRayPoints;
  289. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  290. pXRayPoint->SetPosition(CPoint(point.X, point.Y));
  291. listXRayPoints.push_back(pXRayPoint);
  292. // set get quantify info flag
  293. if (bQuant)
  294. {
  295. m_pEDS->SetQuantification(TRUE);
  296. }
  297. else
  298. {
  299. m_pEDS->SetQuantification(FALSE);
  300. }
  301. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  302. DWORD* xrd;
  303. xrd = listXRayPoints[0]->GetXrayData();
  304. for (int j = 0; j < (int)EDSConst::XANA_CHANNELS; j++)
  305. {
  306. a_XrayData[j] = xrd[j];
  307. }
  308. if (bQuant)
  309. {
  310. CElementChemistriesList& listElement = listXRayPoints[0]->GetElementQuantifyData();
  311. int nElementNum = (int)listElement.size();
  312. CString strElementResult = _T("");
  313. for (auto pElement : listElement)
  314. {
  315. CString strResult;
  316. CString strName = pElement->GetName();
  317. double dPercent = pElement->GetPercentage();
  318. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  319. strElementResult += strResult;
  320. }
  321. a_strEleResult = gcnew String(strElementResult);
  322. }
  323. return bRet;
  324. }
  325. bool COTSControlFunExport::GetXRayBySingleFeature(unsigned long a_nMilliseconds, COTSFeatureClr^ feature, array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant)
  326. {
  327. std::vector<CPosXrayPtr> listXRayPoints;
  328. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  329. listXRayPoints.push_back(pXRayPoint);
  330. std::vector<BrukerSegment> listSegment;
  331. std::vector<BrukerFeature>listFeatures;
  332. auto otsSegs = feature->GetSegmentsList();
  333. for (int j = 0; j < otsSegs->Count; j++)
  334. {
  335. auto seg = otsSegs[j];
  336. BrukerSegment oSegment;
  337. oSegment.XCount = seg->GetLength();
  338. oSegment.XStart = seg->GetStart();
  339. oSegment.Y = seg->GetHeight();
  340. listSegment.push_back(oSegment);
  341. }
  342. BrukerFeature ofeature;
  343. ofeature.SegmentCount = listSegment.size();
  344. ofeature.pSegment = &listSegment[0];
  345. listFeatures.push_back(ofeature);
  346. bool bRet = FALSE;
  347. // set get quantify info flag
  348. if (bQuant)
  349. {
  350. m_pEDS->SetQuantification(TRUE);
  351. }
  352. else
  353. {
  354. m_pEDS->SetQuantification(FALSE);
  355. }
  356. bRet = m_pEDS->GetXRayByFeatures(listXRayPoints, listFeatures, a_nMilliseconds);
  357. DWORD* xrd;
  358. pXRayPoint = listXRayPoints[0];
  359. xrd = pXRayPoint->GetXrayData();
  360. for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  361. {
  362. a_XrayData[i] = xrd[i];
  363. }
  364. if (bQuant)
  365. {
  366. CElementChemistriesList& listElement = listXRayPoints[0]->GetElementQuantifyData();
  367. int nElementNum = (int)listElement.size();
  368. CString strElementResult = _T("");
  369. for (auto pElement : listElement)
  370. {
  371. CString strResult;
  372. CString strName = pElement->GetName();
  373. double dPercent = pElement->GetPercentage();
  374. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  375. strElementResult += strResult;
  376. }
  377. a_strEleResult = gcnew String(strElementResult);
  378. }
  379. return bRet;
  380. }
  381. bool COTSControlFunExport::GetXRayElements(unsigned long a_nMilliseconds, array<unsigned long>^% a_XrayData, int^% a_nElementNum, String^% a_strResult)
  382. {
  383. std::vector<CPosXrayPtr> listXRayPoints;
  384. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  385. pXRayPoint->SetPosition(CPoint(10, 10));
  386. listXRayPoints.push_back(pXRayPoint);
  387. CPosXrayPtr pXRayPoint1 = CPosXrayPtr(new CPosXray());
  388. pXRayPoint1->SetPosition(CPoint(20, 20));
  389. listXRayPoints.push_back(pXRayPoint1);
  390. // set get quantify info flag
  391. m_pEDS->SetQuantification(TRUE);
  392. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  393. //bool bRet = m_LpEDSBase->GetXRayByFeaturesFromMultiPoint(listXRayPoints, listFeatures, a_nMilliseconds);
  394. DWORD* xrd;
  395. pXRayPoint = listXRayPoints[1];
  396. xrd = pXRayPoint->GetXrayData();
  397. // element quantify data
  398. CElementChemistriesList& listElement = listXRayPoints[1]->GetElementQuantifyData();
  399. int nElementNum = (int)listElement.size();
  400. CString strElementResult = _T("");
  401. for (auto pElement : listElement)
  402. {
  403. CString strResult;
  404. CString strName = pElement->GetName();
  405. double dPercent = pElement->GetPercentage();
  406. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  407. strElementResult += strResult;
  408. }
  409. for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  410. {
  411. a_XrayData[i] = xrd[i];
  412. }
  413. a_nElementNum = nElementNum;
  414. a_strResult = gcnew String(strElementResult);
  415. return bRet;
  416. }
  417. bool COTSControlFunExport::GetXRayAndElements(unsigned long a_nMilliseconds, int a_BSEX, int a_BSEY, array<unsigned long>^% a_XrayData, int^% a_nElementNum, String^% a_strResult)
  418. {
  419. std::vector<CPosXrayPtr> listXRayPoints;
  420. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  421. pXRayPoint->SetPosition(CPoint(a_BSEX, a_BSEY));
  422. listXRayPoints.push_back(pXRayPoint);
  423. CPosXrayPtr pXRayPoint1 = CPosXrayPtr(new CPosXray());
  424. pXRayPoint1->SetPosition(CPoint(a_BSEX, a_BSEY));
  425. listXRayPoints.push_back(pXRayPoint1);
  426. // set get quantify info flag
  427. m_pEDS->SetQuantification(FALSE);
  428. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  429. //bool bRet = m_LpEDSBase->GetXRayByFeaturesFromMultiPoint(listXRayPoints, listFeatures, a_nMilliseconds);
  430. std::vector<CPosXrayPtr> listXRayPointsTemp;
  431. CPosXrayPtr pXRayPointTemp = CPosXrayPtr(new CPosXray());
  432. listXRayPointsTemp.push_back(pXRayPointTemp);
  433. for (int i = 0; i < 2; i++)
  434. {
  435. listXRayPointsTemp[0] = listXRayPoints[i];
  436. m_pEDS->SetQuantification(TRUE);
  437. bool bRet = m_pEDS->GetXRayByPoints(listXRayPointsTemp, a_nMilliseconds);
  438. listXRayPoints[i] = listXRayPointsTemp[0];
  439. }
  440. DWORD* xrd;
  441. pXRayPoint = listXRayPoints[1];
  442. xrd = pXRayPoint->GetXrayData();
  443. // element quantify data
  444. CElementChemistriesList& listElement = listXRayPoints[1]->GetElementQuantifyData();
  445. int nElementNum = (int)listElement.size();
  446. CString strElementResult = _T("");
  447. for (auto pElement : listElement)
  448. {
  449. CString strResult;
  450. CString strName = pElement->GetName();
  451. double dPercent = pElement->GetPercentage();
  452. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  453. strElementResult += strResult;
  454. }
  455. for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  456. {
  457. a_XrayData[i] = xrd[i];
  458. }
  459. a_nElementNum = nElementNum;
  460. a_strResult = gcnew String(strElementResult);
  461. return bRet;
  462. }
  463. int COTSControlFunExport::AcquireBSEImage(int a_nMatrixIndex, int nReads, int nDwell, array<System::Byte>^% a_ImgData)
  464. {
  465. int bRet = 0;
  466. CSize sz;
  467. int height, width;
  468. CBSEImgPtr pbseImg = nullptr;
  469. pbseImg = m_pScan->AcquireBSEImage(a_nMatrixIndex, nReads, nDwell);
  470. sz = pbseImg->GetImageSize();
  471. height = sz.cx;
  472. width = sz.cy;
  473. bRet = height * width;
  474. BYTE* lpData = pbseImg->GetImageDataPointer();
  475. for (int i = 0; i < bRet; i++)
  476. {
  477. a_ImgData[i] = lpData[i];
  478. }
  479. return bRet;
  480. // return 0;
  481. }
  482. //void COTSControlFunExport::InitDevPoint()
  483. //{
  484. //
  485. //
  486. //
  487. //
  488. //}
  489. }