SGraphPointListDelete.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * ********************************************************************************************************************
  3. *
  4. * :*$@@%$*: ;: ;; ;;
  5. * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
  6. * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
  7. * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
  8. * =@* %! @ $= % %@= =%@! %=
  9. * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
  10. * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
  11. * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
  12. * $@* ;@@@%=!: *@*
  13. * =@$ ;;;!=%@@@@=! =@!
  14. * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司
  15. * ;%@@$=$@@%* *@@@$=%@@%;
  16. * ::;:: ::;:: All rights reserved.
  17. *
  18. * ********************************************************************************************************************
  19. */
  20. import { SPoint } from "@saga-web/draw/lib";
  21. import { SGraphCommand, SGraphItem, SGraphScene } from "../index";
  22. /**
  23. * 多边形、折线等相关顶点的位置删除命令
  24. *
  25. * @author 韩耀龙
  26. */
  27. export class SGraphPointListDelete extends SGraphCommand {
  28. /** 命令名称 */
  29. readonly command: string;
  30. /** 指向item对象 */
  31. item: SGraphItem;
  32. /** 索引 */
  33. index: number | null;
  34. /** 删除位置 */
  35. pos: SPoint | null;
  36. /** 顶点数组 */
  37. pointList: SPoint[];
  38. /**
  39. * 构造函数
  40. * @param scene item所在场景
  41. * @param item 指向item对象
  42. * @param pointList 顶点数组
  43. * @param pos 删除的点
  44. * @param index 索引
  45. */
  46. constructor(
  47. scene: SGraphScene,
  48. item: SGraphItem,
  49. pointList: SPoint[],
  50. pos: SPoint,
  51. index: number | null = null
  52. ) {
  53. super(scene);
  54. this.item = item;
  55. this.index = index;
  56. this.pointList = pointList;
  57. this.pos = pos;
  58. this.command = "SGraphPointListDelete";
  59. this.desc = `删除折点=${item.id}`;
  60. } // Constructor
  61. /**
  62. * 执行重做操作执行
  63. */
  64. redo(): void {
  65. if (this.index == null) {
  66. this.pointList.pop();
  67. } else {
  68. this.pointList.splice(this.index, 1);
  69. }
  70. this.item.update();
  71. } // Function redo()
  72. /**
  73. * 执行取消操作执行
  74. */
  75. undo(): void {
  76. if (this.pos == null) return;
  77. if (this.index == null) {
  78. this.pointList.push(this.pos);
  79. } else {
  80. this.pointList.splice(this.index, 0, this.pos);
  81. }
  82. this.item.update();
  83. } // Function undo()
  84. /**
  85. * 命令细节描述
  86. *
  87. * */
  88. toString(): string {
  89. const pointList = `pointList=${JSON.stringify(this.pointList)}`;
  90. const pos = `pos=${JSON.stringify(this.pos)}`;
  91. const index = `index=${this.index}`;
  92. return `${index};\n${pos};\n${pointList}`;
  93. } // Function toString()
  94. } // Class SGraphPointListDelete