MeasureRandRectangle.cs 65 KB

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