MeasureMulSegment.cs 56 KB

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