123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import { SPoint } from "@persagy-web/draw";
- import { SGraphCommand, SGraphItem, SGraphScene } from "@persagy-web/graph/";
- export class SGraphPointListDelete extends SGraphCommand {
-
- readonly command: string;
-
- item: SGraphItem;
-
- index: number | null;
-
- pos: SPoint | null;
-
- pointList: SPoint[];
-
- constructor(
- scene: SGraphScene,
- item: SGraphItem,
- pointList: SPoint[],
- pos: SPoint,
- index: number | null = null
- ) {
- super(scene);
- this.item = item;
- this.index = index;
- this.pointList = pointList;
- this.pos = pos;
- this.command = "SGraphPointListDelete";
- this.desc = `删除折点=${item.id}`;
- }
-
- redo(): void {
- if (this.index == null) {
- this.pointList.pop();
- } else {
- this.pointList.splice(this.index, 1);
- }
- this.item.update();
- }
-
- undo(): void {
- if (this.pos == null) return;
- if (this.index == null) {
- this.pointList.push(this.pos);
- } else {
- this.pointList.splice(this.index, 0, this.pos);
- }
- this.item.update();
- }
-
- toString(): string {
- const pointList = `pointList=${JSON.stringify(this.pointList)}`;
- const pos = `pos=${JSON.stringify(this.pos)}`;
- const index = `index=${this.index}`;
- return `${index};\n${pos};\n${pointList}`;
- }
- }
|