|
@@ -140,7 +140,7 @@ export class SLineItem extends SGraphItem {
|
|
|
* 构造函数
|
|
|
*
|
|
|
* @param parent 父级
|
|
|
- */
|
|
|
+ */
|
|
|
constructor(parent: SGraphItem | null);
|
|
|
|
|
|
/**
|
|
@@ -148,7 +148,7 @@ export class SLineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param parent 父级
|
|
|
* @param line 坐标集合
|
|
|
- */
|
|
|
+ */
|
|
|
constructor(parent: SGraphItem | null, line: SPoint[]);
|
|
|
|
|
|
/**
|
|
@@ -156,7 +156,7 @@ export class SLineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param parent 父级
|
|
|
* @param point 第一个点坐标
|
|
|
- */
|
|
|
+ */
|
|
|
constructor(parent: SGraphItem | null, point: SPoint);
|
|
|
|
|
|
/**
|
|
@@ -164,7 +164,7 @@ export class SLineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param parent 父级
|
|
|
* @param line 坐标集合|第一个点坐标
|
|
|
- */
|
|
|
+ */
|
|
|
constructor(parent: SGraphItem | null, line?: SPoint | SPoint[]) {
|
|
|
super(parent);
|
|
|
if (line) {
|
|
@@ -179,10 +179,17 @@ export class SLineItem extends SGraphItem {
|
|
|
} // Constructor
|
|
|
|
|
|
/**
|
|
|
+ * 点发生变化
|
|
|
+ */
|
|
|
+ protected pointChange(): void {
|
|
|
+ // do nothing
|
|
|
+ } // Function pointChange()
|
|
|
+
|
|
|
+ /**
|
|
|
* 添加点至数组中
|
|
|
*
|
|
|
* @param p 添加的点
|
|
|
- */
|
|
|
+ */
|
|
|
private addPoint(p: SPoint): void {
|
|
|
if (this.line.length < 2) {
|
|
|
this.line.push(p);
|
|
@@ -193,6 +200,7 @@ export class SLineItem extends SGraphItem {
|
|
|
this.status = SItemStatus.Normal;
|
|
|
this.releaseItem();
|
|
|
this.$emit("finishCreated");
|
|
|
+ this.pointChange();
|
|
|
}
|
|
|
this.update();
|
|
|
} // Function addPoint()
|
|
@@ -202,7 +210,7 @@ export class SLineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param event 事件参数
|
|
|
* @return 是否处理事件
|
|
|
- */
|
|
|
+ */
|
|
|
onDoubleClick(event: SMouseEvent): boolean {
|
|
|
if (this.status == SItemStatus.Normal) {
|
|
|
this.status = SItemStatus.Edit;
|
|
@@ -220,7 +228,7 @@ export class SLineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param event 鼠标事件
|
|
|
* @return 是否处理事件
|
|
|
- */
|
|
|
+ */
|
|
|
onMouseDown(event: SMouseEvent): boolean {
|
|
|
this.curIndex = -1;
|
|
|
this.curPoint = null;
|
|
@@ -247,7 +255,7 @@ export class SLineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param event 事件参数
|
|
|
* @return 是否处理事件
|
|
|
- */
|
|
|
+ */
|
|
|
onMouseUp(event: SMouseEvent): boolean {
|
|
|
if (this.status == SItemStatus.Edit) {
|
|
|
if (this.curIndex > -1) {
|
|
@@ -277,7 +285,7 @@ export class SLineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param event 事件参数
|
|
|
* @return 是否处理事件
|
|
|
- */
|
|
|
+ */
|
|
|
onMouseMove(event: SMouseEvent): boolean {
|
|
|
if (event.shiftKey) {
|
|
|
event = this.compare(event);
|
|
@@ -286,11 +294,13 @@ export class SLineItem extends SGraphItem {
|
|
|
if (this.status == SItemStatus.Create) {
|
|
|
if (this.line[0] instanceof SPoint) {
|
|
|
this.line[1] = new SPoint(event.x, event.y);
|
|
|
+ this.pointChange();
|
|
|
}
|
|
|
} else if (this.status == SItemStatus.Edit) {
|
|
|
if (-1 != this.curIndex) {
|
|
|
this.line[this.curIndex].x = event.x;
|
|
|
this.line[this.curIndex].y = event.y;
|
|
|
+ this.pointChange();
|
|
|
}
|
|
|
} else {
|
|
|
return super.onMouseMove(event);
|
|
@@ -304,7 +314,7 @@ export class SLineItem extends SGraphItem {
|
|
|
* 获取点击点与 Point[] 中的点距离最近点
|
|
|
*
|
|
|
* @param p 鼠标点击点
|
|
|
- */
|
|
|
+ */
|
|
|
findNearestPoint(p: SPoint): void {
|
|
|
let len = this.sceneDis;
|
|
|
for (let i = 0; i < this.line.length; i++) {
|
|
@@ -327,7 +337,7 @@ export class SLineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param SGraphCommand 相关命令类
|
|
|
* @param any 对应传入参数
|
|
|
- */
|
|
|
+ */
|
|
|
protected recordAction(SGraphCommand: any, any: any[]): void {
|
|
|
// 记录相关命令并推入堆栈中 todo
|
|
|
const command = new SGraphCommand(this.scene, this, ...any);
|
|
@@ -339,7 +349,7 @@ export class SLineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param x x 坐标
|
|
|
* @param y y 坐标
|
|
|
- */
|
|
|
+ */
|
|
|
moveToOrigin(x: number, y: number): void {
|
|
|
super.moveToOrigin(x, y);
|
|
|
this.line = this.line.map(t => {
|
|
@@ -356,7 +366,7 @@ export class SLineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param event 事件
|
|
|
* @return 处理后的事件对象
|
|
|
- */
|
|
|
+ */
|
|
|
compare(event: SMouseEvent): SMouseEvent {
|
|
|
if (this.line.length) {
|
|
|
let last = new SPoint(event.x, event.y);
|
|
@@ -387,7 +397,7 @@ export class SLineItem extends SGraphItem {
|
|
|
* @param x x 坐标
|
|
|
* @param y y 坐标
|
|
|
* @return 是否包含
|
|
|
- */
|
|
|
+ */
|
|
|
contains(x: number, y: number): boolean {
|
|
|
if (this.line.length == 2) {
|
|
|
let p = new SPoint(x, y);
|
|
@@ -404,7 +414,7 @@ export class SLineItem extends SGraphItem {
|
|
|
|
|
|
/**
|
|
|
* 撤销操作
|
|
|
- */
|
|
|
+ */
|
|
|
undo(): void {
|
|
|
if (this.status != SItemStatus.Normal) {
|
|
|
this.undoStack.undo();
|
|
@@ -413,7 +423,7 @@ export class SLineItem extends SGraphItem {
|
|
|
|
|
|
/**
|
|
|
* 重做操作
|
|
|
- */
|
|
|
+ */
|
|
|
redo(): void {
|
|
|
if (this.status != SItemStatus.Normal) {
|
|
|
this.undoStack.redo();
|
|
@@ -422,7 +432,7 @@ export class SLineItem extends SGraphItem {
|
|
|
|
|
|
/**
|
|
|
* 取消操作 item 事件
|
|
|
- */
|
|
|
+ */
|
|
|
cancelOperate(): void {
|
|
|
if (this.status == SItemStatus.Create) {
|
|
|
this.parent = null;
|
|
@@ -437,7 +447,7 @@ export class SLineItem extends SGraphItem {
|
|
|
* Item 对象边界区域
|
|
|
*
|
|
|
* @return 边界区域
|
|
|
- */
|
|
|
+ */
|
|
|
boundingRect(): SRect {
|
|
|
if (this.line.length) {
|
|
|
this.minX = this.line[0].x;
|
|
@@ -474,7 +484,7 @@ export class SLineItem extends SGraphItem {
|
|
|
* Item 绘制操作
|
|
|
*
|
|
|
* @param painter 绘制对象
|
|
|
- */
|
|
|
+ */
|
|
|
onDraw(painter: SPainter): void {
|
|
|
this.sceneDis = painter.toPx(this.dis);
|
|
|
painter.pen.lineWidth = painter.toPx(this.lineWidth);
|