|
@@ -25,10 +25,11 @@ import {
|
|
SPainter,
|
|
SPainter,
|
|
SPoint,
|
|
SPoint,
|
|
SRect,
|
|
SRect,
|
|
- SLine
|
|
|
|
|
|
+ SLine,
|
|
|
|
+ SPolygonUtil
|
|
} from "@saga-web/draw";
|
|
} from "@saga-web/draw";
|
|
-import { SRelationState } from "@saga-web/big/lib/enums/SRelationState"
|
|
|
|
import { SMathUtil } from "@saga-web/big/lib/utils/SMathUtil";
|
|
import { SMathUtil } from "@saga-web/big/lib/utils/SMathUtil";
|
|
|
|
+import { SItemStatus } from "@saga-web/big";
|
|
|
|
|
|
/**
|
|
/**
|
|
* 编辑多边形
|
|
* 编辑多边形
|
|
@@ -53,15 +54,12 @@ export class SPolygonItem extends SGraphItem {
|
|
// 编辑当前状态
|
|
// 编辑当前状态
|
|
set setPointList(arr: SPoint[]) {
|
|
set setPointList(arr: SPoint[]) {
|
|
this.pointList = arr;
|
|
this.pointList = arr;
|
|
- if (arr) {
|
|
|
|
- this._xyzListToSPointList(arr);
|
|
|
|
- };
|
|
|
|
this.update();
|
|
this.update();
|
|
};
|
|
};
|
|
/** 是否闭合 */
|
|
/** 是否闭合 */
|
|
closeFlag: boolean = false;
|
|
closeFlag: boolean = false;
|
|
// 当前状态
|
|
// 当前状态
|
|
- _status: number = SRelationState.Normal;
|
|
|
|
|
|
+ _status: number = SItemStatus.Normal;
|
|
// 获取当前状态
|
|
// 获取当前状态
|
|
get getStatus(): number {
|
|
get getStatus(): number {
|
|
return this._status;
|
|
return this._status;
|
|
@@ -70,14 +68,14 @@ export class SPolygonItem extends SGraphItem {
|
|
set setStatus(value: number) {
|
|
set setStatus(value: number) {
|
|
this._status = value;
|
|
this._status = value;
|
|
// 如果状态为show则需清栈
|
|
// 如果状态为show则需清栈
|
|
- if (value == SRelationState.Normal) {
|
|
|
|
|
|
+ if (value == SItemStatus.Normal) {
|
|
if (this.undoStack) {
|
|
if (this.undoStack) {
|
|
this.undoStack.clear();
|
|
this.undoStack.clear();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.update();
|
|
this.update();
|
|
};
|
|
};
|
|
- data: PolygonData | null = null;
|
|
|
|
|
|
+ data: any | null = null;
|
|
/** 边框颜色 */
|
|
/** 边框颜色 */
|
|
borderColor: SColor = new SColor("#0091FF");
|
|
borderColor: SColor = new SColor("#0091FF");
|
|
/** 填充颜色 */
|
|
/** 填充颜色 */
|
|
@@ -154,7 +152,6 @@ export class SPolygonItem extends SGraphItem {
|
|
point = null
|
|
point = null
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- console.log('删除点位', point, i)
|
|
|
|
this.update()
|
|
this.update()
|
|
return point
|
|
return point
|
|
}
|
|
}
|
|
@@ -189,35 +186,6 @@ export class SPolygonItem extends SGraphItem {
|
|
return this.pointList
|
|
return this.pointList
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * xyz数据转换为SPoint格式函数;获取外接矩阵参数
|
|
|
|
- *
|
|
|
|
- * @param arr 外层传入的数据PointList
|
|
|
|
- */
|
|
|
|
- protected _xyzListToSPointList(arr: SPoint[]): void {
|
|
|
|
- if (arr.length) {
|
|
|
|
- this.pointList = arr.map(it => {
|
|
|
|
- let x = it.x,
|
|
|
|
- y = it.y;
|
|
|
|
- if (x < this.minX) {
|
|
|
|
- this.minX = x;
|
|
|
|
- }
|
|
|
|
- if (y < this.minY) {
|
|
|
|
- this.minY = y;
|
|
|
|
- }
|
|
|
|
- if (x > this.maxX) {
|
|
|
|
- this.maxX = x;
|
|
|
|
- }
|
|
|
|
- if (y > this.maxY) {
|
|
|
|
- this.maxY = y;
|
|
|
|
- }
|
|
|
|
- return new SPoint(x, y);
|
|
|
|
- });
|
|
|
|
- } else {
|
|
|
|
- this.pointList = []
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
////////////
|
|
////////////
|
|
// 以下为三种状态下的绘制多边形方法
|
|
// 以下为三种状态下的绘制多边形方法
|
|
|
|
|
|
@@ -396,7 +364,7 @@ export class SPolygonItem extends SGraphItem {
|
|
* 执行取消操作执行
|
|
* 执行取消操作执行
|
|
*/
|
|
*/
|
|
undo(): void {
|
|
undo(): void {
|
|
- if (this._status == SRelationState.Normal) {
|
|
|
|
|
|
+ if (this._status == SItemStatus.Normal) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
if (this.undoStack) {
|
|
if (this.undoStack) {
|
|
@@ -408,7 +376,7 @@ export class SPolygonItem extends SGraphItem {
|
|
* 执行重做操作执行
|
|
* 执行重做操作执行
|
|
*/
|
|
*/
|
|
redo(): void {
|
|
redo(): void {
|
|
- if (this._status == SRelationState.Normal) {
|
|
|
|
|
|
+ if (this._status == SItemStatus.Normal) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
if (this.undoStack) {
|
|
if (this.undoStack) {
|
|
@@ -427,10 +395,12 @@ export class SPolygonItem extends SGraphItem {
|
|
*/
|
|
*/
|
|
onDoubleClick(event: SMouseEvent): boolean {
|
|
onDoubleClick(event: SMouseEvent): boolean {
|
|
// 如果位show状态 双击改对象则需改为编辑状态
|
|
// 如果位show状态 双击改对象则需改为编辑状态
|
|
- if (SRelationState.Normal == this._status) {
|
|
|
|
- this._status = SRelationState.Edit;
|
|
|
|
- } else if (SRelationState.Edit == this._status) {
|
|
|
|
- this._status = SRelationState.Normal;
|
|
|
|
|
|
+ if (SItemStatus.Normal == this._status) {
|
|
|
|
+ this._status = SItemStatus.Edit;
|
|
|
|
+ this.grabItem(this);
|
|
|
|
+ } else if (SItemStatus.Edit == this._status) {
|
|
|
|
+ this._status = SItemStatus.Normal;
|
|
|
|
+ this.releaseItem();
|
|
if (this.undoStack) {
|
|
if (this.undoStack) {
|
|
this.undoStack.clear()
|
|
this.undoStack.clear()
|
|
}
|
|
}
|
|
@@ -448,13 +418,15 @@ export class SPolygonItem extends SGraphItem {
|
|
*/
|
|
*/
|
|
|
|
|
|
onKeyDown(event: KeyboardEvent): boolean {
|
|
onKeyDown(event: KeyboardEvent): boolean {
|
|
- if (this._status == SRelationState.Normal) {
|
|
|
|
|
|
+ if (this._status == SItemStatus.Normal) {
|
|
return false;
|
|
return false;
|
|
- } else if (this._status == SRelationState.Create) {
|
|
|
|
|
|
+ } else if (this._status == SItemStatus.Create) {
|
|
if (event.code == 'Enter') {
|
|
if (event.code == 'Enter') {
|
|
// 当顶点大于二个时才又条件执行闭合操作并清空堆栈
|
|
// 当顶点大于二个时才又条件执行闭合操作并清空堆栈
|
|
if (this.pointList.length > 2) {
|
|
if (this.pointList.length > 2) {
|
|
- this._status = SRelationState.Normal;
|
|
|
|
|
|
+ this._status = SItemStatus.Normal;
|
|
|
|
+ //3 传递完成事件状态
|
|
|
|
+ this.$emit('finishCreated')
|
|
//1 grabItem 置为null
|
|
//1 grabItem 置为null
|
|
if (this.scene) {
|
|
if (this.scene) {
|
|
this.scene.grabItem = null;
|
|
this.scene.grabItem = null;
|
|
@@ -463,11 +435,9 @@ export class SPolygonItem extends SGraphItem {
|
|
if (this.undoStack) {
|
|
if (this.undoStack) {
|
|
this.undoStack.clear();
|
|
this.undoStack.clear();
|
|
}
|
|
}
|
|
- //3 传递完成事件状态
|
|
|
|
- this.$emit('finishItemCreated')
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } else if (this._status == SRelationState.Edit) {
|
|
|
|
|
|
+ } else if (this._status == SItemStatus.Edit) {
|
|
if (event.key == 'Alt') {
|
|
if (event.key == 'Alt') {
|
|
this.isAlt = true;
|
|
this.isAlt = true;
|
|
}
|
|
}
|
|
@@ -483,14 +453,13 @@ export class SPolygonItem extends SGraphItem {
|
|
* @param event 事件参数
|
|
* @param event 事件参数
|
|
* @return boolean
|
|
* @return boolean
|
|
*/
|
|
*/
|
|
- onKeyUp(event: KeyboardEvent): boolean {
|
|
|
|
- if (this._status == SRelationState.Edit) {
|
|
|
|
|
|
+ onKeyUp(event: KeyboardEvent): void {
|
|
|
|
+ if (this._status == SItemStatus.Edit) {
|
|
if (event.key == 'Alt') {
|
|
if (event.key == 'Alt') {
|
|
this.isAlt = false;
|
|
this.isAlt = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.update()
|
|
this.update()
|
|
- return true;
|
|
|
|
} // Function onKeyUp()
|
|
} // Function onKeyUp()
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -501,17 +470,20 @@ export class SPolygonItem extends SGraphItem {
|
|
*/
|
|
*/
|
|
onMouseDown(event: SMouseEvent): boolean {
|
|
onMouseDown(event: SMouseEvent): boolean {
|
|
// 如果状态为编辑状态则添加点
|
|
// 如果状态为编辑状态则添加点
|
|
- if (this._status == SRelationState.Create) {
|
|
|
|
|
|
+ if (this._status == SItemStatus.Create) {
|
|
// 新增顶点
|
|
// 新增顶点
|
|
this.insertPoint(event.x, event.y);
|
|
this.insertPoint(event.x, event.y);
|
|
// 记录新增顶点操作记录压入堆栈
|
|
// 记录新增顶点操作记录压入堆栈
|
|
let pos = new SPoint(event.x, event.y);
|
|
let pos = new SPoint(event.x, event.y);
|
|
- this.recordAction(SGraphPointListInsert, [this.pointList, pos])
|
|
|
|
- } else if (this._status == SRelationState.Edit) {
|
|
|
|
|
|
+ this.recordAction(SGraphPointListInsert, [this.pointList, pos]);
|
|
|
|
+ return true;
|
|
|
|
+ } else if (this._status == SItemStatus.Edit) {
|
|
// 对多边形数组做编辑操作
|
|
// 对多边形数组做编辑操作
|
|
this.editPolygonPoint(event);
|
|
this.editPolygonPoint(event);
|
|
|
|
+ return true;
|
|
|
|
+ } else {
|
|
|
|
+ return super.onMouseDown(event)
|
|
}
|
|
}
|
|
- return true;
|
|
|
|
} // Function onMouseDown()
|
|
} // Function onMouseDown()
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -544,12 +516,12 @@ export class SPolygonItem extends SGraphItem {
|
|
*/
|
|
*/
|
|
|
|
|
|
onMouseMove(event: SMouseEvent): boolean {
|
|
onMouseMove(event: SMouseEvent): boolean {
|
|
- if (this._status == SRelationState.Create) {
|
|
|
|
|
|
+ if (this._status == SItemStatus.Create) {
|
|
this.lastPoint = new SPoint
|
|
this.lastPoint = new SPoint
|
|
this.lastPoint.x = event.x;
|
|
this.lastPoint.x = event.x;
|
|
this.lastPoint.y = event.y;
|
|
this.lastPoint.y = event.y;
|
|
this.update()
|
|
this.update()
|
|
- } else if (this._status == SRelationState.Edit) {
|
|
|
|
|
|
+ } else if (this._status == SItemStatus.Edit) {
|
|
if (-1 != this.curIndex) {
|
|
if (-1 != this.curIndex) {
|
|
this.pointList[this.curIndex].x = event.x;
|
|
this.pointList[this.curIndex].x = event.x;
|
|
this.pointList[this.curIndex].y = event.y;
|
|
this.pointList[this.curIndex].y = event.y;
|
|
@@ -569,7 +541,7 @@ export class SPolygonItem extends SGraphItem {
|
|
*/
|
|
*/
|
|
|
|
|
|
onMouseUp(event: SMouseEvent): boolean {
|
|
onMouseUp(event: SMouseEvent): boolean {
|
|
- if (this._status == SRelationState.Edit) {
|
|
|
|
|
|
+ if (this._status == SItemStatus.Edit) {
|
|
if (-1 != this.curIndex) {
|
|
if (-1 != this.curIndex) {
|
|
const pos = new SPoint(this.pointList[this.curIndex].x, this.pointList[this.curIndex].y)
|
|
const pos = new SPoint(this.pointList[this.curIndex].x, this.pointList[this.curIndex].y)
|
|
this.recordAction(SGraphPointListUpdate, [this.pointList, this.curPoint, pos, this.curIndex])
|
|
this.recordAction(SGraphPointListUpdate, [this.pointList, this.curPoint, pos, this.curIndex])
|
|
@@ -598,12 +570,12 @@ export class SPolygonItem extends SGraphItem {
|
|
*/
|
|
*/
|
|
cancelOperate(): void {
|
|
cancelOperate(): void {
|
|
// 当状态为展示状态
|
|
// 当状态为展示状态
|
|
- if (this._status == SRelationState.Create) {
|
|
|
|
|
|
+ if (this._status == SItemStatus.Create) {
|
|
// 闭合多边形
|
|
// 闭合多边形
|
|
this.parent = null
|
|
this.parent = null
|
|
- } else if (this._status == SRelationState.Edit) {
|
|
|
|
|
|
+ } else if (this._status == SItemStatus.Edit) {
|
|
// 编辑状态
|
|
// 编辑状态
|
|
- this._status = SRelationState.Normal
|
|
|
|
|
|
+ this._status = SItemStatus.Normal
|
|
}
|
|
}
|
|
this.update()
|
|
this.update()
|
|
} // Function cancelOperate()
|
|
} // Function cancelOperate()
|
|
@@ -614,6 +586,28 @@ export class SPolygonItem extends SGraphItem {
|
|
* @return SRect
|
|
* @return SRect
|
|
*/
|
|
*/
|
|
boundingRect(): SRect {
|
|
boundingRect(): SRect {
|
|
|
|
+ if (this.pointList.length) {
|
|
|
|
+ this.minX = this.pointList[0].x;
|
|
|
|
+ this.maxX = this.pointList[0].x;
|
|
|
|
+ this.minY = this.pointList[0].y;
|
|
|
|
+ this.maxY = this.pointList[0].y;
|
|
|
|
+ this.pointList.forEach(it => {
|
|
|
|
+ let x = it.x,
|
|
|
|
+ y = it.y;
|
|
|
|
+ if (x < this.minX) {
|
|
|
|
+ this.minX = x;
|
|
|
|
+ }
|
|
|
|
+ if (y < this.minY) {
|
|
|
|
+ this.minY = y;
|
|
|
|
+ }
|
|
|
|
+ if (x > this.maxX) {
|
|
|
|
+ this.maxX = x;
|
|
|
|
+ }
|
|
|
|
+ if (y > this.maxY) {
|
|
|
|
+ this.maxY = y;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ };
|
|
return new SRect(
|
|
return new SRect(
|
|
this.minX,
|
|
this.minX,
|
|
this.minY,
|
|
this.minY,
|
|
@@ -623,6 +617,20 @@ export class SPolygonItem extends SGraphItem {
|
|
} // Function boundingRect()
|
|
} // Function boundingRect()
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 判断点是否在区域内
|
|
|
|
+ *
|
|
|
|
+ * @param x
|
|
|
|
+ * @param y
|
|
|
|
+ */
|
|
|
|
+ contains(x: number, y: number): boolean {
|
|
|
|
+ let arr = this.pointList;
|
|
|
|
+ if (arr.length < 3 || !SPolygonUtil.pointIn(x, y, arr)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ } // Function contains()
|
|
|
|
+
|
|
|
|
+ /**
|
|
* Item绘制操作
|
|
* Item绘制操作
|
|
*
|
|
*
|
|
* @param painter painter对象
|
|
* @param painter painter对象
|
|
@@ -630,10 +638,10 @@ export class SPolygonItem extends SGraphItem {
|
|
onDraw(painter: SPainter): void {
|
|
onDraw(painter: SPainter): void {
|
|
this.scenceLen = painter.toPx(this.len)
|
|
this.scenceLen = painter.toPx(this.len)
|
|
// 当状态为展示状态
|
|
// 当状态为展示状态
|
|
- if (this._status == SRelationState.Normal) {
|
|
|
|
|
|
+ if (this._status == SItemStatus.Normal) {
|
|
// 闭合多边形
|
|
// 闭合多边形
|
|
this.drawShowPolygon(painter, this.pointList);
|
|
this.drawShowPolygon(painter, this.pointList);
|
|
- } else if (this._status == SRelationState.Create) {
|
|
|
|
|
|
+ } else if (this._status == SItemStatus.Create) {
|
|
// 创建状态
|
|
// 创建状态
|
|
this.drawCreatePolygon(painter, this.pointList)
|
|
this.drawCreatePolygon(painter, this.pointList)
|
|
} else {
|
|
} else {
|