MeasureCircle.cs 63 KB

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