MeasureMulPLine.cs 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  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 MeasureMulPLine : 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 double angle;
  76. private double angleP;
  77. private int num = 0;
  78. /// <summary>
  79. /// 属性绘制点
  80. /// </summary>
  81. private PointF rotationPoint;
  82. private PointF rotationPoint1;
  83. /// <summary>
  84. /// 限制绘制(绘制中)
  85. /// </summary>
  86. public bool mouseUpPointChange = false;
  87. /// <summary>
  88. /// 测量样式信息model
  89. /// </summary>
  90. private MeasureStyleModel.MeasureMulPLine measureStyleModel;
  91. public MeasureStyleModel.MeasureMulPLine MeasureStyleModel
  92. {
  93. set
  94. {
  95. this.measureStyleModel = value;
  96. }
  97. }
  98. public MeasureMulPLine(ISurfaceBox surfaceBox, int x1, int y1, bool clone) : base(surfaceBox)
  99. {
  100. this.objectType = DrawClass.Measure;
  101. this.drawToolType = DrawToolType.MeasureMulPLine;
  102. measureStyleModel = surfaceBox.GetMeasureStyleModel().measureMulPLine;
  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 i = 0; i < decimalPlaces; i++)
  158. {
  159. if (i == 0)
  160. s += ".";
  161. s += "0";
  162. }
  163. }
  164. else
  165. {
  166. int a = s.Length - s.IndexOf(".") - 1;
  167. if (a < decimalPlaces)
  168. {
  169. for (int i = 0; i < decimalPlaces - a; i++)
  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 - 2), decimalPlaces);
  181. else
  182. data.Add(MeasureAttributes.PixelAverageIntercept, Math.Round(Length / (pointArray.Count - 2), decimalPlaces));
  183. s = Math.Round(Length / (pointArray.Count - 2) * 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 MeasureMulPLine(ISurfaceBox surfaceBox, List<PointF> points, ParentStyleModel parentStyleModel, Object content) : base()
  211. {
  212. this.objectType = DrawClass.Measure;
  213. this.drawToolType = DrawToolType.MeasureMulPLine;
  214. this.ISurfaceBox = surfaceBox;
  215. measureStyleModel = (MeasureStyleModel.MeasureMulPLine)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. MeasureMulPLine drawPolygon = new MeasureMulPLine(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. MeasureMulPLine drawPolygon = new MeasureMulPLine(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. public override void Draw(Graphics g)
  257. {
  258. lengthParagraphs = new List<string>();
  259. drawingProperties.TryGetValue(this.drawToolType, out drawingPropertiesList);
  260. if (drawingPropertiesList == null)
  261. {
  262. drawingPropertiesList = drawingPropertiesListClone;
  263. if (!this.drawing)
  264. this.configurationFile = true;
  265. }
  266. pointChangeObject.TryGetValue(this.drawToolType, out SavePointChange);
  267. // 总长度
  268. double allLengh = 0.0;
  269. Font textfont1 = new Font(measureStyleModel.font, measureStyleModel.fontSize);
  270. Brush textbrush1 = new SolidBrush(Color.FromArgb(measureStyleModel.textColor));
  271. SizeF sizeF = new SizeF();
  272. measureStyleModel = this.ISurfaceBox.GetMeasureStyleModel().measureMulPLine;
  273. int a1 = 0;
  274. int a2 = 1;
  275. int a3 = 2;
  276. int a4 = 3;
  277. int a5 = 4;
  278. int a6 = 5;
  279. RectangleF rectangleF;
  280. string frontStr = string.Empty;
  281. if (this.measureStyleModel.showSuffix)
  282. {
  283. frontStr = this.measureStyleModel.suffixName;
  284. }
  285. if (this.measureStyleModel.showSerial)
  286. {
  287. #region [获取序号]
  288. List<DrawObject> newGraphicsList = new List<DrawObject>();
  289. int n = ISurfaceBox.GraphicsList.Count;
  290. int num = 0;
  291. for (int i = n - 1; i >= 0; i--)
  292. {
  293. newGraphicsList.Add(ISurfaceBox.GraphicsList[i].Clone());
  294. }
  295. var newGraphics = newGraphicsList.Where(m => m.ID.Equals(this.ID)).FirstOrDefault();
  296. if (newGraphics != null)
  297. {
  298. num = newGraphicsList.IndexOf(newGraphics) + 1;
  299. }
  300. #endregion
  301. frontStr = $"[{ num }]{frontStr}";
  302. }
  303. if (this.measureStyleModel.showAlias)
  304. {
  305. frontStr = this.measureStyleModel.aliasName + frontStr;
  306. }
  307. // 连续绘制
  308. for (int a = 1; a <= HandleCount - 2; a++)
  309. {
  310. if (HandleCount - 1 >= 2)
  311. {
  312. Font textfont = new Font(measureStyleModel.font, measureStyleModel.fontSize);
  313. Brush textbrush = new SolidBrush(Color.FromArgb(measureStyleModel.textColor));
  314. g.SmoothingMode = SmoothingMode.AntiAlias;
  315. Color color = Color.FromArgb(this.measureStyleModel.lineColor);
  316. Pen pen = new Pen(color, this.measureStyleModel.lineWidth);
  317. pen.DashStyle = (DashStyle)this.measureStyleModel.lineStyle;
  318. if (this.Selected)
  319. {
  320. if (measureStyleModel.chooseStyle != null)
  321. {
  322. textfont = new Font(measureStyleModel.chooseStyle.font, measureStyleModel.chooseStyle.fontSize);
  323. textbrush = new SolidBrush(Color.FromArgb(measureStyleModel.chooseStyle.textColor));
  324. pen = new Pen(Color.FromArgb(measureStyleModel.chooseStyle.lineColor), measureStyleModel.chooseStyle.lineWidth);
  325. pen.DashStyle = (DashStyle)measureStyleModel.chooseStyle.lineStyle;
  326. }
  327. }
  328. if (!this.Selected)
  329. {
  330. this.pointChange = true;
  331. rectangleF1 = new RectangleF();
  332. rectangleF2 = new RectangleF();
  333. rectangleF3 = new RectangleF();
  334. rectangleF4 = new RectangleF();
  335. rectangleF5 = new RectangleF();
  336. }
  337. double length1 = 0.0;
  338. Matrix mtxSave = g.Transform;
  339. Matrix matrix = g.Transform;
  340. length1 = BasicCalculationHelper.GetDistance(pointArray[1], pointArray[0], 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. // 垂足坐标
  348. PointF footPoint = new PointF();
  349. footPoint = BasicCalculationHelper.GetDropFeet(pointArray[1], pointArray[0], pointArray[a]);
  350. //计算需要旋转的角度
  351. //double angleRotate = BasicCalculationHelper.Angle(pointArray[0], pointArray[1], new PointF(pointArray[0].X, pointArray[1].Y));
  352. // 点到直线距离
  353. double length = BasicCalculationHelper.GetDistance(footPoint, pointArray[a], 2);
  354. double angle = Math.Round(BasicCalculationHelper.AngleText(pointArray[0],
  355. pointArray[1], new PointF(pointArray[0].X + 10, pointArray[0].Y)), 2);
  356. double angle1 = 0.0;
  357. // 判断第一个点象限
  358. float x1 = pointArray[0].X - pointArray[1].X;
  359. if (x1 == 0)
  360. x1 = 1;
  361. float y1 = pointArray[0].Y - pointArray[1].Y;
  362. if (y1 == 0)
  363. y1 = 1;
  364. int j1 = 0;
  365. if (x1 > 0 && y1 > 0) //第4象限
  366. {
  367. j1 = 4;
  368. }
  369. else if (x1 > 0 && y1 < 0) //第1象限
  370. {
  371. j1 = 1;
  372. }
  373. else if (x1 < 0 && y1 < 0) //第2象限
  374. {
  375. j1 = 2;
  376. }
  377. else if (x1 < 0 && y1 > 0) //第3象限
  378. {
  379. j1 = 3;
  380. }
  381. // 判断第三个点象限
  382. float x3 = pointArray[a].X - pointArray[1].X;
  383. if (x3 == 0)
  384. x3 = 1;
  385. float y3 = pointArray[a].Y - pointArray[1].Y;
  386. if (y3 == 0)
  387. y3 = 1;
  388. int j3 = 0;
  389. if (x3 > 0 && y3 > 0) //第4象限
  390. {
  391. j3 = 4;
  392. }
  393. else if (x3 > 0 && y3 < 0) //第1象限
  394. {
  395. j3 = 1;
  396. }
  397. else if (x3 < 0 && y3 < 0) //第2象限
  398. {
  399. j3 = 2;
  400. }
  401. else if (x3 < 0 && y3 > 0) //第3象限
  402. {
  403. j3 = 3;
  404. }
  405. if (j1 == 3 || j1 == 4)
  406. {
  407. angle = 360 - angle;
  408. }
  409. double threePointAngle = Math.Round(BasicCalculationHelper.AngleText(pointArray[1],
  410. pointArray[a], pointArray[0]), 2);
  411. // 第一个点于X轴的夹角
  412. double point0ToX = Math.Round(BasicCalculationHelper.AngleText(pointArray[1],
  413. new PointF(pointArray[1].X + 10, pointArray[1].Y), pointArray[0]), 2);
  414. // 第三个点于X轴的夹角
  415. double point2ToX = Math.Round(BasicCalculationHelper.AngleText(pointArray[1],
  416. pointArray[a], new PointF(pointArray[1].X + 10, pointArray[1].Y)), 2);
  417. if (point0ToX > 90)
  418. {
  419. point0ToX = 180 - point0ToX;
  420. }
  421. if (point2ToX > 90)
  422. {
  423. point2ToX = 180 - point2ToX;
  424. }
  425. if ((j1 == 1 && j3 == 1) || (j1 == 2 && j3 == 4)
  426. || (j1 == 3 && j3 == 3) || (j1 == 4 && j3 == 2))
  427. {
  428. if (point0ToX > point2ToX)
  429. {
  430. angle1 = 270;
  431. }
  432. else
  433. {
  434. angle1 = 90;
  435. }
  436. }
  437. else if ((j1 == 1 && j3 == 2) || (j1 == 2 && j3 == 3)
  438. || (j1 == 3 && j3 == 4) || (j1 == 4 && j3 == 1))
  439. {
  440. angle1 = 90;
  441. }
  442. else if (j1 == 1 && j3 == 3 || (j1 == 2 && j3 == 2)
  443. || (j1 == 3 && j3 == 1) || (j1 == 4 && j3 == 4))
  444. {
  445. if (point0ToX > point2ToX)
  446. {
  447. angle1 = 90;
  448. }
  449. else
  450. {
  451. angle1 = 270;
  452. }
  453. }
  454. else if (j1 == 1 && j3 == 4 || (j1 == 2 && j3 == 1)
  455. || (j1 == 3 && j3 == 2) || (j1 == 4 && j3 == 3))
  456. {
  457. angle1 = 270;
  458. }
  459. PointF point = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[0].X + (int)length,
  460. pointArray[0].Y), pointArray[0], angle);
  461. PointF point1 = BasicCalculationHelper.GetAnglePoint(point, pointArray[0], angle1);
  462. double length2 = BasicCalculationHelper.GetDistance(footPoint, pointArray[a], 10);
  463. double length3 = length2;
  464. ////长度文本显示
  465. //g.DrawString(Math.Round(length2 * unitLength, decimalPlaces) + unit, textfont, textbrush, pointArray[a]);
  466. allLengh = allLengh + length2;
  467. int offsetValuePoint = measureStyleModel.fontSize + measureStyleModel.fontSize / 2;
  468. int offsetValue1Point = measureStyleModel.lineWidth * 2 / 3;
  469. int offsetPoint = offsetValue1Point;
  470. if (drawingPropertiesList != null)
  471. {
  472. // 像素长度
  473. if (drawingPropertiesList.Contains(MeasureAttributes.PixelLength.ToString()))
  474. {
  475. offsetPoint += offsetValuePoint;
  476. }
  477. // 物理长度
  478. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalLength.ToString()))
  479. {
  480. offsetPoint += offsetValuePoint;
  481. }
  482. // 像素起始点X
  483. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))
  484. {
  485. offsetPoint += offsetValuePoint;
  486. }
  487. // 像素起始点Y
  488. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))
  489. {
  490. offsetPoint += offsetValuePoint;
  491. }
  492. // 物理起始点X
  493. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))
  494. {
  495. offsetPoint += offsetValuePoint;
  496. }
  497. // 物理起始点Y
  498. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))
  499. {
  500. offsetPoint += offsetValuePoint;
  501. }
  502. }
  503. PointF pointF1;
  504. PointF pointF2;
  505. PointF pointF3;
  506. //计算需要旋转的角度
  507. double angleClass = BasicCalculationHelper.Angle(footPoint, pointArray[a], new PointF(footPoint.X, pointArray[a].Y));
  508. if (angleClass < 90)
  509. pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)footPoint.X + offsetPoint + offsetValue1Point, (int)footPoint.Y), footPoint, angleClass - 90);
  510. else
  511. pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)footPoint.X + offsetPoint + offsetValue1Point, (int)footPoint.Y), footPoint, angleClass + 90);
  512. if (angleClass < 90)
  513. pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[a].X + offsetPoint + offsetValue1Point, (int)pointArray[a].Y), pointArray[a], angleClass - 90);
  514. else
  515. pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[a].X + offsetPoint + offsetValue1Point, (int)pointArray[a].Y), pointArray[a], angleClass + 90);
  516. pointF3 = new PointF((pointF1.X + pointF2.X) / 2, (pointF1.Y + pointF2.Y) / 2);
  517. if (measureStyleModel.linePositionP == 0)
  518. this.rotationPoint1 = pointF1;
  519. else if (measureStyleModel.linePositionP == 1)
  520. this.rotationPoint1 = pointF3;
  521. else if (measureStyleModel.linePositionP == 2)
  522. this.rotationPoint1 = pointF2;
  523. else if (measureStyleModel.linePositionP == 3)
  524. this.rotationPoint1 = footPoint;
  525. else if (measureStyleModel.linePositionP == 4)
  526. this.rotationPoint1 = new PointF((footPoint.X + pointArray[a].X) / 2, (footPoint.Y + pointArray[a].Y) / 2);
  527. else if (measureStyleModel.linePositionP == 5)
  528. this.rotationPoint1 = pointArray[a];
  529. // 画布旋转
  530. if (angleClass < 90)
  531. {
  532. matrix.RotateAt((float)angleClass, this.rotationPoint1);
  533. g.Transform = matrix;
  534. }
  535. else
  536. {
  537. angleClass = BasicCalculationHelper.Angle(pointArray[a], footPoint, new PointF(pointArray[a].X, footPoint.Y));
  538. matrix.RotateAt((float)angleClass, this.rotationPoint1);
  539. g.Transform = matrix;
  540. }
  541. this.angleP = angleClass;
  542. int offsetValue = measureStyleModel.fontSize + measureStyleModel.fontSize / 2;
  543. int offsetValue1 = measureStyleModel.lineWidth * 2 / 3;
  544. int offset = offsetValue1;
  545. if (drawingPropertiesList != null && a > 1)
  546. {
  547. if (drawingPropertiesList.Contains(MeasureAttributes.PixelLength.ToString()))
  548. {
  549. rectangleF = this.RectangleFList[a1];
  550. sizeF = g.MeasureString("" + Math.Round(length3, decimalPlaces) + "px", 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 PointF((int)this.rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint1.Y + offset);
  556. offset += offsetValue;
  557. this.RectangleFList[a1] = rectangleF;
  558. }
  559. g.DrawString("" + Math.Round(length3, decimalPlaces) + "px", textfont1, textbrush1, this.RectangleFList[a1]);
  560. a1 += 6;
  561. }
  562. else
  563. {
  564. this.RectangleFList[a1] = new RectangleF();
  565. a1 += 6;
  566. }
  567. string s = Math.Round(length3 * unitLength, decimalPlaces).ToString();
  568. if (s.IndexOf(".") == -1)
  569. {
  570. for (int i = 0; i < decimalPlaces; i++)
  571. {
  572. if (i == 0)
  573. s += ".";
  574. s += "0";
  575. }
  576. }
  577. else
  578. {
  579. int dic = s.Length - s.IndexOf(".") - 1;
  580. if (dic < decimalPlaces)
  581. {
  582. for (int i = 0; i < decimalPlaces - dic; i++)
  583. {
  584. s += "0";
  585. }
  586. }
  587. }
  588. lengthParagraphs.Add(s);
  589. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalLength.ToString()))
  590. {
  591. rectangleF = this.RectangleFList[a2];
  592. if (a == 2)
  593. {
  594. sizeF = g.MeasureString(frontStr + "" + s + this.unit, textfont1);
  595. }
  596. else
  597. {
  598. sizeF = g.MeasureString("" + s + this.unit, textfont1);
  599. }
  600. rectangleF.Width = sizeF.Width;
  601. rectangleF.Height = sizeF.Height;
  602. if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
  603. {
  604. rectangleF.Location = new PointF((int)this.rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint1.Y + offset);
  605. offset += offsetValue;
  606. this.RectangleFList[a2] = rectangleF;
  607. }
  608. if (a == 2)
  609. {
  610. g.DrawString(frontStr + "" + s + this.unit, textfont1, textbrush1, this.RectangleFList[a2]);
  611. }
  612. else
  613. {
  614. g.DrawString("" + s + this.unit, textfont1, textbrush1, this.RectangleFList[a2]);
  615. }
  616. a2 += 6;
  617. }
  618. else
  619. {
  620. this.RectangleFList[a2] = new RectangleF();
  621. a2 += 6;
  622. }
  623. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))
  624. {
  625. rectangleF = this.RectangleFList[a3];
  626. sizeF = g.MeasureString("" + pointArray[a].X, textfont1);
  627. rectangleF.Width = sizeF.Width;
  628. rectangleF.Height = sizeF.Height;
  629. if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
  630. {
  631. rectangleF.Location = new PointF((int)this.rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint1.Y + offset);
  632. offset += offsetValue;
  633. this.RectangleFList[a3] = rectangleF;
  634. }
  635. g.DrawString("" + pointArray[a].X, textfont1, textbrush1, this.RectangleFList[a3]);
  636. a3 += 6;
  637. }
  638. else
  639. {
  640. this.RectangleFList[a3] = new RectangleF();
  641. a3 += 6;
  642. }
  643. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))
  644. {
  645. rectangleF = this.RectangleFList[a4];
  646. sizeF = g.MeasureString("" + pointArray[a].Y, textfont1);
  647. rectangleF.Width = sizeF.Width;
  648. rectangleF.Height = sizeF.Height;
  649. if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
  650. {
  651. rectangleF.Location = new PointF((int)this.rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint1.Y + offset);
  652. offset += offsetValue;
  653. this.RectangleFList[a4] = rectangleF;
  654. }
  655. g.DrawString("" + pointArray[a].Y, textfont1, textbrush1, this.RectangleFList[a4]);
  656. a4 += 6;
  657. }
  658. else
  659. {
  660. this.RectangleFList[a4] = new RectangleF();
  661. a4 += 6;
  662. }
  663. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))
  664. {
  665. rectangleF = this.RectangleFList[a5];
  666. sizeF = g.MeasureString("" + Math.Round(pointArray[a].X * unitLength, decimalPlaces), textfont1);
  667. rectangleF.Width = sizeF.Width;
  668. rectangleF.Height = sizeF.Height;
  669. if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
  670. {
  671. rectangleF.Location = new PointF((int)this.rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint1.Y + offset);
  672. offset += offsetValue;
  673. this.RectangleFList[a5] = rectangleF;
  674. }
  675. g.DrawString("" + Math.Round(pointArray[a].X * unitLength, decimalPlaces), textfont1, textbrush1, this.RectangleFList[a5]);
  676. a5 += 6;
  677. }
  678. else
  679. {
  680. this.RectangleFList[a5] = new RectangleF();
  681. a5 += 6;
  682. }
  683. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))
  684. {
  685. rectangleF = this.RectangleFList[a6];
  686. sizeF = g.MeasureString("" + Math.Round(pointArray[a].Y * unitLength, decimalPlaces), textfont1);
  687. rectangleF.Width = sizeF.Width;
  688. rectangleF.Height = sizeF.Height;
  689. if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
  690. {
  691. rectangleF.Location = new PointF((int)this.rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint1.Y + offset);
  692. offset += offsetValue;
  693. this.RectangleFList[a6] = rectangleF;
  694. }
  695. g.DrawString("" + Math.Round(pointArray[a].Y * unitLength, decimalPlaces), textfont1, textbrush1, this.RectangleFList[a6]);
  696. a6 += 6;
  697. }
  698. else
  699. {
  700. this.RectangleFList[a6] = new RectangleF();
  701. a6 += 6;
  702. }
  703. }
  704. //还原为原始旋转矩阵
  705. g.Transform = mtxSave;
  706. g.DrawLine(pen, pointArray[0], pointArray[1]);
  707. g.DrawLine(pen, footPoint, pointArray[a]);
  708. pen.Dispose();
  709. matrix.Dispose();
  710. }
  711. }
  712. // 总长度
  713. this.Length = allLengh;
  714. if (pointArray.Count > 1)
  715. {
  716. Matrix mtxSave1 = g.Transform;
  717. Matrix matrix1 = g.Transform;
  718. // 旋转角度
  719. this.angle = BasicCalculationHelper.Angle(pointArray[0], pointArray[1], new PointF(pointArray[0].X, pointArray[1].Y));
  720. int offsetValuePoint = measureStyleModel.fontSize + measureStyleModel.fontSize / 2;
  721. int offsetValue1Point = measureStyleModel.lineWidth * 2 / 3;
  722. int offsetPoint = offsetValue1Point;
  723. if (drawingPropertiesList != null)
  724. {
  725. if (drawingPropertiesList.Contains(MeasureAttributes.PixelAverageIntercept.ToString()))
  726. {
  727. offsetPoint += offsetValuePoint;
  728. }
  729. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalAverage.ToString()))
  730. {
  731. offsetPoint += offsetValuePoint;
  732. }
  733. // 测量方式
  734. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
  735. {
  736. offsetPoint += offsetValuePoint;
  737. }
  738. // 测量单位(中文)
  739. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
  740. {
  741. offsetPoint += offsetValuePoint;
  742. }
  743. // 测量单位(英文)
  744. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
  745. {
  746. offsetPoint += offsetValuePoint;
  747. }
  748. }
  749. PointF pointF1;
  750. PointF pointF2;
  751. if (angle < 90)
  752. pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[0].X + offsetPoint + offsetValue1Point, (int)pointArray[0].Y), pointArray[0], angle - 90);
  753. else
  754. pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[0].X + offsetPoint + offsetValue1Point, (int)pointArray[0].Y), pointArray[0], angle + 90);
  755. if (angle < 90)
  756. pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[1].X + offsetPoint + offsetValue1Point, (int)pointArray[1].Y), pointArray[1], angle - 90);
  757. else
  758. pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[1].X + offsetPoint + offsetValue1Point, (int)pointArray[1].Y), pointArray[1], angle + 90);
  759. PointF pointF3 = new PointF((pointF1.X + pointF2.X) / 2, (pointF1.Y + pointF2.Y) / 2);
  760. if (measureStyleModel.linePositionL == 0)
  761. this.rotationPoint = pointF1;
  762. else if (measureStyleModel.linePositionL == 1)
  763. this.rotationPoint = pointF3;
  764. else if (measureStyleModel.linePositionL == 2)
  765. this.rotationPoint = pointF2;
  766. else if (measureStyleModel.linePositionL == 3)
  767. this.rotationPoint = pointArray[0];
  768. else if (measureStyleModel.linePositionL == 4)
  769. this.rotationPoint = new PointF((pointArray[0].X + pointArray[1].X) / 2, (pointArray[0].Y + pointArray[1].Y) / 2);
  770. else if (measureStyleModel.linePositionL == 5)
  771. this.rotationPoint = pointArray[1];
  772. if (this.angle < 90)
  773. {
  774. matrix1.RotateAt((float)this.angle, this.rotationPoint);
  775. g.Transform = matrix1;
  776. }
  777. else
  778. {
  779. this.angle = BasicCalculationHelper.Angle(pointArray[1], pointArray[0], new PointF(pointArray[1].X, pointArray[0].Y));
  780. matrix1.RotateAt((float)this.angle, this.rotationPoint);
  781. g.Transform = matrix1;
  782. }
  783. if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
  784. {
  785. this.pointL = new Point((int)this.rotationPoint.X, (int)this.rotationPoint.Y);
  786. int offsetValue = measureStyleModel.fontSize + measureStyleModel.fontSize / 2;
  787. int offsetValue1 = measureStyleModel.lineWidth * 2 / 3;
  788. int offset = offsetValue1;
  789. if (drawingPropertiesList != null)
  790. {
  791. if (drawingPropertiesList.Contains(MeasureAttributes.PixelAverageIntercept.ToString()))
  792. {
  793. double length;
  794. if (pointArray.Count == 2)
  795. length = 0;
  796. else
  797. length = Length / (pointArray.Count - 2);
  798. sizeF = g.MeasureString(frontStr + Math.Round(length, decimalPlaces) + "px", textfont1);
  799. rectangleF4.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
  800. offset += offsetValue;
  801. }
  802. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalAverage.ToString()))
  803. {
  804. double length;
  805. if (pointArray.Count == 2)
  806. length = 0;
  807. else
  808. length = Length / (pointArray.Count - 2);
  809. string s = Math.Round(length * unitLength, decimalPlaces).ToString();
  810. if (s.IndexOf(".") == -1)
  811. {
  812. for (int i = 0; i < decimalPlaces; i++)
  813. {
  814. if (i == 0)
  815. s += ".";
  816. s += "0";
  817. }
  818. }
  819. else
  820. {
  821. int a = s.Length - s.IndexOf(".") - 1;
  822. if (a < decimalPlaces)
  823. {
  824. for (int i = 0; i < decimalPlaces - a; i++)
  825. {
  826. s += "0";
  827. }
  828. }
  829. }
  830. sizeF = g.MeasureString(frontStr + s + this.unit, textfont1);
  831. rectangleF5.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
  832. offset += offsetValue;
  833. }
  834. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
  835. {
  836. sizeF = g.MeasureString(frontStr + PdnResources.GetString("Menu.MeasureAction.PointPerpendicular.Text"), textfont1);
  837. rectangleF1.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
  838. offset += offsetValue;
  839. }
  840. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
  841. {
  842. sizeF = g.MeasureString(frontStr + this.unitString, textfont1);
  843. rectangleF2.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
  844. offset += offsetValue;
  845. }
  846. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
  847. {
  848. sizeF = g.MeasureString(frontStr + this.unit, textfont1);
  849. rectangleF3.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
  850. offset += offsetValue;
  851. }
  852. }
  853. }
  854. if (drawingPropertiesList != null)
  855. {
  856. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
  857. {
  858. sizeF = g.MeasureString(frontStr + PdnResources.GetString("Menu.MeasureAction.PointPerpendicular.Text"), textfont1);
  859. rectangleF1.Width = sizeF.Width;
  860. rectangleF1.Height = sizeF.Height;
  861. g.DrawString(frontStr + PdnResources.GetString("Menu.MeasureAction.PointPerpendicular.Text"), textfont1, textbrush1, rectangleF1);
  862. }
  863. else
  864. {
  865. rectangleF1 = new RectangleF();
  866. }
  867. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
  868. {
  869. sizeF = g.MeasureString(frontStr + this.unitString, textfont1);
  870. rectangleF2.Width = sizeF.Width;
  871. rectangleF2.Height = sizeF.Height;
  872. g.DrawString(frontStr + this.unitString, textfont1, textbrush1, rectangleF2);
  873. }
  874. else
  875. {
  876. rectangleF2 = new RectangleF();
  877. }
  878. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
  879. {
  880. sizeF = g.MeasureString(frontStr + this.unit, textfont1);
  881. rectangleF3.Width = sizeF.Width;
  882. rectangleF3.Height = sizeF.Height;
  883. g.DrawString(frontStr + this.unit, textfont1, textbrush1, rectangleF3);
  884. }
  885. else
  886. {
  887. rectangleF3 = new RectangleF();
  888. }
  889. if (drawingPropertiesList.Contains(MeasureAttributes.PixelAverageIntercept.ToString()))
  890. {
  891. double length;
  892. if (pointArray.Count == 2)
  893. length = 0;
  894. else
  895. length = Length / (pointArray.Count - 2);
  896. sizeF = g.MeasureString(frontStr + Math.Round(length, decimalPlaces) + "px", textfont1);
  897. rectangleF4.Width = sizeF.Width;
  898. rectangleF4.Height = sizeF.Height;
  899. g.DrawString(frontStr + Math.Round(length, decimalPlaces) + "px", textfont1, textbrush1, rectangleF4);
  900. }
  901. else
  902. {
  903. rectangleF4 = new RectangleF();
  904. }
  905. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalAverage.ToString()))
  906. {
  907. double length;
  908. if (pointArray.Count == 2)
  909. length = 0;
  910. else
  911. length = Length / (pointArray.Count - 2);
  912. string s = Math.Round(length * unitLength, decimalPlaces).ToString();
  913. if (s.IndexOf(".") == -1)
  914. {
  915. for (int i = 0; i < decimalPlaces; i++)
  916. {
  917. if (i == 0)
  918. s += ".";
  919. s += "0";
  920. }
  921. }
  922. else
  923. {
  924. int a = s.Length - s.IndexOf(".") - 1;
  925. if (a < decimalPlaces)
  926. {
  927. for (int i = 0; i < decimalPlaces - a; i++)
  928. {
  929. s += "0";
  930. }
  931. }
  932. }
  933. sizeF = g.MeasureString(frontStr + s + this.unit, textfont1);
  934. rectangleF5.Width = sizeF.Width;
  935. rectangleF5.Height = sizeF.Height;
  936. g.DrawString(frontStr + s + this.unit, textfont1, textbrush1, rectangleF5);
  937. }
  938. else
  939. {
  940. rectangleF5 = new RectangleF();
  941. }
  942. }
  943. g.Transform = mtxSave1;
  944. matrix1.Dispose();
  945. }
  946. if (this.configurationFile)
  947. this.pointChange = false;
  948. this.mouseUpAttribute = false;
  949. pointChangeObject.Remove(this.drawToolType);
  950. }
  951. /// 停止绘制时
  952. /// </summary>
  953. /// <param name="up"></param>
  954. public override void MouseUp(bool up)
  955. {
  956. mouseUpPointChange = up;
  957. }
  958. public void AddPoint(Point point)
  959. {
  960. pointArray.Add(point);
  961. }
  962. public override int HandleCount
  963. {
  964. get
  965. {
  966. return pointArray.Count + 1;
  967. }
  968. }
  969. /// <summary>
  970. /// Get handle pointscroll by 1-based number
  971. /// </summary>
  972. /// <param name="handleNumber"></param>
  973. /// <returns></returns>
  974. public override PointF GetHandle(int handleNumber)
  975. {
  976. if (handleNumber < 1)
  977. handleNumber = 1;
  978. if (handleNumber > pointArray.Count && handleNumber != pointArray.Count + 1)
  979. handleNumber = pointArray.Count;
  980. if (handleNumber == pointArray.Count + 1)
  981. return this.pointL;
  982. else
  983. return pointArray[handleNumber - 1];
  984. }
  985. public override Cursor GetHandleCursor(int handleNumber)
  986. {
  987. return handleCursor;
  988. }
  989. public override void MoveHandleTo(Point point, int handleNumber)
  990. {
  991. if (handleNumber < 1)
  992. handleNumber = 1;
  993. if (handleNumber > pointArray.Count && handleNumber != pointArray.Count + 1)
  994. handleNumber = pointArray.Count;
  995. if (handleNumber == pointArray.Count + 1)
  996. {
  997. if (this.moveKb == 1 || this.moveKb == 2 || this.moveKb == 3 || this.moveKb == 4 || this.moveKb == 5)
  998. {
  999. point = SetOffsetAfterRotation(point, this.rotationPoint, angle);
  1000. if (this.moveKb == 1)
  1001. this.rectangleF1.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1002. else if (this.moveKb == 2)
  1003. this.rectangleF2.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1004. else if (this.moveKb == 3)
  1005. this.rectangleF3.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1006. else if (this.moveKb == 4)
  1007. this.rectangleF4.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1008. else if (this.moveKb == 5)
  1009. this.rectangleF5.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1010. }
  1011. else
  1012. {
  1013. for (int i = 0; i < this.RectangleFList.Count; i++)
  1014. {
  1015. num = i / 6;
  1016. if (num + 1 < pointArray.Count)
  1017. {
  1018. RectangleF rectangleF = this.RectangleFList[i];
  1019. if (this.moveKb == -i)
  1020. {
  1021. point = SetOffsetAfterRotation(point, pointArray[num + 1], angleP);
  1022. rectangleF.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1023. this.RectangleFList[i] = rectangleF;
  1024. break;
  1025. }
  1026. }
  1027. }
  1028. }
  1029. this.pointL = point;
  1030. }
  1031. else
  1032. {
  1033. this.mouseUpPointChange = true;
  1034. if (handleNumber != 1)
  1035. {
  1036. for (int i = 1; i <= this.RectangleFList.Count; i++)
  1037. {
  1038. if (i == handleNumber)
  1039. {
  1040. RectangleF rectangleF = this.RectangleFList[i * 6 - 12];
  1041. rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
  1042. this.RectangleFList[i * 6 - 12] = rectangleF;
  1043. rectangleF = this.RectangleFList[i * 6 - 11];
  1044. rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
  1045. this.RectangleFList[i * 6 - 11] = rectangleF;
  1046. rectangleF = this.RectangleFList[i * 6 - 10];
  1047. rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
  1048. this.RectangleFList[i * 6 - 10] = rectangleF;
  1049. rectangleF = this.RectangleFList[i * 6 - 9];
  1050. rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
  1051. this.RectangleFList[i * 6 - 9] = rectangleF;
  1052. rectangleF = this.RectangleFList[i * 6 - 8];
  1053. rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
  1054. this.RectangleFList[i * 6 - 8] = rectangleF;
  1055. rectangleF = this.RectangleFList[i * 6 - 7];
  1056. rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
  1057. this.RectangleFList[i * 6 - 7] = rectangleF;
  1058. }
  1059. }
  1060. }
  1061. else
  1062. {
  1063. this.rectangleF1.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1064. this.rectangleF2.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1065. this.rectangleF3.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1066. this.rectangleF4.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1067. this.rectangleF5.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1068. }
  1069. pointArray[handleNumber - 1] = point;
  1070. }
  1071. this.startPoint = pointArray[0];
  1072. Invalidate();
  1073. }
  1074. public override void Move(int deltaX, int deltaY)
  1075. {
  1076. int n = pointArray.Count;
  1077. for (int i = 0; i < n; i++)
  1078. {
  1079. PointF point = new PointF(pointArray[i].X + ISurfaceBox.UnscaleScalar(deltaX), pointArray[i].Y + ISurfaceBox.UnscaleScalar(deltaY));
  1080. pointArray[i] = point;
  1081. }
  1082. this.startPoint = pointArray[0];
  1083. int x = ISurfaceBox.UnscaleScalar(deltaX);
  1084. int y = ISurfaceBox.UnscaleScalar(deltaY);
  1085. pointL.X += x;
  1086. pointL.Y += y;
  1087. this.rectangleF1.Offset(x, y);
  1088. this.rectangleF2.Offset(x, y);
  1089. this.rectangleF3.Offset(x, y);
  1090. this.rectangleF4.Offset(x, y);
  1091. this.rectangleF5.Offset(x, y);
  1092. for (int i = 0; i < this.RectangleFList.Count; i++)
  1093. {
  1094. RectangleF rectangleF = this.RectangleFList[i];
  1095. rectangleF.Offset(x, y);
  1096. this.RectangleFList[i] = rectangleF;
  1097. }
  1098. Invalidate();
  1099. }
  1100. /// <summary>
  1101. /// 用于创建一个路径或者是闭合的范围
  1102. /// 用于响应点击选中
  1103. /// 需要咨询用户是仅点击线还是矩形选择
  1104. /// </summary>
  1105. protected virtual void CreateObjects()
  1106. {
  1107. if (AreaPath != null)
  1108. return;
  1109. AreaPath = new GraphicsPath();
  1110. AreaPath.AddRectangle(GetBoundingBox());
  1111. AreaPath.CloseFigure();
  1112. AreaRegion = new Region(AreaPath);
  1113. }
  1114. /// <summary>
  1115. /// Invalidate object.
  1116. /// When object is invalidated, path used for hit test
  1117. /// is released and should be created again.
  1118. /// </summary>
  1119. protected void Invalidate()
  1120. {
  1121. if (AreaPath != null)
  1122. {
  1123. AreaPath.Dispose();
  1124. AreaPath = null;
  1125. }
  1126. if (AreaPen != null)
  1127. {
  1128. AreaPen.Dispose();
  1129. AreaPen = null;
  1130. }
  1131. if (AreaRegion != null)
  1132. {
  1133. AreaRegion.Dispose();
  1134. AreaRegion = null;
  1135. }
  1136. }
  1137. protected GraphicsPath AreaPath
  1138. {
  1139. get
  1140. {
  1141. return areaPath;
  1142. }
  1143. set
  1144. {
  1145. areaPath = value;
  1146. }
  1147. }
  1148. protected Pen AreaPen
  1149. {
  1150. get
  1151. {
  1152. return areaPen;
  1153. }
  1154. set
  1155. {
  1156. areaPen = value;
  1157. }
  1158. }
  1159. protected Region AreaRegion
  1160. {
  1161. get
  1162. {
  1163. return areaRegion;
  1164. }
  1165. set
  1166. {
  1167. areaRegion = value;
  1168. }
  1169. }
  1170. /// <summary>
  1171. /// Draw tracker for selected object
  1172. /// </summary>
  1173. /// <param name="g"></param>
  1174. public override void DrawTracker(Graphics g)
  1175. {
  1176. if (!Selected)
  1177. return;
  1178. SolidBrush brush = new SolidBrush(Color.FromArgb(MarkpointAreaColor));
  1179. Pen pen = new Pen(Color.FromArgb(MarkpointLineColor), MarkpointLineWidth);
  1180. for (int i = 1; i <= HandleCount; i++)
  1181. {
  1182. if (i == HandleCount)
  1183. {
  1184. brush = new SolidBrush(Color.Transparent);
  1185. pen = new Pen(Color.Transparent);
  1186. }
  1187. switch (MarkpointStyle)
  1188. {
  1189. case 0:
  1190. g.FillRectangle(brush, GetHandleRectangle(i));
  1191. g.DrawRectangle(pen, GetHandleRectangle(i));
  1192. break;
  1193. case 1:
  1194. g.FillEllipse(brush, GetHandleRectangle(i));
  1195. g.DrawEllipse(pen, GetHandleRectangle(i));
  1196. break;
  1197. case 2:
  1198. g.FillPolygon(brush, GetHandlePoint(i));
  1199. g.DrawPolygon(pen, GetHandlePoint(i));
  1200. break;
  1201. }
  1202. }
  1203. brush.Dispose();
  1204. pen.Dispose();
  1205. RectangleF r = GetBoundingBox();
  1206. //g.DrawRectangle(new Pen(Color.White), r.X, r.Y, r.Width, r.Height);
  1207. }
  1208. /// <summary>
  1209. /// Hit test.
  1210. /// Return value: -1 - no hit
  1211. /// 0 - hit anywhere
  1212. /// > 1 - handle number
  1213. /// </summary>
  1214. /// <param name="pointscroll"></param>
  1215. /// <returns></returns>
  1216. public override int HitTest(Point point)
  1217. {
  1218. if (Selected)
  1219. {
  1220. for (int i = 1; i <= HandleCount; i++)
  1221. {
  1222. if (GetHandleRectangle(i).Contains(point))
  1223. return i;
  1224. }
  1225. if (GetRectanglePosition(this.rectangleF1, point, this.rotationPoint, angle))
  1226. {
  1227. this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
  1228. moveKb = 1;
  1229. return this.pointArray.Count + 1;
  1230. }
  1231. else if (GetRectanglePosition(this.rectangleF2, point, this.rotationPoint, angle))
  1232. {
  1233. this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
  1234. moveKb = 2;
  1235. return this.pointArray.Count + 1;
  1236. }
  1237. else if (GetRectanglePosition(this.rectangleF3, point, this.rotationPoint, angle))
  1238. {
  1239. this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
  1240. moveKb = 3;
  1241. return this.pointArray.Count + 1;
  1242. }
  1243. else if (GetRectanglePosition(this.rectangleF4, point, this.rotationPoint, angle))
  1244. {
  1245. this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
  1246. moveKb = 4;
  1247. return this.pointArray.Count + 1;
  1248. }
  1249. else if (GetRectanglePosition(this.rectangleF5, point, this.rotationPoint, angle))
  1250. {
  1251. this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
  1252. moveKb = 5;
  1253. return this.pointArray.Count + 1;
  1254. }
  1255. for (int i = 0; i < this.RectangleFList.Count; i++)
  1256. {
  1257. num = i / 6;
  1258. if (num + 1 < pointArray.Count)
  1259. {
  1260. RectangleF rectangleF = this.RectangleFList[i];
  1261. if (GetRectanglePosition(rectangleF, point, pointArray[num + 1], angleP))
  1262. {
  1263. this.pointL = SetOffsetAfterRotation(point, pointArray[num + 1], angleP);
  1264. moveKb = -i;
  1265. return this.pointArray.Count + 1;
  1266. }
  1267. }
  1268. }
  1269. }
  1270. if (PointInObject(point))
  1271. return 0;
  1272. return -1;
  1273. }
  1274. protected override bool PointInObject(Point point)
  1275. {
  1276. CreateObjects();
  1277. return AreaRegion.IsVisible(point);
  1278. }
  1279. public override bool IntersectsWith(Rectangle rectangle)
  1280. {
  1281. CreateObjects();
  1282. return AreaRegion.IsVisible(rectangle);
  1283. }
  1284. public override RectangleF GetBoundingBox()
  1285. {
  1286. float minx = 0, maxx = 0, miny = 0, maxy = 0;
  1287. for (int i = 0; i < pointArray.Count; i++)
  1288. {
  1289. if (i == 0)
  1290. {
  1291. minx = maxx = pointArray[i].X;
  1292. miny = maxy = pointArray[i].Y;
  1293. }
  1294. else
  1295. {
  1296. if (pointArray[i].X > maxx) maxx = pointArray[i].X;
  1297. if (pointArray[i].X < minx) minx = pointArray[i].X;
  1298. if (pointArray[i].Y > maxy) maxy = pointArray[i].Y;
  1299. if (pointArray[i].Y < miny) miny = pointArray[i].Y;
  1300. }
  1301. }
  1302. return new RectangleF(minx, miny, maxx - minx, maxy - miny);
  1303. }
  1304. internal void setNextPoint(Point p)
  1305. {
  1306. AddPoint(p);
  1307. //startPoint = endPoint;
  1308. //endPoint = p;
  1309. }
  1310. public override List<PointF> GetPoints()
  1311. {
  1312. return pointArray;
  1313. }
  1314. public override ParentStyleModel GetStyle()
  1315. {
  1316. return measureStyleModel;
  1317. }
  1318. }
  1319. }