StageFileClr.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. #include "stdafx.h"
  2. #include "StageFileClr.h"
  3. #include "DlgStageMgr.h"
  4. namespace OTSINTERFACE {
  5. CStageFileClr::CStageFileClr()// constructor
  6. {
  7. mStageFile =new CStageFilePtr( new CStageFile());
  8. }
  9. CStageFileClr::CStageFileClr(CStageFileClr^ a_pSource) // copy constructor
  10. {
  11. if (a_pSource == nullptr)
  12. {
  13. LogErrorTrace(__FILE__, __LINE__, _T("CBSEImgClr: empty BSE image."));
  14. return;
  15. }
  16. // can't copy itself
  17. if (a_pSource == this)
  18. {
  19. return;
  20. }
  21. // copy data over
  22. Duplicate(a_pSource);
  23. }
  24. CStageFileClr::CStageFileClr(CStageFilePtr a_pStageFile) // copy constructor
  25. {
  26. mStageFile = new CStageFilePtr(a_pStageFile);
  27. }
  28. CStageFileClr^ CStageFileClr::operator=(CStageFileClr^ a_pSource) // =operator
  29. {
  30. if (a_pSource == nullptr)
  31. {
  32. LogErrorTrace(__FILE__, __LINE__, _T("CBSEImgClr =: empty BSE image."));
  33. return nullptr;
  34. }
  35. // copy the class data over
  36. Duplicate(a_pSource);
  37. // return class
  38. return this;
  39. }
  40. CStageFileClr::~CStageFileClr()
  41. {
  42. if (mStageFile != nullptr)
  43. {
  44. delete mStageFile;
  45. mStageFile = nullptr;
  46. }
  47. }
  48. CStageFileClr::!CStageFileClr()
  49. {
  50. if (mStageFile != nullptr)
  51. {
  52. delete mStageFile;
  53. mStageFile = nullptr;
  54. }
  55. }
  56. CStageFilePtr CStageFileClr::GetStageFilePtr()
  57. {
  58. return *mStageFile;
  59. }
  60. // load/save a stage from a text file
  61. bool CStageFileClr::LoadStageFromTextFile(String^ a_strFilePathName)
  62. {
  63. bool bRet = false;
  64. bRet = mStageFile->get()->LoadStageFromTextFile(a_strFilePathName);
  65. return bRet;
  66. }
  67. bool CStageFileClr::SaveStageIntoTextFile(int a_nIndex, String^ a_strFilePathName)
  68. {
  69. bool bRet = false;
  70. bRet = mStageFile->get()->SaveStageIntoTextFile(a_nIndex, a_strFilePathName);
  71. return bRet;
  72. }
  73. // Load/Save
  74. bool CStageFileClr::Load(int a_nPackId, bool a_bClear, bool a_bGetFromText)
  75. {
  76. bool bRet = false;
  77. bRet = mStageFile->get()->Load((OTS_SOFT_PACKAGE_ID)a_nPackId, a_bClear, a_bGetFromText);
  78. return bRet;
  79. }
  80. bool CStageFileClr::Save(int a_nPackId)
  81. {
  82. bool bRet = false;
  83. bRet = mStageFile->get()->Save((OTS_SOFT_PACKAGE_ID)a_nPackId);
  84. return bRet;
  85. }
  86. CStagesListClr ^ CStageFileClr::GetStagesList()
  87. {
  88. auto lstStage = mStageFile->get()->GetStagesList();
  89. auto stages = gcnew CStagesListClr();
  90. for (auto s : lstStage)
  91. {
  92. auto stage = gcnew CStageClr(s);
  93. stages->Add(stage);
  94. }
  95. return stages;
  96. }
  97. bool CStageFileClr::SetStagesList(CStagesListClr^ a_listStages, bool a_bClear)
  98. {
  99. ASSERT(a_listStages);
  100. if (!a_listStages)
  101. {
  102. LogErrorTrace(__FILE__, __LINE__, _T("SetStagesList:invalid stage list."));
  103. return false;
  104. }
  105. // stages list
  106. CStagesList listStage;
  107. for (int i = 0; i < a_listStages->Count; i++)
  108. {
  109. CStageClr^ pStageClr = a_listStages[i];
  110. ASSERT(pStageClr);
  111. if (!pStageClr)
  112. {
  113. LogErrorTrace(__FILE__, __LINE__, _T("GetStageFilePtr:invalid stage file pointer."));
  114. return false;
  115. }
  116. CStagePtr pStage = pStageClr->GetStagePtr();
  117. ASSERT(pStage);
  118. if (!pStage)
  119. {
  120. LogErrorTrace(__FILE__, __LINE__, _T("GetStageFilePtr:invalid stage file pointer."));
  121. return false;
  122. }
  123. listStage.push_back(pStage);
  124. }
  125. mStageFile->get()->SetStagesList(listStage, a_bClear);
  126. return true;
  127. }
  128. bool CStageFileClr::SetStageData(CSEMStageDataClr^ a_pStageData)
  129. {
  130. ASSERT(a_pStageData);
  131. if (!a_pStageData)
  132. {
  133. LogErrorTrace(__FILE__, __LINE__, _T("SetStageData:invalid stage pointer."));
  134. return false;
  135. }
  136. CSEMStageDataPtr pSEMStageData = a_pStageData->GetCSEMStageData();
  137. ASSERT(pSEMStageData);
  138. if (!pSEMStageData)
  139. {
  140. LogErrorTrace(__FILE__, __LINE__, _T("Save::invalide stage file pointer"));
  141. return false;
  142. }
  143. mStageFile->get()->SetStageData(pSEMStageData);
  144. return true;
  145. }
  146. // conver SEM cordination to OTS cordination
  147. bool CStageFileClr::ConverSEMToOTSSystem(CDomainClr^ a_pBoundary, CDomainClr^ a_pSTD, CHoleListClr^ a_listStageHoles)
  148. {
  149. if (this == nullptr)
  150. {
  151. LogErrorTrace(__FILE__, __LINE__, _T("ConverSEMToOTSSystem: invalid pointer."));
  152. return false;
  153. }
  154. ASSERT(a_pBoundary);
  155. if (!a_pBoundary)
  156. {
  157. LogErrorTrace(__FILE__, __LINE__, _T("ConverSEMToOTSSystem: invalid boundary pointer."));
  158. return false;
  159. }
  160. CDomainPtr pBoundary = a_pBoundary->GetDomainPtr();
  161. ASSERT(pBoundary);
  162. if (!pBoundary)
  163. {
  164. LogErrorTrace(__FILE__, __LINE__, _T("ConverSEMToOTSSystem: invalid boundary pointer."));
  165. return false;
  166. }
  167. ASSERT(a_pSTD);
  168. if (!a_pSTD)
  169. {
  170. LogErrorTrace(__FILE__, __LINE__, _T("ConverSEMToOTSSystem: invalid STD pointer."));
  171. return false;
  172. }
  173. CDomainPtr pSTD = a_pBoundary->GetDomainPtr();
  174. ASSERT(pSTD);
  175. if (!pSTD)
  176. {
  177. LogErrorTrace(__FILE__, __LINE__, _T("ConverSEMToOTSSystem: invalid STD pointer."));
  178. return false;
  179. }
  180. ASSERT(a_listStageHoles);
  181. if (!a_listStageHoles)
  182. {
  183. LogErrorTrace(__FILE__, __LINE__, _T("ConverSEMToOTSSystem: invalid stage hole pointer."));
  184. return false;
  185. }
  186. CHolesList listHole;
  187. for (int i = 0; i < a_listStageHoles->Count; i++)
  188. {
  189. CHoleClr^ pHoleClr = a_listStageHoles[i];
  190. ASSERT(pHoleClr);
  191. if (!pHoleClr)
  192. {
  193. LogErrorTrace(__FILE__, __LINE__, _T("ConverSEMToOTSSystem: invalid hole pointer."));
  194. return false;
  195. }
  196. CHolePtr pHole = pHoleClr->GetHolePtr();
  197. ASSERT(pHole);
  198. if (!pHole)
  199. {
  200. LogErrorTrace(__FILE__, __LINE__, _T("ConverSEMToOTSSystem: invalid hole pointer"));
  201. return false;
  202. }
  203. listHole.push_back(pHole);
  204. }
  205. bool bRet = false;
  206. bRet =mStageFile->get()->ConverSEMToOTSSystem(pBoundary, pSTD, listHole);
  207. return bRet;
  208. }
  209. // conver OTS point to SEM point
  210. bool CStageFileClr::ConverOTSToSEMPoint(Point^ a_OTSpt, Point^ % a_SEMpt)
  211. {
  212. if (this == nullptr)
  213. {
  214. LogErrorTrace(__FILE__, __LINE__, _T("ConverOTSToSEMPoint: invalid pointer."));
  215. return false;
  216. }
  217. CPoint ptOTS;
  218. ptOTS.x = a_OTSpt->X;
  219. ptOTS.y = a_OTSpt->Y;
  220. CPoint ptSEM;
  221. bool bRet = mStageFile->get()->ConverOTSToSEMPoint(ptOTS, ptSEM);
  222. if (!bRet)
  223. {
  224. LogErrorTrace(__FILE__, __LINE__, _T("ConverOTSToSEMPoint::can't change the point to SEM."));
  225. return false;
  226. }
  227. a_SEMpt->X = ptSEM.x;
  228. a_SEMpt->Y = ptSEM.y;
  229. return bRet;
  230. }
  231. // conver SEM point to OTS point
  232. bool CStageFileClr::ConverSEMToOTSPoint(Point^ a_SEMpt, Point^% a_OTSpt)
  233. {
  234. if (this == nullptr)
  235. {
  236. LogErrorTrace(__FILE__, __LINE__, _T("ConverSEMToOTSPoint: invalid pointer."));
  237. return false;
  238. }
  239. CPoint ptSEM;
  240. ptSEM.x = a_SEMpt->X;
  241. ptSEM.y = a_SEMpt->Y;
  242. CPoint ptOTS;
  243. bool bRet = mStageFile->get()->ConverSEMToOTSPoint(ptSEM, ptOTS);
  244. a_OTSpt->X = ptOTS.x;
  245. a_OTSpt->Y = ptOTS.y;
  246. return bRet;
  247. }
  248. //show stage dialog
  249. CStageFileClr^ CStageFileClr::ShowStageDialogExport(int a_nPackId, CStageFileClr^ a_pStageFile)
  250. {
  251. ASSERT(a_pStageFile);
  252. if (!a_pStageFile)
  253. {
  254. LogErrorTrace(__FILE__, __LINE__, _T("ShowStageDialogExport:invalid stage file pointer."));
  255. return nullptr;
  256. }
  257. CStageFilePtr pStageFile = a_pStageFile->GetStageFilePtr();
  258. ASSERT(pStageFile);
  259. if (!pStageFile)
  260. {
  261. LogErrorTrace(__FILE__, __LINE__, _T("ShowStageDialogExport:invalid stage file pointer."));
  262. return nullptr;
  263. }
  264. CStageFilePtr pNewStageFile = ShowStageMgrDialog((OTS_SOFT_PACKAGE_ID)a_nPackId, pStageFile);
  265. ASSERT(pNewStageFile);
  266. if (!pNewStageFile)
  267. {
  268. LogErrorTrace(__FILE__, __LINE__, _T("ShowStageDialogExport:invalid new stage file pointer."));
  269. return nullptr;
  270. }
  271. CStageFileClr^ pNewStageFileClr = gcnew CStageFileClr(pNewStageFile);
  272. return pNewStageFileClr;
  273. }
  274. CStageClr^ CStageFileClr::GetWorkingStage()
  275. {
  276. if (this == nullptr)
  277. {
  278. LogErrorTrace(__FILE__, __LINE__, _T("GetWorkingStage: invalid pointer."));
  279. return nullptr;
  280. }
  281. CStagePtr pStage = mStageFile->get()->GetWorkingStage();
  282. if (pStage == nullptr)
  283. {
  284. LogErrorTrace(__FILE__, __LINE__, _T("GetWorkingStage::invalide stage pointer"));
  285. return nullptr;
  286. }
  287. CStageClr^ pStageClr = gcnew CStageClr(pStage);
  288. return pStageClr;
  289. }
  290. // duplication
  291. void CStageFileClr::Duplicate(CStageFileClr^ a_oSource)
  292. {
  293. mStageFile=new CStageFilePtr(new CStageFile(a_oSource->GetStageFilePtr().get()));
  294. }
  295. }