OTSControlFunExport.cpp 15 KB

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