#include "stdafx.h" #include "OTSControlFunExport.h" namespace OTSCLRINTERFACE { COTSHardwareMgrPtr g_ControllerMgrPtr = nullptr; CSemBasePtr g_SemBasePtr = nullptr; COTSSimuControlClr::COTSSimuControlClr() { g_ControllerMgrPtr = COTSHardwareMgrPtr(new COTSHardwareMgr); g_SemBasePtr = g_ControllerMgrPtr->GetSemControllerMgrPtr(); } COTSSimuControlClr::~COTSSimuControlClr() { this->!COTSSimuControlClr(); } COTSSimuControlClr::!COTSSimuControlClr() { } bool COTSSimuControlClr::Connect() { if (nullptr == g_SemBasePtr) { return false; } return g_SemBasePtr->Connect(); } //bool COTSSimuControlClr::Disconnect() //{ // if (nullptr == g_SemBasePtr) // { // return false; // } // return g_SemBasePtr->Disconnect(); //} bool COTSSimuControlClr::SetWorkingDistance(double a_dWorkingDistance) { return g_SemBasePtr->SetWorkingDistance(a_dWorkingDistance); } bool COTSSimuControlClr::GetWorkingDistance(double% a_dWorkingDistance) { double WDistance; bool bRev = g_SemBasePtr->GetWorkingDistance(WDistance); a_dWorkingDistance = WDistance; return bRev; } bool COTSSimuControlClr::SetMagnification(double a_dMag) { return g_SemBasePtr->SetMagnification(a_dMag); } bool COTSSimuControlClr::GetMagnification(double% a_dMag) { double dMag; bool bRev = g_SemBasePtr->GetMagnification(dMag); a_dMag = dMag; return bRev; } bool COTSControlFunExport::CollectSpectrum(unsigned long a_nMilliseconds, Point a_oPoint, array^% a_XrayData) { CPoint pt; pt.x = a_oPoint.X; pt.y = a_oPoint.Y; bool bRet = m_pEDS->CollectSpectrum(a_nMilliseconds, pt); DWORD* xrd; xrd = m_pEDS->GetXRayData(); for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++) { a_XrayData[i] = xrd[i]; } return bRet; } bool COTSControlFunExport::CollectSpectrum(unsigned long a_nMilliseconds, array^% a_XrayData, unsigned long a_nBufferSize) { long* aData = new long[a_nBufferSize]; memset(aData, 0, a_nBufferSize); bool bRet = m_pEDS->CollectSpectrum(a_nMilliseconds, aData, a_nBufferSize); for (int i = a_nBufferSize; i < (int)a_nBufferSize; i++) { a_XrayData[i] = aData[i]; } delete[] aData; return bRet; } bool COTSControlFunExport::CollectSpectrum(unsigned long a_nMilliseconds, array^% a_XrayData) { bool bRet = m_pEDS->CollectSpectrum(a_nMilliseconds); DWORD* xrd; xrd = m_pEDS->GetXRayData(); for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++) { a_XrayData[i] = xrd[i]; } return bRet; } bool COTSControlFunExport::GetXRayByPoints(unsigned long a_nMilliseconds, array^ points, array^>^% a_XrayData, array^% a_strEleResult, bool bQuant) { std::vector listXRayPoints; for (int i = 0; i < points->Length; i++) { CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray()); pXRayPoint->SetPosition(CPoint(points[i].X, points[i].Y)); listXRayPoints.push_back(pXRayPoint); } // set get quantify info flag if (bQuant) { m_pEDS->SetQuantification(TRUE); } else { m_pEDS->SetQuantification(FALSE); } bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds); DWORD* xrd; for (int i = 0; i < points->Length; i++) { xrd = listXRayPoints[i]->GetXrayData(); for (int j = 0; j < (int)EDSConst::XANA_CHANNELS; j++) { a_XrayData[i][j] = xrd[j]; } } if (bQuant) { for (int i = 0; i < points->Length; i++) { CElementChemistriesList& listElement = listXRayPoints[i]->GetElementQuantifyData(); int nElementNum = (int)listElement.size(); CString strElementResult = _T(""); for (auto pElement : listElement) { CString strResult; CString strName = pElement->GetName(); double dPercent = pElement->GetPercentage(); strResult.Format(_T("%s: %f\n"), strName, dPercent); strElementResult += strResult; } a_strEleResult[i] = gcnew String(strElementResult); } } return bRet; } bool COTSControlFunExport::GetXRayByPoints(unsigned long a_nMilliseconds, array^ points, array^ parts, bool bQuant) { std::vector listXRayPoints; for (int i = 0; i < points->Length; i++) { CPosXrayPtr pXRayPoint = parts[i]->GetXray()->GetPosXrayPtr(); pXRayPoint->SetPosition(CPoint(points[i].X, points[i].Y)); listXRayPoints.push_back(pXRayPoint); } // set get quantify info flag if (bQuant) { m_pEDS->SetQuantification(TRUE); } else { m_pEDS->SetQuantification(FALSE); } bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds); //DWORD* xrd; for (int i = 0; i < points->Length; i++) { auto part = parts[i]->GetOTSParticlePtr(); part->SetXrayInfo(listXRayPoints[i]); } return bRet; } bool COTSControlFunExport::GetXRayByFeatures(unsigned long a_nMilliseconds, array^ features, array^>^% a_XrayData, array^% a_strEleResult, bool bQuant) { std::vector listXRayPoints; long xraynum = features->Length; for (int i = 0; i < xraynum; i++) { CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray()); listXRayPoints.push_back(pXRayPoint); } std::vectorlistFeatures; for (int i = 0; i < xraynum; i++) { auto feature = features[i]->GetOTSFeaturePtr(); auto otsSegs = feature->GetSegmentsList(); BrukerSegment* segArray = new BrukerSegment[otsSegs.size()]; for (int j = 0; j < otsSegs.size(); j++) { auto seg = otsSegs[j]; BrukerSegment* oSegment = &segArray[j]; oSegment->XCount = seg->GetLength(); oSegment->XStart = seg->GetStart(); oSegment->Y = seg->GetHeight(); } BrukerFeature oFeature; oFeature.SegmentCount = otsSegs.size(); oFeature.pSegment = segArray; listFeatures.push_back(oFeature); } // set get quantify info flag if (bQuant) { m_pEDS->SetQuantification(TRUE); } else { m_pEDS->SetQuantification(FALSE); } bool bRet = m_pEDS->GetXRayByFeatures(listXRayPoints, listFeatures, a_nMilliseconds); DWORD* xrd; for (int i = 0; i < xraynum; i++) { xrd = listXRayPoints[i]->GetXrayData(); for (int j = 0; j < (int)EDSConst::XANA_CHANNELS; j++) { a_XrayData[i][j] = xrd[j]; } delete listFeatures[i].pSegment;// here using the pure pointer increase the understandability but bring another problem: you must not forget to free the pointer or you involve into memory leak! } if (bQuant) { for (int i = 0; i < features->Length; i++) { CElementChemistriesList& listElement = listXRayPoints[i]->GetElementQuantifyData(); int nElementNum = (int)listElement.size(); CString strElementResult = _T(""); for (auto pElement : listElement) { CString strResult; CString strName = pElement->GetName(); double dPercent = pElement->GetPercentage(); strResult.Format(_T("%s: %f\n"), strName, dPercent); strElementResult += strResult; } a_strEleResult[i] = gcnew String(strElementResult); } } return bRet; } bool COTSControlFunExport::GetXRayByFeatures(unsigned long a_nMilliseconds, array^ parts, bool bQuant) { std::vector listXRayPoints; long xraynum = parts->Length; for (int i = 0; i < xraynum; i++) { CPosXrayPtr pXRayPoint = parts[i]->GetXray()->GetPosXrayPtr(); listXRayPoints.push_back(pXRayPoint); } std::vectorlistFeatures; for (int i = 0; i < xraynum; i++) { auto feature = parts[i]->GetOTSParticlePtr()->GetFeature(); auto otsSegs = feature->GetSegmentsList(); BrukerSegment* segArray = new BrukerSegment[otsSegs.size()]; for (int j = 0; j < otsSegs.size(); j++) { auto seg = otsSegs[j]; BrukerSegment* oSegment = &segArray[j]; oSegment->XCount = seg->GetLength(); oSegment->XStart = seg->GetStart(); oSegment->Y = seg->GetHeight(); } BrukerFeature oFeature; oFeature.SegmentCount = otsSegs.size(); oFeature.pSegment = segArray; listFeatures.push_back(oFeature); } // set get quantify info flag if (bQuant) { m_pEDS->SetQuantification(TRUE); } else { m_pEDS->SetQuantification(FALSE); } bool bRet = m_pEDS->GetXRayByFeatures(listXRayPoints, listFeatures, a_nMilliseconds); //DWORD* xrd; for (int i = 0; i < xraynum; i++) { auto part = parts[i]->GetOTSParticlePtr(); part->SetXrayInfo(listXRayPoints[i]); delete listFeatures[i].pSegment;// using the pure pointer increase the understandability but bring another problem: you must not forget to free the pointer or you involve into memory leak! } return bRet; } bool COTSControlFunExport::GetXRayBySinglePoint(unsigned long a_nMilliseconds, Point point, array^% a_XrayData, String^% a_strEleResult, bool bQuant) { std::vector listXRayPoints; CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray()); pXRayPoint->SetPosition(CPoint(point.X, point.Y)); listXRayPoints.push_back(pXRayPoint); // set get quantify info flag if (bQuant) { m_pEDS->SetQuantification(TRUE); } else { m_pEDS->SetQuantification(FALSE); } bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds); DWORD* xrd; xrd = listXRayPoints[0]->GetXrayData(); for (int j = 0; j < (int)EDSConst::XANA_CHANNELS; j++) { a_XrayData[j] = xrd[j]; } if (bQuant) { CElementChemistriesList& listElement = listXRayPoints[0]->GetElementQuantifyData(); int nElementNum = (int)listElement.size(); CString strElementResult = _T(""); for (auto pElement : listElement) { CString strResult; CString strName = pElement->GetName(); double dPercent = pElement->GetPercentage(); strResult.Format(_T("%s: %f\n"), strName, dPercent); strElementResult += strResult; } a_strEleResult = gcnew String(strElementResult); } return bRet; } bool COTSControlFunExport::GetXRayBySingleFeature(unsigned long a_nMilliseconds, COTSFeatureClr^ feature, array^% a_XrayData, String^% a_strEleResult, bool bQuant) { std::vector listXRayPoints; CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray()); listXRayPoints.push_back(pXRayPoint); std::vector listSegment; std::vectorlistFeatures; auto otsSegs = feature->GetSegmentsList(); for (int j = 0; j < otsSegs->Count; j++) { auto seg = otsSegs[j]; BrukerSegment oSegment; oSegment.XCount = seg->GetLength(); oSegment.XStart = seg->GetStart(); oSegment.Y = seg->GetHeight(); listSegment.push_back(oSegment); } BrukerFeature ofeature; ofeature.SegmentCount = listSegment.size(); ofeature.pSegment = &listSegment[0]; listFeatures.push_back(ofeature); bool bRet = FALSE; // set get quantify info flag if (bQuant) { m_pEDS->SetQuantification(TRUE); } else { m_pEDS->SetQuantification(FALSE); } bRet = m_pEDS->GetXRayByFeatures(listXRayPoints, listFeatures, a_nMilliseconds); DWORD* xrd; pXRayPoint = listXRayPoints[0]; xrd = pXRayPoint->GetXrayData(); for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++) { a_XrayData[i] = xrd[i]; } if (bQuant) { CElementChemistriesList& listElement = listXRayPoints[0]->GetElementQuantifyData(); int nElementNum = (int)listElement.size(); CString strElementResult = _T(""); for (auto pElement : listElement) { CString strResult; CString strName = pElement->GetName(); double dPercent = pElement->GetPercentage(); strResult.Format(_T("%s: %f\n"), strName, dPercent); strElementResult += strResult; } a_strEleResult = gcnew String(strElementResult); } return bRet; } bool COTSControlFunExport::GetXRayElements(unsigned long a_nMilliseconds, array^% a_XrayData, int^% a_nElementNum, String^% a_strResult) { std::vector listXRayPoints; CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray()); pXRayPoint->SetPosition(CPoint(10, 10)); listXRayPoints.push_back(pXRayPoint); CPosXrayPtr pXRayPoint1 = CPosXrayPtr(new CPosXray()); pXRayPoint1->SetPosition(CPoint(20, 20)); listXRayPoints.push_back(pXRayPoint1); // set get quantify info flag m_pEDS->SetQuantification(TRUE); bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds); DWORD* xrd; pXRayPoint = listXRayPoints[1]; xrd = pXRayPoint->GetXrayData(); // element quantify data CElementChemistriesList& listElement = listXRayPoints[1]->GetElementQuantifyData(); int nElementNum = (int)listElement.size(); CString strElementResult = _T(""); for (auto pElement : listElement) { CString strResult; CString strName = pElement->GetName(); double dPercent = pElement->GetPercentage(); strResult.Format(_T("%s: %f\n"), strName, dPercent); strElementResult += strResult; } for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++) { a_XrayData[i] = xrd[i]; } a_nElementNum = nElementNum; a_strResult = gcnew String(strElementResult); return bRet; } bool COTSControlFunExport::GetXRayAndElements(unsigned long a_nMilliseconds, int a_BSEX, int a_BSEY, array^% a_XrayData, int^% a_nElementNum, String^% a_strResult) { std::vector listXRayPoints; CPosXrayPtr pXRayPoint = CPosXrayPtr(new CPosXray()); pXRayPoint->SetPosition(CPoint(a_BSEX, a_BSEY)); listXRayPoints.push_back(pXRayPoint); CPosXrayPtr pXRayPoint1 = CPosXrayPtr(new CPosXray()); pXRayPoint1->SetPosition(CPoint(a_BSEX, a_BSEY)); listXRayPoints.push_back(pXRayPoint1); // set get quantify info flag m_pEDS->SetQuantification(FALSE); bool bRet = m_pEDS->GetXRayByPoints(listXRayPoints, a_nMilliseconds); std::vector listXRayPointsTemp; CPosXrayPtr pXRayPointTemp = CPosXrayPtr(new CPosXray()); listXRayPointsTemp.push_back(pXRayPointTemp); for (int i = 0; i < 2; i++) { listXRayPointsTemp[0] = listXRayPoints[i]; m_pEDS->SetQuantification(TRUE); bool bRet = m_pEDS->GetXRayByPoints(listXRayPointsTemp, a_nMilliseconds); listXRayPoints[i] = listXRayPointsTemp[0]; } DWORD* xrd; pXRayPoint = listXRayPoints[1]; xrd = pXRayPoint->GetXrayData(); // element quantify data CElementChemistriesList& listElement = listXRayPoints[1]->GetElementQuantifyData(); int nElementNum = (int)listElement.size(); CString strElementResult = _T(""); for (auto pElement : listElement) { CString strResult; CString strName = pElement->GetName(); double dPercent = pElement->GetPercentage(); strResult.Format(_T("%s: %f\n"), strName, dPercent); strElementResult += strResult; } for (int i = 0; i < (int)EDSConst::XANA_CHANNELS; i++) { a_XrayData[i] = xrd[i]; } a_nElementNum = nElementNum; a_strResult = gcnew String(strElementResult); return bRet; } int COTSControlFunExport::AcquireBSEImage(int a_nMatrixIndex, int nReads, int nDwell, array^% a_ImgData) { int bRet = 0; CSize sz; int height, width; CBSEImgPtr pbseImg = nullptr; pbseImg = m_pScan->AcquireBSEImage(a_nMatrixIndex, nReads, nDwell); if (pbseImg == nullptr) { return bRet; } sz = pbseImg->GetImageSize(); height = sz.cx; width = sz.cy; bRet = height * width; BYTE* lpData = pbseImg->GetImageDataPointer(); for (int i = 0; i < bRet; i++) { a_ImgData[i] = lpData[i]; } return bRet; // return 0; } }