|
@@ -59,13 +59,13 @@ export class SPolygonItem extends SGraphItem {
|
|
|
/** 是否闭合 */
|
|
|
closeFlag: boolean = false;
|
|
|
// 当前状态
|
|
|
- _status: number = SItemStatus.Normal;
|
|
|
+ protected _status: number = SItemStatus.Normal;
|
|
|
// 获取当前状态
|
|
|
- get getStatus(): number {
|
|
|
+ get status(): SItemStatus {
|
|
|
return this._status;
|
|
|
}
|
|
|
// 编辑当前状态
|
|
|
- set setStatus(value: number) {
|
|
|
+ set status(value: SItemStatus) {
|
|
|
this._status = value;
|
|
|
// 如果状态为show则需清栈
|
|
|
if (value == SItemStatus.Normal) {
|
|
@@ -116,7 +116,7 @@ export class SPolygonItem extends SGraphItem {
|
|
|
/** 场景像素 */
|
|
|
private isAlt: boolean = false;
|
|
|
/** undoredo堆栈 */
|
|
|
- private undoStack: SUndoStack | null = new SUndoStack();
|
|
|
+ protected undoStack: SUndoStack | null = new SUndoStack();
|
|
|
|
|
|
/**
|
|
|
* 构造函数
|
|
@@ -347,12 +347,16 @@ export class SPolygonItem extends SGraphItem {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // 如果再线上则为新增点
|
|
|
+ // 判断是否有点
|
|
|
if (len.Point) {
|
|
|
+ console.log(index,len.Point);
|
|
|
+ // 点在了多边形的边上
|
|
|
if (len.MinDis <= this.scenceLen) {
|
|
|
this.pointList.splice(index + 1, 0, len.Point);
|
|
|
// 记录新增顶点操作记录压入堆栈
|
|
|
- this.recordAction(SGraphPointListInsert, [this.pointList, len.Point, index + 1])
|
|
|
+ this.recordAction(SGraphPointListInsert, [this.pointList, len.Point, index + 1]);
|
|
|
+ } else { //没点在多边形边上也没点在多边形顶点上
|
|
|
+ super.onMouseDown(event);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
@@ -385,7 +389,7 @@ export class SPolygonItem extends SGraphItem {
|
|
|
* 执行取消操作执行
|
|
|
*/
|
|
|
undo(): void {
|
|
|
- if (this._status == SItemStatus.Normal) {
|
|
|
+ if (this.status == SItemStatus.Normal) {
|
|
|
return
|
|
|
}
|
|
|
if (this.undoStack) {
|
|
@@ -397,7 +401,7 @@ export class SPolygonItem extends SGraphItem {
|
|
|
* 执行重做操作执行
|
|
|
*/
|
|
|
redo(): void {
|
|
|
- if (this._status == SItemStatus.Normal) {
|
|
|
+ if (this.status == SItemStatus.Normal) {
|
|
|
return
|
|
|
}
|
|
|
if (this.undoStack) {
|
|
@@ -416,11 +420,11 @@ export class SPolygonItem extends SGraphItem {
|
|
|
*/
|
|
|
onDoubleClick(event: SMouseEvent): boolean {
|
|
|
// 如果位show状态 双击改对象则需改为编辑状态
|
|
|
- if (SItemStatus.Normal == this._status) {
|
|
|
- this._status = SItemStatus.Edit;
|
|
|
+ if (SItemStatus.Normal == this.status) {
|
|
|
+ this.status = SItemStatus.Edit;
|
|
|
this.grabItem(this);
|
|
|
- } else if (SItemStatus.Edit == this._status) {
|
|
|
- this._status = SItemStatus.Normal;
|
|
|
+ } else if (SItemStatus.Edit == this.status) {
|
|
|
+ this.status = SItemStatus.Normal;
|
|
|
this.releaseItem();
|
|
|
if (this.undoStack) {
|
|
|
this.undoStack.clear()
|
|
@@ -439,13 +443,13 @@ export class SPolygonItem extends SGraphItem {
|
|
|
*/
|
|
|
|
|
|
onKeyDown(event: KeyboardEvent): boolean {
|
|
|
- if (this._status == SItemStatus.Normal) {
|
|
|
+ if (this.status == SItemStatus.Normal) {
|
|
|
return false;
|
|
|
- } else if (this._status == SItemStatus.Create) {
|
|
|
+ } else if (this.status == SItemStatus.Create) {
|
|
|
if (event.code == 'Enter') {
|
|
|
// 当顶点大于二个时才又条件执行闭合操作并清空堆栈
|
|
|
if (this.pointList.length > 2) {
|
|
|
- this._status = SItemStatus.Normal;
|
|
|
+ this.status = SItemStatus.Normal;
|
|
|
//3 传递完成事件状态
|
|
|
this.$emit('finishCreated')
|
|
|
//1 grabItem 置为null
|
|
@@ -456,7 +460,7 @@ export class SPolygonItem extends SGraphItem {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- } else if (this._status == SItemStatus.Edit) {
|
|
|
+ } else if (this.status == SItemStatus.Edit) {
|
|
|
if (event.key == 'Alt') {
|
|
|
this.isAlt = true;
|
|
|
}
|
|
@@ -473,7 +477,7 @@ export class SPolygonItem extends SGraphItem {
|
|
|
* @return boolean
|
|
|
*/
|
|
|
onKeyUp(event: KeyboardEvent): void {
|
|
|
- if (this._status == SItemStatus.Edit) {
|
|
|
+ if (this.status == SItemStatus.Edit) {
|
|
|
if (event.key == 'Alt') {
|
|
|
this.isAlt = false;
|
|
|
}
|
|
@@ -489,13 +493,13 @@ export class SPolygonItem extends SGraphItem {
|
|
|
*/
|
|
|
onMouseDown(event: SMouseEvent): boolean {
|
|
|
// 如果状态为编辑状态则添加点
|
|
|
- if (this._status == SItemStatus.Create) {
|
|
|
+ if (this.status == SItemStatus.Create) {
|
|
|
// 新增顶点
|
|
|
this.insertPoint(event.x, event.y);
|
|
|
// 记录新增顶点操作记录压入堆栈
|
|
|
let pos = new SPoint(event.x, event.y);
|
|
|
this.recordAction(SGraphPointListInsert, [this.pointList, pos]);
|
|
|
- } else if (this._status == SItemStatus.Edit) {
|
|
|
+ } else if (this.status == SItemStatus.Edit) {
|
|
|
// 对多边形数组做编辑操作
|
|
|
this.editPolygonPoint(event);
|
|
|
} else {
|
|
@@ -535,12 +539,12 @@ export class SPolygonItem extends SGraphItem {
|
|
|
*/
|
|
|
|
|
|
onMouseMove(event: SMouseEvent): boolean {
|
|
|
- if (this._status == SItemStatus.Create) {
|
|
|
+ if (this.status == SItemStatus.Create) {
|
|
|
this.lastPoint = new SPoint
|
|
|
this.lastPoint.x = event.x;
|
|
|
this.lastPoint.y = event.y;
|
|
|
this.update();
|
|
|
- } else if (this._status == SItemStatus.Edit) {
|
|
|
+ } else if (this.status == SItemStatus.Edit) {
|
|
|
if (-1 != this.curIndex) {
|
|
|
this.pointList[this.curIndex].x = event.x;
|
|
|
this.pointList[this.curIndex].y = event.y;
|
|
@@ -561,7 +565,7 @@ export class SPolygonItem extends SGraphItem {
|
|
|
* @return boolean
|
|
|
*/
|
|
|
onMouseUp(event: SMouseEvent): boolean {
|
|
|
- if (this._status == SItemStatus.Edit) {
|
|
|
+ if (this.status == SItemStatus.Edit) {
|
|
|
if (-1 != this.curIndex) {
|
|
|
const pos = new SPoint(this.pointList[this.curIndex].x, this.pointList[this.curIndex].y)
|
|
|
this.recordAction(SGraphPointListUpdate, [this.pointList, this.curPoint, pos, this.curIndex])
|
|
@@ -592,12 +596,12 @@ export class SPolygonItem extends SGraphItem {
|
|
|
*/
|
|
|
cancelOperate(): void {
|
|
|
// 当状态为展示状态
|
|
|
- if (this._status == SItemStatus.Create) {
|
|
|
+ if (this.status == SItemStatus.Create) {
|
|
|
// 闭合多边形
|
|
|
this.parent = null
|
|
|
- } else if (this._status == SItemStatus.Edit) {
|
|
|
+ } else if (this.status == SItemStatus.Edit) {
|
|
|
// 编辑状态
|
|
|
- this._status = SItemStatus.Normal
|
|
|
+ this.status = SItemStatus.Normal
|
|
|
}
|
|
|
this.update()
|
|
|
} // Function cancelOperate()
|
|
@@ -660,10 +664,10 @@ export class SPolygonItem extends SGraphItem {
|
|
|
onDraw(painter: SPainter): void {
|
|
|
this.scenceLen = painter.toPx(this.len)
|
|
|
// 当状态为展示状态
|
|
|
- if (this._status == SItemStatus.Normal) {
|
|
|
+ if (this.status == SItemStatus.Normal) {
|
|
|
// 闭合多边形
|
|
|
this.drawShowPolygon(painter, this.pointList);
|
|
|
- } else if (this._status == SItemStatus.Create) {
|
|
|
+ } else if (this.status == SItemStatus.Create) {
|
|
|
// 创建状态
|
|
|
this.drawCreatePolygon(painter, this.pointList)
|
|
|
} else {
|