MeasureMulHVLine.cs 53 KB

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