CDisplayGDIObject.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. using System.Net;
  6. using System.Numerics;
  7. using System.Windows.Forms;
  8. namespace OTSMeasureApp
  9. {
  10. public class CDisplayGDIObject
  11. {
  12. public CDisplayGDIObject()
  13. {
  14. ID = System.Guid.NewGuid().ToString();
  15. OTSX = -1;
  16. OTSY = -1;
  17. }
  18. /// <summary>
  19. /// 创建图形
  20. /// </summary>
  21. /// <param name="startx">X位置</param>
  22. /// <param name="starty">Y位置</param>
  23. /// <param name="width">宽度</param>
  24. /// <param name="height">高度</param>
  25. /// <param name="cType">图形类型:createType=0 圆角矩形 createType=1 圆形 createType=2 文字</param>
  26. /// <param name="content">文字内容</param>
  27. public CDisplayGDIObject(float startx, float starty, float width, float height, GDIType cType, string content, string name)
  28. {
  29. var rec = new RectangleF(startx, starty, width, height);
  30. m_OrigineRegionF = rec;
  31. SetInitRegionF(m_OrigineRegionF);
  32. GDIType = cType;
  33. strContent = content;
  34. HoleNo = name;
  35. ID = System.Guid.NewGuid().ToString();
  36. OTSX = -1;
  37. OTSY = -1;
  38. }
  39. public CDisplayGDIObject(RectangleF rect, GDIType cType)
  40. {
  41. m_OrigineRegionF = rect;
  42. SetInitRegionF(m_OrigineRegionF);
  43. GDIType = cType;
  44. ID = System.Guid.NewGuid().ToString();
  45. selColor=Color.White;
  46. OTSX = -1;
  47. OTSY = -1;
  48. }
  49. public CDisplayGDIObject(RectangleF rect, GDIType cType, string name)
  50. {
  51. m_OrigineRegionF = rect;
  52. SetInitRegionF(m_OrigineRegionF);
  53. GDIType = cType;
  54. HoleNo = name;
  55. ID = System.Guid.NewGuid().ToString();
  56. OTSX = -1;
  57. OTSY = -1;
  58. }
  59. public CDisplayGDIObject(RectangleF rect, GDIType cType, string name, Color selColor)
  60. {
  61. m_OrigineRegionF = rect;
  62. SetInitRegionF(m_OrigineRegionF);
  63. GDIType = cType;
  64. HoleNo = name;
  65. SelColor = selColor;
  66. ID = System.Guid.NewGuid().ToString();
  67. OTSX = -1;
  68. OTSY = -1;
  69. }
  70. //绘制小矩形
  71. public CDisplayGDIObject(RectangleF rectSingle, GDIType cType, string name, string sampleName, Color selColor)
  72. {
  73. m_OrigineRegionF = rectSingle;
  74. SetInitRegionF(m_OrigineRegionF);
  75. GDIType = cType;
  76. HoleNo = name;
  77. SelColor = selColor;
  78. SampleName = sampleName;
  79. ID = System.Guid.NewGuid().ToString();
  80. OTSX = -1;
  81. OTSY = -1;
  82. }
  83. /// <summary>
  84. /// 获取样品孔中BSE图像
  85. /// </summary>
  86. /// <param name="rect">位置大小</param>
  87. /// <param name="sampleHoleName">所在样品孔名称</param>
  88. /// <param name="bseImage">图像信息</param>
  89. /// <param name="bseImageWitdh">图像宽度</param>
  90. /// <param name="bseImageHeight">图像高度</param>
  91. /// <param name="drawImageLocation">图像开始位置</param>
  92. /// <param name="cType">绘制类型</param>
  93. public CDisplayGDIObject(RectangleF rect, int OTSx, int OTSy, string sampleName, string sampleHoleName, float bseImageWitdh, float bseImageHeight, GDIType cType)
  94. {
  95. m_OrigineRegionF = rect;
  96. SetInitRegionF(m_OrigineRegionF);
  97. HoleNo = sampleHoleName;
  98. SampleName = sampleName;
  99. //生成编号
  100. ID = System.Guid.NewGuid().ToString();
  101. //图像宽度
  102. BSEImageWitdh = bseImageWitdh;
  103. //图像高度
  104. BSEImageHeight = bseImageHeight;
  105. //图像位置
  106. BSEImageLocation = rect.Location;
  107. OTSX = OTSx;
  108. OTSY = OTSy;
  109. //绘制类型
  110. GDIType = cType;
  111. }
  112. #region 变量重写
  113. public virtual void OnPaint(PaintEventArgs e)
  114. {
  115. if (createType == GDIType.StageBoundary_RoundedRectangle)
  116. {
  117. //获取颜色
  118. Color myColor = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.RoundRectangleColor);
  119. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  120. GraphicsPath grPath = CreateRoundedRectanglePath(m_RegionF, 20);
  121. e.Graphics.FillPath(sampleBrush, grPath);
  122. e.Graphics.DrawPath(Pens.Black, grPath);
  123. }
  124. //圆形
  125. else if (createType == GDIType.Circle)
  126. {
  127. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(this.selColor);
  128. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  129. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  130. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  131. e.Graphics.FillEllipse(sampleBrush, m_RegionF);
  132. e.Graphics.DrawEllipse(Pens.Black, m_RegionF);
  133. }
  134. //文字
  135. else if (createType == GDIType.Text)
  136. {
  137. //设置文字对齐方式
  138. StringFormat sf = new StringFormat();
  139. sf.Alignment = StringAlignment.Center;
  140. sf.LineAlignment = StringAlignment.Center;
  141. //文字颜色
  142. Color myColor = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.FontColor);
  143. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  144. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(50, Color.Black));
  145. //字体大小 根据样品孔Rectangle大小
  146. float fontSize = m_RegionF.Width / 2;
  147. Font font = new Font("宋体", fontSize, FontStyle.Regular);
  148. if (fontSize == 0)
  149. {
  150. font = new Font("宋体", 5, FontStyle.Regular);
  151. }
  152. //消除锯齿
  153. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  154. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  155. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  156. e.Graphics.DrawString(strContent, font, sampleBrush, m_RegionF, sf);
  157. }
  158. //矩形
  159. else if (createType == GDIType.Rectangle)
  160. {
  161. Color myColor = System.Drawing.Color.White;
  162. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  163. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  164. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  165. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  166. e.Graphics.FillRectangle(sampleBrush, m_RegionF);
  167. var m_Region = new Rectangle();
  168. m_Region.X = (int)m_RegionF.X;
  169. m_Region.Y = (int)m_RegionF.Y;
  170. m_Region.Width = (int)m_RegionF.Width;
  171. m_Region.Height = (int)m_RegionF.Height;
  172. e.Graphics.DrawRectangle(Pens.Black, m_Region);
  173. }
  174. //绘制帧图 直线
  175. else if (createType == GDIType.SingleLine)
  176. {
  177. //设置颜色
  178. Color myColor = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.FieldColor);
  179. //设置画笔
  180. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  181. Pen pen = new Pen(sampleBrush, 0.0001f);
  182. //未抗锯齿
  183. e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
  184. e.Graphics.InterpolationMode = InterpolationMode.Default;
  185. e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
  186. //设置直线位置与尺寸
  187. PointF startPointF = new PointF(startPoint.X, startPoint.Y);
  188. PointF endPointF = new PointF(endPoint.X, endPoint.Y);
  189. //度量单位
  190. e.Graphics.PageUnit = GraphicsUnit.Display;
  191. e.Graphics.DrawLine(pen, startPointF, endPointF);
  192. }
  193. //绘制标样
  194. else if (createType == GDIType.SpecimenRectangle)
  195. {
  196. Color myColor = System.Drawing.Color.Black;
  197. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  198. Pen pen = new Pen(sampleBrush, 0.0001f);
  199. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
  200. var m_Region = new Rectangle();
  201. m_Region.X = (int)m_RegionF.X;
  202. m_Region.Y = (int)m_RegionF.Y;
  203. m_Region.Width = (int)m_RegionF.Width;
  204. m_Region.Height = (int)m_RegionF.Height;
  205. e.Graphics.DrawRectangle(pen, m_Region);
  206. e.Graphics.FillRectangle(sampleBrush, m_RegionF);
  207. }
  208. //绘制标样
  209. else if (createType == GDIType.SpecimenCircle)
  210. {
  211. Color myColor = System.Drawing.Color.Black;
  212. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  213. Pen pen = new Pen(sampleBrush, 0.0001f);
  214. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
  215. e.Graphics.DrawEllipse(pen, m_RegionF);
  216. e.Graphics.FillEllipse(sampleBrush, m_RegionF);
  217. }
  218. //绘制样品孔BSE图像
  219. else if (createType == GDIType.DrawFrameOfHoleBSEImage)
  220. {
  221. PointF startPointF = new PointF(m_RegionF.Left, m_RegionF.Top);
  222. PointF endPointF = new PointF(m_RegionF.Right + 2, m_RegionF.Bottom + 2);
  223. //绘制样品孔中图像信息
  224. if (BSEImage != null)
  225. {
  226. Image thumbnail = BSEImage.GetThumbnailImage((int)m_RegionF.Width + 2,(int)m_RegionF.Height + 2, null, IntPtr.Zero);
  227. e.Graphics.DrawImage(thumbnail, startPointF);/*, startPointF.X, startPointF.Y, endPointF.X - startPointF.X, endPointF.Y - startPointF.Y*/
  228. }
  229. }
  230. else if (createType == GDIType.DrawPolygonFinish)
  231. {
  232. Color myColor = selColor;
  233. Pen pen = new Pen(myColor, 1);
  234. var m_Region = new Rectangle();
  235. m_Region.X = (int)m_RegionF.X;
  236. m_Region.Y = (int)m_RegionF.Y;
  237. m_Region.Width = (int)m_RegionF.Width;
  238. m_Region.Height = (int)m_RegionF.Height;
  239. e.Graphics.DrawRectangle(pen, m_Region);
  240. }
  241. }
  242. public Image BSEImage
  243. {
  244. get { return bseImage; }
  245. set { bseImage = value; }
  246. }
  247. public float BSEImageWitdh
  248. {
  249. get { return bseImageWidth; }
  250. set { bseImageWidth = value; }
  251. }
  252. public float BSEImageHeight
  253. {
  254. get { return bseImageHeight; }
  255. set { bseImageHeight = value; }
  256. }
  257. public PointF BSEImageLocation
  258. {
  259. get { return bseImageLocation; }
  260. set { bseImageLocation = value; }
  261. }
  262. public Color LineColor
  263. {
  264. get { return lineColor; }
  265. set { lineColor = value; }
  266. }
  267. public float LineLength
  268. {
  269. get { return lineLength; }
  270. set { lineLength = value; }
  271. }
  272. public PointF LineStartPoint
  273. {
  274. get { return lineStartPoint; }
  275. set { lineStartPoint = value; }
  276. }
  277. public int OTSX
  278. {
  279. get { return otsX; }
  280. set { otsX = value; }
  281. }
  282. public int OTSY
  283. {
  284. get { return otsY; }
  285. set { otsY = value; }
  286. }
  287. public GDIType GDIType
  288. {
  289. get { return createType; }
  290. set { createType = value; }
  291. }
  292. public Color SelColor
  293. {
  294. get { return selColor; }
  295. set { selColor = value; }
  296. }
  297. public string HoleNo//holename when they are not field rectangle gdi object.
  298. {
  299. get { return nameOrHoleName; }
  300. set { nameOrHoleName = value; }
  301. }
  302. public string ID
  303. {
  304. get { return id; }
  305. set { id = value; }
  306. }
  307. public string SampleName
  308. {
  309. get { return sampleName; }
  310. set { sampleName = value; }
  311. }
  312. public int SampleCount
  313. {
  314. get { return sampleCount; }
  315. set { sampleCount = value; }
  316. }
  317. public string StrContent
  318. {
  319. get { return strContent; }
  320. set { strContent = value; }
  321. }
  322. public RectangleF GetZoomedRegion
  323. {
  324. get {
  325. var m_Region = new RectangleF();
  326. m_Region.X = m_RegionF.X;
  327. m_Region.Y = m_RegionF.Y;
  328. m_Region.Width = m_RegionF.Width;
  329. m_Region.Height = m_RegionF.Height;
  330. return m_Region;
  331. }
  332. }
  333. public List<PointF> GetVertexPoints()
  334. {
  335. List<PointF> vertexPoint = new List<PointF>();
  336. var region = this.GetZoomedRegionF();
  337. vertexPoint.Add(region.Location);
  338. vertexPoint.Add(new PointF(region.X, region.Y + region.Height));
  339. vertexPoint.Add(new PointF(region.X + region.Width, region.Y));
  340. vertexPoint.Add(new PointF(region.X + region.Width, region.Y + region.Height));
  341. return vertexPoint;
  342. }
  343. public List<PointF> GetOriginalRegionVertexPoints()
  344. {
  345. List<PointF> vertexPoint = new List<PointF>();
  346. var region = this.GetOrigionalDrawRegionF();
  347. vertexPoint.Add(region.Location);
  348. vertexPoint.Add(new PointF(region.X, region.Y + region.Height));
  349. vertexPoint.Add(new PointF(region.X + region.Width, region.Y));
  350. vertexPoint.Add(new PointF(region.X + region.Width, region.Y + region.Height));
  351. return vertexPoint;
  352. }
  353. public RectangleF GetZoomedRegionF()
  354. {
  355. return m_RegionF;
  356. }
  357. public void SetInitRegionF(RectangleF OrigineRegionF)//not zoomed regine value
  358. {
  359. float x1, y1;
  360. x1 = OrigineRegionF.X * m_zoomNum + m_refPoint.X;
  361. y1 = OrigineRegionF.Y * m_zoomNum + m_refPoint.Y;
  362. float w1, h1;
  363. w1 = OrigineRegionF.Width * m_zoomNum;
  364. h1 = OrigineRegionF.Height * m_zoomNum;
  365. m_OrigineRegionF = OrigineRegionF;
  366. m_RegionF = new RectangleF(x1, y1, w1, h1);
  367. }
  368. internal void SetZoomedRegionF(RectangleF scaleRectangleF)
  369. {
  370. float x1, y1;
  371. x1 = (scaleRectangleF.X-m_refPoint.X) / m_zoomNum ;
  372. y1 = (scaleRectangleF.Y-m_refPoint.Y) / m_zoomNum ;
  373. float w1, h1;
  374. w1 = scaleRectangleF.Width / m_zoomNum;
  375. h1 = scaleRectangleF.Height / m_zoomNum;
  376. m_OrigineRegionF = new RectangleF(x1, y1, w1, h1);
  377. m_RegionF = scaleRectangleF;
  378. }
  379. public RectangleF GetOrigionalDrawRegionF()
  380. { return m_OrigineRegionF; }
  381. public virtual GraphicsPath GetGPath()
  382. {
  383. var measureItem = this;
  384. //重新绘制测量区域路径
  385. GraphicsPath GPath = new GraphicsPath();
  386. if (measureItem.GDIType == GDIType.Circle)
  387. {
  388. GPath.AddEllipse(GetZoomedRegionF());
  389. }
  390. else
  391. {
  392. GPath.AddRectangle(GetZoomedRegionF());
  393. }
  394. return GPath;
  395. }
  396. public Point GetZoomedCenterPoint()
  397. {
  398. Point pCenterPoint = new Point();
  399. //获取在工作窗口中X,Y位置
  400. pCenterPoint.X = (int)(this.GetZoomedRegion.X + this.GetZoomedRegion.Width / 2);
  401. pCenterPoint.Y = (int)(this.GetZoomedRegion.Y + this.GetZoomedRegion.Height / 2);
  402. return pCenterPoint;
  403. }
  404. public PointF GetCenterPoint()
  405. {
  406. PointF pCenterPoint = new PointF();
  407. //获取在工作窗口中X,Y位置
  408. pCenterPoint.X = (this.GetOrigionalDrawRegionF().X + this.GetOrigionalDrawRegionF().Width / 2);
  409. pCenterPoint.Y = (this.GetOrigionalDrawRegionF().Y + this.GetOrigionalDrawRegionF().Height / 2);
  410. return pCenterPoint;
  411. }
  412. #endregion
  413. public bool IsDragging
  414. {
  415. get { return m_IsDragging; }
  416. set { m_IsDragging = value; }
  417. }
  418. public bool IsAltering// changing the size by gui operating.
  419. {
  420. get { return m_IsAlter; }
  421. set { m_IsAlter = value; }
  422. }
  423. public bool IsWorkSample
  424. {
  425. get { return m_IsWorkSample; }
  426. set { m_IsWorkSample = value; }
  427. }
  428. virtual public PointF DraggingPoint
  429. {
  430. get { return m_DraggingPoint; }
  431. set {
  432. m_DraggingPoint = value;
  433. }
  434. }
  435. public bool IsMoving { get => m_IsMoving; set => m_IsMoving = value; }
  436. public PointF GetDisplayRefPoint()
  437. { return m_refPoint; }
  438. public void SetDisplayRefPoint(PointF value)
  439. {
  440. m_refPoint = value;
  441. SetInitRegionF(m_OrigineRegionF);
  442. }
  443. public float GetZoomNumber()
  444. { return m_zoomNum; }
  445. virtual public void SetZoomNumber(float value)
  446. {
  447. m_zoomNum = value;
  448. SetInitRegionF(m_OrigineRegionF);
  449. }
  450. #region 画圆角矩形
  451. internal static GraphicsPath CreateRoundedRectanglePath(RectangleF rect, int cornerRadius)
  452. {
  453. GraphicsPath roundedRect = new GraphicsPath();
  454. roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
  455. roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
  456. roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
  457. roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
  458. roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
  459. roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
  460. roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
  461. roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
  462. roundedRect.CloseFigure();
  463. return roundedRect;
  464. }
  465. public bool IfZoomContains(Point mousePoint)
  466. {
  467. if (mousePoint.X > m_RegionF.Left && mousePoint.X < m_RegionF.Left + m_RegionF.Width)
  468. {
  469. if (mousePoint.Y > m_RegionF.Top && mousePoint.Y < m_RegionF.Top + m_RegionF.Height)
  470. {
  471. return true;
  472. }
  473. }
  474. return false;
  475. }
  476. public bool IfContains(PointF thePoint)
  477. {
  478. if (thePoint.X > m_OrigineRegionF.Left && thePoint.X < m_OrigineRegionF.Left + m_OrigineRegionF.Width)
  479. {
  480. if (thePoint.Y > m_OrigineRegionF.Top && thePoint.Y < m_OrigineRegionF.Top + m_OrigineRegionF.Height)
  481. {
  482. return true;
  483. }
  484. }
  485. return false;
  486. }
  487. virtual public void Zoom(PointF mousePoint, float zoomNum)
  488. {
  489. float X1;
  490. float curZoom = m_zoomNum;
  491. float deltaZoom = zoomNum - curZoom;
  492. float Y1;
  493. if (zoomNum == 1)
  494. {
  495. m_zoomNum = 1;
  496. m_RegionF = m_OrigineRegionF;
  497. m_refPoint = new PointF(0, 0);
  498. }
  499. else
  500. {
  501. X1 = (m_RegionF.X - mousePoint.X) / curZoom * deltaZoom + m_RegionF.X;
  502. Y1 = (m_RegionF.Y - mousePoint.Y) / curZoom * deltaZoom + m_RegionF.Y;
  503. m_refPoint.X = (m_refPoint.X - mousePoint.X) / curZoom * deltaZoom + m_refPoint.X;
  504. m_refPoint.Y = (m_refPoint.Y - mousePoint.Y) / curZoom * deltaZoom + m_refPoint.Y;
  505. float Width = GetOrigionalDrawRegionF().Width * zoomNum;
  506. float Height = GetOrigionalDrawRegionF().Height * zoomNum;
  507. m_RegionF = new RectangleF(X1, Y1, Width, Height);
  508. m_zoomNum = zoomNum;
  509. }
  510. BSEImageWitdh = m_RegionF.Width;
  511. BSEImageHeight = m_RegionF.Height;
  512. BSEImageLocation = m_RegionF.Location;
  513. }
  514. virtual public void Move(PointF location)
  515. {
  516. PointF offset = new PointF(location.X - DraggingPoint.X, location.Y - DraggingPoint.Y);
  517. float X1;
  518. float Y1;
  519. X1 = (m_RegionF.X + offset.X);
  520. Y1 = (m_RegionF.Y + offset.Y);
  521. m_RegionF = new RectangleF(X1, Y1, m_RegionF.Width, m_RegionF.Height);
  522. m_refPoint.X = m_refPoint.X + offset.X;
  523. m_refPoint.Y = m_refPoint.Y + offset.Y;
  524. BSEImageWitdh = m_RegionF.Width;
  525. BSEImageHeight = m_RegionF.Height;
  526. BSEImageLocation = m_RegionF.Location;
  527. LineStartPoint = m_RegionF.Location;
  528. m_DraggingPoint = new Point((int)location.X,(int)location.Y);
  529. }
  530. virtual public void PositionAltering(PointF location,bool ifZoomCoord)
  531. {
  532. PointF offset = new PointF(location.X - DraggingPoint.X, location.Y - DraggingPoint.Y);
  533. PointF realShift;
  534. if (ifZoomCoord)
  535. {
  536. realShift = new PointF(offset.X / m_zoomNum, offset.Y / m_zoomNum);
  537. }
  538. else
  539. {
  540. realShift = new PointF(offset.X , offset.Y );
  541. }
  542. m_OrigineRegionF = new RectangleF(m_OrigineRegionF.X+realShift.X, m_OrigineRegionF.Y+realShift.Y, m_OrigineRegionF.Width, m_OrigineRegionF.Height);
  543. SetInitRegionF(m_OrigineRegionF);
  544. BSEImageWitdh = m_RegionF.Width;
  545. BSEImageHeight = m_RegionF.Height;
  546. BSEImageLocation = m_RegionF.Location;
  547. LineStartPoint = m_RegionF.Location;
  548. m_DraggingPoint = new Point((int)location.X, (int)location.Y);
  549. }
  550. public CDisplayGDIObject Duplicate()
  551. {
  552. CDisplayGDIObject r = new CDisplayGDIObject();
  553. r.HoleNo = this.nameOrHoleName;
  554. r.SampleName = this.SampleName;
  555. r.m_OrigineRegionF = this.m_OrigineRegionF;
  556. r.IsWorkSample = this.IsWorkSample;
  557. r.m_RegionF = this.m_RegionF;
  558. r.m_refPoint = this.m_refPoint;
  559. r.m_zoomNum = this.m_zoomNum;
  560. r.createType = this.createType;
  561. return r;
  562. }
  563. #endregion
  564. //是否设置为选择样品
  565. private bool m_IsAlter;
  566. //是否存在帧图信息
  567. //是否设置为拖动
  568. private bool m_IsDragging;
  569. private bool m_IsMoving;
  570. //是否为工作样品
  571. private bool m_IsWorkSample;
  572. private GDIType createType;
  573. private string id;
  574. protected string nameOrHoleName="";
  575. public string sampleName="";
  576. //样品孔中样品的数量
  577. public int sampleCount = 0;
  578. public string strContent;
  579. protected PointF m_DraggingPoint;
  580. protected Color selColor;
  581. protected RectangleF m_RegionF;
  582. //绘制时与移动缩放时记录的位置与尺寸
  583. protected RectangleF m_OrigineRegionF;
  584. //绘制颗粒图
  585. private Color lineColor;
  586. private float lineLength;
  587. private PointF lineStartPoint;
  588. private int otsX;
  589. private int otsY;
  590. //绘制样品孔BSE图像
  591. private Image bseImage;
  592. //绘制样品孔BSE图像宽度
  593. private float bseImageWidth;
  594. //绘制样品孔BSE图像高度
  595. private float bseImageHeight;
  596. //绘制样品孔BSE图像位置
  597. private PointF bseImageLocation;
  598. private PointF startPoint;
  599. private PointF endPoint;
  600. protected float m_zoomNum=1;
  601. protected PointF m_refPoint=new PointF(0,0);
  602. }
  603. public enum XYIndex
  604. {
  605. X = 0,
  606. Y = 1
  607. }
  608. public enum GDIType
  609. {
  610. //圆形
  611. Circle = 0,
  612. //圆角矩形
  613. StageBoundary_RoundedRectangle = 1,
  614. //样品孔中的文字
  615. Text = 2,
  616. //矩形
  617. Rectangle = 3,
  618. //样品孔背景
  619. CorrelateSampleHoleBackGround = 4,//every sample area has a sample hole correlation.
  620. //帧图-直线绘制方式
  621. SingleLine = 6,
  622. //表样-矩形
  623. SpecimenRectangle = 7,
  624. //表样-圆形
  625. SpecimenCircle = 8,
  626. DrawFrameOfHoleBSEImage = 9,
  627. //多边形完成标识
  628. DrawPolygonFinish = 11,
  629. SampleHoleImageBuffer=12
  630. }
  631. public enum ColorType
  632. {
  633. FieldColor,//帧图fd8f8f
  634. RoundRectangleColor,//c8c8c8圆角矩形
  635. SampleBackGroundColor,//c0c0c0圆角矩形
  636. FontColor,//90ee90文字颜色
  637. SampleColor,//f4f4f4 样品未选择
  638. SampleSelColor//505050 样品选择后
  639. }
  640. public enum GrayLevel
  641. {
  642. Min=0,
  643. Max=255
  644. }
  645. }