MeasureDiameterCircle.cs 67 KB

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