MeasureParallelLine.cs 72 KB

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