MeasureRandSquare.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  1. using PaintDotNet.Base.SettingModel;
  2. using System;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. using System.Windows.Forms;
  6. using PaintDotNet.Annotation.Enum;
  7. using System.Collections.Generic;
  8. using PaintDotNet.Base.CommTool;
  9. using System.Linq;
  10. namespace PaintDotNet.Annotation.Measure
  11. {
  12. /// <summary>
  13. /// 测量->多边形测量->任意正方形
  14. /// </summary>
  15. public class MeasureRandSquare : MeasureDrawObject
  16. {
  17. /// <summary>
  18. /// 标注样式信息model
  19. /// </summary>
  20. public MeasureStyleModel.MeasureRandSquare measureRandSquare;
  21. /// <summary>
  22. /// 坐标点集合
  23. /// </summary>
  24. public List<PointF> pointArray;
  25. /// <summary>
  26. /// 第三个点
  27. /// </summary>
  28. PointF linePoint;
  29. /// <summary>
  30. /// 第四个点
  31. /// </summary>
  32. PointF linePoint1;
  33. /// <summary>
  34. /// 中心点
  35. /// </summary>
  36. PointF centerPoint;
  37. /// <summary>
  38. /// 旋转时的最后一个点记录,用于计算角度
  39. /// </summary>
  40. PointF lastPoint;
  41. /// <summary>
  42. /// 旋转时的标记
  43. /// </summary>
  44. public bool isPress = false;
  45. /// <summary>
  46. /// 重新计算过的外接矩形
  47. /// </summary>
  48. RectangleF largerRect;
  49. /// <summary>
  50. /// 周长
  51. /// </summary>
  52. //private double length = 0.0;
  53. /// <summary>
  54. /// 面积
  55. /// </summary>
  56. private double area = 0.0;
  57. /// <summary>
  58. /// 测量信息矩形定义
  59. /// </summary>
  60. private RectangleF rectangleF1 = new RectangleF();
  61. private RectangleF rectangleF2 = new RectangleF();
  62. private RectangleF rectangleF3 = new RectangleF();
  63. private RectangleF rectangleF4 = new RectangleF();
  64. private RectangleF rectangleF5 = new RectangleF();
  65. private RectangleF rectangleF6 = new RectangleF();
  66. private RectangleF rectangleF7 = new RectangleF();
  67. private RectangleF rectangleF8 = new RectangleF();
  68. private RectangleF rectangleF9 = new RectangleF();
  69. private RectangleF rectangleF10 = new RectangleF();
  70. private RectangleF rectangleF11 = new RectangleF();
  71. /// <summary>
  72. /// 文本上用于拖动的点
  73. /// </summary>
  74. private Point pointL = new Point();
  75. /// <summary>
  76. /// 绘制限制(第一次绘制时)
  77. /// </summary>
  78. public bool pointChange = true;
  79. /// <summary>
  80. /// 区分移动文本
  81. /// </summary>
  82. private int moveKb;
  83. /// <summary>
  84. /// 绘制限制(从配置文件加载)
  85. /// </summary>
  86. public bool configurationFile = false;
  87. /// <summary>
  88. /// 绘制限制(更改属性时)
  89. /// </summary>
  90. private bool SavePointChange;
  91. /// <summary>
  92. /// 绘制属性
  93. /// </summary>
  94. private string[] drawingPropertiesList;
  95. /// <summary>
  96. /// 绘制属性(克隆)
  97. /// </summary>
  98. private string[] drawingPropertiesListClone;
  99. private bool drawing;
  100. /// <summary>
  101. /// 旋转角度
  102. /// </summary>
  103. private double angle;
  104. /// <summary>
  105. /// 绘制点
  106. /// </summary>
  107. private PointF PointF = new PointF();
  108. /// <summary>
  109. /// 是否移动了鼠标
  110. /// </summary>
  111. public bool moved = false;
  112. /// <summary>
  113. /// 限制绘制(绘制中)
  114. /// </summary>
  115. public bool mouseUpPointChange = false;
  116. public MeasureRandSquare(ISurfaceBox surfaceBox, int x1, int y1, int x2, int y2, bool clone) : base()
  117. {
  118. this.objectType = DrawClass.Measure;
  119. this.drawToolType = DrawToolType.MeasureRandSquare;
  120. this.pointArray = new List<PointF>();
  121. this.measureRandSquare = surfaceBox.GetMeasureStyleModel().measureRandSquare;
  122. this.startPoint.X = x1;
  123. this.startPoint.Y = y1;
  124. this.endPoint.X = x2;
  125. this.endPoint.Y = y2;
  126. if (clone)
  127. {
  128. drawing = true;
  129. this.pointArray.Add(this.startPoint);
  130. this.pointArray.Add(this.endPoint);
  131. }
  132. this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);
  133. this.unitString = surfaceBox.GetPxPerUnit()[1];
  134. this.unit = surfaceBox.GetPxPerUnit()[2];
  135. }
  136. /// <summary>
  137. /// 测量属性
  138. /// </summary>
  139. /// <returns></returns>
  140. public override Dictionary<System.Enum, object> GetData()
  141. {
  142. if (data.ContainsKey(MeasureAttributes.MeasureMethod))
  143. data[MeasureAttributes.MeasureMethod] = PdnResources.GetString("Menu.MeasureAction.PolygonMeasurement.Text");
  144. else
  145. data.Add(MeasureAttributes.MeasureMethod, PdnResources.GetString("Menu.MeasureAction.PolygonMeasurement.Text"));
  146. if (data.ContainsKey(MeasureAttributes.MeasureUnitCN))
  147. data[MeasureAttributes.MeasureUnitCN] = this.unitString;
  148. else
  149. data.Add(MeasureAttributes.MeasureUnitCN, this.unitString);
  150. if (data.ContainsKey(MeasureAttributes.MeasureUnitEN))
  151. data[MeasureAttributes.MeasureUnitEN] = this.unit;
  152. else
  153. data.Add(MeasureAttributes.MeasureUnitEN, this.unit);
  154. if (data.ContainsKey(MeasureAttributes.PixelStartX))
  155. data[MeasureAttributes.PixelStartX] = startPoint.X;
  156. else
  157. data.Add(MeasureAttributes.PixelStartX, startPoint.X);
  158. if (data.ContainsKey(MeasureAttributes.PixelStartY))
  159. data[MeasureAttributes.PixelStartY] = startPoint.Y;
  160. else
  161. data.Add(MeasureAttributes.PixelStartY, startPoint.Y);
  162. if (data.ContainsKey(MeasureAttributes.PhysicalStartX))
  163. data[MeasureAttributes.PhysicalStartX] = Math.Round(startPoint.X * unitLength, decimalPlaces);
  164. else
  165. data.Add(MeasureAttributes.PhysicalStartX, Math.Round(startPoint.X * unitLength, decimalPlaces));
  166. if (data.ContainsKey(MeasureAttributes.PhysicalStartY))
  167. data[MeasureAttributes.PhysicalStartY] = Math.Round(startPoint.Y * unitLength, decimalPlaces);
  168. else
  169. data.Add(MeasureAttributes.PhysicalStartY, Math.Round(startPoint.Y * unitLength, decimalPlaces));
  170. if (data.ContainsKey(MeasureAttributes.PixelArea))
  171. data[MeasureAttributes.PixelArea] = Math.Round(area, decimalPlaces);
  172. else
  173. data.Add(MeasureAttributes.PixelArea, Math.Round(area, decimalPlaces));
  174. string s = Math.Round(this.area * unitLength, decimalPlaces).ToString();
  175. if (s.IndexOf(".") == -1)
  176. {
  177. for (int i = 0; i < decimalPlaces; i++)
  178. {
  179. if (i == 0)
  180. s += ".";
  181. s += "0";
  182. }
  183. }
  184. else
  185. {
  186. int a = s.Length - s.IndexOf(".") - 1;
  187. if (a < decimalPlaces)
  188. {
  189. for (int i = 0; i < decimalPlaces - a; i++)
  190. {
  191. s += "0";
  192. }
  193. }
  194. }
  195. if (data.ContainsKey(MeasureAttributes.PhysicalArea))
  196. data[MeasureAttributes.PhysicalArea] = s;
  197. else
  198. data.Add(MeasureAttributes.PhysicalArea, s);
  199. if (data.ContainsKey(MeasureAttributes.PixelCircumference))
  200. data[MeasureAttributes.PixelCircumference] = Math.Round(length, decimalPlaces);
  201. else
  202. data.Add(MeasureAttributes.PixelCircumference, Math.Round(length, decimalPlaces));
  203. s = Math.Round(this.length * unitLength, decimalPlaces).ToString();
  204. if (s.IndexOf(".") == -1)
  205. {
  206. for (int i = 0; i < decimalPlaces; i++)
  207. {
  208. if (i == 0)
  209. s += ".";
  210. s += "0";
  211. }
  212. }
  213. else
  214. {
  215. int a = s.Length - s.IndexOf(".") - 1;
  216. if (a < decimalPlaces)
  217. {
  218. for (int i = 0; i < decimalPlaces - a; i++)
  219. {
  220. s += "0";
  221. }
  222. }
  223. }
  224. if (data.ContainsKey(MeasureAttributes.PhysicalCircumference))
  225. data[MeasureAttributes.PhysicalCircumference] = s;
  226. else
  227. data.Add(MeasureAttributes.PhysicalCircumference, s);
  228. return data;
  229. }
  230. public MeasureRandSquare(ISurfaceBox surfaceBox, List<PointF> points, ParentStyleModel parentStyleModel, Object content) : base()
  231. {
  232. this.objectType = DrawClass.Measure;
  233. this.drawToolType = DrawToolType.MeasureRandSquare;
  234. this.ISurfaceBox = surfaceBox;
  235. measureRandSquare = (MeasureStyleModel.MeasureRandSquare)parentStyleModel;
  236. pointArray = DrawRulerHelper.DeepCopyListByReflect(points);
  237. startPoint.X = points[0].X;
  238. startPoint.Y = points[0].Y;
  239. endPoint.X = points[1].X;
  240. endPoint.Y = points[1].Y;
  241. linePoint.X = points[2].X;
  242. linePoint.Y = points[2].Y;
  243. linePoint1.X = points[3].X;
  244. linePoint1.Y = points[3].Y;
  245. CalcOtherRectangle();
  246. CalcCenter();
  247. largerRect = GetBoundingBox();
  248. this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);
  249. this.unitString = surfaceBox.GetPxPerUnit()[1];
  250. this.unit = surfaceBox.GetPxPerUnit()[2];
  251. this.configurationFile = true;
  252. this.moved = true;
  253. }
  254. /// <summary>
  255. /// Clone this instance
  256. /// </summary>
  257. public override DrawObject Clone()
  258. {
  259. MeasureRandSquare measureRandSquare = new MeasureRandSquare(ISurfaceBox, 0, 0, 0, 1, false);
  260. measureRandSquare.objectType = DrawClass.Measure;
  261. measureRandSquare.drawToolType = DrawToolType.MeasureRandSquare;
  262. measureRandSquare.ISurfaceBox = this.ISurfaceBox;
  263. foreach (PointF p in this.pointArray)
  264. {
  265. measureRandSquare.pointArray.Add(p);
  266. }
  267. measureRandSquare.startPoint = this.startPoint;
  268. measureRandSquare.endPoint = this.endPoint;
  269. measureRandSquare.linePoint = this.linePoint;
  270. measureRandSquare.linePoint1 = this.linePoint1;
  271. if (drawingPropertiesList != null)
  272. measureRandSquare.drawingPropertiesListClone = drawingPropertiesList;
  273. measureRandSquare.moved = true;
  274. FillDrawObjectFields(measureRandSquare);
  275. return measureRandSquare;
  276. }
  277. public override DrawObject Clone(ISurfaceBox surfaceBox)
  278. {
  279. MeasureRandSquare measureRandSquare = new MeasureRandSquare(surfaceBox, this.GetPoints(), this.measureRandSquare, null);
  280. if (drawingPropertiesList != null)
  281. measureRandSquare.drawingPropertiesListClone = drawingPropertiesList;
  282. measureRandSquare.moved = true;
  283. FillDrawObjectFields(measureRandSquare);
  284. return measureRandSquare;
  285. }
  286. public override void Draw(Graphics g)
  287. {
  288. if(this.moved)
  289. {
  290. this.measureRandSquare = this.ISurfaceBox.GetMeasureStyleModel().measureRandSquare;
  291. drawingProperties.TryGetValue(this.drawToolType, out drawingPropertiesList);
  292. if (drawingPropertiesList == null)
  293. {
  294. drawingPropertiesList = drawingPropertiesListClone;
  295. if (!this.drawing)
  296. this.configurationFile = true;
  297. }
  298. pointChangeObject.TryGetValue(this.drawToolType, out SavePointChange);
  299. g.SmoothingMode = SmoothingMode.AntiAlias;
  300. Font textfont = new Font(this.measureRandSquare.font, this.measureRandSquare.fontSize);
  301. Brush textbrush = new SolidBrush(Color.FromArgb(this.measureRandSquare.textColor));
  302. Color color = Color.FromArgb(this.measureRandSquare.lineColor);
  303. Pen pen = new Pen(color, this.measureRandSquare.lineWidth);
  304. //Pen pen = new Pen(color, 1);
  305. pen.DashStyle = (DashStyle)this.measureRandSquare.lineStyle;
  306. if (this.Selected)
  307. {
  308. if (measureRandSquare.chooseStyle != null)
  309. {
  310. textfont = new Font(measureRandSquare.chooseStyle.font, measureRandSquare.chooseStyle.fontSize);
  311. textbrush = new SolidBrush(Color.FromArgb(measureRandSquare.chooseStyle.textColor));
  312. pen = new Pen(Color.FromArgb(measureRandSquare.chooseStyle.lineColor), measureRandSquare.chooseStyle.lineWidth);
  313. pen.DashStyle = (DashStyle)measureRandSquare.chooseStyle.lineStyle;
  314. }
  315. }
  316. if (!this.Selected)
  317. {
  318. this.pointChange = true;
  319. rectangleF1 = new RectangleF();
  320. rectangleF2 = new RectangleF();
  321. rectangleF3 = new RectangleF();
  322. rectangleF4 = new RectangleF();
  323. rectangleF5 = new RectangleF();
  324. rectangleF6 = new RectangleF();
  325. rectangleF7 = new RectangleF();
  326. rectangleF8 = new RectangleF();
  327. rectangleF9 = new RectangleF();
  328. rectangleF10 = new RectangleF();
  329. rectangleF11 = new RectangleF();
  330. }
  331. Matrix mtxSave = g.Transform;
  332. Matrix matrix = g.Transform;
  333. string frontStr = string.Empty;
  334. if (this.measureRandSquare.showSuffix)
  335. {
  336. frontStr = this.measureRandSquare.suffixName;
  337. }
  338. if (this.measureRandSquare.showSerial)
  339. {
  340. #region [获取序号]
  341. List<DrawObject> newGraphicsList = new List<DrawObject>();
  342. int n = ISurfaceBox.GraphicsList.Count;
  343. int num = 0;
  344. for (int i = n - 1; i >= 0; i--)
  345. {
  346. newGraphicsList.Add(ISurfaceBox.GraphicsList[i].Clone());
  347. }
  348. var newGraphics = newGraphicsList.Where(m => m.ID.Equals(this.ID)).FirstOrDefault();
  349. if (newGraphics != null)
  350. {
  351. num = newGraphicsList.IndexOf(newGraphics) + 1;
  352. }
  353. #endregion
  354. frontStr = $"[{ num }]{frontStr}";
  355. }
  356. if (this.measureRandSquare.showAlias)
  357. {
  358. frontStr = this.measureRandSquare.aliasName + frontStr;
  359. }
  360. if (pointArray.Count > 3)
  361. {
  362. SizeF sizeF = new SizeF();
  363. g.DrawLine(pen, pointArray[0].X, pointArray[0].Y, pointArray[2].X, pointArray[2].Y);
  364. g.DrawLine(pen, pointArray[2].X, pointArray[2].Y, pointArray[1].X, pointArray[1].Y);
  365. g.DrawLine(pen, pointArray[1].X, pointArray[1].Y, pointArray[3].X, pointArray[3].Y);
  366. g.DrawLine(pen, pointArray[3].X, pointArray[3].Y, pointArray[0].X, pointArray[0].Y);
  367. // 计算矩形长和宽
  368. double h = BasicCalculationHelper.GetDistance(pointArray[0], pointArray[2], 10);
  369. double w = BasicCalculationHelper.GetDistance(pointArray[0], pointArray[3], 10);
  370. length = (h + w) * 2;
  371. area = h * w;
  372. // 是否绘制
  373. if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
  374. {
  375. // 属性文本的间隔定义
  376. int offsetValue = measureRandSquare.fontSize + measureRandSquare.fontSize / 2;
  377. int offsetValue1 = measureRandSquare.lineWidth * 2 / 3;
  378. int offset = offsetValue1;
  379. this.pointL = new Point((int)pointArray[0].X, (int)pointArray[0].Y);
  380. if (drawingPropertiesList != null)
  381. {
  382. // 像素周长
  383. if (drawingPropertiesList.Contains(MeasureAttributes.PixelCircumference.ToString()))
  384. {
  385. sizeF = g.MeasureString(frontStr + "" + Math.Round(this.length, decimalPlaces) + "px", textfont);
  386. rectangleF10.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  387. offset += offsetValue;
  388. }
  389. // 物理周长
  390. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCircumference.ToString()))
  391. {
  392. string s = Math.Round(this.length * unitLength, decimalPlaces).ToString();
  393. if (s.IndexOf(".") == -1)
  394. {
  395. for (int i = 0; i < decimalPlaces; i++)
  396. {
  397. if (i == 0)
  398. s += ".";
  399. s += "0";
  400. }
  401. }
  402. else
  403. {
  404. int a = s.Length - s.IndexOf(".") - 1;
  405. if (a < decimalPlaces)
  406. {
  407. for (int i = 0; i < decimalPlaces - a; i++)
  408. {
  409. s += "0";
  410. }
  411. }
  412. }
  413. sizeF = g.MeasureString(frontStr + s + this.unit, textfont);
  414. rectangleF11.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  415. offset += offsetValue;
  416. }
  417. // 像素面积
  418. if (drawingPropertiesList.Contains(MeasureAttributes.PixelArea.ToString()))
  419. {
  420. sizeF = g.MeasureString(frontStr + "" + Math.Round(this.area, decimalPlaces) + "px²", textfont);
  421. rectangleF8.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  422. offset += offsetValue;
  423. }
  424. // 物理面积
  425. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalArea.ToString()))
  426. {
  427. string s = Math.Round(this.area * unitLength, decimalPlaces).ToString();
  428. if (s.IndexOf(".") == -1)
  429. {
  430. for (int i = 0; i < decimalPlaces; i++)
  431. {
  432. if (i == 0)
  433. s += ".";
  434. s += "0";
  435. }
  436. }
  437. else
  438. {
  439. int a = s.Length - s.IndexOf(".") - 1;
  440. if (a < decimalPlaces)
  441. {
  442. for (int i = 0; i < decimalPlaces - a; i++)
  443. {
  444. s += "0";
  445. }
  446. }
  447. }
  448. sizeF = g.MeasureString(frontStr + s + this.unit + "²", textfont);
  449. rectangleF9.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  450. offset += offsetValue;
  451. }
  452. // 测量方式
  453. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
  454. {
  455. sizeF = g.MeasureString(frontStr + "" + PdnResources.GetString("Menu.MeasureAction.PolygonMeasurement.Text"), textfont);
  456. rectangleF1.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  457. offset += offsetValue;
  458. }
  459. // 测量单位(中文)
  460. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
  461. {
  462. sizeF = g.MeasureString(frontStr + "" + this.unitString, textfont);
  463. rectangleF2.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  464. offset += offsetValue;
  465. }
  466. // 测量单位(英文)
  467. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
  468. {
  469. sizeF = g.MeasureString(frontStr + "" + this.unit, textfont);
  470. rectangleF3.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  471. offset += offsetValue;
  472. }
  473. // 像素起始点X
  474. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))
  475. {
  476. sizeF = g.MeasureString(frontStr + "" + startPoint.X, textfont);
  477. rectangleF4.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  478. offset += offsetValue;
  479. }
  480. // 像素起始点Y
  481. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))
  482. {
  483. sizeF = g.MeasureString(frontStr + "" + startPoint.Y, textfont);
  484. rectangleF5.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  485. offset += offsetValue;
  486. }
  487. // 物理起始点X
  488. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))
  489. {
  490. sizeF = g.MeasureString(frontStr + "" + Math.Round(startPoint.X * unitLength, decimalPlaces), textfont);
  491. rectangleF6.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  492. offset += offsetValue;
  493. }
  494. // 物理起始点Y
  495. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))
  496. {
  497. sizeF = g.MeasureString(frontStr + "" + Math.Round(startPoint.Y * unitLength, decimalPlaces), textfont);
  498. rectangleF7.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  499. offset += offsetValue;
  500. }
  501. }
  502. }
  503. if (drawingPropertiesList != null)
  504. {
  505. // 测量方式
  506. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
  507. {
  508. sizeF = g.MeasureString(frontStr + "" + PdnResources.GetString("Menu.MeasureAction.PolygonMeasurement.Text"), textfont);
  509. rectangleF1.Width = sizeF.Width;
  510. rectangleF1.Height = sizeF.Height;
  511. g.DrawString(frontStr + "" + PdnResources.GetString("Menu.MeasureAction.PolygonMeasurement.Text"), textfont, textbrush, rectangleF1);
  512. }
  513. else
  514. {
  515. rectangleF1 = new RectangleF();
  516. }
  517. // 测量单位(中文)
  518. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
  519. {
  520. sizeF = g.MeasureString(frontStr + "" + this.unitString, textfont);
  521. rectangleF2.Width = sizeF.Width;
  522. rectangleF2.Height = sizeF.Height;
  523. g.DrawString(frontStr + "" + this.unitString, textfont, textbrush, rectangleF2);
  524. }
  525. else
  526. {
  527. rectangleF2 = new RectangleF();
  528. }
  529. // 测量单位(英文)
  530. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
  531. {
  532. sizeF = g.MeasureString(frontStr + "" + this.unit, textfont);
  533. rectangleF3.Width = sizeF.Width;
  534. rectangleF3.Height = sizeF.Height;
  535. g.DrawString(frontStr + "" + this.unit, textfont, textbrush, rectangleF3);
  536. }
  537. else
  538. {
  539. rectangleF3 = new RectangleF();
  540. }
  541. // 像素起始点X
  542. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))
  543. {
  544. sizeF = g.MeasureString(frontStr + "" + startPoint.X, textfont);
  545. rectangleF4.Width = sizeF.Width;
  546. rectangleF4.Height = sizeF.Height;
  547. g.DrawString(frontStr + "" + startPoint.X, textfont, textbrush, rectangleF4);
  548. }
  549. else
  550. {
  551. rectangleF4 = new RectangleF();
  552. }
  553. // 像素起始点Y
  554. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))
  555. {
  556. sizeF = g.MeasureString(frontStr + "" + startPoint.Y, textfont);
  557. rectangleF5.Width = sizeF.Width;
  558. rectangleF5.Height = sizeF.Height;
  559. g.DrawString(frontStr + "" + startPoint.Y, textfont, textbrush, rectangleF5);
  560. }
  561. else
  562. {
  563. rectangleF5 = new RectangleF();
  564. }
  565. // 物理起始点X
  566. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))
  567. {
  568. sizeF = g.MeasureString(frontStr + "" + Math.Round(startPoint.X * unitLength, decimalPlaces), textfont);
  569. rectangleF6.Width = sizeF.Width;
  570. rectangleF6.Height = sizeF.Height;
  571. g.DrawString(frontStr + "" + Math.Round(startPoint.X * unitLength, decimalPlaces), textfont, textbrush, rectangleF6);
  572. }
  573. else
  574. {
  575. rectangleF6 = new RectangleF();
  576. }
  577. // 物理起始点Y
  578. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))
  579. {
  580. sizeF = g.MeasureString(frontStr + "" + Math.Round(startPoint.Y * unitLength, decimalPlaces), textfont);
  581. rectangleF7.Width = sizeF.Width;
  582. rectangleF7.Height = sizeF.Height;
  583. g.DrawString(frontStr + "" + Math.Round(startPoint.Y * unitLength, decimalPlaces), textfont, textbrush, rectangleF7);
  584. }
  585. else
  586. {
  587. rectangleF7 = new RectangleF();
  588. }
  589. // 像素面积
  590. if (drawingPropertiesList.Contains(MeasureAttributes.PixelArea.ToString()))
  591. {
  592. sizeF = g.MeasureString("" + Math.Round(this.area, decimalPlaces) + "px²", textfont);
  593. rectangleF8.Width = sizeF.Width;
  594. rectangleF8.Height = sizeF.Height;
  595. g.DrawString(frontStr + "" + Math.Round(this.area, decimalPlaces) + "px²", textfont, textbrush, rectangleF8);
  596. }
  597. else
  598. {
  599. rectangleF8 = new RectangleF();
  600. }
  601. // 物理面积
  602. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalArea.ToString()))
  603. {
  604. string s = Math.Round(this.area * unitLength, decimalPlaces).ToString();
  605. if (s.IndexOf(".") == -1)
  606. {
  607. for (int i = 0; i < decimalPlaces; i++)
  608. {
  609. if (i == 0)
  610. s += ".";
  611. s += "0";
  612. }
  613. }
  614. else
  615. {
  616. int a = s.Length - s.IndexOf(".") - 1;
  617. if (a < decimalPlaces)
  618. {
  619. for (int i = 0; i < decimalPlaces - a; i++)
  620. {
  621. s += "0";
  622. }
  623. }
  624. }
  625. sizeF = g.MeasureString(frontStr + s + this.unit + "²", textfont);
  626. rectangleF9.Width = sizeF.Width;
  627. rectangleF9.Height = sizeF.Height;
  628. g.DrawString(frontStr + s + this.unit + "²", textfont, textbrush, rectangleF9);
  629. }
  630. else
  631. {
  632. rectangleF9 = new RectangleF();
  633. }
  634. // 像素周长
  635. if (drawingPropertiesList.Contains(MeasureAttributes.PixelCircumference.ToString()))
  636. {
  637. sizeF = g.MeasureString(frontStr + "" + Math.Round(this.length, decimalPlaces) + "px", textfont);
  638. rectangleF10.Width = sizeF.Width;
  639. rectangleF10.Height = sizeF.Height;
  640. g.DrawString(frontStr + "" + Math.Round(this.length, decimalPlaces) + "px", textfont, textbrush, rectangleF10);
  641. }
  642. else
  643. {
  644. rectangleF10 = new RectangleF();
  645. }
  646. // 物理周长
  647. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCircumference.ToString()))
  648. {
  649. string s = Math.Round(this.length * unitLength, decimalPlaces).ToString();
  650. if (s.IndexOf(".") == -1)
  651. {
  652. for (int i = 0; i < decimalPlaces; i++)
  653. {
  654. if (i == 0)
  655. s += ".";
  656. s += "0";
  657. }
  658. }
  659. else
  660. {
  661. int a = s.Length - s.IndexOf(".") - 1;
  662. if (a < decimalPlaces)
  663. {
  664. for (int i = 0; i < decimalPlaces - a; i++)
  665. {
  666. s += "0";
  667. }
  668. }
  669. }
  670. sizeF = g.MeasureString(frontStr + s + this.unit, textfont);
  671. rectangleF11.Width = sizeF.Width;
  672. rectangleF11.Height = sizeF.Height;
  673. g.DrawString(frontStr + s + this.unit, textfont, textbrush, rectangleF11);
  674. }
  675. else
  676. {
  677. rectangleF11 = new RectangleF();
  678. }
  679. //还原为原始旋转矩阵
  680. g.Transform = mtxSave;
  681. }
  682. }
  683. matrix.Dispose();
  684. if (this.configurationFile)
  685. this.pointChange = false;
  686. this.mouseUpAttribute = false;
  687. pointChangeObject.Remove(this.drawToolType);
  688. }
  689. }
  690. /// <summary>
  691. /// 停止绘制时
  692. /// </summary>
  693. /// <param name="up"></param>
  694. public override void MouseUp(bool up)
  695. {
  696. mouseUpPointChange = up;
  697. }
  698. public void CalcCenter()
  699. {
  700. centerPoint = new PointF(rectangle.X + rectangle.Width / 2, rectangle.Y + rectangle.Height / 2);//中心点
  701. }
  702. public override int HandleCount
  703. {
  704. get
  705. {
  706. return 7;
  707. }
  708. }
  709. /// <summary>
  710. /// Get handle pointscroll by 1-based number
  711. /// </summary>
  712. /// <param name="handleNumber"></param>
  713. /// <returns></returns>
  714. public override PointF GetHandle(int handleNumber)
  715. {
  716. float x = 0;
  717. float y = 0;
  718. switch (handleNumber)
  719. {
  720. case 1:
  721. x = (int)pointArray[0].X;
  722. y = (int)pointArray[0].Y;
  723. break;
  724. case 2:
  725. x = (int)pointArray[1].X;
  726. y = (int)pointArray[1].Y;
  727. break;
  728. case 3:
  729. x = largerRect.X;
  730. y = largerRect.Y;
  731. break;
  732. case 4:
  733. x = largerRect.Right;
  734. y = largerRect.Y;
  735. break;
  736. case 5:
  737. x = largerRect.Right;
  738. y = largerRect.Bottom;
  739. break;
  740. case 6:
  741. x = largerRect.X;
  742. y = largerRect.Bottom;
  743. break;
  744. case 7:
  745. x = this.pointL.X;
  746. y = this.pointL.Y;
  747. break;
  748. }
  749. return new PointF(x, y);
  750. }
  751. /// <summary>
  752. /// Hit test.
  753. /// Return value: -1 - no hit
  754. /// 0 - hit anywhere
  755. /// > 1 - handle number
  756. /// </summary>
  757. /// <param name="pointscroll"></param>
  758. /// <returns></returns>
  759. public override int HitTest(Point point)
  760. {
  761. if (Selected)
  762. {
  763. for (int i = 1; i <= HandleCount; i++)
  764. {
  765. if (GetHandleRectangle(i).Contains(point))
  766. return i;
  767. }
  768. if (GetRectanglePosition(this.rectangleF1, point, this.PointF , angle))
  769. {
  770. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  771. moveKb = 1;
  772. return 7;
  773. }
  774. else if (GetRectanglePosition(this.rectangleF2, point, this.PointF , angle))
  775. {
  776. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  777. moveKb = 2;
  778. return 7;
  779. }
  780. else if (GetRectanglePosition(this.rectangleF3, point, this.PointF , angle))
  781. {
  782. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  783. moveKb = 3;
  784. return 7;
  785. }
  786. else if (GetRectanglePosition(this.rectangleF4, point, this.PointF , angle))
  787. {
  788. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  789. moveKb = 4;
  790. return 7;
  791. }
  792. else if (GetRectanglePosition(this.rectangleF5, point, this.PointF , angle))
  793. {
  794. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  795. moveKb = 5;
  796. return 7;
  797. }
  798. else if (GetRectanglePosition(this.rectangleF6, point, this.PointF , angle))
  799. {
  800. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  801. moveKb = 6;
  802. return 7;
  803. }
  804. else if (GetRectanglePosition(this.rectangleF7, point, this.PointF , angle))
  805. {
  806. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  807. moveKb = 7;
  808. return 7;
  809. }
  810. else if (GetRectanglePosition(this.rectangleF8, point, this.PointF , angle))
  811. {
  812. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  813. moveKb = 8;
  814. return 7;
  815. }
  816. else if (GetRectanglePosition(this.rectangleF9, point, this.PointF , angle))
  817. {
  818. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  819. moveKb = 9;
  820. return 7;
  821. }
  822. else if (GetRectanglePosition(this.rectangleF10, point, this.PointF , angle))
  823. {
  824. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  825. moveKb = 10;
  826. return 7;
  827. }
  828. else if (GetRectanglePosition(this.rectangleF11, point, this.PointF , angle))
  829. {
  830. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  831. moveKb = 11;
  832. return 7;
  833. }
  834. }
  835. if (PointInObject(point))
  836. return 0;
  837. return -1;
  838. }
  839. protected override bool PointInObject(Point point)
  840. {
  841. return largerRect.Contains(point);
  842. }
  843. public override bool IntersectsWith(Rectangle rectangle)
  844. {
  845. return largerRect.IntersectsWith(rectangle);
  846. }
  847. public override Cursor GetHandleCursor(int handleNumber)
  848. {
  849. return handleCursor;
  850. }
  851. public override void MoveHandleTo(Point point, int handleNumber)
  852. {
  853. if (handleNumber < 3)
  854. {
  855. this.mouseUpPointChange = true;
  856. switch (handleNumber)
  857. {
  858. case 1:
  859. this.rectangleF1.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  860. this.rectangleF2.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  861. this.rectangleF3.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  862. this.rectangleF4.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  863. this.rectangleF5.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  864. this.rectangleF6.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  865. this.rectangleF7.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  866. this.rectangleF8.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  867. this.rectangleF9.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  868. this.rectangleF10.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  869. this.rectangleF11.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  870. //更新第一个点
  871. startPoint = point;
  872. this.pointArray[0] = startPoint;
  873. //计算第三个点
  874. linePoint.X = (startPoint.X - startPoint.Y + endPoint.X + endPoint.Y) / 2;
  875. linePoint.Y = (startPoint.X + startPoint.Y - endPoint.X + endPoint.Y) / 2;
  876. this.pointArray[2] = linePoint;
  877. //计算第四个点
  878. linePoint1.X = (startPoint.X + startPoint.Y + endPoint.X - endPoint.Y) / 2;
  879. linePoint1.Y = (-(startPoint.X) + startPoint.Y + endPoint.X + endPoint.Y) / 2;
  880. this.pointArray[3] = linePoint1;
  881. break;
  882. case 2:
  883. endPoint = point;
  884. this.pointArray[1] = endPoint;
  885. //计算第三个点
  886. linePoint.X = (startPoint.X - startPoint.Y + endPoint.X + endPoint.Y) / 2;
  887. linePoint.Y = (startPoint.X + startPoint.Y - endPoint.X + endPoint.Y) / 2;
  888. if (this.pointArray.Count == 2)
  889. {
  890. this.pointArray.Add(linePoint);
  891. }
  892. else
  893. {
  894. this.pointArray[2] = linePoint;
  895. }
  896. //计算第四个点
  897. linePoint1.X = (startPoint.X + startPoint.Y + endPoint.X - endPoint.Y) / 2;
  898. linePoint1.Y = (-(startPoint.X) + startPoint.Y + endPoint.X + endPoint.Y) / 2;
  899. if (this.pointArray.Count == 3)
  900. {
  901. this.pointArray.Add(linePoint1);
  902. }
  903. else
  904. {
  905. this.pointArray[3] = linePoint1;
  906. }
  907. break;
  908. }
  909. if(this.pointArray.Count == 4)
  910. {
  911. CalcOtherRectangle();
  912. CalcCenter();
  913. }
  914. }
  915. else
  916. {
  917. float x = 0, y = 0;
  918. switch (handleNumber)
  919. {
  920. case 3:
  921. this.mouseUpPointChange = true;
  922. x = largerRect.X;
  923. y = largerRect.Y;
  924. break;
  925. case 4:
  926. this.mouseUpPointChange = true;
  927. x = largerRect.Right;
  928. y = largerRect.Y;
  929. break;
  930. case 5:
  931. this.mouseUpPointChange = true;
  932. x = largerRect.Right;
  933. y = largerRect.Bottom;
  934. break;
  935. case 6:
  936. this.mouseUpPointChange = true;
  937. x = largerRect.X;
  938. y = largerRect.Bottom;
  939. break;
  940. case 7:
  941. point = SetOffsetAfterRotation(point, this.PointF, angle);
  942. if (this.moveKb == 1)
  943. this.rectangleF1.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  944. else if (this.moveKb == 2)
  945. this.rectangleF2.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  946. else if (this.moveKb == 3)
  947. this.rectangleF3.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  948. else if (this.moveKb == 4)
  949. this.rectangleF4.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  950. else if (this.moveKb == 5)
  951. this.rectangleF5.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  952. else if (this.moveKb == 6)
  953. this.rectangleF6.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  954. else if (this.moveKb == 7)
  955. this.rectangleF7.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  956. else if (this.moveKb == 8)
  957. this.rectangleF8.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  958. else if (this.moveKb == 9)
  959. this.rectangleF9.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  960. else if (this.moveKb == 10)
  961. this.rectangleF10.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  962. else if (this.moveKb == 11)
  963. this.rectangleF11.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  964. this.pointL = point;
  965. break;
  966. }
  967. if(handleNumber != 7)
  968. {
  969. this.mouseUpPointChange = true;
  970. if (!this.isPress)
  971. {
  972. this.isPress = true;
  973. lastPoint = new PointF(x, y);
  974. }
  975. double angle = BasicCalculationHelper.CalculateAngle(centerPoint.X, centerPoint.Y, lastPoint.X, lastPoint.Y, point.X, point.Y);
  976. lastPoint = point;
  977. for (int l = 0; l < pointArray.Count; l++)
  978. {
  979. pointArray[l] = BasicCalculationHelper.GetAnglePoint(pointArray[l], centerPoint, angle);
  980. }
  981. startPoint = BasicCalculationHelper.GetAnglePoint(startPoint, centerPoint, angle);
  982. endPoint = BasicCalculationHelper.GetAnglePoint(endPoint, centerPoint, angle);
  983. linePoint = BasicCalculationHelper.GetAnglePoint(linePoint, centerPoint, angle);
  984. linePoint1 = BasicCalculationHelper.GetAnglePoint(linePoint1, centerPoint, angle);
  985. CalcOtherRectangle();
  986. }
  987. }
  988. }
  989. /// <summary>
  990. /// 计算外接矩形
  991. /// </summary>
  992. private void CalcOtherRectangle()
  993. {
  994. float[] pointX = new float[] { pointArray[0].X, pointArray[1].X, pointArray[2].X, pointArray[3].X };
  995. rectangle.X = (int)pointX.Min();
  996. float[] pointY = new float[] { pointArray[0].Y, pointArray[1].Y, pointArray[2].Y, pointArray[3].Y };
  997. rectangle.Y = (int)pointY.Min();
  998. rectangle.Width = (int)Math.Abs(pointX.Max() - pointX.Min());
  999. rectangle.Height = (int)Math.Abs(pointY.Max() - pointY.Min());
  1000. }
  1001. /// <summary>
  1002. /// 对象移动
  1003. /// </summary>
  1004. /// <param name="deltaX"></param>
  1005. /// <param name="deltaY"></param>
  1006. public override void Move(int deltaX, int deltaY)
  1007. {
  1008. int x = ISurfaceBox.UnscaleScalar(deltaX);
  1009. int y = ISurfaceBox.UnscaleScalar(deltaY);
  1010. startPoint.X += x;
  1011. startPoint.Y += y;
  1012. endPoint.X += x;
  1013. endPoint.Y += y;
  1014. linePoint.X += x;
  1015. linePoint.Y += y;
  1016. linePoint1.X += x;
  1017. linePoint1.Y += y;
  1018. for (int i = 0; i < pointArray.Count; i++)
  1019. {
  1020. pointArray[i] = new PointF(pointArray[i].X + ISurfaceBox.UnscaleScalar(deltaX), pointArray[i].Y + ISurfaceBox.UnscaleScalar(deltaY));
  1021. }
  1022. this.startPoint = pointArray[0];
  1023. pointL.X += x;
  1024. pointL.Y += y;
  1025. this.rectangleF1.Offset(x, y);
  1026. this.rectangleF2.Offset(x, y);
  1027. this.rectangleF3.Offset(x, y);
  1028. this.rectangleF4.Offset(x, y);
  1029. this.rectangleF5.Offset(x, y);
  1030. this.rectangleF6.Offset(x, y);
  1031. this.rectangleF7.Offset(x, y);
  1032. this.rectangleF8.Offset(x, y);
  1033. this.rectangleF9.Offset(x, y);
  1034. this.rectangleF10.Offset(x, y);
  1035. this.rectangleF11.Offset(x, y);
  1036. CalcOtherRectangle();
  1037. CalcCenter();
  1038. }
  1039. public override RectangleF GetBoundingBox()
  1040. {
  1041. RectangleF temp = new RectangleF();
  1042. temp.X = rectangle.X - 10;
  1043. temp.Y = rectangle.Y - 10;
  1044. temp.Width = rectangle.Width + 20;
  1045. temp.Height = rectangle.Height + 20;
  1046. return temp;
  1047. }
  1048. /// <summary>
  1049. /// Draw tracker for selected object
  1050. /// </summary>
  1051. /// <param name="g"></param>
  1052. public override void DrawTracker(Graphics g)
  1053. {
  1054. if (!Selected)
  1055. return;
  1056. if (pointArray.Count >= 4)
  1057. {
  1058. SolidBrush brush = new SolidBrush(Color.FromArgb(MarkpointAreaColor));
  1059. Pen pen = new Pen(Color.FromArgb(MarkpointLineColor), MarkpointLineWidth);
  1060. largerRect = GetBoundingBox();
  1061. for (int i = 1; i <= HandleCount; i++)
  1062. {
  1063. if (i == HandleCount)
  1064. {
  1065. brush = new SolidBrush(Color.Transparent);
  1066. pen = new Pen(Color.Transparent);
  1067. }
  1068. switch (MarkpointStyle)
  1069. {
  1070. case 0:
  1071. g.FillRectangle(brush, GetHandleRectangle(i));
  1072. g.DrawRectangle(pen, GetHandleRectangle(i));
  1073. break;
  1074. case 1:
  1075. g.FillEllipse(brush, GetHandleRectangle(i));
  1076. g.DrawEllipse(pen, GetHandleRectangle(i));
  1077. break;
  1078. case 2:
  1079. g.FillPolygon(brush, GetHandlePoint(i));
  1080. g.DrawPolygon(pen, GetHandlePoint(i));
  1081. break;
  1082. }
  1083. }
  1084. brush.Dispose();
  1085. pen.Dispose();
  1086. }
  1087. }
  1088. /// <summary>
  1089. /// 获取点集合
  1090. /// </summary>
  1091. /// <returns></returns>
  1092. public override List<PointF> GetPoints()
  1093. {
  1094. return pointArray;
  1095. }
  1096. /// <summary>
  1097. /// 获取样式
  1098. /// </summary>
  1099. /// <returns></returns>
  1100. public override ParentStyleModel GetStyle()
  1101. {
  1102. return measureRandSquare;
  1103. }
  1104. }
  1105. }