MeasurePointArcSize.cs 72 KB

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