MeasureLength.cs 55 KB

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