SGraphPointListInsert.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 } from "../index";
  22. /**
  23. * 多边形、折线等相关顶点的位置插入命令
  24. *
  25. * @author 韩耀龙
  26. */
  27. export class SGraphPointListInsert extends SGraphCommand {
  28. /** 指向item对象 */
  29. item: SGraphItem;
  30. /** 当前位置 */
  31. pos: SPoint;
  32. /** 索引 */
  33. index: number | null;
  34. /** 顶点数组 */
  35. pointList: SPoint[];
  36. /**
  37. * 构造函数
  38. * @param item 指向item对象
  39. * @param pointList 顶点数组
  40. * @param pos 当前位置
  41. * @param index 索引
  42. */
  43. constructor(
  44. item: SGraphItem,
  45. pointList: SPoint[],
  46. pos: SPoint,
  47. index: number | null = null
  48. ) {
  49. super(null);
  50. this.item = item;
  51. this.pos = pos;
  52. this.index = index;
  53. this.pointList = pointList;
  54. } // Constructor
  55. /**
  56. * 执行重做操作执行
  57. */
  58. redo(): void {
  59. const point = new SPoint(this.pos.x, this.pos.y);
  60. if (this.index == null) {
  61. this.pointList.push(point);
  62. } else {
  63. this.pointList.splice(this.index, 0, point);
  64. }
  65. this.item.update();
  66. } // Function redo()
  67. /**
  68. * 执行取消操作执行
  69. */
  70. undo(): void {
  71. if (this.index == null) {
  72. this.pointList.pop();
  73. } else {
  74. this.pointList.splice(this.index, 1);
  75. }
  76. this.item.update();
  77. } // Function undo()
  78. } // Class SGraphPointListInsert()