OTSControlFunExport.cpp 15 KB

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