MeasureMulParallelLine.cs 61 KB

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