MeasureOuterCircle.cs 65 KB

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