MeasureVMulPLine.cs 59 KB

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