CDisplayGDIObject.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  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. if (BSEImage != null)
  230. {
  231. e.Graphics.DrawImage(BSEImage, startPointF.X, startPointF.Y, endPointF.X - startPointF.X, endPointF.Y - startPointF.Y);
  232. }
  233. }
  234. else if (createType == GDIType.DrawPolygonFinish)
  235. {
  236. Color myColor = selColor;
  237. Pen pen = new Pen(myColor, 1);
  238. var m_Region = new Rectangle();
  239. m_Region.X = (int)m_RegionF.X;
  240. m_Region.Y = (int)m_RegionF.Y;
  241. m_Region.Width = (int)m_RegionF.Width;
  242. m_Region.Height = (int)m_RegionF.Height;
  243. e.Graphics.DrawRectangle(pen, m_Region);
  244. }
  245. }
  246. public Image BSEImage
  247. {
  248. get { return bseImage; }
  249. set { bseImage = value; }
  250. }
  251. public float BSEImageWitdh
  252. {
  253. get { return bseImageWidth; }
  254. set { bseImageWidth = value; }
  255. }
  256. public float BSEImageHeight
  257. {
  258. get { return bseImageHeight; }
  259. set { bseImageHeight = value; }
  260. }
  261. public PointF BSEImageLocation
  262. {
  263. get { return bseImageLocation; }
  264. set { bseImageLocation = value; }
  265. }
  266. public Color LineColor
  267. {
  268. get { return lineColor; }
  269. set { lineColor = value; }
  270. }
  271. public float LineLength
  272. {
  273. get { return lineLength; }
  274. set { lineLength = value; }
  275. }
  276. public PointF LineStartPoint
  277. {
  278. get { return lineStartPoint; }
  279. set { lineStartPoint = value; }
  280. }
  281. public int OTSX
  282. {
  283. get { return otsX; }
  284. set { otsX = value; }
  285. }
  286. public int OTSY
  287. {
  288. get { return otsY; }
  289. set { otsY = value; }
  290. }
  291. public GDIType GDIType
  292. {
  293. get { return createType; }
  294. set { createType = value; }
  295. }
  296. public Color SelColor
  297. {
  298. get { return selColor; }
  299. set { selColor = value; }
  300. }
  301. public string HoleNo//holename when they are not field rectangle gdi object.
  302. {
  303. get { return nameOrHoleName; }
  304. set { nameOrHoleName = value; }
  305. }
  306. public string ID
  307. {
  308. get { return id; }
  309. set { id = value; }
  310. }
  311. public string SampleName
  312. {
  313. get { return sampleName; }
  314. set { sampleName = value; }
  315. }
  316. public int SampleCount
  317. {
  318. get { return sampleCount; }
  319. set { sampleCount = value; }
  320. }
  321. public string StrContent
  322. {
  323. get { return strContent; }
  324. set { strContent = value; }
  325. }
  326. public RectangleF GetZoomedRegion
  327. {
  328. get {
  329. var m_Region = new RectangleF();
  330. m_Region.X = m_RegionF.X;
  331. m_Region.Y = m_RegionF.Y;
  332. m_Region.Width = m_RegionF.Width;
  333. m_Region.Height = m_RegionF.Height;
  334. return m_Region;
  335. }
  336. }
  337. public List<PointF> GetVertexPoints()
  338. {
  339. List<PointF> vertexPoint = new List<PointF>();
  340. var region = this.GetZoomedRegionF();
  341. vertexPoint.Add(region.Location);
  342. vertexPoint.Add(new PointF(region.X, region.Y + region.Height));
  343. vertexPoint.Add(new PointF(region.X + region.Width, region.Y));
  344. vertexPoint.Add(new PointF(region.X + region.Width, region.Y + region.Height));
  345. return vertexPoint;
  346. }
  347. public List<PointF> GetOriginalRegionVertexPoints()
  348. {
  349. List<PointF> vertexPoint = new List<PointF>();
  350. var region = this.GetOrigionalDrawRegionF();
  351. vertexPoint.Add(region.Location);
  352. vertexPoint.Add(new PointF(region.X, region.Y + region.Height));
  353. vertexPoint.Add(new PointF(region.X + region.Width, region.Y));
  354. vertexPoint.Add(new PointF(region.X + region.Width, region.Y + region.Height));
  355. return vertexPoint;
  356. }
  357. public RectangleF GetZoomedRegionF()
  358. {
  359. return m_RegionF;
  360. }
  361. public void SetInitRegionF(RectangleF OrigineRegionF)//not zoomed regine value
  362. {
  363. float x1, y1;
  364. x1 = OrigineRegionF.X * m_zoomNum + m_refPoint.X;
  365. y1 = OrigineRegionF.Y * m_zoomNum + m_refPoint.Y;
  366. float w1, h1;
  367. w1 = OrigineRegionF.Width * m_zoomNum;
  368. h1 = OrigineRegionF.Height * m_zoomNum;
  369. m_OrigineRegionF = OrigineRegionF;
  370. m_RegionF = new RectangleF(x1, y1, w1, h1);
  371. }
  372. internal void SetZoomedRegionF(RectangleF scaleRectangleF)
  373. {
  374. float x1, y1;
  375. x1 = (scaleRectangleF.X-m_refPoint.X) / m_zoomNum ;
  376. y1 = (scaleRectangleF.Y-m_refPoint.Y) / m_zoomNum ;
  377. float w1, h1;
  378. w1 = scaleRectangleF.Width / m_zoomNum;
  379. h1 = scaleRectangleF.Height / m_zoomNum;
  380. m_OrigineRegionF = new RectangleF(x1, y1, w1, h1);
  381. m_RegionF = scaleRectangleF;
  382. }
  383. public RectangleF GetOrigionalDrawRegionF()
  384. { return m_OrigineRegionF; }
  385. public virtual GraphicsPath GetGPath()
  386. {
  387. var measureItem = this;
  388. //重新绘制测量区域路径
  389. GraphicsPath GPath = new GraphicsPath();
  390. if (measureItem.GDIType == GDIType.Circle)
  391. {
  392. GPath.AddEllipse(GetZoomedRegionF());
  393. }
  394. else
  395. {
  396. GPath.AddRectangle(GetZoomedRegionF());
  397. }
  398. return GPath;
  399. }
  400. public Point GetZoomedCenterPoint()
  401. {
  402. Point pCenterPoint = new Point();
  403. //获取在工作窗口中X,Y位置
  404. pCenterPoint.X = (int)(this.GetZoomedRegion.X + this.GetZoomedRegion.Width / 2);
  405. pCenterPoint.Y = (int)(this.GetZoomedRegion.Y + this.GetZoomedRegion.Height / 2);
  406. return pCenterPoint;
  407. }
  408. public PointF GetCenterPoint()
  409. {
  410. PointF pCenterPoint = new PointF();
  411. //获取在工作窗口中X,Y位置
  412. pCenterPoint.X = (this.GetOrigionalDrawRegionF().X + this.GetOrigionalDrawRegionF().Width / 2);
  413. pCenterPoint.Y = (this.GetOrigionalDrawRegionF().Y + this.GetOrigionalDrawRegionF().Height / 2);
  414. return pCenterPoint;
  415. }
  416. #endregion
  417. public bool IsDragging
  418. {
  419. get { return m_IsDragging; }
  420. set { m_IsDragging = value; }
  421. }
  422. public bool IsAltering// changing the size by gui operating.
  423. {
  424. get { return m_IsAlter; }
  425. set { m_IsAlter = value; }
  426. }
  427. public bool IsWorkSample
  428. {
  429. get { return m_IsWorkSample; }
  430. set { m_IsWorkSample = value; }
  431. }
  432. virtual public PointF DraggingPoint
  433. {
  434. get { return m_DraggingPoint; }
  435. set {
  436. m_DraggingPoint = value;
  437. }
  438. }
  439. public bool IsMoving { get => m_IsMoving; set => m_IsMoving = value; }
  440. public PointF GetDisplayRefPoint()
  441. { return m_refPoint; }
  442. public void SetDisplayRefPoint(PointF value)
  443. {
  444. m_refPoint = value;
  445. SetInitRegionF(m_OrigineRegionF);
  446. }
  447. public float GetZoomNumber()
  448. { return m_zoomNum; }
  449. virtual public void SetZoomNumber(float value)
  450. {
  451. m_zoomNum = value;
  452. SetInitRegionF(m_OrigineRegionF);
  453. }
  454. #region 画圆角矩形
  455. internal static GraphicsPath CreateRoundedRectanglePath(RectangleF rect, int cornerRadius)
  456. {
  457. GraphicsPath roundedRect = new GraphicsPath();
  458. roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
  459. roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
  460. roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
  461. roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
  462. roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
  463. roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
  464. roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
  465. roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
  466. roundedRect.CloseFigure();
  467. return roundedRect;
  468. }
  469. public bool IfZoomContains(Point mousePoint)
  470. {
  471. if (mousePoint.X > m_RegionF.Left && mousePoint.X < m_RegionF.Left + m_RegionF.Width)
  472. {
  473. if (mousePoint.Y > m_RegionF.Top && mousePoint.Y < m_RegionF.Top + m_RegionF.Height)
  474. {
  475. return true;
  476. }
  477. }
  478. return false;
  479. }
  480. public bool IfContains(PointF thePoint)
  481. {
  482. if (thePoint.X > m_OrigineRegionF.Left && thePoint.X < m_OrigineRegionF.Left + m_OrigineRegionF.Width)
  483. {
  484. if (thePoint.Y > m_OrigineRegionF.Top && thePoint.Y < m_OrigineRegionF.Top + m_OrigineRegionF.Height)
  485. {
  486. return true;
  487. }
  488. }
  489. return false;
  490. }
  491. virtual public void Zoom(PointF mousePoint, float zoomNum)
  492. {
  493. float X1;
  494. float curZoom = m_zoomNum;
  495. float deltaZoom = zoomNum - curZoom;
  496. float Y1;
  497. if (zoomNum == 1)
  498. {
  499. m_zoomNum = 1;
  500. m_RegionF = m_OrigineRegionF;
  501. m_refPoint = new PointF(0, 0);
  502. }
  503. else
  504. {
  505. X1 = (m_RegionF.X - mousePoint.X) / curZoom * deltaZoom + m_RegionF.X;
  506. Y1 = (m_RegionF.Y - mousePoint.Y) / curZoom * deltaZoom + m_RegionF.Y;
  507. m_refPoint.X = (m_refPoint.X - mousePoint.X) / curZoom * deltaZoom + m_refPoint.X;
  508. m_refPoint.Y = (m_refPoint.Y - mousePoint.Y) / curZoom * deltaZoom + m_refPoint.Y;
  509. float Width = GetOrigionalDrawRegionF().Width * zoomNum;
  510. float Height = GetOrigionalDrawRegionF().Height * zoomNum;
  511. m_RegionF = new RectangleF(X1, Y1, Width, Height);
  512. m_zoomNum = zoomNum;
  513. }
  514. BSEImageWitdh = m_RegionF.Width;
  515. BSEImageHeight = m_RegionF.Height;
  516. BSEImageLocation = m_RegionF.Location;
  517. }
  518. virtual public void Move(PointF location)
  519. {
  520. PointF offset = new PointF(location.X - DraggingPoint.X, location.Y - DraggingPoint.Y);
  521. float X1;
  522. float Y1;
  523. X1 = (m_RegionF.X + offset.X);
  524. Y1 = (m_RegionF.Y + offset.Y);
  525. m_RegionF = new RectangleF(X1, Y1, m_RegionF.Width, m_RegionF.Height);
  526. m_refPoint.X = m_refPoint.X + offset.X;
  527. m_refPoint.Y = m_refPoint.Y + offset.Y;
  528. BSEImageWitdh = m_RegionF.Width;
  529. BSEImageHeight = m_RegionF.Height;
  530. BSEImageLocation = m_RegionF.Location;
  531. LineStartPoint = m_RegionF.Location;
  532. m_DraggingPoint = new Point((int)location.X,(int)location.Y);
  533. }
  534. virtual public void PositionAltering(PointF location,bool ifZoomCoord)
  535. {
  536. PointF offset = new PointF(location.X - DraggingPoint.X, location.Y - DraggingPoint.Y);
  537. PointF realShift;
  538. if (ifZoomCoord)
  539. {
  540. realShift = new PointF(offset.X / m_zoomNum, offset.Y / m_zoomNum);
  541. }
  542. else
  543. {
  544. realShift = new PointF(offset.X , offset.Y );
  545. }
  546. m_OrigineRegionF = new RectangleF(m_OrigineRegionF.X+realShift.X, m_OrigineRegionF.Y+realShift.Y, m_OrigineRegionF.Width, m_OrigineRegionF.Height);
  547. SetInitRegionF(m_OrigineRegionF);
  548. BSEImageWitdh = m_RegionF.Width;
  549. BSEImageHeight = m_RegionF.Height;
  550. BSEImageLocation = m_RegionF.Location;
  551. LineStartPoint = m_RegionF.Location;
  552. m_DraggingPoint = new Point((int)location.X, (int)location.Y);
  553. }
  554. public CDisplayGDIObject Duplicate()
  555. {
  556. CDisplayGDIObject r = new CDisplayGDIObject();
  557. r.HoleNo = this.nameOrHoleName;
  558. r.SampleName = this.SampleName;
  559. r.m_OrigineRegionF = this.m_OrigineRegionF;
  560. r.IsWorkSample = this.IsWorkSample;
  561. r.m_RegionF = this.m_RegionF;
  562. r.m_refPoint = this.m_refPoint;
  563. r.m_zoomNum = this.m_zoomNum;
  564. r.createType = this.createType;
  565. return r;
  566. }
  567. #endregion
  568. //是否设置为选择样品
  569. private bool m_IsAlter;
  570. //是否存在帧图信息
  571. //是否设置为拖动
  572. private bool m_IsDragging;
  573. private bool m_IsMoving;
  574. //是否为工作样品
  575. private bool m_IsWorkSample;
  576. private GDIType createType;
  577. private string id;
  578. protected string nameOrHoleName="";
  579. public string sampleName="";
  580. //样品孔中样品的数量
  581. public int sampleCount = 0;
  582. public string strContent;
  583. protected PointF m_DraggingPoint;
  584. protected Color selColor;
  585. protected RectangleF m_RegionF;
  586. //绘制时与移动缩放时记录的位置与尺寸
  587. protected RectangleF m_OrigineRegionF;
  588. //绘制颗粒图
  589. private Color lineColor;
  590. private float lineLength;
  591. private PointF lineStartPoint;
  592. private int otsX;
  593. private int otsY;
  594. //绘制样品孔BSE图像
  595. private Image bseImage;
  596. //绘制样品孔BSE图像宽度
  597. private float bseImageWidth;
  598. //绘制样品孔BSE图像高度
  599. private float bseImageHeight;
  600. //绘制样品孔BSE图像位置
  601. private PointF bseImageLocation;
  602. private PointF startPoint;
  603. private PointF endPoint;
  604. protected float m_zoomNum=1;
  605. protected PointF m_refPoint=new PointF(0,0);
  606. }
  607. public enum XYIndex
  608. {
  609. X = 0,
  610. Y = 1
  611. }
  612. public enum GDIType
  613. {
  614. //圆形
  615. Circle = 0,
  616. //圆角矩形
  617. StageBoundary_RoundedRectangle = 1,
  618. //样品孔中的文字
  619. Text = 2,
  620. //矩形
  621. Rectangle = 3,
  622. //样品孔背景
  623. CorrelateSampleHoleBackGround = 4,//every sample area has a sample hole correlation.
  624. //帧图-直线绘制方式
  625. SingleLine = 6,
  626. //表样-矩形
  627. SpecimenRectangle = 7,
  628. //表样-圆形
  629. SpecimenCircle = 8,
  630. DrawFrameOfHoleBSEImage = 9,
  631. //多边形完成标识
  632. DrawPolygonFinish = 11,
  633. SampleHoleImageBuffer=12
  634. }
  635. public enum ColorType
  636. {
  637. FieldColor,//帧图fd8f8f
  638. RoundRectangleColor,//c8c8c8圆角矩形
  639. SampleBackGroundColor,//c0c0c0圆角矩形
  640. FontColor,//90ee90文字颜色
  641. SampleColor,//f4f4f4 样品未选择
  642. SampleSelColor//505050 样品选择后
  643. }
  644. public enum GrayLevel
  645. {
  646. Min=0,
  647. Max=255
  648. }
  649. }