MeasureMulLine.cs 62 KB

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