MsrThreadClr.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. #include "stdafx.h"
  2. #include "MsrThreadClr.h"
  3. #include "MsrThread.h"
  4. namespace OTSINTERFACE {
  5. CMsrThreadClr::CMsrThreadClr()
  6. {
  7. m_pMsrThread =new CMsrThreadPtr( new CMsrThread());
  8. }
  9. CMsrThreadClr::~CMsrThreadClr()
  10. {
  11. if (m_pMsrThread!=nullptr)
  12. {
  13. delete m_pMsrThread;
  14. m_pMsrThread = NULL;
  15. }
  16. }
  17. CMsrThreadClr::!CMsrThreadClr()
  18. {
  19. if (m_pMsrThread != nullptr)
  20. {
  21. delete m_pMsrThread;
  22. m_pMsrThread = NULL;
  23. }
  24. }
  25. CMsrThreadClr::CMsrThreadClr(CMsrThreadPtr pMsrThread)
  26. {
  27. m_pMsrThread = new CMsrThreadPtr(pMsrThread);
  28. }
  29. bool CMsrThreadClr::CheckMeasureParam(CProjMgrClr^ a_pProjMgrFile, COTSSamplesListClr^% a_listMeasurableSample, bool a_bAuto)
  30. {
  31. if (this == nullptr)
  32. {
  33. LogErrorTrace(__FILE__, __LINE__, _T("CMsrThreadClr:invalid pointer."));
  34. return false;
  35. }
  36. // safety check
  37. if (a_pProjMgrFile == nullptr)
  38. {
  39. LogErrorTrace(__FILE__, __LINE__, _T("CheckMeasureParam: invalid project manager file."));
  40. return false;
  41. }
  42. // get C++ pointer of work file pointer
  43. COTSProjMgrFilePtr pProjMgr = COTSProjMgrFilePtr(new COTSProjMgrFile());
  44. pProjMgr = a_pProjMgrFile->GetCProjMgrPtr();
  45. COTSSamplesList listMeasuableSamples;
  46. listMeasuableSamples.clear();
  47. a_listMeasurableSample->Clear();
  48. bool bRet = m_pMsrThread->get()->CheckMeasureParam(pProjMgr, listMeasuableSamples, a_bAuto);
  49. for (auto pSample : listMeasuableSamples)
  50. {
  51. ASSERT(pSample);
  52. if (!pSample)
  53. {
  54. LogErrorTrace(__FILE__, __LINE__, _T("CheckMeasureParam:invalid pointer."));
  55. return false;
  56. }
  57. COTSSampleClr^ pSampleClr = gcnew COTSSampleClr(pSample);
  58. ASSERT(pSampleClr);
  59. if (!pSampleClr)
  60. {
  61. LogErrorTrace(__FILE__, __LINE__, _T("CheckMeasureParam:invalid clr pointer."));
  62. return false;
  63. }
  64. a_listMeasurableSample->Add(pSampleClr);
  65. }
  66. return bRet;
  67. }
  68. void CMsrThreadClr::DoMeasure()
  69. {
  70. m_pMsrThread->get()->DoMeasure();
  71. }
  72. void CMsrThreadClr::DoHolePreview(int a_nHoleID, CDomainClr^ a_pMeasureArea)
  73. {
  74. ASSERT(a_pMeasureArea);
  75. if (!a_pMeasureArea)
  76. {
  77. LogErrorTrace(__FILE__, __LINE__, _T("DoHolePreview:invalid clr pointer."));
  78. return;
  79. }
  80. CDomainPtr pArea = a_pMeasureArea->GetDomainPtr();
  81. ASSERT(pArea);
  82. if (!pArea)
  83. {
  84. LogErrorTrace(__FILE__, __LINE__, _T("DoHolePreview:can't get domain pointer."));
  85. return;
  86. }
  87. m_pMsrThread->get()->DoHolePreview(a_nHoleID, pArea);
  88. }
  89. bool CMsrThreadClr::Init(CProjMgrClr^ a_pProjMgrFile, COTSSamplesListClr^ a_listMeasuableSamples)
  90. {
  91. // safety check
  92. if (a_pProjMgrFile == nullptr)
  93. {
  94. LogErrorTrace(__FILE__, __LINE__, _T("Init: invalid project manager file."));
  95. return false;
  96. }
  97. // get C++ pointer of work file pointer
  98. COTSProjMgrFilePtr pProjMgr = a_pProjMgrFile->GetCProjMgrPtr();
  99. COTSSamplesList listMeasuableSamples;
  100. listMeasuableSamples.clear();
  101. int nSize = a_listMeasuableSamples->Count;
  102. for (int i = 0; i < nSize; i++)
  103. {
  104. COTSSamplePtr pSample = a_listMeasuableSamples[i]->GetSamplePtr();
  105. ASSERT(pSample);
  106. if(!pSample)
  107. {
  108. LogErrorTrace(__FILE__, __LINE__, _T("Init: invalid sample pointer."));
  109. return false;
  110. }
  111. listMeasuableSamples.push_back(pSample);
  112. }
  113. bool bRet = m_pMsrThread->get()->Init(pProjMgr, listMeasuableSamples);
  114. return bRet;
  115. }
  116. bool CMsrThreadClr::Init(CProjMgrClr ^ a_pProjMgrFile)
  117. {// safety check
  118. if (a_pProjMgrFile == nullptr)
  119. {
  120. LogErrorTrace(__FILE__, __LINE__, _T("Init: invalid project manager file."));
  121. return false;
  122. }
  123. // get C++ pointer of work file pointer
  124. COTSProjMgrFilePtr pProjMgr = a_pProjMgrFile->GetCProjMgrPtr();
  125. bool bRet = m_pMsrThread->get()->Init(pProjMgr);
  126. return bRet;
  127. }
  128. void CMsrThreadClr::GetMeasureAppFormName(String^ csFormName)
  129. {
  130. m_pMsrThread->get()->GetMeasureAppFormName(csFormName);
  131. }
  132. void CMsrThreadClr::SetMsrThreadStatus(CMsrThreadStatusClr^ a_pThreadStatus)
  133. {
  134. CMsrThreadStatusPtr pMsrThreadStatus = a_pThreadStatus->GetMsrThreadStatusPtr();
  135. ASSERT(pMsrThreadStatus);
  136. if (!pMsrThreadStatus)
  137. {
  138. LogErrorTrace(__FILE__, __LINE__, _T("SetMsrThreadStatus:invalid pointer."));
  139. return;
  140. }
  141. m_pMsrThread->get()->SetMsrThreadStatus(pMsrThreadStatus);
  142. }
  143. CMsrThreadStatusClr^ CMsrThreadClr::GetMsrThreadStatus()
  144. {
  145. CMsrThreadStatusPtr pMsrThreadStatus = m_pMsrThread->get()->GetMsrThreadStatus();
  146. ASSERT(pMsrThreadStatus);
  147. if (!pMsrThreadStatus)
  148. {
  149. LogErrorTrace(__FILE__, __LINE__, _T("GetMsrThreadStatus:invalid pointer."));
  150. return nullptr;
  151. }
  152. return gcnew CMsrThreadStatusClr(pMsrThreadStatus);
  153. }
  154. void CMsrThreadClr::SetMsrLoopStatus(int a_nMsrLoopStatus)
  155. {
  156. m_pMsrThread->get()->SetMsrLoopStatus((OTS_MSR_THREAD_STATUS)a_nMsrLoopStatus);
  157. }
  158. bool CMsrThreadClr::CheckProjFileSave()
  159. {
  160. bool bRet = m_pMsrThread->get()->CheckProjFileSave();
  161. return bRet;
  162. }
  163. CProjMgrClr^ CMsrThreadClr::GetProjMgr()
  164. {
  165. COTSProjMgrFilePtr pProjMgrFile = COTSProjMgrFilePtr(new COTSProjMgrFile());
  166. pProjMgrFile = m_pMsrThread->get()->GetProjMgrFile();
  167. return gcnew CProjMgrClr(pProjMgrFile);
  168. }
  169. void CMsrThreadClr::SetProjMgr(CProjMgrClr^ a_pProjMgrFile)
  170. {
  171. COTSProjMgrFilePtr pProjMgrFile = a_pProjMgrFile->GetCProjMgrPtr();
  172. m_pMsrThread->get()->SetProjMgrFile(pProjMgrFile);
  173. }
  174. int CMsrThreadClr::GetClassifyParticleId(CPartSTDDataClr^ a_pPartSTDData, int steelTech, String^ a_ElementName)
  175. {
  176. //------------------------------------------------------
  177. //编辑测量数据
  178. //实力新元素对象指针
  179. array<System::String^>^ strArrayElement=a_ElementName->Split('\n');
  180. CElementChemistriesList a_listChemistriesElements;
  181. if (strArrayElement->Length > 0)
  182. {
  183. //循环生成CElementChemistryPtr 对象 记录元素名称与质量百分比
  184. for each (String^ str in strArrayElement)
  185. {
  186. if (str!="")
  187. {
  188. CString tempName = str->Split(':')[0]->ToString();
  189. double tempPercentage = Convert::ToDouble(str->Split(':')[1]->ToString());
  190. CElementChemistryPtr pElementChemistrieNewO = CElementChemistryPtr(new CElementChemistry(tempName, tempPercentage));
  191. a_listChemistriesElements.push_back(pElementChemistrieNewO);
  192. }
  193. }
  194. }
  195. int a_nIncId = (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED;
  196. BOOL result = m_pMsrThread->get()->GetClassifyParticleId(a_pPartSTDData->GetPartSTDDataPtr(), steelTech, a_listChemistriesElements, a_nIncId);
  197. if (result)
  198. {
  199. return a_nIncId;
  200. }
  201. return a_nIncId;
  202. }
  203. /*void CMsrThreadClr::FreeDll()
  204. {
  205. if (NULL != m_pMsrThread)
  206. {
  207. delete m_pMsrThread;
  208. m_pMsrThread = NULL;
  209. }
  210. }*/
  211. }