SGraphMoveCommand.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.SGraphMoveCommand = void 0;
  4. const SGraphCommand_1 = require("./SGraphCommand");
  5. const lib_1 = require("@persagy-web/draw/lib");
  6. class SGraphMoveCommand extends SGraphCommand_1.SGraphCommand {
  7. constructor(scene, item, old, pos) {
  8. super(scene);
  9. this.item = item;
  10. this.old = old;
  11. this.pos = pos;
  12. this.command = "SGraphMoveCommand";
  13. this.desc = `移动对象=${item.id}`;
  14. }
  15. mergeWith(command) {
  16. if (command instanceof SGraphMoveCommand && command.item == this.item) {
  17. command.pos = this.pos;
  18. return true;
  19. }
  20. return false;
  21. }
  22. redo() {
  23. this.item.pos = new lib_1.SPoint(this.pos.x, this.pos.y);
  24. this.item.update();
  25. }
  26. undo() {
  27. this.item.pos = new lib_1.SPoint(this.old.x, this.old.y);
  28. this.item.update();
  29. }
  30. toString() {
  31. return `oldPos=${JSON.stringify(this.old)};\nnewPos=${JSON.stringify(this.pos)}`;
  32. }
  33. }
  34. exports.SGraphMoveCommand = SGraphMoveCommand;