SGraphPointListInsert.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.SGraphPointListInsert = void 0;
  4. const lib_1 = require("@persagy-web/draw/lib");
  5. const index_1 = require("../index");
  6. class SGraphPointListInsert extends index_1.SGraphCommand {
  7. constructor(scene, item, pointList, pos, index = null) {
  8. super(scene);
  9. this.item = item;
  10. this.pos = pos;
  11. this.index = index;
  12. this.pointList = pointList;
  13. this.command = "SGraphPointListInsert";
  14. this.desc = `添加折点=${item.id}`;
  15. }
  16. redo() {
  17. const point = new lib_1.SPoint(this.pos.x, this.pos.y);
  18. if (this.index == null) {
  19. this.pointList.push(point);
  20. }
  21. else {
  22. this.pointList.splice(this.index, 0, point);
  23. }
  24. this.item.update();
  25. }
  26. undo() {
  27. if (this.index == null) {
  28. this.pointList.pop();
  29. }
  30. else {
  31. this.pointList.splice(this.index, 1);
  32. }
  33. this.item.update();
  34. }
  35. toString() {
  36. const pointList = `pointList=${JSON.stringify(this.pointList)}`;
  37. const pos = `pos=${JSON.stringify(this.pos)}`;
  38. const index = `index=${this.index}`;
  39. return `${index};\n${pos};\n${pointList}`;
  40. }
  41. }
  42. exports.SGraphPointListInsert = SGraphPointListInsert;