|
@@ -140,6 +140,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*/
|
|
|
constructor(parent: null | SGraphItem, list: SPoint | SPoint[]) {
|
|
|
super(parent);
|
|
|
+ // 数据类型为 SPoint
|
|
|
if (list instanceof SPoint) {
|
|
|
this.pointList.push(list);
|
|
|
} else {
|
|
@@ -154,6 +155,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* @param index 添加到的索引
|
|
|
*/
|
|
|
private addPoint(p: SPoint, index?: number): void {
|
|
|
+ // 添加的索引存在且索引值有效
|
|
|
if (index && this.canHandle(index)) {
|
|
|
this.pointList.splice(index, 0, p);
|
|
|
this.recordAction(SGraphPointListInsert, [
|
|
@@ -162,6 +164,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
index
|
|
|
]);
|
|
|
} else {
|
|
|
+ // 否则
|
|
|
this.pointList.push(p);
|
|
|
this.recordAction(SGraphPointListInsert, [this.pointList, p]);
|
|
|
}
|
|
@@ -185,6 +188,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* @param index 删除点
|
|
|
*/
|
|
|
deletePoint(index: number): void {
|
|
|
+ // 索引值有效且折线列表有2个以上点
|
|
|
if (this.canHandle(index) && this.pointList.length > 2) {
|
|
|
const p = new SPoint(
|
|
|
this.pointList[this.curIndex].x,
|
|
@@ -210,6 +214,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*/
|
|
|
moveToOrigin(x: number, y: number): void {
|
|
|
super.moveToOrigin(x, y);
|
|
|
+ // 遍历点集列表
|
|
|
this.pointList = this.pointList.map(
|
|
|
(t): SPoint => {
|
|
|
t.x = t.x + x;
|
|
@@ -228,6 +233,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*/
|
|
|
findNearestPoint(p: SPoint): void {
|
|
|
let len = this.sceneDis;
|
|
|
+ // 遍历点集列表
|
|
|
for (let i = 0; i < this.pointList.length; i++) {
|
|
|
let dis = SMathUtil.pointDistance(
|
|
|
p.x,
|
|
@@ -235,6 +241,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
this.pointList[i].x,
|
|
|
this.pointList[i].y
|
|
|
);
|
|
|
+ // 当前距离小于最短距离
|
|
|
if (dis < len) {
|
|
|
len = dis;
|
|
|
this.curIndex = i;
|
|
@@ -253,10 +260,11 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*/
|
|
|
findAddPos(p: SPoint): void {
|
|
|
let len = SMathUtil.pointToLine(
|
|
|
- p,
|
|
|
- new SLine(this.pointList[0], this.pointList[1])
|
|
|
- ),
|
|
|
+ p,
|
|
|
+ new SLine(this.pointList[0], this.pointList[1])
|
|
|
+ ),
|
|
|
index = 0;
|
|
|
+ // 折线点集多余2
|
|
|
if (this.pointList.length > 2) {
|
|
|
for (let i = 1; i < this.pointList.length - 1; i++) {
|
|
|
let dis = SMathUtil.pointToLine(
|
|
@@ -269,7 +277,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ // 最短距离在可吸附范围内且吸附点存在
|
|
|
if (len.MinDis < this.sceneDis && len.Point) {
|
|
|
this.addPoint(len.Point, index + 1);
|
|
|
}
|
|
@@ -282,6 +290,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* @return 事件对象
|
|
|
*/
|
|
|
compare(event: SMouseEvent): SMouseEvent {
|
|
|
+ // 点集列表存在
|
|
|
if (this.pointList.length) {
|
|
|
let last = new SPoint(event.x, event.y);
|
|
|
if (this.status == SItemStatus.Create) {
|
|
@@ -294,9 +303,11 @@ export class SPolylineItem extends SGraphItem {
|
|
|
|
|
|
const dx = Math.abs(event.x - last.x);
|
|
|
const dy = Math.abs(event.y - last.y);
|
|
|
+ // 纵向变量更大
|
|
|
if (dy > dx) {
|
|
|
event.x = last.x;
|
|
|
} else {
|
|
|
+ // 否则
|
|
|
event.y = last.y;
|
|
|
}
|
|
|
}
|
|
@@ -322,6 +333,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* @return 外接矩阵
|
|
|
*/
|
|
|
boundingRect(): SRect {
|
|
|
+ // 点集列表有值
|
|
|
if (this.pointList.length) {
|
|
|
this.minX = this.pointList[0].x;
|
|
|
this.maxX = this.pointList[0].x;
|
|
@@ -370,6 +382,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*/
|
|
|
contains(x: number, y: number): boolean {
|
|
|
let p = new SPoint(x, y);
|
|
|
+ // 遍历点集列表
|
|
|
for (let i = 1; i < this.pointList.length; i++) {
|
|
|
let PTL = SMathUtil.pointToLine(
|
|
|
p,
|
|
@@ -380,6 +393,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
this.pointList[i].y
|
|
|
)
|
|
|
);
|
|
|
+ // 点在吸附范围内
|
|
|
if (PTL.MinDis < this.sceneDis) {
|
|
|
return true;
|
|
|
}
|
|
@@ -391,6 +405,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* 撤销操作
|
|
|
*/
|
|
|
undo(): void {
|
|
|
+ // 非正常态
|
|
|
if (this._status != SItemStatus.Normal) {
|
|
|
this.undoStack.undo();
|
|
|
}
|
|
@@ -400,6 +415,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* 重做操作
|
|
|
*/
|
|
|
redo(): void {
|
|
|
+ // 非正常态
|
|
|
if (this._status != SItemStatus.Normal) {
|
|
|
this.undoStack.redo();
|
|
|
}
|
|
@@ -409,10 +425,12 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* 取消操作执行
|
|
|
*/
|
|
|
cancelOperate(): void {
|
|
|
+ // 创建态
|
|
|
if (this.status == SItemStatus.Create) {
|
|
|
this.parent = null;
|
|
|
this.releaseItem();
|
|
|
} else if (this.status == SItemStatus.Edit) {
|
|
|
+ // 编辑态
|
|
|
this.status = SItemStatus.Normal;
|
|
|
this.releaseItem();
|
|
|
}
|
|
@@ -426,11 +444,13 @@ export class SPolylineItem extends SGraphItem {
|
|
|
drawBaseLine(painter: SPainter): void {
|
|
|
// 绘制基本图形
|
|
|
if (this.lineStyle == SLineStyle.Dashed) {
|
|
|
+ // 虚线
|
|
|
painter.pen.lineDash = [
|
|
|
painter.toPx(this.lineWidth * 3),
|
|
|
painter.toPx(this.lineWidth * 7)
|
|
|
];
|
|
|
} else if (this.lineStyle == SLineStyle.Dotted) {
|
|
|
+ // 点线
|
|
|
painter.pen.lineDash = [
|
|
|
painter.toPx(this.lineWidth),
|
|
|
painter.toPx(this.lineWidth)
|
|
@@ -451,6 +471,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
this.sceneDis = painter.toPx(this.dis);
|
|
|
// 创建状态
|
|
|
painter.pen.lineWidth = painter.toPx(this.lineWidth);
|
|
|
+ // 创建态且最后一个点存在
|
|
|
if (this.status == SItemStatus.Create && this.lastPoint) {
|
|
|
// 绘制基本图形
|
|
|
this.drawBaseLine(painter);
|