|
@@ -203,165 +203,6 @@ export class SPolylineItem extends SGraphItem {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 鼠标按下事件
|
|
|
- *
|
|
|
- * @param event 鼠标事件
|
|
|
- * @return 是否处理事件
|
|
|
- */
|
|
|
- onMouseDown(event: SMouseEvent): boolean {
|
|
|
- this.curIndex = -1;
|
|
|
- this.curPoint = null;
|
|
|
- if (event.shiftKey) {
|
|
|
- event = this.compare(event);
|
|
|
- }
|
|
|
-
|
|
|
- if (event.buttons == 1) {
|
|
|
- if (this.status == SItemStatus.Create) {
|
|
|
- this.addPoint(new SPoint(event.x, event.y));
|
|
|
- return true;
|
|
|
- } else if (this.status == SItemStatus.Edit) {
|
|
|
- // 查询鼠标最近的索引
|
|
|
- this.findNearestPoint(new SPoint(event.x, event.y));
|
|
|
-
|
|
|
- // 增加点
|
|
|
- if (this.curIndex < 0) {
|
|
|
- this.findAddPos(new SPoint(event.x, event.y));
|
|
|
- }
|
|
|
-
|
|
|
- // 删除点
|
|
|
- if (event.altKey && this.canHandle(this.curIndex)) {
|
|
|
- this.deletePoint(this.curIndex);
|
|
|
- }
|
|
|
-
|
|
|
- this.update();
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return super.onMouseDown(event);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return super.onMouseDown(event);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 鼠标移动事件
|
|
|
- *
|
|
|
- * @param event 鼠标事件
|
|
|
- * @return 是否处理事件
|
|
|
- */
|
|
|
- onMouseMove(event: SMouseEvent): boolean {
|
|
|
- if (event.shiftKey) {
|
|
|
- event = this.compare(event);
|
|
|
- }
|
|
|
-
|
|
|
- if (this.status == SItemStatus.Create) {
|
|
|
- if (this.lastPoint) {
|
|
|
- this.lastPoint.x = event.x;
|
|
|
- this.lastPoint.y = event.y;
|
|
|
- } else {
|
|
|
- this.lastPoint = new SPoint(event.x, event.y);
|
|
|
- }
|
|
|
-
|
|
|
- this.update();
|
|
|
- return true;
|
|
|
- } else if (this.status == SItemStatus.Edit) {
|
|
|
- if (event.buttons == 1) {
|
|
|
- if (this.canHandle(this.curIndex)) {
|
|
|
- this.pointList[this.curIndex].x = event.x;
|
|
|
- this.pointList[this.curIndex].y = event.y;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- this.update();
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return super.onMouseMove(event);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 鼠标移动事件
|
|
|
- *
|
|
|
- * @param event 鼠标事件
|
|
|
- * @return 是否处理事件
|
|
|
- */
|
|
|
- onMouseUp(event: SMouseEvent): boolean {
|
|
|
- if (this.status == SItemStatus.Edit) {
|
|
|
- if (this.curIndex > -1) {
|
|
|
- const p = new SPoint(
|
|
|
- this.pointList[this.curIndex].x,
|
|
|
- this.pointList[this.curIndex].y
|
|
|
- );
|
|
|
- this.recordAction(SGraphPointListUpdate, [
|
|
|
- this.pointList,
|
|
|
- this.curPoint,
|
|
|
- p,
|
|
|
- this.curIndex
|
|
|
- ]);
|
|
|
- }
|
|
|
- } else if (this.status == SItemStatus.Normal) {
|
|
|
- this.moveToOrigin(this.x, this.y);
|
|
|
- return super.onMouseUp(event);
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 鼠标双击事件
|
|
|
- *
|
|
|
- * @param event 事件参数
|
|
|
- * @return 是否处理
|
|
|
- */
|
|
|
- onDoubleClick(event: SMouseEvent): boolean {
|
|
|
- // 如果为show状态 双击改对象则需改为编辑状态
|
|
|
- if (this.status == SItemStatus.Normal) {
|
|
|
- this.status = SItemStatus.Edit;
|
|
|
- this.grabItem(this);
|
|
|
- } else if (this.status == SItemStatus.Edit) {
|
|
|
- // 编辑状态
|
|
|
- this.status = SItemStatus.Normal;
|
|
|
- this.releaseItem();
|
|
|
- } else if (this.status == SItemStatus.Create) {
|
|
|
- // 创建状态
|
|
|
- if (this.pointList.length > 1) {
|
|
|
- this.status = SItemStatus.Normal;
|
|
|
- this.releaseItem();
|
|
|
- this.$emit("finishCreated");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- this.$emit("onDoubleClick", event);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /***
|
|
|
- * 键盘按键弹起事件
|
|
|
- *
|
|
|
- * @param event 事件参数
|
|
|
- */
|
|
|
- onKeyUp(event: KeyboardEvent): void {
|
|
|
- if (event.keyCode == SKeyCode.Enter) {
|
|
|
- if (this.pointList.length > 1) {
|
|
|
- if (this.status == SItemStatus.Create) {
|
|
|
- this.$emit("finishCreated");
|
|
|
- }
|
|
|
-
|
|
|
- this.status = SItemStatus.Normal;
|
|
|
- this.releaseItem();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // delete删除点
|
|
|
- if (
|
|
|
- event.keyCode == SKeyCode.Delete &&
|
|
|
- this.status == SItemStatus.Edit
|
|
|
- ) {
|
|
|
- this.deletePoint(this.curIndex);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* 移动后处理所有坐标,并肩原点置为场景原点
|
|
|
*
|
|
|
* @param x x 坐标
|
|
@@ -412,9 +253,9 @@ 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;
|
|
|
if (this.pointList.length > 2) {
|
|
|
for (let i = 1; i < this.pointList.length - 1; i++) {
|