MeasurePointCenterSize.cs 67 KB

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