|
@@ -1,8 +1,12 @@
|
|
import { SColor, SLine, SPainter, SPoint } from "@saga-web/draw/lib";
|
|
import { SColor, SLine, SPainter, SPoint } from "@saga-web/draw/lib";
|
|
-import { SMouseEvent } from "@saga-web/base";
|
|
|
|
|
|
+import { SMouseEvent, SUndoStack } from "@saga-web/base";
|
|
import { SItemStatus } from "..";
|
|
import { SItemStatus } from "..";
|
|
import { SMathUtil } from "../utils/SMathUtil";
|
|
import { SMathUtil } from "../utils/SMathUtil";
|
|
-import { SGraphItem } from "@saga-web/graph/lib";
|
|
|
|
|
|
+import {
|
|
|
|
+ SGraphItem,
|
|
|
|
+ SGraphPointListDelete,
|
|
|
|
+ SGraphPointListInsert, SGraphPointListUpdate
|
|
|
|
+} from "@saga-web/graph/lib";
|
|
|
|
|
|
/**
|
|
/**
|
|
* 直线item
|
|
* 直线item
|
|
@@ -22,7 +26,7 @@ export class SPolylineItem extends SGraphItem {
|
|
this.update();
|
|
this.update();
|
|
}
|
|
}
|
|
/** 鼠标移动时的点 */
|
|
/** 鼠标移动时的点 */
|
|
- lastPoint: SPoint | null = null;
|
|
|
|
|
|
+ private lastPoint: SPoint | null = null;
|
|
/** 线条颜色 */
|
|
/** 线条颜色 */
|
|
_strokeColor: string = "#000000";
|
|
_strokeColor: string = "#000000";
|
|
get strokeColor(): string {
|
|
get strokeColor(): string {
|
|
@@ -53,9 +57,13 @@ export class SPolylineItem extends SGraphItem {
|
|
/** 全局灵敏度 */
|
|
/** 全局灵敏度 */
|
|
dis: number = 10;
|
|
dis: number = 10;
|
|
/** 灵敏度转换为场景长度 */
|
|
/** 灵敏度转换为场景长度 */
|
|
- sceneDis: number = 10;
|
|
|
|
|
|
+ private sceneDis: number = 10;
|
|
/** 当前点索引 */
|
|
/** 当前点索引 */
|
|
- curIndex: number = -1;
|
|
|
|
|
|
+ private curIndex: number = -1;
|
|
|
|
+ /** 当前点索引 */
|
|
|
|
+ private curPoint: SPoint | null = null;
|
|
|
|
+ /** undo/redo堆栈 */
|
|
|
|
+ private undoStack: SUndoStack | null = new SUndoStack();
|
|
|
|
|
|
/**
|
|
/**
|
|
* 构造函数
|
|
* 构造函数
|
|
@@ -97,8 +105,14 @@ export class SPolylineItem extends SGraphItem {
|
|
private addPoint(p: SPoint, index?: number): void {
|
|
private addPoint(p: SPoint, index?: number): void {
|
|
if (index && this.canHandle(index)) {
|
|
if (index && this.canHandle(index)) {
|
|
this.pointList.splice(index, 0, p);
|
|
this.pointList.splice(index, 0, p);
|
|
|
|
+ this.recordAction(SGraphPointListInsert, [
|
|
|
|
+ this.pointList,
|
|
|
|
+ p,
|
|
|
|
+ index
|
|
|
|
+ ]);
|
|
} else {
|
|
} else {
|
|
this.pointList.push(p);
|
|
this.pointList.push(p);
|
|
|
|
+ this.recordAction(SGraphPointListInsert, [this.pointList, p]);
|
|
}
|
|
}
|
|
this.update();
|
|
this.update();
|
|
} // Function addPoint()
|
|
} // Function addPoint()
|
|
@@ -120,7 +134,16 @@ export class SPolylineItem extends SGraphItem {
|
|
* */
|
|
* */
|
|
private delPoint(index: number): void {
|
|
private delPoint(index: number): void {
|
|
if (this.canHandle(index) && this.pointList.length > 2) {
|
|
if (this.canHandle(index) && this.pointList.length > 2) {
|
|
|
|
+ const p = new SPoint(
|
|
|
|
+ this.pointList[this.curIndex].x,
|
|
|
|
+ this.pointList[this.curIndex].y
|
|
|
|
+ );
|
|
this.pointList.splice(index, 0);
|
|
this.pointList.splice(index, 0);
|
|
|
|
+ this.recordAction(SGraphPointListDelete, [
|
|
|
|
+ this.pointList,
|
|
|
|
+ p,
|
|
|
|
+ index
|
|
|
|
+ ]);
|
|
this.update();
|
|
this.update();
|
|
}
|
|
}
|
|
} // Function delPoint
|
|
} // Function delPoint
|
|
@@ -133,6 +156,7 @@ export class SPolylineItem extends SGraphItem {
|
|
* */
|
|
* */
|
|
onMouseDown(event: SMouseEvent): boolean {
|
|
onMouseDown(event: SMouseEvent): boolean {
|
|
this.curIndex = -1;
|
|
this.curIndex = -1;
|
|
|
|
+ this.curPoint = null;
|
|
if (event.buttons == 1) {
|
|
if (event.buttons == 1) {
|
|
if (this.status == SItemStatus.Create) {
|
|
if (this.status == SItemStatus.Create) {
|
|
this.addPoint(new SPoint(event.x, event.y));
|
|
this.addPoint(new SPoint(event.x, event.y));
|
|
@@ -148,6 +172,7 @@ export class SPolylineItem extends SGraphItem {
|
|
if (event.altKey && this.canHandle(this.curIndex)) {
|
|
if (event.altKey && this.canHandle(this.curIndex)) {
|
|
this.pointList.splice(this.curIndex, 1);
|
|
this.pointList.splice(this.curIndex, 1);
|
|
this.curIndex = -1;
|
|
this.curIndex = -1;
|
|
|
|
+ this.curPoint = null;
|
|
}
|
|
}
|
|
this.update();
|
|
this.update();
|
|
return true;
|
|
return true;
|
|
@@ -193,7 +218,22 @@ export class SPolylineItem extends SGraphItem {
|
|
* @return boolean 是否处理事件
|
|
* @return boolean 是否处理事件
|
|
* */
|
|
* */
|
|
onMouseUp(event: SMouseEvent): boolean {
|
|
onMouseUp(event: SMouseEvent): boolean {
|
|
|
|
+ if (this.status == SItemStatus.Edit) {
|
|
|
|
+ if (this.curIndex > -1) {
|
|
|
|
+ const p = new SPoint(
|
|
|
|
+ this.pointList[this.curIndex].x,
|
|
|
|
+ this.pointList[this.curIndex].y
|
|
|
|
+ );
|
|
|
|
+ this.recordAction(SGraphPointListUpdate, [
|
|
|
|
+ this.pointList,
|
|
|
|
+ this.curPoint,
|
|
|
|
+ p,
|
|
|
|
+ this.curIndex
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
this.curIndex = -1;
|
|
this.curIndex = -1;
|
|
|
|
+ this.curPoint = null;
|
|
return true;
|
|
return true;
|
|
} // Function onMouseMove()
|
|
} // Function onMouseMove()
|
|
|
|
|
|
@@ -228,7 +268,7 @@ export class SPolylineItem extends SGraphItem {
|
|
*/
|
|
*/
|
|
onKeyUp(event: KeyboardEvent): void {
|
|
onKeyUp(event: KeyboardEvent): void {
|
|
if (event.keyCode == 13) {
|
|
if (event.keyCode == 13) {
|
|
- this.status = SItemStatus.Edit;
|
|
|
|
|
|
+ this.status = SItemStatus.Normal;
|
|
}
|
|
}
|
|
} // Function onKeyUp()
|
|
} // Function onKeyUp()
|
|
|
|
|
|
@@ -249,6 +289,10 @@ export class SPolylineItem extends SGraphItem {
|
|
if (dis < len) {
|
|
if (dis < len) {
|
|
len = dis;
|
|
len = dis;
|
|
this.curIndex = i;
|
|
this.curIndex = i;
|
|
|
|
+ this.curPoint = new SPoint(
|
|
|
|
+ this.pointList[this.curIndex].x,
|
|
|
|
+ this.pointList[this.curIndex].y
|
|
|
|
+ );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} // Function findNearestPoint()
|
|
} // Function findNearestPoint()
|
|
@@ -284,6 +328,20 @@ export class SPolylineItem extends SGraphItem {
|
|
} // Function findAddPos()
|
|
} // Function findAddPos()
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 记录相关动作并推入栈中
|
|
|
|
+ *
|
|
|
|
+ * @param SGraphCommand 相关命令类
|
|
|
|
+ * @param any 对应传入参数
|
|
|
|
+ */
|
|
|
|
+ protected recordAction(SGraphCommand: any, any: any[]): void {
|
|
|
|
+ // 记录相关命令并推入堆栈中
|
|
|
|
+ const command = new SGraphCommand(this, ...any);
|
|
|
|
+ if (this.undoStack) {
|
|
|
|
+ this.undoStack.push(command);
|
|
|
|
+ }
|
|
|
|
+ } // Function recordAction()
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 判断点是否在区域内
|
|
* 判断点是否在区域内
|
|
*
|
|
*
|
|
* @param x
|
|
* @param x
|
|
@@ -310,6 +368,30 @@ export class SPolylineItem extends SGraphItem {
|
|
} // Function contains()
|
|
} // Function contains()
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 撤销操作
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ undo(): void {
|
|
|
|
+ if (this._status != SItemStatus.Normal) {
|
|
|
|
+ if (this.undoStack) {
|
|
|
|
+ this.undoStack.undo();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } // Function undo()
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 重做操作
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ redo(): void {
|
|
|
|
+ if (this._status != SItemStatus.Normal) {
|
|
|
|
+ if (this.undoStack) {
|
|
|
|
+ this.undoStack.redo();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } // Function redo()
|
|
|
|
+
|
|
|
|
+ /**
|
|
* Item绘制操作
|
|
* Item绘制操作
|
|
*
|
|
*
|
|
* @param painter painter对象
|
|
* @param painter painter对象
|