MeasureCircle.cs 60 KB

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