MeasureVMulPLine.cs 55 KB

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