GasButton.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. *
  3. * @author seagle
  4. * @date 2024-7-22
  5. * @Description 管路图元件对象封装
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace MECF.Framework.UI.Core.DxfScript
  13. {
  14. public class GasButton : GasBaseShape
  15. {
  16. public GasPolyLine InnerPolyLine { get; set; } = null;
  17. public GasText InnerText { get; set; } = null;
  18. public string Text { get; set; }
  19. public string DataKey { get; set; }
  20. public GasButton(GasPolyLine polyLine,GasText text)
  21. {
  22. InnerPolyLine = polyLine;
  23. InnerText = text;
  24. //按上、右、下、左的顺序排线段
  25. GasLine topLine = null;
  26. GasLine rightLine = null;
  27. GasLine bottomLine = null;
  28. GasLine leftLine = null;
  29. foreach(GasLine line in InnerPolyLine.InnerLines)
  30. {
  31. if (line.IsHorizental)
  32. {
  33. if (topLine == null)
  34. {
  35. topLine = line;
  36. }
  37. else
  38. {
  39. if (line.Y1 > topLine.Y1)
  40. {
  41. bottomLine = topLine;
  42. topLine = line;
  43. }
  44. else
  45. {
  46. bottomLine = line;
  47. }
  48. }
  49. }
  50. else
  51. {
  52. //矩形,这里肯定就是竖线了
  53. if (rightLine == null)
  54. {
  55. rightLine = line;
  56. }
  57. else
  58. {
  59. if (line.X1 > rightLine.X1)
  60. {
  61. leftLine = rightLine;
  62. rightLine = line;
  63. }
  64. else
  65. {
  66. leftLine = line;
  67. }
  68. }
  69. }
  70. }
  71. InnerPolyLine.InnerLines.Clear();
  72. InnerPolyLine.InnerLines.Add(topLine);
  73. InnerPolyLine.InnerLines.Add(rightLine);
  74. InnerPolyLine.InnerLines.Add(bottomLine);
  75. InnerPolyLine.InnerLines.Add(leftLine);
  76. Id = InnerPolyLine.Id;
  77. SetDataKey();
  78. }
  79. public override bool Contains(double x, double y)
  80. {
  81. return InnerPolyLine.Contains(x, y);
  82. }
  83. public override void Move(double x, double y)
  84. {
  85. InnerPolyLine.Move(x, y);
  86. InnerText.Move(x, y);
  87. }
  88. private void SetDataKey()
  89. {
  90. DataKey = $"PM1.{InnerText.Text}Enable";
  91. }
  92. }
  93. }