Bladeren bron

折线item更新;undo栈修改

haojianlong 5 jaren geleden
bovenliggende
commit
ec741cb6cd

+ 1 - 1
saga-web-base/src/undo/SUndoStack.ts

@@ -98,11 +98,11 @@ export class SUndoStack extends SObject {
      * @param   cmd     被添加的命令
      */
     push(cmd: SUndoCommand): void {
+        this.cmdStack.length = this._index + 1;
         if (this._index >= 0 && cmd.mergeWith(this.cmdStack[this._index])) {
             return;
         }
 
-        this.cmdStack.length = this._index + 1;
         this.cmdStack.push(cmd);
         this._index = this.cmdStack.length - 1;
     } // Function push()

+ 1 - 1
saga-web-big/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/big",
-    "version": "1.0.9",
+    "version": "1.0.11",
     "description": "上格云建筑信息化库",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 7 - 1
saga-web-big/src/index.ts

@@ -22,6 +22,9 @@ import { STopologyParser } from "./parser/STopologyParser";
 import { SFloorParser } from "./parser/SFloorParser";
 import { SParser } from "./parser/SParser";
 import { SIconTextItem } from "./items/SIconTextItem";
+import { SPolylineItem } from "./items/SPolylineItem";
+import { SLineItem } from "./items/SLineItem";
+import { SRelationState } from "./enums/SRelationState";
 
 export {
     SAnchorItem,
@@ -32,6 +35,8 @@ export {
     SImageItem,
     SLayerItem,
     SLineRelation,
+    SLineItem,
+    SPolylineItem,
     SObjectItem,
     SRelation,
     STextItem,
@@ -47,5 +52,6 @@ export {
     SZoneParser,
     SEquipParser,
     SBigParser,
-    SIconTextItem
+    SIconTextItem,
+    SRelationState
 };

+ 64 - 6
saga-web-big/src/items/SLineItem.ts

@@ -1,7 +1,8 @@
 import { SGraphyItem } from "@saga-web/graphy/lib";
-import { SLine, SPainter, SPoint } from "@saga-web/draw/lib";
+import { SColor, SLine, SPainter, SPoint } from "@saga-web/draw/lib";
 import { SMouseEvent } from "@saga-web/base";
 import { SMathUtil } from "../utils/SMathUtil";
+import { SRelationState } from "..";
 
 /**
  * 直线item
@@ -14,9 +15,45 @@ export class SLineItem extends SGraphyItem {
     /** 线段终止点   */
     p2: SPoint | undefined;
     /** 是否完成绘制  */
-    private isFinish: boolean = true;
+    _status: SRelationState = SRelationState.Create;
+    get status(): SRelationState {
+        return this._status;
+    }
+    set status(v: SRelationState) {
+        this._status = v;
+        this.update();
+    }
+    /** 线条颜色    */
+    _strokeColor: string = "#000000";
+    get strokeColor(): string {
+        return this._strokeColor;
+    }
+    set strokeColor(v: string) {
+        this._strokeColor = v;
+        this.update();
+    }
+    /** 填充色 */
+    _fillColor: string = "#2196f3";
+    get fillColor(): string {
+        return this._fillColor;
+    }
+    set fillColor(v: string) {
+        this._fillColor = v;
+        this.update();
+    }
+    /** 线条宽度    */
+    _lineWidth: number = 1;
+    get lineWidth(): number {
+        return this._lineWidth;
+    }
+    set lineWidth(v: number) {
+        this._lineWidth = v;
+        this.update();
+    }
     /** 拖动灵敏度   */
     dis: number = 10;
+    /** 拖动灵敏度   */
+    sceneDis: number = 10;
 
     /**
      * 构造函数
@@ -57,7 +94,14 @@ export class SLineItem extends SGraphyItem {
      * @return  是否处理事件
      * */
     onMouseDown(event: SMouseEvent): boolean {
-        return false;
+        if (this.status == SRelationState.Normal) {
+            return super.onMouseDown(event);
+        } else if (this.status == SRelationState.Edit) {
+        } else if (this.status == SRelationState.Create) {
+            return true;
+        }
+        this.$emit("mousedown");
+        return true;
     } // Function onMouseDown()
 
     /**
@@ -67,7 +111,7 @@ export class SLineItem extends SGraphyItem {
      * @return  是否处理事件
      * */
     onMouseMove(event: SMouseEvent): boolean {
-        if (!this.isFinish) {
+        if (this.status == SRelationState.Create) {
             if (!this.p2) {
                 this.p2 = new SPoint(event.x, event.y);
             } else {
@@ -87,8 +131,8 @@ export class SLineItem extends SGraphyItem {
      * @return  是否处理事件
      * */
     onMouseUp(event: SMouseEvent): boolean {
-        if (!this.isFinish) {
-            this.isFinish = true;
+        if (this.status == SRelationState.Create) {
+            this.status = SRelationState.Edit;
             return true;
         } else {
             return super.onMouseUp(event);
@@ -121,8 +165,22 @@ export class SLineItem extends SGraphyItem {
      * @param   painter painter对象
      */
     onDraw(painter: SPainter): void {
+        this.sceneDis = painter.toPx(this.dis);
+        painter.pen.lineWidth = painter.toPx(this.lineWidth);
+        painter.pen.color = new SColor(this.strokeColor);
         if (this.p1 instanceof SPoint && this.p2 instanceof SPoint) {
+            // 绘制基本图形
             painter.drawLine(this.p1, this.p2);
+            // 编辑态
+            if (this.status == SRelationState.Edit) {
+                painter.brush.color = SColor.White;
+
+                // painter.brush.color = new SColor(this.fillColor);
+
+                painter.drawCircle(this.p1.x, this.p1.y, painter.toPx(5));
+
+                painter.drawCircle(this.p2.x, this.p2.y, painter.toPx(5));
+            }
         }
     } // Function onDraw()
 } // Class SLineItem

+ 91 - 15
saga-web-big/src/items/SPolylineItem.ts

@@ -1,7 +1,7 @@
 import { SGraphyItem } from "@saga-web/graphy/lib";
 import { SColor, SLine, SPainter, SPoint } from "@saga-web/draw/lib";
 import { SMouseEvent } from "@saga-web/base";
-import { SRelationState } from "../enums/SRelationState";
+import { SRelationState } from "..";
 import { SMathUtil } from "../utils/SMathUtil";
 
 /**
@@ -13,7 +13,14 @@ export class SPolylineItem extends SGraphyItem {
     /** 折点信息    */
     pointList: SPoint[] = [];
     /** 是否绘制完成  */
-    status: SRelationState = SRelationState.Create;
+    _status: SRelationState = SRelationState.Create;
+    get status(): SRelationState {
+        return this._status;
+    }
+    set status(v: SRelationState) {
+        this._status = v;
+        this.update();
+    }
     /** 鼠标移动时的点 */
     lastPoint: SPoint | null = null;
     /** 线条颜色    */
@@ -26,12 +33,13 @@ export class SPolylineItem extends SGraphyItem {
         this.update();
     }
     /** 填充色 */
-    _fillColor: string = "#ffffff";
+    _fillColor: string = "#2196f3";
     get fillColor(): string {
         return this._fillColor;
     }
     set fillColor(v: string) {
         this._fillColor = v;
+        this.update();
     }
     /** 线条宽度    */
     _lineWidth: number = 1;
@@ -92,6 +100,7 @@ export class SPolylineItem extends SGraphyItem {
         } else {
             this.pointList.push(p);
         }
+        this.update();
     } // Function addPoint()
 
     /**
@@ -110,8 +119,9 @@ export class SPolylineItem extends SGraphyItem {
      * @param   index   添加到的索引
      * */
     private delPoint(index: number): void {
-        if (this.canHandle(index)) {
+        if (this.canHandle(index) && this.pointList.length > 2) {
             this.pointList.splice(index, 0);
+            this.update();
         }
     } // Function delPoint
 
@@ -126,8 +136,15 @@ export class SPolylineItem extends SGraphyItem {
             if (this.status == SRelationState.Create) {
                 this.addPoint(new SPoint(event.x, event.y));
                 return true;
+            } else if (this.status == SRelationState.Edit) {
+                this.findNearestPoint(new SPoint(event.x, event.y));
+                if (event.altKey && this.canHandle(this.curIndex)) {
+                    this.pointList.splice(this.curIndex, 1);
+                    this.curIndex = -1;
+                    this.update();
+                }
+                return true;
             } else {
-                //拖动点
             }
         }
         return super.onMouseDown(event);
@@ -140,24 +157,39 @@ export class SPolylineItem extends SGraphyItem {
      * @return  boolean 是否处理事件
      * */
     onMouseMove(event: SMouseEvent): boolean {
-        if (event.buttons == 1) {
-            if (this.status == SRelationState.Create) {
-                if (this.lastPoint) {
-                    this.lastPoint.x = event.x;
-                    this.lastPoint.y = event.y;
-                } else {
-                    this.lastPoint = new SPoint(event.x, event.y);
-                }
-                return true;
+        if (this.status == SRelationState.Create) {
+            if (this.lastPoint) {
+                this.lastPoint.x = event.x;
+                this.lastPoint.y = event.y;
             } else {
-                return super.onMouseMove(event);
+                this.lastPoint = new SPoint(event.x, event.y);
+            }
+            this.update();
+            return true;
+        } else if (this.status == SRelationState.Edit) {
+            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);
         }
     } // Function onMouseMove()
 
     /**
+     * 鼠标移动事件
+     *
+     * @param   event   鼠标事件
+     * @return  boolean 是否处理事件
+     * */
+    onMouseUp(event: SMouseEvent): boolean {
+        this.curIndex = -1;
+        return true;
+    } // Function onMouseMove()
+
+    /**
      * 鼠标双击事件
      *
      * @param	event         事件参数
@@ -166,7 +198,30 @@ export class SPolylineItem extends SGraphyItem {
     onDoubleClick(event: SMouseEvent): boolean {
         if (this.status == SRelationState.Create) {
             this.status = SRelationState.Normal;
+        } else if (this.status == SRelationState.Edit) {
+            let len = SMathUtil.pointToLine(
+                    new SPoint(event.x, event.y),
+                    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++) {
+                    let dis = SMathUtil.pointToLine(
+                        new SPoint(event.x, event.y),
+                        new SLine(this.pointList[i], this.pointList[i + 1])
+                    );
+                    if (dis.MinDis < len.MinDis) {
+                        len = dis;
+                        index = i;
+                    }
+                }
+            }
+            if (len.Point) {
+                this.pointList.splice(index + 1, 0, len.Point);
+                this.update();
+            }
         }
+        this.$emit("onDoubleClick", event);
         return true;
     } // Function onDoubleClick()
 
@@ -182,6 +237,27 @@ export class SPolylineItem extends SGraphyItem {
     } // Function onKeyUp()
 
     /**
+     * 获取点击点与点集中距离最近点
+     *
+     * @param   p   鼠标点击点
+     * */
+    findNearestPoint(p: SPoint): void {
+        let len = this.sceneDis;
+        for (let i = 0; i < this.pointList.length; i++) {
+            let dis = SMathUtil.pointDistance(
+                p.x,
+                p.y,
+                this.pointList[i].x,
+                this.pointList[i].y
+            );
+            if (dis < len) {
+                len = dis;
+                this.curIndex = i;
+            }
+        }
+    } // Function findNearestPoint()
+
+    /**
      * 判断点是否在区域内
      *
      * @param   x

+ 1 - 1
saga-web-big/src/items/STextItem.ts

@@ -37,7 +37,7 @@ export class STextItem extends SObjectItem {
     maxWidth: number | undefined = undefined;
 
     /** 文本颜色    */
-    private _color: string = "#000000";
+    _color: string = "#000000";
     get color(): string {
         return this._color;
     }