MeasureMulSegment.cs 52 KB

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