MeasureHMulPLine.cs 58 KB

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