MeasureMulPLine.cs 59 KB

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