GrainSizeGuideModel.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. using PaintDotNet.Base.SettingModel;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass
  6. {
  7. /// <summary>
  8. /// 需要根据当前操作图片备份和读取的辅助线数据
  9. /// </summary>
  10. class GrainSizeGuideModel
  11. {
  12. public string oldSelectItem;
  13. /// <summary>
  14. /// 辅助线位置
  15. /// </summary>
  16. public PointF loctation;
  17. /// <summary>
  18. /// 辅助线区域
  19. /// </summary>
  20. public RectangleF rectangleFLine = new RectangleF();
  21. //辅助线缩放控制
  22. public float originWidth = 1;
  23. public float originHeight = 1;
  24. //辅助线缩放控制(物理长度)
  25. public float rectangleFLineWidth = 1;
  26. public float rectangleFLineHeight = 1;
  27. /// <summary>
  28. /// 矩形宽
  29. /// </summary>
  30. public double lineRectangleWidth;
  31. public double originLineRectangleWidth;
  32. /// <summary>
  33. /// 矩形高
  34. /// </summary>
  35. public double lineRectangleHeight;
  36. public double originLineRectangleHeight;
  37. /// <summary>
  38. /// 直径
  39. /// </summary>
  40. public double lineDiameter;
  41. public double originLineDiameter;
  42. /// <summary>
  43. /// 长度(物理长度)
  44. /// </summary>
  45. public int lineLength;
  46. public float mat_lineLength;
  47. public double originLineLength;
  48. /// <summary>
  49. /// 间距
  50. /// </summary>
  51. public float mat_lineSpacing;
  52. public double originMat_lineSpacing;
  53. private double originLineSpacing;
  54. /// <summary>
  55. /// 线条数
  56. /// </summary>
  57. public int lineDec;
  58. /// <summary>
  59. /// 直径(物理长度)
  60. /// </summary>
  61. public double diameter;
  62. public float mat_diameter;
  63. public double originDiameter;
  64. /// <summary>
  65. /// 边距(物理长度)
  66. /// </summary>
  67. public double margin;
  68. public float mat_margin;
  69. public double originMargin;
  70. /// <summary>
  71. /// 长度(垂线)(物理长度)
  72. /// </summary>
  73. private double originVLineLength;
  74. public int vLineLength;
  75. public float mat_vLineLength;
  76. /// <summary>
  77. /// 长度(水平线)(物理长度)
  78. /// </summary>
  79. private double originHLineLength;
  80. public int hLineLength;
  81. public float mat_hLineLength;
  82. /// <summary>
  83. /// 左上到右下斜线长度(物理长度)
  84. /// </summary>
  85. private double originTopleftLineLength;
  86. public int TopleftLineLength;
  87. public float mat_TopleftLineLength;
  88. /// <summary>
  89. /// 左下到右上斜线长度(物理长度)
  90. /// </summary>
  91. private double originToprightLineLength;
  92. public int ToprightLineLength;
  93. public float mat_ToprightLineLength;
  94. /// <summary>
  95. /// 垂线到圆距离
  96. /// </summary>
  97. private float VLineToCDistance;
  98. public float mat_VLineToCDistance;
  99. public double originVLineToCDistance;
  100. /// <summary>
  101. /// 水平线到圆距离(物理长度)
  102. /// </summary>
  103. private float HLineToCDistance;
  104. public float mat_HLineToCDistance;
  105. public double originHLineToCDistance;
  106. /// <summary>
  107. /// 线颜色
  108. /// </summary>
  109. public int lineColor;
  110. /// <summary>
  111. /// 线宽
  112. /// </summary>
  113. public int lineWidth;
  114. /// <summary>
  115. /// 找到当前的参数数据
  116. /// </summary>
  117. /// <param name="menuId"></param>
  118. /// <returns></returns>
  119. public GrainSizeGuideModel cloneListParamModel()
  120. {
  121. GrainSizeGuideModel newMod = new GrainSizeGuideModel();
  122. newMod.oldSelectItem = this.oldSelectItem;//######################################
  123. ////newMod.ListParam = new List<GrainSizeAnalysisModel>();
  124. ////foreach (var item in this.ListParam)
  125. //// if (item.menuId == menuId)
  126. //// newMod.ListParam.Add(item.cloneModel());
  127. return newMod;
  128. }
  129. public GrainSizeGuideModel cloneModel()
  130. {
  131. GrainSizeGuideModel newMod = new GrainSizeGuideModel();
  132. newMod.oldSelectItem = this.oldSelectItem;
  133. newMod.loctation = new PointF(loctation.X, loctation.Y);
  134. newMod.rectangleFLine = new RectangleF(rectangleFLine.X, rectangleFLine.Y, rectangleFLine.Width, rectangleFLine.Height);
  135. newMod.originWidth = this.originWidth;
  136. newMod.originHeight = this.originHeight;
  137. newMod.rectangleFLineWidth = this.rectangleFLineWidth;
  138. newMod.rectangleFLineHeight = this.rectangleFLineHeight;
  139. newMod.lineRectangleWidth = this.lineRectangleWidth;
  140. newMod.originLineRectangleWidth = this.originLineRectangleWidth;
  141. newMod.lineRectangleHeight = this.lineRectangleHeight;
  142. newMod.originLineRectangleHeight = this.originLineRectangleHeight;
  143. newMod.lineDiameter = this.lineDiameter;
  144. newMod.originLineDiameter = this.originLineDiameter;
  145. newMod.lineLength = this.lineLength;
  146. newMod.mat_lineLength = this.mat_lineLength;
  147. newMod.originLineLength = this.originLineLength;
  148. newMod.mat_lineSpacing = this.mat_lineSpacing;
  149. newMod.originMat_lineSpacing = this.originMat_lineSpacing;
  150. newMod.originLineSpacing = this.originLineSpacing;
  151. newMod.lineDec = this.lineDec;
  152. newMod.diameter = this.diameter;
  153. newMod.mat_diameter = this.mat_diameter;
  154. newMod.originDiameter = this.originDiameter;
  155. newMod.margin = this.margin;
  156. newMod.mat_margin = this.mat_margin;
  157. newMod.originMargin = this.originMargin;
  158. newMod.vLineLength = this.vLineLength;
  159. newMod.mat_vLineLength = this.mat_vLineLength;
  160. newMod.hLineLength = this.hLineLength;
  161. newMod.mat_hLineLength = this.mat_hLineLength;
  162. newMod.TopleftLineLength = this.TopleftLineLength;
  163. newMod.mat_TopleftLineLength = this.mat_TopleftLineLength;
  164. newMod.ToprightLineLength = this.ToprightLineLength;
  165. newMod.mat_ToprightLineLength = this.mat_ToprightLineLength;
  166. newMod.VLineToCDistance = this.VLineToCDistance;
  167. newMod.mat_VLineToCDistance = this.mat_VLineToCDistance;
  168. newMod.originVLineToCDistance = this.originVLineToCDistance;
  169. newMod.HLineToCDistance = this.HLineToCDistance;
  170. newMod.mat_HLineToCDistance = this.mat_HLineToCDistance;
  171. newMod.originHLineToCDistance = this.originHLineToCDistance;
  172. newMod.lineColor = this.lineColor;
  173. newMod.lineWidth = this.lineWidth;
  174. return newMod;
  175. }
  176. public RectangleF RectangleFLine
  177. {
  178. get
  179. {
  180. return this.rectangleFLine;
  181. }
  182. set
  183. {
  184. this.rectangleFLine = value;
  185. }
  186. }
  187. /// <summary>
  188. /// 绘制辅助线(垂直辅助线)
  189. /// </summary>
  190. public void DrawGuideLines1(Graphics graphics)
  191. {
  192. Matrix mtxSave = graphics.Transform;
  193. Matrix matrix = graphics.Transform;
  194. // 以下为绘制样式
  195. Pen linePen = new Pen(Color.FromArgb(this.lineColor), this.lineWidth);
  196. if (this.lineDec % 2 == 0)
  197. {
  198. float Spacing = (float)this.mat_lineSpacing / 2;
  199. for (int i = 0; i < (float)this.lineDec / 2; i++)
  200. {
  201. graphics.DrawLine(linePen, new PointF((float)this.rectangleFLine.X + this.lineWidth / 2 + (this.rectangleFLine.Width - this.lineWidth) / 2 - Spacing, this.rectangleFLine.Top)
  202. , new PointF((float)this.rectangleFLine.X + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Width - this.lineWidth) / 2 - Spacing, this.rectangleFLine.Bottom));
  203. graphics.DrawLine(linePen, new PointF((float)this.rectangleFLine.X + this.lineWidth / 2 + (this.rectangleFLine.Width - this.lineWidth) / 2 + Spacing, this.rectangleFLine.Top)
  204. , new PointF((float)this.rectangleFLine.X + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Width - this.lineWidth) / 2 + Spacing, this.rectangleFLine.Bottom));
  205. Spacing += this.mat_lineSpacing;
  206. }
  207. }
  208. else
  209. {
  210. if (this.lineDec == 1)
  211. {
  212. graphics.DrawLine(linePen, new PointF(this.rectangleFLine.X + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Width - this.lineWidth) / 2, this.rectangleFLine.Top)
  213. , new PointF(this.rectangleFLine.X + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Width - this.lineWidth) / 2, this.rectangleFLine.Bottom));
  214. }
  215. else
  216. {
  217. float Spacing = this.mat_lineSpacing;
  218. for (int i = 0; i < (this.lineDec - 1) / 2; i++)
  219. {
  220. if (i == 0)
  221. graphics.DrawLine(linePen, new PointF(this.rectangleFLine.X + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Width - this.lineWidth) / 2, this.rectangleFLine.Top)
  222. , new PointF(this.rectangleFLine.X + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Width - this.lineWidth) / 2, this.rectangleFLine.Bottom));
  223. graphics.DrawLine(linePen, new PointF(this.rectangleFLine.X + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Width - this.lineWidth) / 2 + Spacing, this.rectangleFLine.Top)
  224. , new PointF(this.rectangleFLine.X + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Width - this.lineWidth) / 2 + Spacing, this.rectangleFLine.Bottom));
  225. graphics.DrawLine(linePen, new PointF(this.rectangleFLine.X + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Width - this.lineWidth) / 2 - Spacing, this.rectangleFLine.Top)
  226. , new PointF(this.rectangleFLine.X + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Width - this.lineWidth) / 2 - Spacing, this.rectangleFLine.Bottom));
  227. Spacing += this.mat_lineSpacing;
  228. }
  229. }
  230. }
  231. Pen pen = new Pen(Color.FromArgb(this.lineColor), 1);
  232. pen.DashStyle = DashStyle.DashDotDot;
  233. //使用自定义线型
  234. float[] dashArray = {
  235. 2.0f, //线长2个像素
  236. 5.0f, //间断5个像素
  237. 2.0f, //线长2个像素
  238. 5.0f //间断5个像素
  239. };
  240. pen.DashPattern = dashArray;
  241. graphics.DrawRectangle(pen, new Rectangle((int)this.rectangleFLine.X, (int)this.rectangleFLine.Y, (int)this.rectangleFLine.Width, (int)this.rectangleFLine.Height));
  242. pen.Dispose();
  243. //显示辅助线像素长度
  244. SizeF sizeF = graphics.MeasureString("" + this.lineLength, new System.Drawing.Font("宋体", 20));
  245. matrix.RotateAt((float)270, new PointF(this.rectangleFLine.Left - sizeF.Height, this.rectangleFLine.Top + sizeF.Width));
  246. graphics.Transform = matrix;
  247. graphics.DrawString("" + this.lineLength, new System.Drawing.Font("宋体", 20), new SolidBrush(Color.Black), new PointF(this.rectangleFLine.Left - sizeF.Height, this.rectangleFLine.Top + sizeF.Width));
  248. graphics.Transform = mtxSave;
  249. }
  250. /// <summary>
  251. /// 绘制辅助线(水平辅助线)
  252. /// </summary>
  253. public void DrawGuideLines2(Graphics graphics)
  254. {
  255. // 以下为绘制样式
  256. Pen linePen = new Pen(Color.FromArgb(this.lineColor), this.lineWidth);
  257. if (this.lineDec % 2 == 0)
  258. {
  259. float Spacing = (float)this.mat_lineSpacing / 2;
  260. for (int i = 0; i < (float)this.lineDec / 2; i++)
  261. {
  262. graphics.DrawLine(linePen, new PointF(this.rectangleFLine.Left, this.rectangleFLine.Y + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Height - this.lineWidth) / 2 - Spacing)
  263. , new PointF(this.rectangleFLine.Right, this.rectangleFLine.Y + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Height - this.lineWidth) / 2 - Spacing));
  264. graphics.DrawLine(linePen, new PointF(this.rectangleFLine.Left, this.rectangleFLine.Y + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Height - this.lineWidth) / 2 + Spacing)
  265. , new PointF(this.rectangleFLine.Right, this.rectangleFLine.Y + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Height - this.lineWidth) / 2 + Spacing));
  266. Spacing += this.mat_lineSpacing;
  267. }
  268. }
  269. else
  270. {
  271. if (this.lineDec == 1)
  272. {
  273. graphics.DrawLine(linePen, new PointF(this.rectangleFLine.Left, this.rectangleFLine.Y + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Height - this.lineWidth) / 2)
  274. , new PointF(this.rectangleFLine.Right, this.rectangleFLine.Y + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Height - this.lineWidth) / 2));
  275. }
  276. else
  277. {
  278. float Spacing = this.mat_lineSpacing;
  279. for (int i = 0; i < (this.lineDec - 1) / 2; i++)
  280. {
  281. if (i == 0)
  282. graphics.DrawLine(linePen, new PointF(this.rectangleFLine.Left, this.rectangleFLine.Y + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Height - this.lineWidth) / 2)
  283. , new PointF(this.rectangleFLine.Right, this.rectangleFLine.Y + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Height - this.lineWidth) / 2));
  284. graphics.DrawLine(linePen, new PointF(this.rectangleFLine.Left, this.rectangleFLine.Y + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Height - this.lineWidth) / 2 - Spacing)
  285. , new PointF(this.rectangleFLine.Right, this.rectangleFLine.Y + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Height - this.lineWidth) / 2 - Spacing));
  286. graphics.DrawLine(linePen, new PointF(this.rectangleFLine.Left, this.rectangleFLine.Y + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Height - this.lineWidth) / 2 + Spacing)
  287. , new PointF(this.rectangleFLine.Right, this.rectangleFLine.Y + (float)this.lineWidth / 2 + (float)(this.rectangleFLine.Height - this.lineWidth) / 2 + Spacing));
  288. Spacing += this.mat_lineSpacing;
  289. }
  290. }
  291. }
  292. Pen pen = new Pen(Color.FromArgb(this.lineColor), 1);
  293. pen.DashStyle = DashStyle.DashDotDot;
  294. //使用自定义线型
  295. float[] dashArray = {
  296. 2.0f, //线长2个像素
  297. 5.0f, //间断5个像素
  298. 2.0f, //线长2个像素
  299. 5.0f //间断5个像素
  300. };
  301. pen.DashPattern = dashArray;
  302. graphics.DrawRectangle(pen, new Rectangle((int)this.rectangleFLine.X, (int)this.rectangleFLine.Y, (int)this.rectangleFLine.Width, (int)this.rectangleFLine.Height));
  303. pen.Dispose();
  304. //显示辅助线像素长度
  305. SizeF sizeF = graphics.MeasureString("" + this.lineLength, new System.Drawing.Font("宋体", 20));
  306. graphics.DrawString("" + this.lineLength, new System.Drawing.Font("宋体", 20), new SolidBrush(Color.Black), new PointF(this.rectangleFLine.Right - sizeF.Width, this.rectangleFLine.Top - sizeF.Height));
  307. }
  308. /// <summary>
  309. /// 绘制辅助线(单圆辅助线)
  310. /// </summary>
  311. public void DrawGuideLines3(Graphics graphics)
  312. {
  313. // 以下为绘制样式
  314. Pen linePen = new Pen(Color.FromArgb(this.lineColor), this.lineWidth);
  315. graphics.DrawEllipse(linePen, this.rectangleFLine.X, this.rectangleFLine.Y, this.rectangleFLine.Width, this.rectangleFLine.Height);
  316. Pen pen = new Pen(Color.FromArgb(this.lineColor), 1);
  317. pen.DashStyle = DashStyle.DashDotDot;
  318. //使用自定义线型
  319. float[] dashArray = {
  320. 2.0f, //线长2个像素
  321. 5.0f, //间断5个像素
  322. 2.0f, //线长2个像素
  323. 5.0f //间断5个像素
  324. };
  325. pen.DashPattern = dashArray;
  326. graphics.DrawRectangle(pen, new Rectangle((int)this.rectangleFLine.X, (int)this.rectangleFLine.Y, (int)this.rectangleFLine.Width, (int)this.rectangleFLine.Height));
  327. pen.Dispose();
  328. }
  329. /// <summary>
  330. /// 绘制辅助线(三圆辅助线)
  331. /// </summary>
  332. public void DrawGuideLines4(Graphics graphics)
  333. {
  334. // 以下为绘制样式
  335. Pen linePen = new Pen(Color.FromArgb(this.lineColor), this.lineWidth);
  336. graphics.DrawEllipse(linePen, this.rectangleFLine.X, this.rectangleFLine.Y, this.rectangleFLine.Width, this.rectangleFLine.Height);
  337. graphics.DrawEllipse(linePen, this.rectangleFLine.X + this.mat_margin, this.rectangleFLine.Y + this.mat_margin, this.rectangleFLine.Width - 2 * this.mat_margin, this.rectangleFLine.Height - 2 * this.mat_margin);
  338. graphics.DrawEllipse(linePen, this.rectangleFLine.X + 2 * this.mat_margin, this.rectangleFLine.Y + 2 * this.mat_margin, this.rectangleFLine.Width - 4 * this.mat_margin, this.rectangleFLine.Height - 4 * this.mat_margin);
  339. Pen pen = new Pen(Color.FromArgb(this.lineColor), 1);
  340. pen.DashStyle = DashStyle.DashDotDot;
  341. //使用自定义线型
  342. float[] dashArray = {
  343. 2.0f, //线长2个像素
  344. 5.0f, //间断5个像素
  345. 2.0f, //线长2个像素
  346. 5.0f //间断5个像素
  347. };
  348. pen.DashPattern = dashArray;
  349. graphics.DrawRectangle(pen, new Rectangle((int)this.rectangleFLine.X, (int)this.rectangleFLine.Y, (int)this.rectangleFLine.Width, (int)this.rectangleFLine.Height));
  350. pen.Dispose();
  351. }
  352. /// <summary>
  353. /// 绘制辅助线(复合辅助线)
  354. /// </summary>
  355. public void DrawGuideLines5(Graphics graphics)
  356. {
  357. // 以下为绘制样式
  358. Pen linePen = new Pen(Color.FromArgb(this.lineColor), this.lineWidth);
  359. graphics.DrawLine(linePen,
  360. new PointF(this.rectangleFLine.X, this.rectangleFLine.Y + this.rectangleFLine.Height / 2 - this.mat_HLineToCDistance / 2 - this.mat_vLineLength / 2)
  361. , new PointF(this.rectangleFLine.X, this.rectangleFLine.Y + this.rectangleFLine.Height / 2 - this.mat_HLineToCDistance / 2 + this.mat_vLineLength / 2));
  362. graphics.DrawLine(linePen,
  363. new PointF(this.rectangleFLine.X + this.rectangleFLine.Width / 2 + this.mat_VLineToCDistance / 2 - this.mat_hLineLength / 2, this.rectangleFLine.Bottom)
  364. , new PointF(this.rectangleFLine.X + this.rectangleFLine.Width / 2 + this.mat_VLineToCDistance / 2 + this.mat_hLineLength / 2, this.rectangleFLine.Bottom));
  365. // 圆心
  366. Point center = new Point((int)(this.rectangleFLine.X + this.rectangleFLine.Width / 2 + this.mat_VLineToCDistance / 2), (int)(this.rectangleFLine.Y + this.rectangleFLine.Height / 2 - this.mat_HLineToCDistance / 2));
  367. double len = System.Math.Sqrt(((this.mat_ToprightLineLength / 2) * (this.mat_ToprightLineLength / 2)) / 2);
  368. // 左下到右上斜线
  369. Point a = new Point((int)center.X - (int)len, (int)center.Y + (int)len);
  370. Point b = new Point((int)center.X + (int)len, (int)center.Y - (int)len);
  371. graphics.DrawLine(linePen, a, b);
  372. len = System.Math.Sqrt(((this.mat_TopleftLineLength / 2) * (this.mat_TopleftLineLength / 2)) / 2);
  373. // 左上到右下斜线
  374. a = new Point((int)center.X - (int)len, (int)center.Y - (int)len);
  375. b = new Point((int)center.X + (int)len, (int)center.Y + (int)len);
  376. graphics.DrawLine(linePen, a, b);
  377. graphics.DrawEllipse(linePen, center.X - this.mat_diameter / 2, center.Y - this.mat_diameter / 2, this.mat_diameter, this.mat_diameter);
  378. graphics.DrawEllipse(linePen, center.X - this.mat_diameter / 2 - this.mat_margin, center.Y - this.mat_diameter / 2 - this.mat_margin, this.mat_diameter + 2 * this.mat_margin, this.mat_diameter + 2 * this.mat_margin);
  379. graphics.DrawEllipse(linePen, center.X - this.mat_diameter / 2 - 2 * this.mat_margin, center.Y - this.mat_diameter / 2 - 2 * this.mat_margin, this.mat_diameter + 4 * this.mat_margin, this.mat_diameter + 4 * this.mat_margin);
  380. Pen pen = new Pen(Color.FromArgb(this.lineColor), 1);
  381. pen.DashStyle = DashStyle.DashDotDot;
  382. //使用自定义线型
  383. float[] dashArray = {
  384. 2.0f, //线长2个像素
  385. 5.0f, //间断5个像素
  386. 2.0f, //线长2个像素
  387. 5.0f //间断5个像素
  388. };
  389. pen.DashPattern = dashArray;
  390. graphics.DrawRectangle(pen, new Rectangle((int)this.rectangleFLine.X, (int)this.rectangleFLine.Y, (int)this.rectangleFLine.Width, (int)this.rectangleFLine.Height));
  391. pen.Dispose();
  392. }
  393. /// <summary>
  394. /// 切换辅助线时控制缩放比例避免超出当前图片(垂直辅助线)
  395. /// </summary>
  396. /// <param name="multiple">放大倍数</param>
  397. /// <param name="physical_Micron">标尺</param>
  398. /// <param name="rGuideStyle">配置文件rGuideStyle</param>
  399. public void updateWithGuideModel1(double multiple, double physical_Micron, float recWidth)
  400. {
  401. if (recWidth == -1)
  402. {//###
  403. this.mat_lineLength = this.rectangleFLine.Height;
  404. this.lineLength = (int)(this.mat_lineLength * physical_Micron);
  405. this.mat_lineSpacing = (int)(this.rectangleFLine.Width / System.Math.Max(1, this.lineDec - 1));
  406. return;
  407. }
  408. this.lineLength = (int)(multiple * this.lineLength);
  409. this.mat_lineLength = (float)(this.lineLength / physical_Micron);
  410. this.originMat_lineSpacing = this.originLineSpacing / physical_Micron;
  411. this.mat_lineSpacing = (int)(multiple * recWidth / System.Math.Max(1, this.lineDec - 1));
  412. }
  413. /// <summary>
  414. /// 切换辅助线时控制缩放比例避免超出当前图片(水平辅助线)
  415. /// </summary>
  416. /// <param name="multiple">放大倍数</param>
  417. /// <param name="physical_Micron">标尺</param>
  418. /// <param name="rGuideStyle">配置文件rGuideStyle</param>
  419. public void updateWithGuideModel2(double multiple, double physical_Micron, float recHeight)
  420. {
  421. if (recHeight == -1)
  422. {//###
  423. this.mat_lineLength = this.rectangleFLine.Width;
  424. this.lineLength = (int)(this.mat_lineLength * physical_Micron);
  425. this.mat_lineSpacing = (int)(this.rectangleFLine.Height / System.Math.Max(1, this.lineDec - 1));
  426. return;
  427. }
  428. this.lineLength = (int)(multiple * this.lineLength);
  429. this.mat_lineLength = (float)(this.lineLength / physical_Micron);
  430. this.originMat_lineSpacing = this.originLineSpacing / physical_Micron;
  431. this.mat_lineSpacing = (int)(multiple * recHeight / System.Math.Max(1, this.lineDec - 1));
  432. }
  433. /// <summary>
  434. /// 切换辅助线时控制缩放比例避免超出当前图片(单圆辅助线)
  435. /// </summary>
  436. /// <param name="multiple">放大倍数</param>
  437. /// <param name="physical_Micron">标尺</param>
  438. /// <param name="rGuideStyle">配置文件rGuideStyle</param>
  439. public void updateWithGuideModel3(double multiple, double physical_Micron, bool moving = false)
  440. {
  441. if (moving)
  442. {
  443. this.diameter = multiple * this.originDiameter;
  444. this.mat_diameter = (int)(this.diameter / physical_Micron);
  445. return;
  446. }
  447. this.diameter = (double)(multiple * this.diameter);
  448. this.mat_diameter = (float)(this.diameter / physical_Micron);
  449. ////###
  450. //this.diameter = multiple * this.originDiameter;
  451. //this.mat_diameter = (int)(this.diameter / physical_Micron);
  452. }
  453. /// <summary>
  454. /// 切换辅助线时控制缩放比例避免超出当前图片(三圆辅助线)
  455. /// </summary>
  456. /// <param name="multiple">放大倍数</param>
  457. /// <param name="physical_Micron">标尺</param>
  458. /// <param name="rGuideStyle">配置文件rGuideStyle</param>
  459. public void updateWithGuideModel4(double multiple, double physical_Micron, bool moving = false)
  460. {
  461. if (moving)
  462. {
  463. this.diameter = multiple * this.originDiameter;
  464. this.mat_diameter = (int)(this.diameter / physical_Micron);
  465. this.margin = multiple * this.originMargin;
  466. this.mat_margin = (int)(this.margin / physical_Micron);
  467. return;
  468. }
  469. this.diameter = (double)(multiple * this.diameter);
  470. this.mat_diameter = (float)(this.diameter / physical_Micron);
  471. this.margin = (double)(multiple * this.margin);
  472. this.mat_margin = (float)(this.margin / physical_Micron);
  473. ////###
  474. //this.diameter = multiple * this.originDiameter;
  475. //this.mat_diameter = (int)(this.diameter / physical_Micron);
  476. //this.margin = multiple * this.originMargin;
  477. //this.mat_margin = (int)(this.margin / physical_Micron);
  478. }
  479. /// <summary>
  480. /// 切换辅助线时控制缩放比例避免超出当前图片(复合辅助线)
  481. /// </summary>
  482. /// <param name="multiple">放大倍数</param>
  483. /// <param name="physical_Micron">标尺</param>
  484. /// <param name="rGuideStyle">配置文件rGuideStyle</param>
  485. public void updateWithGuideModel5(double multiple, double physical_Micron, bool moving = false)
  486. {
  487. if (moving)
  488. {
  489. this.vLineLength = (int)(multiple * this.originVLineLength);
  490. this.mat_vLineLength = (int)(this.vLineLength / physical_Micron);
  491. this.hLineLength = (int)(multiple * this.originHLineLength);
  492. this.mat_hLineLength = (int)(this.hLineLength / physical_Micron);
  493. this.diameter = multiple * this.originDiameter;
  494. this.mat_diameter = (int)(this.diameter / physical_Micron);
  495. this.margin = multiple * this.originMargin;
  496. this.mat_margin = (int)(this.margin / physical_Micron);
  497. this.TopleftLineLength = (int)(multiple * this.originTopleftLineLength);
  498. this.mat_TopleftLineLength = (int)(this.TopleftLineLength / physical_Micron);
  499. this.ToprightLineLength = (int)(multiple * this.originToprightLineLength);
  500. this.mat_ToprightLineLength = (int)(this.ToprightLineLength / physical_Micron);
  501. this.VLineToCDistance = (int)(multiple * this.originVLineToCDistance);
  502. this.mat_VLineToCDistance = (int)(this.VLineToCDistance / physical_Micron);
  503. this.HLineToCDistance = (int)(multiple * this.originHLineToCDistance);
  504. this.mat_HLineToCDistance = (int)(this.HLineToCDistance / physical_Micron);
  505. return;
  506. }
  507. this.vLineLength = (int)(multiple * this.vLineLength);
  508. this.mat_vLineLength = (float)(this.vLineLength / physical_Micron);
  509. this.hLineLength = (int)(multiple * this.hLineLength);
  510. this.mat_hLineLength = (float)(this.hLineLength / physical_Micron);
  511. this.diameter = (double)(multiple * this.diameter);
  512. this.mat_diameter = (float)(this.diameter / physical_Micron);
  513. this.margin = (double)(multiple * this.margin);
  514. this.mat_margin = (float)(this.margin / physical_Micron);
  515. this.TopleftLineLength = (int)(multiple * this.TopleftLineLength);
  516. this.mat_TopleftLineLength = (float)(this.TopleftLineLength / physical_Micron);
  517. this.ToprightLineLength = (int)(multiple * this.ToprightLineLength);
  518. this.mat_ToprightLineLength = (float)(this.ToprightLineLength / physical_Micron);
  519. this.VLineToCDistance = (float)(multiple * this.VLineToCDistance);
  520. this.HLineToCDistance = (float)(multiple * this.HLineToCDistance);
  521. this.mat_VLineToCDistance = (float)(this.VLineToCDistance / physical_Micron);
  522. this.mat_HLineToCDistance = (float)(this.HLineToCDistance / physical_Micron);
  523. ////###
  524. //this.vLineLength = (int)(multiple * this.originVLineLength);
  525. //this.mat_vLineLength = (int)(this.vLineLength / physical_Micron);
  526. //this.hLineLength = (int)(multiple * this.originHLineLength);
  527. //this.mat_hLineLength = (int)(this.hLineLength / physical_Micron);
  528. //this.diameter = multiple * this.originDiameter;
  529. //this.mat_diameter = (int)(this.diameter / physical_Micron);
  530. //this.margin = multiple * this.originMargin;
  531. //this.mat_margin = (int)(this.margin / physical_Micron);
  532. //this.TopleftLineLength = (int)(multiple * this.originTopleftLineLength);
  533. //this.mat_TopleftLineLength = (int)(this.TopleftLineLength / physical_Micron);
  534. //this.ToprightLineLength = (int)(multiple * this.originToprightLineLength);
  535. //this.mat_ToprightLineLength = (int)(this.ToprightLineLength / physical_Micron);
  536. //this.VLineToCDistance = (int)(multiple * this.originVLineToCDistance);
  537. //this.mat_VLineToCDistance = (int)(this.VLineToCDistance / physical_Micron);
  538. //this.HLineToCDistance = (int)(multiple * this.originHLineToCDistance);
  539. //this.mat_HLineToCDistance = (int)(this.HLineToCDistance / physical_Micron);
  540. }
  541. /// <summary>
  542. /// 通过配置文件rGuideStyle给model赋值(垂直辅助线)
  543. /// </summary>
  544. /// <param name="multiple">放大倍数</param>
  545. /// <param name="physical_Micron">标尺</param>
  546. /// <param name="rGuideStyle">配置文件rGuideStyle</param>
  547. public void initWithGrainRGuideStyle1(double multiple, double physical_Micron, GrainSizeGuideStyleModel.VGuideStyle vGuideStyle)
  548. {
  549. this.originLineLength = 1/*multiple*/ * vGuideStyle.lineLength;
  550. this.lineLength = (int)(multiple * vGuideStyle.lineLength);
  551. this.mat_lineLength = (int)(multiple * vGuideStyle.lineLength / physical_Micron);
  552. this.originLineSpacing = 1/*multiple*/ * vGuideStyle.lineSpacing;
  553. this.originMat_lineSpacing = 1/*multiple*/ * vGuideStyle.lineSpacing / physical_Micron;
  554. this.mat_lineSpacing = (int)(multiple * vGuideStyle.lineSpacing / physical_Micron);
  555. this.lineDec = vGuideStyle.lineDec;
  556. this.lineColor = vGuideStyle.lineColor;
  557. this.lineWidth = vGuideStyle.lineWidth;
  558. }
  559. /// <summary>
  560. /// 通过配置文件rGuideStyle给model赋值(水平辅助线)
  561. /// </summary>
  562. /// <param name="multiple">放大倍数</param>
  563. /// <param name="physical_Micron">标尺</param>
  564. /// <param name="rGuideStyle">配置文件rGuideStyle</param>
  565. public void initWithGrainRGuideStyle2(double multiple, double physical_Micron, GrainSizeGuideStyleModel.HGuideStyle hGuideStyle)
  566. {
  567. this.originLineLength = 1/*multiple*/ * hGuideStyle.lineLength;
  568. this.lineLength = (int)(multiple * hGuideStyle.lineLength);
  569. this.mat_lineLength = (int)(multiple * hGuideStyle.lineLength / physical_Micron);
  570. this.originLineSpacing = 1/*multiple*/ * hGuideStyle.lineSpacing;
  571. this.originMat_lineSpacing = 1/*multiple*/ * hGuideStyle.lineSpacing / physical_Micron;
  572. this.mat_lineSpacing = (int)(multiple * hGuideStyle.lineSpacing / physical_Micron);
  573. this.lineDec = hGuideStyle.lineDec;
  574. this.lineColor = hGuideStyle.lineColor;
  575. this.lineWidth = hGuideStyle.lineWidth;
  576. }
  577. /// <summary>
  578. /// 通过配置文件rGuideStyle给model赋值(单圆辅助线)
  579. /// </summary>
  580. /// <param name="multiple">放大倍数</param>
  581. /// <param name="physical_Micron">标尺</param>
  582. /// <param name="rGuideStyle">配置文件rGuideStyle</param>
  583. public void initWithGrainRGuideStyle3(double multiple, double physical_Micron, GrainSizeGuideStyleModel.CGuideStyle cGuideStyle)
  584. {
  585. this.originDiameter = 1/*multiple*/ * cGuideStyle.diameter;
  586. this.diameter = multiple * cGuideStyle.diameter;
  587. this.mat_diameter = (int)(multiple * cGuideStyle.diameter / physical_Micron);
  588. this.lineColor = cGuideStyle.lineColor;
  589. this.lineWidth = cGuideStyle.lineWidth;
  590. }
  591. /// <summary>
  592. /// 通过配置文件rGuideStyle给model赋值(三圆辅助线)
  593. /// </summary>
  594. /// <param name="multiple">放大倍数</param>
  595. /// <param name="physical_Micron">标尺</param>
  596. /// <param name="rGuideStyle">配置文件rGuideStyle</param>
  597. public void initWithGrainRGuideStyle4(double multiple, double physical_Micron, GrainSizeGuideStyleModel.TCGuideStyle tCGuideStyle)
  598. {
  599. this.originDiameter = 1/*multiple*/ * tCGuideStyle.diameter;
  600. this.diameter = multiple * tCGuideStyle.diameter;
  601. this.mat_diameter = (int)(multiple * tCGuideStyle.diameter / physical_Micron);
  602. this.originMargin = 1/*multiple*/ * tCGuideStyle.margin;
  603. this.margin = multiple * tCGuideStyle.margin;
  604. this.mat_margin = (int)(multiple * tCGuideStyle.margin / physical_Micron);
  605. this.lineColor = tCGuideStyle.lineColor;
  606. this.lineWidth = tCGuideStyle.lineWidth;
  607. }
  608. /// <summary>
  609. /// 通过配置文件rGuideStyle给model赋值(复合辅助线)
  610. /// </summary>
  611. /// <param name="multiple">放大倍数</param>
  612. /// <param name="physical_Micron">标尺</param>
  613. /// <param name="rGuideStyle">配置文件rGuideStyle</param>
  614. public void initWithGrainRGuideStyle5(double multiple, double physical_Micron, GrainSizeGuideStyleModel.RGuideStyle rGuideStyle)
  615. {
  616. this.originVLineLength = 1/*multiple*/ * rGuideStyle.vLineLength;
  617. this.vLineLength = (int)(multiple * rGuideStyle.vLineLength);
  618. this.mat_vLineLength = (int)(multiple * rGuideStyle.vLineLength / physical_Micron);
  619. this.originHLineLength = 1/*multiple*/ * rGuideStyle.hLineLength;
  620. this.hLineLength = (int)(multiple * rGuideStyle.hLineLength);
  621. this.mat_hLineLength = (int)(multiple * rGuideStyle.hLineLength / physical_Micron);
  622. this.originDiameter = 1/*multiple*/ * rGuideStyle.diameter;
  623. this.diameter = multiple * rGuideStyle.diameter;
  624. this.mat_diameter = (int)(multiple * rGuideStyle.diameter / physical_Micron);
  625. this.originMargin = 1/*multiple*/ * rGuideStyle.margin;
  626. this.margin = multiple * rGuideStyle.margin;
  627. this.mat_margin = (int)(multiple * rGuideStyle.margin / physical_Micron);
  628. this.originTopleftLineLength = 1/*multiple*/ * rGuideStyle.TopleftLineLength;
  629. this.TopleftLineLength = (int)(multiple * rGuideStyle.TopleftLineLength);
  630. this.mat_TopleftLineLength = (int)(multiple * rGuideStyle.TopleftLineLength / physical_Micron);
  631. this.originToprightLineLength = 1/*multiple*/ * rGuideStyle.ToprightLineLength;
  632. this.ToprightLineLength = (int)(multiple * rGuideStyle.ToprightLineLength);
  633. this.mat_ToprightLineLength = (int)(multiple * rGuideStyle.ToprightLineLength / physical_Micron);
  634. this.originVLineToCDistance = 1/*multiple*/ * rGuideStyle.VLineToCDistance;
  635. this.VLineToCDistance = (int)(multiple * rGuideStyle.VLineToCDistance);
  636. this.mat_VLineToCDistance = (int)(multiple * rGuideStyle.VLineToCDistance / physical_Micron);
  637. this.originHLineToCDistance = 1/*multiple*/ * rGuideStyle.HLineToCDistance;
  638. this.HLineToCDistance = (int)(multiple * rGuideStyle.HLineToCDistance);
  639. this.mat_HLineToCDistance = (int)(multiple * rGuideStyle.HLineToCDistance / physical_Micron);
  640. this.lineColor = rGuideStyle.lineColor;
  641. this.lineWidth = rGuideStyle.lineWidth;
  642. }
  643. }
  644. }