CreateRectangle.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  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. else if (createType == (int)CreateRectangleType.CircleByThreePoints)
  800. {
  801. Color myColor = selColor;
  802. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  803. Pen p = new Pen(myColor, 1);
  804. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  805. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  806. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  807. GraphicsPath MeasureAreaPath = new GraphicsPath();
  808. MeasureAreaPath.AddEllipse(m_RegionF);
  809. e.Graphics.DrawEllipse(p, m_Region);
  810. }
  811. }
  812. public override bool IsDragging
  813. {
  814. get { return m_IsDragging; }
  815. set { m_IsDragging = value; }
  816. }
  817. public override bool IsSelect
  818. {
  819. get { return m_IsSelect; }
  820. set { m_IsSelect = value; }
  821. }
  822. public override bool IsSingle
  823. {
  824. get { return m_IsSingle; }
  825. set { m_IsSingle = value; }
  826. }
  827. public override bool IsWorkSample
  828. {
  829. get { return m_IsWorkSample; }
  830. set { m_IsWorkSample = value; }
  831. }
  832. public override Point DraggingPoint
  833. {
  834. get { return m_DraggingPoint; }
  835. set { m_DraggingPoint = value; }
  836. }
  837. #region 画圆角矩形
  838. internal static GraphicsPath CreateRoundedRectanglePath(Rectangle rect, int cornerRadius)
  839. {
  840. GraphicsPath roundedRect = new GraphicsPath();
  841. roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
  842. roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
  843. roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
  844. roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
  845. roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
  846. roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
  847. roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
  848. roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
  849. roundedRect.CloseFigure();
  850. return roundedRect;
  851. }
  852. #endregion
  853. //是否设置为选择样品
  854. private bool m_IsSelect;
  855. //是否存在帧图信息
  856. private bool m_IsSingle;
  857. //是否设置为拖动
  858. private bool m_IsDragging;
  859. //是否为工作样品
  860. private bool m_IsWorkSample;
  861. private int createType;
  862. private int shape;
  863. private string id;
  864. private string name;
  865. public string sampleName;
  866. //样品孔中样品的数量
  867. public int sampleCount = 0;
  868. public string strContent;
  869. private Color selColor;
  870. private Point m_DraggingPoint;
  871. private Rectangle m_Region;
  872. private RectangleF m_RegionF;
  873. //绘制时与移动缩放时记录的位置与尺寸
  874. private RectangleF m_DrawRegionF;
  875. private GraphicsPath g_Path;
  876. private PointF startPoint;
  877. private PointF endPoint;
  878. private PointF sampleCenterDifferCenterPoint;
  879. //绘制颗粒图
  880. private Color lineColor;
  881. private float lineLength;
  882. private PointF lineStartPoint;
  883. private int otsX;
  884. private int otsY;
  885. //绘制样品孔BSE图像
  886. private Image bseImage;
  887. //绘制样品孔BSE图像宽度
  888. private float bseImageWidth;
  889. //绘制样品孔BSE图像高度
  890. private float bseImageHeight;
  891. //绘制样品孔BSE图像位置
  892. private PointF bseImageLocation;
  893. //绘制SEM中心位置
  894. private PointF semCenterPoint;
  895. //
  896. private List<Point> m_PolygonPointRegion;
  897. private List<PointF> m_PolygonPointRegionF;
  898. //绘制时与移动缩放时记录的位置
  899. private List<PointF> m_DrawPolygonPointRegionF;
  900. }
  901. public enum SEMControlIndex
  902. {
  903. Magnification=0,
  904. WorkingDistance=1
  905. }
  906. public enum XYIndex
  907. {
  908. X = 0,
  909. Y = 1
  910. }
  911. //public enum IndexNum
  912. //{
  913. // First = 0,
  914. // Second = 1
  915. //}
  916. public enum CreateRectangleType
  917. {
  918. //样品台-圆形
  919. SampleBackGround_Circle = -1,
  920. //圆形
  921. Circle = 0,
  922. //圆角矩形
  923. SampleBackGround_Rectangle = 1,
  924. //样品孔中的文字
  925. Font = 2,
  926. //矩形
  927. Rectangle = 3,
  928. //选择的样品
  929. SelectSample = 4,
  930. //测量区域
  931. MeasureArea = 5,
  932. //帧图-直线绘制方式
  933. SingleLine = 6,
  934. //表样-矩形
  935. SpecimenRectangle = 7,
  936. //表样-圆形
  937. SpecimenCircle = 8,
  938. //帧图-矩形绘制
  939. SingleRectangle = 9,
  940. //颗粒直线图
  941. ParticleLine = 10,
  942. //颗粒分布图 鼠标
  943. ParticleAreaRectangle = 11,
  944. //绘制拍摄样品孔BSE照片
  945. DrawSampleHoleBSEImage = 12,
  946. //绘制sem中心点+
  947. DrawSEMCenterPoint=13,
  948. //绘制BSE采集标记
  949. DrawBSEElementSignPoint = 14,
  950. //多边形
  951. Polygon = 15,
  952. //多边形完成标识
  953. DrawPolygonFinish = 16,
  954. //圆形三点法
  955. CircleByThreePoints=17
  956. }
  957. public enum ContextMenuType
  958. {
  959. //样品孔右键菜单
  960. SampleHoleMenu = 0,
  961. //样品右键菜单
  962. SampleMenu = 1,
  963. //测量区域右键菜单
  964. MeasureMenu = 2,
  965. //线程运行后菜单
  966. ThreadRunMenu = 3,
  967. //样品台右键菜单
  968. SampleStateMenu = 4,
  969. //样品孔BSE图像
  970. SampleHoleBSEImage = 5,
  971. //帧图菜单
  972. SingleMenu = 6
  973. }
  974. public enum MeasureStateMenuType
  975. {
  976. //获取BSE图
  977. SampleParaLock = 0,
  978. //设置可视化灰度
  979. SetVisualGray = 1,
  980. //显示BSE灰度曲线图
  981. SetVisualGrayForSpecialGray=2,
  982. grayToolStripMenuItem =4,
  983. //切换至BSE图
  984. ChangeDiffImageShow = 5,
  985. //BSE去背景图
  986. DelBSEBG =6,
  987. //显示BSE去背景灰度曲线图
  988. SampleHoleBSEImage = 7,
  989. //线扫描曲线
  990. MenuItemLineScam = 9,
  991. //单点采集Xray与元素信息
  992. PointScanElementMenuItem = 10,
  993. //导出采集信息报告
  994. ExportReport =11
  995. }
  996. //public enum photoMode
  997. //{
  998. // measureMode=0,
  999. // sampleHoleMode=1
  1000. //}
  1001. public enum MenuIndex
  1002. {
  1003. AddSample = 0,
  1004. DeleteSample = 1,
  1005. SampleStripSeparator = 2,
  1006. ReadSEMData = 3,
  1007. SetSemData = 4,
  1008. SetSEMCenterLocation = 5,
  1009. DriveSEMToCenterLocation = 6,
  1010. DriveSEMToCurrentLocation = 7,
  1011. SEMStripSeparator = 8,
  1012. ShootBSEPicture = 9,
  1013. DeleteBSEPicture = 10
  1014. }
  1015. public enum ColorType
  1016. {
  1017. SingleColor,//帧图fd8f8f
  1018. RoundRectangleColor,//c8c8c8圆角矩形
  1019. SampleBackGroundColor,//c0c0c0圆角矩形
  1020. FontColor,//90ee90文字颜色
  1021. SampleColor,//f4f4f4 样品未选择
  1022. SampleSelColor//505050 样品选择后
  1023. }
  1024. public enum GrayLevel
  1025. {
  1026. Min=0,
  1027. Max=255
  1028. }
  1029. }