MeasureThreePointArc.cs 60 KB

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