|
@@ -1,7 +1,6 @@
|
|
|
-
|
|
|
import { SColor, SLine, SPainter, SPoint } from "@saga-web/draw/lib";
|
|
|
import { SMouseEvent } from "@saga-web/base";
|
|
|
-import { SRelationState } from "..";
|
|
|
+import { SItemStatus } from "..";
|
|
|
import { SMathUtil } from "../utils/SMathUtil";
|
|
|
import { SGraphItem } from "@saga-web/graph/lib";
|
|
|
|
|
@@ -14,11 +13,11 @@ export class SPolylineItem extends SGraphItem {
|
|
|
/** 折点信息 */
|
|
|
pointList: SPoint[] = [];
|
|
|
/** 是否绘制完成 */
|
|
|
- _status: SRelationState = SRelationState.Create;
|
|
|
- get status(): SRelationState {
|
|
|
+ _status: SItemStatus = SItemStatus.Create;
|
|
|
+ get status(): SItemStatus {
|
|
|
return this._status;
|
|
|
}
|
|
|
- set status(v: SRelationState) {
|
|
|
+ set status(v: SItemStatus) {
|
|
|
this._status = v;
|
|
|
this.update();
|
|
|
}
|
|
@@ -133,19 +132,24 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* @return boolean 是否处理事件
|
|
|
* */
|
|
|
onMouseDown(event: SMouseEvent): boolean {
|
|
|
+ this.curIndex = -1;
|
|
|
if (event.buttons == 1) {
|
|
|
- if (this.status == SRelationState.Create) {
|
|
|
+ if (this.status == SItemStatus.Create) {
|
|
|
this.addPoint(new SPoint(event.x, event.y));
|
|
|
return true;
|
|
|
- } else if (this.status == SRelationState.Edit) {
|
|
|
+ } else if (this.status == SItemStatus.Edit) {
|
|
|
+ // 查询鼠标最近的索引
|
|
|
this.findNearestPoint(new SPoint(event.x, event.y));
|
|
|
+ // 增加点
|
|
|
+ // 删除点
|
|
|
if (event.altKey && this.canHandle(this.curIndex)) {
|
|
|
this.pointList.splice(this.curIndex, 1);
|
|
|
this.curIndex = -1;
|
|
|
- this.update();
|
|
|
}
|
|
|
+ this.update();
|
|
|
return true;
|
|
|
} else {
|
|
|
+ return super.onMouseDown(event);
|
|
|
}
|
|
|
}
|
|
|
return super.onMouseDown(event);
|
|
@@ -158,7 +162,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* @return boolean 是否处理事件
|
|
|
* */
|
|
|
onMouseMove(event: SMouseEvent): boolean {
|
|
|
- if (this.status == SRelationState.Create) {
|
|
|
+ if (this.status == SItemStatus.Create) {
|
|
|
if (this.lastPoint) {
|
|
|
this.lastPoint.x = event.x;
|
|
|
this.lastPoint.y = event.y;
|
|
@@ -167,7 +171,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
}
|
|
|
this.update();
|
|
|
return true;
|
|
|
- } else if (this.status == SRelationState.Edit) {
|
|
|
+ } else if (this.status == SItemStatus.Edit) {
|
|
|
if (this.canHandle(this.curIndex)) {
|
|
|
this.pointList[this.curIndex].x = event.x;
|
|
|
this.pointList[this.curIndex].y = event.y;
|
|
@@ -197,30 +201,12 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* @return boolean
|
|
|
*/
|
|
|
onDoubleClick(event: SMouseEvent): boolean {
|
|
|
- if (this.status == SRelationState.Create) {
|
|
|
- this.status = SRelationState.Normal;
|
|
|
- } else if (this.status == SRelationState.Edit) {
|
|
|
- let len = SMathUtil.pointToLine(
|
|
|
- new SPoint(event.x, event.y),
|
|
|
- new SLine(this.pointList[0], this.pointList[1])
|
|
|
- ),
|
|
|
- index = 0;
|
|
|
- if (this.pointList.length > 2) {
|
|
|
- for (let i = 1; i < this.pointList.length - 1; i++) {
|
|
|
- let dis = SMathUtil.pointToLine(
|
|
|
- new SPoint(event.x, event.y),
|
|
|
- new SLine(this.pointList[i], this.pointList[i + 1])
|
|
|
- );
|
|
|
- if (dis.MinDis < len.MinDis) {
|
|
|
- len = dis;
|
|
|
- index = i;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (len.Point) {
|
|
|
- this.pointList.splice(index + 1, 0, len.Point);
|
|
|
- this.update();
|
|
|
- }
|
|
|
+ if (this.status == SItemStatus.Normal) {
|
|
|
+ this.status = SItemStatus.Edit;
|
|
|
+ } else if (this.status == SItemStatus.Edit) {
|
|
|
+ this.status = SItemStatus.Normal;
|
|
|
+ } else if (this.status == SItemStatus.Create) {
|
|
|
+ this.status = SItemStatus.Edit;
|
|
|
}
|
|
|
this.$emit("onDoubleClick", event);
|
|
|
return true;
|
|
@@ -233,7 +219,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*/
|
|
|
onKeyUp(event: KeyboardEvent): void {
|
|
|
if (event.keyCode == 13) {
|
|
|
- this.status = SRelationState.Normal;
|
|
|
+ this.status = SItemStatus.Edit;
|
|
|
}
|
|
|
} // Function onKeyUp()
|
|
|
|
|
@@ -259,6 +245,35 @@ export class SPolylineItem extends SGraphItem {
|
|
|
} // Function findNearestPoint()
|
|
|
|
|
|
/**
|
|
|
+ * 计算增加点的位置
|
|
|
+ *
|
|
|
+ * @param p 鼠标点击点
|
|
|
+ * */
|
|
|
+ findAddPos(p: SPoint): void {
|
|
|
+ let len = {
|
|
|
+ MinDis: this.sceneDis
|
|
|
+ },
|
|
|
+ index = 0;
|
|
|
+ if (this.pointList.length > 2) {
|
|
|
+ for (let i = 0; i < this.pointList.length - 1; i++) {
|
|
|
+ let dis = SMathUtil.pointToLine(
|
|
|
+ new SPoint(p.x, p.y),
|
|
|
+ new SLine(this.pointList[i], this.pointList[i + 1])
|
|
|
+ );
|
|
|
+ if (dis.MinDis < len.MinDis) {
|
|
|
+ len = dis;
|
|
|
+ index = i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // @ts-ignore
|
|
|
+ if (len.Point) {
|
|
|
+ // @ts-ignore
|
|
|
+ this.addPoint(new SPoint(len.Point.X, len.Point.Y), index);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } // Function findAddPos()
|
|
|
+
|
|
|
+ /**
|
|
|
* 判断点是否在区域内
|
|
|
*
|
|
|
* @param x
|
|
@@ -297,12 +312,12 @@ export class SPolylineItem extends SGraphItem {
|
|
|
painter.pen.color = new SColor(this.strokeColor);
|
|
|
painter.drawPolyline(this.pointList);
|
|
|
// 创建状态
|
|
|
- if (this.status == SRelationState.Create && this.lastPoint) {
|
|
|
+ if (this.status == SItemStatus.Create && this.lastPoint) {
|
|
|
painter.drawLine(
|
|
|
this.pointList[this.pointList.length - 1],
|
|
|
this.lastPoint
|
|
|
);
|
|
|
- } else if (this.status == SRelationState.Edit) {
|
|
|
+ } else if (this.status == SItemStatus.Edit) {
|
|
|
// 编辑状态
|
|
|
this.pointList.forEach((t, i): void => {
|
|
|
painter.brush.color = SColor.White;
|