MeasureMulVLine.cs 66 KB

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