ViewWindow.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using HalconDotNet;
  6. namespace ViewWindow
  7. {
  8. public class ViewWindow : Model.IViewWindow
  9. {
  10. public Model.HWndCtrl _hWndControl;
  11. private Model.ROIController _roiController;
  12. public ViewWindow(HWindowControl window)
  13. {
  14. this._hWndControl = new Model.HWndCtrl(window);
  15. this._roiController = new Model.ROIController();
  16. this._hWndControl.setROIController(this._roiController);
  17. this._hWndControl.setViewState(Model.HWndCtrl.MODE_VIEW_NONE);
  18. }
  19. //清空所有显示内容
  20. public void ClearWindow()
  21. {
  22. //清空显示image
  23. _hWndControl.clearList();
  24. //清空hobjectList
  25. _hWndControl.clearHObjectList();
  26. }
  27. public void displayImage(HObject img)
  28. {
  29. //添加背景图片
  30. this._hWndControl.addImageShow(img);
  31. //清空roi容器,不让roi显示
  32. this._roiController.reset();
  33. //显示图片
  34. this._roiController.resetWindowImage();
  35. //this._hWndControl.resetWindow();
  36. // this._hWndControl.resetAll();
  37. //this._hWndControl.repaint();
  38. }
  39. public void notDisplayRoi()
  40. {
  41. this._roiController.reset();
  42. //显示图片
  43. this._roiController.resetWindowImage();
  44. }
  45. //获取当前窗口显示的roi数量
  46. public int getRoiCount()
  47. {
  48. return _roiController.ROIList.Count;
  49. }
  50. //是否开启缩放事件
  51. public void setDrawModel(bool flag)
  52. {
  53. _hWndControl.drawModel = flag;
  54. }
  55. //是否开启编辑事件
  56. public void setEditModel(bool flag)
  57. {
  58. _roiController.EditModel = flag;
  59. // _hWndControl.drawModel = flag;
  60. }
  61. public void resetWindowImage()
  62. {
  63. this._hWndControl.resetWindow();
  64. this._roiController.resetWindowImage();
  65. }
  66. public void mouseleave()
  67. {
  68. _hWndControl.raiseMouseup();
  69. }
  70. public void zoomWindowImage()
  71. {
  72. this._roiController.zoomWindowImage();
  73. }
  74. public void moveWindowImage()
  75. {
  76. this._roiController.moveWindowImage();
  77. }
  78. public void noneWindowImage()
  79. {
  80. this._roiController.noneWindowImage();
  81. }
  82. public void genRect1(double row1, double col1, double row2, double col2, ref List<Model.ROI> rois)
  83. {
  84. this._roiController.genRect1(row1, col1, row2, col2, ref rois);
  85. }
  86. public void genNurbs(HTuple rows, HTuple cols, ref List<Model.ROI> rois)
  87. {
  88. this._roiController.genNurbs( rows,cols,ref rois);
  89. }
  90. public void genInitRect1( ref List<Model.ROI> rois)
  91. {
  92. this._roiController.genInitRect1(_roiController.viewController .imageHeight , ref rois);
  93. }
  94. public void genRect2(double row, double col, double phi, double length1, double length2, ref List<Model.ROI> rois)
  95. {
  96. this._roiController.genRect2(row, col, phi, length1, length2, ref rois);
  97. }
  98. public void genInitRect2(ref List<Model.ROI> rois)
  99. {
  100. this._roiController.genInitRect2(_roiController.viewController.imageHeight, ref rois);
  101. }
  102. public void genCircle(double row, double col, double radius, ref List<Model.ROI> rois)
  103. {
  104. this._roiController.genCircle(row, col, radius, ref rois);
  105. }
  106. public void genCircularArc(double row, double col, double radius, double startPhi, double extentPhi, string direct,ref List<Model.ROI> rois)
  107. {
  108. this._roiController.genCircularArc(row, col, radius, startPhi, extentPhi,direct,ref rois);
  109. }
  110. public void genLine(double beginRow, double beginCol, double endRow, double endCol, ref List<Model.ROI> rois)
  111. {
  112. this._roiController.genLine(beginRow, beginCol, endRow, endCol, ref rois);
  113. }
  114. public List<double> smallestActiveROI(out string name, out int index)
  115. {
  116. List<double> resual = this._roiController.smallestActiveROI(out name,out index);
  117. return resual;
  118. }
  119. public Model.ROI smallestActiveROI(out List<double> data, out int index)
  120. {
  121. Model.ROI roi = this._roiController.smallestActiveROI(out data, out index);
  122. return roi;
  123. }
  124. public void selectROI(int index)
  125. {
  126. this._roiController.selectROI(index);
  127. }
  128. public void selectROI( List<Model.ROI> rois, int index)
  129. {
  130. //this._roiController.selectROI(index);
  131. if ((rois.Count > index)&&(index>=0))
  132. {
  133. this._hWndControl.resetAll();
  134. this._hWndControl.repaint();
  135. HTuple m_roiData = null;
  136. m_roiData = rois[index].getModelData();
  137. switch (rois[index].Type)
  138. {
  139. case "ROIRectangle1":
  140. if (m_roiData != null)
  141. {
  142. this._roiController.displayRect1(rois[index].Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D);
  143. }
  144. break;
  145. case "ROIRectangle2":
  146. if (m_roiData != null)
  147. {
  148. this._roiController.displayRect2(rois[index].Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D, m_roiData[4].D);
  149. }
  150. break;
  151. case "ROICircle":
  152. if (m_roiData != null)
  153. {
  154. this._roiController.displayCircle(rois[index].Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D);
  155. }
  156. break;
  157. case "ROICircularArc":
  158. if (m_roiData != null)
  159. {
  160. this._roiController.displayCircularArc(rois[index].Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D, m_roiData[4].D);
  161. }
  162. break;
  163. case "ROILine":
  164. if (m_roiData != null)
  165. {
  166. this._roiController.displayLine(rois[index].Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D);
  167. }
  168. break;
  169. default:
  170. break;
  171. }
  172. }
  173. }
  174. public void displayROI(List<Model.ROI> rois)
  175. {
  176. if (rois == null)
  177. {
  178. return;
  179. }
  180. //this._hWndControl.resetAll();
  181. //this._hWndControl.repaint();
  182. foreach (var roi in rois)
  183. {
  184. switch (roi.Type)
  185. {
  186. case "ROIRectangle1":
  187. HTuple m_roiData = null;
  188. m_roiData = roi.getModelData();
  189. if (m_roiData != null)
  190. {
  191. this._roiController.displayRect1(roi.Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D);
  192. }
  193. break;
  194. case "ROIRectangle2":
  195. m_roiData = null;
  196. m_roiData = roi.getModelData();
  197. if (m_roiData != null)
  198. {
  199. this._roiController.displayRect2(roi.Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D, m_roiData[4].D);
  200. }
  201. break;
  202. case "ROICircle":
  203. m_roiData = roi.getModelData();
  204. if (m_roiData != null)
  205. {
  206. this._roiController.displayCircle(roi.Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D);
  207. }
  208. break;
  209. case "ROILine":
  210. m_roiData = roi.getModelData();
  211. if (m_roiData != null)
  212. {
  213. this._roiController.displayLine(roi.Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D);
  214. }
  215. break;
  216. case "ROINurbs":
  217. HTuple rows, cols;
  218. roi.getModelData(out rows ,out cols );
  219. if (rows != null)
  220. {
  221. this._roiController.displayNurbs(roi.Color, rows, cols);
  222. }
  223. break;
  224. default:
  225. break;
  226. }
  227. }
  228. }
  229. public void removeActiveROI(ref List<Model.ROI> rois)
  230. {
  231. this._roiController.removeActiveROI(ref rois);
  232. }
  233. public void setActiveRoi(int index)
  234. {
  235. this._roiController.activeROIidx = index;
  236. }
  237. public void saveROI(List<Model.ROI> rois, string fileNmae)
  238. {
  239. List<Model.RoiData> m_RoiData = new List<Model.RoiData>();
  240. for (int i = 0; i < rois.Count; i++)
  241. {
  242. m_RoiData.Add(new Model.RoiData(i, rois[i]));
  243. }
  244. Config.SerializeHelper.Save(m_RoiData, fileNmae);
  245. }
  246. public void loadROI(string fileName, out List<Model.ROI> rois)
  247. {
  248. rois = new List<Model.ROI>();
  249. List<Model.RoiData> m_RoiData = new List<Model.RoiData>();
  250. m_RoiData = (List<Model.RoiData>)Config.SerializeHelper.Load(m_RoiData.GetType(), fileName);
  251. for (int i = 0; i < m_RoiData.Count; i++)
  252. {
  253. switch (m_RoiData[i].Name)
  254. {
  255. case "Rectangle1":
  256. this._roiController.genRect1(m_RoiData[i].Rectangle1.Row1, m_RoiData[i].Rectangle1.Column1,
  257. m_RoiData[i].Rectangle1.Row2, m_RoiData[i].Rectangle1.Column2, ref rois);
  258. rois.Last().Color = m_RoiData[i].Rectangle1.Color;
  259. break;
  260. case "Rectangle2":
  261. this._roiController.genRect2(m_RoiData[i].Rectangle2.Row, m_RoiData[i].Rectangle2.Column,
  262. m_RoiData[i].Rectangle2.Phi, m_RoiData[i].Rectangle2.Lenth1, m_RoiData[i].Rectangle2.Lenth2, ref rois);
  263. rois.Last().Color = m_RoiData[i].Rectangle2.Color;
  264. break;
  265. case "Circle":
  266. this._roiController.genCircle(m_RoiData[i].Circle.Row, m_RoiData[i].Circle.Column, m_RoiData[i].Circle.Radius, ref rois);
  267. rois.Last().Color = m_RoiData[i].Circle.Color;
  268. break;
  269. case "Line":
  270. this._roiController.genLine(m_RoiData[i].Line.RowBegin, m_RoiData[i].Line.ColumnBegin,
  271. m_RoiData[i].Line.RowEnd, m_RoiData[i].Line.ColumnEnd, ref rois);
  272. rois.Last().Color = m_RoiData[i].Line.Color;
  273. break;
  274. default:
  275. break;
  276. }
  277. }
  278. this._hWndControl.resetAll();
  279. this._hWndControl.repaint();
  280. }
  281. #region 专门用于 显示region 和xld的方法
  282. public void displayHobject(HObject obj,string color)
  283. {
  284. _hWndControl.DispObj(obj, color);
  285. }
  286. public void displayHobject(HObject obj)
  287. {
  288. _hWndControl.DispObj(obj, null);
  289. }
  290. #endregion
  291. }
  292. }