MeasureThreePointArc.cs 63 KB

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