MeasureHMulPLine.cs 61 KB

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