OTSControlFunExport.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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. BrukerSegment* segArray = new BrukerSegment[otsSegs.size()];
  184. for (int j = 0; j < otsSegs.size(); j++)
  185. {
  186. auto seg = otsSegs[j];
  187. BrukerSegment* oSegment = &segArray[j];
  188. oSegment->XCount = seg->GetLength();
  189. oSegment->XStart = seg->GetStart();
  190. oSegment->Y = seg->GetHeight();
  191. }
  192. BrukerFeature oFeature;
  193. oFeature.SegmentCount = otsSegs.size();
  194. oFeature.pSegment = segArray;
  195. listFeatures.push_back(oFeature);
  196. }
  197. // set get quantify info flag
  198. if (bQuant)
  199. {
  200. m_pEDS->SetQuantification(TRUE);
  201. }
  202. else
  203. {
  204. m_pEDS->SetQuantification(FALSE);
  205. }
  206. bool bRet = m_pEDS->GetXRayByFeatures(listXRayPoints, listFeatures, a_nMilliseconds);
  207. DWORD* xrd;
  208. for (int i = 0; i < xraynum; i++)
  209. {
  210. xrd = listXRayPoints[i]->GetXrayData();
  211. for (int j = 0; j < (int)EDSConst::XANA_CHANNELS; j++)
  212. {
  213. a_XrayData[i][j] = xrd[j];
  214. }
  215. delete listFeatures[i].pSegment;// using the pure pointer increase the understandability but bring another problem: you mast not forget to free the pointer or you involve into memory leak!
  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 = parts[i]->GetXray()->GetPosXrayPtr();
  244. listXRayPoints.push_back(pXRayPoint);
  245. }
  246. std::vector<BrukerFeature>listFeatures;
  247. for (int i = 0; i < xraynum; i++)
  248. {
  249. auto feature = parts[i]->GetOTSParticlePtr()->GetFeature();
  250. auto otsSegs = feature->GetSegmentsList();
  251. BrukerSegment* segArray = new BrukerSegment[otsSegs.size()];
  252. for (int j = 0; j < otsSegs.size(); j++)
  253. {
  254. auto seg = otsSegs[j];
  255. BrukerSegment* oSegment = &segArray[j];
  256. oSegment->XCount = seg->GetLength();
  257. oSegment->XStart = seg->GetStart();
  258. oSegment->Y = seg->GetHeight();
  259. }
  260. BrukerFeature oFeature;
  261. oFeature.SegmentCount = otsSegs.size();
  262. oFeature.pSegment = segArray;
  263. listFeatures.push_back(oFeature);
  264. }
  265. // set get quantify info flag
  266. if (bQuant)
  267. {
  268. m_pEDS->SetQuantification(TRUE);
  269. }
  270. else
  271. {
  272. m_pEDS->SetQuantification(FALSE);
  273. }
  274. bool bRet = m_pEDS->GetXRayByFeatures(listXRayPoints, listFeatures, a_nMilliseconds);
  275. //DWORD* xrd;
  276. for (int i = 0; i < xraynum; i++)
  277. {
  278. auto part = parts[i]->GetOTSParticlePtr();
  279. part->SetXrayInfo(listXRayPoints[i]);
  280. delete listFeatures[i].pSegment;// using the pure pointer increase the understandability but bring another problem: you mast not forget to free the pointer or you involve into memory leak!
  281. }
  282. return bRet;
  283. }
  284. bool COTSControlFunExport::GetXRayBySinglePoint(unsigned long a_nMilliseconds, Point point, array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant)
  285. {
  286. std::vector<CPosXrayPtr> listXRayPoints;
  287. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  288. pXRayPoint->SetPosition(CPoint(point.X, point.Y));
  289. listXRayPoints.push_back(pXRayPoint);
  290. // set get quantify info flag
  291. if (bQuant)
  292. {
  293. m_pEDS->SetQuantification(TRUE);
  294. }
  295. else
  296. {
  297. m_pEDS->SetQuantification(FALSE);
  298. }
  299. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  300. DWORD* xrd;
  301. xrd = listXRayPoints[0]->GetXrayData();
  302. for (int j = 0; j < (int)EDSConst::XANA_CHANNELS; j++)
  303. {
  304. a_XrayData[j] = xrd[j];
  305. }
  306. if (bQuant)
  307. {
  308. CElementChemistriesList& listElement = listXRayPoints[0]->GetElementQuantifyData();
  309. int nElementNum = (int)listElement.size();
  310. CString strElementResult = _T("");
  311. for (auto pElement : listElement)
  312. {
  313. CString strResult;
  314. CString strName = pElement->GetName();
  315. double dPercent = pElement->GetPercentage();
  316. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  317. strElementResult += strResult;
  318. }
  319. a_strEleResult = gcnew String(strElementResult);
  320. }
  321. return bRet;
  322. }
  323. bool COTSControlFunExport::GetXRayBySingleFeature(unsigned long a_nMilliseconds, COTSFeatureClr^ feature, array<unsigned long>^% a_XrayData, String^% a_strEleResult, bool bQuant)
  324. {
  325. std::vector<CPosXrayPtr> listXRayPoints;
  326. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  327. listXRayPoints.push_back(pXRayPoint);
  328. std::vector<BrukerSegment> listSegment;
  329. std::vector<BrukerFeature>listFeatures;
  330. auto otsSegs = feature->GetSegmentsList();
  331. for (int j = 0; j < otsSegs->Count; j++)
  332. {
  333. auto seg = otsSegs[j];
  334. BrukerSegment oSegment;
  335. oSegment.XCount = seg->GetLength();
  336. oSegment.XStart = seg->GetStart();
  337. oSegment.Y = seg->GetHeight();
  338. listSegment.push_back(oSegment);
  339. }
  340. BrukerFeature ofeature;
  341. ofeature.SegmentCount = listSegment.size();
  342. ofeature.pSegment = &listSegment[0];
  343. listFeatures.push_back(ofeature);
  344. bool bRet = FALSE;
  345. // set get quantify info flag
  346. if (bQuant)
  347. {
  348. m_pEDS->SetQuantification(TRUE);
  349. }
  350. else
  351. {
  352. m_pEDS->SetQuantification(FALSE);
  353. }
  354. bRet = m_pEDS->GetXRayByFeatures(listXRayPoints, listFeatures, a_nMilliseconds);
  355. DWORD* xrd;
  356. pXRayPoint = listXRayPoints[0];
  357. xrd = pXRayPoint->GetXrayData();
  358. for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  359. {
  360. a_XrayData[i] = xrd[i];
  361. }
  362. if (bQuant)
  363. {
  364. CElementChemistriesList& listElement = listXRayPoints[0]->GetElementQuantifyData();
  365. int nElementNum = (int)listElement.size();
  366. CString strElementResult = _T("");
  367. for (auto pElement : listElement)
  368. {
  369. CString strResult;
  370. CString strName = pElement->GetName();
  371. double dPercent = pElement->GetPercentage();
  372. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  373. strElementResult += strResult;
  374. }
  375. a_strEleResult = gcnew String(strElementResult);
  376. }
  377. return bRet;
  378. }
  379. bool COTSControlFunExport::GetXRayElements(unsigned long a_nMilliseconds, array<unsigned long>^% a_XrayData, int^% a_nElementNum, String^% a_strResult)
  380. {
  381. std::vector<CPosXrayPtr> listXRayPoints;
  382. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  383. pXRayPoint->SetPosition(CPoint(10, 10));
  384. listXRayPoints.push_back(pXRayPoint);
  385. CPosXrayPtr pXRayPoint1 = CPosXrayPtr(new CPosXray());
  386. pXRayPoint1->SetPosition(CPoint(20, 20));
  387. listXRayPoints.push_back(pXRayPoint1);
  388. // set get quantify info flag
  389. m_pEDS->SetQuantification(TRUE);
  390. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  391. //bool bRet = m_LpEDSBase->GetXRayByFeaturesFromMultiPoint(listXRayPoints, listFeatures, a_nMilliseconds);
  392. DWORD* xrd;
  393. pXRayPoint = listXRayPoints[1];
  394. xrd = pXRayPoint->GetXrayData();
  395. // element quantify data
  396. CElementChemistriesList& listElement = listXRayPoints[1]->GetElementQuantifyData();
  397. int nElementNum = (int)listElement.size();
  398. CString strElementResult = _T("");
  399. for (auto pElement : listElement)
  400. {
  401. CString strResult;
  402. CString strName = pElement->GetName();
  403. double dPercent = pElement->GetPercentage();
  404. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  405. strElementResult += strResult;
  406. }
  407. for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  408. {
  409. a_XrayData[i] = xrd[i];
  410. }
  411. a_nElementNum = nElementNum;
  412. a_strResult = gcnew String(strElementResult);
  413. return bRet;
  414. }
  415. bool COTSControlFunExport::GetXRayAndElements(unsigned long a_nMilliseconds, int a_BSEX, int a_BSEY, array<unsigned long>^% a_XrayData, int^% a_nElementNum, String^% a_strResult)
  416. {
  417. std::vector<CPosXrayPtr> listXRayPoints;
  418. CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray());
  419. pXRayPoint->SetPosition(CPoint(a_BSEX, a_BSEY));
  420. listXRayPoints.push_back(pXRayPoint);
  421. CPosXrayPtr pXRayPoint1 = CPosXrayPtr(new CPosXray());
  422. pXRayPoint1->SetPosition(CPoint(a_BSEX, a_BSEY));
  423. listXRayPoints.push_back(pXRayPoint1);
  424. // set get quantify info flag
  425. m_pEDS->SetQuantification(FALSE);
  426. bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds);
  427. //bool bRet = m_LpEDSBase->GetXRayByFeaturesFromMultiPoint(listXRayPoints, listFeatures, a_nMilliseconds);
  428. std::vector<CPosXrayPtr> listXRayPointsTemp;
  429. CPosXrayPtr pXRayPointTemp = CPosXrayPtr(new CPosXray());
  430. listXRayPointsTemp.push_back(pXRayPointTemp);
  431. for (int i = 0; i < 2; i++)
  432. {
  433. listXRayPointsTemp[0] = listXRayPoints[i];
  434. m_pEDS->SetQuantification(TRUE);
  435. bool bRet = m_pEDS->GetXRayByPoints(listXRayPointsTemp, a_nMilliseconds);
  436. listXRayPoints[i] = listXRayPointsTemp[0];
  437. }
  438. DWORD* xrd;
  439. pXRayPoint = listXRayPoints[1];
  440. xrd = pXRayPoint->GetXrayData();
  441. // element quantify data
  442. CElementChemistriesList& listElement = listXRayPoints[1]->GetElementQuantifyData();
  443. int nElementNum = (int)listElement.size();
  444. CString strElementResult = _T("");
  445. for (auto pElement : listElement)
  446. {
  447. CString strResult;
  448. CString strName = pElement->GetName();
  449. double dPercent = pElement->GetPercentage();
  450. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  451. strElementResult += strResult;
  452. }
  453. for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++)
  454. {
  455. a_XrayData[i] = xrd[i];
  456. }
  457. a_nElementNum = nElementNum;
  458. a_strResult = gcnew String(strElementResult);
  459. return bRet;
  460. }
  461. int COTSControlFunExport::AcquireBSEImage(int a_nMatrixIndex, int nReads, int nDwell, array<System::Byte>^% a_ImgData)
  462. {
  463. int bRet = 0;
  464. CSize sz;
  465. int height, width;
  466. CBSEImgPtr pbseImg = nullptr;
  467. pbseImg = m_pScan->AcquireBSEImage(a_nMatrixIndex, nReads, nDwell);
  468. sz = pbseImg->GetImageSize();
  469. height = sz.cx;
  470. width = sz.cy;
  471. bRet = height * width;
  472. BYTE* lpData = pbseImg->GetImageDataPointer();
  473. for (int i = 0; i < bRet; i++)
  474. {
  475. a_ImgData[i] = lpData[i];
  476. }
  477. return bRet;
  478. // return 0;
  479. }
  480. //void COTSControlFunExport::InitDevPoint()
  481. //{
  482. //
  483. //
  484. //
  485. //
  486. //}
  487. }