|
@@ -1,29 +1,5 @@
|
|
-/*
|
|
|
|
- * ********************************************************************************************************************
|
|
|
|
- *
|
|
|
|
- * :*$@@%$*: ;: ;; ;;
|
|
|
|
- * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
|
|
|
|
- * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
|
|
|
|
- * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
|
|
|
|
- * =@* %! @ $= % %@= =%@! %=
|
|
|
|
- * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
|
|
|
|
- * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
|
|
|
|
- * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
|
|
|
|
- * $@* ;@@@%=!: *@*
|
|
|
|
- * =@$ ;;;!=%@@@@=! =@!
|
|
|
|
- * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司
|
|
|
|
- * ;%@@$=$@@%* *@@@$=%@@%;
|
|
|
|
- * ::;:: ::;:: All rights reserved.
|
|
|
|
- *
|
|
|
|
- * ********************************************************************************************************************
|
|
|
|
- */
|
|
|
|
-import {
|
|
|
|
- SGraphItem,
|
|
|
|
- SGraphPointListInsert,
|
|
|
|
- SGraphPointListDelete,
|
|
|
|
- SGraphPointListUpdate
|
|
|
|
-} from "@saga-web/graph/lib";
|
|
|
|
-import { SMouseEvent, SUndoStack } from "@saga-web/base/";
|
|
|
|
|
|
+import { SGraphItem, SGraphPointListInsert, SGraphPointListDelete, SGraphPointListUpdate } from "@saga-web/graph/lib";
|
|
|
|
+import { SMouseEvent, SUndoStack } from "@saga-web/base/";;
|
|
import {
|
|
import {
|
|
SColor,
|
|
SColor,
|
|
SLineCapStyle,
|
|
SLineCapStyle,
|
|
@@ -60,17 +36,17 @@ export class SPolygonItem extends SGraphItem {
|
|
set setPointList(arr: SPoint[]) {
|
|
set setPointList(arr: SPoint[]) {
|
|
this.pointList = arr;
|
|
this.pointList = arr;
|
|
this.update();
|
|
this.update();
|
|
- }
|
|
|
|
|
|
+ };
|
|
/** 是否闭合 */
|
|
/** 是否闭合 */
|
|
closeFlag: boolean = false;
|
|
closeFlag: boolean = false;
|
|
// 当前状态
|
|
// 当前状态
|
|
- _status: number = SItemStatus.Normal;
|
|
|
|
|
|
+ protected _status: number = SItemStatus.Normal;
|
|
// 获取当前状态
|
|
// 获取当前状态
|
|
- get getStatus(): number {
|
|
|
|
|
|
+ get status(): SItemStatus {
|
|
return this._status;
|
|
return this._status;
|
|
}
|
|
}
|
|
// 编辑当前状态
|
|
// 编辑当前状态
|
|
- set setStatus(value: number) {
|
|
|
|
|
|
+ set status(value: SItemStatus) {
|
|
this._status = value;
|
|
this._status = value;
|
|
// 如果状态为show则需清栈
|
|
// 如果状态为show则需清栈
|
|
if (value == SItemStatus.Normal) {
|
|
if (value == SItemStatus.Normal) {
|
|
@@ -79,33 +55,56 @@ export class SPolygonItem extends SGraphItem {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.update();
|
|
this.update();
|
|
- }
|
|
|
|
|
|
+ };
|
|
|
|
+ data: any | null = null;
|
|
/** 边框颜色 */
|
|
/** 边框颜色 */
|
|
- borderColor: SColor = new SColor("#0091FF");
|
|
|
|
|
|
+ _strokeColor: SColor = new SColor("#0091FF");
|
|
|
|
+ /** 画笔颜色 */
|
|
|
|
+ get strokeColor(): SColor {
|
|
|
|
+ return this._strokeColor
|
|
|
|
+ };
|
|
|
|
+ set strokeColor(v: SColor) {
|
|
|
|
+ this._strokeColor = v
|
|
|
|
+ }
|
|
/** 填充颜色 */
|
|
/** 填充颜色 */
|
|
- brushColor: SColor = new SColor("#1EE887");
|
|
|
|
- /** border宽 只可输入像素宽*/
|
|
|
|
- borderLine: number = 4;
|
|
|
|
|
|
+ _fillColor: SColor = new SColor("#1EE887");
|
|
|
|
+ get fillColor(): SColor {
|
|
|
|
+ return this._fillColor
|
|
|
|
+ };
|
|
|
|
+ set fillColor(v: SColor) {
|
|
|
|
+ this._fillColor = v
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** 边框的宽 只可输入像素宽*/
|
|
|
|
+ _lineWidth: number = 4;
|
|
|
|
+ get lineWidth(): number {
|
|
|
|
+ return this._lineWidth
|
|
|
|
+ }
|
|
|
|
+ set lineWidth(v: number) {
|
|
|
|
+ this._lineWidth = v;
|
|
|
|
+ this.update();
|
|
|
|
+ };
|
|
/** 鼠标移动点 */
|
|
/** 鼠标移动点 */
|
|
private lastPoint: SPoint | null = null;
|
|
private lastPoint: SPoint | null = null;
|
|
/** 当前鼠标获取顶点对应索引 */
|
|
/** 当前鼠标获取顶点对应索引 */
|
|
private curIndex: number = -1;
|
|
private curIndex: number = -1;
|
|
/** 当前鼠标获取顶点对应坐标 */
|
|
/** 当前鼠标获取顶点对应坐标 */
|
|
- private curPoint: null | SPoint = null;
|
|
|
|
|
|
+ private curPoint: null | SPoint = null
|
|
/** 灵敏像素 */
|
|
/** 灵敏像素 */
|
|
private len: number = 10;
|
|
private len: number = 10;
|
|
/** 场景像素 内部将灵敏像素换算为场景实际距离 */
|
|
/** 场景像素 内部将灵敏像素换算为场景实际距离 */
|
|
private scenceLen: number = 15;
|
|
private scenceLen: number = 15;
|
|
/** 场景像素 */
|
|
/** 场景像素 */
|
|
private isAlt: boolean = false;
|
|
private isAlt: boolean = false;
|
|
- /** undo/redo堆栈 */
|
|
|
|
- private undoStack: SUndoStack | null = new SUndoStack();
|
|
|
|
|
|
+ /** undoredo堆栈 */
|
|
|
|
+ protected undoStack: SUndoStack | null = new SUndoStack();
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 构造函数
|
|
|
|
- *
|
|
|
|
- * @param parent 指向父对象
|
|
|
|
- */
|
|
|
|
|
|
+ * 构造函数
|
|
|
|
+ *
|
|
|
|
+ * @param parent 指向父对象
|
|
|
|
+ * @param data PolygonData数据
|
|
|
|
+ */
|
|
constructor(parent: SGraphItem | null) {
|
|
constructor(parent: SGraphItem | null) {
|
|
super(parent);
|
|
super(parent);
|
|
}
|
|
}
|
|
@@ -124,12 +123,12 @@ export class SPolygonItem extends SGraphItem {
|
|
insertPoint(x: number, y: number, i: number | null = null): SPoint {
|
|
insertPoint(x: number, y: number, i: number | null = null): SPoint {
|
|
const point = new SPoint(x, y);
|
|
const point = new SPoint(x, y);
|
|
if (i == null) {
|
|
if (i == null) {
|
|
- this.pointList.push(point);
|
|
|
|
|
|
+ this.pointList.push(point)
|
|
} else {
|
|
} else {
|
|
this.pointList.splice(i, 0, point);
|
|
this.pointList.splice(i, 0, point);
|
|
}
|
|
}
|
|
- this.update();
|
|
|
|
- return point;
|
|
|
|
|
|
+ this.update()
|
|
|
|
+ return point
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -141,8 +140,8 @@ export class SPolygonItem extends SGraphItem {
|
|
deletePoint(i: number | null = null): SPoint | null {
|
|
deletePoint(i: number | null = null): SPoint | null {
|
|
let point = null;
|
|
let point = null;
|
|
if (i != null) {
|
|
if (i != null) {
|
|
- if (i >= this.pointList.length || i < 0) {
|
|
|
|
- point = null;
|
|
|
|
|
|
+ if (i >= (this.pointList.length) || i < 0) {
|
|
|
|
+ point = null
|
|
} else {
|
|
} else {
|
|
point = new SPoint(this.pointList[i].x, this.pointList[i].y);
|
|
point = new SPoint(this.pointList[i].x, this.pointList[i].y);
|
|
this.pointList.splice(i, 1);
|
|
this.pointList.splice(i, 1);
|
|
@@ -152,11 +151,11 @@ export class SPolygonItem extends SGraphItem {
|
|
point = this.pointList[this.pointList.length - 1];
|
|
point = this.pointList[this.pointList.length - 1];
|
|
this.pointList.pop();
|
|
this.pointList.pop();
|
|
} else {
|
|
} else {
|
|
- point = null;
|
|
|
|
|
|
+ point = null
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- this.update();
|
|
|
|
- return point;
|
|
|
|
|
|
+ this.update()
|
|
|
|
+ return point
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -167,17 +166,17 @@ export class SPolygonItem extends SGraphItem {
|
|
* @param i 点位得i坐标
|
|
* @param i 点位得i坐标
|
|
* @return 移动对应得点。如果索引无法找到移动顶点,则返回null
|
|
* @return 移动对应得点。如果索引无法找到移动顶点,则返回null
|
|
*/
|
|
*/
|
|
- movePoint(x: number, y: number, i: number): SPoint | null {
|
|
|
|
|
|
+ movePoint(x: number, y: number, i: number, ): SPoint | null {
|
|
let point = null;
|
|
let point = null;
|
|
- if (i >= this.pointList.length || i < 0) {
|
|
|
|
- return null;
|
|
|
|
|
|
+ if (i >= (this.pointList.length) || i < 0) {
|
|
|
|
+ return null
|
|
}
|
|
}
|
|
if (this.pointList.length) {
|
|
if (this.pointList.length) {
|
|
this.pointList[i].x = x;
|
|
this.pointList[i].x = x;
|
|
this.pointList[i].y = y;
|
|
this.pointList[i].y = y;
|
|
}
|
|
}
|
|
point = this.pointList[i];
|
|
point = this.pointList[i];
|
|
- return point;
|
|
|
|
|
|
+ return point
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -186,7 +185,7 @@ export class SPolygonItem extends SGraphItem {
|
|
* @return 顶点数组
|
|
* @return 顶点数组
|
|
*/
|
|
*/
|
|
PrintPointList(): SPoint[] {
|
|
PrintPointList(): SPoint[] {
|
|
- return this.pointList;
|
|
|
|
|
|
+ return this.pointList
|
|
}
|
|
}
|
|
|
|
|
|
////////////
|
|
////////////
|
|
@@ -199,13 +198,24 @@ export class SPolygonItem extends SGraphItem {
|
|
* @param pointList 绘制多边形数组
|
|
* @param pointList 绘制多边形数组
|
|
*/
|
|
*/
|
|
protected drawShowPolygon(painter: SPainter, pointList: SPoint[]): void {
|
|
protected drawShowPolygon(painter: SPainter, pointList: SPoint[]): void {
|
|
|
|
+ painter.save();
|
|
painter.pen.lineCapStyle = SLineCapStyle.Square;
|
|
painter.pen.lineCapStyle = SLineCapStyle.Square;
|
|
- painter.pen.color = this.borderColor;
|
|
|
|
- painter.pen.lineWidth = painter.toPx(this.borderLine);
|
|
|
|
- painter.brush.color = this.brushColor;
|
|
|
|
|
|
+ painter.pen.color = this._strokeColor;
|
|
|
|
+ painter.pen.lineWidth = painter.toPx(this._lineWidth);
|
|
|
|
+ painter.brush.color = this._fillColor;
|
|
|
|
+ if (this.selected) {
|
|
|
|
+ painter.shadow.shadowBlur = 10;
|
|
|
|
+ painter.shadow.shadowColor = new SColor(`#00000060`);
|
|
|
|
+ painter.shadow.shadowOffsetX = 5;
|
|
|
|
+ painter.shadow.shadowOffsetY = 5;
|
|
|
|
+ } else {
|
|
|
|
+ painter.shadow.shadowColor = SColor.Transparent;
|
|
|
|
+ }
|
|
painter.drawPolygon([...pointList]);
|
|
painter.drawPolygon([...pointList]);
|
|
|
|
+ painter.restore();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 创建状态 --绘制多边形数组
|
|
* 创建状态 --绘制多边形数组
|
|
*
|
|
*
|
|
@@ -214,25 +224,35 @@ export class SPolygonItem extends SGraphItem {
|
|
*/
|
|
*/
|
|
protected drawCreatePolygon(painter: SPainter, pointList: SPoint[]): void {
|
|
protected drawCreatePolygon(painter: SPainter, pointList: SPoint[]): void {
|
|
painter.pen.lineCapStyle = SLineCapStyle.Square;
|
|
painter.pen.lineCapStyle = SLineCapStyle.Square;
|
|
- painter.pen.color = this.borderColor;
|
|
|
|
- painter.pen.lineWidth = painter.toPx(this.borderLine);
|
|
|
|
|
|
+ painter.pen.color = this._strokeColor;
|
|
|
|
+ painter.pen.lineWidth = painter.toPx(this._lineWidth);
|
|
if (this.lastPoint && pointList.length) {
|
|
if (this.lastPoint && pointList.length) {
|
|
- painter.drawLine(
|
|
|
|
- pointList[pointList.length - 1].x,
|
|
|
|
- pointList[pointList.length - 1].y,
|
|
|
|
- this.lastPoint.x,
|
|
|
|
- this.lastPoint.y
|
|
|
|
- );
|
|
|
|
|
|
+ painter.drawLine(pointList[pointList.length - 1].x, pointList[pointList.length - 1].y, this.lastPoint.x, this.lastPoint.y);
|
|
}
|
|
}
|
|
painter.drawPolyline(pointList);
|
|
painter.drawPolyline(pointList);
|
|
painter.pen.color = SColor.Transparent;
|
|
painter.pen.color = SColor.Transparent;
|
|
- painter.brush.color = this.brushColor;
|
|
|
|
- painter.pen.lineWidth = painter.toPx(this.borderLine);
|
|
|
|
|
|
+ painter.brush.color = new SColor(this._fillColor.value + "80");
|
|
|
|
+ painter.pen.lineWidth = painter.toPx(this._lineWidth);
|
|
|
|
+
|
|
if (this.lastPoint) {
|
|
if (this.lastPoint) {
|
|
painter.drawPolygon([...pointList, this.lastPoint]);
|
|
painter.drawPolygon([...pointList, this.lastPoint]);
|
|
|
|
+ // 绘制顶点块
|
|
|
|
+ painter.pen.color = SColor.Black;
|
|
|
|
+ painter.brush.color = SColor.White;
|
|
|
|
+ pointList.forEach((item, index) => {
|
|
|
|
+ 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))
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
painter.drawPolygon(pointList);
|
|
painter.drawPolygon(pointList);
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -244,13 +264,17 @@ export class SPolygonItem extends SGraphItem {
|
|
*/
|
|
*/
|
|
protected drawEditPolygon(painter: SPainter, pointList: SPoint[]): void {
|
|
protected drawEditPolygon(painter: SPainter, pointList: SPoint[]): void {
|
|
// 展示多边形
|
|
// 展示多边形
|
|
- this.drawShowPolygon(painter, pointList);
|
|
|
|
|
|
+ painter.pen.lineCapStyle = SLineCapStyle.Square;
|
|
|
|
+ painter.pen.color = this._strokeColor;
|
|
|
|
+ painter.pen.lineWidth = painter.toPx(this._lineWidth);
|
|
|
|
+ painter.brush.color = new SColor(this._fillColor.value + "80");
|
|
|
|
+ painter.drawPolygon([...pointList]);
|
|
// 绘制顶点块
|
|
// 绘制顶点块
|
|
painter.pen.color = SColor.Black;
|
|
painter.pen.color = SColor.Black;
|
|
painter.brush.color = SColor.White;
|
|
painter.brush.color = SColor.White;
|
|
pointList.forEach((item, index) => {
|
|
pointList.forEach((item, index) => {
|
|
- painter.drawCircle(item.x, item.y, painter.toPx(this.len / 2));
|
|
|
|
- });
|
|
|
|
|
|
+ painter.drawCircle(item.x, item.y, painter.toPx(this.len / 2))
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -264,7 +288,7 @@ export class SPolygonItem extends SGraphItem {
|
|
// 判断是否为删除状态 isAlt = true为删除状态
|
|
// 判断是否为删除状态 isAlt = true为删除状态
|
|
if (this.isAlt) {
|
|
if (this.isAlt) {
|
|
// 1 判断是否点击在多边形顶点
|
|
// 1 判断是否点击在多边形顶点
|
|
- let lenIndex = -1; // 当前点击到的点位索引;
|
|
|
|
|
|
+ let lenIndex = -1; // 当前点击到的点位索引;
|
|
let curenLen = this.scenceLen; // 当前的灵敏度
|
|
let curenLen = this.scenceLen; // 当前的灵敏度
|
|
this.pointList.forEach((item, index) => {
|
|
this.pointList.forEach((item, index) => {
|
|
let dis = SMathUtil.pointDistance(
|
|
let dis = SMathUtil.pointDistance(
|
|
@@ -281,25 +305,18 @@ export class SPolygonItem extends SGraphItem {
|
|
// 若点击到,对该索引对应的点做删除
|
|
// 若点击到,对该索引对应的点做删除
|
|
if (lenIndex != -1) {
|
|
if (lenIndex != -1) {
|
|
if (this.pointList.length <= 3) {
|
|
if (this.pointList.length <= 3) {
|
|
- return;
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
- const delePoint = new SPoint(
|
|
|
|
- this.pointList[lenIndex].x,
|
|
|
|
- this.pointList[lenIndex].y
|
|
|
|
- );
|
|
|
|
|
|
+ const delePoint = new SPoint(this.pointList[lenIndex].x, this.pointList[lenIndex].y)
|
|
this.deletePoint(lenIndex);
|
|
this.deletePoint(lenIndex);
|
|
// 记录顶点操作记录压入堆栈
|
|
// 记录顶点操作记录压入堆栈
|
|
- this.recordAction(SGraphPointListDelete, [
|
|
|
|
- this.pointList,
|
|
|
|
- delePoint,
|
|
|
|
- lenIndex
|
|
|
|
- ]);
|
|
|
|
|
|
+ this.recordAction(SGraphPointListDelete, [this.pointList, delePoint, lenIndex]);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
// 1 判断是否点击在多边形顶点
|
|
// 1 判断是否点击在多边形顶点
|
|
this.curIndex = -1;
|
|
this.curIndex = -1;
|
|
this.curPoint = null;
|
|
this.curPoint = null;
|
|
- let lenIndex = -1; // 当前点击到的点位索引;
|
|
|
|
|
|
+ let lenIndex = -1; // 当前点击到的点位索引;
|
|
let curenLen = this.scenceLen; // 当前的灵敏度
|
|
let curenLen = this.scenceLen; // 当前的灵敏度
|
|
this.pointList.forEach((item, index) => {
|
|
this.pointList.forEach((item, index) => {
|
|
let dis = SMathUtil.pointDistance(
|
|
let dis = SMathUtil.pointDistance(
|
|
@@ -317,9 +334,9 @@ export class SPolygonItem extends SGraphItem {
|
|
// 2判断是否点击在多边形得边上
|
|
// 2判断是否点击在多边形得边上
|
|
if (-1 == lenIndex) {
|
|
if (-1 == lenIndex) {
|
|
let len = SMathUtil.pointToLine(
|
|
let len = SMathUtil.pointToLine(
|
|
- new SPoint(event.x, event.y),
|
|
|
|
- new SLine(this.pointList[0], this.pointList[1])
|
|
|
|
- ),
|
|
|
|
|
|
+ new SPoint(event.x, event.y),
|
|
|
|
+ new SLine(this.pointList[0], this.pointList[1])
|
|
|
|
+ ),
|
|
index = 0;
|
|
index = 0;
|
|
if (this.pointList.length > 2) {
|
|
if (this.pointList.length > 2) {
|
|
for (let i = 1; i < this.pointList.length; i++) {
|
|
for (let i = 1; i < this.pointList.length; i++) {
|
|
@@ -327,7 +344,7 @@ export class SPolygonItem extends SGraphItem {
|
|
new SPoint(event.x, event.y),
|
|
new SPoint(event.x, event.y),
|
|
new SLine(this.pointList[i], this.pointList[i + 1])
|
|
new SLine(this.pointList[i], this.pointList[i + 1])
|
|
);
|
|
);
|
|
- if (i + 1 == this.pointList.length) {
|
|
|
|
|
|
+ if ((i + 1) == this.pointList.length) {
|
|
dis = SMathUtil.pointToLine(
|
|
dis = SMathUtil.pointToLine(
|
|
new SPoint(event.x, event.y),
|
|
new SPoint(event.x, event.y),
|
|
new SLine(this.pointList[i], this.pointList[0])
|
|
new SLine(this.pointList[i], this.pointList[0])
|
|
@@ -339,28 +356,26 @@ export class SPolygonItem extends SGraphItem {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- // 如果再线上则为新增点
|
|
|
|
|
|
+ // 判断是否有点
|
|
if (len.Point) {
|
|
if (len.Point) {
|
|
|
|
+ console.log(index,len.Point);
|
|
|
|
+ // 点在了多边形的边上
|
|
if (len.MinDis <= this.scenceLen) {
|
|
if (len.MinDis <= this.scenceLen) {
|
|
this.pointList.splice(index + 1, 0, len.Point);
|
|
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 {
|
|
} else {
|
|
// 当捕捉到顶点后 ,记录当前点的xy坐标,用于undo、redo操作
|
|
// 当捕捉到顶点后 ,记录当前点的xy坐标,用于undo、redo操作
|
|
- this.curPoint = new SPoint(
|
|
|
|
- this.pointList[this.curIndex].x,
|
|
|
|
- this.pointList[this.curIndex].y
|
|
|
|
- );
|
|
|
|
|
|
+ this.curPoint = new SPoint(this.pointList[this.curIndex].x, this.pointList[this.curIndex].y);
|
|
}
|
|
}
|
|
// 刷新视图
|
|
// 刷新视图
|
|
this.update();
|
|
this.update();
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/////////////////////
|
|
/////////////////////
|
|
@@ -383,8 +398,8 @@ export class SPolygonItem extends SGraphItem {
|
|
* 执行取消操作执行
|
|
* 执行取消操作执行
|
|
*/
|
|
*/
|
|
undo(): void {
|
|
undo(): void {
|
|
- if (this._status == SItemStatus.Normal) {
|
|
|
|
- return;
|
|
|
|
|
|
+ if (this.status == SItemStatus.Normal) {
|
|
|
|
+ return
|
|
}
|
|
}
|
|
if (this.undoStack) {
|
|
if (this.undoStack) {
|
|
this.undoStack.undo();
|
|
this.undoStack.undo();
|
|
@@ -395,8 +410,8 @@ export class SPolygonItem extends SGraphItem {
|
|
* 执行重做操作执行
|
|
* 执行重做操作执行
|
|
*/
|
|
*/
|
|
redo(): void {
|
|
redo(): void {
|
|
- if (this._status == SItemStatus.Normal) {
|
|
|
|
- return;
|
|
|
|
|
|
+ if (this.status == SItemStatus.Normal) {
|
|
|
|
+ return
|
|
}
|
|
}
|
|
if (this.undoStack) {
|
|
if (this.undoStack) {
|
|
this.undoStack.redo();
|
|
this.undoStack.redo();
|
|
@@ -414,20 +429,21 @@ export class SPolygonItem extends SGraphItem {
|
|
*/
|
|
*/
|
|
onDoubleClick(event: SMouseEvent): boolean {
|
|
onDoubleClick(event: SMouseEvent): boolean {
|
|
// 如果位show状态 双击改对象则需改为编辑状态
|
|
// 如果位show状态 双击改对象则需改为编辑状态
|
|
- if (SItemStatus.Normal == this._status) {
|
|
|
|
- this._status = SItemStatus.Edit;
|
|
|
|
|
|
+ if (SItemStatus.Normal == this.status) {
|
|
|
|
+ this.status = SItemStatus.Edit;
|
|
this.grabItem(this);
|
|
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();
|
|
this.releaseItem();
|
|
if (this.undoStack) {
|
|
if (this.undoStack) {
|
|
- this.undoStack.clear();
|
|
|
|
|
|
+ this.undoStack.clear()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- this.update();
|
|
|
|
|
|
+ this.update()
|
|
return true;
|
|
return true;
|
|
} // Function onDoubleClick()
|
|
} // Function onDoubleClick()
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 键盘事件
|
|
* 键盘事件
|
|
*
|
|
*
|
|
@@ -436,15 +452,15 @@ export class SPolygonItem extends SGraphItem {
|
|
*/
|
|
*/
|
|
|
|
|
|
onKeyDown(event: KeyboardEvent): boolean {
|
|
onKeyDown(event: KeyboardEvent): boolean {
|
|
- if (this._status == SItemStatus.Normal) {
|
|
|
|
|
|
+ if (this.status == SItemStatus.Normal) {
|
|
return false;
|
|
return false;
|
|
- } else if (this._status == SItemStatus.Create) {
|
|
|
|
- if (event.code == "Enter") {
|
|
|
|
|
|
+ } else if (this.status == SItemStatus.Create) {
|
|
|
|
+ if (event.code == 'Enter') {
|
|
// 当顶点大于二个时才又条件执行闭合操作并清空堆栈
|
|
// 当顶点大于二个时才又条件执行闭合操作并清空堆栈
|
|
if (this.pointList.length > 2) {
|
|
if (this.pointList.length > 2) {
|
|
- this._status = SItemStatus.Normal;
|
|
|
|
|
|
+ this.status = SItemStatus.Normal;
|
|
//3 传递完成事件状态
|
|
//3 传递完成事件状态
|
|
- this.$emit("finishCreated");
|
|
|
|
|
|
+ this.$emit('finishCreated')
|
|
//1 grabItem 置为null
|
|
//1 grabItem 置为null
|
|
this.releaseItem();
|
|
this.releaseItem();
|
|
//2 清空undo
|
|
//2 清空undo
|
|
@@ -453,8 +469,8 @@ export class SPolygonItem extends SGraphItem {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } else if (this._status == SItemStatus.Edit) {
|
|
|
|
- if (event.key == "Alt") {
|
|
|
|
|
|
+ } else if (this.status == SItemStatus.Edit) {
|
|
|
|
+ if (event.key == 'Alt') {
|
|
this.isAlt = true;
|
|
this.isAlt = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -462,6 +478,7 @@ export class SPolygonItem extends SGraphItem {
|
|
return true;
|
|
return true;
|
|
} // Function onKeyDown()
|
|
} // Function onKeyDown()
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 键盘键抬起事件
|
|
* 键盘键抬起事件
|
|
*
|
|
*
|
|
@@ -469,12 +486,12 @@ export class SPolygonItem extends SGraphItem {
|
|
* @return boolean
|
|
* @return boolean
|
|
*/
|
|
*/
|
|
onKeyUp(event: KeyboardEvent): void {
|
|
onKeyUp(event: KeyboardEvent): void {
|
|
- if (this._status == SItemStatus.Edit) {
|
|
|
|
- if (event.key == "Alt") {
|
|
|
|
|
|
+ if (this.status == SItemStatus.Edit) {
|
|
|
|
+ if (event.key == 'Alt') {
|
|
this.isAlt = false;
|
|
this.isAlt = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- this.update();
|
|
|
|
|
|
+ this.update()
|
|
} // Function onKeyUp()
|
|
} // Function onKeyUp()
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -485,19 +502,33 @@ export class SPolygonItem extends SGraphItem {
|
|
*/
|
|
*/
|
|
onMouseDown(event: SMouseEvent): boolean {
|
|
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) {
|
|
|
|
|
|
+ let len = SMathUtil.pointDistance(event.x, event.y, this.pointList[0].x, this.pointList[0].y);
|
|
|
|
+ if (this.pointList.length > 2 && 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);
|
|
|
|
+ // 记录新增顶点操作记录压入堆栈
|
|
|
|
+ let pos = new SPoint(event.x, event.y);
|
|
|
|
+ this.recordAction(SGraphPointListInsert, [this.pointList, pos]);
|
|
|
|
+ }
|
|
|
|
+ } else if (this.status == SItemStatus.Edit) {
|
|
// 对多边形数组做编辑操作
|
|
// 对多边形数组做编辑操作
|
|
this.editPolygonPoint(event);
|
|
this.editPolygonPoint(event);
|
|
} else {
|
|
} else {
|
|
- // return super.onMouseDown(event)
|
|
|
|
|
|
+ return super.onMouseDown(event)
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
|
|
+
|
|
} // Function onMouseDown()
|
|
} // Function onMouseDown()
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -510,6 +541,7 @@ export class SPolygonItem extends SGraphItem {
|
|
return true;
|
|
return true;
|
|
} // Function onMouseEnter()
|
|
} // Function onMouseEnter()
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 鼠标移出事件
|
|
* 鼠标移出事件
|
|
*
|
|
*
|
|
@@ -529,17 +561,17 @@ export class SPolygonItem extends SGraphItem {
|
|
*/
|
|
*/
|
|
|
|
|
|
onMouseMove(event: SMouseEvent): boolean {
|
|
onMouseMove(event: SMouseEvent): boolean {
|
|
- if (this._status == SItemStatus.Create) {
|
|
|
|
- this.lastPoint = new SPoint();
|
|
|
|
|
|
+ if (this.status == SItemStatus.Create) {
|
|
|
|
+ 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 == SItemStatus.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;
|
|
}
|
|
}
|
|
- this.update();
|
|
|
|
|
|
+ this.update()
|
|
} else {
|
|
} else {
|
|
// return super.onMouseMove(event)
|
|
// return super.onMouseMove(event)
|
|
}
|
|
}
|
|
@@ -547,6 +579,7 @@ export class SPolygonItem extends SGraphItem {
|
|
return true;
|
|
return true;
|
|
} // Function onMouseMove()
|
|
} // Function onMouseMove()
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 鼠标抬起事件
|
|
* 鼠标抬起事件
|
|
*
|
|
*
|
|
@@ -554,18 +587,10 @@ export class SPolygonItem extends SGraphItem {
|
|
* @return boolean
|
|
* @return boolean
|
|
*/
|
|
*/
|
|
onMouseUp(event: SMouseEvent): boolean {
|
|
onMouseUp(event: SMouseEvent): boolean {
|
|
- if (this._status == SItemStatus.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
|
|
|
|
- );
|
|
|
|
- this.recordAction(SGraphPointListUpdate, [
|
|
|
|
- this.pointList,
|
|
|
|
- this.curPoint,
|
|
|
|
- pos,
|
|
|
|
- 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])
|
|
}
|
|
}
|
|
this.curIndex = -1;
|
|
this.curIndex = -1;
|
|
this.curPoint = null;
|
|
this.curPoint = null;
|
|
@@ -589,17 +614,18 @@ export class SPolygonItem extends SGraphItem {
|
|
/**
|
|
/**
|
|
* 取消操作
|
|
* 取消操作
|
|
*
|
|
*
|
|
|
|
+ * @param painter painter对象
|
|
*/
|
|
*/
|
|
cancelOperate(): void {
|
|
cancelOperate(): void {
|
|
// 当状态为展示状态
|
|
// 当状态为展示状态
|
|
- if (this._status == SItemStatus.Create) {
|
|
|
|
|
|
+ if (this.status == SItemStatus.Create) {
|
|
// 闭合多边形
|
|
// 闭合多边形
|
|
- this.parent = null;
|
|
|
|
- } else if (this._status == SItemStatus.Edit) {
|
|
|
|
|
|
+ this.parent = null
|
|
|
|
+ } else if (this.status == SItemStatus.Edit) {
|
|
// 编辑状态
|
|
// 编辑状态
|
|
- this._status = SItemStatus.Normal;
|
|
|
|
|
|
+ this.status = SItemStatus.Normal
|
|
}
|
|
}
|
|
- this.update();
|
|
|
|
|
|
+ this.update()
|
|
} // Function cancelOperate()
|
|
} // Function cancelOperate()
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -629,7 +655,7 @@ export class SPolygonItem extends SGraphItem {
|
|
this.maxY = y;
|
|
this.maxY = y;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
- }
|
|
|
|
|
|
+ };
|
|
return new SRect(
|
|
return new SRect(
|
|
this.minX,
|
|
this.minX,
|
|
this.minY,
|
|
this.minY,
|
|
@@ -646,7 +672,10 @@ export class SPolygonItem extends SGraphItem {
|
|
*/
|
|
*/
|
|
contains(x: number, y: number): boolean {
|
|
contains(x: number, y: number): boolean {
|
|
let arr = this.pointList;
|
|
let arr = this.pointList;
|
|
- return !(arr.length < 3 || !SPolygonUtil.pointIn(x, y, arr));
|
|
|
|
|
|
+ if (arr.length < 3 || !SPolygonUtil.pointIn(x, y, arr)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
} // Function contains()
|
|
} // Function contains()
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -655,17 +684,19 @@ export class SPolygonItem extends SGraphItem {
|
|
* @param painter painter对象
|
|
* @param painter painter对象
|
|
*/
|
|
*/
|
|
onDraw(painter: SPainter): void {
|
|
onDraw(painter: SPainter): void {
|
|
- this.scenceLen = painter.toPx(this.len);
|
|
|
|
|
|
+ this.scenceLen = painter.toPx(this.len)
|
|
// 当状态为展示状态
|
|
// 当状态为展示状态
|
|
- if (this._status == SItemStatus.Normal) {
|
|
|
|
|
|
+ if (this.status == SItemStatus.Normal) {
|
|
// 闭合多边形
|
|
// 闭合多边形
|
|
this.drawShowPolygon(painter, this.pointList);
|
|
this.drawShowPolygon(painter, this.pointList);
|
|
- } else if (this._status == SItemStatus.Create) {
|
|
|
|
|
|
+ } else if (this.status == SItemStatus.Create) {
|
|
// 创建状态
|
|
// 创建状态
|
|
- this.drawCreatePolygon(painter, this.pointList);
|
|
|
|
|
|
+ this.drawCreatePolygon(painter, this.pointList)
|
|
} else {
|
|
} else {
|
|
// 编辑状态
|
|
// 编辑状态
|
|
this.drawEditPolygon(painter, this.pointList);
|
|
this.drawEditPolygon(painter, this.pointList);
|
|
}
|
|
}
|
|
} // Function onDraw()
|
|
} // Function onDraw()
|
|
-}
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|