CreateRectangle.cs 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. using System.Windows.Forms;
  6. namespace OTSMeasureApp
  7. {
  8. public abstract class ARectangleGDIObject
  9. {
  10. #region 共同属性
  11. /// <summary>
  12. /// 所有图形共同属性 尺寸(int类型)
  13. /// </summary>
  14. public abstract Rectangle Region { get; set; }
  15. /// <summary>
  16. /// 所有图形共同属性 尺寸(float类型)
  17. /// </summary>
  18. public abstract RectangleF RegionF { get; set; }
  19. /// <summary>
  20. /// 所有图形共同属性 绘制时与移动缩放时记录的位置与尺寸(float类型)
  21. /// </summary>
  22. public abstract RectangleF DrawRegionF { get; set; }
  23. /// <summary>
  24. /// 多边形点集合对象 位置(int类型)
  25. /// </summary>
  26. public abstract List<Point> PolygonPointRegion { get; set; }
  27. /// <summary>
  28. /// 多边形点集合对象 位置(float类型)
  29. /// </summary>
  30. public abstract List<PointF> PolygonPointRegionF { get; set; }
  31. /// <summary>
  32. /// 多边形点集合对象 绘制时与移动缩放时记录的位置(float类型)
  33. /// </summary>
  34. public abstract List<PointF> DrawPolygonPointRegionF { get; set; }
  35. /// <summary>
  36. /// 编号
  37. /// </summary>
  38. public abstract string ID { get; set; }
  39. /// <summary>
  40. /// 样品孔名称
  41. /// </summary>
  42. public abstract string Name { get; set; }
  43. /// <summary>
  44. /// 所有图形共同属性 是否拖动
  45. /// </summary>
  46. public abstract bool IsDragging { get; set; }
  47. /// <summary>
  48. /// 创建类型 记录生成的图形类型
  49. /// </summary>
  50. public abstract int CreateType { get; set; }
  51. //0:圆形 1:矩形
  52. public abstract int Shape { get; set; }
  53. /// <summary>
  54. /// 拖动到的位置
  55. /// </summary>
  56. public abstract Point DraggingPoint { get; set; }
  57. /// <summary>
  58. /// 绘制事件
  59. /// </summary>
  60. /// <param name="e"></param>
  61. public abstract void OnPaint(PaintEventArgs e);
  62. #endregion
  63. #region 样品台属性
  64. /// <summary>
  65. /// 记录样品台中的样品数量(样品台属性)
  66. /// </summary>
  67. public abstract int SampleCount { get; set; }
  68. /// <summary>
  69. /// 样品台中心与工作区域中心相差的位置
  70. /// </summary>
  71. public abstract PointF SampleCenterDifferCenterPoint { get; set; }
  72. #endregion
  73. #region 样品属性
  74. /// <summary>
  75. /// 样品名称
  76. /// </summary>
  77. public abstract string SampleName { get; set; }
  78. /// <summary>
  79. /// 是否选中 (测量区域与样品属性)
  80. /// </summary>
  81. public abstract bool IsSelect { get; set; }
  82. /// <summary>
  83. /// 是否为工作样品 (样品属性)
  84. /// </summary>
  85. public abstract bool IsWorkSample { get; set; }
  86. #endregion
  87. #region 测量区域属性
  88. /// <summary>
  89. /// 是否存在帧图 (测量区域属性)
  90. /// </summary>
  91. public abstract bool IsSingle { get; set; }
  92. /// <summary>
  93. /// 图形的路径 (圆角矩形、测量区域)
  94. /// </summary>
  95. public abstract GraphicsPath GPath { get; set; }
  96. #endregion
  97. #region 帧图属性
  98. /// <summary>
  99. /// 创建新图形时的颜色 (样品、帧图、标样)
  100. /// </summary>
  101. public abstract Color SelColor { get; set; }
  102. /// <summary>
  103. /// 绘制直线的开始位置 (帧图绘制直线)
  104. /// </summary>
  105. public abstract PointF StartPoint { get; set; }
  106. /// <summary>
  107. /// 绘制直线的开始位置 (帧图绘制直线)
  108. /// </summary>
  109. public abstract PointF EndPoint { get; set; }
  110. #endregion
  111. #region 颗粒属性
  112. /// <summary>
  113. /// 创建新图形时的颜色
  114. /// </summary>
  115. public abstract Color LineColor { get; set; }
  116. /// <summary>
  117. /// 创建颗粒直线长度
  118. /// </summary>
  119. public abstract float LineLength { get; set; }
  120. /// <summary>
  121. /// 创建颗粒直线长度
  122. /// </summary>
  123. public abstract PointF LineStartPoint { get; set; }
  124. /// <summary>
  125. /// SEM中心位置
  126. /// </summary>
  127. public abstract PointF SEMCenterPoint { get; set; }
  128. #endregion
  129. #region 测量区域
  130. /// <summary>
  131. /// OTS帧图X位置
  132. /// </summary>
  133. public abstract int OTSX { get; set; }
  134. /// <summary>
  135. /// OTS帧图Y位置
  136. /// </summary>
  137. public abstract int OTSY { get; set; }
  138. #endregion
  139. #region 绘制样品孔BSE图像
  140. public abstract Image BSEImage { get; set; }
  141. //绘制样品孔BSE图像宽度
  142. public abstract float BSEImageWitdh { get; set; }
  143. //绘制样品孔BSE图像高度
  144. public abstract float BSEImageHeight { get; set; }
  145. //绘制样品孔BSE图像位置
  146. public abstract PointF BSEImageLocation { get; set; }
  147. #endregion
  148. }
  149. public class CreateRectangle : ARectangleGDIObject // 同样的方式可以从ADraggableGDIObject生成其它图形的继承角类,比如矩形,三形等等。。
  150. {
  151. /// <summary>
  152. /// 创建图形
  153. /// </summary>
  154. /// <param name="startx">X位置</param>
  155. /// <param name="starty">Y位置</param>
  156. /// <param name="width">宽度</param>
  157. /// <param name="height">高度</param>
  158. /// <param name="cType">图形类型:createType=0 圆角矩形 createType=1 圆形 createType=2 文字</param>
  159. /// <param name="str">文字内容</param>
  160. public CreateRectangle(float startx, float starty, float width, float height, int cType, string str, string name)
  161. {
  162. m_Region = new Rectangle((int)startx, (int)starty, (int)width, (int)height);
  163. m_RegionF = new RectangleF(startx, starty, width, height);
  164. m_DrawRegionF = new RectangleF(startx, starty, width, height);
  165. CreateType = cType;
  166. strContent = str;
  167. Name = name;
  168. ID = System.Guid.NewGuid().ToString();
  169. OTSX = -1;
  170. OTSY = -1;
  171. }
  172. public CreateRectangle(RectangleF rect, int cType)
  173. {
  174. m_Region = new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height);
  175. m_RegionF = rect;
  176. m_DrawRegionF = rect;
  177. CreateType = cType;
  178. ID = System.Guid.NewGuid().ToString();
  179. startPoint = new PointF(rect.Left, rect.Top);
  180. EndPoint = new PointF(rect.Right, rect.Bottom);
  181. OTSX = -1;
  182. OTSY = -1;
  183. }
  184. public CreateRectangle(RectangleF rect, int cType, string name)
  185. {
  186. m_Region = new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height);
  187. m_RegionF = rect;
  188. m_DrawRegionF = rect;
  189. CreateType = cType;
  190. Name = name;
  191. ID = System.Guid.NewGuid().ToString();
  192. OTSX = -1;
  193. OTSY = -1;
  194. }
  195. public CreateRectangle(RectangleF rect, int cType, int shape, string name)
  196. {
  197. m_Region = new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height);
  198. m_RegionF = rect;
  199. m_DrawRegionF = rect;
  200. CreateType = cType;
  201. Name = name;
  202. Shape = shape;
  203. ID = System.Guid.NewGuid().ToString();
  204. OTSX = -1;
  205. OTSY = -1;
  206. }
  207. public CreateRectangle(RectangleF rect, int cType, int shape, string name, Color selColor)
  208. {
  209. m_Region = new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height);
  210. m_RegionF = rect;
  211. m_DrawRegionF = rect;
  212. CreateType = cType;
  213. Name = name;
  214. Shape = shape;
  215. SelColor = selColor;
  216. ID = System.Guid.NewGuid().ToString();
  217. OTSX = -1;
  218. OTSY = -1;
  219. }
  220. public CreateRectangle(RectangleF rectMeasure, PointF sampleCenterDifferPoint, int cType, int shape, string name, string sampleName, Color selColor)
  221. {
  222. m_Region = new Rectangle((int)rectMeasure.X, (int)rectMeasure.Y, (int)rectMeasure.Width, (int)rectMeasure.Height);
  223. m_RegionF = rectMeasure;
  224. m_DrawRegionF = rectMeasure;
  225. SampleCenterDifferCenterPoint = sampleCenterDifferPoint;
  226. CreateType = cType;
  227. Name = name;
  228. Shape = shape;
  229. SelColor = selColor;
  230. SampleName = sampleName;
  231. ID = System.Guid.NewGuid().ToString();
  232. OTSX = -1;
  233. OTSY = -1;
  234. }
  235. //绘制帧图
  236. public CreateRectangle(RectangleF rectSingle, int cType, string name, string sampleName, Color selColor)
  237. {
  238. m_Region = new Rectangle((int)rectSingle.X, (int)rectSingle.Y, (int)rectSingle.Width, (int)rectSingle.Height);
  239. m_RegionF = rectSingle;
  240. m_DrawRegionF = rectSingle;
  241. CreateType = cType;
  242. Name = name;
  243. Shape = 0;
  244. SelColor = selColor;
  245. SampleName = sampleName;
  246. ID = System.Guid.NewGuid().ToString();
  247. OTSX = -1;
  248. OTSY = -1;
  249. }
  250. //绘制帧图
  251. public CreateRectangle(RectangleF rectSingle, int OTSx, int OTSy, int cType, string name, string sampleName, Color selColor)
  252. {
  253. m_Region = new Rectangle((int)rectSingle.X, (int)rectSingle.Y, (int)rectSingle.Width, (int)rectSingle.Height);
  254. m_RegionF = rectSingle;
  255. m_DrawRegionF = rectSingle;
  256. CreateType = cType;
  257. Name = name;
  258. Shape = 0;
  259. SelColor = selColor;
  260. SampleName = sampleName;
  261. ID = System.Guid.NewGuid().ToString();
  262. OTSX = OTSx;
  263. OTSY = OTSy;
  264. }
  265. /// <summary>
  266. /// 绘制颗粒图
  267. /// </summary>
  268. /// <param name="lineStartPoint">绘制直线开始点</param>
  269. /// <param name="lineLength">直线的长度</param>
  270. /// <param name="cType">类型</param>
  271. /// <param name="lineColor">颜色</param>
  272. public CreateRectangle(PointF lineStartPoint, float lineLength, int cType, Color lineColor)
  273. {
  274. m_Region = new Rectangle((int)lineStartPoint.X, (int)lineStartPoint.Y, (int)lineLength, 1);
  275. m_RegionF = new RectangleF(lineStartPoint.X, lineStartPoint.Y, lineLength, 1);
  276. LineColor = lineColor;
  277. CreateType = cType;
  278. LineStartPoint = lineStartPoint;
  279. LineLength = lineLength;
  280. OTSX = -1;
  281. OTSY = -1;
  282. }
  283. /// <summary>
  284. /// 获取样品孔中BSE图像
  285. /// </summary>
  286. /// <param name="rect">位置大小</param>
  287. /// <param name="sampleHoleName">所在样品孔名称</param>
  288. /// <param name="bseImage">图像信息</param>
  289. /// <param name="bseImageWitdh">图像宽度</param>
  290. /// <param name="bseImageHeight">图像高度</param>
  291. /// <param name="drawImageLocation">图像开始位置</param>
  292. /// <param name="cType">绘制类型</param>
  293. public CreateRectangle(RectangleF rect, int OTSx, int OTSy, string sampleName, string sampleHoleName, Image bseImage, float bseImageWitdh, float bseImageHeight, Point drawImageLocation, int cType)
  294. {
  295. m_Region = new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height);
  296. m_RegionF = rect;
  297. m_DrawRegionF = rect;
  298. Name = sampleHoleName;
  299. SampleName = sampleName;
  300. //生成编号
  301. ID = System.Guid.NewGuid().ToString();
  302. //图像信息
  303. BSEImage = bseImage;
  304. //图像宽度
  305. BSEImageWitdh = bseImageWitdh;
  306. //图像高度
  307. BSEImageHeight = bseImageHeight;
  308. //图像位置
  309. BSEImageLocation = rect.Location;
  310. OTSX = OTSx;
  311. OTSY = OTSy;
  312. //绘制类型
  313. CreateType = cType;
  314. }
  315. /// <summary>
  316. /// 获取SEM中心位置
  317. /// </summary>
  318. /// <param name="semCPoint"></param>
  319. /// <param name="cType"></param>
  320. public CreateRectangle(PointF semCPoint, int cType)
  321. {
  322. CreateType = cType;
  323. ID = System.Guid.NewGuid().ToString();
  324. semCenterPoint = semCPoint;
  325. }
  326. public CreateRectangle(RectangleF rect, Point ImgPoint, float m_Multiple, int cType)
  327. {
  328. m_Region = new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height);
  329. m_RegionF.X = m_Region.X - ImgPoint.X * m_Multiple;
  330. m_RegionF.Y = m_Region.Y - ImgPoint.Y * m_Multiple;
  331. m_DrawRegionF = m_Region;
  332. CreateType = cType;
  333. ID = System.Guid.NewGuid().ToString();
  334. startPoint = new PointF(m_Region.Left, m_Region.Top);
  335. EndPoint = new PointF(m_Region.Right, m_Region.Bottom);
  336. OTSX = -1;
  337. OTSY = -1;
  338. }
  339. /// <summary>
  340. /// 获取多边形点集合
  341. /// </summary>
  342. /// <param name="mPoint"></param>
  343. /// <param name="cType"></param>
  344. public CreateRectangle(List<PointF> mPoint, int cType, int shape, string name, string sampleName, Color selColor)
  345. {
  346. ID = System.Guid.NewGuid().ToString();
  347. List<Point> PointRegion = new List<Point>();
  348. foreach (var item in mPoint)
  349. {
  350. PointRegion.Add(new Point((int)item.X, (int)item.Y));
  351. }
  352. PolygonPointRegion = PointRegion;
  353. PolygonPointRegionF = mPoint;
  354. List<PointF> DrawPoint = new List<PointF>();
  355. foreach (var item in mPoint)
  356. {
  357. DrawPoint.Add(item);
  358. }
  359. DrawPolygonPointRegionF = DrawPoint;
  360. Name = name;
  361. SampleName = sampleName;
  362. CreateType = cType;
  363. Shape = cType;
  364. SelColor = selColor;
  365. }
  366. #region 变量重写
  367. public override Image BSEImage
  368. {
  369. get { return bseImage; }
  370. set { bseImage = value; }
  371. }
  372. public override float BSEImageWitdh
  373. {
  374. get { return bseImageWidth; }
  375. set { bseImageWidth = value; }
  376. }
  377. public override float BSEImageHeight
  378. {
  379. get { return bseImageHeight; }
  380. set { bseImageHeight = value; }
  381. }
  382. public override PointF BSEImageLocation
  383. {
  384. get { return bseImageLocation; }
  385. set { bseImageLocation = value; }
  386. }
  387. public override Color LineColor
  388. {
  389. get { return lineColor; }
  390. set { lineColor = value; }
  391. }
  392. public override float LineLength
  393. {
  394. get { return lineLength; }
  395. set { lineLength = value; }
  396. }
  397. public override PointF LineStartPoint
  398. {
  399. get { return lineStartPoint; }
  400. set { lineStartPoint = value; }
  401. }
  402. public override PointF SEMCenterPoint
  403. {
  404. get { return semCenterPoint; }
  405. set { semCenterPoint = value; }
  406. }
  407. public override int OTSX
  408. {
  409. get { return otsX; }
  410. set { otsX = value; }
  411. }
  412. public override int OTSY
  413. {
  414. get { return otsY; }
  415. set { otsY = value; }
  416. }
  417. public override int CreateType
  418. {
  419. get { return createType; }
  420. set { createType = value; }
  421. }
  422. public override int Shape
  423. {
  424. get { return shape; }
  425. set { shape = value; }
  426. }
  427. public override Color SelColor
  428. {
  429. get { return selColor; }
  430. set { selColor = value; }
  431. }
  432. public override string Name
  433. {
  434. get { return name; }
  435. set { name = value; }
  436. }
  437. public override string ID
  438. {
  439. get { return id; }
  440. set { id = value; }
  441. }
  442. public override string SampleName
  443. {
  444. get { return sampleName; }
  445. set { sampleName = value; }
  446. }
  447. public override int SampleCount
  448. {
  449. get { return sampleCount; }
  450. set { sampleCount = value; }
  451. }
  452. public string StrContent
  453. {
  454. get { return strContent; }
  455. set { strContent = value; }
  456. }
  457. public override Rectangle Region
  458. {
  459. get { return m_Region; }
  460. set { m_Region = value; }
  461. }
  462. public override RectangleF RegionF
  463. {
  464. get { return m_RegionF; }
  465. set { m_RegionF = value; }
  466. }
  467. public override RectangleF DrawRegionF
  468. {
  469. get { return m_DrawRegionF; }
  470. set { m_DrawRegionF = value; }
  471. }
  472. public override List<Point> PolygonPointRegion
  473. {
  474. get { return m_PolygonPointRegion; }
  475. set { m_PolygonPointRegion = value; }
  476. }
  477. public override List<PointF> PolygonPointRegionF
  478. {
  479. get { return m_PolygonPointRegionF; }
  480. set { m_PolygonPointRegionF = value; }
  481. }
  482. public override List<PointF> DrawPolygonPointRegionF
  483. {
  484. get { return m_DrawPolygonPointRegionF; }
  485. set { m_DrawPolygonPointRegionF = value; }
  486. }
  487. public override GraphicsPath GPath
  488. {
  489. get { return g_Path; }
  490. set { g_Path = value; }
  491. }
  492. public override PointF StartPoint
  493. {
  494. get { return startPoint; }
  495. set { startPoint = value; }
  496. }
  497. public override PointF EndPoint
  498. {
  499. get { return endPoint; }
  500. set { endPoint = value; }
  501. }
  502. public override PointF SampleCenterDifferCenterPoint
  503. {
  504. get { return sampleCenterDifferCenterPoint; }
  505. set { sampleCenterDifferCenterPoint = value; }
  506. }
  507. #endregion
  508. public override void OnPaint(PaintEventArgs e)
  509. {
  510. //createType=0 圆角矩形 createType=1 圆形 createType=2 文字
  511. if (createType == (int)CreateRectangleType.SampleBackGround_Rectangle)
  512. {
  513. //获取颜色
  514. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.RoundRectangleColor);
  515. Color myColor = ColorTranslator.FromHtml(ColorStr);
  516. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  517. GraphicsPath grPath = CreateRoundedRectanglePath(m_Region, 20);
  518. e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
  519. e.Graphics.FillPath(sampleBrush, grPath);
  520. e.Graphics.DrawPath(Pens.Black, grPath);
  521. }
  522. //样品台-圆形
  523. else if (createType == (int)CreateRectangleType.SampleBackGround_Circle)
  524. {
  525. //获取颜色
  526. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleBackGroundColor);
  527. Color myColor = ColorTranslator.FromHtml(ColorStr);
  528. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  529. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  530. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  531. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  532. e.Graphics.FillEllipse(sampleBrush, m_Region);
  533. e.Graphics.DrawEllipse(Pens.Black, m_Region);
  534. }
  535. //圆形
  536. else if (createType == (int)CreateRectangleType.Circle)
  537. {
  538. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White);
  539. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  540. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  541. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  542. e.Graphics.FillEllipse(sampleBrush, m_Region);
  543. e.Graphics.DrawEllipse(Pens.Black, m_Region);
  544. }
  545. //文字
  546. else if (createType == (int)CreateRectangleType.Font)
  547. {
  548. //设置文字对齐方式
  549. StringFormat sf = new StringFormat();
  550. sf.Alignment = StringAlignment.Center;
  551. sf.LineAlignment = StringAlignment.Center;
  552. //文字颜色
  553. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.FontColor);
  554. Color myColor = ColorTranslator.FromHtml(ColorStr);
  555. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  556. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(50, Color.Black));
  557. //字体大小 根据样品孔Rectangle大小
  558. float fontSize = m_Region.Width / 4;
  559. Font font = new Font("宋体", fontSize, FontStyle.Regular);
  560. if (fontSize == 0)
  561. {
  562. font = new Font("宋体", fontSize, FontStyle.Regular);
  563. }
  564. //消除锯齿
  565. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  566. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  567. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  568. //绘制文字阴影
  569. Rectangle rectFont = m_Region;
  570. rectFont.X += 2;
  571. rectFont.Y += 2;
  572. e.Graphics.DrawString(strContent, font, solidBrush, rectFont, sf);
  573. e.Graphics.DrawString(strContent, font, sampleBrush, m_Region, sf);
  574. }
  575. //矩形
  576. else if (createType == (int)CreateRectangleType.Rectangle)
  577. {
  578. Color myColor = System.Drawing.Color.White;
  579. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  580. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  581. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  582. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  583. e.Graphics.FillRectangle(sampleBrush, m_Region);
  584. e.Graphics.DrawRectangle(Pens.Black, m_Region);
  585. }
  586. //选择样品台
  587. else if (createType == (int)CreateRectangleType.SelectSample)
  588. {
  589. Color myColor = selColor;
  590. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  591. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  592. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  593. e.Graphics.CompositingQuality = CompositingQuality.AssumeLinear;//再加一点
  594. if (Shape == 0)
  595. {
  596. e.Graphics.FillEllipse(sampleBrush, m_Region);
  597. e.Graphics.DrawEllipse(Pens.Black, m_Region);
  598. }
  599. else
  600. {
  601. e.Graphics.FillRectangle(sampleBrush, m_Region);
  602. e.Graphics.DrawRectangle(Pens.Black, m_Region);
  603. }
  604. }
  605. //测试区域
  606. else if (createType == (int)CreateRectangleType.MeasureArea)
  607. {
  608. Color myColor = selColor;
  609. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  610. Pen p = new Pen(myColor, 1);
  611. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  612. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  613. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  614. GraphicsPath MeasureAreaPath = new GraphicsPath();
  615. if (Shape == 0)
  616. {
  617. MeasureAreaPath.AddEllipse(m_RegionF);
  618. e.Graphics.DrawEllipse(p, m_Region);
  619. }
  620. else
  621. {
  622. MeasureAreaPath.AddRectangle(m_RegionF);
  623. e.Graphics.DrawRectangle(p, m_Region.X, m_Region.Y, m_Region.Width, m_Region.Height);
  624. }
  625. }
  626. //绘制帧图 直线
  627. else if (createType == (int)CreateRectangleType.SingleLine)
  628. {
  629. //设置颜色
  630. string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SingleColor);
  631. Color myColor = ColorTranslator.FromHtml(ColorStr);
  632. //设置画笔
  633. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  634. Pen pen = new Pen(sampleBrush, 0.0001f);
  635. //未抗锯齿
  636. e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
  637. e.Graphics.InterpolationMode = InterpolationMode.Default;
  638. e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
  639. //设置直线位置与尺寸
  640. PointF startPointF = new PointF(startPoint.X, startPoint.Y);
  641. PointF endPointF = new PointF(endPoint.X, endPoint.Y);
  642. //度量单位
  643. e.Graphics.PageUnit = GraphicsUnit.Display;
  644. e.Graphics.DrawLine(pen, startPointF, endPointF);
  645. }
  646. //绘制标样
  647. else if (createType == (int)CreateRectangleType.SpecimenRectangle)
  648. {
  649. Color myColor = System.Drawing.Color.Black;
  650. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  651. Pen pen = new Pen(sampleBrush, 0.0001f);
  652. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
  653. e.Graphics.DrawRectangle(pen, m_Region);
  654. e.Graphics.FillRectangle(sampleBrush, m_Region);
  655. }
  656. //绘制标样
  657. else if (createType == (int)CreateRectangleType.SpecimenCircle)
  658. {
  659. Color myColor = System.Drawing.Color.Black;
  660. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  661. Pen pen = new Pen(sampleBrush, 0.0001f);
  662. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
  663. e.Graphics.DrawEllipse(pen, m_Region);
  664. e.Graphics.FillEllipse(sampleBrush, m_Region);
  665. }
  666. //绘制帧图
  667. else if (createType == (int)CreateRectangleType.SingleRectangle)
  668. {
  669. Color myColor = SelColor;
  670. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  671. Pen pen = new Pen(sampleBrush, 0.01f);
  672. e.Graphics.SmoothingMode = SmoothingMode.Default;
  673. //设置直线位置与尺寸
  674. PointF startPointF = new PointF(m_RegionF.Left, m_RegionF.Top);
  675. PointF endPointF = new PointF(m_RegionF.Right, m_RegionF.Bottom);
  676. //绘制帧图
  677. e.Graphics.DrawRectangle(pen, startPointF.X, startPointF.Y, endPointF.X - startPointF.X, endPointF.Y - startPointF.Y);
  678. }
  679. //绘制颗粒
  680. else if (createType == (int)CreateRectangleType.ParticleLine)
  681. {
  682. Color myColor = LineColor;
  683. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  684. Pen pen = new Pen(sampleBrush, 0.01f);
  685. e.Graphics.SmoothingMode = SmoothingMode.Default;
  686. //设置直线位置与长度
  687. PointF startPointF = LineStartPoint;
  688. float length = LineLength;
  689. PointF endPointF = new PointF(startPointF.X + length, startPointF.Y);
  690. e.Graphics.DrawLine(pen, startPointF, endPointF);
  691. }
  692. //矩形
  693. else if (createType == (int)CreateRectangleType.ParticleAreaRectangle)
  694. {
  695. Color myColor = System.Drawing.Color.White;
  696. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  697. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  698. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  699. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  700. e.Graphics.DrawRectangle(Pens.Black, m_Region);
  701. }
  702. //绘制样品孔BSE图像
  703. else if (createType == (int)CreateRectangleType.DrawSampleHoleBSEImage)
  704. {
  705. Color myColor = System.Drawing.Color.White;
  706. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  707. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  708. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  709. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  710. //设置直线位置与尺寸
  711. PointF startPointF = new PointF(m_RegionF.Left, m_RegionF.Top);
  712. PointF endPointF = new PointF(m_RegionF.Right + 2, m_RegionF.Bottom + 2);
  713. //绘制样品孔中图像信息
  714. if (BSEImage != null)
  715. {
  716. e.Graphics.DrawImage(BSEImage, startPointF.X, startPointF.Y, endPointF.X - startPointF.X, endPointF.Y - startPointF.Y);
  717. }
  718. }
  719. else if (createType == (int)CreateRectangleType.DrawSEMCenterPoint)
  720. {
  721. Color myColor = System.Drawing.Color.Red;
  722. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  723. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  724. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  725. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  726. //X轴线
  727. PointF startPointX = semCenterPoint;
  728. startPointX.X = startPointX.X - 3;
  729. PointF endPointX = semCenterPoint;
  730. endPointX.X = endPointX.X + 3;
  731. //Y轴线
  732. PointF startPointY = semCenterPoint;
  733. startPointY.Y = startPointY.Y - 3;
  734. PointF endPointY = semCenterPoint;
  735. endPointY.Y = endPointY.Y + 3;
  736. //绘制XY轴交叉线+
  737. Pen pen = new Pen(sampleBrush, 0.0001f);
  738. e.Graphics.DrawLine(pen, startPointX, endPointX);
  739. e.Graphics.DrawLine(pen, startPointY, endPointY);
  740. }
  741. //绘制BSE标记
  742. else if (createType == (int)CreateRectangleType.DrawBSEElementSignPoint)
  743. {
  744. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Green);
  745. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  746. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  747. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  748. Pen pen = new Pen(sampleBrush, 2f);
  749. int X = (int)m_DrawRegionF.X;
  750. int Y = (int)m_DrawRegionF.Y;
  751. e.Graphics.DrawLine(pen, new Point(X-8,Y), new Point(X+8, Y));
  752. e.Graphics.DrawLine(pen, new Point(X, Y-8), new Point(X, Y+8));
  753. }
  754. //绘制多边形测量区域
  755. else if (createType == (int)CreateRectangleType.Polygon)
  756. {
  757. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  758. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  759. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  760. Color myColor = selColor;
  761. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  762. Pen pen = new Pen(myColor, 1);
  763. if (PolygonPointRegionF.Count > 0)
  764. {
  765. List<PointF> PolygonPointF = new List<PointF>();
  766. foreach (var item in PolygonPointRegionF)
  767. {
  768. PolygonPointF.Add(item);
  769. }
  770. if (EndPoint.X != 0 && EndPoint.Y != 0)
  771. {
  772. PolygonPointF.Add(EndPoint);
  773. }
  774. try
  775. {
  776. e.Graphics.DrawLines(pen, PolygonPointF.ToArray());
  777. //多边形的外接矩形
  778. //if (Region != null)
  779. //{
  780. // e.Graphics.DrawRectangle(new Pen(Color.Green), Region);
  781. //}
  782. }
  783. catch (Exception)
  784. {
  785. }
  786. }
  787. }//多边形测量区域完成标识
  788. else if (createType == (int)CreateRectangleType.DrawPolygonFinish)
  789. {
  790. Color myColor = selColor;
  791. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  792. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  793. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  794. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  795. Pen pen = new Pen(myColor, 1);
  796. e.Graphics.DrawRectangle(pen, m_Region);
  797. }
  798. }
  799. public override bool IsDragging
  800. {
  801. get { return m_IsDragging; }
  802. set { m_IsDragging = value; }
  803. }
  804. public override bool IsSelect
  805. {
  806. get { return m_IsSelect; }
  807. set { m_IsSelect = value; }
  808. }
  809. public override bool IsSingle
  810. {
  811. get { return m_IsSingle; }
  812. set { m_IsSingle = value; }
  813. }
  814. public override bool IsWorkSample
  815. {
  816. get { return m_IsWorkSample; }
  817. set { m_IsWorkSample = value; }
  818. }
  819. public override Point DraggingPoint
  820. {
  821. get { return m_DraggingPoint; }
  822. set { m_DraggingPoint = value; }
  823. }
  824. #region 画圆角矩形
  825. internal static GraphicsPath CreateRoundedRectanglePath(Rectangle rect, int cornerRadius)
  826. {
  827. GraphicsPath roundedRect = new GraphicsPath();
  828. roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
  829. roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
  830. roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
  831. roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
  832. roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
  833. roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
  834. roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
  835. roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
  836. roundedRect.CloseFigure();
  837. return roundedRect;
  838. }
  839. #endregion
  840. //是否设置为选择样品
  841. private bool m_IsSelect;
  842. //是否存在帧图信息
  843. private bool m_IsSingle;
  844. //是否设置为拖动
  845. private bool m_IsDragging;
  846. //是否为工作样品
  847. private bool m_IsWorkSample;
  848. private int createType;
  849. private int shape;
  850. private string id;
  851. private string name;
  852. public string sampleName;
  853. //样品孔中样品的数量
  854. public int sampleCount = 0;
  855. public string strContent;
  856. private Color selColor;
  857. private Point m_DraggingPoint;
  858. private Rectangle m_Region;
  859. private RectangleF m_RegionF;
  860. //绘制时与移动缩放时记录的位置与尺寸
  861. private RectangleF m_DrawRegionF;
  862. private GraphicsPath g_Path;
  863. private PointF startPoint;
  864. private PointF endPoint;
  865. private PointF sampleCenterDifferCenterPoint;
  866. //绘制颗粒图
  867. private Color lineColor;
  868. private float lineLength;
  869. private PointF lineStartPoint;
  870. private int otsX;
  871. private int otsY;
  872. //绘制样品孔BSE图像
  873. private Image bseImage;
  874. //绘制样品孔BSE图像宽度
  875. private float bseImageWidth;
  876. //绘制样品孔BSE图像高度
  877. private float bseImageHeight;
  878. //绘制样品孔BSE图像位置
  879. private PointF bseImageLocation;
  880. //绘制SEM中心位置
  881. private PointF semCenterPoint;
  882. //
  883. private List<Point> m_PolygonPointRegion;
  884. private List<PointF> m_PolygonPointRegionF;
  885. //绘制时与移动缩放时记录的位置
  886. private List<PointF> m_DrawPolygonPointRegionF;
  887. }
  888. public enum SEMControlIndex
  889. {
  890. Magnification=0,
  891. WorkingDistance=1
  892. }
  893. public enum XYIndex
  894. {
  895. X = 0,
  896. Y = 1
  897. }
  898. //public enum IndexNum
  899. //{
  900. // First = 0,
  901. // Second = 1
  902. //}
  903. public enum CreateRectangleType
  904. {
  905. //样品台-圆形
  906. SampleBackGround_Circle = -1,
  907. //圆形
  908. Circle = 0,
  909. //圆角矩形
  910. SampleBackGround_Rectangle = 1,
  911. //样品孔中的文字
  912. Font = 2,
  913. //矩形
  914. Rectangle = 3,
  915. //选择的样品
  916. SelectSample = 4,
  917. //测量区域
  918. MeasureArea = 5,
  919. //帧图-直线绘制方式
  920. SingleLine = 6,
  921. //表样-矩形
  922. SpecimenRectangle = 7,
  923. //表样-圆形
  924. SpecimenCircle = 8,
  925. //帧图-矩形绘制
  926. SingleRectangle = 9,
  927. //颗粒直线图
  928. ParticleLine = 10,
  929. //颗粒分布图 鼠标
  930. ParticleAreaRectangle = 11,
  931. //绘制拍摄样品孔BSE照片
  932. DrawSampleHoleBSEImage = 12,
  933. //绘制sem中心点+
  934. DrawSEMCenterPoint=13,
  935. //绘制BSE采集标记
  936. DrawBSEElementSignPoint = 14,
  937. //多边形
  938. Polygon = 15,
  939. //多边形完成标识
  940. DrawPolygonFinish = 16
  941. }
  942. public enum ContextMenuType
  943. {
  944. //样品孔右键菜单
  945. SampleHoleMenu = 0,
  946. //样品右键菜单
  947. SampleMenu = 1,
  948. //测量区域右键菜单
  949. MeasureMenu = 2,
  950. //线程运行后菜单
  951. ThreadRunMenu = 3,
  952. //样品台右键菜单
  953. SampleStateMenu = 4,
  954. //样品孔BSE图像
  955. SampleHoleBSEImage = 5,
  956. //帧图菜单
  957. SingleMenu = 6
  958. }
  959. public enum MeasureStateMenuType
  960. {
  961. //获取BSE图
  962. SampleParaLock = 0,
  963. //设置可视化灰度
  964. SetVisualGray = 1,
  965. //显示BSE灰度曲线图
  966. grayToolStripMenuItem = 2,
  967. //切换至BSE图
  968. ChangeDiffImageShow = 4,
  969. //BSE去背景图
  970. DelBSEBG = 5,
  971. //显示BSE去背景灰度曲线图
  972. SampleHoleBSEImage = 6,
  973. //线扫描曲线
  974. MenuItemLineScam = 8,
  975. //单点采集Xray与元素信息
  976. PointScanElementMenuItem = 9,
  977. //导出采集信息报告
  978. ExportReport =10
  979. }
  980. //public enum photoMode
  981. //{
  982. // measureMode=0,
  983. // sampleHoleMode=1
  984. //}
  985. public enum MenuIndex
  986. {
  987. AddSample = 0,
  988. DeleteSample = 1,
  989. SampleStripSeparator = 2,
  990. ReadSEMData = 3,
  991. SetSemData = 4,
  992. SetSEMCenterLocation = 5,
  993. DriveSEMToCenterLocation = 6,
  994. DriveSEMToCurrentLocation = 7,
  995. SEMStripSeparator = 8,
  996. ShootBSEPicture = 9,
  997. DeleteBSEPicture = 10
  998. }
  999. public enum ColorType
  1000. {
  1001. SingleColor,//帧图fd8f8f
  1002. RoundRectangleColor,//c8c8c8圆角矩形
  1003. SampleBackGroundColor,//c0c0c0圆角矩形
  1004. FontColor,//90ee90文字颜色
  1005. SampleColor,//f4f4f4 样品未选择
  1006. SampleSelColor//505050 样品选择后
  1007. }
  1008. public enum GrayLevel
  1009. {
  1010. Min=0,
  1011. Max=255
  1012. }
  1013. }