|
@@ -53,12 +53,7 @@ export class SPolygonItem extends SGraphItem {
|
|
|
// 编辑当前状态
|
|
|
set status(value: SItemStatus) {
|
|
|
this._status = value;
|
|
|
- // 如果状态为show则需清栈
|
|
|
- if (value == SItemStatus.Normal) {
|
|
|
- if (this.undoStack) {
|
|
|
- this.undoStack.clear();
|
|
|
- }
|
|
|
- }
|
|
|
+ this.undoStack.clear();
|
|
|
this.update();
|
|
|
}
|
|
|
data: any | null = null;
|
|
@@ -102,7 +97,7 @@ export class SPolygonItem extends SGraphItem {
|
|
|
/** 场景像素 */
|
|
|
private isAlt: boolean = false;
|
|
|
/** undoredo堆栈 */
|
|
|
- protected undoStack: SUndoStack | null = new SUndoStack();
|
|
|
+ protected undoStack: SUndoStack = new SUndoStack();
|
|
|
|
|
|
/**
|
|
|
* 构造函数
|
|
@@ -250,26 +245,28 @@ export class SPolygonItem extends SGraphItem {
|
|
|
// 绘制顶点块
|
|
|
painter.pen.color = SColor.Black;
|
|
|
painter.brush.color = SColor.White;
|
|
|
- pointList.forEach((item, index) => {
|
|
|
+ pointList.forEach(item => {
|
|
|
painter.drawCircle(item.x, item.y, painter.toPx(this.len / 2));
|
|
|
});
|
|
|
// 如果最后一个点在第一个点的灵敏度范围内,第一个点填充变红
|
|
|
- if (
|
|
|
- SMathUtil.pointDistance(
|
|
|
- this.lastPoint.x,
|
|
|
- this.lastPoint.y,
|
|
|
- this.pointList[0].x,
|
|
|
- this.pointList[0].y
|
|
|
- ) < this.scenceLen
|
|
|
- ) {
|
|
|
- // 绘制第一个点的顶点块
|
|
|
- painter.pen.color = SColor.Black;
|
|
|
- painter.brush.color = SColor.Red;
|
|
|
- painter.drawCircle(
|
|
|
- this.pointList[0].x,
|
|
|
- this.pointList[0].y,
|
|
|
- painter.toPx(this.len / 2)
|
|
|
- );
|
|
|
+ if (this.pointList.length) {
|
|
|
+ if (
|
|
|
+ SMathUtil.pointDistance(
|
|
|
+ this.lastPoint.x,
|
|
|
+ this.lastPoint.y,
|
|
|
+ this.pointList[0].x,
|
|
|
+ this.pointList[0].y
|
|
|
+ ) < this.scenceLen
|
|
|
+ ) {
|
|
|
+ // 绘制第一个点的顶点块
|
|
|
+ painter.pen.color = SColor.Black;
|
|
|
+ painter.brush.color = SColor.Red;
|
|
|
+ painter.drawCircle(
|
|
|
+ this.pointList[0].x,
|
|
|
+ this.pointList[0].y,
|
|
|
+ painter.toPx(this.len / 2)
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
painter.drawPolygon(pointList);
|
|
@@ -427,9 +424,7 @@ export class SPolygonItem extends SGraphItem {
|
|
|
protected recordAction(SGraphCommand: any, any: any[]): void {
|
|
|
// 记录相关命令并推入堆栈中
|
|
|
const sgraphcommand = new SGraphCommand(this.scene, this, ...any);
|
|
|
- if (this.undoStack) {
|
|
|
- this.undoStack.push(sgraphcommand);
|
|
|
- }
|
|
|
+ this.undoStack.push(sgraphcommand);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -439,9 +434,7 @@ export class SPolygonItem extends SGraphItem {
|
|
|
if (this.status == SItemStatus.Normal) {
|
|
|
return;
|
|
|
}
|
|
|
- if (this.undoStack) {
|
|
|
- this.undoStack.undo();
|
|
|
- }
|
|
|
+ this.undoStack.undo();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -451,9 +444,7 @@ export class SPolygonItem extends SGraphItem {
|
|
|
if (this.status == SItemStatus.Normal) {
|
|
|
return;
|
|
|
}
|
|
|
- if (this.undoStack) {
|
|
|
- this.undoStack.redo();
|
|
|
- }
|
|
|
+ this.undoStack.redo();
|
|
|
}
|
|
|
|
|
|
///////////////////////////////
|
|
@@ -473,9 +464,6 @@ export class SPolygonItem extends SGraphItem {
|
|
|
} else if (SItemStatus.Edit == this.status) {
|
|
|
this.status = SItemStatus.Normal;
|
|
|
this.releaseItem();
|
|
|
- if (this.undoStack) {
|
|
|
- this.undoStack.clear();
|
|
|
- }
|
|
|
}
|
|
|
this.update();
|
|
|
return true;
|
|
@@ -500,10 +488,6 @@ export class SPolygonItem extends SGraphItem {
|
|
|
this.$emit("finishCreated");
|
|
|
//1 grabItem 置为null
|
|
|
this.releaseItem();
|
|
|
- //2 清空undo
|
|
|
- if (this.undoStack) {
|
|
|
- this.undoStack.clear();
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
} else if (this.status == SItemStatus.Edit) {
|
|
@@ -545,22 +529,21 @@ export class SPolygonItem extends SGraphItem {
|
|
|
// 如果状态为编辑状态则添加点
|
|
|
if (this.status == SItemStatus.Create) {
|
|
|
// 新增顶点
|
|
|
- let len = SMathUtil.pointDistance(
|
|
|
- event.x,
|
|
|
- event.y,
|
|
|
- this.pointList[0].x,
|
|
|
- this.pointList[0].y
|
|
|
- );
|
|
|
- if (this.pointList.length > 2 && len < this.scenceLen) {
|
|
|
+ let len = -1;
|
|
|
+ if (this.pointList.length) {
|
|
|
+ len = SMathUtil.pointDistance(
|
|
|
+ event.x,
|
|
|
+ event.y,
|
|
|
+ this.pointList[0].x,
|
|
|
+ this.pointList[0].y
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (this.pointList.length > 2 && len > 0 && len < this.scenceLen) {
|
|
|
this.status = SItemStatus.Normal;
|
|
|
//3 传递完成事件状态
|
|
|
this.$emit("finishCreated");
|
|
|
//1 grabItem 置为null
|
|
|
this.releaseItem();
|
|
|
- //2 清空undo
|
|
|
- if (this.undoStack) {
|
|
|
- this.undoStack.clear();
|
|
|
- }
|
|
|
} else {
|
|
|
this.insertPoint(event.x, event.y);
|
|
|
// 记录新增顶点操作记录压入堆栈
|