MeasureInnerCircle.cs 64 KB

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