MeasurePointEdgeSize.cs 69 KB

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