GrainPointStyleClass.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. using PaintDotNet.Base.CommTool;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass
  6. {
  7. class GrainPointStyleClass
  8. {
  9. /// <summary>
  10. /// 需要根据当前操作图片备份和读取的截点数据
  11. /// </summary>
  12. public GrainPointStyleModel styleModel = new GrainPointStyleModel();
  13. /// <summary>
  14. /// 根据图片保存截点数据
  15. /// </summary>
  16. public Dictionary<string, GrainPointStyleModel> styleDict = new Dictionary<string, GrainPointStyleModel>();
  17. /// <summary>
  18. /// 节点区分 1:0.5截点 | 2:1截点 | 3:1.5/2截点(1.5) | 4:1.5/2截点(2)
  19. /// </summary>
  20. private int pointKb = 0;
  21. /// <summary>
  22. /// 节点区分 1:0.5截点 | 2:1截点 | 3:1.5/2截点(1.5) | 4:1.5/2截点(2)
  23. /// </summary>
  24. public int PointKb
  25. {
  26. get
  27. {
  28. return pointKb;
  29. }
  30. set
  31. {
  32. pointKb = value;
  33. }
  34. }
  35. int minDistance = 10;
  36. /// <summary>
  37. /// 鼠标按下
  38. /// </summary>
  39. /// <param name="point1">换算后的点</param>
  40. /// <param name="rectangleF">辅助线边框</param>
  41. /// <param name="linePointList">辅助线的点集合</param>
  42. /// <param name="sender"></param>
  43. /// <param name="e"></param>
  44. public void OnMouseDownFirst(PointF point1, RectangleF rectangleF, List<PointF> linePointList, object sender, MouseEventArgs e)
  45. {
  46. if (e.Button == MouseButtons.Left && e.Clicks == 1)
  47. {
  48. // 0.5截点
  49. if (this.pointKb == 1)
  50. {
  51. //if (add == 0)
  52. // rectangleF = guideClass.RectangleFLine;
  53. if (rectangleF.Contains(point1))
  54. {
  55. double distance = 0;
  56. int init = 0;
  57. PointF pointFAdd = new PointF();
  58. foreach (var linePoint in linePointList)
  59. {
  60. double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10);
  61. if (init == 0)
  62. distance = distance1;
  63. else
  64. {
  65. if (distance1 < distance)
  66. {
  67. distance = distance1;
  68. pointFAdd = linePoint;
  69. }
  70. }
  71. init++;
  72. }
  73. if (distance > minDistance)
  74. {
  75. return;
  76. }
  77. styleModel.manualAddPoint(pointFAdd, this.pointKb);
  78. }
  79. }
  80. // 1截点
  81. else if (this.pointKb == 2)
  82. {
  83. //if (add == 0)
  84. // rectangleF = guideClass.RectangleFLine;
  85. if (rectangleF.Contains(point1))
  86. {
  87. double distance = 0;
  88. int init = 0;
  89. PointF pointFAdd = new PointF();
  90. foreach (var linePoint in linePointList)
  91. {
  92. double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10);
  93. if (init == 0)
  94. distance = distance1;
  95. else
  96. {
  97. if (distance1 < distance)
  98. {
  99. distance = distance1;
  100. pointFAdd = linePoint;
  101. }
  102. }
  103. init++;
  104. }
  105. if (distance > minDistance)
  106. {
  107. return;
  108. }
  109. styleModel.manualAddPoint(pointFAdd, this.pointKb);
  110. }
  111. }
  112. // 1.5/2截点(1.5)
  113. else if (this.pointKb == 3)
  114. {
  115. //if (add == 0)
  116. // rectangleF = guideClass.RectangleFLine;
  117. if (rectangleF.Contains(point1))
  118. {
  119. double distance = 0;
  120. int init = 0;
  121. PointF pointFAdd = new PointF();
  122. foreach (var linePoint in linePointList)
  123. {
  124. double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10);
  125. if (init == 0)
  126. distance = distance1;
  127. else
  128. {
  129. if (distance1 < distance)
  130. {
  131. distance = distance1;
  132. pointFAdd = linePoint;
  133. }
  134. }
  135. init++;
  136. }
  137. if (distance > minDistance)
  138. {
  139. return;
  140. }
  141. styleModel.manualAddPoint(pointFAdd, this.pointKb);
  142. }
  143. }
  144. // 1.5/2截点(2)
  145. else if (this.pointKb == 4)
  146. {
  147. //if (add == 0)
  148. // rectangleF = guideClass.RectangleFLine;
  149. if (rectangleF.Contains(point1))
  150. {
  151. double distance = 0;
  152. int init = 0;
  153. PointF pointFAdd = new PointF();
  154. foreach (var linePoint in linePointList)
  155. {
  156. double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10);
  157. if (init == 0)
  158. distance = distance1;
  159. else
  160. {
  161. if (distance1 < distance)
  162. {
  163. distance = distance1;
  164. pointFAdd = linePoint;
  165. }
  166. }
  167. init++;
  168. }
  169. if (distance > minDistance)
  170. {
  171. return;
  172. }
  173. styleModel.manualAddPoint(pointFAdd, this.pointKb);
  174. }
  175. }
  176. }
  177. }
  178. /// <summary>
  179. /// 鼠标按下
  180. /// </summary>
  181. /// <param name="point1">换算后的点</param>
  182. /// <param name="rectangleF">辅助线边框</param>
  183. /// <param name="linePointList">辅助线的点集合</param>
  184. /// <param name="e"></param>
  185. public void OnMouseDownFirst(PointF point1, RectangleF rectangleF, List<PointF> linePointList, MouseEventArgs e)
  186. {
  187. if (e.Button != MouseButtons.Left || e.Clicks != 1)
  188. return;
  189. // 0.5截点
  190. if (this.pointKb == 1)
  191. {
  192. if (rectangleF.Contains(point1))
  193. {
  194. double distance = 0;
  195. int init = 0;
  196. PointF pointFAdd = new PointF();
  197. foreach (var linePoint in linePointList)
  198. {
  199. double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10);
  200. if (init == 0)
  201. distance = distance1;
  202. else
  203. {
  204. if (distance1 < distance)
  205. {
  206. distance = distance1;
  207. pointFAdd = linePoint;
  208. }
  209. }
  210. init++;
  211. }
  212. if (distance > minDistance)
  213. {
  214. return;
  215. }
  216. styleModel.manualAddPoint(pointFAdd, this.pointKb);
  217. }
  218. }
  219. // 1截点
  220. else if (this.pointKb == 2)
  221. {
  222. if (rectangleF.Contains(point1))
  223. {
  224. double distance = 0;
  225. int init = 0;
  226. PointF pointFAdd = new PointF();
  227. foreach (var linePoint in linePointList)
  228. {
  229. double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10);
  230. if (init == 0)
  231. distance = distance1;
  232. else
  233. {
  234. if (distance1 < distance)
  235. {
  236. distance = distance1;
  237. pointFAdd = linePoint;
  238. }
  239. }
  240. init++;
  241. }
  242. if (distance > minDistance)
  243. {
  244. return;
  245. }
  246. styleModel.manualAddPoint(pointFAdd, this.pointKb);
  247. }
  248. }
  249. // 1.5/2截点(1.5)
  250. else if (this.pointKb == 3)
  251. {
  252. if (rectangleF.Contains(point1))
  253. {
  254. double distance = 0;
  255. int init = 0;
  256. PointF pointFAdd = new PointF();
  257. foreach (var linePoint in linePointList)
  258. {
  259. double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10);
  260. if (init == 0)
  261. distance = distance1;
  262. else
  263. {
  264. if (distance1 < distance)
  265. {
  266. distance = distance1;
  267. pointFAdd = linePoint;
  268. }
  269. }
  270. init++;
  271. }
  272. if (distance > minDistance)
  273. {
  274. return;
  275. }
  276. styleModel.manualAddPoint(pointFAdd, this.pointKb);
  277. }
  278. }
  279. // 1.5/2截点(2)
  280. else if (this.pointKb == 4)
  281. {
  282. if (rectangleF.Contains(point1))
  283. {
  284. double distance = 0;
  285. int init = 0;
  286. PointF pointFAdd = new PointF();
  287. foreach (var linePoint in linePointList)
  288. {
  289. double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10);
  290. if (init == 0)
  291. distance = distance1;
  292. else
  293. {
  294. if (distance1 < distance)
  295. {
  296. distance = distance1;
  297. pointFAdd = linePoint;
  298. }
  299. }
  300. init++;
  301. }
  302. if (distance > minDistance)
  303. {
  304. return;
  305. }
  306. styleModel.manualAddPoint(pointFAdd, this.pointKb);
  307. }
  308. }
  309. styleModel.ReloadLineValueList();
  310. }
  311. /// <summary>
  312. /// 返回布尔类型空或者下一步是否可以添加截点
  313. /// </summary>
  314. /// <param name="point1"></param>
  315. /// <param name="sender"></param>
  316. /// <param name="e"></param>
  317. /// <returns></returns>
  318. public bool OnMouseDownNext(PointF point1, object sender, MouseEventArgs e)
  319. {
  320. // 右键取消添加
  321. if (e.Button == MouseButtons.Right)
  322. {
  323. this.pointKb = 0;
  324. return false;
  325. }
  326. bool toAddPoint = true;
  327. if (e.Button == MouseButtons.Left && e.Clicks == 1)
  328. styleModel.manualRemovePoint(point1, out toAddPoint);
  329. return toAddPoint;
  330. }
  331. /// <summary>
  332. /// 获取截点的中间数据
  333. /// </summary>
  334. public List<List<string>> getTableDataList(GrainPointStyleModel styleModel, double physical_length)
  335. {
  336. //拼接中间数据
  337. List<List<string>> dataList = new List<List<string>>();
  338. List<string> columnName = new List<string>();
  339. columnName.Add(PdnResources.GetString("Menu.Imagement.Measurementlist.ordernumber.text"));
  340. columnName.Add(PdnResources.GetString("Menu.Thestartingpointofthetransversal.Text"));
  341. columnName.Add(PdnResources.GetString("Menu.Theendingpointofthetransversal.Text"));
  342. columnName.Add(PdnResources.GetString("Menu.Thelengthofthethread.Text")+"(μm)");
  343. dataList.Add(columnName);
  344. int index = 0;
  345. foreach (var lineKey in styleModel.lineValueList.Keys)
  346. {
  347. List<string> strList = new List<string>();
  348. strList.Add((++index).ToString());
  349. strList.Add("" + lineKey.startPoint.X + "," + lineKey.startPoint.Y + "");
  350. strList.Add("" + lineKey.endPoint.X + "," + lineKey.endPoint.Y + "");
  351. strList.Add("" + styleModel.lineValueList[lineKey] * physical_length);
  352. dataList.Add(strList);
  353. }
  354. return dataList;
  355. }
  356. }
  357. internal class Line
  358. {
  359. /// <summary>
  360. /// 直线的起点
  361. /// </summary>
  362. public System.Drawing.Point startPoint;
  363. /// <summary>
  364. /// 直线的终点
  365. /// </summary>
  366. public System.Drawing.Point endPoint;
  367. /// <summary>
  368. /// 构造方法
  369. /// </summary>
  370. /// <param name="s"></param>
  371. /// <param name="e"></param>
  372. public Line(System.Drawing.Point s, System.Drawing.Point e)
  373. {
  374. this.startPoint = s;
  375. this.endPoint = e;
  376. }
  377. }
  378. }