STextMarkerItem.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import { Marker } from "../../types/topology/Marker";
  2. import { SGraphItem, STextItem } from "@saga-web/graph/lib";
  3. import { SPainter, SColor } from "@saga-web/draw";
  4. /**
  5. * 标识对象Item(文本类型)
  6. *
  7. * * @author 张宇(taohuzy@163.com)
  8. */
  9. export class STextMarkerItem extends STextItem {
  10. /** 标识对象数据 */
  11. data: Marker;
  12. /** x轴缩放属性 */
  13. _scaleX: number = 1;
  14. get scaleX(): number {
  15. return this._scaleX;
  16. }
  17. set scaleX(v: number) {
  18. this._scaleX = v;
  19. if (this.data.Scale) {
  20. this.data.Scale.X = v;
  21. }
  22. this.update();
  23. }
  24. /** y轴缩放属性 */
  25. _scaleY: number = 1;
  26. get scaleY(): number {
  27. return this._scaleY;
  28. }
  29. set scaleY(v: number) {
  30. this._scaleY = v;
  31. if (this.data.Scale) {
  32. this.data.Scale.Y = v;
  33. }
  34. this.update();
  35. }
  36. /** y轴旋转属性 */
  37. _rolate: number = 0;
  38. get rolate(): number {
  39. return this._rolate;
  40. }
  41. set rolate(v: number) {
  42. this._rolate = v;
  43. if (this.data.Rolate) {
  44. this.data.Rolate.Z = v;
  45. }
  46. this.update();
  47. }
  48. set name(v: string) {
  49. this.data.Name = v;
  50. }
  51. set text(v: string) {
  52. if (this.data.Properties) {
  53. this.data.Properties.Text = v;
  54. }
  55. }
  56. set x(v: number) {
  57. this.data.Pos.X = v;
  58. }
  59. set y(v: number) {
  60. this.data.Pos.Y = v;
  61. }
  62. set width(v: number) {
  63. if (this.data.Size) {
  64. this.data.Size.Width = v;
  65. }
  66. }
  67. set height(v: number) {
  68. if (this.data.Size) {
  69. this.data.Size.Height = v;
  70. }
  71. }
  72. /**
  73. * 构造函数
  74. *
  75. * @param parent 指向父对象
  76. * @param data 标识对象数据
  77. */
  78. constructor(parent: SGraphItem | null, data: Marker) {
  79. super(parent);
  80. this.data = data;
  81. this.moveTo(data.Pos.X, data.Pos.Y);
  82. if (this.data.Scale) {
  83. this.scaleX = this.data.Scale.X;
  84. this.scaleY = this.data.Scale.Y;
  85. }
  86. if (this.data.Rolate && this.data.Rolate.Z) {
  87. this.rolate = this.data.Rolate.Z;
  88. }
  89. if (this.data.Size) {
  90. this.width = this.data.Size.Width;
  91. this.height = this.data.Size.Height;
  92. }
  93. if (this.data.Properties && this.data.Properties.Text) {
  94. if (this.data.Properties.Text instanceof String) {
  95. this.text = this.data.Properties.Text;
  96. }
  97. }
  98. } // Constructor
  99. /**
  100. * Item绘制操作
  101. *
  102. * @param painter 绘画类
  103. */
  104. onDraw(painter: SPainter): void {
  105. // 绘制文本
  106. painter.brush.color = new SColor(this.color);
  107. painter.font = this.font;
  108. painter.scale(this.scaleX, this.scaleY);
  109. painter.rotate(this.rolate);
  110. this.drawFormatText(painter);
  111. } // Function onDraw()
  112. } // Class STextMarkerItem