/* * ******************************************************************************************************************** * * :*$@@%$*: ;: ;; ;; * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@ * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$ * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$= * =@* %! @ $= % %@= =%@! %= * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =% * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%* * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$ * $@* ;@@@%=!: *@* * =@$ ;;;!=%@@@@=! =@! * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司 * ;%@@$=$@@%* *@@@$=%@@%; * ::;:: ::;:: All rights reserved. * * ******************************************************************************************************************** */ import { SPoint } from "@saga-web/draw/lib"; import { SGraphCommand, SGraphItem, SGraphScene } from "../index"; /** * 多边形、折线等相关顶点的位置删除命令 * * @author 韩耀龙 */ export class SGraphPointListDelete extends SGraphCommand { /** 命令名称 */ readonly command: string; /** 指向item对象 */ item: SGraphItem; /** 索引 */ index: number | null; /** 删除位置 */ pos: SPoint | null; /** 顶点数组 */ pointList: SPoint[]; /** * 构造函数 * @param scene item所在场景 * @param item 指向item对象 * @param pointList 顶点数组 * @param pos 删除的点 * @param index 索引 */ 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}`; } // Constructor /** * 执行重做操作执行 */ redo(): void { if (this.index == null) { this.pointList.pop(); } else { this.pointList.splice(this.index, 1); } this.item.update(); } // Function redo() /** * 执行取消操作执行 */ 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(); } // Function undo() /** * 命令细节描述 * * */ 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}`; } // Function toString() } // Class SGraphPointListDelete