MeasureMulParallelLine.cs 64 KB

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