|
@@ -29,7 +29,8 @@ import { SMouseButton, SMouseEvent, SUndoStack } from "@persagy-web/base";
|
|
|
import { SItemStatus } from "@persagy-web/big";
|
|
|
import {
|
|
|
SLineStyle,
|
|
|
- SGraphItem, SGraphPointListInsert
|
|
|
+ SGraphItem,
|
|
|
+ SGraphPointListInsert
|
|
|
} from "@persagy-web/graph/";
|
|
|
import { SGraphEdit } from "..";
|
|
|
import { Marker } from "../type/Marker";
|
|
@@ -121,29 +122,31 @@ export class SBaseTriangleEdit extends SGraphEdit {
|
|
|
constructor(parent: SGraphItem | null, data: Marker) {
|
|
|
super(parent);
|
|
|
this.data = data;
|
|
|
+ // 数据中存有默认样式
|
|
|
if (data.style && data.style.default) {
|
|
|
// 关于顶点
|
|
|
if (data.style.default.Line) {
|
|
|
let setPointList: SPoint[];
|
|
|
+ // 生成点列表
|
|
|
setPointList = data.style.default.line.map(i => {
|
|
|
- return new SPoint(i.x, i.y)
|
|
|
+ return new SPoint(i.x, i.y);
|
|
|
});
|
|
|
this.line = setPointList;
|
|
|
}
|
|
|
|
|
|
- // 颜色
|
|
|
+ // 设置颜色
|
|
|
if (data.style.default.strokeColor) {
|
|
|
- this.strokeColor = new SColor(data.style.default.strokeColor)
|
|
|
+ this.strokeColor = new SColor(data.style.default.strokeColor);
|
|
|
}
|
|
|
|
|
|
- // 线宽
|
|
|
+ // 设置线宽
|
|
|
if (data.style.default.lineWidth) {
|
|
|
- this.lineWidth = data.style.default.lineWidth
|
|
|
+ this.lineWidth = data.style.default.lineWidth;
|
|
|
}
|
|
|
|
|
|
- // 线样式
|
|
|
+ // 设置线样式
|
|
|
if (data.style.default.lineStyle) {
|
|
|
- this.lineStyle = data.style.default.lineStyle
|
|
|
+ this.lineStyle = data.style.default.lineStyle;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -157,6 +160,7 @@ export class SBaseTriangleEdit extends SGraphEdit {
|
|
|
resize(oldSize: SRect, newSize: SRect): void {
|
|
|
const xs = newSize.width / oldSize.width;
|
|
|
const ys = newSize.height / oldSize.height;
|
|
|
+ // 遍历点列表
|
|
|
this.line = this.line.map(t => {
|
|
|
t.x = t.x * xs;
|
|
|
t.y = t.y * ys;
|
|
@@ -173,11 +177,14 @@ export class SBaseTriangleEdit extends SGraphEdit {
|
|
|
* @return 是否处理事件
|
|
|
*/
|
|
|
onMouseDown(event: SMouseEvent): boolean {
|
|
|
+ // 按下左键
|
|
|
if (event.buttons == SMouseButton.LeftButton) {
|
|
|
+ // 处于创建态
|
|
|
if (this.status == SItemStatus.Create) {
|
|
|
this.addPoint(new SPoint(event.x, event.y));
|
|
|
return true;
|
|
|
} else {
|
|
|
+ // 否则
|
|
|
return super.onMouseDown(event);
|
|
|
}
|
|
|
}
|
|
@@ -192,12 +199,15 @@ export class SBaseTriangleEdit extends SGraphEdit {
|
|
|
* @return 是否处理事件
|
|
|
*/
|
|
|
onMouseMove(event: SMouseEvent): boolean {
|
|
|
+ // 处于创建态
|
|
|
if (this.status == SItemStatus.Create) {
|
|
|
+ // 存在一个点
|
|
|
if (this.line[0] instanceof SPoint) {
|
|
|
this.line[1] = new SPoint(event.x, event.y);
|
|
|
- this.calRect()
|
|
|
+ this.calRect();
|
|
|
}
|
|
|
} else {
|
|
|
+ // 否则
|
|
|
return super.onMouseMove(event);
|
|
|
}
|
|
|
|
|
@@ -212,6 +222,7 @@ export class SBaseTriangleEdit extends SGraphEdit {
|
|
|
* @return 是否处理事件
|
|
|
*/
|
|
|
onMouseUp(event: SMouseEvent): boolean {
|
|
|
+ // 处于非创建态
|
|
|
if (this.status != SItemStatus.Create) {
|
|
|
super.onMouseUp(event);
|
|
|
}
|
|
@@ -227,6 +238,7 @@ export class SBaseTriangleEdit extends SGraphEdit {
|
|
|
const fi = this.line[0];
|
|
|
const se = this.line[1];
|
|
|
let minx, maxx, miny, maxy;
|
|
|
+ // 保存 x 最大值和最小值
|
|
|
if (fi.x < se.x) {
|
|
|
minx = fi.x;
|
|
|
maxx = se.x;
|
|
@@ -235,6 +247,7 @@ export class SBaseTriangleEdit extends SGraphEdit {
|
|
|
maxx = fi.x;
|
|
|
}
|
|
|
|
|
|
+ // 保存 y 最大值和最小值
|
|
|
if (fi.y < se.y) {
|
|
|
miny = fi.y;
|
|
|
maxy = se.y;
|
|
@@ -245,7 +258,7 @@ export class SBaseTriangleEdit extends SGraphEdit {
|
|
|
|
|
|
this._leftTop = new SPoint(minx, miny);
|
|
|
this._rightBottom = new SPoint(maxx, maxy);
|
|
|
- this.calTriangle()
|
|
|
+ this.calTriangle();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -255,8 +268,15 @@ export class SBaseTriangleEdit extends SGraphEdit {
|
|
|
private calTriangle(): void {
|
|
|
this.pointList = [];
|
|
|
this.pointList.push(new SPoint(this._leftTop.x, this._rightBottom.y));
|
|
|
- this.pointList.push(new SPoint((this._leftTop.x + this._rightBottom.x) / 2, this._leftTop.y));
|
|
|
- this.pointList.push(new SPoint(this._rightBottom.x, this._rightBottom.y));
|
|
|
+ this.pointList.push(
|
|
|
+ new SPoint(
|
|
|
+ (this._leftTop.x + this._rightBottom.x) / 2,
|
|
|
+ this._leftTop.y
|
|
|
+ )
|
|
|
+ );
|
|
|
+ this.pointList.push(
|
|
|
+ new SPoint(this._rightBottom.x, this._rightBottom.y)
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -265,10 +285,12 @@ export class SBaseTriangleEdit extends SGraphEdit {
|
|
|
* @param p 添加的点
|
|
|
*/
|
|
|
private addPoint(p: SPoint): void {
|
|
|
+ // 列表中点个数少于 2 个
|
|
|
if (this.line.length < 2) {
|
|
|
this.line.push(p);
|
|
|
this.recordAction(SGraphPointListInsert, [this.line, p]);
|
|
|
} else {
|
|
|
+ // 否则
|
|
|
this.line[1] = p;
|
|
|
this.recordAction(SGraphPointListInsert, [this.line, p, 1]);
|
|
|
this.status = SItemStatus.Normal;
|
|
@@ -298,18 +320,20 @@ export class SBaseTriangleEdit extends SGraphEdit {
|
|
|
* @return 边界区域
|
|
|
*/
|
|
|
boundingRect(): SRect {
|
|
|
+ // 列表中点个超个 1 个
|
|
|
if (this.line.length > 1) {
|
|
|
this.calRect();
|
|
|
return new SRect(this._leftTop, this._rightBottom);
|
|
|
}
|
|
|
|
|
|
- return new SRect()
|
|
|
+ return new SRect();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 撤销操作
|
|
|
*/
|
|
|
undo(): void {
|
|
|
+ // 处于非正常态
|
|
|
if (this._status != SItemStatus.Normal) {
|
|
|
this.undoStack.undo();
|
|
|
}
|
|
@@ -319,6 +343,7 @@ export class SBaseTriangleEdit extends SGraphEdit {
|
|
|
* 重做操作
|
|
|
*/
|
|
|
redo(): void {
|
|
|
+ // 处于非正常态
|
|
|
if (this._status != SItemStatus.Normal) {
|
|
|
this.undoStack.redo();
|
|
|
}
|
|
@@ -328,10 +353,12 @@ export class SBaseTriangleEdit extends SGraphEdit {
|
|
|
* 取消操作执行
|
|
|
*/
|
|
|
cancelOperate(): void {
|
|
|
+ // 处于创建态
|
|
|
if (this.status == SItemStatus.Create) {
|
|
|
this.parent = null;
|
|
|
this.releaseItem();
|
|
|
} else if (this.status == SItemStatus.Edit) {
|
|
|
+ // 处于编辑态
|
|
|
this.status = SItemStatus.Normal;
|
|
|
this.releaseItem();
|
|
|
}
|
|
@@ -343,16 +370,19 @@ export class SBaseTriangleEdit extends SGraphEdit {
|
|
|
* @param painter 绘制对象
|
|
|
*/
|
|
|
onDraw(painter: SPainter): void {
|
|
|
+ // 列表中点个数为 2
|
|
|
if (this.line.length == 2) {
|
|
|
painter.pen.color = this.strokeColor;
|
|
|
painter.brush.color = this.fillColor;
|
|
|
painter.pen.lineWidth = this.lineWidth;
|
|
|
+ // 线类型为虚线
|
|
|
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 * 2),
|
|
|
painter.toPx(this.lineWidth * 2)
|