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