MeasureCenterCenterSize.cs 83 KB

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