DomainClr.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. #include "stdafx.h"
  2. #include "DomainClr.h"
  3. #include "COTSUtilityDllFunExport.h"
  4. namespace OTSCLRINTERFACE {
  5. CDomainClr::CDomainClr()
  6. {
  7. m_LpDomain = new CDomainPtr(new CDomain());
  8. }
  9. CDomainClr::CDomainClr(CDomainPtr a_pDomain) // constructor
  10. {
  11. ASSERT(a_pDomain);
  12. if (!a_pDomain)
  13. {
  14. LogErrorTrace(__FILE__, __LINE__, _T("CBSEImgClr: Generate CDomainClr pointer failed."));
  15. return;
  16. }
  17. m_LpDomain = new CDomainPtr(a_pDomain);
  18. }
  19. CDomainClr::CDomainClr(int a_nShape, System::Drawing::Rectangle^ a_rectDomain) // constructor
  20. {
  21. m_LpDomain = new CDomainPtr(new CDomain());
  22. CDomainPtr d = *m_LpDomain;
  23. if (a_rectDomain == nullptr)
  24. {
  25. LogErrorTrace(__FILE__, __LINE__, _T("CDomainClr: invalide rectangle."));
  26. return;
  27. }
  28. d->SetShape((DOMAIN_SHAPE)a_nShape);
  29. CRect r = CRect((int)a_rectDomain->Left, (int)a_rectDomain->Top, (int)a_rectDomain->Right, (int)a_rectDomain->Bottom);
  30. d->SetDomainRect(r);
  31. }
  32. CDomainClr::~CDomainClr()
  33. {
  34. if (m_LpDomain != nullptr)
  35. {
  36. delete m_LpDomain;
  37. m_LpDomain = NULL;
  38. }
  39. }
  40. /*CDomainClr::!CDomainClr()
  41. {
  42. if (m_LpDomain != nullptr)
  43. {
  44. delete m_LpDomain;
  45. m_LpDomain = NULL;
  46. }
  47. }*/
  48. CDomainClr::CDomainClr(CDomain* a_pSource) // copy constructor
  49. {
  50. ASSERT(a_pSource);
  51. if (!a_pSource)
  52. {
  53. LogErrorTrace(__FILE__, __LINE__, _T("CBSEImgClr: Generate CDomainClr pointer failed."));
  54. return;
  55. }
  56. m_LpDomain = new CDomainPtr(a_pSource);
  57. }
  58. void CDomainClr::MyDispose()
  59. {
  60. if (m_LpDomain != nullptr)
  61. {
  62. delete m_LpDomain;
  63. m_LpDomain = NULL;
  64. }
  65. }
  66. bool CDomainClr::IsEmpty()
  67. {
  68. if (m_LpDomain == nullptr)
  69. {
  70. LogErrorTrace(__FILE__, __LINE__, _T("GetName: current CLR point is IsEmpty."));
  71. return false;
  72. }
  73. CDomainPtr pDomain = GetDomainPtr();
  74. ASSERT(pDomain);
  75. if (!pDomain)
  76. {
  77. LogErrorTrace(__FILE__, __LINE__, _T("GetName:IsEmpty pointer."));
  78. return false;
  79. }
  80. return pDomain->IsEmpty();
  81. }
  82. bool CDomainClr::IsRound()
  83. {
  84. if (m_LpDomain == nullptr)
  85. {
  86. LogErrorTrace(__FILE__, __LINE__, _T("GetName: current CLR point is IsRound."));
  87. return false;
  88. }
  89. CDomainPtr pDomain = GetDomainPtr();
  90. ASSERT(pDomain);
  91. if (!pDomain)
  92. {
  93. LogErrorTrace(__FILE__, __LINE__, _T("GetName:invalid pointer."));
  94. return false;
  95. }
  96. return pDomain->IsRound();
  97. }
  98. bool CDomainClr::IsRect()
  99. {
  100. if (m_LpDomain == nullptr)
  101. {
  102. LogErrorTrace(__FILE__, __LINE__, _T("GetName: current CLR point is IsRect."));
  103. return false;
  104. }
  105. CDomainPtr pDomain = GetDomainPtr();
  106. ASSERT(pDomain);
  107. if (!pDomain)
  108. {
  109. LogErrorTrace(__FILE__, __LINE__, _T("GetName:invalid pointer."));
  110. return false;
  111. }
  112. return pDomain->IsRect();
  113. }
  114. bool CDomainClr::IsInvalid()
  115. {
  116. CDomainPtr pDomain = GetDomainPtr();
  117. ASSERT(pDomain);
  118. if (!pDomain)
  119. {
  120. LogErrorTrace(__FILE__, __LINE__, _T("CDomainClr::IsInvalid: invalid pointer."));
  121. return false;
  122. }
  123. bool bRet = false;
  124. bRet = pDomain->IsInvalid();
  125. return bRet;
  126. }
  127. // domain center
  128. Point CDomainClr::GetDomainCenter()
  129. {
  130. Point oRet;
  131. CDomainPtr pDomain = GetDomainPtr();
  132. ASSERT(pDomain);
  133. if (!pDomain)
  134. {
  135. LogErrorTrace(__FILE__, __LINE__, _T("GetDomainCenter::IsInvalid: invalid pointer."));
  136. return oRet;
  137. }
  138. CPoint oPoint = pDomain->GetDomainCenter();
  139. oRet.X = oPoint.x;
  140. oRet.Y = oPoint.y;
  141. return oRet;
  142. }
  143. void CDomainClr::OffsetDomain(Point a_poiMove)
  144. {
  145. CDomainPtr pDomain = GetDomainPtr();
  146. ASSERT(pDomain);
  147. if (!pDomain)
  148. {
  149. LogErrorTrace(__FILE__, __LINE__, _T("GetDomainCenter::IsInvalid: invalid pointer."));
  150. return;
  151. }
  152. CPoint oPoint;
  153. oPoint.x = a_poiMove.X;
  154. oPoint.y = a_poiMove.Y;
  155. pDomain->OffsetDomain(oPoint);
  156. }
  157. long CDomainClr::GetDiameter()
  158. {
  159. int nDiameter = -1;
  160. if (m_LpDomain != nullptr)
  161. {
  162. nDiameter = (int)m_LpDomain->get()->GetDiameter();
  163. }
  164. return nDiameter;
  165. }
  166. // check if have common area with the given domain
  167. bool CDomainClr::IntersectDomain(CDomainClr^ a_oDomain)
  168. {
  169. CDomainPtr pDomain = GetDomainPtr();
  170. ASSERT(pDomain);
  171. if (!pDomain)
  172. {
  173. LogErrorTrace(__FILE__, __LINE__, _T("IntersectDomain::IsInvalid: invalid pointer."));
  174. return false;
  175. }
  176. if (a_oDomain == nullptr)
  177. {
  178. LogErrorTrace(__FILE__, __LINE__, _T("IntersectDomain::IsInvalid: invalid pointer."));
  179. return false;
  180. }
  181. const CDomainPtr pInsertDomain = a_oDomain->GetDomainPtr();
  182. ASSERT(pInsertDomain);
  183. if (!pInsertDomain)
  184. {
  185. LogErrorTrace(__FILE__, __LINE__, _T("IntersectDomain::IsInvalid: invalid pointer."));
  186. return false;
  187. }
  188. bool bRet = false;
  189. bRet = pDomain->IntersectDomain(pInsertDomain.get());
  190. return bRet;
  191. }
  192. // check if the point in the domain
  193. bool CDomainClr::PtInDomain(Point^ a_poiCheck)
  194. {
  195. CDomainPtr pDomain = GetDomainPtr();
  196. ASSERT(pDomain);
  197. if (!pDomain)
  198. {
  199. LogErrorTrace(__FILE__, __LINE__, _T("PtInDomain::IsInvalid: invalid pointer."));
  200. return false;
  201. }
  202. ASSERT(a_poiCheck);
  203. if (!a_poiCheck)
  204. {
  205. LogErrorTrace(__FILE__, __LINE__, _T("PtInDomain::IsInvalid: invalid pointer."));
  206. return false;
  207. }
  208. CPoint poiCheck;
  209. poiCheck.x = a_poiCheck->X;
  210. poiCheck.y = a_poiCheck->Y;
  211. bool bRet = false;
  212. bRet = pDomain->PtInDomain(poiCheck);
  213. return bRet;
  214. }
  215. void CDomainClr::SetShape(int a_nShape)
  216. {
  217. if (m_LpDomain != nullptr)
  218. {
  219. m_LpDomain->get()->SetShape(( OTSDATA::DOMAIN_SHAPE)a_nShape);
  220. }
  221. }
  222. int CDomainClr::GetShape()
  223. {
  224. int nGetShape = -1;
  225. if (m_LpDomain != nullptr)
  226. {
  227. nGetShape = (int)m_LpDomain->get()->GetShape();
  228. }
  229. return nGetShape;
  230. }
  231. void CDomainClr::SetRectDomain(System::Drawing::Rectangle a_oRect)
  232. {
  233. CDomainPtr d = GetDomainPtr();
  234. CRect r = CRect(a_oRect.Left, a_oRect.Top, a_oRect.Right, a_oRect.Bottom);
  235. d->SetDomainRect(r);
  236. }
  237. System::Drawing::Rectangle CDomainClr::GetRectDomain()
  238. {
  239. CDomainPtr d = GetDomainPtr();
  240. CRect cr = d->GetDomainRect();
  241. System::Drawing::Rectangle r(cr.left ,cr.top ,cr.Width() ,cr.Height() );
  242. return r;
  243. }
  244. bool CDomainClr::DomainInDomain(CDomainClr^ a_oDomain)
  245. {
  246. if (a_oDomain == nullptr)
  247. {
  248. LogErrorTrace(__FILE__, __LINE__, _T("DomainInDomain : invalide domain."));
  249. return false;
  250. }
  251. bool bRet = false;
  252. CDomainPtr pDomainThis = GetDomainPtr();
  253. if (pDomainThis == nullptr)
  254. {
  255. LogErrorTrace(__FILE__, __LINE__, _T("DomainInDomain : invalide domain."));
  256. return false;
  257. }
  258. const CDomainPtr pDomainParam = a_oDomain->GetDomainPtr();
  259. if (pDomainParam == nullptr)
  260. {
  261. LogErrorTrace(__FILE__, __LINE__, _T("DomainInDomain : invalide domain."));
  262. return false;
  263. }
  264. bRet = pDomainThis->DomainInDomain(*pDomainParam.get());
  265. return bRet;
  266. }
  267. CDomainPtr CDomainClr::GetDomainPtr()
  268. {
  269. return *m_LpDomain;
  270. }
  271. void CDomainClr::SetPolygonPoint(System::Collections::Generic::List<System::Drawing::Point>^ a_PolygonPoint)
  272. {
  273. CDomainPtr domainPtr = GetDomainPtr();
  274. std::vector<CPoint> listPolygonPoint;
  275. listPolygonPoint.clear();
  276. for (int i = 0; i < (int)a_PolygonPoint->Count; i++)
  277. {
  278. CPoint pt(a_PolygonPoint[i].X, a_PolygonPoint[i].Y);
  279. listPolygonPoint.push_back(pt);
  280. }
  281. if (domainPtr != nullptr)
  282. {
  283. domainPtr->SetPolygonPoint(listPolygonPoint);
  284. }
  285. }
  286. System::Collections::Generic::List<System::Drawing::Point>^ CDomainClr::GetPolygonPoint()
  287. {
  288. CDomainPtr domainPtr = GetDomainPtr();
  289. std::vector<CPoint> vectorCPoint=domainPtr->GetPolygonPoint();
  290. System::Collections::Generic::List<System::Drawing::Point>^ listPolygonPoint = gcnew System::Collections::Generic::List < System::Drawing::Point >();
  291. for (int i = 0; i < (int)vectorCPoint.size(); i++)
  292. {
  293. System::Drawing::Point pt(vectorCPoint[i].x, vectorCPoint[i].y);
  294. listPolygonPoint->Add(pt);
  295. }
  296. return listPolygonPoint;
  297. }
  298. }