MeasureParallelLine.cs 76 KB

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