CreateRectangle.cs 43 KB

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