MeasureTwoLineVLDistance.cs 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. using PaintDotNet.Annotation.Enum;
  2. using PaintDotNet.Base.SettingModel;
  3. using PaintDotNet.Base.CommTool;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Drawing;
  7. using System.Drawing.Drawing2D;
  8. using System.Linq;
  9. using System.Windows.Forms;
  10. namespace PaintDotNet.Annotation.Measure
  11. {
  12. using PointList = List<PointF>;
  13. /// <summary>
  14. /// 测量->对准度->两线中垂线距离
  15. /// </summary>
  16. public class MeasureTwoLineVLDistance : MeasureDrawObject
  17. {
  18. public PointList pointArray;
  19. private const string entryLength = "Length";
  20. private const string entryPoint = "Point";
  21. /// <summary>
  22. /// Graphic objects for hit test
  23. /// </summary>
  24. private GraphicsPath areaPath = null;
  25. private Pen areaPen = null;
  26. private Region areaRegion = null;
  27. /// <summary>
  28. /// 总长度
  29. /// </summary>
  30. private double Length = 0.0;
  31. /// <summary>
  32. /// 测量信息矩形定义
  33. /// </summary>
  34. private RectangleF rectangleF1 = new RectangleF();
  35. private RectangleF rectangleF2 = new RectangleF();
  36. private RectangleF rectangleF3 = new RectangleF();
  37. private RectangleF rectangleF4 = new RectangleF();
  38. private RectangleF rectangleF5 = new RectangleF();
  39. private RectangleF rectangleF6 = new RectangleF();
  40. private RectangleF rectangleF7 = new RectangleF();
  41. private RectangleF rectangleF8 = new RectangleF();
  42. private RectangleF rectangleF9 = new RectangleF();
  43. /// <summary>
  44. /// 文本上用于拖动的点
  45. /// </summary>
  46. private Point pointL = new Point();
  47. /// <summary>
  48. /// 绘制限制(第一次绘制时)
  49. /// </summary>
  50. public bool pointChange = true;
  51. /// <summary>
  52. /// 区分移动文本
  53. /// </summary>
  54. private int moveKb;
  55. /// <summary>
  56. /// 绘制限制(从配置文件加载)
  57. /// </summary>
  58. public bool configurationFile = false;
  59. /// <summary>
  60. /// 绘制限制(更改属性时)
  61. /// </summary>
  62. private bool SavePointChange;
  63. /// <summary>
  64. /// 绘制属性
  65. /// </summary>
  66. private string[] drawingPropertiesList;
  67. /// <summary>
  68. /// 绘制属性(克隆)
  69. /// </summary>
  70. private string[] drawingPropertiesListClone;
  71. private bool drawing;
  72. /// <summary>
  73. /// 旋转角度
  74. /// </summary>
  75. private double angle;
  76. /// <summary>
  77. /// 属性绘制点
  78. /// </summary>
  79. private PointF rotationPoint;
  80. private PointF rotationPoint1;
  81. /// <summary>
  82. /// 限制绘制(绘制中)
  83. /// </summary>
  84. public bool mouseUpPointChange = false;
  85. /// <summary>
  86. /// 测量样式信息model
  87. /// </summary>
  88. private MeasureStyleModel.MeasureTwoLineVLDistance measureStyleModel;
  89. public MeasureStyleModel.MeasureTwoLineVLDistance MeasureStyleModel
  90. {
  91. set
  92. {
  93. this.measureStyleModel = value;
  94. }
  95. }
  96. public MeasureTwoLineVLDistance(ISurfaceBox surfaceBox, int x1, int y1, bool clone) : base(surfaceBox)
  97. {
  98. this.objectType = DrawClass.Measure;
  99. this.drawToolType = DrawToolType.MeasureTwoLineVLDistance;
  100. measureStyleModel = surfaceBox.GetMeasureStyleModel().measureTwoLineVLDistance;
  101. pointArray = new PointList();
  102. startPoint.X = x1;
  103. startPoint.Y = y1;
  104. if (clone)
  105. {
  106. drawing = true;
  107. pointArray.Add(new Point(x1, y1));
  108. }
  109. this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);
  110. this.unitString = surfaceBox.GetPxPerUnit()[1];
  111. this.unit = surfaceBox.GetPxPerUnit()[2];
  112. surfaceBox.getMeasureInfo().TryGetValue(measurementUnit, out unitLength);
  113. Initialize();
  114. }
  115. /// <summary>
  116. /// 测量属性
  117. /// </summary>
  118. /// <returns></returns>
  119. public override Dictionary<System.Enum, object> GetData()
  120. {
  121. if (data.ContainsKey(MeasureAttributes.MeasureMethod))
  122. data[MeasureAttributes.MeasureMethod] = PdnResources.GetString("Menu.MeasureAction.LengthMeasurement.Text");
  123. else
  124. data.Add(MeasureAttributes.MeasureMethod, PdnResources.GetString("Menu.MeasureAction.LengthMeasurement.Text"));
  125. if (data.ContainsKey(MeasureAttributes.MeasureUnitCN))
  126. data[MeasureAttributes.MeasureUnitCN] = this.unitString;
  127. else
  128. data.Add(MeasureAttributes.MeasureUnitCN, this.unitString);
  129. if (data.ContainsKey(MeasureAttributes.MeasureUnitEN))
  130. data[MeasureAttributes.MeasureUnitEN] = this.unit;
  131. else
  132. data.Add(MeasureAttributes.MeasureUnitEN, this.unit);
  133. if (data.ContainsKey(MeasureAttributes.PixelStartX))
  134. data[MeasureAttributes.PixelStartX] = startPoint.X;
  135. else
  136. data.Add(MeasureAttributes.PixelStartX, startPoint.X);
  137. if (data.ContainsKey(MeasureAttributes.PixelStartY))
  138. data[MeasureAttributes.PixelStartY] = startPoint.Y;
  139. else
  140. data.Add(MeasureAttributes.PixelStartY, startPoint.Y);
  141. if (data.ContainsKey(MeasureAttributes.PhysicalStartX))
  142. data[MeasureAttributes.PhysicalStartX] = Math.Round(startPoint.X * unitLength, decimalPlaces);
  143. else
  144. data.Add(MeasureAttributes.PhysicalStartX, Math.Round(startPoint.X * unitLength, decimalPlaces));
  145. if (data.ContainsKey(MeasureAttributes.PhysicalStartY))
  146. data[MeasureAttributes.PhysicalStartY] = Math.Round(startPoint.Y * unitLength, decimalPlaces);
  147. else
  148. data.Add(MeasureAttributes.PhysicalStartY, Math.Round(startPoint.Y * unitLength, decimalPlaces));
  149. if (data.ContainsKey(MeasureAttributes.PixelLength))
  150. data[MeasureAttributes.PixelLength] = Math.Round(Length, decimalPlaces);
  151. else
  152. data.Add(MeasureAttributes.PixelLength, Math.Round(Length, decimalPlaces));
  153. string s = Math.Round(Length * unitLength, decimalPlaces).ToString();
  154. if (s.IndexOf(".") == -1)
  155. {
  156. for (int i = 0; i < decimalPlaces; i++)
  157. {
  158. if (i == 0)
  159. s += ".";
  160. s += "0";
  161. }
  162. }
  163. else
  164. {
  165. int a = s.Length - s.IndexOf(".") - 1;
  166. if (a < decimalPlaces)
  167. {
  168. for (int i = 0; i < decimalPlaces - a; i++)
  169. {
  170. s += "0";
  171. }
  172. }
  173. }
  174. if (data.ContainsKey(MeasureAttributes.PhysicalLength))
  175. data[MeasureAttributes.PhysicalLength] = s;
  176. else
  177. data.Add(MeasureAttributes.PhysicalLength, s);
  178. return data;
  179. }
  180. public MeasureTwoLineVLDistance(ISurfaceBox surfaceBox, List<PointF> points, ParentStyleModel parentStyleModel, Object content) : base()
  181. {
  182. this.objectType = DrawClass.Measure;
  183. this.drawToolType = DrawToolType.MeasureTwoLineVLDistance;
  184. this.ISurfaceBox = surfaceBox;
  185. measureStyleModel = (MeasureStyleModel.MeasureTwoLineVLDistance)parentStyleModel;
  186. pointArray = DrawRulerHelper.DeepCopyListByReflect(points);
  187. startPoint = points[0];
  188. this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);
  189. this.unitString = surfaceBox.GetPxPerUnit()[1];
  190. this.unit = surfaceBox.GetPxPerUnit()[2];
  191. surfaceBox.getMeasureInfo().TryGetValue(measurementUnit, out unitLength);
  192. this.configurationFile = true;
  193. }
  194. /// <summary>
  195. /// Clone this instance
  196. /// </summary>
  197. public override DrawObject Clone()
  198. {
  199. MeasureTwoLineVLDistance drawPolygon = new MeasureTwoLineVLDistance(ISurfaceBox, (int)pointArray[0].X, (int)pointArray[0].Y, false);
  200. drawPolygon.ISurfaceBox = ISurfaceBox;
  201. foreach (PointF p in this.pointArray)
  202. {
  203. drawPolygon.pointArray.Add(p);
  204. }
  205. if (drawingPropertiesList != null)
  206. drawPolygon.drawingPropertiesListClone = drawingPropertiesList;
  207. FillDrawObjectFields(drawPolygon);
  208. return drawPolygon;
  209. }
  210. public override DrawObject Clone(ISurfaceBox surfaceBox)
  211. {
  212. MeasureTwoLineVLDistance drawPolygon = new MeasureTwoLineVLDistance(surfaceBox, this.GetPoints(), this.measureStyleModel, null);
  213. if (drawingPropertiesList != null)
  214. drawPolygon.drawingPropertiesListClone = drawingPropertiesList;
  215. FillDrawObjectFields(drawPolygon);
  216. return drawPolygon;
  217. }
  218. public override void Draw(Graphics g)
  219. {
  220. drawingProperties.TryGetValue(this.drawToolType, out drawingPropertiesList);
  221. if (drawingPropertiesList == null)
  222. {
  223. drawingPropertiesList = drawingPropertiesListClone;
  224. if (!this.drawing)
  225. this.configurationFile = true;
  226. }
  227. float width = ISurfaceBox.GetDocumentSize().Width;
  228. float height = ISurfaceBox.GetDocumentSize().Height;
  229. pointChangeObject.TryGetValue(this.drawToolType, out SavePointChange);
  230. if (HandleCount - 1 >= 2)
  231. {
  232. Font textfont = new Font(measureStyleModel.font, measureStyleModel.fontSize);
  233. Brush textbrush = new SolidBrush(Color.FromArgb(measureStyleModel.textColor));
  234. g.SmoothingMode = SmoothingMode.AntiAlias;
  235. Color color = Color.FromArgb(this.measureStyleModel.lineColor);
  236. Pen pen = new Pen(color, this.measureStyleModel.lineWidth);
  237. pen.DashStyle = (DashStyle)this.measureStyleModel.lineStyle;
  238. g.DrawLine(pen, pointArray[0], pointArray[1]);
  239. PointList pointFs2 = new PointList();
  240. if (HandleCount - 1 == 2 || HandleCount - 1 == 3)
  241. {
  242. g.DrawLine(pen, pointArray[0], pointArray[1]);
  243. PointF center = new PointF((pointArray[0].X + pointArray[1].X) / 2, (pointArray[0].Y + pointArray[1].Y) / 2);
  244. // A点
  245. PointF pointFA = pointArray[0];
  246. // B点
  247. PointF pointFB = pointArray[1];
  248. // 中垂线x坐标
  249. float x = 0;
  250. // 中垂线y坐标
  251. float y = 0;
  252. // 中垂线方程
  253. y = -(pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y) * x + (pointFA.Y + pointFB.Y) / 2 + (pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y) * (pointFA.X + pointFB.X) / 2;
  254. x = (y - ((pointFA.Y + pointFB.Y) / 2 + (pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y) * (pointFA.X + pointFB.X) / 2)) / (-(pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y));
  255. List<PointF> pointFs = new PointList();
  256. List<PointF> pointFs1 = new PointList();
  257. // 求出可能的图片四个边的交点
  258. PointF pointFL;
  259. x = 0;
  260. y = -(pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y) * x + (pointFA.Y + pointFB.Y) / 2 + (pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y) * (pointFA.X + pointFB.X) / 2;
  261. pointFL = new PointF(x, y);
  262. pointFs.Add(pointFL);
  263. y = 0;
  264. x = (y - ((pointFA.Y + pointFB.Y) / 2 + (pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y) * (pointFA.X + pointFB.X) / 2)) / (-(pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y));
  265. pointFL = new PointF(x, y);
  266. pointFs.Add(pointFL);
  267. x = width;
  268. y = -(pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y) * x + (pointFA.Y + pointFB.Y) / 2 + (pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y) * (pointFA.X + pointFB.X) / 2;
  269. pointFL = new PointF(x, y);
  270. pointFs.Add(pointFL);
  271. y = height;
  272. x = (y - ((pointFA.Y + pointFB.Y) / 2 + (pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y) * (pointFA.X + pointFB.X) / 2)) / (-(pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y));
  273. pointFL = new PointF(x, y);
  274. pointFs.Add(pointFL);
  275. RectangleF rectangleF = new RectangleF(-10, -10, width + 10, height + 10);
  276. foreach (PointF item in pointFs)
  277. {
  278. if (item.X >= 0 && item.X <= rectangleF.Width && item.Y >= 0 && item.Y <= rectangleF.Height)
  279. {
  280. pointFs1.Add(item);
  281. }
  282. }
  283. if (pointFs1.Count == 2)
  284. g.DrawLines(pen, pointFs1.ToArray());
  285. }
  286. if (HandleCount - 1 == 4)
  287. {
  288. g.DrawLine(pen, pointArray[0], pointArray[1]);
  289. g.DrawLine(pen, pointArray[2], pointArray[3]);
  290. for (int i = 0; i < 2; i++)
  291. {
  292. // A点
  293. PointF pointFA ;
  294. // B点
  295. PointF pointFB;
  296. if(i == 0)
  297. {
  298. // A点
  299. pointFA = pointArray[0];
  300. if (pointArray[0].X == pointArray[1].X)
  301. pointArray[1] = new PointF(pointArray[1].X + 1, pointArray[1].Y);
  302. if (pointArray[0].Y == pointArray[1].Y)
  303. pointArray[1] = new PointF(pointArray[1].X, pointArray[1].Y + 1);
  304. // B点
  305. pointFB = pointArray[1];
  306. }
  307. else
  308. {
  309. // A点
  310. pointFA = pointArray[2];
  311. if (pointArray[2].X == pointArray[3].X)
  312. pointArray[3] = new PointF(pointArray[3].X + 1, pointArray[3].Y);
  313. if (pointArray[2].Y == pointArray[3].Y)
  314. pointArray[3] = new PointF(pointArray[3].X, pointArray[3].Y + 1);
  315. // B点
  316. pointFB = pointArray[3];
  317. }
  318. // 中垂线x坐标
  319. float x = 0;
  320. // 中垂线y坐标
  321. float y = 0;
  322. // 中垂线方程
  323. List<PointF> pointFs = new PointList();
  324. List<PointF> pointFs1 = new PointList();
  325. // 求出可能的图片四个边的交点
  326. PointF pointFL;
  327. x = 0;
  328. y = -(pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y) * x + (pointFA.Y + pointFB.Y) / 2 + (pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y) * (pointFA.X + pointFB.X) / 2;
  329. if (pointFA.Y == pointFB.Y)
  330. y = 0;
  331. pointFL = new PointF(x, y);
  332. pointFs.Add(pointFL);
  333. y = 0;
  334. x = (y - ((pointFA.Y + pointFB.Y) / 2 + (pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y) * (pointFA.X + pointFB.X) / 2)) / (-(pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y));
  335. pointFL = new PointF(x, y);
  336. pointFs.Add(pointFL);
  337. x = width;
  338. y = -(pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y) * x + (pointFA.Y + pointFB.Y) / 2 + (pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y) * (pointFA.X + pointFB.X) / 2;
  339. if (pointFA.Y == pointFB.Y)
  340. y = height;
  341. pointFL = new PointF(x, y);
  342. pointFs.Add(pointFL);
  343. y = height;
  344. x = (y - ((pointFA.Y + pointFB.Y) / 2 + (pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y) * (pointFA.X + pointFB.X) / 2)) / (-(pointFA.X - pointFB.X) / (pointFA.Y - pointFB.Y));
  345. pointFL = new PointF(x, y);
  346. pointFs.Add(pointFL);
  347. foreach (PointF item in pointFs)
  348. {
  349. if (item.X >= 0 && item.X <= width && item.Y >= 0 && item.Y <= height)
  350. {
  351. pointFs1.Add(item);
  352. }
  353. }
  354. PointF pointF = new PointF();
  355. if (pointFs1.Count == 3)
  356. {
  357. int add = 0;
  358. foreach (var item in pointFs1)
  359. {
  360. if(add == 0)
  361. pointF = item;
  362. else
  363. {
  364. if (item.X == pointF.X && item.Y == pointF.Y)
  365. {
  366. pointFs1.Remove(item);
  367. break;
  368. }
  369. }
  370. add++;
  371. }
  372. }
  373. if (pointFs1.Count == 2)
  374. {
  375. g.DrawLines(pen, pointFs1.ToArray());
  376. if(i == 0)
  377. pointFs2.Add(new PointF((pointFs1[0].X + pointFs1[1].X) / 2, (pointFs1[0].Y + pointFs1[1].Y) / 2));
  378. else
  379. {
  380. PointF footPoint = new PointF();
  381. if (pointFs2.Count > 0)
  382. {
  383. footPoint = BasicCalculationHelper.GetDropFeet(pointFs1[1], pointFs1[0], pointFs2[0]);
  384. pointFs2.Add(footPoint);
  385. }
  386. }
  387. }
  388. }
  389. if (pointFs2.Count == 2)
  390. {
  391. g.DrawLines(pen, pointFs2.ToArray());
  392. startPoint = pointFs2[0];
  393. endPoint = pointFs2[1];
  394. // 垂足坐标
  395. SizeF sizeF = new SizeF();
  396. // 点到直线距离
  397. Length = BasicCalculationHelper.GetDistance(pointFs2[0], pointFs2[1], 10);
  398. //计算需要旋转的角度
  399. angle = BasicCalculationHelper.Angle(pointFs2[0], pointFs2[1], new PointF(pointFs2[0].X, pointFs2[1].Y));
  400. Matrix mtxSave = g.Transform;
  401. Matrix matrix = g.Transform;
  402. // 求线上面三个点
  403. int offsetValuePoint = measureStyleModel.fontSize + measureStyleModel.fontSize / 2;
  404. int offsetValue1Point = measureStyleModel.lineWidth * 2 / 3;
  405. int offsetPoint = offsetValue1Point;
  406. if (drawingPropertiesList != null)
  407. {
  408. // 像素长度
  409. if (drawingPropertiesList.Contains(MeasureAttributes.PixelLength.ToString()))
  410. {
  411. offsetPoint += offsetValuePoint;
  412. }
  413. // 物理长度
  414. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalLength.ToString()))
  415. {
  416. offsetPoint += offsetValuePoint;
  417. }
  418. // 测量方式
  419. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
  420. {
  421. offsetPoint += offsetValuePoint;
  422. }
  423. // 测量单位(中文)
  424. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
  425. {
  426. offsetPoint += offsetValuePoint;
  427. }
  428. // 测量单位(英文)
  429. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
  430. {
  431. offsetPoint += offsetValuePoint;
  432. }
  433. // 像素起始点X
  434. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))
  435. {
  436. offsetPoint += offsetValuePoint;
  437. }
  438. // 像素起始点Y
  439. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))
  440. {
  441. offsetPoint += offsetValuePoint;
  442. }
  443. // 物理起始点X
  444. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))
  445. {
  446. offsetPoint += offsetValuePoint;
  447. }
  448. // 物理起始点Y
  449. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))
  450. {
  451. offsetPoint += offsetValuePoint;
  452. }
  453. }
  454. PointF pointF1;
  455. PointF pointF2;
  456. if (angle < 90)
  457. pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointFs2[0].X + offsetPoint + offsetValue1Point, (int)pointFs2[0].Y), pointFs2[0], angle - 90);
  458. else
  459. pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointFs2[0].X + offsetPoint + offsetValue1Point, (int)pointFs2[0].Y), pointFs2[0], angle + 90);
  460. if (angle < 90)
  461. pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointFs2[1].X + offsetPoint + offsetValue1Point, (int)pointFs2[1].Y), pointFs2[1], angle - 90);
  462. else
  463. pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointFs2[1].X + offsetPoint + offsetValue1Point, (int)pointFs2[1].Y), pointFs2[1], angle + 90);
  464. PointF pointF3 = new PointF((pointF1.X + pointF2.X) / 2, (pointF1.Y + pointF2.Y) / 2);
  465. if (measureStyleModel.linePosition == 0)
  466. this.rotationPoint = pointF1;
  467. else if (measureStyleModel.linePosition == 1)
  468. this.rotationPoint = pointF3;
  469. else if (measureStyleModel.linePosition == 2)
  470. this.rotationPoint = pointF2;
  471. else if (measureStyleModel.linePosition == 3)
  472. this.rotationPoint = pointFs2[0];
  473. else if (measureStyleModel.linePosition == 4)
  474. this.rotationPoint = new PointF((pointFs2[0].X + pointFs2[1].X) / 2, (pointFs2[0].Y + pointFs2[1].Y) / 2);
  475. else if (measureStyleModel.linePosition == 5)
  476. this.rotationPoint = pointFs2[1];
  477. // 画布旋转
  478. if (angle < 90)
  479. {
  480. matrix.RotateAt((float)angle, new PointF(this.rotationPoint.X, this.rotationPoint.Y));
  481. g.Transform = matrix;
  482. }
  483. else
  484. {
  485. angle = BasicCalculationHelper.Angle(pointFs2[1], pointFs2[0], new PointF(pointFs2[1].X, pointFs2[0].Y));
  486. matrix.RotateAt((float)angle, new PointF(this.rotationPoint.X, this.rotationPoint.Y));
  487. g.Transform = matrix;
  488. }
  489. // 是否绘制
  490. if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
  491. {
  492. // 属性文本的间隔定义
  493. int offsetValue = measureStyleModel.fontSize + measureStyleModel.fontSize / 2;
  494. int offsetValue1 = measureStyleModel.lineWidth * 2 / 3;
  495. int offset = offsetValue1;
  496. this.pointL = new Point((int)this.rotationPoint.X, (int)this.rotationPoint.Y);
  497. if (drawingPropertiesList != null)
  498. {
  499. // 像素长度
  500. if (drawingPropertiesList.Contains(MeasureAttributes.PixelLength.ToString()))
  501. {
  502. sizeF = g.MeasureString("" + Math.Round(Length, decimalPlaces) + "px", textfont);
  503. rectangleF8.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
  504. offset += offsetValue;
  505. }
  506. // 物理长度
  507. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalLength.ToString()))
  508. {
  509. string s = Math.Round(Length * unitLength, decimalPlaces).ToString();
  510. if (s.IndexOf(".") == -1)
  511. {
  512. for (int i = 0; i < decimalPlaces; i++)
  513. {
  514. if (i == 0)
  515. s += ".";
  516. s += "0";
  517. }
  518. }
  519. else
  520. {
  521. int a = s.Length - s.IndexOf(".") - 1;
  522. if (a < decimalPlaces)
  523. {
  524. for (int i = 0; i < decimalPlaces - a; i++)
  525. {
  526. s += "0";
  527. }
  528. }
  529. }
  530. sizeF = g.MeasureString(s + this.unit, textfont);
  531. rectangleF9.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
  532. offset += offsetValue;
  533. }
  534. // 测量方式
  535. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
  536. {
  537. sizeF = g.MeasureString("" + PdnResources.GetString("Menu.MeasureAction.LengthMeasurement.Text"), textfont);
  538. rectangleF1.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
  539. offset += offsetValue;
  540. }
  541. // 测量单位(中文)
  542. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
  543. {
  544. sizeF = g.MeasureString("" + this.unitString, textfont);
  545. rectangleF2.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
  546. offset += offsetValue;
  547. }
  548. // 测量单位(英文)
  549. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
  550. {
  551. sizeF = g.MeasureString("" + this.unit, textfont);
  552. rectangleF3.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
  553. offset += offsetValue;
  554. }
  555. // 像素起始点X
  556. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))
  557. {
  558. sizeF = g.MeasureString("" + pointFs2[0].X, textfont);
  559. rectangleF4.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
  560. offset += offsetValue;
  561. }
  562. // 像素起始点Y
  563. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))
  564. {
  565. sizeF = g.MeasureString("" + pointFs2[0].Y, textfont);
  566. rectangleF5.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
  567. offset += offsetValue;
  568. }
  569. // 物理起始点X
  570. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))
  571. {
  572. sizeF = g.MeasureString("" + Math.Round(pointFs2[0].X * unitLength, decimalPlaces), textfont);
  573. rectangleF6.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
  574. offset += offsetValue;
  575. }
  576. // 物理起始点Y
  577. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))
  578. {
  579. sizeF = g.MeasureString("" + Math.Round(pointFs2[0].Y * unitLength, decimalPlaces), textfont);
  580. rectangleF7.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
  581. offset += offsetValue;
  582. }
  583. }
  584. }
  585. if (drawingPropertiesList != null)
  586. {
  587. // 测量方式
  588. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
  589. {
  590. sizeF = g.MeasureString("" + PdnResources.GetString("Menu.MeasureAction.LengthMeasurement.Text"), textfont);
  591. rectangleF1.Width = sizeF.Width;
  592. rectangleF1.Height = sizeF.Height;
  593. g.DrawString("" + PdnResources.GetString("Menu.MeasureAction.LengthMeasurement.Text"), textfont, textbrush, rectangleF1);
  594. }
  595. else
  596. {
  597. rectangleF1 = new RectangleF();
  598. }
  599. // 测量单位(中文)
  600. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
  601. {
  602. sizeF = g.MeasureString("" + this.unitString, textfont);
  603. rectangleF2.Width = sizeF.Width;
  604. rectangleF2.Height = sizeF.Height;
  605. g.DrawString("" + this.unitString, textfont, textbrush, rectangleF2);
  606. }
  607. else
  608. {
  609. rectangleF2 = new RectangleF();
  610. }
  611. // 测量单位(英文)
  612. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
  613. {
  614. sizeF = g.MeasureString("" + this.unit, textfont);
  615. rectangleF3.Width = sizeF.Width;
  616. rectangleF3.Height = sizeF.Height;
  617. g.DrawString("" + this.unit, textfont, textbrush, rectangleF3);
  618. }
  619. else
  620. {
  621. rectangleF3 = new RectangleF();
  622. }
  623. // 像素起始点X
  624. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))
  625. {
  626. sizeF = g.MeasureString("" + pointFs2[0].X, textfont);
  627. rectangleF4.Width = sizeF.Width;
  628. rectangleF4.Height = sizeF.Height;
  629. g.DrawString("" + pointFs2[0].X, textfont, textbrush, rectangleF4);
  630. }
  631. else
  632. {
  633. rectangleF4 = new RectangleF();
  634. }
  635. // 像素起始点Y
  636. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))
  637. {
  638. sizeF = g.MeasureString("" + pointFs2[0].Y, textfont);
  639. rectangleF5.Width = sizeF.Width;
  640. rectangleF5.Height = sizeF.Height;
  641. g.DrawString("" + pointFs2[0].Y, textfont, textbrush, rectangleF5);
  642. }
  643. else
  644. {
  645. rectangleF5 = new RectangleF();
  646. }
  647. // 物理起始点X
  648. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))
  649. {
  650. sizeF = g.MeasureString("" + Math.Round(pointFs2[0].X * unitLength, decimalPlaces), textfont);
  651. rectangleF6.Width = sizeF.Width;
  652. rectangleF6.Height = sizeF.Height;
  653. g.DrawString("" + Math.Round(pointFs2[0].X * unitLength, decimalPlaces), textfont, textbrush, rectangleF6);
  654. }
  655. else
  656. {
  657. rectangleF6 = new RectangleF();
  658. }
  659. // 物理起始点Y
  660. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))
  661. {
  662. sizeF = g.MeasureString("" + Math.Round(pointFs2[0].Y * unitLength, decimalPlaces), textfont);
  663. rectangleF7.Width = sizeF.Width;
  664. rectangleF7.Height = sizeF.Height;
  665. g.DrawString("" + Math.Round(pointFs2[0].Y * unitLength, decimalPlaces), textfont, textbrush, rectangleF7);
  666. }
  667. else
  668. {
  669. rectangleF7 = new RectangleF();
  670. }
  671. // 像素长度
  672. if (drawingPropertiesList.Contains(MeasureAttributes.PixelLength.ToString()))
  673. {
  674. sizeF = g.MeasureString("" + Math.Round(Length, decimalPlaces) + "px", textfont);
  675. rectangleF8.Width = sizeF.Width;
  676. rectangleF8.Height = sizeF.Height;
  677. g.DrawString("" + Math.Round(Length, decimalPlaces) + "px", textfont, textbrush, rectangleF8);
  678. }
  679. else
  680. {
  681. rectangleF8 = new RectangleF();
  682. }
  683. // 物理长度
  684. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalLength.ToString()))
  685. {
  686. string s = Math.Round(Length * unitLength, decimalPlaces).ToString();
  687. if (s.IndexOf(".") == -1)
  688. {
  689. for (int i = 0; i < decimalPlaces; i++)
  690. {
  691. if (i == 0)
  692. s += ".";
  693. s += "0";
  694. }
  695. }
  696. else
  697. {
  698. int a = s.Length - s.IndexOf(".") - 1;
  699. if (a < decimalPlaces)
  700. {
  701. for (int i = 0; i < decimalPlaces - a; i++)
  702. {
  703. s += "0";
  704. }
  705. }
  706. }
  707. sizeF = g.MeasureString(s + this.unit, textfont);
  708. rectangleF9.Width = sizeF.Width;
  709. rectangleF9.Height = sizeF.Height;
  710. g.DrawString(s + this.unit, textfont, textbrush, rectangleF9);
  711. }
  712. else
  713. {
  714. rectangleF9 = new RectangleF();
  715. }
  716. }
  717. //还原为原始旋转矩阵
  718. g.Transform = mtxSave;
  719. matrix.Dispose();
  720. }
  721. pen.Dispose();
  722. }
  723. }
  724. if (this.configurationFile)
  725. this.pointChange = false;
  726. this.mouseUpAttribute = false;
  727. pointChangeObject.Remove(this.drawToolType);
  728. }
  729. /// <summary>
  730. /// 停止绘制时
  731. /// </summary>
  732. /// <param name="up"></param>
  733. public override void MouseUp(bool up)
  734. {
  735. mouseUpPointChange = up;
  736. }
  737. public void AddPoint(Point point)
  738. {
  739. pointArray.Add(point);
  740. }
  741. public override int HandleCount
  742. {
  743. get
  744. {
  745. return pointArray.Count + 1;
  746. }
  747. }
  748. /// <summary>
  749. /// Get handle pointscroll by 1-based number
  750. /// </summary>
  751. /// <param name="handleNumber"></param>
  752. /// <returns></returns>
  753. public override PointF GetHandle(int handleNumber)
  754. {
  755. if (handleNumber < 1)
  756. handleNumber = 1;
  757. if (handleNumber > pointArray.Count && handleNumber != pointArray.Count + 1)
  758. handleNumber = pointArray.Count;
  759. if (handleNumber == pointArray.Count + 1)
  760. return this.pointL;
  761. else
  762. return pointArray[handleNumber - 1];
  763. }
  764. public override Cursor GetHandleCursor(int handleNumber)
  765. {
  766. return handleCursor;
  767. }
  768. private Point GetInsectPoint(Point pt1, Point pt2, int insectPtY)
  769. {
  770. Point pt = new Point();
  771. float k = 0f;
  772. if (pt1.X == pt2.X)//不存在斜率x=x1为直线方程90度
  773. {
  774. pt.X = pt1.X;
  775. pt.Y = insectPtY;
  776. return pt;
  777. }
  778. else if (pt1.Y == pt2.Y && pt1.Y != insectPtY)//y=y1为直线方程,0度,两条直线平行没有交点
  779. {
  780. return pt;
  781. }
  782. else if (pt1.Y == pt2.Y && pt1.Y == insectPtY)//0度,两条直线重合,任意点即为交点
  783. {
  784. pt.X = pt1.X;
  785. pt.Y = insectPtY;
  786. return pt;
  787. }
  788. else
  789. {
  790. k = (float)(pt2.Y - pt1.Y) / (float)(pt2.X - pt1.X);
  791. float b = pt1.Y - k * pt1.X;
  792. float x = (insectPtY - b) / k;
  793. pt.X = (int)x;
  794. pt.Y = insectPtY;
  795. }
  796. return pt;
  797. }
  798. public override void MoveHandleTo(Point point, int handleNumber)
  799. {
  800. double k = 0.0;
  801. if (handleNumber < 1)
  802. handleNumber = 1;
  803. if (handleNumber > pointArray.Count && handleNumber != pointArray.Count + 1)
  804. handleNumber = pointArray.Count;
  805. if (handleNumber == pointArray.Count + 1)
  806. {
  807. point = SetOffsetAfterRotation(point, this.rotationPoint, angle);
  808. if (this.moveKb == 1)
  809. this.rectangleF1.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  810. else if (this.moveKb == 2)
  811. this.rectangleF2.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  812. else if (this.moveKb == 3)
  813. this.rectangleF3.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  814. else if (this.moveKb == 4)
  815. this.rectangleF4.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  816. else if (this.moveKb == 5)
  817. this.rectangleF5.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  818. else if (this.moveKb == 6)
  819. this.rectangleF6.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  820. else if (this.moveKb == 7)
  821. this.rectangleF7.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  822. else if (this.moveKb == 8)
  823. this.rectangleF8.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  824. else if (this.moveKb == 9)
  825. this.rectangleF9.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  826. this.pointL = point;
  827. }
  828. else
  829. {
  830. this.mouseUpPointChange = true;
  831. if (handleNumber == 1)
  832. {
  833. this.rectangleF1.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y);
  834. this.rectangleF2.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y);
  835. this.rectangleF3.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y);
  836. this.rectangleF4.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y);
  837. this.rectangleF5.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y);
  838. this.rectangleF6.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y);
  839. this.rectangleF7.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y);
  840. this.rectangleF8.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y);
  841. this.rectangleF9.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y);
  842. //double angle = BasicCalculationHelper.Angle(pointArray[0], pointArray[1], new PointF(pointArray[0].X, pointArray[1].Y));
  843. pointArray[handleNumber - 1] = point;
  844. //double angle1 = BasicCalculationHelper.Angle(pointArray[0], pointArray[1], new PointF(pointArray[0].X, pointArray[1].Y));
  845. //PointF pointF = BasicCalculationHelper.GetAnglePoint(pointArray[3], pointArray[2], - (angle - angle1));
  846. //pointArray[3] = pointF;
  847. MoveHandleTo(point, 4);
  848. }
  849. else if (handleNumber == 2)
  850. {
  851. //double angle = BasicCalculationHelper.Angle(pointArray[1], pointArray[0], new PointF(pointArray[1].X, pointArray[0].Y));
  852. pointArray[handleNumber - 1] = point;
  853. //double angle1 = BasicCalculationHelper.Angle(pointArray[1], pointArray[0], new PointF(pointArray[1].X, pointArray[0].Y));
  854. //PointF pointF = BasicCalculationHelper.GetAnglePoint(pointArray[2], pointArray[3], - (angle - angle1));
  855. //pointArray[2] = pointF;
  856. MoveHandleTo(point, 3);
  857. }
  858. else if(handleNumber == 4)
  859. {
  860. k = (double)(pointArray[1].Y - pointArray[0].Y) / (pointArray[1].X - pointArray[0].X);
  861. double y = 0;
  862. double x = 0;
  863. if (Math.Abs(k) >= 1)
  864. {
  865. y = point.Y;
  866. x = (point.Y - pointArray[2].Y) / k + pointArray[2].X;
  867. }
  868. else
  869. {
  870. x = point.X;
  871. y = k * (point.X - pointArray[2].X) + pointArray[2].Y;
  872. }
  873. point = new Point((int)x, (int)y);
  874. pointArray[handleNumber - 1] = point;
  875. }
  876. else if (handleNumber == 3)
  877. {
  878. k = (double)(pointArray[1].Y - pointArray[0].Y) / (pointArray[1].X - pointArray[0].X);
  879. double y = 0;
  880. double x = 0;
  881. if (Math.Abs(k) >= 1)
  882. {
  883. y = point.Y;
  884. x = (point.Y - pointArray[3].Y) / k + pointArray[3].X;
  885. }
  886. else
  887. {
  888. x = point.X;
  889. y = k * (point.X - pointArray[3].X) + pointArray[3].Y;
  890. }
  891. point = new Point((int)x, (int)y);
  892. pointArray[handleNumber - 1] = point;
  893. }
  894. }
  895. Invalidate();
  896. }
  897. public override void Move(int deltaX, int deltaY)
  898. {
  899. int n = pointArray.Count;
  900. for (int i = 0; i < n; i++)
  901. {
  902. PointF point = new PointF(pointArray[i].X + ISurfaceBox.UnscaleScalar(deltaX), pointArray[i].Y + ISurfaceBox.UnscaleScalar(deltaY));
  903. pointArray[i] = point;
  904. }
  905. this.startPoint = pointArray[0];
  906. int x = ISurfaceBox.UnscaleScalar(deltaX);
  907. int y = ISurfaceBox.UnscaleScalar(deltaY);
  908. pointL.X += x;
  909. pointL.Y += y;
  910. this.mouseUpPointChange = true;
  911. Invalidate();
  912. }
  913. /// <summary>
  914. /// 用于创建一个路径或者是闭合的范围
  915. /// 用于响应点击选中
  916. /// 需要咨询用户是仅点击线还是矩形选择
  917. /// </summary>
  918. protected virtual void CreateObjects()
  919. {
  920. if (AreaPath != null)
  921. return;
  922. AreaPath = new GraphicsPath();
  923. AreaPath.AddRectangle(GetBoundingBox());
  924. AreaPath.CloseFigure();
  925. AreaRegion = new Region(AreaPath);
  926. }
  927. /// <summary>
  928. /// Invalidate object.
  929. /// When object is invalidated, path used for hit test
  930. /// is released and should be created again.
  931. /// </summary>
  932. protected void Invalidate()
  933. {
  934. if (AreaPath != null)
  935. {
  936. AreaPath.Dispose();
  937. AreaPath = null;
  938. }
  939. if (AreaPen != null)
  940. {
  941. AreaPen.Dispose();
  942. AreaPen = null;
  943. }
  944. if (AreaRegion != null)
  945. {
  946. AreaRegion.Dispose();
  947. AreaRegion = null;
  948. }
  949. }
  950. protected GraphicsPath AreaPath
  951. {
  952. get
  953. {
  954. return areaPath;
  955. }
  956. set
  957. {
  958. areaPath = value;
  959. }
  960. }
  961. protected Pen AreaPen
  962. {
  963. get
  964. {
  965. return areaPen;
  966. }
  967. set
  968. {
  969. areaPen = value;
  970. }
  971. }
  972. protected Region AreaRegion
  973. {
  974. get
  975. {
  976. return areaRegion;
  977. }
  978. set
  979. {
  980. areaRegion = value;
  981. }
  982. }
  983. /// <summary>
  984. /// Draw tracker for selected object
  985. /// </summary>
  986. /// <param name="g"></param>
  987. public override void DrawTracker(Graphics g)
  988. {
  989. if (!Selected)
  990. return;
  991. SolidBrush brush = new SolidBrush(Color.Black);
  992. for (int i = 1; i <= HandleCount; i++)
  993. {
  994. if (i == HandleCount)
  995. brush = new SolidBrush(Color.Transparent);
  996. g.FillRectangle(brush, GetHandleRectangle(i));
  997. }
  998. brush.Dispose();
  999. RectangleF r = GetBoundingBox();
  1000. //g.DrawRectangle(new Pen(Color.White), r.X, r.Y, r.Width, r.Height);
  1001. }
  1002. Point point = new Point();
  1003. /// <summary>
  1004. /// Hit test.
  1005. /// Return value: -1 - no hit
  1006. /// 0 - hit anywhere
  1007. /// > 1 - handle number
  1008. /// </summary>
  1009. /// <param name="pointscroll"></param>
  1010. /// <returns></returns>
  1011. public override int HitTest(Point point)
  1012. {
  1013. this.point = point;
  1014. if (Selected)
  1015. {
  1016. for (int i = 1; i <= HandleCount; i++)
  1017. {
  1018. if (GetHandleRectangle(i).Contains(point))
  1019. return i;
  1020. }
  1021. if (GetRectanglePosition(this.rectangleF1, point, rotationPoint, angle))
  1022. {
  1023. this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle);
  1024. moveKb = 1;
  1025. return this.pointArray.Count + 1;
  1026. }
  1027. else if (GetRectanglePosition(this.rectangleF2, point, rotationPoint, angle))
  1028. {
  1029. this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle);
  1030. moveKb = 2;
  1031. return this.pointArray.Count + 1;
  1032. }
  1033. else if (GetRectanglePosition(this.rectangleF3, point, rotationPoint, angle))
  1034. {
  1035. this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle);
  1036. moveKb = 3;
  1037. return this.pointArray.Count + 1;
  1038. }
  1039. else if (GetRectanglePosition(this.rectangleF4, point, rotationPoint, angle))
  1040. {
  1041. this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle);
  1042. moveKb = 4;
  1043. return this.pointArray.Count + 1;
  1044. }
  1045. else if (GetRectanglePosition(this.rectangleF5, point, rotationPoint, angle))
  1046. {
  1047. this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle);
  1048. moveKb = 5;
  1049. return this.pointArray.Count + 1;
  1050. }
  1051. else if (GetRectanglePosition(this.rectangleF6, point, rotationPoint, angle))
  1052. {
  1053. this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle);
  1054. moveKb = 6;
  1055. return this.pointArray.Count + 1;
  1056. }
  1057. else if (GetRectanglePosition(this.rectangleF7, point, rotationPoint, angle))
  1058. {
  1059. this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle);
  1060. moveKb = 7;
  1061. return this.pointArray.Count + 1;
  1062. }
  1063. else if (GetRectanglePosition(this.rectangleF8, point, rotationPoint, angle))
  1064. {
  1065. this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle);
  1066. moveKb = 8;
  1067. return this.pointArray.Count + 1;
  1068. }
  1069. else if (GetRectanglePosition(this.rectangleF9, point, rotationPoint, angle))
  1070. {
  1071. this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle);
  1072. moveKb = 9;
  1073. return this.pointArray.Count + 1;
  1074. }
  1075. }
  1076. if (PointInObject(point))
  1077. return 0;
  1078. return -1;
  1079. }
  1080. protected override bool PointInObject(Point point)
  1081. {
  1082. CreateObjects();
  1083. return AreaRegion.IsVisible(point);
  1084. }
  1085. public override bool IntersectsWith(Rectangle rectangle)
  1086. {
  1087. CreateObjects();
  1088. return AreaRegion.IsVisible(rectangle);
  1089. }
  1090. public override RectangleF GetBoundingBox()
  1091. {
  1092. float minx = 0, maxx = 0, miny = 0, maxy = 0;
  1093. for (int i = 0; i < pointArray.Count; i++)
  1094. {
  1095. if (i == 0)
  1096. {
  1097. minx = maxx = pointArray[i].X;
  1098. miny = maxy = pointArray[i].Y;
  1099. }
  1100. else
  1101. {
  1102. if (pointArray[i].X > maxx) maxx = pointArray[i].X;
  1103. if (pointArray[i].X < minx) minx = pointArray[i].X;
  1104. if (pointArray[i].Y > maxy) maxy = pointArray[i].Y;
  1105. if (pointArray[i].Y < miny) miny = pointArray[i].Y;
  1106. }
  1107. }
  1108. return new RectangleF(minx, miny, maxx - minx, maxy - miny);
  1109. }
  1110. internal void setNextPoint(Point p)
  1111. {
  1112. AddPoint(p);
  1113. //startPoint = endPoint;
  1114. //endPoint = p;
  1115. }
  1116. internal void setEndPoint(Point p)
  1117. {
  1118. endPoint = p;
  1119. }
  1120. public override List<PointF> GetPoints()
  1121. {
  1122. return pointArray;
  1123. }
  1124. public override ParentStyleModel GetStyle()
  1125. {
  1126. return measureStyleModel;
  1127. }
  1128. }
  1129. }