MeasureCenterCenterSize.cs 80 KB

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